From beaa71168b2e12a5ea93278d6864fd4b929e2607 Mon Sep 17 00:00:00 2001 From: Michael Malura Date: Wed, 20 Jun 2018 19:33:43 +0200 Subject: [PATCH 1/2] Make projekt cmake compatible --- CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..606e6aa --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.11) + +project(entity VERSION 1.0.0 LANGUAGES CXX) + +add_library(entity + entity/world.cpp + entity/system.cpp + entity/event.cpp + entity/entity.cpp + entity/component.cpp +) + +target_compile_features(entity PRIVATE cxx_std_17) + +target_include_directories(entity + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) From e55eddf7f20b2eb19098506341936d486c8704d7 Mon Sep 17 00:00:00 2001 From: Michael Malura Date: Wed, 20 Jun 2018 19:37:30 +0200 Subject: [PATCH 2/2] Fix typo in readme and example --- README.md | 4 ++-- example.cpp | 58 +++++++++++++++++++++++++++-------------------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 5de92f9..198b77e 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,8 @@ public: for (auto e : GetEntities()) { auto &position = e.GetComponent(); const auto &velocity = e.GetComponent(); - position.x += velocity.x; - position.y += velocity.y; + position.x += velocity.dx; + position.y += velocity.dy; } } }; diff --git a/example.cpp b/example.cpp index 1748618..bafb5d4 100644 --- a/example.cpp +++ b/example.cpp @@ -4,50 +4,52 @@ using namespace entity; struct PositionComponent { - PositionComponent(int x = 0, int y = 0) : x(x), y(y) {} - int x, y; + PositionComponent(int x = 0, int y = 0) : x(x), y(y) {} + int x, y; }; struct VelocityComponent { - VelocityComponent(int dx = 0, int dy = 0) : dx(dx), dy(dy) {} - int dx, dy; + VelocityComponent(int dx = 0, int dy = 0) : dx(dx), dy(dy) {} + int dx, dy; }; class MoveSystem : public System { public: - MoveSystem() - { - RequireComponent(); - RequireComponent(); - } + MoveSystem() + { + RequireComponent(); + RequireComponent(); + } - void Update() + void Update() + { + for (auto e : GetEntities()) { - for (auto e : GetEntities()) { - auto &position = e.GetComponent(); - const auto velocity = e.GetComponent(); - position.x += velocity.x; - position.y += velocity.y; - } + auto &position = e.GetComponent(); + const auto velocity = e.GetComponent(); + position.x += velocity.dx; + position.y += velocity.dy; } + } }; int main() { - World world; - auto e = world.CreateEntity(); - e.AddComponent(100, 100); - e.AddComponent(10, 10); - world.GetSystemManager().AddSystem(); + World world; + auto e = world.CreateEntity(); + e.AddComponent(100, 100); + e.AddComponent(10, 10); + world.GetSystemManager().AddSystem(); - for (int i = 0; i < 10; i++) { - world.Update(); - world.GetSystemManager().GetSystem().Update(); - auto &position = e.GetComponent(); - std::cout << "x: " << position.x << ", y: " << position.y << std::endl; - } + for (int i = 0; i < 10; i++) + { + world.Update(); + world.GetSystemManager().GetSystem().Update(); + auto &position = e.GetComponent(); + std::cout << "x: " << position.x << ", y: " << position.y << std::endl; + } - return 0; + return 0; }