My Project
NetworkSystem.hpp
1 /*
2 ** EPITECH PROJECT, 2022
3 ** B-CPP-500-PAR-5-1-rtype-martin.vanaud
4 ** File description:
5 ** NetworkSystem
6 */
7 
8 #ifndef NETWORKSYSTEM_HPP_
9  #define NETWORKSYSTEM_HPP_
10 
11  #include <unordered_map>
12 
13  /* Serialization */
14  #include "Serialization.hpp"
15 
16  /* Ecs */
17  #include "Registry.hpp"
18 
19  /* Component */
20  #include "Component/CNetworkQueue.hpp"
21 
25 namespace System {
29  class NetworkSystem {
30  public:
34  NetworkSystem();
35  ~NetworkSystem() = default;
36 
43  void operator()(
44  Registry &registry,
46  );
47 
54  void dispatchToPositionQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
55 
62  void dispatchToNewEntityQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
63 
70  void dispatchToKillEntityQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
71 
78  void dispatchToKillEntityTypeQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
79 
86  void dispatchToGetLobbiesQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
87 
94  void dispatchNbPlayersInLobbyQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
95 
102  void dispatchNetworkClientIdQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
103 
110  void dispatchUpdateEntityHealthQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
111 
118  void dispatchUpdateEntityScoreQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
119 
126  void dispatchNewLevelQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
127 
134  void dispatchEndGameQueue(std::vector<byte> const &bytes, Sparse_array<component::cnetwork_queue_t> &network);
135  protected:
136  private:
137  std::unordered_map<NETWORK_SERVER_TO_CLIENT::PACKET_TYPE, std::function<void(std::vector<byte> const &, Sparse_array<component::cnetwork_queue_t> &)>> _callBacks;
138 
139  };
140 }
141 
142 #endif /* !NETWORKSYSTEM_HPP_ */
Sparse_array
Class that handle Element of type Component like a vector which can be holed.
Definition: SparseArray.hpp:22
System::NetworkSystem::dispatchUpdateEntityScoreQueue
void dispatchUpdateEntityScoreQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the update entity score queue.
Definition: NetworkSystem.cpp:107
System
Namespace for systems.
Definition: DirectionSystem.hpp:24
System::NetworkSystem
NetworkSystem class that handles the communication using queues with the server to send it tasks as p...
Definition: NetworkSystem.hpp:29
System::NetworkSystem::operator()
void operator()(Registry &registry, Sparse_array< component::cnetwork_queue_t > &network)
Function that will be automaticaly called while the client is working (on loop)
Definition: NetworkSystem.cpp:40
System::NetworkSystem::dispatchToGetLobbiesQueue
void dispatchToGetLobbiesQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the get lobbies queue.
Definition: NetworkSystem.cpp:83
System::NetworkSystem::NetworkSystem
NetworkSystem()
Construct a new Network System object.
Definition: NetworkSystem.cpp:23
System::NetworkSystem::dispatchUpdateEntityHealthQueue
void dispatchUpdateEntityHealthQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the update entity health queue.
Definition: NetworkSystem.cpp:101
System::NetworkSystem::dispatchToKillEntityQueue
void dispatchToKillEntityQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the kill entity queue.
Definition: NetworkSystem.cpp:71
Registry
Class that handle ECS.
Definition: Registry.hpp:22
System::NetworkSystem::dispatchToKillEntityTypeQueue
void dispatchToKillEntityTypeQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the kill entity type queue.
Definition: NetworkSystem.cpp:77
System::NetworkSystem::dispatchToPositionQueue
void dispatchToPositionQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the position queue.
Definition: NetworkSystem.cpp:59
System::NetworkSystem::dispatchToNewEntityQueue
void dispatchToNewEntityQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the new entity queue.
Definition: NetworkSystem.cpp:65
System::NetworkSystem::dispatchEndGameQueue
void dispatchEndGameQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the end Game queue.
Definition: NetworkSystem.cpp:119
System::NetworkSystem::dispatchNewLevelQueue
void dispatchNewLevelQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the new level queue.
Definition: NetworkSystem.cpp:113
System::NetworkSystem::dispatchNbPlayersInLobbyQueue
void dispatchNbPlayersInLobbyQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the Nb Players in queue.
Definition: NetworkSystem.cpp:89
System::NetworkSystem::dispatchNetworkClientIdQueue
void dispatchNetworkClientIdQueue(std::vector< byte > const &bytes, Sparse_array< component::cnetwork_queue_t > &network)
A method to send informations to the network client id queue.
Definition: NetworkSystem.cpp:95