From a7535d87a738157cfdfd30177828ae87c26ccaaa Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Sat, 18 Jul 2015 21:22:10 -0400 Subject: Remove ambiguity that old compilers can't resolve. --- README.md | 7 +++---- entityx/Entity.h | 10 ---------- entityx/Entity_test.cc | 15 +-------------- examples/example.cc | 10 +++++----- 4 files changed, 9 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index b450c18..90057da 100644 --- 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([](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 { void update(entityx::EntityManager &es, entityx::EventManager &events, TimeDelta dt) override { - es.each([dt](Position &position, Direction &direction) { + es.each([dt](Entity entity, Position &position, Direction &direction) { position.x += direction.x * dt; position.y += direction.y * dt; }); diff --git a/entityx/Entity.h b/entityx/Entity.h index 9f44106..0565f9c 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -433,11 +433,6 @@ class EntityManager : entityx::help::NonCopyable { public: template struct identity { typedef T type; }; - void each(typename identity>::type f) { - for (auto it : *this) - f(*(it.template component().get())...); - } - void each(typename identity>::type f) { for (auto it : *this) f(it, *(it.template component().get())...); @@ -720,11 +715,6 @@ class EntityManager : entityx::help::NonCopyable { template struct identity { typedef T type; }; - template - void each(typename identity>::type f) { - return entities_with_components().each(f); - } - template void each(typename identity>::type f) { return entities_with_components().each(f); diff --git a/entityx/Entity_test.cc b/entityx/Entity_test.cc index a79becb..2076ed7 100644 --- a/entityx/Entity_test.cc +++ b/entityx/Entity_test.cc @@ -609,7 +609,7 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestEntityManagerEach") { Entity a = em.create(); a.assign(1, 2); int count = 0; - em.each([&count](Position &position) { + em.each([&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(1, 2); - int count = 0; - em.entities_with_components().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(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().get() == position); }); REQUIRE(count == 1); } diff --git a/examples/example.cc b/examples/example.cc index 7474f7f..bd049ba 100644 --- a/examples/example.cc +++ b/examples/example.cc @@ -87,7 +87,7 @@ public: void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override { int c = 0; ex::ComponentHandle collideable; - es.each([&](Collideable&) { ++c; }); + es.each([&](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 { void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override { - es.each([dt](Body &body) { + es.each([dt](ex::Entity entity, Body &body) { body.position += body.direction * static_cast(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([this](Body &body) { + es.each([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([&vertices](Particle &particle, Body &body) { + es.each([&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([this](Body &body, Renderable &renderable) { + es.each([this](ex::Entity entity, Body &body, Renderable &renderable) { renderable.shape->setPosition(body.position); renderable.shape->setRotation(body.rotation); target.draw(*renderable.shape.get()); -- cgit v1.2.3