Tuesday, August 9, 2011

Baddies 2.5–FSM and Scene

A FSMNode (finite state machine node), is a node with the special property that it has one active node, and that is the only one which gets updated and drawn. The FSMNode also has special methods to change the active node. A FSM is a pattern I find myself using a lot when I program games, so a generic Node-like FSM is a great deal.


Closely linked with the FSMNode is the Scene node. This is so because in any given game you have different scenes and only one of them active at any given time, so the FSMNode is the perfect place to hang SceneNodes. The one peculiar thing the SceneNodes have is a ContentManager, so the loaded content is local to each scene and when we swap scenes we don’t have to worry about what we load/unload. The common assets can be loaded in the Game ContentManager.


Seeing as the ContentManager class already caches and takes care of assets for us, there is no immediate need to make a resource manager and manage all assets globally. Again, we sacrifice a small amount of performance for simplicity of use.

That’s it for the specifics of those two classes.

No comments:

Post a Comment