Grid class redesign

In the past days I’ve been going through a general Grid class design overhaul. As it was before, the Grid class consisted in a single instance (singleton) that had the responsibility to manage map assets, load them into the game and make it work. This implied a precise set of properties maps had to have, one of these is the playable character.

Before the redesign, every map file had to contain a Character set to playable, in order to give some object the camera would have followed, allowing for the game to effectively run. After all, years ago, I just assumed I could have only one map loaded at a time, and only one playable character that was bounded in navigating through its map. Characters where destroyed and reinstanced every map change, delegating the character existence responsibility to the Map itself.

That sounded very reasonable back in the past, after all, this was meant to be just a small engine with the maximum ambition set to the be somewhat similar to RPGMakerXP. This is not the case anymore, so we’re aiming for a more flexible management of maps (Grid s):

  • More maps should be allowed to exist in the game world at the same time
  • More than one character should be playable and manageable at the same time
  • The playable characters creation shouldn’t be responsibility of the maps directly, but only held temporarily
  • Maps should stay into the scene graph and should be activated / deactivated as preferred, allowing for transitions and different kinds of transformation

We started a transition from Grid being a singleton to being an instantiable object holding a single map, managed by the new born GridManager, addressed in commits:
cd48091931c86f23fe6e01328266e8927327e041,
de051b25e871077bb85a439560bed27d2eeba481,
cbf6d61021a87976689a0dd59d45cbd61808a28b and
a92cf7ca1c620134961ce6dad83ae7733b1531cb.

A map is created by calling the appropriate method in the GridManager class as the example that follows.

# map can be instantiated
gridManager.addGrid('test.map', 'prova1')

# map can be retrieved
gridManager.getGrid('prova1')

# map can be moved with a Point3 vector
gridManager.getGrid('prova2').move(Point3(0.5,0,0))

# map can be stashed (removed from rendering and collision checking)
gridManager.getGrid('prova2').stash()
gridManager.getGrid('prova2').unstash()
gridManager.getGrid('prova2').toggleStash()
gridManager.getGrid('prova2').isStashed()

Here is the final result with 2 maps, both with a playable character enabled, one panning towards the left, while moving the character too.

See you at the next update!