Skip to content

Commit

Permalink
CI - wip6 switch to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
tristankpka committed Jul 22, 2024
1 parent aea81e2 commit 07e6f8b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#define COMPONENT_H

#include <type_traits>
#include <cstdint>
#include <variant>


#include "components/Position.h"
#include "components/Velocity.h"
Expand Down
1 change: 1 addition & 0 deletions include/ComponentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <array>
#include <cstdint>
#include <typeindex>
#include <variant>

#include "Entity.h"
#include "Component.h"
Expand Down
3 changes: 0 additions & 3 deletions include/ComponentManager.tpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// ComponentManager.tpp

#include <typeinfo>
#include <variant>

template<ComponentType T>
void ComponentManager::addComponent(const Entity::Id entityId, T component) {
componentMaps[entityId][typeid(T)] = std::make_unique<Component<T>>(std::move(component));
Expand Down
70 changes: 18 additions & 52 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,64 +1,30 @@
#include <iostream>

#include "ComponentManager.h"
#include "Coordinator.h"
#include "MovementSystem.h"
#include "components/Position.h"
#include "components/Velocity.h"
#include <iostream>

int main() {
EntityManager entityManager;
// MovementSystem movementSystem(entityManager);

Entity::Id e1 = entityManager.createEntity();
Entity::Id e2 = entityManager.createEntity();

entityManager.addComponent<Position>(e1, Position{0.0f, 0.0f});
entityManager.addComponent<Velocity>(e1, Velocity{1.0f, 1.0f});

entityManager.addComponent<Position>(e2, Position{10.0f, 10.0f});
entityManager.addComponent<Velocity>(e2, Velocity{0.5f, -0.5f});

// Output initial positions
if (entityManager.hasComponent<Position>(e1)) {
const auto& pos = entityManager.getComponent<Position>(e1);
std::cout << "Entity 1 Position: (" << pos.x << ", " << pos.y << ")\n";
}

if (entityManager.hasComponent<Position>(e2)) {
const auto& pos = entityManager.getComponent<Position>(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<Position>(e1)) {
const auto& pos = entityManager.getComponent<Position>(e1);
std::cout << "Entity 1 Position: (" << pos.x << ", " << pos.y << ")\n";
}
int main() {
Coordinator coordinator;
coordinator.init();

if (entityManager.hasComponent<Position>(e2)) {
const auto& pos = entityManager.getComponent<Position>(e2);
std::cout << "Entity 2 Position: (" << pos.x << ", " << pos.y << ")\n";
}
const Entity::Id entityId = coordinator.createEntity();
coordinator.addComponent<Position>(entityId, {1.0f, 2.0f});
coordinator.addComponent<Velocity>(entityId, {1.0f, 2.0f});

// Destroy an entity
entityManager.destroyEntity(e1);
MovementSystem::QueryFunction movementQuery = coordinator.getComponentQuery<Position, Velocity>();
auto movementSystem = coordinator.registerSystem<MovementSystem>(movementQuery);

// Check if entity 1 is valid
if (!entityManager.isValid(e1)) {
std::cout << "Entity 1 has been destroyed.\n";
}
auto& position = coordinator.getComponent<Position>(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<Position>(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<Position>(entityId);
std::cout << "Entity position after update " << i << ": (" << position.x << ", " << position.y << ")\n";
}

return 0;
}
}

0 comments on commit 07e6f8b

Please sign in to comment.