aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlec Thomas <alec@swapoff.org>2014-10-27 12:57:11 +1100
committerAlec Thomas <alec@swapoff.org>2014-10-27 12:57:11 +1100
commitcb06961a67b1aaeedea3edd0f3b18aa88cb50b99 (patch)
tree6aaad1686388c1c83cd6488b6e73ee26e0e5886b
parentaa2c0b4722cfd43c0a148db6f0b0bcf2d5899bf6 (diff)
DeltaTime -> TimeDelta
-rw-r--r--README.md8
-rw-r--r--entityx/Entity.h29
-rw-r--r--entityx/Entity_test.cc13
-rw-r--r--entityx/System.h6
-rw-r--r--entityx/System_test.cc2
-rw-r--r--entityx/config.h.in2
-rw-r--r--entityx/deps/Dependencies.h2
-rw-r--r--examples/example.cc14
8 files changed, 59 insertions, 17 deletions
diff --git a/README.md b/README.md
index abeb76d..3a7ffd0 100644
--- a/README.md
+++ b/README.md
@@ -185,7 +185,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, DeltaTime dt) override {
+ void update(entityx::EntityManager &es, entityx::EventManager &events, TimeDelta dt) override {
Position::Handle position;
Direction::Handle direction;
for (Entity entity : es.entities_with_components(position, direction)) {
@@ -222,7 +222,7 @@ Next we implement our collision system, which emits ``Collision`` objects via an
```c++
class CollisionSystem : public System<CollisionSystem> {
public:
- void update(entityx::EntityManager &es, entityx::EventManager &events, DeltaTime dt) override {
+ void update(entityx::EntityManager &es, entityx::EventManager &events, TimeDelta dt) override {
Position::Handle left_position, right_position;
for (Entity left_entity : es.entities_with_components(left_position)) {
for (Entity right_entity : es.entities_with_components(right_position)) {
@@ -245,7 +245,7 @@ struct DebugSystem : public System<DebugSystem>, Receiver<DebugSystem> {
event_manager.subscribe<Collision>(*this);
}
- void update(entityx::EntityManager &entities, entityx::EventManager &events, DeltaTime dt) {}
+ void update(entityx::EntityManager &entities, entityx::EventManager &events, TimeDelta dt) {}
void receive(const Collision &collision) {
LOG(DEBUG) << "entities collided: " << collision.left << " and " << collision.right << endl;
@@ -301,7 +301,7 @@ public:
}
}
- void update(DeltaTime dt) {
+ void update(TimeDelta dt) {
systems.update<DebugSystem>(dt);
systems.update<MovementSystem>(dt);
systems.update<CollisionSystem>(dt);
diff --git a/entityx/Entity.h b/entityx/Entity.h
index 1410bd8..ce5d2fb 100644
--- a/entityx/Entity.h
+++ b/entityx/Entity.h
@@ -144,6 +144,12 @@ public:
template <typename C>
const ComponentHandle<const C> component() const;
+ template <typename ... Components>
+ std::tuple<ComponentHandle<Components>...> components();
+
+ template <typename ... Components>
+ std::tuple<ComponentHandle<const Components>...> components() const;
+
template <typename C>
bool has_component() const;
@@ -658,6 +664,16 @@ class EntityManager : entityx::help::NonCopyable {
return ComponentHandle<const C>(this, id);
}
+ template <typename ... Components>
+ std::tuple<ComponentHandle<Components>...> components(Entity::Id id) {
+ return std::make_tuple(component<Components>(id)...);
+ }
+
+ template <typename ... Components>
+ std::tuple<ComponentHandle<const Components>...> components(Entity::Id id) const {
+ return std::make_tuple(component<const Components>(id)...);
+ }
+
/**
* Find Entities that have all of the specified Components.
*
@@ -866,6 +882,19 @@ const ComponentHandle<const C> Entity::component() const {
return manager_->component<const C>(id_);
}
+template <typename ... Components>
+std::tuple<ComponentHandle<Components>...> Entity::components() {
+ assert(valid());
+ return manager_->components<Components...>(id_);
+}
+
+template <typename ... Components>
+std::tuple<ComponentHandle<const Components>...> Entity::components() const {
+ assert(valid());
+ return manager_->components<const Components...>(id_);
+}
+
+
template <typename C>
bool Entity::has_component() const {
assert(valid());
diff --git a/entityx/Entity_test.cc b/entityx/Entity_test.cc
index cd7b2a1..9872116 100644
--- a/entityx/Entity_test.cc
+++ b/entityx/Entity_test.cc
@@ -520,6 +520,19 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestEntityInStdMap") {
REQUIRE(entityMap[c] == 3);
}
+TEST_CASE_METHOD(EntityManagerFixture, "TestEntityComponentsFromTuple") {
+ Entity e = em.create();
+ e.assign<Position>(1, 2);
+ e.assign<Direction>(3, 4);
+
+ std::tuple<Position::Handle, Direction::Handle> components = e.components<Position, Direction>();
+
+ REQUIRE(std::get<0>(components)->x == 1);
+ REQUIRE(std::get<0>(components)->y == 2);
+ REQUIRE(std::get<1>(components)->x == 3);
+ REQUIRE(std::get<1>(components)->y == 4);
+}
+
TEST_CASE("TestComponentDestructorCalledWhenManagerDestroyed") {
struct Freed {
explicit Freed(bool &yes) : yes(yes) {}
diff --git a/entityx/System.h b/entityx/System.h
index 076bb33..0f56215 100644
--- a/entityx/System.h
+++ b/entityx/System.h
@@ -48,7 +48,7 @@ class BaseSystem : entityx::help::NonCopyable {
*
* Called every game step.
*/
- virtual void update(EntityManager &entities, EventManager &events, DeltaTime dt) = 0;
+ virtual void update(EntityManager &entities, EventManager &events, TimeDelta dt) = 0;
static Family family_counter_;
@@ -60,7 +60,7 @@ class BaseSystem : entityx::help::NonCopyable {
* Use this class when implementing Systems.
*
* struct MovementSystem : public System<MovementSystem> {
- * void update(EntityManager &entities, EventManager &events, DeltaTime dt) {
+ * void update(EntityManager &entities, EventManager &events, TimeDelta dt) {
* // Do stuff to/with entities...
* }
* }
@@ -136,7 +136,7 @@ class SystemManager : entityx::help::NonCopyable {
* Call the System::update() method for a registered system.
*/
template <typename S>
- void update(DeltaTime dt) {
+ void update(TimeDelta dt) {
assert(initialized_ && "SystemManager::configure() not called");
std::shared_ptr<S> s = system<S>();
s->update(entity_manager_, event_manager_, dt);
diff --git a/entityx/System_test.cc b/entityx/System_test.cc
index 5c8fb42..312a733 100644
--- a/entityx/System_test.cc
+++ b/entityx/System_test.cc
@@ -36,7 +36,7 @@ class MovementSystem : public System<MovementSystem> {
public:
explicit MovementSystem(string label = "") : label(label) {}
- void update(EntityManager &es, EventManager &events, DeltaTime) override {
+ void update(EntityManager &es, EventManager &events, TimeDelta) override {
EntityManager::View entities =
es.entities_with_components<Position, Direction>();
ComponentHandle<Position> position;
diff --git a/entityx/config.h.in b/entityx/config.h.in
index 42e1418..a46fc24 100644
--- a/entityx/config.h.in
+++ b/entityx/config.h.in
@@ -6,6 +6,6 @@
namespace entityx {
static const size_t MAX_COMPONENTS = @ENTITYX_MAX_COMPONENTS@;
-typedef @ENTITYX_DT_TYPE@ DeltaTime;
+typedef @ENTITYX_DT_TYPE@ TimeDelta;
} // namespace entityx
diff --git a/entityx/deps/Dependencies.h b/entityx/deps/Dependencies.h
index 4f9883b..b1fb93c 100644
--- a/entityx/deps/Dependencies.h
+++ b/entityx/deps/Dependencies.h
@@ -35,7 +35,7 @@ public:
events.subscribe<ComponentAddedEvent<C>>(*this);
}
- virtual void update(EntityManager &entities, EventManager &events, DeltaTime dt) override {}
+ virtual void update(EntityManager &entities, EventManager &events, TimeDelta dt) override {}
private:
template <typename D>
diff --git a/examples/example.cc b/examples/example.cc
index 6cf75d4..582e324 100644
--- a/examples/example.cc
+++ b/examples/example.cc
@@ -86,7 +86,7 @@ struct CollisionEvent : public ex::Event<CollisionEvent> {
// Updates a body's position and rotation.
struct BodySystem : public ex::System<BodySystem> {
- void update(ex::EntityManager &es, ex::EventManager &events, ex::DeltaTime dt) override {
+ void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
Body::Handle body;
for (ex::Entity entity : es.entities_with_components(body)) {
body->position += body->direction * static_cast<float>(dt);
@@ -99,7 +99,7 @@ struct BodySystem : public ex::System<BodySystem> {
// Fades out the alpha value of any Renderable and Fadeable entity. Once the
// object has completely faded out it is destroyed.
struct FadeOutSystem : public ex::System<FadeOutSystem> {
- void update(ex::EntityManager &es, ex::EventManager &events, ex::DeltaTime dt) override {
+ void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
Fadeable::Handle fade;
Renderable::Handle renderable;
for (ex::Entity entity : es.entities_with_components(fade, renderable)) {
@@ -121,7 +121,7 @@ class BounceSystem : public ex::System<BounceSystem> {
public:
explicit BounceSystem(sf::RenderTarget &target) : size(target.getSize()) {}
- void update(ex::EntityManager &es, ex::EventManager &events, ex::DeltaTime dt) override {
+ void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
Body::Handle body;
for (ex::Entity entity : es.entities_with_components(body)) {
if (body->position.x + body->direction.x < 0 ||
@@ -159,7 +159,7 @@ class CollisionSystem : public ex::System<CollisionSystem> {
size.y = size.y / PARTITIONS + 1;
}
- void update(ex::EntityManager &es, ex::EventManager &events, ex::DeltaTime dt) override {
+ void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
reset();
collect(es);
collide(events);
@@ -226,7 +226,7 @@ public:
events.subscribe<CollisionEvent>(*this);
}
- void update(ex::EntityManager &es, ex::EventManager &events, ex::DeltaTime dt) override {
+ void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
for (ex::Entity entity : collided) {
emit_particles(es, entity);
entity.destroy();
@@ -285,7 +285,7 @@ public:
text.setColor(sf::Color::White);
}
- void update(ex::EntityManager &es, ex::EventManager &events, ex::DeltaTime dt) override {
+ void update(ex::EntityManager &es, ex::EventManager &events, ex::TimeDelta dt) override {
Body::Handle body;
Renderable::Handle renderable;
for (ex::Entity entity : es.entities_with_components(body, renderable)) {
@@ -341,7 +341,7 @@ public:
}
}
- void update(ex::DeltaTime dt) {
+ void update(ex::TimeDelta dt) {
systems.update<BodySystem>(dt);
systems.update<FadeOutSystem>(dt);
systems.update<BounceSystem>(dt);