3#include "Protocol/EntityPayload.hpp"
5#include "components/Dead.hpp"
6#include "components/NetworkEntity.hpp"
9#include <unordered_map>
12namespace rtype::server {
31 const std::unordered_map<std::uint32_t, std::size_t> &players,
32 const std::uint32_t &serverTick)
33 : _server(server), _players(players), _serverTick(serverTick) {}
40 void onStart(rtk::ecs::Registry &)
override {}
46 void update(rtk::ecs::Registry ®,
float)
override {
50 std::vector<std::size_t> toDestroy;
51 for (
auto entity : view) {
52 toDestroy.push_back(entity);
55 for (
auto entity : toDestroy) {
56 auto *netEnt = netEntities.get(entity);
57 if (netEnt && netEnt->id != 0) {
60 for (
const auto &[playerId, dummy] : _players) {
65 reg.remove_entity_from_all_pools(entity);
66 reg.kill_entity(entity);
73 void onStop(rtk::ecs::Registry &)
override {}
77 const std::unordered_map<std::uint32_t, std::size_t> &_players;
78 const std::uint32_t &_serverTick;
Destroys dead entities and tells every player with DestroyEntity.
Definition ServerDeathSystem.hpp:21
void update(rtk::ecs::Registry ®, float) override
Broadcasts and destroys every entity tagged with Dead.
Definition ServerDeathSystem.hpp:46
void onStop(rtk::ecs::Registry &) override
Does nothing.
Definition ServerDeathSystem.hpp:73
ServerDeathSystem(Server &server, const std::unordered_map< std::uint32_t, std::size_t > &players, const std::uint32_t &serverTick)
Creates the system.
Definition ServerDeathSystem.hpp:29
void onStart(rtk::ecs::Registry &) override
Does nothing.
Definition ServerDeathSystem.hpp:40
Game level layer over NetworkServer that decodes client messages and encodes server messages.
Definition Server.hpp:30
bool sendDestroyEntity(std::uint32_t connectionId, const protocol::DestroyEntityPayload &payload)
Sends a DestroyEntity message.
Definition Server.cpp:170
DestroyEntityPayload destroyEntityPayload(std::uint32_t serverTick, std::uint32_t networkId, DestroyReason reason)
Builds a DestroyEntity payload.
Definition EntityPayload.hpp:142
@ Collision
Removed by gameplay, such as a hit.
Tag marking an entity for destruction at the end of the frame.
Definition Dead.hpp:17
Links a local entity to its replicated counterpart.
Definition NetworkEntity.hpp:18