From: TimePath Date: Wed, 7 Oct 2015 01:43:32 +0000 (+1100) Subject: Registry: overflow check X-Git-Tag: xonotic-v0.8.2~1859 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=45713cbd76a882a667d0dcaa2ed234fb06b556c5;p=xonotic%2Fxonotic-data.pk3dir.git Registry: overflow check --- diff --git a/qcsrc/client/weapons/projectile.qc b/qcsrc/client/weapons/projectile.qc index fc08f7ffd..9d23e3cab 100644 --- a/qcsrc/client/weapons/projectile.qc +++ b/qcsrc/client/weapons/projectile.qc @@ -47,7 +47,7 @@ void Projectile_DrawTrail(vector to) if (self.traileffect) { particles_alphamin = particles_alphamax = particles_fade = sqrt(self.alpha); - boxparticles(particleeffectnum(effects_ent[self.traileffect]), self, from, to, self.velocity, self.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL); + boxparticles(particleeffectnum(Effects[self.traileffect]), self, from, to, self.velocity, self.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL); } } diff --git a/qcsrc/common/buffs/all.qh b/qcsrc/common/buffs/all.qh index 4cf371baa..709903470 100644 --- a/qcsrc/common/buffs/all.qh +++ b/qcsrc/common/buffs/all.qh @@ -8,11 +8,11 @@ #include "../teams.qh" #include "../util.qh" -REGISTRY(Buffs, 16) +REGISTRY(Buffs, BIT(4)) REGISTER_REGISTRY(RegisterBuffs) #define REGISTER_BUFF(id) \ - REGISTER(RegisterBuffs, BUFF, Buffs, Buffs_COUNT, id, m_id, NEW(Buff)); \ + REGISTER(RegisterBuffs, BUFF, Buffs, 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/effects/effectinfo.qc b/qcsrc/common/effects/effectinfo.qc index 932ce9b72..731903b63 100644 --- a/qcsrc/common/effects/effectinfo.qc +++ b/qcsrc/common/effects/effectinfo.qc @@ -284,20 +284,13 @@ void effectinfo_dump(int fh, bool alsoprint) } -void RegisterEffectInfo(); -const int MAX_EFFECTINFOS = 512; -entity EFFECTINFOS[MAX_EFFECTINFOS], EFFECTINFOS_first, EFFECTINFOS_last; -int EFFECTINFOS_COUNT; - +REGISTRY(EffectInfos, BIT(9)) +REGISTER_REGISTRY(RegisterEffectInfos) #define EFFECTINFO(name) \ [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) { } \ - REGISTER(RegisterEffectInfo, EFFECTINFO, EFFECTINFOS, EFFECTINFOS_COUNT, name, m_id, NEW(EffectInfoGroup)) { \ + REGISTER(RegisterEffectInfos, EFFECTINFO, EffectInfos, name, m_id, NEW(EffectInfoGroup)) { \ effectinfo_##name(this, NULL); \ } -REGISTER_REGISTRY(RegisterEffectInfo) - - -#define REGISTER_EFFECTINFO(id) var void effectinfo_##id(EffectInfoGroup parent) #define MY(f) this.effectinfo_##f #define DEF(name) EFFECTINFO(name) diff --git a/qcsrc/common/effects/effects.qc b/qcsrc/common/effects/effects.qc index dd015e0f6..78bb6755a 100644 --- a/qcsrc/common/effects/effects.qc +++ b/qcsrc/common/effects/effects.qc @@ -1,9 +1,9 @@ #ifdef CSQC void Read_Effect(bool is_new) { - int net_name = (EFFECT_COUNT >= 255) ? ReadShort() : ReadByte(); + int net_name = (Effects_COUNT >= 255) ? ReadShort() : ReadByte(); - entity eff = effects_ent[net_name]; + entity eff = Effects[net_name]; vector v, vel = '0 0 0'; int eff_cnt = 1; @@ -37,7 +37,7 @@ void Read_Effect(bool is_new) bool Net_Write_Effect(entity this, entity client, int sf) { WriteByte(MSG_ENTITY, ENT_CLIENT_EFFECT); - (EFFECT_COUNT >= 255) + (Effects_COUNT >= 255) ? WriteShort(MSG_ENTITY, self.m_id) : WriteByte(MSG_ENTITY, self.m_id); WriteCoord(MSG_ENTITY, self.eent_net_location_x); @@ -81,7 +81,7 @@ void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt) void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt) { // problem with this is, we might not have all the available effects for it - FOREACH(effects_ent, it.eent_eff_name == eff_name, LAMBDA( + FOREACH(Effects, it.eent_eff_name == eff_name, LAMBDA( Send_Effect(it, eff_loc, eff_vel, eff_cnt); return; )); diff --git a/qcsrc/common/effects/effects.qh b/qcsrc/common/effects/effects.qh index a1102e96a..21821758c 100644 --- a/qcsrc/common/effects/effects.qh +++ b/qcsrc/common/effects/effects.qh @@ -10,14 +10,10 @@ void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt); #define particleeffectnum(e) _particleeffectnum(e.eent_eff_name) -void RegisterEffects(); -const int MAX_EFFECTS = 512; -entity effects_ent[MAX_EFFECTS], effects_ent_first, effects_ent_last; -int EFFECT_COUNT; - -#define EFFECT(istrail, name, realname) \ - REGISTER(RegisterEffects, EFFECT, effects_ent, EFFECT_COUNT, name, m_id, Create_Effect_Entity(realname, istrail)); +REGISTRY(Effects, BIT(8)) REGISTER_REGISTRY(RegisterEffects) +#define EFFECT(istrail, name, realname) \ + REGISTER(RegisterEffects, EFFECT, Effects, name, m_id, Create_Effect_Entity(realname, istrail)); .int m_id; .string eent_eff_name; diff --git a/qcsrc/common/items/all.qh b/qcsrc/common/items/all.qh index 8097ab50f..672ed707c 100644 --- a/qcsrc/common/items/all.qh +++ b/qcsrc/common/items/all.qh @@ -3,10 +3,10 @@ #include "item.qh" -REGISTRY(Items, 24) +REGISTRY(Items, BIT(5)) REGISTER_REGISTRY(RegisterItems) /** If you register a new item, make sure to add it to all.inc */ -#define REGISTER_ITEM(id, class) REGISTER(RegisterItems, ITEM, Items, Items_COUNT, id, m_id, NEW(class)) +#define REGISTER_ITEM(id, class) REGISTER(RegisterItems, ITEM, Items, id, m_id, NEW(class)) void Dump_Items(); diff --git a/qcsrc/common/mapinfo.qc b/qcsrc/common/mapinfo.qc index 8c898cc54..ba21ff43d 100644 --- a/qcsrc/common/mapinfo.qc +++ b/qcsrc/common/mapinfo.qc @@ -602,13 +602,13 @@ void _MapInfo_Map_ApplyGametype(string s, int pWantedType, int pThisType, int lo string _MapInfo_GetDefaultEx(float t) { - FOREACH(MAPINFO_TYPES, it.items == t, LAMBDA(return it.model2)); + FOREACH(Gametypes, it.items == t, LAMBDA(return it.model2)); return ""; } float _MapInfo_GetTeamPlayBool(float t) { - FOREACH(MAPINFO_TYPES, it.items == t, LAMBDA(return it.team)); + FOREACH(Gametypes, it.items == t, LAMBDA(return it.team)); return false; } @@ -723,14 +723,14 @@ int MapInfo_Type_FromString(string t) deprecate(assault, as); deprecate(race, rc); if (t == "all") return MAPINFO_TYPE_ALL; - FOREACH(MAPINFO_TYPES, it.mdl == t, LAMBDA(return it.items)); + FOREACH(Gametypes, it.mdl == t, LAMBDA(return it.items)); return 0; #undef deprecate } string MapInfo_Type_Description(float t) { - FOREACH(MAPINFO_TYPES, it.items == t, LAMBDA(return it.gametype_description)); + FOREACH(Gametypes, it.items == t, LAMBDA(return it.gametype_description)); return ""; } @@ -738,13 +738,13 @@ string MapInfo_Type_ToString(float t) { if(t == MAPINFO_TYPE_ALL) return "all"; - FOREACH(MAPINFO_TYPES, it.items == t, LAMBDA(return it.mdl)); + FOREACH(Gametypes, it.items == t, LAMBDA(return it.mdl)); return ""; } string MapInfo_Type_ToText(float t) { - FOREACH(MAPINFO_TYPES, it.items == t, LAMBDA(return it.message)); + FOREACH(Gametypes, it.items == t, LAMBDA(return it.message)); /* xgettext:no-c-format */ return _("@!#%'n Tuba Throwing"); } @@ -1249,7 +1249,7 @@ int MapInfo_CurrentFeatures() int MapInfo_CurrentGametype() { int prev = cvar("gamecfg"); - FOREACH(MAPINFO_TYPES, cvar(it.netname) && it.items != prev, LAMBDA(return it.items)); + FOREACH(Gametypes, cvar(it.netname) && it.items != prev, LAMBDA(return it.items)); if (prev) return prev; return MAPINFO_TYPE_DEATHMATCH; } @@ -1275,7 +1275,7 @@ float MapInfo_CheckMap(string s) // returns 0 if the map can't be played with th void MapInfo_SwitchGameType(int t) { - FOREACH(MAPINFO_TYPES, true, LAMBDA( + FOREACH(Gametypes, true, LAMBDA( cvar_set(it.netname, (it.items == t) ? "1" : "0") )); } diff --git a/qcsrc/common/mapinfo.qh b/qcsrc/common/mapinfo.qh index 19799df74..6faef6e05 100644 --- a/qcsrc/common/mapinfo.qh +++ b/qcsrc/common/mapinfo.qh @@ -38,22 +38,18 @@ CLASS(Gametype, Object) } 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; +REGISTRY(Gametypes, BIT(4)) +REGISTER_REGISTRY(RegisterGametypes) int MAPINFO_TYPE_ALL; - #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, \ + REGISTER(RegisterGametypes, MAPINFO_TYPE, Gametypes, 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) diff --git a/qcsrc/common/minigames/cl_minigames.qh b/qcsrc/common/minigames/cl_minigames.qh index 76d109864..a073af897 100644 --- a/qcsrc/common/minigames/cl_minigames.qh +++ b/qcsrc/common/minigames/cl_minigames.qh @@ -116,12 +116,10 @@ void HUD_MinigameMenu_CustomEntry(entity parent, string message, string event_ar while( (entityvar = findentity(entityvar,owner,active_minigame)) ) -void RegisterMinigames(); -const int MINIGAMES_MAX = 24; -entity MINIGAMES[MINIGAMES_MAX], MINIGAMES_first, MINIGAMES_last; -int MINIGAMES_COUNT; +REGISTRY(Minigames, BIT(3)) +REGISTER_REGISTRY(RegisterMinigames) #define REGISTER_MINIGAME(name,nicename) \ - REGISTER(RegisterMinigames, MINIGAME, MINIGAMES, MINIGAMES_COUNT, name, m_id, spawn()); \ + REGISTER(RegisterMinigames, MINIGAME, Minigames, name, m_id, spawn()); \ void name##_hud_board(vector, vector); \ void name##_hud_status(vector, vector); \ int name##_client_event(entity, string, ...); \ @@ -134,6 +132,5 @@ int MINIGAMES_COUNT; this.minigame_event = name##_client_event; \ } \ REGISTER_INIT(MINIGAME, name) -REGISTER_REGISTRY(RegisterMinigames) #endif diff --git a/qcsrc/common/minigames/cl_minigames_hud.qc b/qcsrc/common/minigames/cl_minigames_hud.qc index b0dba86c1..2a0b03620 100644 --- a/qcsrc/common/minigames/cl_minigames_hud.qc +++ b/qcsrc/common/minigames/cl_minigames_hud.qc @@ -213,7 +213,7 @@ void HUD_MinigameMenu_ClickCreate() { entity curr; entity prev = self; - FOREACH(MINIGAMES, true, LAMBDA( + FOREACH(Minigames, true, LAMBDA( { curr = HUD_MinigameMenu_SpawnSubEntry( it.message, HUD_MinigameMenu_ClickCreate_Entry, self ); diff --git a/qcsrc/common/minigames/minigames.qc b/qcsrc/common/minigames/minigames.qc index 6a24d37ad..bc854952e 100644 --- a/qcsrc/common/minigames/minigames.qc +++ b/qcsrc/common/minigames/minigames.qc @@ -2,7 +2,7 @@ entity minigame_get_descriptor(string id) { - FOREACH(MINIGAMES, true, LAMBDA( + FOREACH(Minigames, true, LAMBDA( { if(it.netname == id) return it; diff --git a/qcsrc/common/minigames/sv_minigames.qc b/qcsrc/common/minigames/sv_minigames.qc index 7a428d8d0..c06e23c9c 100644 --- a/qcsrc/common/minigames/sv_minigames.qc +++ b/qcsrc/common/minigames/sv_minigames.qc @@ -350,7 +350,7 @@ void ClientCommand_minigame(int request, int argc, string command) } else if ( minig_cmd == "list" ) { - FOREACH(MINIGAMES, true, LAMBDA( + FOREACH(Minigames, true, LAMBDA( { sprint(self,it.netname," (",it.message,") ","\n"); })); diff --git a/qcsrc/common/minigames/sv_minigames.qh b/qcsrc/common/minigames/sv_minigames.qh index f00605316..e36d690d9 100644 --- a/qcsrc/common/minigames/sv_minigames.qh +++ b/qcsrc/common/minigames/sv_minigames.qh @@ -46,12 +46,10 @@ entity minigame_sessions; bool minigame_SendEntity(entity this, entity to, int sf); -void RegisterMinigames(); -const int MINIGAMES_MAX = 24; -entity MINIGAMES[MINIGAMES_MAX], MINIGAMES_first, MINIGAMES_last; -int MINIGAMES_COUNT; +REGISTRY(Minigames, BIT(3)) +REGISTER_REGISTRY(RegisterMinigames) #define REGISTER_MINIGAME(name,nicename) \ - REGISTER(RegisterMinigames, MINIGAME, MINIGAMES, MINIGAMES_COUNT, name, m_id, spawn()); \ + REGISTER(RegisterMinigames, MINIGAME, Minigames, name, m_id, spawn()); \ int name##_server_event(entity, string, ...); \ REGISTER_INIT_POST(MINIGAME, name) { \ this.classname = "minigame_descriptor"; \ @@ -60,6 +58,5 @@ int MINIGAMES_COUNT; this.minigame_event = name##_server_event; \ } \ REGISTER_INIT(MINIGAME, name) -REGISTER_REGISTRY(RegisterMinigames) #endif diff --git a/qcsrc/common/models/all.qh b/qcsrc/common/models/all.qh index 0f9464431..38c533449 100644 --- a/qcsrc/common/models/all.qh +++ b/qcsrc/common/models/all.qh @@ -3,7 +3,7 @@ #define setmodel(e, m) _setmodel((e), (m).model_str()) -REGISTRY(Models, 128) +REGISTRY(Models, BIT(9)) REGISTER_REGISTRY(RegisterModels) CLASS(Model, Object) @@ -27,7 +27,7 @@ ENDCLASS(Model) #define MODEL(name, path) \ string MDL_##name##_get() { return path; } \ - REGISTER(RegisterModels, MDL, Models, Models_COUNT, name, m_id, NEW(Model, MDL_##name##_get)) + REGISTER(RegisterModels, MDL, Models, name, m_id, NEW(Model, MDL_##name##_get)) STATIC_INIT(RegisterModels_precache) { FOREACH(Models, true, LAMBDA({ diff --git a/qcsrc/common/monsters/all.qh b/qcsrc/common/monsters/all.qh index f31e976d6..39a928a85 100644 --- a/qcsrc/common/monsters/all.qh +++ b/qcsrc/common/monsters/all.qh @@ -3,12 +3,12 @@ #include "monster.qh" -REGISTRY(Monsters, 24) +REGISTRY(Monsters, BIT(3)) REGISTER_REGISTRY(RegisterMonsters) 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, Monsters_COUNT, id, monsterid, inst) +#define REGISTER_MONSTER(id, inst) REGISTER(RegisterMonsters, MON, Monsters, id, monsterid, inst) REGISTER_MONSTER(Null, NEW(Monster)); diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh index 6fa77a858..9a535a296 100644 --- a/qcsrc/common/mutators/base.qh +++ b/qcsrc/common/mutators/base.qh @@ -220,7 +220,7 @@ noref int MUTATORS_COUNT; bool ret = MUTATORFUNCTION_##id##_hooks(mode); if (ret) return ret; \ } \ bool MUTATOR_##id##_check() { return dependence; } \ - REGISTER(RegisterMutators, MUTATOR, MUTATORS, MUTATORS_COUNT, id, m_id, NEW(Mutator, #id, MUTATORFUNCTION_##id)) \ + REGISTER(RegisterMutators, MUTATOR, MUTATORS, 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/waypoints/all.qh b/qcsrc/common/mutators/mutator/waypoints/all.qh index 790d08698..6120888db 100644 --- a/qcsrc/common/mutators/mutator/waypoints/all.qh +++ b/qcsrc/common/mutators/mutator/waypoints/all.qh @@ -3,13 +3,10 @@ #include "waypointsprites.qh" -void RegisterWaypoints(); -const int MAX_WAYPOINTS = 240; -entity WAYPOINTS[MAX_WAYPOINTS], WAYPOINTS_first, WAYPOINTS_last; -int WAYPOINT_COUNT; -/** If you register a new waypoint, make sure to add it to all.inc */ -#define REGISTER_WAYPOINT_(id, init) REGISTER(RegisterWaypoints, WP, WAYPOINTS, WAYPOINT_COUNT, id, m_id, init) +REGISTRY(Waypoints, BIT(6)) REGISTER_REGISTRY(RegisterWaypoints) +/** 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) CLASS(Waypoint, Object) ATTRIB(Waypoint, m_id, int, 0) diff --git a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc index bd4be8d75..89f9a0f0f 100644 --- a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc +++ b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc @@ -259,7 +259,7 @@ string spritelookuptext(string s) if (s == WP_Monster.netname) return get_monsterinfo(self.wp_extra).monster_name; // need to loop, as our netname could be one of three - FOREACH(WAYPOINTS, it.netname == s, LAMBDA( + FOREACH(Waypoints, it.netname == s, LAMBDA( return it.m_name; )); diff --git a/qcsrc/common/nades/all.qh b/qcsrc/common/nades/all.qh index 84b390043..ad51a1e55 100644 --- a/qcsrc/common/nades/all.qh +++ b/qcsrc/common/nades/all.qh @@ -21,9 +21,9 @@ const int PROJECTILE_NADE_HEAL_BURN = 81; const int PROJECTILE_NADE_MONSTER = 82; const int PROJECTILE_NADE_MONSTER_BURN = 83; -REGISTRY(Nades, 8) +REGISTRY(Nades, BIT(3)) REGISTER_REGISTRY(RegisterNades) -#define REGISTER_NADE(id) REGISTER(RegisterNades, NADE_TYPE, Nades, Nades_COUNT, id, m_id, NEW(Nade)) +#define REGISTER_NADE(id) REGISTER(RegisterNades, NADE_TYPE, Nades, id, m_id, NEW(Nade)) CLASS(Nade, Object) ATTRIB(Nade, m_id, int, 0) diff --git a/qcsrc/common/sounds/all.qh b/qcsrc/common/sounds/all.qh index d567d0a44..90858f39d 100644 --- a/qcsrc/common/sounds/all.qh +++ b/qcsrc/common/sounds/all.qh @@ -18,7 +18,7 @@ // Used in places where a string is required #define SND(id) (SND_##id.sound_str()) -REGISTRY(Sounds, 128) +REGISTRY(Sounds, BIT(8)) REGISTER_REGISTRY(RegisterSounds) CLASS(Sound, Object) @@ -42,7 +42,7 @@ ENDCLASS(Sound) #define SOUND(name, path) \ string SND_##name##_get() { return path; } \ - REGISTER(RegisterSounds, SND, Sounds, Sounds_COUNT, name, m_id, NEW(Sound, SND_##name##_get)) + REGISTER(RegisterSounds, SND, Sounds, name, m_id, NEW(Sound, SND_##name##_get)) STATIC_INIT(RegisterSounds_precache) { FOREACH(Sounds, true, LAMBDA({ diff --git a/qcsrc/common/turrets/all.qh b/qcsrc/common/turrets/all.qh index eb001bd4a..2b9a87d42 100644 --- a/qcsrc/common/turrets/all.qh +++ b/qcsrc/common/turrets/all.qh @@ -3,12 +3,12 @@ #include "turret.qh" -REGISTRY(Turrets, 24) +REGISTRY(Turrets, BIT(5)) REGISTER_REGISTRY(RegisterTurrets) const int TUR_FIRST = 1; #define TUR_LAST (Turrets_COUNT - 1) -#define REGISTER_TURRET(id, inst) REGISTER(RegisterTurrets, TUR, Turrets, Turrets_COUNT, id, m_id, inst) +#define REGISTER_TURRET(id, inst) REGISTER(RegisterTurrets, TUR, Turrets, id, m_id, inst) REGISTER_TURRET(Null, NEW(Turret)); diff --git a/qcsrc/common/vehicles/all.qh b/qcsrc/common/vehicles/all.qh index 706585597..a44eb2209 100644 --- a/qcsrc/common/vehicles/all.qh +++ b/qcsrc/common/vehicles/all.qh @@ -3,13 +3,13 @@ #include "vehicle.qh" -REGISTRY(Vehicles, 24) +REGISTRY(Vehicles, BIT(3)) REGISTER_REGISTRY(RegisterVehicles) 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, Vehicles_COUNT, id, vehicleid, inst) +#define REGISTER_VEHICLE(id, inst) REGISTER(RegisterVehicles, VEH, Vehicles, id, vehicleid, inst) #if defined(SVQC) #include "sv_vehicles.qh" diff --git a/qcsrc/common/vehicles/vehicle/bumblebee_weapons.qc b/qcsrc/common/vehicles/vehicle/bumblebee_weapons.qc index c01f1f7ca..0966ddf64 100644 --- a/qcsrc/common/vehicles/vehicle/bumblebee_weapons.qc +++ b/qcsrc/common/vehicles/vehicle/bumblebee_weapons.qc @@ -112,7 +112,7 @@ void bumble_raygun_draw() if(self.total_damages < time) { - boxparticles(particleeffectnum(effects_ent[self.traileffect]), self, self.origin, self.origin + _dir * -64, _dir * -_len , _dir * -_len, 1, PARTICLES_USEALPHA); + boxparticles(particleeffectnum(Effects[self.traileffect]), self, self.origin, self.origin + _dir * -64, _dir * -_len , _dir * -_len, 1, PARTICLES_USEALPHA); boxparticles(self.lip, self, self.move_origin, self.move_origin + _dir * -64, _dir * -200 , _dir * -200, 1, PARTICLES_USEALPHA); self.total_damages = time + 0.1; } diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index c1b8527af..c96061fe6 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -36,7 +36,7 @@ entity get_weaponinfo(int id); #define REGISTER_WEAPON(id, inst) \ /* WepSet WEPSET_##id; */ \ - REGISTER(RegisterWeapons, WEP, Weapons, Weapons_COUNT, id, m_id, inst) + REGISTER(RegisterWeapons, WEP, Weapons, 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 de6525fe9..2928ce84a 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -71,7 +71,7 @@ void UncustomizeEntitiesRun() #ifdef CSQC #define REGISTER_NET_LINKED(id, param) \ void Ent_Read##id(entity this, param) { this = self; } \ - REGISTER(RegisterLinkedEntities, NET, LinkedEntities, LinkedEntities_COUNT, id, m_id, spawn()) { \ + REGISTER(RegisterLinkedEntities, NET, LinkedEntities, id, m_id, spawn()) { \ this.netname = #id; \ this.m_read = Ent_Read##id; \ } \ @@ -79,12 +79,12 @@ void UncustomizeEntitiesRun() #else #define REGISTER_NET_LINKED(id, param) \ const bool NET_##id##_istemp = false; \ - REGISTER(RegisterLinkedEntities, NET, LinkedEntities, LinkedEntities_COUNT, id, m_id, spawn()) { \ + REGISTER(RegisterLinkedEntities, NET, LinkedEntities, id, m_id, spawn()) { \ this.netname = #id; \ } #endif -REGISTRY(LinkedEntities, 24) +REGISTRY(LinkedEntities, BIT(0)) REGISTER_REGISTRY(RegisterLinkedEntities) REGISTRY_SORT(LinkedEntities, netname, 0) STATIC_INIT(RegisterLinkedEntities_renumber) { @@ -96,7 +96,7 @@ STATIC_INIT(RegisterLinkedEntities_renumber) { #ifdef CSQC #define REGISTER_NET_TEMP(id, param) \ void Net_Read##id(entity this, param); \ - REGISTER(RegisterTempEntities, NET, TempEntities, TempEntities_COUNT, id, m_id, spawn()) { \ + REGISTER(RegisterTempEntities, NET, TempEntities, id, m_id, spawn()) { \ this.netname = #id; \ this.m_read = Net_Read##id; \ } \ @@ -104,12 +104,12 @@ STATIC_INIT(RegisterLinkedEntities_renumber) { #else #define REGISTER_NET_TEMP(id, param) \ const bool NET_##id##_istemp = true; \ - REGISTER(RegisterTempEntities, NET, TempEntities, TempEntities_COUNT, id, m_id, spawn()) { \ + REGISTER(RegisterTempEntities, NET, TempEntities, id, m_id, spawn()) { \ this.netname = #id; \ } #endif -REGISTRY(TempEntities, 24) +REGISTRY(TempEntities, BIT(0)) REGISTER_REGISTRY(RegisterTempEntities) REGISTRY_SORT(TempEntities, netname, 0) STATIC_INIT(RegisterTempEntities_renumber) { diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index 942c5b2bb..688a71191 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -17,7 +17,7 @@ * 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, FOOS_COUNT, id, m_id, NEW(Foo)); \ + * REGISTER(RegisterFoos, FOO, FOOS, id, m_id, NEW(Foo)); \ * REGISTER_INIT_POST(FOO, id) { \ * print("Registering foo #", this.m_id + 1, "\n"); \ * } \ @@ -30,21 +30,21 @@ * @param initfunc The global constructor to accumulate into * @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 counter Global to count number of entries * @param id The identifier of the current entity being registered * @param fld The field to store the current count into * @param inst An expression to create a new instance, invoked for every registration */ -#define REGISTER(initfunc, ns, array, counter, id, fld, inst) \ +#define REGISTER(initfunc, ns, array, id, fld, inst) \ entity ns##_##id; \ REGISTER_INIT(ns, id) { } \ REGISTER_INIT_POST(ns, id) { } \ .entity enemy; /* internal next pointer */ \ void Register_##ns##_##id() { \ + if (array##_COUNT >= array##_MAX) LOG_FATALF("Registry capacity exceeded (%s)", ftos(array##_MAX)); \ entity this = inst; \ ns##_##id = this; \ - this.fld = counter; \ - array[counter++] = this; \ + this.fld = array##_COUNT; \ + array[array##_COUNT++] = this; \ if (!array##_first) array##_first = this; \ if ( array##_last) array##_last.enemy = this; \ array##_last = this; \ diff --git a/qcsrc/menu/gamesettings.qh b/qcsrc/menu/gamesettings.qh index 5085d3b4a..7c7dc70db 100644 --- a/qcsrc/menu/gamesettings.qh +++ b/qcsrc/menu/gamesettings.qh @@ -2,14 +2,11 @@ #ifndef GAMESETTINGS_H #define GAMESETTINGS_H -void RegisterSettings(); -const int MAX_SETTINGS = 24; -Lazy SETTINGS[MAX_SETTINGS], SETTINGS_first, SETTINGS_last; -int SETTINGS_COUNT; +REGISTRY(Settings, BIT(3)) +REGISTER_REGISTRY(RegisterSettings) #define REGISTER_SETTINGS(id, impl) \ LAZY_NEW(id, impl) \ - REGISTER(RegisterSettings, MENU, SETTINGS, SETTINGS_COUNT, id, m_id, NEW(Lazy, LAZY(id))) -REGISTER_REGISTRY(RegisterSettings) + REGISTER(RegisterSettings, MENU, Settings, id, m_id, NEW(Lazy, LAZY(id))) #endif #endif diff --git a/qcsrc/menu/xonotic/dialog_settings_game.qc b/qcsrc/menu/xonotic/dialog_settings_game.qc index 16bc110ad..69ab67582 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game.qc @@ -7,12 +7,12 @@ CLASS(SettingSource, DataSource) METHOD(SettingSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) { - Lazy l = SETTINGS[i]; + Lazy l = Settings[i]; entity it = l.m_get(); if (returns) returns(it.title, string_null); return it; } - METHOD(SettingSource, reload, int(entity this, string filter)) { return SETTINGS_COUNT; } + METHOD(SettingSource, reload, int(entity this, string filter)) { return Settings_COUNT; } ENDCLASS(SettingSource) #include "listbox.qc" diff --git a/qcsrc/server/mutators/gamemode_keyhunt.qc b/qcsrc/server/mutators/gamemode_keyhunt.qc index c02b42513..be45c3db0 100644 --- a/qcsrc/server/mutators/gamemode_keyhunt.qc +++ b/qcsrc/server/mutators/gamemode_keyhunt.qc @@ -380,9 +380,9 @@ void kh_Key_AssignTo(entity key, entity player) // runs every time a key is pic { if (!k.owner) continue; entity first = WP_Null; - FOREACH(WAYPOINTS, it.netname == k.owner.waypointsprite_attachedforcarrier.model1, LAMBDA(first = it; break)); + FOREACH(Waypoints, it.netname == k.owner.waypointsprite_attachedforcarrier.model1, LAMBDA(first = it; break)); entity third = WP_Null; - FOREACH(WAYPOINTS, it.netname == k.owner.waypointsprite_attachedforcarrier.model3, LAMBDA(third = it; break)); + FOREACH(Waypoints, it.netname == k.owner.waypointsprite_attachedforcarrier.model3, LAMBDA(third = it; break)); WaypointSprite_UpdateSprites(k.owner.waypointsprite_attachedforcarrier, first, WP_KeyCarrierFinish, third); } } @@ -395,9 +395,9 @@ void kh_Key_AssignTo(entity key, entity player) // runs every time a key is pic { if (!k.owner) continue; entity first = WP_Null; - FOREACH(WAYPOINTS, it.netname == k.owner.waypointsprite_attachedforcarrier.model1, LAMBDA(first = it; break)); + FOREACH(Waypoints, it.netname == k.owner.waypointsprite_attachedforcarrier.model1, LAMBDA(first = it; break)); entity third = WP_Null; - FOREACH(WAYPOINTS, it.netname == k.owner.waypointsprite_attachedforcarrier.model3, LAMBDA(third = it; break)); + FOREACH(Waypoints, it.netname == k.owner.waypointsprite_attachedforcarrier.model3, LAMBDA(third = it; break)); WaypointSprite_UpdateSprites(k.owner.waypointsprite_attachedforcarrier, first, WP_KeyCarrierFriend, third); } }