Version 4, last updated by Jason Spafford at August 18, 2010 01:38 UTC
Module State Machine
The Valkyrie engine is designed around what's called a state machine. These "states" are represented by modules that the developer of the game creates. These modules have methods which the engine will call when it updates, draws, or you push modules to the screen. However, you can manually manage the modules using the ModuleManager.
Creating a Module
All modules must implement the IModule interface. These provide the basic methods of which a module is managed. The following are a description of the IModule's methods.
void Tick(GameTime gameTime);
Tick is called when the module is to be updated. The TileEngine passes it's current gametime down to the current module using this method
void Draw(SpriteBatch spriteBatch, GameTime gameTime);
Draw is called when the module is to be drawn to the screen. This happens when TileEngine.Draw is to be drawn and the current module's "Draw" is called. The TileEngine passes down both SpriteBatch and GameTime to the module when this is called.
void Load();
Load is called when the module should be initialized and it's data loaded. The engine uses this to ensure that the module can load and has a chance to load all of the resources it needs before it is updated or drawn.
void Unload();
Unload is called when the engine is going to unload the current module. It is a chance for the module to unload and dispose of any resources.
void Activate();
Activate is called when the module is activated from some previous state whether it's been paused, or the game has been minimized or something else. It is not a time to reload resources but to continue the flow of logic and resume where it left off.
void Deactivate();
Deactive is called when the module should be put on "hold" or stopped. It gives a chance for the module to stop itself before it is temporarily or perminently unused. It is not the palce to unload resources as it may be used again shortly, or in a period of time.
Managing, adding, and pushing modules to the screen
Loading modules is a very simple progress. Just call ModuleManager.AddModule and give it an instance of your module as well as the name of the module to use in the module manager.