aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-06-23 15:51:59 +0100
committerYann Herklotz <ymherklotz@gmail.com>2018-06-23 15:51:59 +0100
commit93c8bfea8b5bcfc0d6513d93cec0eafe82dc465a (patch)
tree3f06a7d35e8ec647041fccea90d5d763ebe6849f
parent8dfc67bd3d2297410a39bf907d9a59589c6c7d9d (diff)
downloadYAGE-93c8bfea8b5bcfc0d6513d93cec0eafe82dc465a.tar.gz
YAGE-93c8bfea8b5bcfc0d6513d93cec0eafe82dc465a.zip
Updating example to test out the new entity systemdevelop
-rw-r--r--tests/entity_test.cpp35
1 files 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<Position> {
double x;
double y;
+ Position() = default;
Position(double x_, double y_) : x(x_), y(y_) {}
};
@@ -18,7 +19,8 @@ struct Size : public Component<Size> {
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<MovementSystem>
@@ -26,27 +28,36 @@ class MovementSystem : public System<MovementSystem>
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>([](Position &pos) {
+ std::cout << " X: " << pos.x << ", Y: " << pos.y << "\n";
+ ++pos.x, ++pos.y;
+ });
+ std::cout << " Size\n";
+ em.each<Size>([](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<Size>(10, 5))
+ .add_component(e1, std::make_unique<Position>(1, 5))
+ .add_component(e2, std::make_unique<Position>(5, 2));
+ s.update(60, em);
+ s.update(60, em);
+ em.delete_entity(e2);
s.update(60, em);
}