Dev Diary

Closing in on the hand-in date for our final assignment in Game Programming I!

12/1 17:30 – 21:30

To do:

  • comment camera
  • sound effect on hit
  • gui
  • remove colliders when exiting rooms (we’re currently only removing the POINTER to the colliders, not the colliders themselves, resulting in a memory leak!)
  • get keys to work

Discussed how to get keys to work, and how to prevent global entities from displaying when entering new rooms. Decided to remove global entities, eg an enemy, when entering new rooms using an iterator in GameState.cpp in the NextRoom() function.

When attempting this, we encountered an error, “vector iterators incompatible.” The reason for this error is related to how vectors function: in order to dynamically allocate memory, every time an element is added or removed from a vector resulting in a different memory size required, the array is copied over to a new array of corresponding memory size. When using an iterator to delete items from the vector, we end up trying to access the address of the vector at its previous size – which it no longer has, as we have deleted an element from it and it has now been copied to a new memory address with a new size. http://stackoverflow.com/questions/8421623/vector-iterators-incompatible

In order to resolve this, we simply ignored the for-loop, and instead used vector function erase(), from begin+1 (we don’t want to erase the player, who is always the first entity in m_entities), to end(). (See the NextRoom() function GameState.cpp)

We also need the rooms to return whatever objects were in them when last exited, upon re-entry. My partner worked on this. He accomplished this by making Room’s Load function create a temporary vector to save all the entities which will be loaded into the new room (since we cannot access m_entities from outside of GameState, we use a temporary vector in Room’s Load() function. We then access the temporary vector from GameState and add it to m_entities). Only the rooms know what objects they will have (text file for the different rooms). Upon entering a room, GameState adds all of the entities from the temporary vector to the entity list.

Upon exiting a room, NextRoom() in GameState erases all entities from that room and removes them from the entity list. Upon entering/re-entering a room, Room Manager looks at the tilemap, GameState’s Draw() draws appropriate elements per tilemap character, and Room’s Load() loads in the entities as specified by the tilemap, into the temporary vector, which is then added to m_entities in GameState!
Fixed the sound manager since it did not include adding created clips to a map (now we don’t have create a new clip every time we want to play a sound).

About Dee Majek

2014  Programming