My Project
Client.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** B-CPP-500-PAR-5-1-rtype-martin.vanaud
4 ** File description:
5 ** Client
6 */
7 
8 #ifndef CLIENT_HPP_
9  #define CLIENT_HPP_
10 
11  #if defined(_WIN32)
12  #define NOGDI // All GDI defines and routines
13  #define NOUSER// All USER defines and routines
14  #endif
15  #define CLIENT_HPP_
16 
17  #include <thread>
18 
19  #include "UdpCommunication.hpp"
20 
21  /* System */
22  #include "System/NetworkSystem/NetworkSystem.hpp"
23  #include "System/DrawTextSystem/DrawTextSystem.hpp"
24  #include "System/DrawSpriteSystem/DrawSpriteSystem.hpp"
25  #include "System/EndGameSystem/EndGameSystem.hpp"
26  #include "System/RectSystem/RectSystem.hpp"
27  #include "System/ControlSystem/ControlSystem.hpp"
28  #include "System/NewEntitySystem/NewEntitySystem.hpp"
29  #include "System/ParallaxSystem/ParallaxSystem.hpp"
30  #include "System/PositionSystem/PositionSystem.hpp"
31  #include "System/MoveSystem/MoveSystem.hpp"
32  #include "System/KillSystem/KillSystem.hpp"
33  #include "System/GetInfoInLobbySystem/GetInfoInLobbySystem.hpp"
34  #include "System/KillEntityTypeSystem/KillEntityTypeSystem.hpp"
35  #include "System/GetInfoInLobbySystem/GetInfoInLobbySystem.hpp"
36  #include "System/GetLobbiesSystem/GetLobbiesSystem.hpp"
37  #include "System/SetNbPlayerInLobbySystem/SetNbPlayerInLobbySystem.hpp"
38  #include "System/NewClientResponseSystem/NewClientResponseSystem.hpp"
39  #include "System/MouseSystem/MouseSystem.hpp"
40  #include "System/UpdateEntityInfosSystem/UpdateEntityInfosSystem.hpp"
41  #include "System/NewLevelSystem/NewLevelSystem.hpp"
42 
43 
47 class Client {
48  public:
54  Client(std::map<std::string, std::string> &configurationFiles);
55 
59  ~Client();
60 
64  void setUpEcs();
65 
69  void setUpSystems();
70 
74  void setUpComponents();
75 
79  void machineRun();
80 
84  void tryToConnect();
85 
89  void disconnect();
90 
97  void loadButtons(std::string const &filepath, Sparse_array<component::casset_t> &assets);
98 
105  void loadImages(std::string const &filepath, Sparse_array<component::casset_t> &assets);
106 
112  void loadTexts(std::string const &filepath);
113 
122  void createText(nlohmann::json const &oneData, std::array<float, 2> pos, int scene, std::string const &ref);
123 
133  void createImage(nlohmann::json const &oneData, std::array<float, 2> pos, int scene, const std::string &ref, Sparse_array<component::casset_t> &assets);
134 
135  private:
139  void handleReceive();
140 
144  void SendPacket();
145 
152  void pushNewPacketsToQueue(asio::error_code const &e, std::size_t nbBytes);
153 
159  void sendNewDirection(std::vector<byte> &byte);
160 
166  void sendNewShoot(std::vector<byte> &byte);
167 
172  void connectToServer();
173 
178  void goToOptions();
179 
180  void backToOptions();
181  void goToAudio();
182  void goToCredits();
183 
184  void downgradeMusic();
185  void upgradeMusic();
186 
191  void nameInput();
192 
197  void ipInput();
198 
203  void portInput();
204 
209  void noCallback() {};
210 
215  void exitGame();
216 
222  void seeRooms();
227  void backToConnection();
228 
233  void startGame();
234 
239  void backToMainMenu();
240 
245  void joinRoomOne();
246 
251  void joinRoomtwo();
252 
257  void joinRoomThree();
258 
262  void threadLoop();
263 
264  std::string _ip;
265  std::string _port;
266  std::string _name;
267 
268  asio::io_context _context;
269 
270  std::unique_ptr<rtype::GraphicalLib> _graphicLib;
271  std::unique_ptr<UdpCommunication> _com;
272  Registry _registry;
273  std::thread _thread;
274 
275  std::vector<byte> _bufferToGet;
276 
277  std::map<std::string, std::string> _configurationFiles;
278 
279  bool _isConnected = false;
280 
281  // Systems
282  System::NetworkSystem _networkSystem;
283  System::DrawSpriteSystem _drawSpriteSystem;
284  System::DrawTextSystem _drawTextSystem;
285  System::RectSystem _rectSystem;
286  System::ControlSystem _controlSystem;
287  System::NewEntitySystem _newEntitySystem;
288  System::ParallaxSystem _parallaxSystem;
289  System::PositionSystem _positionSystem;
290  System::MoveSystem _moveSystem;
291  System::KillEntityTypeSystem _killEntityTypeSystem;
292  System::KillSystem _killSystem;
293  System::GetInfoInLobbySystem _getInfoInLobbySystem;
294  System::GetLobbiesSystem _getLobbiesSystem;
295  System::SetNbPlayerInLobbySystem _setNbPlayerInLobbySystem;
296  System::NewClientResponseSystem _newClientResponseSystem;
297  System::MouseSystem _mouseSystem;
298  System::UpdateEntityInfosSystem _updateEntityInfosSystem;
299  System::NewLevelSystem _newLevelSystem;
300  System::EndGameSystem _endGameSystem;
301 };
302 
303 #endif /* !CLIENT_HPP_ */
Client::setUpSystems
void setUpSystems()
Set the Up Systems object.
Definition: Client.cpp:144
Sparse_array
Class that handle Element of type Component like a vector which can be holed.
Definition: SparseArray.hpp:22
System::GetInfoInLobbySystem
GetInfoInLobbySystem class that handles the dynamic info of the entities.
Definition: GetInfoInLobbySystem.hpp:28
System::DrawSpriteSystem
DrawSpriteSystem class that handles the drawing of all the sprite entities.
Definition: DrawSpriteSystem.hpp:35
Client::createImage
void createImage(nlohmann::json const &oneData, std::array< float, 2 > pos, int scene, const std::string &ref, Sparse_array< component::casset_t > &assets)
Create a Image object.
Definition: Client.cpp:239
System::NewLevelSystem
System to handle when a new level is reached.
Definition: NewLevelSystem.hpp:26
System::RectSystem
System that draws a part of all entities.
Definition: RectSystem.hpp:27
System::NetworkSystem
NetworkSystem class that handles the communication using queues with the server to send it tasks as p...
Definition: NetworkSystem.hpp:29
Client::setUpEcs
void setUpEcs()
Set the Up Ecs object.
Definition: Client.cpp:115
System::MouseSystem
MouseSystem class that handles the mouse.
Definition: MouseSystem.hpp:39
Client::~Client
~Client()
Destroy the Client object.
Definition: Client.cpp:44
Client::machineRun
void machineRun()
A method to launch the core features of a client.
Definition: Client.cpp:59
Client::Client
Client(std::map< std::string, std::string > &configurationFiles)
Construct a new Client object.
Definition: Client.cpp:32
Registry
Class that handle ECS.
Definition: Registry.hpp:22
Client::createText
void createText(nlohmann::json const &oneData, std::array< float, 2 > pos, int scene, std::string const &ref)
Create a Text object.
Definition: Client.cpp:216
System::ParallaxSystem
ParallaxSystem class that handles the parallax effect.
Definition: ParallaxSystem.hpp:27
System::MoveSystem
The Move System class, it handles all packets related to movement by the clients.
Definition: MoveSystem.hpp:30
System::EndGameSystem
The End Game System class, it handles the end of the game of lobbies.
Definition: EndGameSystem.hpp:27
System::KillEntityTypeSystem
KillEntityTypeSystem class that handles the killing of entities type.
Definition: KillEntityTypeSystem.hpp:24
Client::disconnect
void disconnect()
A method to call juste before a client is deconected.
Definition: Client.cpp:79
System::UpdateEntityInfosSystem
Update entity info system class that handles the update of an entity.
Definition: UpdateEntityInfosSystem.hpp:28
Client::loadImages
void loadImages(std::string const &filepath, Sparse_array< component::casset_t > &assets)
A method to load the assets of the images.
Definition: Client.cpp:266
Client::loadTexts
void loadTexts(std::string const &filepath)
A method to load the assets of the text.
Definition: Client.cpp:198
System::GetLobbiesSystem
GetLobbiesSystem class that handles the request to send to Server to get lobbies.
Definition: GetLobbiesSystem.hpp:26
Client::loadButtons
void loadButtons(std::string const &filepath, Sparse_array< component::casset_t > &assets)
A method to load the assets of the buttons.
Definition: Client.cpp:284
System::NewEntitySystem
NewEntitySystem class that handles the creation of an entity.
Definition: NewEntitySystem.hpp:40
System::ControlSystem
ControlSystem class that handles the control of all the entities.
Definition: ControlSystem.hpp:27
System::KillSystem
KillSystem class that handles the killing of entities.
Definition: KillSystem.hpp:30
System::DrawTextSystem
DrawTextSystem class that handles the drawing of all the sprite entities.
Definition: DrawTextSystem.hpp:29
System::SetNbPlayerInLobbySystem
System that set number of player in Lobby.
Definition: SetNbPlayerInLobbySystem.hpp:24
Client::tryToConnect
void tryToConnect()
A method to try to connect to a target server.
Definition: Client.cpp:52
Client
The Client class, it defines a client and its interactions with the server.
Definition: Client.hpp:47
System::NewClientResponseSystem
NewClientResponseSystem class that handles the creation of a client.
Definition: NewClientResponseSystem.hpp:25
System::PositionSystem
PositionSystem class that handles the position of the entities.
Definition: PositionSystem.hpp:26
Client::setUpComponents
void setUpComponents()
Set the Up Components object.
Definition: Client.cpp:167