]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/state.qh
Fix compile
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / state.qh
1 /**
2  * Purpose: common player state, usable on client and server
3  * Client: singleton representing the viewed player
4  * Server: instance per client, clients decoupled from players
5  */
6 CLASS(PlayerState, Object)
7         ATTRIB(PlayerState, m_client, entity, NULL)
8         CONSTRUCTOR(PlayerState, entity client)
9         {
10                 CONSTRUCT(PlayerState);
11                 this.m_client = client;
12         }
13         ATTRIB(PlayerState, m_switchingweapon, Weapon, Weapons_from(-1))
14         ATTRIB(PlayerState, m_switchweapon, Weapon, Weapons_from(-1))
15         ATTRIB(PlayerState, m_weapon, Weapon, Weapons_from(-1))
16         METHOD(PlayerState, ps_push, void(PlayerState this, entity cl))
17         {
18                 STAT(ACTIVEWEAPON, cl) = this.m_weapon.m_id;
19                 STAT(SWITCHINGWEAPON, cl) = this.m_switchingweapon.m_id;
20                 STAT(SWITCHWEAPON, cl) = this.m_switchweapon.m_id;
21         }
22 ENDCLASS(PlayerState)
23
24 .PlayerState _ps;
25 #if NDEBUG
26         #define PS(this) (this._ps)
27 #else
28         PlayerState PS(entity this) { assert(IS_CLIENT(this)); return this._ps; }
29 #endif
30
31 void PlayerState_attach(entity this)
32 {
33         // TODO: dynamic
34         // this._ps = NEW(PlayerState, this);
35 }
36
37 void PlayerState_detach(entity this)
38 {
39         // TODO: dynamic
40         // if (!PS(this)) return;  // initial connect
41         // remove(PS(this));
42         // this._ps = NULL;
43 }
44
45 /**
46  * Purpose: common client state, usable on client and server
47  * Client: singleton representing the viewed player
48  * Server: instance per client
49  */
50 CLASS(ClientState, Object)
51         ATTRIB(ClientState, m_client, entity, NULL)
52         CONSTRUCTOR(ClientState, entity client)
53         {
54                 CONSTRUCT(ClientState);
55                 this.m_client = client;
56         }
57 ENDCLASS(ClientState)
58
59 .ClientState _cs;
60
61 #if NDEBUG
62         #define CS(this) (this._cs)
63 #else
64         ClientState CS(entity this) { assert(IS_CLIENT(this)); assert(this._cs); return this._cs; }
65 #endif
66
67 void ClientState_attach(entity this)
68 {
69         this._cs = NEW(ClientState, this);
70         this._ps = NEW(PlayerState, this);  // TODO: dynamic
71 }
72
73 void ClientState_detach(entity this)
74 {
75         remove(CS(this));
76         this._cs = NULL;
77         this._ps = NULL;  // TODO: dynamic
78 }