-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aea81e2
commit 07e6f8b
Showing
5 changed files
with
21 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |