diff options
author | max-001 <maxsmits21@kpnmail.nl> | 2024-11-05 16:12:23 +0100 |
---|---|---|
committer | max-001 <maxsmits21@kpnmail.nl> | 2024-11-05 16:12:23 +0100 |
commit | 6071387c2bbe6d36a95c113ad137e8e2ce80be27 (patch) | |
tree | 81d0df4230979f74388dfd464e3026329779f9e7 /src/example/scene_manager.cpp | |
parent | d478c8b76d6155bd9653f81787f73db07c55d9f3 (diff) |
Added examples for the SceneManager
Diffstat (limited to 'src/example/scene_manager.cpp')
-rw-r--r-- | src/example/scene_manager.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp new file mode 100644 index 0000000..417a188 --- /dev/null +++ b/src/example/scene_manager.cpp @@ -0,0 +1,75 @@ +#include <iostream> + +#include "../crepe/api/SceneManager.h" +#include "../crepe/api/Scene.h" +#include "../crepe/api/GameObject.h" +#include "../crepe/Metadata.h" +#include "../crepe/ComponentManager.h" + +using namespace crepe::api; +using namespace crepe; +using namespace std; + +class concreteScene1 : public Scene { +public: + concreteScene1(string name) : Scene(name) {} + + void load_scene() { + GameObject object1(0, "scene_1", "tag_scene_1", Point{0, 0}, 0, 1); + GameObject object2(1, "scene_1", "tag_scene_1", Point{1, 0}, 0, 1); + GameObject object3(2, "scene_1", "tag_scene_1", Point{2, 0}, 0, 1); + } +}; + +class concreteScene2 : public Scene { +public: + concreteScene2(string name) : Scene(name) {} + + void load_scene() { + GameObject object1(0, "scene_2", "tag_scene_2", Point{0, 0}, 0, 1); + GameObject object2(1, "scene_2", "tag_scene_2", Point{0, 1}, 0, 1); + GameObject object3(2, "scene_2", "tag_scene_2", Point{0, 2}, 0, 1); + GameObject object4(3, "scene_2", "tag_scene_2", Point{0, 3}, 0, 1); + } +}; + +int main() { + SceneManager & scene_mgr = SceneManager::get_instance(); + + // Add the scenes to the scene manager + scene_mgr.add_scene<concreteScene1>("scene1"); + scene_mgr.add_scene<concreteScene2>("scene2"); + + // Load scene1 to the queue + scene_mgr.load_scene("scene1"); + // Empty the queue (now scene1 is loaded) + scene_mgr.empty_queue(); + + // Get the Metadata components of each GameObject of Scene1 + ComponentManager & component_mgr = ComponentManager::get_instance(); + vector<reference_wrapper<Metadata>> metadata = component_mgr.get_components_by_type<Metadata>(); + + cout << "Metadata components of Scene1:" << endl; + // Print the Metadata + for (auto & m : metadata) { + cout << "Id: " << m.get().game_object_id << " Name: " << m.get().name + << " Tag: " << m.get().tag << endl; + } + + // Load scene2 to the queue + scene_mgr.load_scene("scene2"); + // Empty the queue (now scene2 is loaded) + scene_mgr.empty_queue(); + + // Get the Metadata components of each GameObject of Scene2 + metadata = component_mgr.get_components_by_type<Metadata>(); + + cout << "Metadata components of Scene2:" << endl; + // Print the Metadata + for (auto & m : metadata) { + cout << "Id: " << m.get().game_object_id << " Name: " << m.get().name + << " Tag: " << m.get().tag << endl; + } + + return 0; +} |