Line |
Branch |
Exec |
Source |
1 |
|
|
#include <iostream> |
2 |
|
|
#include <ECS/ECS.hpp> |
3 |
|
|
|
4 |
|
|
// Inclure les composants communs |
5 |
|
|
|
6 |
|
|
#include <common/components/Position.hpp> |
7 |
|
|
#include <common/components/Velocity.hpp> |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
// Inclure les composants spécifiques au client |
11 |
|
|
#include "client/components/client.hpp" |
12 |
|
|
//#include "components/render.hpp" |
13 |
|
|
//#include "components/camera.hpp" |
14 |
|
|
//#include "components/audio.hpp" |
15 |
|
|
|
16 |
|
|
// Inclure les systèmes client |
17 |
|
|
#include "client/components/systems/RenderSystem.hpp" |
18 |
|
|
#include "client/components/systems/InputSystem.hpp" |
19 |
|
|
|
20 |
|
✗ |
int main() { |
21 |
|
✗ |
std::cout << "Hello World from Client!" << std::endl; |
22 |
|
✗ |
std::cout << "Client is connecting..." << std::endl; |
23 |
|
|
|
24 |
|
|
// Démonstration ECS avec composants client/serveur |
25 |
|
✗ |
std::cout << "\n=== ECS Library Demo (Client avec composants partagés) ===" << std::endl; |
26 |
|
|
|
27 |
|
✗ |
ECS::World world; |
28 |
|
|
|
29 |
|
|
// Créer des entités |
30 |
|
✗ |
auto player = world.CreateEntity(); |
31 |
|
✗ |
auto enemy = world.CreateEntity(); |
32 |
|
✗ |
auto ui_element = world.CreateEntity(); |
33 |
|
|
|
34 |
|
✗ |
std::cout << "Created entities: Player(" << player << "), Enemy(" << enemy << "), UI(" << ui_element << ")" << std::endl; |
35 |
|
|
|
36 |
|
|
// Ajouter des composants communs (partagés avec le serveur) |
37 |
|
|
|
38 |
|
|
using rtype::common::components::Position; |
39 |
|
|
using rtype::common::components::Velocity; |
40 |
|
|
using rtype::client::components::Renderable; |
41 |
|
|
using rtype::client::components::RenderLayer; |
42 |
|
|
using rtype::client::components::Camera; |
43 |
|
|
using rtype::client::components::AudioSource; |
44 |
|
|
using rtype::client::components::AudioType; |
45 |
|
|
|
46 |
|
✗ |
world.AddComponent<Position>(player, 100.0f, 200.0f, 0.0f); |
47 |
|
✗ |
world.AddComponent<Velocity>(player, 0.0f, 0.0f, 250.0f); |
48 |
|
|
|
49 |
|
✗ |
world.AddComponent<Position>(enemy, 300.0f, 150.0f, 3.14f/2); |
50 |
|
✗ |
world.AddComponent<Velocity>(enemy, -50.0f, 0.0f, 100.0f); |
51 |
|
|
|
52 |
|
|
// Ajouter des composants spécifiques au client |
53 |
|
✗ |
world.AddComponent<Renderable>(player, "player.png", 64.0f, 64.0f, RenderLayer::Entities); |
54 |
|
✗ |
world.AddComponent<Renderable>(enemy, "enemy.png", 48.0f, 48.0f, RenderLayer::Entities); |
55 |
|
✗ |
world.AddComponent<Renderable>(ui_element, "health_bar.png", 200.0f, 20.0f, RenderLayer::UI); |
56 |
|
|
|
57 |
|
|
// Ajouter caméra |
58 |
|
✗ |
world.AddComponent<Camera>(world.CreateEntity(), 1.0f); |
59 |
|
|
|
60 |
|
|
// Ajouter son |
61 |
|
✗ |
world.AddComponent<AudioSource>(player, "player_move.wav", AudioType::SFX); |
62 |
|
|
|
63 |
|
✗ |
std::cout << "Added components to entities" << std::endl; |
64 |
|
|
|
65 |
|
|
// Simulation d'une boucle de jeu simplifiée |
66 |
|
✗ |
std::cout << "\n=== Simulation de boucle de jeu ===" << std::endl; |
67 |
|
|
|
68 |
|
✗ |
for (int frame = 0; frame < 5; ++frame) { |
69 |
|
✗ |
float deltaTime = 0.016f; // ~60 FPS |
70 |
|
|
|
71 |
|
✗ |
std::cout << "Frame " << frame << ":" << std::endl; |
72 |
|
|
|
73 |
|
|
// Système de mouvement (logique partagée client/serveur) |
74 |
|
✗ |
auto* positions = world.GetAllComponents<Position>(); |
75 |
|
✗ |
if (positions) { |
76 |
|
✗ |
for (const auto& pair : *positions) { |
77 |
|
✗ |
ECS::EntityID entity = pair.first; |
78 |
|
✗ |
auto* pos = pair.second.get(); |
79 |
|
✗ |
auto* vel = world.GetComponent<Velocity>(entity); |
80 |
|
|
|
81 |
|
✗ |
if (vel) { |
82 |
|
✗ |
pos->x += vel->vx * deltaTime; |
83 |
|
✗ |
pos->y += vel->vy * deltaTime; |
84 |
|
✗ |
std::cout << " Entity " << entity << " moved to (" << pos->x << ", " << pos->y << ")" << std::endl; |
85 |
|
|
} |
86 |
|
|
} |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
// Système de rendu (spécifique client) |
90 |
|
✗ |
auto* renderables = world.GetAllComponents<Renderable>(); |
91 |
|
✗ |
if (renderables) { |
92 |
|
✗ |
std::cout << " Rendering:" << std::endl; |
93 |
|
✗ |
for (const auto& pair : *renderables) { |
94 |
|
✗ |
ECS::EntityID entity = pair.first; |
95 |
|
✗ |
auto* renderable = pair.second.get(); |
96 |
|
✗ |
auto* pos = world.GetComponent<Position>(entity); |
97 |
|
|
|
98 |
|
✗ |
if (pos && renderable->visible) { |
99 |
|
✗ |
std::cout << " " << renderable->texturePath |
100 |
|
✗ |
<< " at (" << pos->x << ", " << pos->y << ") " |
101 |
|
✗ |
<< "layer=" << static_cast<int>(renderable->layer) << std::endl; |
102 |
|
|
} |
103 |
|
|
} |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
|
107 |
|
✗ |
std::cout << "\nTotal alive entities: " << world.GetAliveEntityCount() << std::endl; |
108 |
|
✗ |
return 0; |
109 |
|
✗ |
} |
110 |
|
|
|