Merge branch 'master' into martin-t/globals
[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 ENDCLASS(PlayerState)
16
17 .PlayerState _ps;
18 #define PS(this) ((this)._ps)
19
20 // TODO: renew on death
21 void PlayerState_attach(entity this);
22 void PlayerState_detach(entity this);
23
24 /**
25  * Purpose: common client state, usable on client and server
26  * Client: singleton representing the viewed player
27  * Server: instance per client
28  */
29 CLASS(ClientState, Object)
30         ATTRIB(ClientState, m_client, entity);
31         CONSTRUCTOR(ClientState, entity client)
32         {
33                 CONSTRUCT(ClientState);
34                 this.m_client = client;
35         }
36         METHOD(PlayerState, ps_push, void(PlayerState this, entity cl))
37         {
38                 TC(PlayerState, this);
39         }
40 ENDCLASS(ClientState)
41
42 .ClientState _cs;
43
44 #if NDEBUG
45         #define CS(this) (this._cs)
46 #else
47         ClientState CS(Client this) { TC(Client, this); assert(this._cs); return this._cs; }
48 #endif
49
50 void ClientState_attach(entity this);
51 void ClientState_detach(entity this);