// needs to be done so early because of the constants they create
static_init();
CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
- CALL_ACCUMULATED_FUNCTION(RegisterMonsters);
- CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
CALL_ACCUMULATED_FUNCTION(RegisterHUD_Panels);
../common/util-pre.qh
../dpdefs/csprogsdefs.qh
+../common/util-post.qh
announcer.qc
bgmscript.qc
void RegisterBuffs();
const int BUFFS_MAX = 16;
-entity BUFFS[BUFFS_MAX];
+entity BUFFS[BUFFS_MAX], BUFFS_first, BUFFS_last;
int BUFFS_COUNT;
#define REGISTER_BUFF(id) \
- REGISTER(RegisterBuffs, BUFF, BUFFS, BUFFS_COUNT, id, Buff, m_id); \
+ REGISTER(RegisterBuffs, BUFF, BUFFS, BUFFS_COUNT, id, m_id, NEW(Buff)); \
REGISTER_INIT_POST(BUFF, id) { \
this.netname = this.m_name; \
this.m_itemid = BIT(this.m_id - 1); \
void RegisterItems();
const int MAX_ITEMS = 24;
-entity ITEMS[MAX_ITEMS];
+entity ITEMS[MAX_ITEMS], ITEMS_first, ITEMS_last;
int ITEM_COUNT;
/** If you register a new item, make sure to add it to all.inc */
-#define REGISTER_ITEM(id, class) REGISTER(RegisterItems, ITEM, ITEMS, ITEM_COUNT, id, class, m_id)
+#define REGISTER_ITEM(id, class) REGISTER(RegisterItems, ITEM, ITEMS, ITEM_COUNT, id, m_id, NEW(class))
REGISTER_REGISTRY(RegisterItems)
void Dump_Items();
string _MapInfo_GetDefaultEx(float t)
{
entity e;
- for(e = MapInfo_Type_first; e; e = e.enemy)
+ for(e = MAPINFO_TYPES_first; e; e = e.enemy)
if(t == e.items)
return e.model2;
return "";
float _MapInfo_GetTeamPlayBool(float t)
{
entity e;
- for(e = MapInfo_Type_first; e; e = e.enemy)
+ for(e = MAPINFO_TYPES_first; e; e = e.enemy)
if(t == e.items)
return e.team;
return false;
}
if(t == "all")
return MAPINFO_TYPE_ALL;
- for(e = MapInfo_Type_first; e; e = e.enemy)
+ for(e = MAPINFO_TYPES_first; e; e = e.enemy)
if(t == e.mdl)
return e.items;
return 0;
string MapInfo_Type_Description(float t)
{
entity e;
- for(e = MapInfo_Type_first; e; e = e.enemy)
+ for(e = MAPINFO_TYPES_first; e; e = e.enemy)
if(t == e.items)
return e.gametype_description;
return "";
entity e;
if(t == MAPINFO_TYPE_ALL)
return "all";
- for(e = MapInfo_Type_first; e; e = e.enemy)
+ for(e = MAPINFO_TYPES_first; e; e = e.enemy)
if(t == e.items)
return e.mdl;
return "";
string MapInfo_Type_ToText(float t)
{
entity e;
- for(e = MapInfo_Type_first; e; e = e.enemy)
+ for(e = MAPINFO_TYPES_first; e; e = e.enemy)
if(t == e.items)
return e.message;
/* xgettext:no-c-format */
else if(t == "cdtrack")
{
t = car(s); s = cdr(s);
- if(pGametypeToSet) // FIXME is this check right here?
+ // We do this only if pGametypeToSet even though this
+ // content is theoretically game type independent,
+ // because MapInfo_Map_clientstuff contains otherwise
+ // game type dependent stuff. That way this value stays
+ // empty when not setting a game type to not set any
+ // false expectations.
+ if(pGametypeToSet)
{
if (!cvar_value_issafe(t))
print("Map ", pFilename, " contains a potentially harmful cdtrack, ignored\n");
{
entity e;
int prev = cvar("gamecfg");
- for(e = MapInfo_Type_first; e; e = e.enemy)
+ for(e = MAPINFO_TYPES_first; e; e = e.enemy)
if(cvar(e.netname))
if(prev != e.items)
return e.items;
void MapInfo_SwitchGameType(int t)
{
- for (entity e = MapInfo_Type_first; e; e = e.enemy) {
+ for (entity e = MAPINFO_TYPES_first; e; e = e.enemy) {
cvar_set(e.netname, (t == e.items) ? "1" : "0");
}
}
#include "util.qh"
+CLASS(Gametype, Object)
+ ATTRIB(Gametype, m_id, int, 0)
+ /** game type ID */
+ ATTRIB(Gametype, items, int, 0)
+ /** game type name as in cvar (with g_ prefix) */
+ ATTRIB(Gametype, netname, string, string_null)
+ /** game type short name */
+ ATTRIB(Gametype, mdl, string, string_null)
+ /** human readable name */
+ ATTRIB(Gametype, message, string, string_null)
+ /** does this gametype support teamplay? */
+ ATTRIB(Gametype, team, bool, false)
+ /** game type defaults */
+ ATTRIB(Gametype, model2, string, string_null)
+ /** game type description */
+ ATTRIB(Gametype, gametype_description, string, string_null)
+ CONSTRUCTOR(Gametype, string hname, string sname, string g_name, bool gteamplay, string defaults, string gdescription)
+ {
+ CONSTRUCT(Gametype);
+ this.netname = g_name;
+ this.mdl = sname;
+ this.message = hname;
+ this.team = gteamplay;
+ this.model2 = defaults;
+ this.gametype_description = gdescription;
+ return this;
+ }
+ENDCLASS(Gametype)
+
+void RegisterGametypes();
+const int MAX_MAPINFO_TYPES = 24;
+entity MAPINFO_TYPES[MAX_MAPINFO_TYPES], MAPINFO_TYPES_first, MAPINFO_TYPES_last;
+int MAPINFO_TYPE_COUNT;
int MAPINFO_TYPE_ALL;
-entity MapInfo_Type_first;
-entity MapInfo_Type_last;
-.entity enemy; // internal next pointer
-
-.int items; // game type ID
-.string netname; // game type name as in cvar (with g_ prefix)
-.string mdl; // game type short name
-.string message; // human readable name
-.int team; // does this gametype support teamplay?
-.string model2; // game type defaults
-.string gametype_description; // game type description
-
-#define REGISTER_GAMETYPE(hname,sname,g_name,NAME,gteamplay,defaults,gdescription) \
- int MAPINFO_TYPE_##NAME; \
- entity MapInfo_Type##g_name; \
- void RegisterGametypes_##g_name() \
- { \
- MAPINFO_TYPE_##NAME = MAPINFO_TYPE_ALL + 1; \
- MAPINFO_TYPE_ALL |= MAPINFO_TYPE_##NAME; \
- MapInfo_Type##g_name = spawn(); \
- MapInfo_Type##g_name.items = MAPINFO_TYPE_##NAME; \
- MapInfo_Type##g_name.netname = #g_name; \
- MapInfo_Type##g_name.mdl = #sname; \
- MapInfo_Type##g_name.message = hname; \
- MapInfo_Type##g_name.team = gteamplay; \
- MapInfo_Type##g_name.model2 = defaults; \
- MapInfo_Type##g_name.gametype_description = gdescription; \
- if(!MapInfo_Type_first) \
- MapInfo_Type_first = MapInfo_Type##g_name; \
- if(MapInfo_Type_last) \
- MapInfo_Type_last.enemy = MapInfo_Type##g_name; \
- MapInfo_Type_last = MapInfo_Type##g_name; \
- } \
- ACCUMULATE_FUNCTION(RegisterGametypes, RegisterGametypes_##g_name)
+
+#define REGISTER_GAMETYPE(hname, sname, g_name, NAME, gteamplay, defaults, gdescription) \
+ int MAPINFO_TYPE_##NAME; \
+ REGISTER(RegisterGametypes, MAPINFO_TYPE, MAPINFO_TYPES, MAPINFO_TYPE_COUNT, g_name, m_id, \
+ NEW(Gametype, hname, #sname, #g_name, gteamplay, defaults, gdescription) \
+ ) { \
+ /* same as `1 << m_id` */ \
+ MAPINFO_TYPE_##NAME = MAPINFO_TYPE_ALL + 1; MAPINFO_TYPE_ALL |= MAPINFO_TYPE_##NAME; \
+ this.items = MAPINFO_TYPE_##NAME; \
+ }
+REGISTER_REGISTRY(RegisterGametypes)
#define IS_GAMETYPE(NAME) \
- (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
+ (MapInfo_LoadedGametype == MAPINFO_TYPE_##NAME)
REGISTER_GAMETYPE(_("Deathmatch"),dm,g_dm,DEATHMATCH,false,"timelimit=20 pointlimit=30 leadlimit=0",_("Kill all enemies"));
#define g_dm IS_GAMETYPE(DEATHMATCH)
void RegisterMonsters();
const int MON_MAXCOUNT = 24;
-entity monster_info[MON_MAXCOUNT];
+entity monster_info[MON_MAXCOUNT], monster_info_first, monster_info_last;
entity get_monsterinfo(float id);
int MON_COUNT;
const int MON_FIRST = 1;
#define MON_LAST (MON_FIRST + MON_COUNT - 1)
/** If you register a new monster, make sure to add it to all.inc */
-#define REGISTER_MONSTER(id, class) REGISTER(RegisterMonsters, MON, monster_info, MON_COUNT, id, class, monsterid)
+#define REGISTER_MONSTER(id, class) REGISTER(RegisterMonsters, MON, monster_info, MON_COUNT, id, monsterid, NEW(class))
#include "monster.qh"
#define REGISTER_MONSTER_SIMPLE(id, monsterflags, min_s, max_s, modelname, shortname, mname) \
REGISTER_MONSTER(id, Monster) { \
this.model = strzone(strcat("models/monsters/", modelname)); \
} \
REGISTER_INIT(MON, id)
+REGISTER_REGISTRY(RegisterMonsters)
#include "../util.qh"
void RegisterNades();
const int NADES_MAX = 8;
-entity NADES[NADES_MAX];
+entity NADES[NADES_MAX], NADES_first, NADES_last;
int NADES_COUNT;
-#define REGISTER_NADE(id) REGISTER(RegisterNades, NADE_TYPE, NADES, NADES_COUNT, id, Nade, m_id)
+#define REGISTER_NADE(id) REGISTER(RegisterNades, NADE_TYPE, NADES, NADES_COUNT, id, m_id, NEW(Nade))
REGISTER_REGISTRY(RegisterNades)
CLASS(Nade, Object)
#ifndef OO_H
#define OO_H
+#include "registry.qh"
+
#ifdef MENUQC
- #define NULL (null_entity)
+ #define NULL (null_entity)
#else
- #define NULL (world)
+ #define NULL (world)
#endif
.string classname;
-.string vtblname;
-.entity vtblbase;
-entity spawnVtbl(entity this, entity base)
-{
- entity vtbl = spawn();
- copyentity(this, vtbl);
- vtbl.vtblname = vtbl.classname;
- vtbl.classname = "vtbl";
- vtbl.vtblbase = base ? base : vtbl; // Top level objects use vtbl as base
- return vtbl;
+/** Location entity was spawned from in source */
+.string sourceLocFile;
+.int sourceLocLine;
+entity _spawn();
+entity __spawn(string _classname, string _sourceFile, int _sourceLine) {
+ entity this = _spawn();
+ this.classname = _classname;
+ this.sourceLocFile = _sourceFile;
+ this.sourceLocLine = _sourceLine;
+ return this;
}
-entity Object_vtbl;
-entity spawnObject(entity this, entity)
-{
- this = spawn();
- this.classname = "Object";
- if (!Object_vtbl) Object_vtbl = spawnVtbl(this, NULL);
- return this;
-}
-// Classes have a `spawn##cname(entity, entity)` constructor
-// The parameters are used as locals for [[accumulate]]
+
+#define entityclass(...) OVERLOAD(entityclass, __VA_ARGS__)
+#define entityclass_1(name) entityclass_2(name, Object)
+#ifndef QCC_SUPPORT_ENTITYCLASS
+ #define entityclass_2(name, base) typedef entity name
+ #define class(name)
+ #define new(class) __spawn(#class, __FILE__, __LINE__)
+#else
+ #define entityclass_2(name, base) entityclass name : base {}
+ #define class(name) [[class(name)]]
+ #define new(class) ((class) __spawn(#class, __FILE__, __LINE__))
+#endif
+
+// Classes have a `spawn##cname(entity)` constructor
+// The parameter is used across [[accumulate]] functions
// Macro to hide this implementation detail
-#define NEW(cname) (spawn##cname(NULL, NULL))
+#define NEW(cname, ...) \
+ OVERLOAD(spawn##cname, new(cname), ##__VA_ARGS__)
-#define CLASS(cname, base) \
-entity spawn##cname(entity this, entity basevtbl) { \
- this = NEW(base); basevtbl = base##_vtbl; \
-}
+#define CONSTRUCT(cname, ...) \
+ OVERLOAD(spawn##cname, this, ##__VA_ARGS__)
-#define METHOD(cname, name, prototype) \
-prototype cname##_##name; \
-.prototype name; \
-[[accumulate]] entity spawn##cname(entity this, entity basevtbl) { \
- this.name = cname##_##name; \
-}
+#define CONSTRUCTOR(cname, ...) \
+ cname OVERLOAD(spawn##cname, cname this, __VA_ARGS__)
-#define ATTRIB(cname, name, type, val) \
-.type name; \
-[[accumulate]] entity spawn##cname(entity this, entity basevtbl) { \
- this.name = val; \
-}
+.string vtblname;
+.entity vtblbase;
-#define ATTRIBARRAY(cname, name, type, cnt) \
-.type name[cnt];
-
-#define ENDCLASS(cname) \
-.bool instanceOf##cname; \
-entity cname##_vtbl; \
-[[accumulate]] [[last]] entity spawn##cname(entity this, entity basevtbl) { \
- this.instanceOf##cname = true; \
- this.classname = #cname; \
- if (!cname##_vtbl) cname##_vtbl = spawnVtbl(this, basevtbl); \
- return this; \
-}
+void RegisterClasses() { }
+ACCUMULATE_FUNCTION(__static_init, RegisterClasses)
+
+#define VTBL(cname, base) \
+ INIT_STATIC(cname); \
+ entity cname##_vtbl; \
+ void cname##_vtbl_init() { \
+ cname e = new(vtbl); \
+ spawn##cname##_static(e); \
+ e.vtblname = #cname; \
+ /* Top level objects refer to themselves */ \
+ e.vtblbase = base##_vtbl ? base##_vtbl : e; \
+ cname##_vtbl = e; \
+ } \
+ ACCUMULATE_FUNCTION(RegisterClasses, cname##_vtbl_init)
+
+#define INIT_STATIC(cname) [[accumulate]] void spawn##cname##_static(cname this)
+#define INIT(cname) [[accumulate]] cname spawn##cname##_1(cname this)
+
+#define CLASS(cname, base) \
+ entityclass(cname, base); \
+ class(cname) .bool instanceOf##cname; \
+ VTBL(cname, base) \
+ INIT_STATIC(cname) { \
+ if (cname##_vtbl) { \
+ copyentity(cname##_vtbl, this); \
+ return; \
+ } \
+ spawn##base##_static(this); \
+ this.instanceOf##cname = true; \
+ } \
+ INIT(cname) { \
+ /* Only statically initialize the current class, it contains everything it inherits */ \
+ if (cname##_vtbl.vtblname == this.classname) { \
+ spawn##cname##_static(this); \
+ this.classname = #cname; \
+ this.vtblname = string_null; \
+ this.vtblbase = cname##_vtbl; \
+ } \
+ spawn##base##_1(this); \
+ }
+
+#define METHOD(cname, name, prototype) \
+ class(cname) .prototype name; \
+ prototype cname##_##name; \
+ INIT_STATIC(cname) { this.name = cname##_##name; }
+
+#define ATTRIB(cname, name, type, val) \
+ class(cname) .type name; \
+ INIT(cname) { this.name = val; }
+
+#define ATTRIBARRAY(cname, name, type, cnt) \
+ class(cname) .type name[cnt];
+
+#define ENDCLASS(cname) \
+ [[last]] INIT(cname) { return this; }
#define SUPER(cname) (cname##_vtbl.vtblbase)
+#define spawn_static(this)
+#define spawn_1(this)
+#define _vtbl NULL
+CLASS(Object, ); ENDCLASS(Object)
+#undef spawn_static
+#undef spawn_1
+#undef _vtbl
+
#endif
#define REGISTRY_H
#include "oo.qh"
+#include "util.qh"
#define REGISTER_INIT(ns, id) [[accumulate]] void Register_##ns##_##id##_init(entity this)
#define REGISTER_INIT_POST(ns, id) [[accumulate]] void Register_##ns##_##id##_init_post(entity this)
-#define REGISTER(initfunc, ns, array, counter, id, class, fld) \
+#define REGISTER(initfunc, ns, array, counter, id, fld, inst) \
entity ns##_##id; \
REGISTER_INIT(ns, id) { } \
REGISTER_INIT_POST(ns, id) { } \
+ .entity enemy; /* internal next pointer */ \
void Register_##ns##_##id() { \
- entity this = NEW(class); \
+ entity this = inst; \
ns##_##id = this; \
this.fld = counter; \
array[counter++] = this; \
+ if (!array##_first) array##_first = this; \
+ if ( array##_last) array##_last.enemy = this; \
+ array##_last = this; \
Register_##ns##_##id##_init(this); \
Register_##ns##_##id##_init_post(this); \
} \
#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
#define REGISTER_REGISTRY(func) ACCUMULATE_FUNCTION(__static_init, func)
+#define STATIC_INIT(func) \
+ void _static_##func(); \
+ ACCUMULATE_FUNCTION(__static_init, _static_##func) \
+ void _static_##func()
+
#endif
--- /dev/null
+#ifndef UTIL_POST_H
+#define UTIL_POST_H
+
+#define spawn() new(entity)
+
+#include "oo.qh"
+
+#endif
const int false = 0;
#endif
-#ifndef QCC_SUPPORT_ENTITYCLASS
- #define entityclass(name) typedef entity name
- #define class(name)
- #define new(class) spawn()
-#else
- #define entityclass(name) entityclass name {}
- #define class(name) [[class(name)]]
- #define new(class) ((class) spawn())
-#endif
-
// Transitional aliases
[[deprecated("use true")]] [[alias("true")]] const bool TRUE;
[[deprecated("use false")]] [[alias("false")]] const bool FALSE;
#define TRUE _TRUE
#define FALSE _FALSE
+#define spawn _spawn
+
#include "upstream/csprogsdefs.qc"
#undef true
#undef TRUE
#undef FALSE
+#undef spawn
+
#pragma noref 0
#endif
#define TRUE _TRUE
#define FALSE _FALSE
+#define spawn _spawn
+
#include "upstream/menudefs.qc"
#undef true
#undef TRUE
#undef FALSE
+#undef spawn
+
int(string str, string sub, int startpos) _strstrofs = #221;
#define strstrofs _strstrofs
int(string str, int ofs) _str2chr = #222;
#define TRUE _TRUE
#define FALSE _FALSE
+#define spawn _spawn
+
#include "upstream/progsdefs.qc"
#undef true
#undef TRUE
#undef FALSE
+#undef spawn
+
#pragma noref 0
#endif
// needs to be done so early because of the constants they create
static_init();
CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
- CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
RegisterSLCategories();
../common/util-pre.qh
../dpdefs/menudefs.qh
../dpdefs/keycodes.qh
+../common/util-post.qh
oo/classes.qc
// needs to be done so early because of the constants they create
static_init();
CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
- CALL_ACCUMULATED_FUNCTION(RegisterMonsters);
- CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
// needs to be done so early because of the constants they create
static_init();
CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
- CALL_ACCUMULATED_FUNCTION(RegisterMonsters);
- CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
../dpdefs/progsdefs.qh
../dpdefs/dpextensions.qh
sys-post.qh
+../common/util-post.qh
anticheat.qc
antilag.qc