]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/state.qh
Type check macros
[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, NULL)
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                 STAT(ACTIVEWEAPON, cl) = this.m_weapon.m_id;
21                 STAT(SWITCHINGWEAPON, cl) = this.m_switchingweapon.m_id;
22                 STAT(SWITCHWEAPON, cl) = this.m_switchweapon.m_id;
23         }
24 ENDCLASS(PlayerState)
25
26 .PlayerState _ps;
27 #define PS(this) (this._ps)
28
29 // TODO: renew on death
30 void PlayerState_attach(entity this);
31 void PlayerState_detach(entity this);
32
33 /**
34  * Purpose: common client state, usable on client and server
35  * Client: singleton representing the viewed player
36  * Server: instance per client
37  */
38 CLASS(ClientState, Object)
39         ATTRIB(ClientState, m_client, entity, NULL)
40         CONSTRUCTOR(ClientState, entity client)
41         {
42                 CONSTRUCT(ClientState);
43                 this.m_client = client;
44         }
45 ENDCLASS(ClientState)
46
47 .ClientState _cs;
48
49 #if NDEBUG
50         #define CS(this) (this._cs)
51 #else
52         ClientState CS(entity this) { assert(IS_CLIENT(this)); assert(this._cs); return this._cs; }
53 #endif
54
55 void ClientState_attach(entity this);
56 void ClientState_detach(entity this);