diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fdc4f5..0a7699f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,7 +54,7 @@ jobs: working-directory: ${{ github.workspace }}/build - name: Configure CMake - run: cmake .. -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=20 -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES="conan_provider.cmake" -DCMAKE_BUILD_TYPE=Release + run: cmake .. -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=20 -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES="conan_provider.cmake" -DCMAKE_BUILD_TYPE=Debug working-directory: ${{ github.workspace }}/build - name: Build diff --git a/include/Component.h b/include/Component.h index a73eebd..6999f62 100644 --- a/include/Component.h +++ b/include/Component.h @@ -6,8 +6,7 @@ #define COMPONENT_H #include -#include -#include + #include "components/Position.h" #include "components/Velocity.h" diff --git a/include/ComponentManager.h b/include/ComponentManager.h index 2f2614c..f54c04e 100644 --- a/include/ComponentManager.h +++ b/include/ComponentManager.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "Entity.h" #include "Component.h" diff --git a/include/ComponentManager.tpp b/include/ComponentManager.tpp index c9960a6..fecdde5 100644 --- a/include/ComponentManager.tpp +++ b/include/ComponentManager.tpp @@ -1,8 +1,5 @@ // ComponentManager.tpp -#include -#include - template void ComponentManager::addComponent(const Entity::Id entityId, T component) { componentMaps[entityId][typeid(T)] = std::make_unique>(std::move(component)); diff --git a/main.cpp b/main.cpp index 9952b9c..7531c83 100644 --- a/main.cpp +++ b/main.cpp @@ -1,64 +1,30 @@ -#include - -#include "ComponentManager.h" +#include "Coordinator.h" #include "MovementSystem.h" #include "components/Position.h" #include "components/Velocity.h" +#include -int main() { - EntityManager entityManager; - // MovementSystem movementSystem(entityManager); - - Entity::Id e1 = entityManager.createEntity(); - Entity::Id e2 = entityManager.createEntity(); - - entityManager.addComponent(e1, Position{0.0f, 0.0f}); - entityManager.addComponent(e1, Velocity{1.0f, 1.0f}); - - entityManager.addComponent(e2, Position{10.0f, 10.0f}); - entityManager.addComponent(e2, Velocity{0.5f, -0.5f}); - - // Output initial positions - if (entityManager.hasComponent(e1)) { - const auto& pos = entityManager.getComponent(e1); - std::cout << "Entity 1 Position: (" << pos.x << ", " << pos.y << ")\n"; - } - - if (entityManager.hasComponent(e2)) { - const auto& pos = entityManager.getComponent(e2); - std::cout << "Entity 2 Position: (" << pos.x << ", " << pos.y << ")\n"; - } - - // - // - // // Update movement system to move entities - // movementSystem.update(); - // Output updated positions - if (entityManager.hasComponent(e1)) { - const auto& pos = entityManager.getComponent(e1); - std::cout << "Entity 1 Position: (" << pos.x << ", " << pos.y << ")\n"; - } +int main() { + Coordinator coordinator; + coordinator.init(); - if (entityManager.hasComponent(e2)) { - const auto& pos = entityManager.getComponent(e2); - std::cout << "Entity 2 Position: (" << pos.x << ", " << pos.y << ")\n"; - } + const Entity::Id entityId = coordinator.createEntity(); + coordinator.addComponent(entityId, {1.0f, 2.0f}); + coordinator.addComponent(entityId, {1.0f, 2.0f}); - // Destroy an entity - entityManager.destroyEntity(e1); + MovementSystem::QueryFunction movementQuery = coordinator.getComponentQuery(); + auto movementSystem = coordinator.registerSystem(movementQuery); - // Check if entity 1 is valid - if (!entityManager.isValid(e1)) { - std::cout << "Entity 1 has been destroyed.\n"; - } + auto& position = coordinator.getComponent(entityId); + std::cout << "Initial Entity position: (" << position.x << ", " << position.y << ")\n"; - // Attempt to access a component of the destroyed entity (should throw an error) - try { - entityManager.getComponent(e1); - } catch (const std::exception& e) { - std::cout << e.what() << std::endl; // Output: Attempted to get a component from an invalid entity. + // Simulate game loop + for (int i = 0; i < 10; ++i) { + movementSystem->update(); + auto& position = coordinator.getComponent(entityId); + std::cout << "Entity position after update " << i << ": (" << position.x << ", " << position.y << ")\n"; } return 0; -} +} \ No newline at end of file