From dc4826c13d66ebc34a49ba927dd1bcf6edf7bf20 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sun, 1 Nov 2015 15:56:44 +1100 Subject: [PATCH] Registry: hide arrays --- qcsrc/client/hud.qc | 9 +++---- qcsrc/client/hud.qh | 1 + qcsrc/client/hud_config.qc | 24 +++++++++---------- qcsrc/client/weapons/projectile.qc | 2 +- qcsrc/common/buffs/all.qh | 1 + qcsrc/common/command/all.qh | 1 + qcsrc/common/deathtypes/all.qc | 2 +- qcsrc/common/deathtypes/all.qh | 11 +++++---- qcsrc/common/effects/all.qc | 2 +- qcsrc/common/effects/all.qh | 1 + qcsrc/common/effects/effectinfo.qc | 1 + qcsrc/common/items/all.qh | 1 + qcsrc/common/mapinfo.qh | 1 + qcsrc/common/minigames/cl_minigames.qh | 1 + qcsrc/common/minigames/sv_minigames.qh | 1 + qcsrc/common/models/all.inc | 4 ++-- qcsrc/common/models/all.qh | 1 + qcsrc/common/monsters/all.qh | 10 ++------ qcsrc/common/mutators/base.qh | 1 + qcsrc/common/mutators/mutator/casings.qc | 4 ++-- .../common/mutators/mutator/waypoints/all.qh | 2 ++ .../mutator/waypoints/waypointsprites.qc | 10 ++++---- qcsrc/common/nades/all.qh | 1 + qcsrc/common/notifications.qh | 4 ++-- qcsrc/common/sounds/all.inc | 10 ++++---- qcsrc/common/sounds/all.qh | 1 + qcsrc/common/turrets/all.qh | 11 ++------- qcsrc/common/vehicles/all.qh | 11 ++------- .../vehicles/vehicle/bumblebee_weapons.qc | 2 +- qcsrc/common/weapons/all.qh | 14 +++-------- qcsrc/lib/net.qh | 6 +++-- qcsrc/lib/registry.qh | 23 +++++++++--------- qcsrc/menu/gamesettings.qh | 1 + qcsrc/menu/xonotic/dialog_settings_game.qc | 4 ++-- qcsrc/server/g_damage.qc | 2 +- qcsrc/server/miscfunctions.qc | 2 +- .../server/mutators/mutator/mutator_nades.qc | 16 ++++++------- 37 files changed, 96 insertions(+), 103 deletions(-) diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index b24d7cb38..070bcbff1 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -846,8 +846,9 @@ void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expan float bonusNades = getstatf(STAT_NADE_BONUS); float bonusProgress = getstatf(STAT_NADE_BONUS_SCORE); float bonusType = getstati(STAT_NADE_BONUS_TYPE); - vector nadeColor = Nades[bonusType].m_color; - string nadeIcon = Nades[bonusType].m_icon; + Nade def = Nades_from(bonusType); + vector nadeColor = def.m_color; + string nadeIcon = def.m_icon; vector iconPos, textPos; @@ -2221,7 +2222,7 @@ void HUD_Radar(void) drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0); } } - entity icon = RadarIcons[tm.teamradar_icon]; + entity icon = RadarIcons_from(tm.teamradar_icon); draw_teamradar_icon(tm.origin, icon, tm, spritelookupcolor(tm, icon.netname, tm.teamradar_color), panel_fg_alpha); } for(tm = world; (tm = find(tm, classname, "entcs_receiver")); ) @@ -4834,7 +4835,7 @@ void HUD_Main(void) hud_draw_maximized = 0; // draw panels in the order specified by panel_order array for(i = hud_panels_COUNT - 1; i >= 0; --i) - HUD_Panel_Draw(hud_panels[panel_order[i]]); + HUD_Panel_Draw(hud_panels_from(panel_order[i])); HUD_Vehicle(); diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index 95a80a9ee..60386ac1e 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -7,6 +7,7 @@ bool HUD_Radar_Clickable(); void HUD_Radar_Mouse(); REGISTRY(hud_panels, BITS(6)) +#define hud_panels_from(i) _hud_panels_from(i, NULL) REGISTER_REGISTRY(Registerhud_panels) #define REGISTER_HUD_PANEL(id, draw_func, name, configflags, showflags) \ diff --git a/qcsrc/client/hud_config.qc b/qcsrc/client/hud_config.qc index 48b3c821d..6b05078d5 100644 --- a/qcsrc/client/hud_config.qc +++ b/qcsrc/client/hud_config.qc @@ -55,7 +55,7 @@ void HUD_Panel_ExportCfg(string cfgname) // common cvars for all panels for (int i = 0; i < hud_panels_COUNT; ++i) { - panel = hud_panels[i]; + panel = hud_panels_from(i); HUD_Write_PanelCvar_n(""); HUD_Write_PanelCvar_q("_pos"); @@ -234,7 +234,7 @@ vector HUD_Panel_CheckMove(vector myPos, vector mySize) vector myTarget = myPos; int i; for (i = 0; i < hud_panels_COUNT; ++i) { - panel = hud_panels[i]; + panel = hud_panels_from(i); if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; if(panel == highlightedPanel) continue; HUD_Panel_UpdatePosSize(); @@ -331,7 +331,7 @@ vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) { float ratio = mySize.x/mySize.y; int i; for (i = 0; i < hud_panels_COUNT; ++i) { - panel = hud_panels[i]; + panel = hud_panels_from(i); if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; if(panel == highlightedPanel) continue; HUD_Panel_UpdatePosSize(); @@ -783,7 +783,7 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) { for(i = 0; i < hud_panels_COUNT; ++i) { - panel = hud_panels[i]; + panel = hud_panels_from(i); if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; if (panel == tab_panels[i] || panel == starting_panel) @@ -932,7 +932,7 @@ float HUD_Panel_Check_Mouse_Pos(float allow_move) i = panel_order[j]; j += 1; - panel = hud_panels[i]; + panel = hud_panels_from(i); if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; HUD_Panel_UpdatePosSize(); @@ -1014,7 +1014,7 @@ void HUD_Panel_Highlight(float allow_move) i = panel_order[j]; j += 1; - panel = hud_panels[i]; + panel = hud_panels_from(i); if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; HUD_Panel_UpdatePosSize(); @@ -1024,7 +1024,7 @@ void HUD_Panel_Highlight(float allow_move) // move if(allow_move && mousepos.x > panel_pos.x && mousepos.y > panel_pos.y && mousepos.x < panel_pos.x + panel_size.x && mousepos.y < panel_pos.y + panel_size.y) { - highlightedPanel = hud_panels[i]; + highlightedPanel = hud_panels_from(i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 1; panel_click_distance = mousepos - panel_pos; @@ -1033,7 +1033,7 @@ void HUD_Panel_Highlight(float allow_move) // resize from topleft border else if(mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + 0.5 * panel_size.y) { - highlightedPanel = hud_panels[i]; + highlightedPanel = hud_panels_from(i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; resizeCorner = 1; @@ -1044,7 +1044,7 @@ void HUD_Panel_Highlight(float allow_move) // resize from topright border else if(mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + 0.5 * panel_size.y) { - highlightedPanel = hud_panels[i]; + highlightedPanel = hud_panels_from(i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; resizeCorner = 2; @@ -1056,7 +1056,7 @@ void HUD_Panel_Highlight(float allow_move) // resize from bottomleft border else if(mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + panel_size.y + border) { - highlightedPanel = hud_panels[i]; + highlightedPanel = hud_panels_from(i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; resizeCorner = 3; @@ -1068,7 +1068,7 @@ void HUD_Panel_Highlight(float allow_move) // resize from bottomright border else if(mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + panel_size.y + border) { - highlightedPanel = hud_panels[i]; + highlightedPanel = hud_panels_from(i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; resizeCorner = 4; @@ -1243,7 +1243,7 @@ void HUD_Configure_Frame() setcursormode(1); hudShiftState = 0; for(i = hud_panels_COUNT - 1; i >= 0; --i) - hud_panels[panel_order[i]].update_time = time; + hud_panels_from(panel_order[i]).update_time = time; } // NOTE this check is necessary because _menu_alpha isn't updated the frame the menu gets enabled diff --git a/qcsrc/client/weapons/projectile.qc b/qcsrc/client/weapons/projectile.qc index 7d6abf312..9969a89f1 100644 --- a/qcsrc/client/weapons/projectile.qc +++ b/qcsrc/client/weapons/projectile.qc @@ -45,7 +45,7 @@ void Projectile_DrawTrail(entity this, vector to) if (this.traileffect) { particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha); - boxparticles(particleeffectnum(Effects[this.traileffect]), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL); + boxparticles(particleeffectnum(Effects_from(this.traileffect)), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL); } } diff --git a/qcsrc/common/buffs/all.qh b/qcsrc/common/buffs/all.qh index 450917390..073e3b3aa 100644 --- a/qcsrc/common/buffs/all.qh +++ b/qcsrc/common/buffs/all.qh @@ -9,6 +9,7 @@ #include "../util.qh" REGISTRY(Buffs, BITS(4)) +#define Buffs_from(i) _Buffs_from(i, BUFF_Null) REGISTER_REGISTRY(RegisterBuffs) #define REGISTER_BUFF(id) \ diff --git a/qcsrc/common/command/all.qh b/qcsrc/common/command/all.qh index d1164f11a..b2e85dd87 100644 --- a/qcsrc/common/command/all.qh +++ b/qcsrc/common/command/all.qh @@ -3,6 +3,7 @@ #include "command.qh" REGISTRY(GENERIC_COMMANDS, BITS(7)) +#define GENERIC_COMMANDS_from(i) _GENERIC_COMMANDS_from(i, NULL) REGISTER_REGISTRY(RegisterGENERIC_COMMANDS) REGISTRY_SORT(GENERIC_COMMANDS, m_name, 0) diff --git a/qcsrc/common/deathtypes/all.qc b/qcsrc/common/deathtypes/all.qc index 4fdafa9a8..823a20f8e 100644 --- a/qcsrc/common/deathtypes/all.qc +++ b/qcsrc/common/deathtypes/all.qc @@ -3,7 +3,7 @@ string Deathtype_Name(int deathtype) { if (DEATH_ISSPECIAL(deathtype)) { - entity deathent = Deathtypes[deathtype - DT_FIRST]; + entity deathent = Deathtypes_from(deathtype - DT_FIRST); if (!deathent) { backtrace("Deathtype_Name: Could not find deathtype entity!\n"); return ""; } return deathent.nent_name; } diff --git a/qcsrc/common/deathtypes/all.qh b/qcsrc/common/deathtypes/all.qh index 9562ab786..28f5a16b7 100644 --- a/qcsrc/common/deathtypes/all.qh +++ b/qcsrc/common/deathtypes/all.qh @@ -4,6 +4,7 @@ #include "../notifications.qh" REGISTRY(Deathtypes, BITS(8)) +#define Deathtypes_from(i) _Deathtypes_from(i, NULL) REGISTER_REGISTRY(RegisterDeathtypes) .entity death_msgself; @@ -32,11 +33,11 @@ const int DEATH_HITTYPEMASK = HITTYPE_SECONDARY | HITTYPE_SPLASH | HITTYPE_BOUNC const int DT_FIRST = BIT(13); #define DEATH_ISSPECIAL(t) (t >= DT_FIRST) -#define DEATH_IS(t, dt) (DEATH_ISSPECIAL(t) && (Deathtypes[t - DT_FIRST]) == dt) -#define DEATH_ENT(t) (DEATH_ISSPECIAL(t) ? (Deathtypes[t - DT_FIRST]) : NULL) -#define DEATH_ISVEHICLE(t) (DEATH_ISSPECIAL(t) && (Deathtypes[t - DT_FIRST]).death_msgextra == "vehicle") -#define DEATH_ISTURRET(t) (DEATH_ISSPECIAL(t) && (Deathtypes[t - DT_FIRST]).death_msgextra == "turret") -#define DEATH_ISMONSTER(t) (DEATH_ISSPECIAL(t) && (Deathtypes[t - DT_FIRST]).death_msgextra == "monster") +#define DEATH_IS(t, dt) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)) == dt) +#define DEATH_ENT(t) (DEATH_ISSPECIAL(t) ? (Deathtypes_from(t - DT_FIRST)) : NULL) +#define DEATH_ISVEHICLE(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "vehicle") +#define DEATH_ISTURRET(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "turret") +#define DEATH_ISMONSTER(t) (DEATH_ISSPECIAL(t) && (Deathtypes_from(t - DT_FIRST)).death_msgextra == "monster") #define DEATH_WEAPONOF(t) (DEATH_ISSPECIAL(t) ? WEP_Null : get_weaponinfo((t) & DEATH_WEAPONMASK)) #define DEATH_ISWEAPON(t, w) (DEATH_WEAPONOF(t) == (w)) diff --git a/qcsrc/common/effects/all.qc b/qcsrc/common/effects/all.qc index 6b136fa49..a18d741f6 100644 --- a/qcsrc/common/effects/all.qc +++ b/qcsrc/common/effects/all.qc @@ -5,7 +5,7 @@ void Read_Effect(bool is_new) { int net_name = (Effects_COUNT >= 255) ? ReadShort() : ReadByte(); - entity eff = Effects[net_name]; + entity eff = Effects_from(net_name); vector v, vel = '0 0 0'; int eff_cnt = 1; diff --git a/qcsrc/common/effects/all.qh b/qcsrc/common/effects/all.qh index 39c67dc96..5006ff090 100644 --- a/qcsrc/common/effects/all.qh +++ b/qcsrc/common/effects/all.qh @@ -11,6 +11,7 @@ void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt); #endif REGISTRY(Effects, BITS(8)) +#define Effects_from(i) _Effects_from(i, EFFECT_Null) REGISTER_REGISTRY(RegisterEffects) #define EFFECT(istrail, name, realname) \ REGISTER(RegisterEffects, EFFECT, Effects, name, m_id, Create_Effect_Entity(realname, istrail)); diff --git a/qcsrc/common/effects/effectinfo.qc b/qcsrc/common/effects/effectinfo.qc index f85ad06b1..d6e929b20 100644 --- a/qcsrc/common/effects/effectinfo.qc +++ b/qcsrc/common/effects/effectinfo.qc @@ -320,6 +320,7 @@ 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) #define EFFECTINFO(name) \ [[accumulate]] void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) { } \ diff --git a/qcsrc/common/items/all.qh b/qcsrc/common/items/all.qh index 4d76aa338..ca0189292 100644 --- a/qcsrc/common/items/all.qh +++ b/qcsrc/common/items/all.qh @@ -6,6 +6,7 @@ #include "item.qh" REGISTRY(Items, BITS(5)) +#define Items_from(i) _Items_from(i, NULL) 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, id, m_id, NEW(class)) diff --git a/qcsrc/common/mapinfo.qh b/qcsrc/common/mapinfo.qh index 3466d7ee3..24674b6d6 100644 --- a/qcsrc/common/mapinfo.qh +++ b/qcsrc/common/mapinfo.qh @@ -43,6 +43,7 @@ CLASS(Gametype, Object) ENDCLASS(Gametype) REGISTRY(Gametypes, BITS(4)) +#define Gametypes_from(i) _Gametypes_from(i, NULL) REGISTER_REGISTRY(RegisterGametypes) int MAPINFO_TYPE_ALL; #define REGISTER_GAMETYPE(hname, sname, g_name, NAME, gteamplay, mutators, defaults, gdescription) \ diff --git a/qcsrc/common/minigames/cl_minigames.qh b/qcsrc/common/minigames/cl_minigames.qh index 50eb5b42d..9a5131995 100644 --- a/qcsrc/common/minigames/cl_minigames.qh +++ b/qcsrc/common/minigames/cl_minigames.qh @@ -115,6 +115,7 @@ 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) #define REGISTER_MINIGAME(name,nicename) \ REGISTER(RegisterMinigames, MINIGAME, Minigames, name, m_id, spawn()); \ diff --git a/qcsrc/common/minigames/sv_minigames.qh b/qcsrc/common/minigames/sv_minigames.qh index af23fd193..02c3c82fa 100644 --- a/qcsrc/common/minigames/sv_minigames.qh +++ b/qcsrc/common/minigames/sv_minigames.qh @@ -47,6 +47,7 @@ entity minigame_sessions; bool minigame_SendEntity(entity this, entity to, int sf); REGISTRY(Minigames, BITS(3)) +#define Minigames_from(i) _Minigames_from(i, NULL) REGISTER_REGISTRY(RegisterMinigames) #define REGISTER_MINIGAME(name,nicename) \ REGISTER(RegisterMinigames, MINIGAME, Minigames, name, m_id, spawn()); \ diff --git a/qcsrc/common/models/all.inc b/qcsrc/common/models/all.inc index f675d8a9e..bd1f0b9e7 100644 --- a/qcsrc/common/models/all.inc +++ b/qcsrc/common/models/all.inc @@ -144,7 +144,7 @@ MODEL(GIB_ROBO_7, "models/gibs/robo7.md3"); MODEL(GIB_ROBO_8, "models/gibs/robo8.md3"); Model MDL_GIB_ROBO_RANDOM() { int i = floor(random() * 8); - return Models[MDL_GIB_ROBO_1.m_id + i]; + return Models_from(MDL_GIB_ROBO_1.m_id + i); } MODEL(CASING_SHELL, "models/casing_shell.mdl"); @@ -346,7 +346,7 @@ MODEL(9, "models/sprites/9.spr32"); MODEL(10, "models/sprites/10.spr32"); Model MDL_NUM(int i) { if ((i >= 0 && i <= 10)) - return Models[MDL_0.m_id + i]; + return Models_from(MDL_0.m_id + i); return MDL_Null; } diff --git a/qcsrc/common/models/all.qh b/qcsrc/common/models/all.qh index ed8a31a0d..f38b23fff 100644 --- a/qcsrc/common/models/all.qh +++ b/qcsrc/common/models/all.qh @@ -4,6 +4,7 @@ #include "model.qh" REGISTRY(Models, BITS(9)) +#define Models_from(i) _Models_from(i, MDL_Null) REGISTER_REGISTRY(RegisterModels) #define MODEL(name, path) \ diff --git a/qcsrc/common/monsters/all.qh b/qcsrc/common/monsters/all.qh index f32470b58..5e46e8a80 100644 --- a/qcsrc/common/monsters/all.qh +++ b/qcsrc/common/monsters/all.qh @@ -6,6 +6,8 @@ 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) const int MON_FIRST = 1; #define MON_LAST (Monsters_COUNT - 1) @@ -14,14 +16,6 @@ const int MON_FIRST = 1; REGISTER_MONSTER(Null, NEW(Monster)); -Monster get_monsterinfo(int id) -{ - if (id >= MON_FIRST && id <= MON_LAST) { - Monster m = Monsters[id]; - if (m) return m; - } - return MON_Null; -} #include "all.inc" diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh index ce98cd508..b125c145e 100644 --- a/qcsrc/common/mutators/base.qh +++ b/qcsrc/common/mutators/base.qh @@ -155,6 +155,7 @@ CLASS(Mutator, Object) ENDCLASS(Mutator) REGISTRY(Mutators, BITS(6)) +#define Mutators_from(i) _Mutators_from(i, NULL) Mutator loaded_mutators[Mutators_MAX]; bool Mutator_Add(Mutator mut) diff --git a/qcsrc/common/mutators/mutator/casings.qc b/qcsrc/common/mutators/mutator/casings.qc index 319ab8e77..249757b7b 100644 --- a/qcsrc/common/mutators/mutator/casings.qc +++ b/qcsrc/common/mutators/mutator/casings.qc @@ -70,13 +70,13 @@ SOUND(BRASS1, W_Sound("brass1")); SOUND(BRASS2, W_Sound("brass2")); SOUND(BRASS3, W_Sound("brass3")); Sound SND_BRASS_RANDOM() { - return Sounds[SND_BRASS1.m_id + floor(prandom() * 3)]; + return Sounds_from(SND_BRASS1.m_id + floor(prandom() * 3)); } SOUND(CASINGS1, W_Sound("casings1")); SOUND(CASINGS2, W_Sound("casings2")); SOUND(CASINGS3, W_Sound("casings3")); Sound SND_CASINGS_RANDOM() { - return Sounds[SND_CASINGS1.m_id + floor(prandom() * 3)]; + return Sounds_from(SND_CASINGS1.m_id + floor(prandom() * 3)); } void Casing_Touch() diff --git a/qcsrc/common/mutators/mutator/waypoints/all.qh b/qcsrc/common/mutators/mutator/waypoints/all.qh index 27797b7f4..d5187b4b8 100644 --- a/qcsrc/common/mutators/mutator/waypoints/all.qh +++ b/qcsrc/common/mutators/mutator/waypoints/all.qh @@ -4,6 +4,7 @@ #include "waypointsprites.qh" REGISTRY(Waypoints, BITS(6)) +#define Waypoints_from(i) _Waypoints_from(i, WP_Null) 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) @@ -26,6 +27,7 @@ ENDCLASS(Waypoint) #define REGISTER_WAYPOINT(id, text, color, blink) REGISTER_WAYPOINT_(id, NEW(Waypoint, #id, text, color, blink)) REGISTRY(RadarIcons, BITS(7)) +#define RadarIcons_from(i) _RadarIcons_from(i, RADARICON_NONE) REGISTER_REGISTRY(RegisterRadarIcons) .int m_radaricon; #define REGISTER_RADARICON(id, num) REGISTER(RegisterRadarIcons, RADARICON, RadarIcons, id, m_id, new(RadarIcon)) { this.m_radaricon = num; this.netname = #id; } diff --git a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc index 16e8628b1..491bff1c8 100644 --- a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc +++ b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc @@ -224,7 +224,7 @@ float spritelookupblinkvalue(string s) if (get_weaponinfo(self.wp_extra).spawnflags & WEP_FLAG_SUPERWEAPON) return 2; } - if (s == WP_Item.netname) return Items[self.wp_extra].m_waypointblink; + if (s == WP_Item.netname) return Items_from(self.wp_extra).m_waypointblink; return 1; } @@ -232,8 +232,8 @@ float spritelookupblinkvalue(string s) vector spritelookupcolor(entity this, string s, vector def) { if (s == WP_Weapon.netname || s == RADARICON_Weapon.netname) return get_weaponinfo(this.wp_extra).wpcolor; - if (s == WP_Item.netname || s == RADARICON_Item.netname) return Items[this.wp_extra].m_color; - if (s == WP_Buff.netname || s == RADARICON_Buff.netname) return Buffs[this.wp_extra].m_color; + if (s == WP_Item.netname || s == RADARICON_Item.netname) return Items_from(this.wp_extra).m_color; + if (s == WP_Buff.netname || s == RADARICON_Buff.netname) return Buffs_from(this.wp_extra).m_color; return def; } @@ -241,8 +241,8 @@ string spritelookuptext(string s) {SELFPARAM(); if (s == WP_RaceStartFinish.netname) return (race_checkpointtime || race_mycheckpointtime) ? _("Finish") : _("Start"); if (s == WP_Weapon.netname) return get_weaponinfo(self.wp_extra).m_name; - if (s == WP_Item.netname) return Items[self.wp_extra].m_waypoint; - if (s == WP_Buff.netname) return Buffs[self.wp_extra].m_prettyName; + if (s == WP_Item.netname) return Items_from(self.wp_extra).m_waypoint; + if (s == WP_Buff.netname) return Buffs_from(self.wp_extra).m_prettyName; if (s == WP_Monster.netname) return get_monsterinfo(self.wp_extra).monster_name; // need to loop, as our netname could be one of three diff --git a/qcsrc/common/nades/all.qh b/qcsrc/common/nades/all.qh index 37c9bee5f..9b2b6ec35 100644 --- a/qcsrc/common/nades/all.qh +++ b/qcsrc/common/nades/all.qh @@ -22,6 +22,7 @@ const int PROJECTILE_NADE_MONSTER = 82; const int PROJECTILE_NADE_MONSTER_BURN = 83; REGISTRY(Nades, BITS(4)) +#define Nades_from(i) _Nades_from(i, NADE_TYPE_Null) REGISTER_REGISTRY(RegisterNades) #define REGISTER_NADE(id) REGISTER(RegisterNades, NADE_TYPE, Nades, id, m_id, NEW(Nade)) diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index e1779b613..076206fa7 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -318,8 +318,8 @@ const float ARG_DC = 6; // unique result to durcnt/centerprint ARG_CASE(ARG_CS_SV, "spree_end", (autocvar_notification_show_sprees ? notif_arg_spree_inf(-1, "", "", f1) : "")) \ ARG_CASE(ARG_CS_SV, "spree_lost", (autocvar_notification_show_sprees ? notif_arg_spree_inf(-2, "", "", f1) : "")) \ ARG_CASE(ARG_CS_SV, "item_wepname", WEP_NAME(f1)) \ - ARG_CASE(ARG_CS_SV, "item_buffname", sprintf("%s%s", rgb_to_hexcolor(Buffs[f1].m_color), Buffs[f1].m_prettyName)) \ - ARG_CASE(ARG_CS_SV, "f3buffname", sprintf("%s%s", rgb_to_hexcolor(Buffs[f3].m_color), Buffs[f3].m_prettyName)) \ + ARG_CASE(ARG_CS_SV, "item_buffname", sprintf("%s%s", rgb_to_hexcolor(Buffs_from(f1).m_color), Buffs_from(f1).m_prettyName)) \ + ARG_CASE(ARG_CS_SV, "f3buffname", sprintf("%s%s", rgb_to_hexcolor(Buffs_from(f3).m_color), Buffs_from(f3).m_prettyName)) \ ARG_CASE(ARG_CS_SV, "item_wepammo", (s1 != "" ? sprintf(_(" with %s"), s1) : "")) \ ARG_CASE(ARG_DC, "item_centime", ftos(autocvar_notification_item_centerprinttime)) \ ARG_CASE(ARG_SV, "death_team", Team_ColoredFullName(f1)) \ diff --git a/qcsrc/common/sounds/all.inc b/qcsrc/common/sounds/all.inc index 8a7dbbca3..87c28c353 100644 --- a/qcsrc/common/sounds/all.inc +++ b/qcsrc/common/sounds/all.inc @@ -36,7 +36,7 @@ SOUND(GRENADE_BOUNCE4, W_Sound("grenade_bounce4")); SOUND(GRENADE_BOUNCE5, W_Sound("grenade_bounce5")); SOUND(GRENADE_BOUNCE6, W_Sound("grenade_bounce6")); Sound SND_GRENADE_BOUNCE_RANDOM() { - return Sounds[SND_GRENADE_BOUNCE1.m_id + rint(random() * 5)]; + return Sounds_from(SND_GRENADE_BOUNCE1.m_id + rint(random() * 5)); } SOUND(GRENADE_FIRE, W_Sound("grenade_fire")); SOUND(GRENADE_IMPACT, W_Sound("grenade_impact")); @@ -48,7 +48,7 @@ SOUND(HAGEXP1, W_Sound("hagexp1")); SOUND(HAGEXP2, W_Sound("hagexp2")); SOUND(HAGEXP3, W_Sound("hagexp3")); Sound SND_HAGEXP_RANDOM() { - return Sounds[SND_HAGEXP1.m_id + rint(random() * 2)]; + return Sounds_from(SND_HAGEXP1.m_id + rint(random() * 2)); } SOUND(HOOKBOMB_FIRE, W_Sound("hookbomb_fire")); @@ -71,7 +71,7 @@ SOUND(NEXWHOOSH1, W_Sound("nexwhoosh1")); SOUND(NEXWHOOSH2, W_Sound("nexwhoosh2")); SOUND(NEXWHOOSH3, W_Sound("nexwhoosh3")); Sound SND_NEXWHOOSH_RANDOM() { - return Sounds[SND_NEXWHOOSH1.m_id + rint(random() * 2)]; + return Sounds_from(SND_NEXWHOOSH1.m_id + rint(random() * 2)); } SOUND(RELOAD, W_Sound("reload")); // until weapons have individual reload sounds, precache the reload sound here @@ -79,7 +79,7 @@ SOUND(RIC1, W_Sound("ric1")); SOUND(RIC2, W_Sound("ric2")); SOUND(RIC3, W_Sound("ric3")); Sound SND_RIC_RANDOM() { - return Sounds[SND_RIC1.m_id + rint(random() * 2)]; + return Sounds_from(SND_RIC1.m_id + rint(random() * 2)); } SOUND(ROCKET_DET, W_Sound("rocket_det")); @@ -260,7 +260,7 @@ SOUND(GIB_SPLAT02, "misc/gib_splat02.wav"); SOUND(GIB_SPLAT03, "misc/gib_splat03.wav"); SOUND(GIB_SPLAT04, "misc/gib_splat04.wav"); Sound SND_GIB_SPLAT_RANDOM() { - return Sounds[SND_GIB_SPLAT01.m_id + floor(prandom() * 4)]; + return Sounds_from(SND_GIB_SPLAT01.m_id + floor(prandom() * 4)); } SOUND(HIT, "misc/hit.wav"); diff --git a/qcsrc/common/sounds/all.qh b/qcsrc/common/sounds/all.qh index d39c701d7..fd56eeca3 100644 --- a/qcsrc/common/sounds/all.qh +++ b/qcsrc/common/sounds/all.qh @@ -4,6 +4,7 @@ #include "sound.qh" REGISTRY(Sounds, BITS(8)) +#define Sounds_from(i) _Sounds_from(i, SND_Null) REGISTER_REGISTRY(RegisterSounds) #define SOUND(name, path) \ diff --git a/qcsrc/common/turrets/all.qh b/qcsrc/common/turrets/all.qh index fa16be08b..0848478bf 100644 --- a/qcsrc/common/turrets/all.qh +++ b/qcsrc/common/turrets/all.qh @@ -7,6 +7,8 @@ #include "turret.qh" REGISTRY(Turrets, BITS(5)) +#define Turrets_from(i) _Turrets_from(i, TUR_Null) +#define get_turretinfo(i) Turrets_from(i) REGISTER_REGISTRY(RegisterTurrets) @@ -71,15 +73,6 @@ const int TUR_FIRST = 1; REGISTER_TURRET(Null, NEW(Turret)); -Turret get_turretinfo(int id) -{ - if (id >= TUR_FIRST && id <= TUR_LAST) { - Turret t = Turrets[id]; - if (t) return t; - } - return TUR_Null; -} - #include "all.inc" #endif diff --git a/qcsrc/common/vehicles/all.qh b/qcsrc/common/vehicles/all.qh index 8a57182f8..f5d643431 100644 --- a/qcsrc/common/vehicles/all.qh +++ b/qcsrc/common/vehicles/all.qh @@ -4,6 +4,8 @@ #include "vehicle.qh" REGISTRY(Vehicles, BITS(3)) +#define Vehicles_from(i) _Vehicles_from(i, VEH_Null) +#define get_vehicleinfo(i) Vehicles_from(i) REGISTER_REGISTRY(RegisterVehicles) const int VEH_FIRST = 1; #define VEH_LAST (Vehicles_COUNT - 1) @@ -19,15 +21,6 @@ const int VEH_FIRST = 1; REGISTER_VEHICLE(Null, NEW(Vehicle)); -Vehicle get_vehicleinfo(int id) -{ - if (id >= VEH_FIRST && id <= VEH_LAST) { - Vehicle v = Vehicles[id]; - if (v) return v; - } - return VEH_Null; -} - #include "all.inc" #endif diff --git a/qcsrc/common/vehicles/vehicle/bumblebee_weapons.qc b/qcsrc/common/vehicles/vehicle/bumblebee_weapons.qc index 722c6852e..d58e88701 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(entity this) if(self.total_damages < time) { - boxparticles(particleeffectnum(Effects[self.traileffect]), self, self.origin, self.origin + _dir * -64, _dir * -_len , _dir * -_len, 1, PARTICLES_USEALPHA); + boxparticles(particleeffectnum(Effects_from(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 6ba62eb2f..c89408986 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -34,9 +34,10 @@ WepSet ReadWepSet(); #endif 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) STATIC_INIT(WeaponPickup) { FOREACH(Weapons, true, LAMBDA(it.m_pickup = NEW(WeaponPickup, it))); } -entity get_weaponinfo(int id); GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPONTODO: make this work with other progs than just server @@ -131,15 +132,6 @@ REGISTER_WEAPON(Null, NEW(Weapon)); #include "all.inc" -entity get_weaponinfo(int id) -{ - if (id >= WEP_FIRST && id <= WEP_LAST) { - Weapon w = Weapons[id]; - if (w) return w; - } - return WEP_Null; -} - // TODO: remove after 0.8.2. Retains impulse number compatibility because 0.8.1 clients don't reload the weapons.cfg #define WEP_HARDCODED_IMPULSES 22 @@ -169,7 +161,7 @@ STATIC_INIT(register_weapons_done) #endif weaponorder_byid = ""; for (int i = Weapons_MAX - 1; i >= 1; --i) - if (Weapons[i]) + if (Weapons_from(i)) weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i)); weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1)); } diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index 39c9c8db8..1739ec69e 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -104,12 +104,13 @@ #endif REGISTRY(LinkedEntities, BITS(4)) +#define LinkedEntities_from(i) _LinkedEntities_from(i, NULL) REGISTER_REGISTRY(RegisterLinkedEntities) REGISTRY_SORT(LinkedEntities, netname, 0) STATIC_INIT(RegisterLinkedEntities_renumber) { for (int i = 0; i < LinkedEntities_COUNT; ++i) - LinkedEntities[i].m_id = 100 + i; + LinkedEntities_from(i).m_id = 100 + i; } #ifdef CSQC @@ -131,12 +132,13 @@ STATIC_INIT(RegisterLinkedEntities_renumber) #endif REGISTRY(TempEntities, BITS(4)) +#define TempEntities_from(i) _TempEntities_from(i, NULL) REGISTER_REGISTRY(RegisterTempEntities) REGISTRY_SORT(TempEntities, netname, 0) STATIC_INIT(RegisterTempEntities_renumber) { for (int i = 0; i < TempEntities_COUNT; ++i) - TempEntities[i].m_id = 115 + i; + TempEntities_from(i).m_id = 115 + i; } #ifndef MENUQC diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index 811bbf31e..8da286195 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -9,8 +9,9 @@ #define REGISTRY(id, max) \ void Register##id() {} \ const int id##_MAX = max; \ - noref entity id[id##_MAX], id##_first, id##_last; \ - int id##_COUNT; + noref entity _##id[id##_MAX], id##_first, id##_last; \ + 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; } /** * Register a new entity with a global constructor. @@ -44,9 +45,9 @@ entity this = inst; \ ns##_##id = this; \ this.fld = array##_COUNT; \ - array[array##_COUNT++] = this; \ + _##array[array##_COUNT++] = this; \ if (!array##_first) array##_first = this; \ - if (array##_last) array##_last.REGISTRY_NEXT = this; \ + if (array##_last) array##_last.REGISTRY_NEXT = this; \ array##_last = this; \ Register_##ns##_##id##_init(this); \ Register_##ns##_##id##_init_post(this); \ @@ -63,25 +64,25 @@ { \ i += skip; j += skip; \ \ - entity a = id[i], b = id[j]; \ - id[i] = b; \ - id[j] = a; \ + entity a = _##id[i], b = _##id[j]; \ + _##id[i] = b; \ + _##id[j] = a; \ \ entity a_next = a.REGISTRY_NEXT, b_next = b.REGISTRY_NEXT; \ a.REGISTRY_NEXT = b_next; \ b.REGISTRY_NEXT = a_next; \ \ if (i == 0) id##_first = b; \ - else id[i - 1].REGISTRY_NEXT = b; \ + else _##id[i - 1].REGISTRY_NEXT = b; \ \ if (j == 0) id##_first = a; \ - else id[j - 1].REGISTRY_NEXT = a; \ + else _##id[j - 1].REGISTRY_NEXT = a; \ } \ float _REGISTRY_CMP_##id(int i, int j, entity pass) \ { \ i += skip; j += skip; \ - string a = id[i].field; \ - string b = id[j].field; \ + string a = _##id[i].field; \ + string b = _##id[j].field; \ return strcasecmp(a, b); \ } \ STATIC_INIT(Registry_sort_##id) \ diff --git a/qcsrc/menu/gamesettings.qh b/qcsrc/menu/gamesettings.qh index 49c5f21dc..24a40edf0 100644 --- a/qcsrc/menu/gamesettings.qh +++ b/qcsrc/menu/gamesettings.qh @@ -5,6 +5,7 @@ #include "xonotic/tab.qc" REGISTRY(Settings, BITS(3)) +#define Settings_from(i) _Settings_from(i, NULL) REGISTER_REGISTRY(RegisterSettings) #define REGISTER_SETTINGS(id, impl) \ LAZY_NEW(id, impl) \ diff --git a/qcsrc/menu/xonotic/dialog_settings_game.qc b/qcsrc/menu/xonotic/dialog_settings_game.qc index 0a9907b80..d8e7c4b65 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game.qc @@ -7,14 +7,14 @@ CLASS(SettingSource, DataSource) METHOD(SettingSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) { - Lazy l = Settings[i]; + Lazy l = Settings_from(i); entity it = l.m_get(); if (returns) returns(it.title, string_null); return it; } METHOD(SettingSource, getEntryTooltip, entity(entity this, int i, void(string theTooltip) returns)) { - Lazy l = Settings[i]; + Lazy l = Settings_from(i); entity it = l.m_get(); if (returns) returns(it.tooltip); return it; diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index 802eabd7f..e1bd4e0ab 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -204,7 +204,7 @@ void Obituary_SpecialDeath( { if(DEATH_ISSPECIAL(deathtype)) { - entity deathent = Deathtypes[deathtype - DT_FIRST]; + entity deathent = Deathtypes_from(deathtype - DT_FIRST); if (!deathent) { backtrace("Obituary_SpecialDeath: Could not find deathtype entity!\n"); return; } if(murder) diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 0160d7687..87aeb4ee0 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -296,7 +296,7 @@ string formatmessage(string msg) case "l": replacement = NearestLocation(self.origin); break; case "y": replacement = NearestLocation(cursor); break; case "d": replacement = NearestLocation(self.death_origin); break; - case "w": replacement = WEP_NAME((!self.weapon) ? (!self.switchweapon ? self.cnt : self.switchweapon) : self.weapon); break; + case "w": replacement = WEP_NAME(((!self.weapon) ? (!self.switchweapon ? self.cnt : self.switchweapon) : self.weapon)); break; case "W": replacement = ammoitems; break; case "x": replacement = ((cursor_ent.netname == "" || !cursor_ent) ? "nothing" : cursor_ent.netname); break; case "s": replacement = ftos(vlen(self.velocity - self.velocity_z * '0 0 1')); break; diff --git a/qcsrc/server/mutators/mutator/mutator_nades.qc b/qcsrc/server/mutators/mutator/mutator_nades.qc index cc567d2b8..c14ab1241 100644 --- a/qcsrc/server/mutators/mutator/mutator_nades.qc +++ b/qcsrc/server/mutators/mutator/mutator_nades.qc @@ -64,7 +64,7 @@ void nade_timer_think() void nade_burn_spawn(entity _nade) { - CSQCProjectile(_nade, true, Nades[_nade.nade_type].m_projectile[true], true); + CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[true], true); } void nade_spawn(entity _nade) @@ -83,7 +83,7 @@ void nade_spawn(entity _nade) _nade.effects |= EF_LOWPRECISION; - CSQCProjectile(_nade, true, Nades[_nade.nade_type].m_projectile[false], true); + CSQCProjectile(_nade, true, Nades_from(_nade.nade_type).m_projectile[false], true); } void napalm_damage(float dist, float damage, float edgedamage, float burntime) @@ -513,7 +513,7 @@ void nade_boom() entity expef = NULL; bool nade_blast = true; - switch ( Nades[self.nade_type] ) + switch ( Nades_from(self.nade_type) ) { case NADE_TYPE_NAPALM: nade_blast = autocvar_g_nades_napalm_blast; @@ -565,7 +565,7 @@ void nade_boom() } if(self.takedamage) - switch ( Nades[self.nade_type] ) + switch ( Nades_from(self.nade_type) ) { case NADE_TYPE_NAPALM: nade_napalm_boom(); break; case NADE_TYPE_ICE: nade_ice_boom(); break; @@ -808,7 +808,7 @@ float nade_customize() { //self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION; if(!self.traileffectnum) - self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades[self.nade_type].m_projectile[false], self.team).eent_eff_name); + self.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(self.nade_type).m_projectile[false], self.team).eent_eff_name); self.alpha = 1; } @@ -852,8 +852,8 @@ void nade_prime() //setattachment(n, self, "bip01 l hand"); n.exteriormodeltoclient = self; n.customizeentityforclient = nade_customize; - n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades[n.nade_type].m_projectile[false], self.team).eent_eff_name); - n.colormod = Nades[n.nade_type].m_color; + n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(n.nade_type).m_projectile[false], self.team).eent_eff_name); + n.colormod = Nades_from(n.nade_type).m_color; n.realowner = self; n.colormap = self.colormap; n.glowmod = self.glowmod; @@ -867,7 +867,7 @@ void nade_prime() int slot = 0; // TODO: unhardcode setattachment(fn, self.weaponentity[slot], ""); fn.realowner = fn.owner = self; - fn.colormod = Nades[n.nade_type].m_color; + fn.colormod = Nades_from(n.nade_type).m_color; fn.colormap = self.colormap; fn.glowmod = self.glowmod; fn.think = SUB_Remove; -- 2.39.2