Updated Scene System (markdown)

Kayne Ruse
2013-05-02 04:56:52 -07:00
parent 8b9989c074
commit e3e59643e9
+24 -2
@@ -10,6 +10,28 @@ The scene system is the backbone of the game client, utilizing the [strategy pat
## Breakdown ## Breakdown
main.cpp simply creates an instance of SceneManager, calls it's Init(), Loop() and Quit() functions in order, and handles any fatal exceptions thrown from the rest of the program. main.cpp simply creates an instance of SceneManager, calls it's Init(), Loop() and Quit() functions in order, and handles any fatal exceptions thrown from the rest of the program.
scene_list.hpp holds an enum class of macros, one for each scene in the game. All scenes in the game should include this file in the .cpp. scene_list.hpp holds an enum class of macros, one for each scene in the game. All scenes in the game should include this file in the *.cpp. The macros QUIT, CONTINUE and FIRST are reserved.
base_scene.hpp and base_scene.cpp hold the interface of the strategy pattern i.e. all scenes in the game MUST inherit from the BaseScene class. This class handles the game's screen (which is a static member) and the player's input (via SDL). base_scene.hpp and base_scene.cpp hold the interface of the strategy pattern i.e. all scenes in the game MUST inherit from the BaseScene class. This class handles the game's screen (which is a static member) and the player's input (via SDL).
... scene_manager.hpp and scene_manager.cpp hold the SceneManager class, which initializes and deinitializes the game client, and handles the transition between scenes in the strategy pattern.
## Instructions
To add a new scene to the game, create a class that inherits from BaseScene, overriding any or all of it's members. Then, include the class's header into scene_manager.cpp where it's indicated. Finally, add a new macro for your scene to scene_list.hpp, and modify SceneManager::LoadScene(SceneIndex) to include that macro and your scene's constructor.
Here's an example, using a class called "NewScene":
```c++11
void SceneManager::LoadScene(SceneList sceneIndex) {
UnloadScene();
switch(sceneIndex) {
//add scene creation calls here
case SceneList::FIRST: //use this to indicate the first scene created
case SceneList::NEWSCENE: //the macro
activeScene = new NewScene(); //the creation of a scene
break;
default:
throw(std::logic_error("Failed to recognize the scene index"));
}
}
```