From: TimePath Date: Tue, 10 Nov 2015 06:29:25 +0000 (+1100) Subject: Registry: cleanup X-Git-Tag: xonotic-v0.8.2~1683 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=46ae54b152183f3e2895457f958fe830b1d97eb8;p=xonotic%2Fxonotic-data.pk3dir.git Registry: cleanup --- diff --git a/qcsrc/client/hud/hud.qh b/qcsrc/client/hud/hud.qh index 5c5a0fe96..7762d16c0 100644 --- a/qcsrc/client/hud/hud.qh +++ b/qcsrc/client/hud/hud.qh @@ -8,11 +8,11 @@ void HUD_Radar_Mouse(); REGISTRY(hud_panels, BITS(6)) #define hud_panels_from(i) _hud_panels_from(i, NULL) -REGISTER_REGISTRY(Registerhud_panels) +REGISTER_REGISTRY(hud_panels) #define REGISTER_HUD_PANEL(id, draw_func, name, configflags, showflags) \ void draw_func(); \ - REGISTER(Registerhud_panels, HUD_PANEL, hud_panels, id, m_id, new(hud_panel)) { \ + REGISTER(hud_panels, HUD_PANEL, id, m_id, new(hud_panel)) { \ make_pure(this); \ this.panel_id = this.m_id; \ this.panel_draw = draw_func; \ diff --git a/qcsrc/common/command/all.qh b/qcsrc/common/command/all.qh index 05ccb4641..d1eb3cf76 100644 --- a/qcsrc/common/command/all.qh +++ b/qcsrc/common/command/all.qh @@ -4,7 +4,7 @@ #include "command.qh" REGISTRY(GENERIC_COMMANDS, BITS(7)) #define GENERIC_COMMANDS_from(i) _GENERIC_COMMANDS_from(i, NULL) -REGISTER_REGISTRY(RegisterGENERIC_COMMANDS) +REGISTER_REGISTRY(GENERIC_COMMANDS) REGISTRY_SORT(GENERIC_COMMANDS, 0) #define GENERIC_COMMAND(id, description) \ @@ -12,7 +12,7 @@ REGISTRY_SORT(GENERIC_COMMANDS, 0) ATTRIB(genericcommand_##id, m_name, string, #id); \ ATTRIB(genericcommand_##id, m_description, string, description); \ ENDCLASS(genericcommand_##id) \ - REGISTER(RegisterGENERIC_COMMANDS, CMD_G, GENERIC_COMMANDS, id, m_id, NEW(genericcommand_##id)); \ + REGISTER(GENERIC_COMMANDS, CMD_G, id, m_id, NEW(genericcommand_##id)); \ METHOD(genericcommand_##id, m_invokecmd, void(int request, int arguments, string command)) STATIC_INIT(GENERIC_COMMANDS_aliases) { diff --git a/qcsrc/common/deathtypes/all.qh b/qcsrc/common/deathtypes/all.qh index b3a671d26..dcf64b11f 100644 --- a/qcsrc/common/deathtypes/all.qh +++ b/qcsrc/common/deathtypes/all.qh @@ -5,7 +5,7 @@ REGISTRY(Deathtypes, BITS(8)) #define Deathtypes_from(i) _Deathtypes_from(i, NULL) -REGISTER_REGISTRY(RegisterDeathtypes) +REGISTER_REGISTRY(Deathtypes) REGISTRY_CHECK(Deathtypes) .entity death_msgself; @@ -13,7 +13,7 @@ REGISTRY_CHECK(Deathtypes) .string death_msgextra; #define REGISTER_DEATHTYPE(id, msg_death, msg_death_by, extra) \ - REGISTER(RegisterDeathtypes, DEATH, Deathtypes, id, m_id, new(deathtype)) { \ + REGISTER(Deathtypes, DEATH, id, m_id, new(deathtype)) { \ make_pure(this); \ this.m_id += DT_FIRST; \ this.nent_name = #id; \ diff --git a/qcsrc/common/effects/all.qh b/qcsrc/common/effects/all.qh index 58284fb0e..e0e9a3ca8 100644 --- a/qcsrc/common/effects/all.qh +++ b/qcsrc/common/effects/all.qh @@ -10,10 +10,10 @@ void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt); REGISTRY(Effects, BITS(8)) #define Effects_from(i) _Effects_from(i, EFFECT_Null) -REGISTER_REGISTRY(RegisterEffects) +REGISTER_REGISTRY(Effects) REGISTRY_CHECK(Effects) #define EFFECT(istrail, name, realname) \ - REGISTER(RegisterEffects, EFFECT, Effects, name, m_id, Create_Effect_Entity(realname, istrail)); + REGISTER(Effects, EFFECT, name, m_id, Create_Effect_Entity(realname, istrail)); EFFECT(0, Null, string_null) #include "all.inc" diff --git a/qcsrc/common/effects/effectinfo.qc b/qcsrc/common/effects/effectinfo.qc index d6e929b20..f4df3237d 100644 --- a/qcsrc/common/effects/effectinfo.qc +++ b/qcsrc/common/effects/effectinfo.qc @@ -321,10 +321,10 @@ GENERIC_COMMAND(dumpeffectinfo, "Dump all effectinfo to effectinfo_dump.txt") REGISTRY(EffectInfos, BITS(9)) #define EffectInfos_from(i) _EffectInfos_from(i, NULL) -REGISTER_REGISTRY(RegisterEffectInfos) +REGISTER_REGISTRY(EffectInfos) #define EFFECTINFO(name) \ [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) { } \ - REGISTER(RegisterEffectInfos, EFFECTINFO, EffectInfos, name, m_id, NEW(EffectInfoGroup)) { \ + REGISTER(EffectInfos, EFFECTINFO, name, m_id, NEW(EffectInfoGroup)) { \ effectinfo_##name(this, NULL); \ } diff --git a/qcsrc/common/items/all.qh b/qcsrc/common/items/all.qh index 809398bb2..ab86ea673 100644 --- a/qcsrc/common/items/all.qh +++ b/qcsrc/common/items/all.qh @@ -7,9 +7,9 @@ REGISTRY(Items, BITS(5)) #define Items_from(i) _Items_from(i, NULL) -REGISTER_REGISTRY(RegisterItems) +REGISTER_REGISTRY(Items) /** If you register a new item, make sure to add it to all.inc */ -#define REGISTER_ITEM(id, class) REGISTER(RegisterItems, ITEM, Items, id, m_id, NEW(class)) +#define REGISTER_ITEM(id, class) REGISTER(Items, ITEM, id, m_id, NEW(class)) REGISTRY_SORT(Items, 0) REGISTRY_CHECK(Items) diff --git a/qcsrc/common/mapinfo.qh b/qcsrc/common/mapinfo.qh index 055777bf8..702798bbf 100644 --- a/qcsrc/common/mapinfo.qh +++ b/qcsrc/common/mapinfo.qh @@ -44,13 +44,13 @@ ENDCLASS(Gametype) REGISTRY(Gametypes, BITS(4)) #define Gametypes_from(i) _Gametypes_from(i, NULL) -REGISTER_REGISTRY(RegisterGametypes) +REGISTER_REGISTRY(Gametypes) REGISTRY_CHECK(Gametypes) int MAPINFO_TYPE_ALL; #define REGISTER_GAMETYPE(hname, sname, g_name, NAME, gteamplay, mutators, defaults, gdescription) \ int MAPINFO_TYPE_##NAME; \ bool NAME##_mapinfo(string k, string v) { return = false; } \ - REGISTER(RegisterGametypes, MAPINFO_TYPE, Gametypes, g_name, m_id, \ + REGISTER(Gametypes, MAPINFO_TYPE, g_name, m_id, \ NEW(Gametype, hname, #sname, #g_name, gteamplay, #sname " " mutators, defaults, gdescription) \ ) { \ /* same as `1 << m_id` */ \ diff --git a/qcsrc/common/minigames/cl_minigames.qh b/qcsrc/common/minigames/cl_minigames.qh index 6fb461c6b..f21c6e482 100644 --- a/qcsrc/common/minigames/cl_minigames.qh +++ b/qcsrc/common/minigames/cl_minigames.qh @@ -113,10 +113,10 @@ void HUD_MinigameMenu_CustomEntry(entity parent, string message, string event_ar REGISTRY(Minigames, BITS(3)) #define Minigames_from(i) _Minigames_from(i, NULL) -REGISTER_REGISTRY(RegisterMinigames) +REGISTER_REGISTRY(Minigames) REGISTRY_CHECK(Minigames) #define REGISTER_MINIGAME(name,nicename) \ - REGISTER(RegisterMinigames, MINIGAME, Minigames, name, m_id, new(minigame_descriptor)); \ + REGISTER(Minigames, MINIGAME, name, m_id, new(minigame_descriptor)); \ void name##_hud_board(vector, vector); \ void name##_hud_status(vector, vector); \ int name##_client_event(entity, string, ...); \ diff --git a/qcsrc/common/minigames/sv_minigames.qh b/qcsrc/common/minigames/sv_minigames.qh index f60b2d6db..eb6825ed6 100644 --- a/qcsrc/common/minigames/sv_minigames.qh +++ b/qcsrc/common/minigames/sv_minigames.qh @@ -48,10 +48,10 @@ bool minigame_SendEntity(entity this, entity to, int sf); REGISTRY(Minigames, BITS(3)) #define Minigames_from(i) _Minigames_from(i, NULL) -REGISTER_REGISTRY(RegisterMinigames) +REGISTER_REGISTRY(Minigames) REGISTRY_CHECK(Minigames) #define REGISTER_MINIGAME(name,nicename) \ - REGISTER(RegisterMinigames, MINIGAME, Minigames, name, m_id, new(minigame_descriptor)); \ + REGISTER(Minigames, MINIGAME, name, m_id, new(minigame_descriptor)); \ int name##_server_event(entity, string, ...); \ REGISTER_INIT_POST(MINIGAME, name) { \ make_pure(this); \ diff --git a/qcsrc/common/models/all.qh b/qcsrc/common/models/all.qh index b81567427..ac95c2c84 100644 --- a/qcsrc/common/models/all.qh +++ b/qcsrc/common/models/all.qh @@ -5,11 +5,11 @@ REGISTRY(Models, BITS(9)) #define Models_from(i) _Models_from(i, MDL_Null) -REGISTER_REGISTRY(RegisterModels) +REGISTER_REGISTRY(Models) #define MODEL(name, path) \ string MDL_##name##_get() { return path; } \ - REGISTER(RegisterModels, MDL, Models, name, m_id, NEW(Model, MDL_##name##_get)) + REGISTER(Models, MDL, name, m_id, NEW(Model, MDL_##name##_get)) PRECACHE(Models) { FOREACH(Models, true, LAMBDA({ diff --git a/qcsrc/common/monsters/all.qh b/qcsrc/common/monsters/all.qh index fd5978c91..b771984f2 100644 --- a/qcsrc/common/monsters/all.qh +++ b/qcsrc/common/monsters/all.qh @@ -8,12 +8,12 @@ string M_Model(string m_mdl); REGISTRY(Monsters, BITS(5)) #define Monsters_from(i) _Monsters_from(i, MON_Null) #define get_monsterinfo(i) Monsters_from(i) -REGISTER_REGISTRY(RegisterMonsters) +REGISTER_REGISTRY(Monsters) REGISTRY_CHECK(Monsters) const int MON_FIRST = 1; #define MON_LAST (Monsters_COUNT - 1) /** If you register a new monster, make sure to add it to all.inc */ -#define REGISTER_MONSTER(id, inst) REGISTER(RegisterMonsters, MON, Monsters, id, monsterid, inst) +#define REGISTER_MONSTER(id, inst) REGISTER(Monsters, MON, id, monsterid, inst) REGISTER_MONSTER(Null, NEW(Monster)); diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh index 07a3c8237..7cfc29789 100644 --- a/qcsrc/common/mutators/base.qh +++ b/qcsrc/common/mutators/base.qh @@ -210,7 +210,7 @@ void Mutator_Remove(Mutator mut) bool ret = MUTATORFUNCTION_##id##_hooks(mode); if (ret) return ret; \ } \ bool MUTATOR_##id##_check() { return dependence; } \ - REGISTER(RegisterMutators, MUTATOR, Mutators, id, m_id, NEW(Mutator, #id, MUTATORFUNCTION_##id)) \ + REGISTER(Mutators, MUTATOR, id, m_id, NEW(Mutator, #id, MUTATORFUNCTION_##id)) \ { this.mutatorcheck = MUTATOR_##id##_check; } \ [[accumulate]] bool MUTATORFUNCTION_##id(int mode) diff --git a/qcsrc/common/mutators/mutator/buffs/all.qh b/qcsrc/common/mutators/mutator/buffs/all.qh index 5b641f7fb..94a00b9de 100644 --- a/qcsrc/common/mutators/mutator/buffs/all.qh +++ b/qcsrc/common/mutators/mutator/buffs/all.qh @@ -13,11 +13,11 @@ REGISTER_RADARICON(Buff, 1); REGISTRY(Buffs, BITS(4)) #define Buffs_from(i) _Buffs_from(i, BUFF_Null) -REGISTER_REGISTRY(RegisterBuffs) +REGISTER_REGISTRY(Buffs) REGISTRY_CHECK(Buffs) #define REGISTER_BUFF(id) \ - REGISTER(RegisterBuffs, BUFF, Buffs, id, m_id, NEW(Buff)); \ + REGISTER(Buffs, BUFF, id, m_id, NEW(Buff)); \ REGISTER_INIT_POST(BUFF, id) { \ this.netname = this.m_name; \ this.m_itemid = BIT(this.m_id - 1); \ diff --git a/qcsrc/common/mutators/mutator/nades/nades.qh b/qcsrc/common/mutators/mutator/nades/nades.qh index a218b71a6..2e4829354 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qh +++ b/qcsrc/common/mutators/mutator/nades/nades.qh @@ -20,10 +20,10 @@ const int PROJECTILE_NADE_MONSTER_BURN = 83; REGISTRY(Nades, BITS(4)) #define Nades_from(i) _Nades_from(i, NADE_TYPE_Null) -REGISTER_REGISTRY(RegisterNades) +REGISTER_REGISTRY(Nades) REGISTRY_CHECK(Nades) -#define REGISTER_NADE(id) REGISTER(RegisterNades, NADE_TYPE, Nades, id, m_id, NEW(Nade)) +#define REGISTER_NADE(id) REGISTER(Nades, NADE_TYPE, id, m_id, NEW(Nade)) CLASS(Nade, Object) ATTRIB(Nade, m_id, int, 0) diff --git a/qcsrc/common/mutators/mutator/waypoints/all.qh b/qcsrc/common/mutators/mutator/waypoints/all.qh index b98d28a68..9693d2809 100644 --- a/qcsrc/common/mutators/mutator/waypoints/all.qh +++ b/qcsrc/common/mutators/mutator/waypoints/all.qh @@ -5,11 +5,11 @@ REGISTRY(Waypoints, BITS(6)) #define Waypoints_from(i) _Waypoints_from(i, WP_Null) -REGISTER_REGISTRY(RegisterWaypoints) +REGISTER_REGISTRY(Waypoints) REGISTRY_CHECK(Waypoints) /** If you register a new waypoint, make sure to add it to all.inc */ -#define REGISTER_WAYPOINT_(id, init) REGISTER(RegisterWaypoints, WP, Waypoints, id, m_id, init) +#define REGISTER_WAYPOINT_(id, init) REGISTER(Waypoints, WP, id, m_id, init) CLASS(Waypoint, Object) ATTRIB(Waypoint, m_id, int, 0) @@ -30,11 +30,11 @@ ENDCLASS(Waypoint) REGISTRY(RadarIcons, BITS(7)) #define RadarIcons_from(i) _RadarIcons_from(i, RADARICON_NONE) -REGISTER_REGISTRY(RegisterRadarIcons) +REGISTER_REGISTRY(RadarIcons) REGISTRY_CHECK(RadarIcons) .int m_radaricon; -#define REGISTER_RADARICON(id, num) REGISTER(RegisterRadarIcons, RADARICON, RadarIcons, id, m_id, new(RadarIcon)) { make_pure(this); this.m_radaricon = num; this.netname = #id; } +#define REGISTER_RADARICON(id, num) REGISTER(RadarIcons, RADARICON, id, m_id, new(RadarIcon)) { make_pure(this); this.m_radaricon = num; this.netname = #id; } REGISTER_WAYPOINT(Null, "", '0 0 0', 1); diff --git a/qcsrc/common/sounds/all.qh b/qcsrc/common/sounds/all.qh index e81206cd1..8225db736 100644 --- a/qcsrc/common/sounds/all.qh +++ b/qcsrc/common/sounds/all.qh @@ -5,11 +5,11 @@ REGISTRY(Sounds, BITS(8)) #define Sounds_from(i) _Sounds_from(i, SND_Null) -REGISTER_REGISTRY(RegisterSounds) +REGISTER_REGISTRY(Sounds) #define SOUND(name, path) \ string SND_##name##_get() { return path; } \ - REGISTER(RegisterSounds, SND, Sounds, name, m_id, NEW(Sound, SND_##name##_get)) + REGISTER(Sounds, SND, name, m_id, NEW(Sound, SND_##name##_get)) // Used in places where a string is required #define SND(id) Sound_fixpath(SND_##id) diff --git a/qcsrc/common/turrets/all.qh b/qcsrc/common/turrets/all.qh index fa6ef43d4..fc7940043 100644 --- a/qcsrc/common/turrets/all.qh +++ b/qcsrc/common/turrets/all.qh @@ -9,7 +9,7 @@ REGISTRY(Turrets, BITS(5)) #define Turrets_from(i) _Turrets_from(i, TUR_Null) #define get_turretinfo(i) Turrets_from(i) -REGISTER_REGISTRY(RegisterTurrets) +REGISTER_REGISTRY(Turrets) REGISTRY_CHECK(Turrets) @@ -70,7 +70,7 @@ GENERIC_COMMAND(dumpturrets, "Dump all turrets into turrets_dump.txt") const int TUR_FIRST = 1; #define TUR_LAST (Turrets_COUNT - 1) -#define REGISTER_TURRET(id, inst) REGISTER(RegisterTurrets, TUR, Turrets, id, m_id, inst) +#define REGISTER_TURRET(id, inst) REGISTER(Turrets, TUR, id, m_id, inst) REGISTER_TURRET(Null, NEW(Turret)); diff --git a/qcsrc/common/vehicles/all.qh b/qcsrc/common/vehicles/all.qh index d2d943c4e..3867cf1ed 100644 --- a/qcsrc/common/vehicles/all.qh +++ b/qcsrc/common/vehicles/all.qh @@ -6,14 +6,14 @@ REGISTRY(Vehicles, BITS(3)) #define Vehicles_from(i) _Vehicles_from(i, VEH_Null) #define get_vehicleinfo(i) Vehicles_from(i) -REGISTER_REGISTRY(RegisterVehicles) +REGISTER_REGISTRY(Vehicles) REGISTRY_CHECK(Vehicles) const int VEH_FIRST = 1; #define VEH_LAST (Vehicles_COUNT - 1) /** If you register a new vehicle, make sure to add it to all.inc */ -#define REGISTER_VEHICLE(id, inst) REGISTER(RegisterVehicles, VEH, Vehicles, id, vehicleid, inst) +#define REGISTER_VEHICLE(id, inst) REGISTER(Vehicles, VEH, id, vehicleid, inst) #if defined(SVQC) #include "sv_vehicles.qh" diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index af2795064..93df313c0 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -37,7 +37,7 @@ WepSet ReadWepSet(); REGISTRY(Weapons, 72) // Increase as needed. Can be up to 72. #define Weapons_from(i) _Weapons_from(i, WEP_Null) #define get_weaponinfo(i) Weapons_from(i) -REGISTER_REGISTRY(RegisterWeapons) +REGISTER_REGISTRY(Weapons) STATIC_INIT(WeaponPickup) { FOREACH(Weapons, true, LAMBDA(it.m_pickup = NEW(WeaponPickup, it))); } @@ -96,7 +96,7 @@ GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPON #define REGISTER_WEAPON(id, inst) \ /* WepSet WEPSET_##id; */ \ - REGISTER(RegisterWeapons, WEP, Weapons, id, m_id, inst) + REGISTER(Weapons, WEP, id, m_id, inst) // create cvars for weapon settings #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name; diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index f6013f97a..07385b092 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -92,7 +92,7 @@ this.sourceLocFile = __FILE__; \ this.sourceLocLine = __LINE__; \ } \ - REGISTER(RegisterLinkedEntities, NET, LinkedEntities, id, m_id, new(net_linked_packet)) \ + REGISTER(LinkedEntities, NET, id, m_id, new(net_linked_packet)) \ { \ make_pure(this); \ this.netname = #id; \ @@ -101,7 +101,7 @@ #else #define REGISTER_NET_LINKED(id) \ const bool NET_##id##_istemp = false; \ - REGISTER(RegisterLinkedEntities, NET, LinkedEntities, id, m_id, new(net_linked_packet)) \ + REGISTER(LinkedEntities, NET, id, m_id, new(net_linked_packet)) \ { \ make_pure(this); \ this.netname = #id; \ @@ -110,7 +110,7 @@ REGISTRY(LinkedEntities, BITS(8) - 1) #define LinkedEntities_from(i) _LinkedEntities_from(i, NULL) -REGISTER_REGISTRY(RegisterLinkedEntities) +REGISTER_REGISTRY(LinkedEntities) REGISTRY_SORT(LinkedEntities, 0) REGISTRY_CHECK(LinkedEntities) STATIC_INIT(RegisterLinkedEntities_renumber) @@ -122,7 +122,7 @@ STATIC_INIT(RegisterLinkedEntities_renumber) #ifdef CSQC #define REGISTER_NET_TEMP(id) \ NET_HANDLE(id, bool); \ - REGISTER(RegisterTempEntities, NET, TempEntities, id, m_id, new(net_temp_packet)) \ + REGISTER(TempEntities, NET, id, m_id, new(net_temp_packet)) \ { \ make_pure(this); \ this.netname = #id; \ @@ -131,7 +131,7 @@ STATIC_INIT(RegisterLinkedEntities_renumber) #else #define REGISTER_NET_TEMP(id) \ const bool NET_##id##_istemp = true; \ - REGISTER(RegisterTempEntities, NET, TempEntities, id, m_id, new(net_temp_packet)) \ + REGISTER(TempEntities, NET, id, m_id, new(net_temp_packet)) \ { \ make_pure(this); \ this.netname = #id; \ @@ -140,7 +140,7 @@ STATIC_INIT(RegisterLinkedEntities_renumber) REGISTRY(TempEntities, BITS(8) - 80) #define TempEntities_from(i) _TempEntities_from(i, NULL) -REGISTER_REGISTRY(RegisterTempEntities) +REGISTER_REGISTRY(TempEntities) REGISTRY_SORT(TempEntities, 0) REGISTRY_CHECK(TempEntities) STATIC_INIT(RegisterTempEntities_renumber) diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index 59ddf25ff..52ab23377 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -3,11 +3,12 @@ #include "oo.qh" -#define REGISTER_REGISTRY(func) ACCUMULATE_FUNCTION(__static_init, func) - -#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) - +/** + * Declare a new registry. + * + * Don't forget to call `REGISTER_REGISTRY`: + * REGISTER_REGISTRY(Foos) + */ #define REGISTRY(id, max) \ void Register##id() {} \ const int id##_MAX = max; \ @@ -15,52 +16,53 @@ int id##_COUNT; \ entity _##id##_from(int i, entity null) { if (i >= 0 && i < id##_COUNT) { entity e = _##id[i]; if (e) return e; } return null; } +REGISTRY(Registries, BITS(8)) + /** registered item identifier */ .string registered_id; /** - * Register a new entity with a global constructor. + * Register a new entity with a registry. * Must be followed by a semicolon or a function body with a `this` parameter. * Wrapper macros may perform actions after user initialization like so: * #define REGISTER_FOO(id) \ - * REGISTER(RegisterFoos, FOO, FOOS, id, m_id, NEW(Foo)); \ + * REGISTER(Foos, FOO, id, m_id, NEW(Foo)); \ * REGISTER_INIT_POST(FOO, id) { \ * print("Registering foo #", this.m_id + 1, "\n"); \ * } \ * REGISTER_INIT(FOO, id) * - * Don't forget to forward declare `initfunc` and call `REGISTER_REGISTRY`: - * void RegisterFoos(); - * REGISTER_REGISTRY(RegisterFoos) * - * @param initfunc The global constructor to accumulate into + * @param registry The registry to add each entity to. * @param ns Short for namespace, prefix for each global (ns##_##id) - * @param array The array to add each entity to. Also requires `array##_first` and `array##_last` to be defined * @param id The identifier of the current entity being registered - * @param fld The field to store the current count into + * @param fld The field to store the locally unique unique entity id * @param inst An expression to create a new instance, invoked for every registration */ -#define REGISTER(initfunc, ns, array, id, fld, inst) \ +#define REGISTER(registry, ns, id, fld, inst) \ entity ns##_##id; \ REGISTER_INIT(ns, id) {} \ REGISTER_INIT_POST(ns, id) {} \ void Register_##ns##_##id() \ { \ - if (array##_COUNT >= array##_MAX) LOG_FATALF("Registry capacity exceeded (%s)", ftos(array##_MAX)); \ - entity this = inst; \ - ns##_##id = this; \ + if (registry##_COUNT >= registry##_MAX) LOG_FATALF("Registry capacity exceeded (%s)", ftos(registry##_MAX)); \ + entity this = ns##_##id = inst; \ 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; \ + this.fld = registry##_COUNT; \ + _##registry[registry##_COUNT] = this; \ + ++registry##_COUNT; \ + if (!registry##_first) registry##_first = this; \ + if (registry##_last) registry##_last.REGISTRY_NEXT = this; \ + registry##_last = this; \ Register_##ns##_##id##_init(this); \ Register_##ns##_##id##_init_post(this); \ } \ - ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id) \ + ACCUMULATE_FUNCTION(Register##registry, Register_##ns##_##id) \ REGISTER_INIT(ns, id) +#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) + /** internal next pointer */ #define REGISTRY_NEXT enemy .entity REGISTRY_NEXT; @@ -119,7 +121,7 @@ void Registry_send(string id, string hash); string h = REGISTRY_HASH(id) = strzone(digest_hex(algo, s)); \ LOG_TRACEF(#id ": %s\n[%s]\n", h, s); \ } \ - [[accumulate]] void Registry_check(string r, string sv) \ + void Registry_check(string r, string sv) \ { \ if (r == #id) \ { \ @@ -130,6 +132,17 @@ void Registry_send(string id, string hash); } \ } \ } \ - [[accumulate]] void Registry_send_all() { Registry_send(#id, REGISTRY_HASH(id)); } \ + void Registry_send_all() { Registry_send(#id, REGISTRY_HASH(id)); } \ + +#define REGISTER_REGISTRY(...) EVAL(OVERLOAD(REGISTER_REGISTRY, __VA_ARGS__)) +#define REGISTER_REGISTRY_1(id) REGISTER_REGISTRY_2(id, #id) +#define REGISTER_REGISTRY_2(id, str) \ + ACCUMULATE_FUNCTION(__static_init, Register##id) \ + CLASS(id##Registry, Object) \ + ATTRIB(id##Registry, m_name, string, str) \ + ATTRIB(id##Registry, REGISTRY_NEXT, entity, id##_first) \ + ENDCLASS(id##Registry) \ + REGISTER(Registries, REGISTRY, id, m_id, NEW(id##Registry)); + #endif diff --git a/qcsrc/lib/stats.qh b/qcsrc/lib/stats.qh index f522023ef..7dd2706fd 100644 --- a/qcsrc/lib/stats.qh +++ b/qcsrc/lib/stats.qh @@ -20,7 +20,7 @@ #define _STAT(id) g_stat_##id #define REGISTER_STAT(id, type) \ type _STAT(id); \ - REGISTER(RegisterStats, STAT, Stats, id, m_id, new(stat)) \ + REGISTER(Stats, STAT, id, m_id, new(stat)) \ { \ make_pure(this); \ } \ @@ -43,7 +43,7 @@ #define _STAT(id) stat_##id #define REGISTER_STAT(id, type) \ .type _STAT(id); \ - REGISTER(RegisterStats, STAT, Stats, id, m_id, new(stat)) \ + REGISTER(Stats, STAT, id, m_id, new(stat)) \ { \ make_pure(this); \ } \ @@ -58,7 +58,7 @@ const int STATS_ENGINE_RESERVE = 32 + (8 * 3); // Not sure how to handle vector stats yet, reserve them too REGISTRY(Stats, 220 - STATS_ENGINE_RESERVE) -REGISTER_REGISTRY(RegisterStats) +REGISTER_REGISTRY(Stats) REGISTRY_SORT(Stats, 0) REGISTRY_CHECK(Stats) STATIC_INIT(RegisterStats_renumber) diff --git a/qcsrc/menu/gamesettings.qh b/qcsrc/menu/gamesettings.qh index 24a40edf0..0db9f77f2 100644 --- a/qcsrc/menu/gamesettings.qh +++ b/qcsrc/menu/gamesettings.qh @@ -6,10 +6,10 @@ REGISTRY(Settings, BITS(3)) #define Settings_from(i) _Settings_from(i, NULL) -REGISTER_REGISTRY(RegisterSettings) +REGISTER_REGISTRY(Settings) #define REGISTER_SETTINGS(id, impl) \ LAZY_NEW(id, impl) \ - REGISTER(RegisterSettings, MENU, Settings, id, m_id, NEW(Lazy, LAZY(id))) + REGISTER(Settings, MENU, id, m_id, NEW(Lazy, LAZY(id))) #endif #endif diff --git a/qcsrc/server/cl_player.qh b/qcsrc/server/cl_player.qh index b74b6f01c..76c49d852 100644 --- a/qcsrc/server/cl_player.qh +++ b/qcsrc/server/cl_player.qh @@ -103,12 +103,12 @@ void VoiceMessage(string type, string msg); REGISTRY(GlobalSounds, BITS(8) - 1) #define GlobalSounds_from(i) _GlobalSounds_from(i, NULL) #define REGISTER_GLOBALSOUND(id, str) \ - REGISTER(RegisterGlobalSounds, GS, GlobalSounds, id, m_id, new(GlobalSound)) \ + REGISTER(GlobalSounds, GS, id, m_id, new(GlobalSound)) \ { \ make_pure(this); \ this.m_globalsoundstr = str; \ } -REGISTER_REGISTRY(RegisterGlobalSounds) +REGISTER_REGISTRY(GlobalSounds) REGISTRY_SORT(GlobalSounds, 0) REGISTRY_CHECK(GlobalSounds) PRECACHE(GlobalSounds)