BaseSystem::~BaseSystem() {
}
+void SystemManager::updateAll(TimeDelta dt) {
+ assert(initialized_ && "SystemManager::configure() not called");
+ for (auto &pair : systems_) {
+ pair.second->update(entity_manager_, event_manager_, dt);
+ }
+}
+
void SystemManager::configure() {
for (auto &pair : systems_) {
pair.second->configure(event_manager_);
float x, y;
};
+struct Counter : Component<Counter> {
+ explicit Counter(int counter = 0) : counter(counter) {}
+
+ int counter;
+};
+
class MovementSystem : public System<MovementSystem> {
public:
explicit MovementSystem(string label = "") : label(label) {}
string label;
};
+class CounterSystem : public System<CounterSystem> {
+public:
+ void update(EntityManager &es, EventManager &events, TimeDelta) override {
+ EntityManager::View entities =
+ es.entities_with_components<Counter>();
+ Counter::Handle counter;
+ for (auto entity : entities) {
+ entity.unpack<Counter>(counter);
+ counter->counter++;
+ }
+ }
+};
+
class EntitiesFixture : public EntityX {
public:
std::vector<Entity> created_entities;
created_entities.push_back(e);
if (i % 2 == 0) e.assign<Position>(1, 2);
if (i % 3 == 0) e.assign<Direction>(1, 1);
+
+ e.assign<Counter>(0);
}
}
};
}
}
}
+
+TEST_CASE_METHOD(EntitiesFixture, "TestApplyAllSystems") {
+ systems.add<MovementSystem>();
+ systems.add<CounterSystem>();
+ systems.configure();
+
+ systems.updateAll(0.0);
+ Position::Handle position;
+ Direction::Handle direction;
+ Counter::Handle counter;
+ for (auto entity : created_entities) {
+ entity.unpack<Position, Direction, Counter>(position, direction, counter);
+ if (position && direction) {
+ REQUIRE(2.0 == Approx(position->x));
+ REQUIRE(3.0 == Approx(position->y));
+ } else if (position) {
+ REQUIRE(1.0 == Approx(position->x));
+ REQUIRE(2.0 == Approx(position->y));
+ }
+ REQUIRE(1 == counter->counter);
+ }
+}