Line |
Branch |
Exec |
Source |
1 |
|
|
#include <iostream> |
2 |
|
|
#include <ECS/ECS.hpp> |
3 |
|
|
|
4 |
|
|
// Example components for demonstration |
5 |
|
|
class Position : public ECS::Component<Position> { |
6 |
|
|
public: |
7 |
|
|
float x, y; |
8 |
|
✗ |
Position(float x = 0.0f, float y = 0.0f) : x(x), y(y) {} |
9 |
|
|
}; |
10 |
|
|
|
11 |
|
|
class Velocity : public ECS::Component<Velocity> { |
12 |
|
|
public: |
13 |
|
|
float vx, vy; |
14 |
|
✗ |
Velocity(float vx = 0.0f, float vy = 0.0f) : vx(vx), vy(vy) {} |
15 |
|
|
}; |
16 |
|
|
|
17 |
|
|
class Health : public ECS::Component<Health> { |
18 |
|
|
public: |
19 |
|
|
int hp; |
20 |
|
✗ |
Health(int hp = 100) : hp(hp) {} |
21 |
|
|
}; |
22 |
|
|
|
23 |
|
✗ |
int main() { |
24 |
|
✗ |
std::cout << "Hello World from Server!" << std::endl; |
25 |
|
✗ |
std::cout << "Server is running..." << std::endl; |
26 |
|
|
|
27 |
|
|
// Demonstrate ECS library usage |
28 |
|
✗ |
std::cout << "\n=== ECS Library Demo (Server) ===" << std::endl; |
29 |
|
|
|
30 |
|
✗ |
ECS::World world; |
31 |
|
|
|
32 |
|
|
// Create some entities |
33 |
|
✗ |
auto player = world.CreateEntity(); |
34 |
|
✗ |
auto enemy1 = world.CreateEntity(); |
35 |
|
✗ |
auto enemy2 = world.CreateEntity(); |
36 |
|
|
|
37 |
|
✗ |
std::cout << "Created entities: Player(" << player << "), Enemy1(" << enemy1 << "), Enemy2(" << enemy2 << ")" << std::endl; |
38 |
|
|
|
39 |
|
|
// Add components to player |
40 |
|
✗ |
world.AddComponent<Position>(player, 10.0f, 20.0f); |
41 |
|
✗ |
world.AddComponent<Velocity>(player, 1.5f, 0.0f); |
42 |
|
✗ |
world.AddComponent<Health>(player, 100); |
43 |
|
|
|
44 |
|
|
// Add components to enemies |
45 |
|
✗ |
world.AddComponent<Position>(enemy1, 50.0f, 30.0f); |
46 |
|
✗ |
world.AddComponent<Health>(enemy1, 50); |
47 |
|
|
|
48 |
|
✗ |
world.AddComponent<Position>(enemy2, 75.0f, 45.0f); |
49 |
|
✗ |
world.AddComponent<Velocity>(enemy2, -1.0f, 0.5f); |
50 |
|
✗ |
world.AddComponent<Health>(enemy2, 75); |
51 |
|
|
|
52 |
|
✗ |
std::cout << "Added components to entities" << std::endl; |
53 |
|
|
|
54 |
|
|
// Query and display component data |
55 |
|
✗ |
if (auto pos = world.GetComponent<Position>(player)) { |
56 |
|
✗ |
std::cout << "Player position: (" << pos->x << ", " << pos->y << ")" << std::endl; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
✗ |
if (auto health = world.GetComponent<Health>(player)) { |
60 |
|
✗ |
std::cout << "Player health: " << health->hp << std::endl; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
// Demonstrate component queries |
64 |
|
✗ |
std::cout << "Player has Velocity: " << (world.HasComponent<Velocity>(player) ? "Yes" : "No") << std::endl; |
65 |
|
✗ |
std::cout << "Enemy1 has Velocity: " << (world.HasComponent<Velocity>(enemy1) ? "Yes" : "No") << std::endl; |
66 |
|
|
|
67 |
|
✗ |
std::cout << "Total alive entities: " << world.GetAliveEntityCount() << std::endl; |
68 |
|
|
|
69 |
|
✗ |
return 0; |
70 |
|
✗ |
} |
71 |
|
|
|