]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/state.qh
Add missing include guards
[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 #if NDEBUG
28         #define PS(this) (this._ps)
29 #else
30         PlayerState PS(entity this) { assert(IS_CLIENT(this)); return this._ps; }
31 #endif
32
33 void PlayerState_attach(entity this)
34 {
35         // TODO: dynamic
36         // this._ps = NEW(PlayerState, this);
37 }
38
39 void PlayerState_detach(entity this)
40 {
41         // TODO: dynamic
42         // if (!PS(this)) return;  // initial connect
43         // remove(PS(this));
44         // this._ps = NULL;
45 }
46
47 /**
48  * Purpose: common client state, usable on client and server
49  * Client: singleton representing the viewed player
50  * Server: instance per client
51  */
52 CLASS(ClientState, Object)
53         ATTRIB(ClientState, m_client, entity, NULL)
54         CONSTRUCTOR(ClientState, entity client)
55         {
56                 CONSTRUCT(ClientState);
57                 this.m_client = client;
58         }
59 ENDCLASS(ClientState)
60
61 .ClientState _cs;
62
63 #if NDEBUG
64         #define CS(this) (this._cs)
65 #else
66         ClientState CS(entity this) { assert(IS_CLIENT(this)); assert(this._cs); return this._cs; }
67 #endif
68
69 void ClientState_attach(entity this)
70 {
71         this._cs = NEW(ClientState, this);
72         this._ps = NEW(PlayerState, this);  // TODO: dynamic
73 }
74
75 void ClientState_detach(entity this)
76 {
77         remove(CS(this));
78         this._cs = NULL;
79         this._ps = NULL;  // TODO: dynamic
80 }