diff options
author | max-001 <maxsmits21@kpnmail.nl> | 2024-11-05 14:17:22 +0100 |
---|---|---|
committer | max-001 <maxsmits21@kpnmail.nl> | 2024-11-05 14:17:22 +0100 |
commit | 4460bd204d32f4f3dd00661b1b3e42c89588233f (patch) | |
tree | 51d38fd599818337f2ff70fd4095a26f21634750 /src/example | |
parent | 99f71fea64ada18def09e9c32633cf7c8e7ce5d7 (diff) |
Improved test by adding one Transform component too much
Diffstat (limited to 'src/example')
-rw-r--r-- | src/example/ecs.cpp | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp index 2eb09b2..5646edd 100644 --- a/src/example/ecs.cpp +++ b/src/example/ecs.cpp @@ -24,31 +24,33 @@ int main() { rightLeg.set_parent(body); leftLeg.set_parent(body); - // Get the Metadata and Transform components of each GameObject - ComponentManager & mgr = ComponentManager::get_instance(); - vector<reference_wrapper<Metadata>> metadata - = mgr.get_components_by_type<Metadata>(); - vector<reference_wrapper<Transform>> transform - = mgr.get_components_by_type<Transform>(); - - // Print the Metadata and Transform components - for (auto & m : metadata) { - cout << "Id: " << m.get().game_object_id - << " Name: " << m.get().name << " Tag: " << m.get().tag - << " Parent: " << m.get().parent << " Children: "; - for (auto & c : m.get().children) { - cout << c << " "; - } - cout << endl; - } - for (auto & t : transform) { - cout << "Id: " << t.get().game_object_id << " Position: [" - << t.get().position.x << ", " << t.get().position.y << "]" - << endl; - } + // Adding a second Transform component is not allowed and will invoke an exception + body.add_component<Transform>(Point{10, 10}, 0, 1); } catch (const exception & e) { cerr << e.what() << endl; } + // Get the Metadata and Transform components of each GameObject + ComponentManager & mgr = ComponentManager::get_instance(); + vector<reference_wrapper<Metadata>> metadata + = mgr.get_components_by_type<Metadata>(); + vector<reference_wrapper<Transform>> transform + = mgr.get_components_by_type<Transform>(); + + // Print the Metadata and Transform components + for (auto & m : metadata) { + cout << "Id: " << m.get().game_object_id << " Name: " << m.get().name + << " Tag: " << m.get().tag << " Parent: " << m.get().parent + << " Children: "; + for (auto & c : m.get().children) { + cout << c << " "; + } + cout << endl; + } + for (auto & t : transform) { + cout << "Id: " << t.get().game_object_id << " Position: [" + << t.get().position.x << ", " << t.get().position.y << "]" << endl; + } + return 0; } |