diff options
author | max-001 <maxsmits21@kpnmail.nl> | 2024-11-07 09:54:51 +0100 |
---|---|---|
committer | max-001 <maxsmits21@kpnmail.nl> | 2024-11-07 09:54:51 +0100 |
commit | 7dfaa964a5039d7c24d16038589c77032152b9f2 (patch) | |
tree | dcb2448fa697dabcb2f248326616a16e62821125 /src/example | |
parent | fd60c0280440da053948f7500657ae65b94036bf (diff) | |
parent | 3a5201961ce31d415042c6273d03e46aed7e6eb8 (diff) |
Merge remote-tracking branch 'origin/master' into max/big-cleanup
Diffstat (limited to 'src/example')
-rw-r--r-- | src/example/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/example/scene_manager.cpp | 75 |
2 files changed, 76 insertions, 0 deletions
diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 81df8d1..023d0ad 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -25,3 +25,4 @@ add_example(asset_manager) add_example(particle) add_example(physics) add_example(ecs) +add_example(scene_manager) diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp new file mode 100644 index 0000000..bce42ca --- /dev/null +++ b/src/example/scene_manager.cpp @@ -0,0 +1,75 @@ +#include <iostream> + +#include "../crepe/ComponentManager.h" +#include "../crepe/api/GameObject.h" +#include "../crepe/api/Metadata.h" +#include "../crepe/api/Point.h" +#include "../crepe/api/Scene.h" +#include "../crepe/api/SceneManager.h" + +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"); + + // There is no need to call set_next_scene() at the beginnen, because the first scene will be automatically set as the next scene + // Load scene1 (the first scene added) + scene_mgr.load_next_scene(); + + // 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; + } + + // Set scene2 as the next scene + scene_mgr.set_next_scene("scene2"); + // Load scene2 + scene_mgr.load_next_scene(); + + // 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; +} |