#include "dinkyecs.hpp" #include #include using namespace fmt; using DinkyECS::Entity, DinkyECS::World; struct Position { double x, y; }; struct Velocity { double x, y; }; struct Gravity { double level; }; int main() { World me; Entity test = me.entity(); Entity test2 = me.entity(); me.assign(test, {10,20}); me.assign(test, {1,2}); me.assign(test2, {1,1}); me.assign(test2, {10,20}); Position &pos = me.component(test); println("GOT POS x={}, y={}", pos.x, pos.y); Velocity &vel = me.component(test); println("GOT VELOCITY x={}, y={}", vel.x, vel.y); println("--- Position only system:"); me.system([](const auto &ent, auto &pos) { println("entity={}, pos.x={}, pos.y={}", ent, pos.x, pos.y); }); println("--- Velocity only system:"); me.system([](const auto &, auto &vel) { println("vel.x={}, vel.y={}", vel.x, vel.y); }); println("--- Manually get the velocity in position system:"); me.system([&](const auto &ent, auto &pos) { Velocity &vel = me.component(ent); println("entity={}, vel.x, vel.y, pos.x={}, pos.y={}", ent, vel.x, vel.y, pos.x, pos.y); }); println("--- Creating facts (singletons)"); me.set({0.9}); println("--- Query only entities with Position and Velocity:"); me.system([&](const auto &ent, auto &pos, auto &vel) { Gravity &grav = me.get(); println("grav={}, entity={}, vel.x, vel.y, pos.x={}, pos.y={}", grav.level, ent, vel.x, vel.y, pos.x, pos.y); }); // now remove Velocity me.remove(test); println("--- After remove test, should only result in test2:"); me.system([&](const auto &ent, auto &pos, auto &vel) { println("entity={}, vel.x, vel.y, pos.x={}, pos.y={}", ent, vel.x, vel.y, pos.x, pos.y); }); println("--- Create a stored system you can save for later."); auto movementSystem = me.runner([&](const auto &ent, auto &pos, auto &vel) { println("entity={}, vel.x, vel.y, pos.x={}, pos.y={}", ent, vel.x, vel.y, pos.x, pos.y); }); movementSystem(); return 0; }