// not so constant
-#ifdef SVQC
-#define PL_VIEW_OFS autocvar_sv_player_viewoffset
-#define PL_MIN autocvar_sv_player_mins
-#define PL_MAX autocvar_sv_player_maxs
-#define PL_CROUCH_VIEW_OFS autocvar_sv_player_crouch_viewoffset
-#define PL_CROUCH_MIN autocvar_sv_player_crouch_mins
-#define PL_CROUCH_MAX autocvar_sv_player_crouch_maxs
-#define PL_HEAD autocvar_sv_player_headsize
-#elif defined(CSQC)
-#define PL_VIEW_OFS vec3(getstatf(STAT_PL_VIEW_OFS1), getstatf(STAT_PL_VIEW_OFS2), getstatf(STAT_PL_VIEW_OFS3))
-#define PL_MIN vec3(getstatf(STAT_PL_MIN1), getstatf(STAT_PL_MIN2), getstatf(STAT_PL_MIN3))
-#define PL_MAX vec3(getstatf(STAT_PL_MAX1), getstatf(STAT_PL_MAX2), getstatf(STAT_PL_MAX3))
-#define PL_CROUCH_VIEW_OFS vec3(getstatf(STAT_PL_CROUCH_VIEW_OFS1), getstatf(STAT_PL_CROUCH_VIEW_OFS2), getstatf(STAT_PL_CROUCH_VIEW_OFS3))
-#define PL_CROUCH_MIN vec3(getstatf(STAT_PL_CROUCH_MIN1), getstatf(STAT_PL_CROUCH_MIN2), getstatf(STAT_PL_CROUCH_MIN3))
-#define PL_CROUCH_MAX vec3(getstatf(STAT_PL_CROUCH_MAX1), getstatf(STAT_PL_CROUCH_MAX2), getstatf(STAT_PL_CROUCH_MAX3))
-#endif
+#define PL_VIEW_OFS STAT(PL_VIEW_OFS, NULL)
+#define PL_CROUCH_VIEW_OFS STAT(PL_CROUCH_VIEW_OFS, NULL)
+#define PL_MIN STAT(PL_MIN, NULL)
+#define PL_CROUCH_MIN STAT(PL_CROUCH_MIN, NULL)
+#define PL_MAX STAT(PL_MAX, NULL)
+#define PL_CROUCH_MAX STAT(PL_CROUCH_MAX, NULL)
// a bit more constant
const vector PL_MAX_CONST = '16 16 45';
return cvar(strcat("sv_", option));
}
-void Physics_AddStats()
-{
- // static view offset and hitbox vectors
- // networked for all you bandwidth pigs out there
- addstat(STAT_PL_VIEW_OFS1, AS_FLOAT, stat_pl_view_ofs_x);
- addstat(STAT_PL_VIEW_OFS2, AS_FLOAT, stat_pl_view_ofs_y);
- addstat(STAT_PL_VIEW_OFS3, AS_FLOAT, stat_pl_view_ofs_z);
- addstat(STAT_PL_CROUCH_VIEW_OFS1, AS_FLOAT, stat_pl_crouch_view_ofs_x);
- addstat(STAT_PL_CROUCH_VIEW_OFS2, AS_FLOAT, stat_pl_crouch_view_ofs_y);
- addstat(STAT_PL_CROUCH_VIEW_OFS3, AS_FLOAT, stat_pl_crouch_view_ofs_z);
-
- addstat(STAT_PL_MIN1, AS_FLOAT, stat_pl_min_x);
- addstat(STAT_PL_MIN2, AS_FLOAT, stat_pl_min_y);
- addstat(STAT_PL_MIN3, AS_FLOAT, stat_pl_min_z);
- addstat(STAT_PL_MAX1, AS_FLOAT, stat_pl_max_x);
- addstat(STAT_PL_MAX2, AS_FLOAT, stat_pl_max_y);
- addstat(STAT_PL_MAX3, AS_FLOAT, stat_pl_max_z);
- addstat(STAT_PL_CROUCH_MIN1, AS_FLOAT, stat_pl_crouch_min_x);
- addstat(STAT_PL_CROUCH_MIN2, AS_FLOAT, stat_pl_crouch_min_y);
- addstat(STAT_PL_CROUCH_MIN3, AS_FLOAT, stat_pl_crouch_min_z);
- addstat(STAT_PL_CROUCH_MAX1, AS_FLOAT, stat_pl_crouch_max_x);
- addstat(STAT_PL_CROUCH_MAX2, AS_FLOAT, stat_pl_crouch_max_y);
- addstat(STAT_PL_CROUCH_MAX3, AS_FLOAT, stat_pl_crouch_max_z);
-}
-
void Physics_UpdateStats(entity this, float maxspd_mod)
{
- // blah
- this.stat_pl_view_ofs = PL_VIEW_OFS;
- this.stat_pl_crouch_view_ofs = PL_CROUCH_VIEW_OFS;
-
- this.stat_pl_min = PL_MIN;
- this.stat_pl_max = PL_MAX;
- this.stat_pl_crouch_min = PL_CROUCH_MIN;
- this.stat_pl_crouch_max = PL_CROUCH_MAX;
-
STAT(MOVEVARS_AIRACCEL_QW, this) = AdjustAirAccelQW(Physics_ClientOption(this, "airaccel_qw"), maxspd_mod);
STAT(MOVEVARS_AIRSTRAFEACCEL_QW, this) = (Physics_ClientOption(this, "airstrafeaccel_qw"))
? AdjustAirAccelQW(Physics_ClientOption(this, "airstrafeaccel_qw"), maxspd_mod)
bool Physics_Valid(string thecvar);
- .vector stat_pl_view_ofs;
- .vector stat_pl_crouch_view_ofs;
-
- .vector stat_pl_min, stat_pl_max;
- .vector stat_pl_crouch_min, stat_pl_crouch_max;
-
.float stat_sv_airspeedlimit_nonqw = _STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW);
.float stat_sv_maxspeed = _STAT(MOVEVARS_MAXSPEED);
const int STAT_VIEWHEIGHT = 16; // .view_ofs_z
#endif
-enum {
- STAT_WEAPONS = 32,
- STAT_WEAPONS2,
- STAT_WEAPONS3,
+REGISTER_STAT(WEAPONS, vectori)
+REGISTER_STAT(WEAPONSINMAP, vectori)
- STAT_WEAPONSINMAP,
- STAT_WEAPONSINMAP2,
- STAT_WEAPONSINMAP3,
+REGISTER_STAT(PL_VIEW_OFS, vector, autocvar_sv_player_viewoffset)
+REGISTER_STAT(PL_CROUCH_VIEW_OFS, vector, autocvar_sv_player_crouch_viewoffset)
- STAT_PL_VIEW_OFS1,
- STAT_PL_VIEW_OFS2,
- STAT_PL_VIEW_OFS3,
+REGISTER_STAT(PL_MIN, vector, autocvar_sv_player_mins)
+REGISTER_STAT(PL_CROUCH_MIN, vector, autocvar_sv_player_crouch_mins)
- STAT_PL_CROUCH_VIEW_OFS1,
- STAT_PL_CROUCH_VIEW_OFS2,
- STAT_PL_CROUCH_VIEW_OFS3,
-
- STAT_PL_MIN1,
- STAT_PL_MIN2,
- STAT_PL_MIN3,
-
- STAT_PL_MAX1,
- STAT_PL_MAX2,
- STAT_PL_MAX3,
-
- STAT_PL_CROUCH_MIN1,
- STAT_PL_CROUCH_MIN2,
- STAT_PL_CROUCH_MIN3,
-
- STAT_PL_CROUCH_MAX1,
- STAT_PL_CROUCH_MAX2,
- STAT_PL_CROUCH_MAX3,
-};
+REGISTER_STAT(PL_MAX, vector, autocvar_sv_player_maxs)
+REGISTER_STAT(PL_CROUCH_MAX, vector, autocvar_sv_player_crouch_maxs)
REGISTER_STAT(KH_KEYS, int)
/** weapon requested to switch to; next WANTED weapon (for HUD) */
return '1 0 0' * power2of(a);
}
#ifdef SVQC
-void WepSet_AddStat()
-{
- addstat(STAT_WEAPONS, AS_INT, weapons_x);
- if (Weapons_MAX > 24)
- addstat(STAT_WEAPONS2, AS_INT, weapons_y);
- if (Weapons_MAX > 48)
- addstat(STAT_WEAPONS3, AS_INT, weapons_z);
-}
-void WepSet_AddStat_InMap()
-{
- addstat(STAT_WEAPONSINMAP, AS_INT, weaponsinmap_x);
- if (Weapons_MAX > 24)
- addstat(STAT_WEAPONSINMAP2, AS_INT, weaponsinmap_y);
- if (Weapons_MAX > 48)
- addstat(STAT_WEAPONSINMAP3, AS_INT, weaponsinmap_z);
-}
void WriteWepSet(float dst, WepSet w)
{
if (Weapons_MAX > 48)
#ifdef CSQC
WepSet WepSet_GetFromStat()
{
- WepSet w = '0 0 0';
- w.x = getstati(STAT_WEAPONS);
- if (Weapons_MAX > 24)
- w.y = getstati(STAT_WEAPONS2);
- if (Weapons_MAX > 48)
- w.z = getstati(STAT_WEAPONS3);
- return w;
+ return STAT(WEAPONS);
}
WepSet WepSet_GetFromStat_InMap()
{
- WepSet w = '0 0 0';
- w_x = getstati(STAT_WEAPONSINMAP);
- if (Weapons_MAX > 24)
- w_y = getstati(STAT_WEAPONSINMAP2);
- if (Weapons_MAX > 48)
- w_z = getstati(STAT_WEAPONSINMAP3);
- return w;
+ return STAT(WEAPONSINMAP);
}
WepSet ReadWepSet()
{
#define WEPSET(id) WepSet_FromWeapon(WEP_##id.m_id)
WepSet WepSet_FromWeapon(int a);
#ifdef SVQC
-void WepSet_AddStat();
-void WepSet_AddStat_InMap();
void WriteWepSet(float dest, WepSet w);
#endif
entity this = inst; \
ns##_##id = this; \
this.registered_id = #id; \
- this.fld = array##_COUNT; \
- _##array[array##_COUNT++] = this; \
- if (!array##_first) array##_first = this; \
- if (array##_last) array##_last.REGISTRY_NEXT = this; \
- array##_last = this; \
+ REGISTRY_PUSH(array, fld, this); \
Register_##ns##_##id##_init(this); \
Register_##ns##_##id##_init_post(this); \
} \
ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id) \
REGISTER_INIT(ns, id)
+#define REGISTRY_PUSH(array, fld, it) do { \
+ it.fld = array##_COUNT; \
+ _##array[array##_COUNT++] = it; \
+ if (!array##_first) array##_first = it; \
+ if (array##_last) array##_last.REGISTRY_NEXT = it; \
+ array##_last = it; \
+} while (0)
+
+#define REGISTRY_RESERVE(registry, fld, id, suffix) do { \
+ entity e = new(registry_reserved); \
+ e.registered_id = #id #suffix; \
+ REGISTRY_PUSH(registry, fld, e); \
+} while (0)
+
/** internal next pointer */
#define REGISTRY_NEXT enemy
.entity REGISTRY_NEXT;
#include "sort.qh"
.int m_id;
+typedef vector vectori;
#define REGISTER_STAT(...) EVAL(OVERLOAD(REGISTER_STAT, __VA_ARGS__))
#if defined(CSQC)
#define getstat_int(id) getstati(id, 0, 24)
#define getstat_bool(id) boolean(getstati(id))
#define getstat_float(id) getstatf(id)
+ #define getstat_vector(id) vec3(getstat_float(id + 0), getstat_float(id + 1), getstat_float(id + 2))
+ #define getstat_vectori(id) vec3(getstat_int(id + 0), getstat_int(id + 1), getstat_int(id + 2))
#define _STAT(id) g_stat_##id
- #define REGISTER_STAT_2(id, type) \
- type _STAT(id); \
+ #define REGISTER_STAT_2(id, T) \
+ T _STAT(id); \
REGISTER(RegisterStats, STAT, Stats, id, m_id, new(stat)) \
{ \
make_pure(this); \
+ if (#T == "vector" || #T == "vectori") { \
+ REGISTRY_RESERVE(Stats, m_id, id, _y); \
+ REGISTRY_RESERVE(Stats, m_id, id, _z); \
+ } \
} \
[[accumulate]] void stats_get() \
{ \
- _STAT(id) = getstat_##type(STAT_##id.m_id); \
+ _STAT(id) = getstat_##T(STAT_##id.m_id); \
}
#define REGISTER_STAT_3(x, T, expr) REGISTER_STAT(x, T)
#elif defined(SVQC)
#define addstat_int(id, fld) addstat(id, AS_INT, fld)
#define addstat_bool(id, fld) addstat(id, AS_INT, fld)
#define addstat_float(id, fld) addstat(id, AS_FLOAT, fld)
+ #define addstat_vector(id, fld) do { \
+ addstat_float(id + 0, fld##_x); \
+ addstat_float(id + 1, fld##_y); \
+ addstat_float(id + 2, fld##_z); \
+ } while (0)
+ #define addstat_vectori(id, fld) do { \
+ addstat_int(id + 0, fld##_x); \
+ addstat_int(id + 1, fld##_y); \
+ addstat_int(id + 2, fld##_z); \
+ } while (0)
const int AS_STRING = 1;
const int AS_INT = 2;
const int AS_FLOAT = 8;
}
#define _STAT(id) stat_##id
- #define REGISTER_STAT_2(id, type) \
- .type _STAT(id); \
+ #define REGISTER_STAT_2(id, T) \
+ .T _STAT(id); \
REGISTER(RegisterStats, STAT, Stats, id, m_id, new(stat)) \
{ \
make_pure(this); \
+ if (#T == "vector" || #T == "vectori") { \
+ REGISTRY_RESERVE(Stats, m_id, id, _y); \
+ REGISTRY_RESERVE(Stats, m_id, id, _z); \
+ } \
} \
[[accumulate]] void stats_add() \
{ \
- addstat_##type(STAT_##id.m_id, _STAT(id)); \
+ addstat_##T(STAT_##id.m_id, _STAT(id)); \
}
void GlobalStats_update(entity this) {}
- #define REGISTER_STAT_3(x, T, expr) REGISTER_STAT(x, T); [[accumulate]] void GlobalStats_update(entity this) { STAT(x, this) = (expr); }
+ #define REGISTER_STAT_3(x, T, expr) \
+ REGISTER_STAT(x, T); \
+ [[accumulate]] void GlobalStats_update(entity this) { STAT(x, this) = (expr); } \
+ STATIC_INIT(worldstat_##x) { entity this = world; STAT(x, this) = (expr); }
#else
#define REGISTER_STAT_2(id, type)
#define REGISTER_STAT_3(x, T, expr)
#endif
-const int STATS_ENGINE_RESERVE = 32 + (8 * 3); // Not sure how to handle vector stats yet, reserve them too
+const int STATS_ENGINE_RESERVE = 32;
REGISTRY(Stats, 256 - STATS_ENGINE_RESERVE)
REGISTER_REGISTRY(RegisterStats)
if (!self.crouch)
{
self.crouch = true;
- self.view_ofs = self.stat_pl_crouch_view_ofs;
- setsize (self, self.stat_pl_crouch_min, self.stat_pl_crouch_max);
+ self.view_ofs = STAT(PL_CROUCH_VIEW_OFS, self);
+ setsize (self, STAT(PL_CROUCH_MIN, self), STAT(PL_CROUCH_MAX, self));
// setanim(self, self.anim_duck, false, true, true); // this anim is BROKEN anyway
}
}
{
if (self.crouch)
{
- tracebox(self.origin, self.stat_pl_min, self.stat_pl_max, self.origin, false, self);
+ tracebox(self.origin, STAT(PL_MIN, self), STAT(PL_MAX, self), self.origin, false, self);
if (!trace_startsolid)
{
self.crouch = false;
- self.view_ofs = self.stat_pl_view_ofs;
- setsize (self, self.stat_pl_min, self.stat_pl_max);
+ self.view_ofs = STAT(PL_VIEW_OFS, self);
+ setsize (self, STAT(PL_MIN, self), STAT(PL_MAX, self));
}
}
}
// WEAPONTODO: remove this
WepSet weaponsInMap;
-.WepSet weaponsinmap;
+#define weapons _STAT(WEAPONS)
+#define weaponsinmap _STAT(WEAPONSINMAP)
.float respawn_countdown; // next number to count
void ClientInit_Spawn();
void WeaponStats_Init();
void WeaponStats_Shutdown();
-void Physics_AddStats();
spawnfunc(worldspawn)
{
float fd, l, j, n;
WeaponStats_Init();
- WepSet_AddStat();
- WepSet_AddStat_InMap();
Nagger_Init();
- // physics
- Physics_AddStats();
-
next_pingtime = time + 5;
detect_maptype();