diff options
Diffstat (limited to 'src')
-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; } |