-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientNetwork.cpp
More file actions
36 lines (32 loc) · 1.4 KB
/
ClientNetwork.cpp
File metadata and controls
36 lines (32 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "ClientNetwork.hpp"
#include "ECSCustomTypes.hpp"
#include "NitworkClient.hpp"
#include "Registry.hpp"
namespace Systems {
void receiveLifeUpdate(std::any &any, boost::asio::ip::udp::endpoint &)
{
struct msgLifeUpdate_s msg = std::any_cast<struct msgLifeUpdate_s>(any);
Registry ®istry = Registry::getInstance();
Registry::components<struct health_s> arrHealth = registry.getComponents<struct health_s>();
std::vector<std::size_t> ids =
registry.getEntitiesByComponents({typeid(struct health_s), typeid(Types::Player)});
for (auto id : ids) {
struct health_s &life = arrHealth[id];
if (life.hp != msg.life.hp) {
life.hp = msg.life.hp;
}
}
}
void receiveEnemyDeath(std::any &any, boost::asio::ip::udp::endpoint &)
{
struct msgEnemyDeath_s enemyDeath = std::any_cast<struct msgEnemyDeath_s>(any);
Registry::components<Types::Enemy> enemies = Registry::getInstance().getComponents<Types::Enemy>();
std::vector<std::size_t> ids = enemies.getExistingsId();
for (auto id : ids) {
if (enemies[id].constId.value == enemyDeath.enemyId.value) {
Registry::getInstance().removeEntity(id);
return;
}
}
}
} // namespace Systems