VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Visibility.hpp
Go to the documentation of this file.
1#pragma once
2
12#include <array>
13#include <functional>
14#include <memory>
15#include <vector>
16
17namespace VoltMod
18{
19
20/** Glow colors and an optional per-slot veto. */
22{
23 Color TerroristColor{255, 128, 0};
24 Color CtColor{0, 160, 255};
25 /** Extra veto on top of the live, team and hidden checks; empty glows everyone. */
26 std::function<bool(int slot)> Filter;
27};
28
29/**
30 * @brief Which clients receive which entities, filtered after CheckTransmit.
31 *
32 * A hidden pawn takes its weapons, wearables and shadow with it but stays visible to whoever
33 * spectates it; a hidden controller loses its scoreboard row and chat attribution. Sounds are
34 * networked separately and are unaffected.
35 */
37{
38public:
39 /** @p slots resets a slot's hiding when it changes hands. Both must outlive this. */
40 Visibility(EntitySystem& entities, SlotEvents& slots);
41 Visibility(const Visibility&) = delete;
42 Visibility& operator=(const Visibility&) = delete;
43
44 /** Hide or show `slot`'s pawn from every other client. */
45 void SetPawnHidden(int slot, bool hidden);
46
47 /** Hide or show `slot`'s controller from every other client. */
48 void SetControllerHidden(int slot, bool hidden);
49
50 bool IsPawnHidden(int slot) const;
51
52 /** Network `entity` to `slot` alone. Calling again moves it to another slot. */
53 void ShowOnlyTo(EntityRef entity, int slot);
54
55 /** Network `entity` to `team` alone, spectators excluded. Calling again moves it. */
56 void ShowOnlyToTeam(EntityRef entity, Team team);
57
58 /** Keep `entity` from every client on `team`. Calling again moves it. */
59 void HideFromTeam(EntityRef entity, Team team);
60
61 /** Undo the calls above; a removed entity needs no call. */
62 void ShowToEveryone(EntityRef entity);
63
64 /** A @ref GlowVision for @p viewerSlot alone; its clones go with the last owner. */
65 std::shared_ptr<GlowVision> CreateGlow(int viewerSlot, GlowConfig config = {});
66
67 /** A @ref GlowVision the whole of @p viewerTeam shares. */
68 std::shared_ptr<GlowVision> CreateGlow(Team viewerTeam, GlowConfig config = {});
69
70 /** @internal Called by the framework after ISource2GameEntities::CheckTransmit. */
71 void OnCheckTransmit(CCheckTransmitInfo** infoList, int infoCount);
72
73private:
74 struct SlotState
75 {
76 bool PawnHidden = false;
77 bool ControllerHidden = false;
78
79 bool Any() const { return PawnHidden || ControllerHidden; }
80 };
81
82 /** Sent to @ref Viewer alone, else to @ref ShownTo alone, else to everyone off @ref HiddenFrom. */
83 struct PrivateEntity
84 {
85 EntityRef Entity;
86 int Viewer = -1;
87 Team ShownTo = Team::None;
88 Team HiddenFrom = Team::None;
89 int Index = -1; ///< resolved once per snapshot
90
91 bool IsHiddenFrom(int recipient, Team recipientTeam) const;
92 };
93
94 /** Replaces the entry for the same entity, or adds it. */
95 void SetPrivate(const PrivateEntity& entry);
96
97 EntitySystem& _entities;
98 std::array<SlotState, MaxPlayers> _state{};
99 std::vector<PrivateEntity> _private;
100 /** Declared last: unregisters before the state it resets. */
101 Subscription _slotListener;
102};
103
104} // namespace VoltMod
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
"The occupant of this slot changed" - raised by PlayerManager, consumed below it.
void ShowOnlyToTeam(EntityRef entity, Team team)
Visibility(const Visibility &)=delete
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)
Visibility & operator=(const Visibility &)=delete
An RGBA color in the engine's byte order, as m_clrRender and glow colors hold it.
Definition Color.hpp:15
std::function< bool(int slot)> Filter