From 93c8bfea8b5bcfc0d6513d93cec0eafe82dc465a Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 23 Jun 2018 15:51:59 +0100 Subject: Updating example to test out the new entity system --- tests/entity_test.cpp | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/tests/entity_test.cpp b/tests/entity_test.cpp index 0e40d3ea..578f1671 100644 --- a/tests/entity_test.cpp +++ b/tests/entity_test.cpp @@ -11,6 +11,7 @@ struct Position : public Component { double x; double y; + Position() = default; Position(double x_, double y_) : x(x_), y(y_) {} }; @@ -18,7 +19,8 @@ struct Size : public Component { double width; double height; - Size(double w, double h) : width(w), height(h) {} + Size() = default; + Size(double w_, double h_) : width(w_), height(h_) {} }; class MovementSystem : public System @@ -26,27 +28,36 @@ class MovementSystem : public System public: void update(double dt, EntityManager &em) override { - for (auto &&x : em.component_masks_) { - if(x[1] == 1) { - std::cout << "Found size: "; - } - } + std::cout << "New Iteration\n"; + std::cout << " Position\n"; + em.each([](Position &pos) { + std::cout << " X: " << pos.x << ", Y: " << pos.y << "\n"; + ++pos.x, ++pos.y; + }); + std::cout << " Size\n"; + em.each([](Size &size) { + std::cout << " WIDTH: " << size.width + << ", HEIGHT: " << size.height << "\n"; + size.width += 7; + size.height += 10; + }); } }; int main() { EntityManager em; - Position p1(1, 2); - Position p2(2, 1); - Size s1(5, 5); Entity e1 = em.create_entity(); Entity e2 = em.create_entity(); - std::cout << "e1: " << e1 << ", e2: " << e2 << "\n"; - MovementSystem s; - em.add_component(e1, &p1).add_component(e2, &p2).add_component(e2, &s1); + std::cout << "e1: " << e1 << "\n"; + em.add_component(e1, std::make_unique(10, 5)) + .add_component(e1, std::make_unique(1, 5)) + .add_component(e2, std::make_unique(5, 2)); + s.update(60, em); + s.update(60, em); + em.delete_entity(e2); s.update(60, em); } -- cgit