fenaren/cs420-game — pull request #14 by fenaren (2014-10-25 22:05:10+00:00)
Title: Em owns events

Events are much easier to deal with if the event manager takes ownership of them when you queue them, so I updated the event manager to do this. This makes things easier because we don't have to statically allocate all the events we will ever need in our classes before we use them. All we have to do is new them immediately before they're needed and then queue them in the event manager, and forget about them. The event manager will delete them after triggering them. Note that EventManager::triggerEvent hasn't been changed, it still takes a reference to an existing event.

I went through the game logic and updated it to work with the event manager in this new way. All the events statically allocated in the class are gone, and are now created dynamically as needed. Check it out, it's much easier to use events this way.

I also did a couple other side things. One is I updated the Map class to use its own Terrain enumeration, and made the Terrain enumeration public so other classes can use it (which the game logic now does). I removed the ActorMovedEventHandler from the game logic, since it's really not necessary (the game logic doesn't need to be notified when an actor moves because it itself is moving the actors, it already knows). I registered the ShipMoveCmdEventHandler with the ShipMoveCmdEvent, so now ShipMoveCmdEventHandler is called when the ShipMoveCmdEvent is called. It even works ... sort of.

The "sort of" is that there's an inconsistency in how the game logic and how the map interpret map coordinates. The game logic thinks the X axis of the map is horizontal, left-to-right, and the Y axis is vertical, top-to-bottom. When it uses the map class's getTerrain function it assumes the first parameter is the X coordinate, and the second is Y. That isn't actually how the map is stored internally in the Map class though. The Map class assumes the first coordinate to getTerrain is "rows", and the second is "columns". So as you increase the first parameter, it's actually looking at terrain moving downwards on the map, top-to-bottom.