Using maps and iterators instead of for-loops

These coming blogs will detail my coding efforts and my work to create a working clone of the Legend of Zelda for the NES, using SDL and C++.

 

To start off with , I needed some way of inputting information and managing that input. We had been offered a template for the general setup of this inputmanager  in our Arkanoid clone project, but as I both wanted to try to learn new things and try different approaches, some changes have been made so far.

 

For this  I needed an external library which could help craft the specific vectors I required (gml, an opengl math library), as well as a standard library (map) to create something to hold information on what keys we had pressed.

Before, a for-loop was executed going through every single key’s assigned number to check if a key was pressed or not. This was more memory-efficient, but not quite as fast as a different method I was given the suggestion of using. Now, a so-called map is used to both hold and save checked  numbers, which creates the keys’ positions as required. An iterator (auto) goes through them in order until the end of said map is reached, returning a bool state, true or false, upon completion.

At the same time, values are assigned to our gml vectors to determine just what position our mouse is at.

 

This code obviously doesn’t actually do anything just yet beyond check for input, but it seems as good a place as any to start.

 

About Karl Malm

2015 Programming