7#include <engine2/isource2server.h>
8#include <entity2/entityinstance.h>
9#include <entityhandle.h>
10#include <networksystem/networkvar.h>
25 CEntityInstance*
Pawn =
nullptr;
40 const auto* handles =
static_cast<const HandleVector*
>(vector);
101 _slotListener = slots.
Changed += [
this](
int slot) {
107 std::erase_if(_private, [slot](
const PrivateEntity& e) {
return e.Viewer == slot; });
115 _state[slot].PawnHidden = hidden;
123 _state[slot].ControllerHidden = hidden;
129 return IsValidSlot(slot) && _state[slot].PawnHidden;
139 SetPrivate({.Entity = entity, .Viewer = slot});
149 SetPrivate({.Entity = entity, .ShownTo = team});
159 SetPrivate({.Entity = entity, .HiddenFrom = team});
162void Visibility::SetPrivate(
const PrivateEntity& entry)
164 const auto found = std::ranges::find(_private, entry.Entity, &PrivateEntity::Entity);
165 if (found != _private.end())
171 _private.push_back(entry);
177 std::erase_if(_private, [entity](
const PrivateEntity& e) {
return e.Entity == entity; });
182 return std::make_shared<GlowVision>(_entities, *
this, viewerSlot, std::move(config));
187 return std::make_shared<GlowVision>(_entities, *
this, viewerTeam, std::move(config));
190bool Visibility::PrivateEntity::IsHiddenFrom(
int recipient,
Team recipientTeam)
const
194 return Viewer != recipient;
198 return ShownTo != recipientTeam;
200 return HiddenFrom == recipientTeam;
206 for (
auto& entry : _private)
208 const Entity entity = _entities.Get(entry.Entity);
211 std::erase_if(_private, [](
const PrivateEntity& e) {
return e.Index <= 0; });
217 if (_private.empty() && std::ranges::none_of(_state, &SlotState::Any))
223 std::array<HiddenPlayer, MaxPlayers> hidden;
227 const auto& state = _state[slot];
230 CollectHiddenPlayer(_entities, slot, state.PawnHidden, state.ControllerHidden, hidden[hiddenCount++]);
234 for (
int i = 0; i < infoCount; ++i)
236 auto* info = infoList[i];
237 if (!info || !info->m_pTransmitEntity)
242 const int recipient = info->m_nPlayerSlot.Get();
243 CEntityInstance* observed = hiddenCount > 0 ?
ObserverTarget(_entities, recipient) :
nullptr;
244 const Team recipientTeam = _entities.Controller(recipient).TeamNum();
246 for (
int h = 0; h < hiddenCount; ++h)
248 const auto& player = hidden[h];
249 if (player.Slot == recipient)
254 if (observed != player.Pawn)
256 for (
int n = 0; n < player.IndexCount; ++n)
258 info->m_pTransmitEntity->Clear(player.PawnIndices[n]);
262 if (player.ControllerIndex > 0)
264 info->m_pTransmitEntity->Clear(player.ControllerIndex);
268 for (
const auto& entry : _private)
270 if (entry.IsHiddenFrom(recipient, recipientTeam))
272 info->m_pTransmitEntity->Clear(entry.Index);
A player's identity behind a slot: name, money, team, scoreboard row. It survives death and respawn; ...
VoltMod::Pawn InputPawn() const
VoltMod::Pawn Pawn() const
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
VoltMod::Controller Controller(int slot)
Entity Get(EntityRef ref)
A live entity, valid for this frame only.
CEntityInstance * Raw() const noexcept
A player turned into a nameless spectator nobody else sees, who sees every player through walls.
std::array< int, MaxIndicesPerPlayer > PawnIndices
A player's body: health, armor, movement, aim, weapons. The engine replaces it on every spawn; the Co...
EntityRef ObserverTarget() const
"The occupant of this slot changed" - raised by PlayerManager, consumed below it.
void ShowOnlyToTeam(EntityRef entity, Team team)
void SetPawnHidden(int slot, bool hidden)
bool IsPawnHidden(int slot) const
void HideFromTeam(EntityRef entity, Team team)
void ShowToEveryone(EntityRef entity)
void SetControllerHidden(int slot, bool hidden)
std::shared_ptr< GlowVision > CreateGlow(int viewerSlot, GlowConfig config={})
void ShowOnlyTo(EntityRef entity, int slot)
void OnCheckTransmit(CCheckTransmitInfo **infoList, int infoCount)
Visibility(EntitySystem &entities, SlotEvents &slots)
constexpr bool IsPlaying(Team team)
CNetworkUtlVectorBase< CEntityHandle > HandleVector
static void CollectHiddenPlayer(EntitySystem &entities, int slot, bool pawnHidden, bool controllerHidden, HiddenPlayer &out)
constexpr bool IsValidSlot(int slot)
static CEntityInstance * ObserverTarget(EntitySystem &entities, int recipientSlot)
static void AddHandleVector(EntitySystem &entities, HiddenPlayer &player, const void *vector)
static constexpr int MaxIndicesPerPlayer
static void AddIndex(HiddenPlayer &player, int index)