]> code.bitgloo.com Git - clyne/entityx.git/commitdiff
Remove ambiguity that old compilers can't resolve.
authorAlec Thomas <alec@swapoff.org>
Sun, 19 Jul 2015 01:22:10 +0000 (21:22 -0400)
committerAlec Thomas <alec@swapoff.org>
Sun, 19 Jul 2015 01:22:43 +0000 (21:22 -0400)
README.md
entityx/Entity.h
entityx/Entity_test.cc
examples/example.cc

index b450c184de53d26e7e2a55f008850e69a3bf49a4..90057da69c2c67086941a1c6c8a6f6ce04f8377c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -147,9 +147,8 @@ To query all entities with a set of components assigned you can use two
 methods. Both methods will return only those entities that have *all* of the
 specified components associated with them.
 
-`entityx::EntityManager::each(f) provides functional-style iteration over
-`entity components. The callback for `each()` can optionally accept an Entity as
-`its first argument.
+`entityx::EntityManager::each(f)` provides functional-style iteration over
+entity components:
 
 ```c++
 entities.each<Position, Direction>([](Entity entity, Position &position, Direction &direction) {
@@ -205,7 +204,7 @@ A basic movement system might be implemented with something like the following:
 ```c++
 struct MovementSystem : public System<MovementSystem> {
   void update(entityx::EntityManager &es, entityx::EventManager &events, TimeDelta dt) override {
-    es.each<Position, Direction>([dt](Position &position, Direction &direction) {
+    es.each<Position, Direction>([dt](Entity entity, Position &position, Direction &direction) {
       position.x += direction.x * dt;
       position.y += direction.y * dt;
     });
index 9f44106831c64517354d3129866130075bbff3f2..0565f9c98805b1e9c8851a7e3f935cb0b56cf9f7 100644 (file)
@@ -433,11 +433,6 @@ class EntityManager : entityx::help::NonCopyable {
   public:
     template <typename T> struct identity { typedef T type; };
 
-    void each(typename identity<std::function<void(Components&...)>>::type f) {
-      for (auto it : *this)
-        f(*(it.template component<Components>().get())...);
-    }
-
     void each(typename identity<std::function<void(Entity entity, Components&...)>>::type f) {
       for (auto it : *this)
         f(it, *(it.template component<Components>().get())...);
@@ -720,11 +715,6 @@ class EntityManager : entityx::help::NonCopyable {
 
   template <typename T> struct identity { typedef T type; };
 
-  template <typename ... Components>
-  void each(typename identity<std::function<void(Components&...)>>::type f) {
-    return entities_with_components<Components...>().each(f);
-  }
-
   template <typename ... Components>
   void each(typename identity<std::function<void(Entity entity, Components&...)>>::type f) {
     return entities_with_components<Components...>().each(f);
index a79becb50c369b074b536a400df5b186ce0f525a..2076ed7951a08bbb701231bb896e443395c79bdd 100644 (file)
@@ -609,7 +609,7 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestEntityManagerEach") {
   Entity a = em.create();
   a.assign<Position>(1, 2);
   int count = 0;
-  em.each<Position>([&count](Position &position) {
+  em.each<Position>([&count](Entity entity, Position &position) {
     count++;
     REQUIRE(position.x == 1);
     REQUIRE(position.y == 2);
@@ -618,18 +618,6 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestEntityManagerEach") {
 }
 
 TEST_CASE_METHOD(EntityManagerFixture, "TestViewEach") {
-  Entity a = em.create();
-  a.assign<Position>(1, 2);
-  int count = 0;
-  em.entities_with_components<Position>().each([&count](Position &position) {
-    count++;
-    REQUIRE(position.x == 1);
-    REQUIRE(position.y == 2);
-  });
-  REQUIRE(count == 1);
-}
-
-TEST_CASE_METHOD(EntityManagerFixture, "TestViewEachWithEntity") {
   Entity a = em.create();
   a.assign<Position>(1, 2);
   int count = 0;
@@ -637,7 +625,6 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestViewEachWithEntity") {
     count++;
     REQUIRE(position.x == 1);
     REQUIRE(position.y == 2);
-    REQUIRE(*entity.component<Position>().get() == position);
   });
   REQUIRE(count == 1);
 }
index 7474f7f139a1272b162aba629bc36961804f1a95..bd049ba1eac31d40caa5aa4f01d5d0183cf01249 100644 (file)
@@ -87,7 +87,7 @@ public:
   void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
     int c = 0;
     ex::ComponentHandle<Collideable> collideable;
-    es.each<Collideable>([&](Collideable&) { ++c; });
+    es.each<Collideable>([&](ex::Entity entity, Collideable&) { ++c; });
 
     for (int i = 0; i < count - c; i++) {
       ex::Entity entity = es.create();
@@ -117,7 +117,7 @@ private:
 // Updates a body's position and rotation.
 struct BodySystem : public ex::System<BodySystem> {
   void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
-    es.each<Body>([dt](Body &body) {
+    es.each<Body>([dt](ex::Entity entity, Body &body) {
       body.position += body.direction * static_cast<float>(dt);
       body.rotation += body.rotationd * dt;
     });
@@ -131,7 +131,7 @@ public:
   explicit BounceSystem(sf::RenderTarget &target) : size(target.getSize()) {}
 
   void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
-    es.each<Body>([this](Body &body) {
+    es.each<Body>([this](ex::Entity entity, Body &body) {
       if (body.position.x + body.direction.x < 0 ||
           body.position.x + body.direction.x >= size.x)
         body.direction.x = -body.direction.x;
@@ -246,7 +246,7 @@ public:
 
   void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
     sf::VertexArray vertices(sf::Quads);
-    es.each<Particle, Body>([&vertices](Particle &particle, Body &body) {
+    es.each<Particle, Body>([&vertices](ex::Entity entity, Particle &particle, Body &body) {
       const float r = particle.radius;
       vertices.append(sf::Vertex(body.position + sf::Vector2f(-r, -r), particle.colour));
       vertices.append(sf::Vertex(body.position + sf::Vector2f(r, -r), particle.colour));
@@ -324,7 +324,7 @@ public:
   }
 
   void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
-    es.each<Body, Renderable>([this](Body &body, Renderable &renderable) {
+    es.each<Body, Renderable>([this](ex::Entity entity, Body &body, Renderable &renderable) {
       renderable.shape->setPosition(body.position);
       renderable.shape->setRotation(body.rotation);
       target.draw(*renderable.shape.get());