diff --git a/.idea/ecsgame.iml b/.idea/ecsgame.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/ecsgame.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8822db8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..26103e7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6fbf53f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.15) +project(ecsgame) + +set(CMAKE_CXX_STANDARD 17) + +add_executable(ecsgame main.cpp) \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..4226a0c --- /dev/null +++ b/main.cpp @@ -0,0 +1,50 @@ +#include +#include "ECS.h" + +using namespace ECS; + +struct Position +{ + Position(float x, float y, float z) : x(x), y(y), z(z) {} + Position() : x(0.f), y(0.f), z(0.f) {} + + float x; + float y; + float z; +}; + +class GravitySystem : public EntitySystem +{ +public: + GravitySystem(float amount) + { + gravityAmount = amount; + } + + virtual ~GravitySystem() {} + + virtual void tick(World* world, float deltaTime) override + { + world->each([&](Entity* ent, ComponentHandle position) { + position->y += gravityAmount * deltaTime; + }); + } + +private: + float gravityAmount; +}; + +int main() { + World* world = World::createWorld(); + world->registerSystem(new GravitySystem(-9.8f)); + + Entity* ent = world->create(); + ent->assign(0.f, 0.f, 0.f); // assign() takes arguments and passes them to the constructor + + world->tick(1.0f); + + ComponentHandle pos = ent->get(); + + std::cout << "y position after tick: " << pos->y << std::endl; + return 0; +}