Skip to content

How to use System

mackfoggia edited this page Aug 6, 2021 · 1 revision

System

The primary purpose of the System is to run the game loop and manage Scenes. FarOut uses smart pointers to manage memory.

Basic functions of System

runWindow - Should be called after you are done setting up, starts the game
setFPSCounter - Used to toggle the built in FPS counter
quit - The preferred way to stop the game, pops all scenes and save data to file

Scene collection

System maintains a collection of all game scenes, so you must add your created scenes to this collection.

Relevant functions:
addScene - Add a created scene to the System's collection
getScene - Retrieve a pointer to a scene in the System's collection, given the ID

Active scene stack

System also maintains a stack of active scenes. When you want a scene to be drawn and updated it must be pushed onto this stack. When you want to switch to a different scene, first pop the previous scene and then push the new scene.

Relevant functions:
pushScene - Push a scene onto the top of the System's active scene stack
popScene - Pop the top scene off the System's active scene stack

Data storage module

System also features a data storage system that is accessible globally. This can be used to store data that you might want to access from other objects or scenes. This data is stored to disk when the game closes and is restored when it is reopened (*not currently implemented)

Relevant functions:
addData - Store data in the system
getData - Retrieve data stored in the system
changeData - Change a data value that is already stored in the system

Startup example

When you have created a class that inherits from Scene, create a shared pointer to an object of your class and then pass it to the System.addScene function. The first argument of this function is the ID of the scene, this is for your reference, the second argument is the pointer. Then, call System.pushScene on the same pointer. Now, call System.runWindow to start the game. You should see your scene display.

int main()
{
    std::shared_ptr<Scene> s (new MyScene);
    System.addScene(1, s);
    System.pushScene(s);

    System.runWindow();

    return 0;
}

Clone this wiki locally