]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/state.qh
Ensure headers are always #included
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / state.qh
1 #pragma once
2
3 /**
4  * Purpose: common player state, usable on client and server
5  * Client: singleton representing the viewed player
6  * Server: instance per client, clients decoupled from players
7  */
8 CLASS(PlayerState, Object)
9         ATTRIB(PlayerState, m_client, entity);
10         CONSTRUCTOR(PlayerState, entity client)
11         {
12                 CONSTRUCT(PlayerState);
13                 this.m_client = client;
14         }
15         ATTRIB(PlayerState, m_switchingweapon, Weapon, Weapons_from(-1));
16         ATTRIB(PlayerState, m_switchweapon, Weapon, Weapons_from(-1));
17         ATTRIB(PlayerState, m_weapon, Weapon, Weapons_from(-1));
18         METHOD(PlayerState, ps_push, void(PlayerState this, entity cl))
19         {
20             TC(PlayerState, this);
21                 STAT(ACTIVEWEAPON, cl) = this.m_weapon.m_id;
22                 STAT(SWITCHINGWEAPON, cl) = this.m_switchingweapon.m_id;
23                 STAT(SWITCHWEAPON, cl) = this.m_switchweapon.m_id;
24         }
25 ENDCLASS(PlayerState)
26
27 .PlayerState _ps;
28 #define PS(this) ((this)._ps)
29
30 // TODO: renew on death
31 void PlayerState_attach(entity this);
32 void PlayerState_detach(entity this);
33
34 /**
35  * Purpose: common client state, usable on client and server
36  * Client: singleton representing the viewed player
37  * Server: instance per client
38  */
39 CLASS(ClientState, Object)
40         ATTRIB(ClientState, m_client, entity);
41         CONSTRUCTOR(ClientState, entity client)
42         {
43                 CONSTRUCT(ClientState);
44                 this.m_client = client;
45         }
46 ENDCLASS(ClientState)
47
48 .ClientState _cs;
49
50 #if NDEBUG
51         #define CS(this) (this._cs)
52 #else
53         ClientState CS(Client this) { TC(Client, this); assert(this._cs); return this._cs; }
54 #endif
55
56 void ClientState_attach(entity this);
57 void ClientState_detach(entity this);