From: terencehill Date: Wed, 27 May 2020 19:46:32 +0000 (+0200) Subject: Registry API: add REGISTRY_GET X-Git-Tag: xonotic-v0.8.5~1010^2~2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=717defe5e02506bb5c857025d71fb605d6eb8c55;p=xonotic%2Fxonotic-data.pk3dir.git Registry API: add REGISTRY_GET --- diff --git a/qcsrc/client/commands/cl_cmd.qh b/qcsrc/client/commands/cl_cmd.qh index f6f96501a..725baa408 100644 --- a/qcsrc/client/commands/cl_cmd.qh +++ b/qcsrc/client/commands/cl_cmd.qh @@ -8,10 +8,11 @@ void ConsoleCommand_macro_init(); void LocalCommand_macro_write_aliases(int fh); REGISTRY(CLIENT_COMMANDS, BITS(7)) -#define CLIENT_COMMANDS_from(i) _CLIENT_COMMANDS_from(i, NULL) REGISTER_REGISTRY(CLIENT_COMMANDS) REGISTRY_SORT(CLIENT_COMMANDS) +REGISTRY_DEFINE_GET(CLIENT_COMMANDS, NULL) + #define CLIENT_COMMAND(id, description) \ CLASS(clientcommand_##id, Command) \ ATTRIB(clientcommand_##id, m_name, string, #id); \ diff --git a/qcsrc/client/hud/hud.qc b/qcsrc/client/hud/hud.qc index dd91dbd68..91770fd72 100644 --- a/qcsrc/client/hud/hud.qc +++ b/qcsrc/client/hud/hud.qc @@ -408,7 +408,7 @@ void HUD_Vehicle() if(hud == HUD_BUMBLEBEE_GUN) CSQC_BUMBLE_GUN_HUD(); else { - Vehicle info = Vehicles_from(hud); + Vehicle info = REGISTRY_GET(Vehicles, hud); info.vr_hud(info); } @@ -708,7 +708,7 @@ void HUD_Main() hud_draw_maximized = 0; // draw panels in the order specified by panel_order array for(i = REGISTRY_COUNT(hud_panels) - 1; i >= 0; --i) - HUD_Panel_Draw(hud_panels_from(panel_order[i])); + HUD_Panel_Draw(REGISTRY_GET(hud_panels, panel_order[i])); HUD_Vehicle(); diff --git a/qcsrc/client/hud/hud.qh b/qcsrc/client/hud/hud.qh index c0a322244..38ca8a018 100644 --- a/qcsrc/client/hud/hud.qh +++ b/qcsrc/client/hud/hud.qh @@ -11,9 +11,10 @@ bool HUD_WouldShowCursor(); bool QuickMenu_IsOpened(); REGISTRY(hud_panels, BITS(6)) -#define hud_panels_from(i) _hud_panels_from(i, NULL) REGISTER_REGISTRY(hud_panels) +REGISTRY_DEFINE_GET(hud_panels, NULL) + #define _REGISTER_HUD_PANEL(id, draw_func, export_func, configflags, showflags) \ void draw_func(); \ void export_func(int fh); \ diff --git a/qcsrc/client/hud/hud_config.qc b/qcsrc/client/hud/hud_config.qc index 61f0d4dcb..9b768e025 100644 --- a/qcsrc/client/hud/hud_config.qc +++ b/qcsrc/client/hud/hud_config.qc @@ -62,7 +62,7 @@ void HUD_Panel_ExportCfg(string cfgname) // common cvars for all panels for (int i = 0; i < REGISTRY_COUNT(hud_panels); ++i) { - panel = hud_panels_from(i); + panel = REGISTRY_GET(hud_panels, i); HUD_Write_PanelCvar("_pos"); HUD_Write_PanelCvar("_size"); @@ -103,7 +103,7 @@ vector HUD_Panel_CheckMove(vector myPos, vector mySize) vector myTarget = myPos; int i; for (i = 0; i < REGISTRY_COUNT(hud_panels); ++i) { - panel = hud_panels_from(i); + panel = REGISTRY_GET(hud_panels, i); if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; if(panel == highlightedPanel) continue; HUD_Panel_UpdatePosSize(); @@ -200,7 +200,7 @@ vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) { float ratio = mySize.x/mySize.y; int i; for (i = 0; i < REGISTRY_COUNT(hud_panels); ++i) { - panel = hud_panels_from(i); + panel = REGISTRY_GET(hud_panels, i); if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; if(panel == highlightedPanel) continue; HUD_Panel_UpdatePosSize(); @@ -647,7 +647,7 @@ LABEL(find_tab_panel) { for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i) { - panel = hud_panels_from(i); + panel = REGISTRY_GET(hud_panels, i); if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; if (panel == tab_panels[i] || panel == starting_panel) @@ -799,7 +799,7 @@ int HUD_Panel_Check_Mouse_Pos(bool allow_move) i = panel_order[j]; j += 1; - panel = hud_panels_from(i); + panel = REGISTRY_GET(hud_panels, i); if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; HUD_Panel_UpdatePosSize(); @@ -879,7 +879,7 @@ void HUD_Panel_Highlight(float allow_move) i = panel_order[j]; j += 1; - panel = hud_panels_from(i); + panel = REGISTRY_GET(hud_panels, i); if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue; HUD_Panel_UpdatePosSize(); @@ -889,7 +889,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_from(i); + highlightedPanel = REGISTRY_GET(hud_panels, i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 1; panel_click_distance = mousepos - panel_pos; @@ -898,7 +898,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_from(i); + highlightedPanel = REGISTRY_GET(hud_panels, i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; resizeCorner = 1; @@ -909,7 +909,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_from(i); + highlightedPanel = REGISTRY_GET(hud_panels, i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; resizeCorner = 2; @@ -921,7 +921,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_from(i); + highlightedPanel = REGISTRY_GET(hud_panels, i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; resizeCorner = 3; @@ -933,7 +933,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_from(i); + highlightedPanel = REGISTRY_GET(hud_panels, i); HUD_Panel_FirstInDrawQ(i); highlightedAction = 2; resizeCorner = 4; @@ -1083,7 +1083,7 @@ void HUD_Configure_Frame() { hudShiftState = 0; for(i = REGISTRY_COUNT(hud_panels) - 1; i >= 0; --i) - hud_panels_from(panel_order[i]).update_time = time; + REGISTRY_GET(hud_panels, 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/hud/panel/notify.qc b/qcsrc/client/hud/panel/notify.qc index bfb23bf2c..0dfb11db7 100644 --- a/qcsrc/client/hud/panel/notify.qc +++ b/qcsrc/client/hud/panel/notify.qc @@ -126,7 +126,7 @@ void HUD_Notify() { attacker = sprintf(_("Player %d"), count + 1); victim = sprintf(_("Player %d"), count + 2); - icon = Weapons_from(min(WEP_FIRST + count * 2, WEP_LAST)).model2; + icon = REGISTRY_GET(Weapons, min(WEP_FIRST + count * 2, WEP_LAST)).model2; alpha = bound(0, 1.2 - count / entry_count, 1); } else diff --git a/qcsrc/client/hud/panel/radar.qc b/qcsrc/client/hud/panel/radar.qc index b75b36d33..e31aa01e9 100644 --- a/qcsrc/client/hud/panel/radar.qc +++ b/qcsrc/client/hud/panel/radar.qc @@ -368,7 +368,7 @@ void HUD_Radar() drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0); } } - entity icon = RadarIcons_from(it.teamradar_icon); + entity icon = REGISTRY_GET(RadarIcons, it.teamradar_icon); draw_teamradar_icon(it.origin, icon, it, spritelookupcolor(it, icon.netname, it.teamradar_color), panel_fg_alpha); }); AL_EACH(_entcs, e, it != NULL, { diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index d6a073a5d..e51adebd0 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -1228,7 +1228,7 @@ NET_HANDLE(TE_CSQC_PINGPLREPORT, bool isNew) NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew) { int weapon_id = ReadByte(); - complain_weapon = Weapons_from(weapon_id); + complain_weapon = REGISTRY_GET(Weapons, weapon_id); complain_weapon_type = ReadByte(); return = true; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index c5de3aeea..3fccbb3bb 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -787,7 +787,7 @@ void View_EventChase(entity this) { if(hud != HUD_BUMBLEBEE_GUN) { - Vehicle info = Vehicles_from(hud); + Vehicle info = REGISTRY_GET(Vehicles, hud); vehicle_viewdist = info.height; vehicle_viewofs = info.view_ofs; if(vehicle_viewdist < 0) // when set below 0, this vehicle doesn't use third person view (gunner slots) @@ -898,7 +898,7 @@ void HUD_Crosshair_Vehicle(entity this) { if(hud != HUD_BUMBLEBEE_GUN) { - Vehicle info = Vehicles_from(hud); + Vehicle info = REGISTRY_GET(Vehicles, hud); info.vr_crosshair(info, this); } } @@ -1552,7 +1552,7 @@ void SpecialCommand() vector splash_size = '0 0 0'; splash_size.x = max(vid_conwidth, vid_conheight) * SPECIALCOMMAND_SIZE; splash_size.y = max(vid_conwidth, vid_conheight) * SPECIALCOMMAND_SIZE; - entity wep = Weapons_from(slot.z); + entity wep = REGISTRY_GET(Weapons, slot.z); if(wep == WEP_Null) drawpic(vec2(slot), "gfx/smile", vec2(splash_size), specialcommand_colors[j], 0.95, DRAWFLAG_NORMAL); else diff --git a/qcsrc/client/weapons/projectile.qc b/qcsrc/client/weapons/projectile.qc index 067c0badb..fcdac111e 100644 --- a/qcsrc/client/weapons/projectile.qc +++ b/qcsrc/client/weapons/projectile.qc @@ -48,7 +48,8 @@ void Projectile_DrawTrail(entity this, vector to) if (this.traileffect) { particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha); - boxparticles(particleeffectnum(Effects_from(this.traileffect)), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL); + entity eff = REGISTRY_GET(Effects, this.traileffect); + boxparticles(particleeffectnum(eff), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL); } } diff --git a/qcsrc/common/animdecide.qh b/qcsrc/common/animdecide.qh index 16feb948c..bfbba7cb8 100644 --- a/qcsrc/common/animdecide.qh +++ b/qcsrc/common/animdecide.qh @@ -24,7 +24,8 @@ ENDCLASS(Animation) REGISTRY(Animations, BITS(8)) REGISTER_REGISTRY(Animations) -#define Animations_from(id) _Animations_from(id, NULL) + +REGISTRY_DEFINE_GET(Animations, NULL) #define WriteAnimation(to, it) WriteRegistered(Animations, to, it) #define ReadAnimation() ReadRegistered(Animations) #define REGISTER_ANIMATION(id, framenames) \ diff --git a/qcsrc/common/command/reg.qh b/qcsrc/common/command/reg.qh index a6f669fd9..abb40b509 100644 --- a/qcsrc/common/command/reg.qh +++ b/qcsrc/common/command/reg.qh @@ -2,10 +2,11 @@ #include "command.qh" REGISTRY(GENERIC_COMMANDS, BITS(7)) -#define GENERIC_COMMANDS_from(i) _GENERIC_COMMANDS_from(i, NULL) REGISTER_REGISTRY(GENERIC_COMMANDS) REGISTRY_SORT(GENERIC_COMMANDS) +REGISTRY_DEFINE_GET(GENERIC_COMMANDS, NULL) + .bool m_menubased; // switch to tell whether this alias should be registered as a menu or client based command #define GENERIC_COMMAND(id, description, menubased) \ diff --git a/qcsrc/common/deathtypes/all.qc b/qcsrc/common/deathtypes/all.qc index 823a20f8e..6bc2995b2 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_from(deathtype - DT_FIRST); + entity deathent = REGISTRY_GET(Deathtypes, 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 2169c8bd7..f4b498018 100644 --- a/qcsrc/common/deathtypes/all.qh +++ b/qcsrc/common/deathtypes/all.qh @@ -3,10 +3,11 @@ #include REGISTRY(Deathtypes, BITS(8)) -#define Deathtypes_from(i) _Deathtypes_from(i, NULL) REGISTER_REGISTRY(Deathtypes) REGISTRY_CHECK(Deathtypes) +REGISTRY_DEFINE_GET(Deathtypes, NULL) + .entity death_msgself; .entity death_msgmurder; .string death_msgextra; @@ -32,12 +33,12 @@ 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_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 : Weapons_from((t) & DEATH_WEAPONMASK)) +#define DEATH_IS(t, dt) (DEATH_ISSPECIAL(t) && (REGISTRY_GET(Deathtypes, t - DT_FIRST)) == dt) +#define DEATH_ENT(t) (DEATH_ISSPECIAL(t) ? (REGISTRY_GET(Deathtypes, t - DT_FIRST)) : NULL) +#define DEATH_ISVEHICLE(t) (DEATH_ISSPECIAL(t) && (REGISTRY_GET(Deathtypes, t - DT_FIRST)).death_msgextra == "vehicle") +#define DEATH_ISTURRET(t) (DEATH_ISSPECIAL(t) && (REGISTRY_GET(Deathtypes, t - DT_FIRST)).death_msgextra == "turret") +#define DEATH_ISMONSTER(t) (DEATH_ISSPECIAL(t) && (REGISTRY_GET(Deathtypes, t - DT_FIRST)).death_msgextra == "monster") +#define DEATH_WEAPONOF(t) (DEATH_ISSPECIAL(t) ? WEP_Null : REGISTRY_GET(Weapons, (t) & DEATH_WEAPONMASK)) #define DEATH_ISWEAPON(t, w) (DEATH_WEAPONOF(t) == (w)) string Deathtype_Name(int deathtype); diff --git a/qcsrc/common/effects/all.qc b/qcsrc/common/effects/all.qc index 99849deb9..9ee58f5fe 100644 --- a/qcsrc/common/effects/all.qc +++ b/qcsrc/common/effects/all.qc @@ -6,7 +6,7 @@ NET_HANDLE(net_effect, bool isNew) { int net_name = (REGISTRY_COUNT(Effects) >= 255) ? ReadShort() : ReadByte(); - entity eff = Effects_from(net_name); + entity eff = REGISTRY_GET(Effects, net_name); vector vel = '0 0 0'; int eff_cnt = 1; diff --git a/qcsrc/common/effects/all.qh b/qcsrc/common/effects/all.qh index 758161837..fe7bbc31a 100644 --- a/qcsrc/common/effects/all.qh +++ b/qcsrc/common/effects/all.qh @@ -8,11 +8,11 @@ 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(Effects) REGISTRY_CHECK(Effects) #define EFFECT(istrail, name, realname) \ REGISTER(Effects, EFFECT, name, m_id, Create_Effect_Entity(realname, istrail)); EFFECT(0, Null, string_null) +REGISTRY_DEFINE_GET(Effects, EFFECT_Null) #include "all.inc" diff --git a/qcsrc/common/effects/effectinfo.qc b/qcsrc/common/effects/effectinfo.qc index 79d31eb46..6b97dd91b 100644 --- a/qcsrc/common/effects/effectinfo.qc +++ b/qcsrc/common/effects/effectinfo.qc @@ -322,8 +322,9 @@ GENERIC_COMMAND(dumpeffectinfo, "Dump all effectinfo to effectinfo_dump.txt", fa REGISTRY(EffectInfos, BITS(9)) -#define EffectInfos_from(i) _EffectInfos_from(i, NULL) REGISTER_REGISTRY(EffectInfos) + +REGISTRY_DEFINE_GET(EffectInfos, NULL) #define EFFECTINFO(name) \ ACCUMULATE void effectinfo_##name(EffectInfoGroup parent, EffectInfo this) { } \ REGISTER(EffectInfos, EFFECTINFO, name, m_id, NEW(EffectInfoGroup)) { \ diff --git a/qcsrc/common/effects/qc/casings.qc b/qcsrc/common/effects/qc/casings.qc index d07557f9a..68eccb461 100644 --- a/qcsrc/common/effects/qc/casings.qc +++ b/qcsrc/common/effects/qc/casings.qc @@ -81,13 +81,13 @@ SOUND(BRASS1, W_Sound("brass1")); SOUND(BRASS2, W_Sound("brass2")); SOUND(BRASS3, W_Sound("brass3")); Sound SND_BRASS_RANDOM() { - return Sounds_from(SND_BRASS1.m_id + floor(prandom() * 3)); + return REGISTRY_GET(Sounds, 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_from(SND_CASINGS1.m_id + floor(prandom() * 3)); + return REGISTRY_GET(Sounds, SND_CASINGS1.m_id + floor(prandom() * 3)); } void Casing_Touch(entity this, entity toucher) diff --git a/qcsrc/common/effects/qc/globalsound.qc b/qcsrc/common/effects/qc/globalsound.qc index 9fc46ff67..4e8467e8a 100644 --- a/qcsrc/common/effects/qc/globalsound.qc +++ b/qcsrc/common/effects/qc/globalsound.qc @@ -85,7 +85,7 @@ NET_HANDLE(globalsound, bool isnew) { - entity gs = GlobalSounds_from(ReadByte()); + entity gs = REGISTRY_GET(GlobalSounds, ReadByte()); float r = ReadByte() / 255; string sample = GlobalSound_sample(gs.m_globalsoundstr, r); int who = ReadByte(); @@ -112,7 +112,7 @@ NET_HANDLE(playersound, bool isnew) { - entity ps = PlayerSounds_from(ReadByte()); + entity ps = REGISTRY_GET(PlayerSounds, ReadByte()); float r = ReadByte() / 255; int who = ReadByte(); entity e = entcs_receiver(who - 1); diff --git a/qcsrc/common/effects/qc/globalsound.qh b/qcsrc/common/effects/qc/globalsound.qh index b5631ed5f..2b6b52896 100644 --- a/qcsrc/common/effects/qc/globalsound.qh +++ b/qcsrc/common/effects/qc/globalsound.qh @@ -11,7 +11,6 @@ ..string m_playersoundfld; REGISTRY(PlayerSounds, BITS(8) - 1) -#define PlayerSounds_from(i) _PlayerSounds_from(i, NULL) #define REGISTER_PLAYERSOUND(id) \ .string _playersound_##id; \ REGISTER(PlayerSounds, playersound, id, m_id, new_pure(PlayerSound)) \ @@ -21,6 +20,8 @@ REGISTRY(PlayerSounds, BITS(8) - 1) } REGISTER_REGISTRY(PlayerSounds) REGISTRY_SORT(PlayerSounds) + +REGISTRY_DEFINE_GET(PlayerSounds, NULL) STATIC_INIT(PlayerSounds_renumber) { FOREACH(PlayerSounds, true, it.m_id = i); @@ -84,7 +85,6 @@ REGISTER_VOICEMSG(seenenemy, VOICETYPE_TEAMRADIO, false) .string m_globalsoundstr; REGISTRY(GlobalSounds, BITS(8) - 1) -#define GlobalSounds_from(i) _GlobalSounds_from(i, NULL) #define REGISTER_GLOBALSOUND(id, str) \ REGISTER(GlobalSounds, GS, id, m_id, new_pure(GlobalSound)) \ { \ @@ -92,6 +92,8 @@ REGISTRY(GlobalSounds, BITS(8) - 1) } REGISTER_REGISTRY(GlobalSounds) REGISTRY_SORT(GlobalSounds) + +REGISTRY_DEFINE_GET(GlobalSounds, NULL) STATIC_INIT(GlobalSounds_renumber) { FOREACH(GlobalSounds, true, it.m_id = i); diff --git a/qcsrc/common/ent_cs.qc b/qcsrc/common/ent_cs.qc index 2675d3201..a7aa27961 100644 --- a/qcsrc/common/ent_cs.qc +++ b/qcsrc/common/ent_cs.qc @@ -6,10 +6,11 @@ #endif REGISTRY(EntCSProps, BITS(16) - 1) -#define EntCSProps_from(i) _EntCSProps_from(i, NULL) REGISTER_REGISTRY(EntCSProps) REGISTRY_SORT(EntCSProps) REGISTRY_CHECK(EntCSProps) + +REGISTRY_DEFINE_GET(EntCSProps, NULL) STATIC_INIT(EntCSProps_renumber) { FOREACH(EntCSProps, true, it.m_id = i); } // these entcs_props ids need to be referenced directly diff --git a/qcsrc/common/impulses/all.qh b/qcsrc/common/impulses/all.qh index e5a2b7b60..d870e6d2c 100644 --- a/qcsrc/common/impulses/all.qh +++ b/qcsrc/common/impulses/all.qh @@ -3,6 +3,8 @@ REGISTRY(IMPULSES, 255) REGISTER_REGISTRY(IMPULSES) REGISTRY_SORT(IMPULSES) + +REGISTRY_DEFINE_GET(IMPULSES, NULL) STATIC_INIT(IMPULSES_renumber) { FOREACH(IMPULSES, true, it.m_id = i); diff --git a/qcsrc/common/items/all.qh b/qcsrc/common/items/all.qh index 3ae473503..840eb0a88 100644 --- a/qcsrc/common/items/all.qh +++ b/qcsrc/common/items/all.qh @@ -6,7 +6,6 @@ // 24 so it matches the limit for the .items field REGISTRY(Items, 24) -#define Items_from(i) _Items_from(i, NULL) #ifdef GAMEQC REGISTRY_DEPENDS(Items, Models) #endif @@ -15,6 +14,8 @@ REGISTER_REGISTRY(Items) REGISTRY_SORT(Items) REGISTRY_CHECK(Items) + +REGISTRY_DEFINE_GET(Items, NULL) STATIC_INIT(Items) { FOREACH(Items, true, it.m_id = i); } void Dump_Items(); diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index 29a02047f..1c9d21669 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -38,7 +38,7 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew) if (!(minorBits & BIT(j))) { continue; } - const GameItem it = Items_from(Inventory_groups_minor * i + j); + const GameItem it = REGISTRY_GET(Items, Inventory_groups_minor * i + j); .int fld = inv_items[it.m_id]; int prev = this.(fld); int next = this.(fld) = ReadByte(); @@ -86,7 +86,7 @@ void Inventory_Write(Inventory data) if (!(minorBits & BIT(j))) continue; - const entity it = Items_from(Inventory_groups_minor * i + j); + const entity it = REGISTRY_GET(Items, Inventory_groups_minor * i + j); WriteByte(MSG_ENTITY, data.inv_items[it.m_id]); } } diff --git a/qcsrc/common/mapinfo.qc b/qcsrc/common/mapinfo.qc index f771b0f83..ae387e3db 100644 --- a/qcsrc/common/mapinfo.qc +++ b/qcsrc/common/mapinfo.qc @@ -1147,7 +1147,7 @@ int MapInfo_CurrentFeatures() Gametype MapInfo_CurrentGametype() { - Gametype prev = Gametypes_from(cvar("gamecfg")); + Gametype prev = REGISTRY_GET(Gametypes, cvar("gamecfg")); FOREACH(Gametypes, cvar(it.netname) && it != prev, return it); return prev ? prev : MAPINFO_TYPE_DEATHMATCH; } diff --git a/qcsrc/common/mapinfo.qh b/qcsrc/common/mapinfo.qh index b669ba1f7..4d598e88c 100644 --- a/qcsrc/common/mapinfo.qh +++ b/qcsrc/common/mapinfo.qh @@ -101,9 +101,10 @@ CLASS(Gametype, Object) ENDCLASS(Gametype) REGISTRY(Gametypes, 24) -#define Gametypes_from(i) _Gametypes_from(i, NULL) REGISTER_REGISTRY(Gametypes) REGISTRY_CHECK(Gametypes) + +REGISTRY_DEFINE_GET(Gametypes, NULL) #define REGISTER_GAMETYPE(NAME, inst) REGISTER(Gametypes, MAPINFO_TYPE, NAME, m_id, inst) #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 415984a2a..5b4b8a3bd 100644 --- a/qcsrc/common/minigames/cl_minigames.qh +++ b/qcsrc/common/minigames/cl_minigames.qh @@ -101,9 +101,10 @@ void minigame_prompt(); REGISTRY(Minigames, BITS(4)) -#define Minigames_from(i) _Minigames_from(i, NULL) REGISTER_REGISTRY(Minigames) REGISTRY_CHECK(Minigames) + +REGISTRY_DEFINE_GET(Minigames, NULL) #define REGISTER_MINIGAME(name,nicename) \ REGISTER(Minigames, MINIGAME_##name, m_id, new_pure(minigame_descriptor)); \ void name##_hud_board(vector, vector); \ diff --git a/qcsrc/common/minigames/sv_minigames.qh b/qcsrc/common/minigames/sv_minigames.qh index b5015a1f4..28a524d04 100644 --- a/qcsrc/common/minigames/sv_minigames.qh +++ b/qcsrc/common/minigames/sv_minigames.qh @@ -46,9 +46,10 @@ entity minigame_sessions; bool minigame_SendEntity(entity this, entity to, int sf); REGISTRY(Minigames, BITS(4)) -#define Minigames_from(i) _Minigames_from(i, NULL) REGISTER_REGISTRY(Minigames) REGISTRY_CHECK(Minigames) + +REGISTRY_DEFINE_GET(Minigames, NULL) #define REGISTER_MINIGAME(name,nicename) \ REGISTER(Minigames, MINIGAME_##name, m_id, new_pure(minigame_descriptor)); \ int name##_server_event(entity, string, ...); \ diff --git a/qcsrc/common/models/all.inc b/qcsrc/common/models/all.inc index eb95d7c28..fe5c7b93d 100644 --- a/qcsrc/common/models/all.inc +++ b/qcsrc/common/models/all.inc @@ -147,7 +147,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_from(MDL_GIB_ROBO_1.m_id + i); + return REGISTRY_GET(Models, MDL_GIB_ROBO_1.m_id + i); } MODEL(CASING_SHELL, "models/casing_shell.mdl"); @@ -350,7 +350,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_from(MDL_0.m_id + i); + return REGISTRY_GET(Models, MDL_0.m_id + i); return MDL_Null; } diff --git a/qcsrc/common/models/all.qh b/qcsrc/common/models/all.qh index ce9862941..c4f865ddb 100644 --- a/qcsrc/common/models/all.qh +++ b/qcsrc/common/models/all.qh @@ -3,7 +3,6 @@ #include "model.qh" REGISTRY(Models, BITS(9)) -#define Models_from(i) _Models_from(i, MDL_Null) REGISTER_REGISTRY(Models) #define MODEL(name, path) \ @@ -20,4 +19,5 @@ PRECACHE(Models) { } MODEL(Null, "null"); +REGISTRY_DEFINE_GET(Models, MDL_Null) #include "all.inc" diff --git a/qcsrc/common/monsters/all.qh b/qcsrc/common/monsters/all.qh index e31fd0bad..58840159e 100644 --- a/qcsrc/common/monsters/all.qh +++ b/qcsrc/common/monsters/all.qh @@ -3,8 +3,7 @@ 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) +#define get_monsterinfo(i) REGISTRY_GET(Monsters, i) REGISTER_REGISTRY(Monsters) REGISTRY_CHECK(Monsters) const int MON_FIRST = 1; @@ -14,3 +13,4 @@ const int MON_FIRST = 1; #include "monster.qh" REGISTER_MONSTER(Null, NEW(Monster)); +REGISTRY_DEFINE_GET(Monsters, MON_Null) diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index 4f2139cc1..d85b16b0e 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -78,7 +78,7 @@ bool Monster_ValidTarget(entity this, entity targ) if((targ == this) || (autocvar_g_monsters_lineofsight && !checkpvs(this.origin + this.view_ofs, targ)) // enemy cannot be seen - || (IS_VEHICLE(targ) && !((Monsters_from(this.monsterid)).spawnflags & MON_FLAG_RANGED)) // melee vs vehicle is useless + || (IS_VEHICLE(targ) && !((REGISTRY_GET(Monsters, this.monsterid)).spawnflags & MON_FLAG_RANGED)) // melee vs vehicle is useless || (time < game_starttime) // monsters do nothing before match has started || (targ.takedamage == DAMAGE_NO) || (game_stopped) @@ -260,7 +260,7 @@ void Monster_Sound_Precache(string f) void Monster_Sounds_Precache(entity this) { - string m = (Monsters_from(this.monsterid)).m_model.model_str(); + string m = (REGISTRY_GET(Monsters, this.monsterid)).m_model.model_str(); float globhandle, n, i; string f; @@ -465,7 +465,7 @@ void Monster_UpdateModel(entity this) this.anim_die2 = animfixfps(this, '9 1 0.01', '0 0 0');*/ // then get the real values - Monster mon = Monsters_from(this.monsterid); + Monster mon = REGISTRY_GET(Monsters, this.monsterid); mon.mr_anim(mon, this); } @@ -977,7 +977,7 @@ void Monster_Dead(entity this, entity attacker, float gibbed) CSQCModel_UnlinkEntity(this); - Monster mon = Monsters_from(this.monsterid); + Monster mon = REGISTRY_GET(Monsters, this.monsterid); mon.mr_death(mon, this); if(this.candrop && this.weapon) @@ -1008,7 +1008,7 @@ void Monster_Damage(entity this, entity inflictor, entity attacker, float damage float take = v.x; //float save = v.y; - Monster mon = Monsters_from(this.monsterid); + Monster mon = REGISTRY_GET(Monsters, this.monsterid); take = mon.mr_pain(mon, this, take, attacker, deathtype); if(take) @@ -1235,7 +1235,7 @@ void Monster_Think(entity this) this.last_enemycheck = time + 1; // check for enemies every second } - Monster mon = Monsters_from(this.monsterid); + Monster mon = REGISTRY_GET(Monsters, this.monsterid); if(mon.mr_think(mon, this)) { Monster_Move(this, this.speed2, this.speed, this.stopspeed); @@ -1251,7 +1251,7 @@ void Monster_Think(entity this) bool Monster_Spawn_Setup(entity this) { - Monster mon = Monsters_from(this.monsterid); + Monster mon = REGISTRY_GET(Monsters, this.monsterid); mon.mr_setup(mon, this); // ensure some basic needs are met @@ -1317,7 +1317,7 @@ bool Monster_Spawn_Setup(entity this) bool Monster_Spawn(entity this, bool check_appear, int mon_id) { // setup the basic required properties for a monster - entity mon = Monsters_from(mon_id); + entity mon = REGISTRY_GET(Monsters, mon_id); if(!mon.monsterid) { return false; } // invalid monster if(!autocvar_g_monsters) { Monster_Remove(this); return false; } diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh index cc4cc0129..2b4d3e34c 100644 --- a/qcsrc/common/mutators/base.qh +++ b/qcsrc/common/mutators/base.qh @@ -165,7 +165,8 @@ CLASS(Mutator, Object) ENDCLASS(Mutator) REGISTRY(Mutators, BITS(7)) -#define Mutators_from(i) _Mutators_from(i, NULL) + +REGISTRY_DEFINE_GET(Mutators, NULL) bool Mutator_Add(Mutator mut); void Mutator_Remove(Mutator mut); bool mutator_log = false; diff --git a/qcsrc/common/mutators/mutator/buffs/buffs.qc b/qcsrc/common/mutators/mutator/buffs/buffs.qc index 4a5dcc82a..2ab07ddf2 100644 --- a/qcsrc/common/mutators/mutator/buffs/buffs.qc +++ b/qcsrc/common/mutators/mutator/buffs/buffs.qc @@ -2,7 +2,7 @@ string BUFF_NAME(int i) { - Buff b = Buffs_from(i); + Buff b = REGISTRY_GET(Buffs, i); return strcat(rgb_to_hexcolor(b.m_color), b.m_name); } diff --git a/qcsrc/common/mutators/mutator/buffs/buffs.qh b/qcsrc/common/mutators/mutator/buffs/buffs.qh index b381db4be..91f56066f 100644 --- a/qcsrc/common/mutators/mutator/buffs/buffs.qh +++ b/qcsrc/common/mutators/mutator/buffs/buffs.qh @@ -13,7 +13,6 @@ REGISTER_RADARICON(Buff, 1); #endif REGISTRY(Buffs, BITS(5)) -#define Buffs_from(i) _Buffs_from(i, BUFF_Null) REGISTER_REGISTRY(Buffs) REGISTRY_CHECK(Buffs) @@ -72,4 +71,5 @@ entity buff_FirstFromFlags(int _buffs); REGISTER_BUFF(Null); BUFF_SPAWNFUNCS(random, BUFF_Null) +REGISTRY_DEFINE_GET(Buffs, BUFF_Null) #include "all.inc" diff --git a/qcsrc/common/mutators/mutator/buffs/cl_buffs.qc b/qcsrc/common/mutators/mutator/buffs/cl_buffs.qc index 349ca20b8..f33e3ff63 100644 --- a/qcsrc/common/mutators/mutator/buffs/cl_buffs.qc +++ b/qcsrc/common/mutators/mutator/buffs/cl_buffs.qc @@ -15,7 +15,7 @@ MUTATOR_HOOKFUNCTION(cl_buffs, WP_Format) string s = M_ARGV(1, string); if (s == WP_Buff.netname || s == RADARICON_Buff.netname) { - Buff b = Buffs_from(this.wp_extra); + Buff b = REGISTRY_GET(Buffs, this.wp_extra); M_ARGV(2, vector) = b.m_color; M_ARGV(3, string) = b.m_name; M_ARGV(4, string) = strcat("buff_", b.netname); diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index 9ac33b45b..7dffc0f4d 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -125,7 +125,7 @@ void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expan float bonusNades = STAT(NADE_BONUS); float bonusProgress = STAT(NADE_BONUS_SCORE); float bonusType = STAT(NADE_BONUS_TYPE); - Nade def = Nades_from(bonusType); + Nade def = REGISTRY_GET(Nades, bonusType); vector nadeColor = def.m_color; string nadeIcon = def.m_icon; @@ -181,7 +181,7 @@ void nade_timer_think(entity this) void nade_burn_spawn(entity _nade) { - CSQCProjectile(_nade, true, Nades_from(STAT(NADE_BONUS_TYPE, _nade)).m_projectile[true], true); + CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[true], true); } void nade_spawn(entity _nade) @@ -199,7 +199,7 @@ void nade_spawn(entity _nade) _nade.effects |= EF_LOWPRECISION; - CSQCProjectile(_nade, true, Nades_from(STAT(NADE_BONUS_TYPE, _nade)).m_projectile[false], true); + CSQCProjectile(_nade, true, REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, _nade)).m_projectile[false], true); } void napalm_damage(entity this, float dist, float damage, float edgedamage, float burntime) @@ -714,7 +714,7 @@ void nade_boom(entity this) entity expef = NULL; bool nade_blast = true; - switch ( Nades_from(STAT(NADE_BONUS_TYPE, this)) ) + switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) ) { case NADE_TYPE_NAPALM: nade_blast = autocvar_g_nades_napalm_blast; @@ -776,7 +776,7 @@ void nade_boom(entity this) } if(this.takedamage) - switch ( Nades_from(STAT(NADE_BONUS_TYPE, this)) ) + switch ( REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)) ) { case NADE_TYPE_NAPALM: nade_napalm_boom(this); break; case NADE_TYPE_ICE: nade_ice_boom(this); break; @@ -1074,7 +1074,10 @@ bool nade_customize(entity this, entity client) { //this.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION; if(!this.traileffectnum) - this.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(STAT(NADE_BONUS_TYPE, this)).m_projectile[false], this.team).eent_eff_name); + { + entity nade = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, this)); + this.traileffectnum = _particleeffectnum(Nade_TrailEffect(nade.m_projectile[false], this.team).eent_eff_name); + } this.alpha = 1; } @@ -1088,7 +1091,7 @@ void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, strin STAT(NADE_BONUS_TYPE, n) = max(1, ntype); n.pokenade_type = pntype; - if(Nades_from(STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null) + if(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)) == NADE_TYPE_Null) STAT(NADE_BONUS_TYPE, n) = NADE_TYPE_NORMAL.m_id; .entity weaponentity = weaponentities[0]; // TODO: unhardcode @@ -1097,8 +1100,8 @@ void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, strin //setattachment(n, player, "bip01 l hand"); n.exteriormodeltoclient = player; setcefc(n, nade_customize); - n.traileffectnum = _particleeffectnum(Nade_TrailEffect(Nades_from(STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name); - n.colormod = Nades_from(STAT(NADE_BONUS_TYPE, n)).m_color; + n.traileffectnum = _particleeffectnum(Nade_TrailEffect(REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_projectile[false], player.team).eent_eff_name); + n.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color; n.realowner = nowner; n.colormap = player.colormap; n.glowmod = player.glowmod; @@ -1109,19 +1112,19 @@ void spawn_held_nade(entity player, entity nowner, float ntime, int ntype, strin n.projectiledeathtype = DEATH_NADE.m_id; n.weaponentity_fld = weaponentity; n.nade_lifetime = ntime; - n.alpha = Nades_from(STAT(NADE_BONUS_TYPE, n)).m_alpha; + n.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha; setmodel(fn, MDL_NADE_VIEW); //setattachment(fn, player.(weaponentity), ""); fn.viewmodelforclient = player; fn.realowner = fn.owner = player; - fn.colormod = Nades_from(STAT(NADE_BONUS_TYPE, n)).m_color; + fn.colormod = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_color; fn.colormap = player.colormap; fn.glowmod = player.glowmod; setthink(fn, SUB_Remove); fn.nextthink = n.wait; fn.weaponentity_fld = weaponentity; - fn.alpha = Nades_from(STAT(NADE_BONUS_TYPE, n)).m_alpha; + fn.alpha = REGISTRY_GET(Nades, STAT(NADE_BONUS_TYPE, n)).m_alpha; player.nade = n; player.fake_nade = fn; diff --git a/qcsrc/common/mutators/mutator/nades/nades.qh b/qcsrc/common/mutators/mutator/nades/nades.qh index d76eb9414..963dbce38 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qh +++ b/qcsrc/common/mutators/mutator/nades/nades.qh @@ -22,7 +22,6 @@ const int PROJECTILE_NADE_VEIL = 86; const int PROJECTILE_NADE_VEIL_BURN = 87; REGISTRY(Nades, BITS(4)) -#define Nades_from(i) _Nades_from(i, NADE_TYPE_Null) REGISTER_REGISTRY(Nades) REGISTRY_CHECK(Nades) @@ -42,6 +41,7 @@ CLASS(Nade, Object) ENDCLASS(Nade) REGISTER_NADE(Null); +REGISTRY_DEFINE_GET(Nades, NADE_TYPE_Null) Nade Nade_FromProjectile(int proj) { diff --git a/qcsrc/common/mutators/mutator/nix/sv_nix.qc b/qcsrc/common/mutators/mutator/nix/sv_nix.qc index 7214a699e..b399d3c62 100644 --- a/qcsrc/common/mutators/mutator/nix/sv_nix.qc +++ b/qcsrc/common/mutators/mutator/nix/sv_nix.qc @@ -80,7 +80,7 @@ REGISTER_MUTATOR(nix, expr_evaluate(cvar_string("g_nix")) && !MUTATOR_IS_ENABLED bool NIX_CanChooseWeapon(int wpn) { - entity e = Weapons_from(wpn); + entity e = REGISTRY_GET(Weapons, wpn); if (e == WEP_Null) return false; // skip dummies if(g_weaponarena) { @@ -125,12 +125,12 @@ void NIX_GiveCurrentWeapon(entity this) nix_nextchange = time; // start the first round now! else nix_nextchange = time + autocvar_g_balance_nix_roundtime; - // Weapon w = Weapons_from(nix_weapon); + // Weapon w = REGISTRY_GET(Weapons, nix_weapon); // w.wr_init(w); // forget it, too slow } // get weapon info - entity wpn = Weapons_from(nix_weapon); + entity wpn = REGISTRY_GET(Weapons, nix_weapon); if(nix_nextchange != this.nix_lastchange_id) // this shall only be called once per round! { diff --git a/qcsrc/common/mutators/mutator/waypoints/all.qh b/qcsrc/common/mutators/mutator/waypoints/all.qh index 132600237..fa1cbd31a 100644 --- a/qcsrc/common/mutators/mutator/waypoints/all.qh +++ b/qcsrc/common/mutators/mutator/waypoints/all.qh @@ -3,7 +3,6 @@ #include "waypointsprites.qh" REGISTRY(Waypoints, BITS(7)) -#define Waypoints_from(i) _Waypoints_from(i, WP_Null) REGISTER_REGISTRY(Waypoints) REGISTRY_CHECK(Waypoints) @@ -30,7 +29,6 @@ ENDCLASS(Waypoint) #define REGISTER_WAYPOINT(id, text, icon, color, blink) REGISTER_WAYPOINT_(id, NEW(Waypoint, #id, text, icon, color, blink)) REGISTRY(RadarIcons, BITS(7)) -#define RadarIcons_from(i) _RadarIcons_from(i, RADARICON_NONE) REGISTER_REGISTRY(RadarIcons) REGISTRY_CHECK(RadarIcons) @@ -38,8 +36,11 @@ REGISTRY_CHECK(RadarIcons) #define REGISTER_RADARICON(id, num) REGISTER(RadarIcons, RADARICON, id, m_id, new_pure(RadarIcon)) { this.m_radaricon = num; this.netname = #id; } REGISTER_WAYPOINT(Null, "", "", '0 0 0', 1); +REGISTRY_DEFINE_GET(Waypoints, WP_Null) REGISTER_RADARICON(NONE, 0); +REGISTRY_DEFINE_GET(RadarIcons, RADARICON_NONE) + REGISTER_RADARICON(FLAG, 1); REGISTER_RADARICON(FLAGCARRIER, 1); diff --git a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc index 0b4fe28ff..786971645 100644 --- a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc +++ b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc @@ -213,10 +213,10 @@ void Ent_WaypointSprite(entity this, bool isnew) float spritelookupblinkvalue(entity this, string s) { if (s == WP_Weapon.netname) { - if (Weapons_from(this.wp_extra).spawnflags & WEP_FLAG_SUPERWEAPON) + if (REGISTRY_GET(Weapons, this.wp_extra).spawnflags & WEP_FLAG_SUPERWEAPON) return 2; } - if (s == WP_Item.netname) return Items_from(this.wp_extra).m_waypointblink; + if (s == WP_Item.netname) return REGISTRY_GET(Items, this.wp_extra).m_waypointblink; if(s == WP_FlagReturn.netname) return 2; return 1; @@ -224,8 +224,8 @@ float spritelookupblinkvalue(entity this, string s) vector spritelookupcolor(entity this, string s, vector def) { - if (s == WP_Weapon.netname || s == RADARICON_Weapon.netname) return Weapons_from(this.wp_extra).wpcolor; - if (s == WP_Item.netname || s == RADARICON_Item.netname) return Items_from(this.wp_extra).m_color; + if (s == WP_Weapon.netname || s == RADARICON_Weapon.netname) return REGISTRY_GET(Weapons, this.wp_extra).wpcolor; + if (s == WP_Item.netname || s == RADARICON_Item.netname) return REGISTRY_GET(Items, this.wp_extra).m_color; if (MUTATOR_CALLHOOK(WP_Format, this, s)) { return M_ARGV(2, vector); @@ -238,8 +238,8 @@ string spritelookuptext(entity this, string s) if(autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam) return "Spam"; // no need to translate this debug string if (s == WP_RaceStartFinish.netname) return (race_checkpointtime || race_mycheckpointtime) ? _("Finish") : _("Start"); - if (s == WP_Weapon.netname) return Weapons_from(this.wp_extra).m_name; - if (s == WP_Item.netname) return Items_from(this.wp_extra).m_waypoint; + if (s == WP_Weapon.netname) return REGISTRY_GET(Weapons, this.wp_extra).m_name; + if (s == WP_Item.netname) return REGISTRY_GET(Items, this.wp_extra).m_waypoint; if (s == WP_Monster.netname) return get_monsterinfo(this.wp_extra).monster_name; if (MUTATOR_CALLHOOK(WP_Format, this, s)) { @@ -257,9 +257,9 @@ string spritelookuptext(entity this, string s) string spritelookupicon(entity this, string s) { // TODO: needs icons! //if (s == WP_RaceStartFinish.netname) return (race_checkpointtime || race_mycheckpointtime) ? _("Finish") : _("Start"); - if (s == WP_Weapon.netname) return Weapons_from(this.wp_extra).model2; - if (s == WP_Item.netname) return Items_from(this.wp_extra).m_icon; - if (s == WP_Vehicle.netname) return Vehicles_from(this.wp_extra).m_icon; + if (s == WP_Weapon.netname) return REGISTRY_GET(Weapons, this.wp_extra).model2; + if (s == WP_Item.netname) return REGISTRY_GET(Items, this.wp_extra).m_icon; + if (s == WP_Vehicle.netname) return REGISTRY_GET(Vehicles, this.wp_extra).m_icon; //if (s == WP_Monster.netname) return get_monsterinfo(this.wp_extra).m_icon; if (MUTATOR_CALLHOOK(WP_Format, this, s)) { diff --git a/qcsrc/common/notifications/all.qh b/qcsrc/common/notifications/all.qh index 3b009b256..bbaa8845e 100644 --- a/qcsrc/common/notifications/all.qh +++ b/qcsrc/common/notifications/all.qh @@ -435,7 +435,7 @@ string BUFF_NAME(int i); ARG_CASE(ARG_CS_SV, "spree_inf", (autocvar_notification_show_sprees ? notif_arg_spree_inf(1, input, s2, f2) : "")) \ 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", Weapons_from(f1).m_name) \ + ARG_CASE(ARG_CS_SV, "item_wepname", REGISTRY_GET(Weapons, f1).m_name) \ ARG_CASE(ARG_CS_SV, "item_buffname", BUFF_NAME(f1)) \ ARG_CASE(ARG_CS_SV, "f3buffname", BUFF_NAME(f3)) \ ARG_CASE(ARG_CS_SV, "item_wepammo", (f2 > 0 ? notif_arg_item_wepammo(f1, f2) : "")) \ @@ -633,7 +633,7 @@ string notif_arg_spree_inf(float type, string input, string player, float spree) string notif_arg_item_wepammo(float f1, float f2) { string ammoitems = ""; - Weapon wep = Weapons_from(f1); + Weapon wep = REGISTRY_GET(Weapons, f1); switch (wep.ammo_type) { case RES_SHELLS: ammoitems = ITEM_Shells.m_name; break; @@ -701,6 +701,8 @@ string notif_arg_item_wepammo(float f1, float f2) REGISTRY(Notifications, BITS(11)) REGISTER_REGISTRY(Notifications) REGISTRY_SORT(Notifications); + +REGISTRY_DEFINE_GET(Notifications, NULL) STATIC_INIT(Notifications) { FOREACH(Notifications, true, it.m_id = i); } REGISTRY_CHECK(Notifications) @@ -730,7 +732,7 @@ string Get_Notif_CvarName(Notification notif) Notification Get_Notif_Ent(MSG net_type, int net_name) { - Notification it = _Notifications_from(net_name, NULL); + Notification it = REGISTRY_GET(Notifications, net_name); if (it.nent_type != net_type) { LOG_WARNF("Get_Notif_Ent(%s (%d), %s (%d)): Improper net type '%s'!", Get_Notif_TypeName(net_type), net_type, diff --git a/qcsrc/common/scores.qh b/qcsrc/common/scores.qh index 377a78077..3bc6c5563 100644 --- a/qcsrc/common/scores.qh +++ b/qcsrc/common/scores.qh @@ -4,10 +4,11 @@ #define REGISTER_SP(id) REGISTER(Scores, SP, id, m_id, new_pure(PlayerScoreField)) REGISTRY(Scores, MAX_SCORE); -#define Scores_from(i) _Scores_from(i, NULL) REGISTER_REGISTRY(Scores) REGISTRY_SORT(Scores); REGISTRY_CHECK(Scores); + +REGISTRY_DEFINE_GET(Scores, NULL) STATIC_INIT(Scores_renumber) { FOREACH(Scores, true, it.m_id = i); } /* diff --git a/qcsrc/common/sounds/all.inc b/qcsrc/common/sounds/all.inc index 29f2946b0..58b145a4c 100644 --- a/qcsrc/common/sounds/all.inc +++ b/qcsrc/common/sounds/all.inc @@ -39,7 +39,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_from(SND_GRENADE_BOUNCE1.m_id + rint(random() * 5)); + return REGISTRY_GET(Sounds, SND_GRENADE_BOUNCE1.m_id + rint(random() * 5)); } SOUND(GRENADE_FIRE, W_Sound("grenade_fire")); SOUND(GRENADE_IMPACT, W_Sound("grenade_impact")); @@ -51,7 +51,7 @@ SOUND(HAGEXP1, W_Sound("hagexp1")); SOUND(HAGEXP2, W_Sound("hagexp2")); SOUND(HAGEXP3, W_Sound("hagexp3")); Sound SND_HAGEXP_RANDOM() { - return Sounds_from(SND_HAGEXP1.m_id + rint(random() * 2)); + return REGISTRY_GET(Sounds, SND_HAGEXP1.m_id + rint(random() * 2)); } SOUND(HOOKBOMB_FIRE, W_Sound("hookbomb_fire")); @@ -74,7 +74,7 @@ SOUND(NEXWHOOSH1, W_Sound("nexwhoosh1")); SOUND(NEXWHOOSH2, W_Sound("nexwhoosh2")); SOUND(NEXWHOOSH3, W_Sound("nexwhoosh3")); Sound SND_NEXWHOOSH_RANDOM() { - return Sounds_from(SND_NEXWHOOSH1.m_id + rint(random() * 2)); + return REGISTRY_GET(Sounds, SND_NEXWHOOSH1.m_id + rint(random() * 2)); } SOUND(RELOAD, W_Sound("reload")); // until weapons have individual reload sounds, precache the reload sound here @@ -82,7 +82,7 @@ SOUND(RIC1, W_Sound("ric1")); SOUND(RIC2, W_Sound("ric2")); SOUND(RIC3, W_Sound("ric3")); Sound SND_RIC_RANDOM() { - return Sounds_from(SND_RIC1.m_id + rint(random() * 2)); + return REGISTRY_GET(Sounds, SND_RIC1.m_id + rint(random() * 2)); } SOUND(ROCKET_DET, W_Sound("rocket_det")); @@ -265,7 +265,7 @@ SOUND(GIB_SPLAT02, "misc/gib_splat02"); SOUND(GIB_SPLAT03, "misc/gib_splat03"); SOUND(GIB_SPLAT04, "misc/gib_splat04"); Sound SND_GIB_SPLAT_RANDOM() { - return Sounds_from(SND_GIB_SPLAT01.m_id + floor(prandom() * 4)); + return REGISTRY_GET(Sounds, SND_GIB_SPLAT01.m_id + floor(prandom() * 4)); } SOUND(HIT, "misc/hit"); diff --git a/qcsrc/common/sounds/all.qh b/qcsrc/common/sounds/all.qh index b7b296341..6d011e21a 100644 --- a/qcsrc/common/sounds/all.qh +++ b/qcsrc/common/sounds/all.qh @@ -3,7 +3,6 @@ #include "sound.qh" REGISTRY(Sounds, BITS(9)) -#define Sounds_from(i) _Sounds_from(i, SND_Null) REGISTER_REGISTRY(Sounds) #define SOUND(name, path) \ @@ -18,5 +17,6 @@ PRECACHE(Sounds) { } SOUND(Null, "misc/null"); +REGISTRY_DEFINE_GET(Sounds, SND_Null) #include "all.inc" #include "all.qc" diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index e1d9d583b..7ecbd58e9 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -505,7 +505,7 @@ void Item_RespawnCountdown(entity this) { do { { - entity wi = Weapons_from(this.weapon); + entity wi = REGISTRY_GET(Weapons, this.weapon); if (wi != WEP_Null) { entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Weapon); wp.wp_extra = wi.m_id; @@ -853,7 +853,7 @@ bool Item_GiveTo(entity item, entity player) { .entity weaponentity = weaponentities[slot]; if(player.(weaponentity).m_weapon != WEP_Null || slot == 0) - W_SwitchWeapon_Force(player, Weapons_from(item.weapon), weaponentity); + W_SwitchWeapon_Force(player, REGISTRY_GET(Weapons, item.weapon), weaponentity); } return true; } @@ -1200,7 +1200,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default } if(weaponid) - STAT(WEAPONS, this) = WepSet_FromWeapon(Weapons_from(weaponid)); + STAT(WEAPONS, this) = WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid)); this.flags = FL_ITEM | itemflags; IL_PUSH(g_items, this); @@ -1304,7 +1304,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default this.is_item = true; } - weaponsInMap |= WepSet_FromWeapon(Weapons_from(weaponid)); + weaponsInMap |= WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid)); if ( def.instanceOfPowerup || def.instanceOfWeaponPickup @@ -1588,7 +1588,7 @@ spawnfunc(target_items) float GiveWeapon(entity e, float wpn, float op, float val) { WepSet v0, v1; - WepSet s = WepSet_FromWeapon(Weapons_from(wpn)); + WepSet s = WepSet_FromWeapon(REGISTRY_GET(Weapons, wpn)); v0 = (STAT(WEAPONS, e) & s); switch(op) { diff --git a/qcsrc/common/turrets/all.qh b/qcsrc/common/turrets/all.qh index ee0e1918e..5727234e2 100644 --- a/qcsrc/common/turrets/all.qh +++ b/qcsrc/common/turrets/all.qh @@ -6,8 +6,7 @@ #include "turret.qh" REGISTRY(Turrets, BITS(5)) -#define Turrets_from(i) _Turrets_from(i, TUR_Null) -#define get_turretinfo(i) Turrets_from(i) +#define get_turretinfo(i) REGISTRY_GET(Turrets, i) REGISTER_REGISTRY(Turrets) REGISTRY_CHECK(Turrets) @@ -117,5 +116,6 @@ const int TUR_FIRST = 1; #define REGISTER_TURRET(id, inst) REGISTER(Turrets, TUR, id, m_id, inst) REGISTER_TURRET(Null, NEW(Turret)); +REGISTRY_DEFINE_GET(Turrets, TUR_Null) #include "turret/_mod.qh" diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 3b7513013..3567a2b09 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -508,7 +508,7 @@ string fixPriorityList(string order, float from, float to, float subtract, float n = tokenize_console(neworder); for(w = to; w >= from; --w) { - int wflags = Weapons_from(w).spawnflags; + int wflags = REGISTRY_GET(Weapons, w).spawnflags; if(wflags & WEP_FLAG_SPECIALATTACK) continue; for(i = 0; i < n; ++i) diff --git a/qcsrc/common/vehicles/all.qh b/qcsrc/common/vehicles/all.qh index 94af40c66..2e4a2be50 100644 --- a/qcsrc/common/vehicles/all.qh +++ b/qcsrc/common/vehicles/all.qh @@ -3,7 +3,6 @@ #include "vehicle.qh" REGISTRY(Vehicles, BITS(4)) -#define Vehicles_from(i) _Vehicles_from(i, VEH_Null) REGISTER_REGISTRY(Vehicles) REGISTRY_CHECK(Vehicles) @@ -19,5 +18,6 @@ const int VEH_FIRST = 1; #endif REGISTER_VEHICLE(Null, NEW(Vehicle)); +REGISTRY_DEFINE_GET(Vehicles, VEH_Null) #include "vehicle/_mod.qh" diff --git a/qcsrc/common/vehicles/cl_vehicles.qc b/qcsrc/common/vehicles/cl_vehicles.qc index 06c8484ff..667c1f75a 100644 --- a/qcsrc/common/vehicles/cl_vehicles.qc +++ b/qcsrc/common/vehicles/cl_vehicles.qc @@ -134,7 +134,7 @@ NET_HANDLE(TE_CSQC_VEHICLESETUP, bool isnew) AuxiliaryXhair[0].axh_image = vCROSS_BURST; // Plasma cannons AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Raygun } else { - Vehicle info = Vehicles_from(hud_id); + Vehicle info = REGISTRY_GET(Vehicles, hud_id); info.vr_setup(info, NULL); } } diff --git a/qcsrc/common/vehicles/sv_vehicles.qc b/qcsrc/common/vehicles/sv_vehicles.qc index 3ec02901d..cc2e13e22 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qc +++ b/qcsrc/common/vehicles/sv_vehicles.qc @@ -450,7 +450,7 @@ void vehicles_reset_colors(entity this, entity player) this.velocity = '0 0 0'; this.effects = eff; - Vehicle info = Vehicles_from(this.vehicleid); + Vehicle info = REGISTRY_GET(Vehicles, this.vehicleid); info.vr_setcolors(info, this); } @@ -741,7 +741,7 @@ void vehicles_damage(entity this, entity inflictor, entity attacker, float damag antilag_clear(this, this); - Vehicle info = Vehicles_from(this.vehicleid); + Vehicle info = REGISTRY_GET(Vehicles, this.vehicleid); info.vr_death(info, this); vehicles_setreturn(this); } @@ -931,7 +931,7 @@ void vehicles_touch(entity this, entity toucher) } if(this.play_time < time) { - Vehicle info = Vehicles_from(this.vehicleid); + Vehicle info = REGISTRY_GET(Vehicles, this.vehicleid); info.vr_impact(info, this); } @@ -976,7 +976,7 @@ void vehicles_enter(entity pl, entity veh) || (pl.vehicle) ) { return; } - Vehicle info = Vehicles_from(veh.vehicleid); + Vehicle info = REGISTRY_GET(Vehicles, veh.vehicleid); if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO) if(veh.vehicle_flags & VHF_MULTISLOT) @@ -1115,7 +1115,7 @@ void vehicles_think(entity this) if(this.owner) STAT(VEHICLESTAT_W2MODE, this.owner) = STAT(VEHICLESTAT_W2MODE, this); - Vehicle info = Vehicles_from(this.vehicleid); + Vehicle info = REGISTRY_GET(Vehicles, this.vehicleid); info.vr_think(info, this); vehicles_painframe(this); @@ -1188,7 +1188,7 @@ void vehicles_spawn(entity this) }); - Vehicle info = Vehicles_from(this.vehicleid); + Vehicle info = REGISTRY_GET(Vehicles, this.vehicleid); info.vr_spawn(info, this); vehicles_reset_colors(this, NULL); diff --git a/qcsrc/common/vehicles/vehicle/bumblebee_weapons.qc b/qcsrc/common/vehicles/vehicle/bumblebee_weapons.qc index 81fd93aa0..0afd31f8c 100644 --- a/qcsrc/common/vehicles/vehicle/bumblebee_weapons.qc +++ b/qcsrc/common/vehicles/vehicle/bumblebee_weapons.qc @@ -96,7 +96,8 @@ void bumble_raygun_draw(entity this) if(this.bumble_raygun_nextdraw < time) { - boxparticles(particleeffectnum(Effects_from(this.traileffect)), this, this.origin, this.origin + _dir * -64, _dir * -_len , _dir * -_len, 1, PARTICLES_USEALPHA); + entity eff = REGISTRY_GET(Effects, this.traileffect); + boxparticles(particleeffectnum(eff), this, this.origin, this.origin + _dir * -64, _dir * -_len , _dir * -_len, 1, PARTICLES_USEALPHA); boxparticles(this.lip, this, this.bumble_origin, this.bumble_origin + _dir * -64, _dir * -200 , _dir * -200, 1, PARTICLES_USEALPHA); this.bumble_raygun_nextdraw = time + 0.1; } diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 45ba22906..736ed9c9d 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -107,7 +107,7 @@ string W_NameWeaponOrder_MapFunc(string s) int i = stof(s); if (s == "0" || i) { - entity wi = Weapons_from(i); + entity wi = REGISTRY_GET(Weapons, i); if (wi != WEP_Null) return wi.netname; } return s; @@ -156,9 +156,9 @@ void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass) float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass) { int si = W_FixWeaponOrder_BuildImpulseList_buf[i]; - Weapon e1 = Weapons_from(si); + Weapon e1 = REGISTRY_GET(Weapons, si); int sj = W_FixWeaponOrder_BuildImpulseList_buf[j]; - Weapon e2 = Weapons_from(sj); + Weapon e2 = REGISTRY_GET(Weapons, sj); int d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10; if (d != 0) return -d; // high impulse first! return strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index e82dce3da..1a6dddbc2 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -25,7 +25,6 @@ WepSet ReadWepSet(); #include REGISTRY(Weapons, 72) // Increase as needed. Can be up to 72. -#define Weapons_from(i) _Weapons_from(i, WEP_Null) REGISTER_REGISTRY(Weapons) STATIC_INIT(WeaponPickup) { FOREACH(Weapons, true, it.m_pickup = NEW(WeaponPickup, it)); } @@ -126,6 +125,7 @@ STATIC_INIT_LATE(W_PROP_reloader) [[alias("WEP_" #id)]] Weapon _wep_##sname REGISTER_WEAPON(Null, NEW(Weapon)); +REGISTRY_DEFINE_GET(Weapons, WEP_Null) Weapon Weapons_fromstr(string s) { @@ -256,7 +256,7 @@ const .float reloading_time = reload_time; .void(Weapon this, int i) wr_net; NET_HANDLE(WeaponUpdate, bool isnew) { - Weapon w = Weapons_from(ReadByte()); + Weapon w = REGISTRY_GET(Weapons, ReadByte()); for (int i; (i = ReadByte()); ) { w.wr_net(w, i); @@ -333,7 +333,7 @@ STATIC_INIT(register_weapons_done) #endif weaponorder_byid = ""; for (int i = REGISTRY_MAX(Weapons) - 1; i >= 1; --i) - if (Weapons_from(i)) + if (REGISTRY_GET(Weapons, i)) weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i)); weaponorder_byid = strzone(substring(weaponorder_byid, 1, -1)); } diff --git a/qcsrc/common/wepent.qc b/qcsrc/common/wepent.qc index 38ef3bd1f..5e78207d4 100644 --- a/qcsrc/common/wepent.qc +++ b/qcsrc/common/wepent.qc @@ -8,15 +8,15 @@ MACRO_END #define WEPENT_NETPROPS(PROP) PROP(false, sv_entnum, WEPENT_SET_NORMAL, {}, {}) /* sentinel */ \ PROP(false, m_switchweapon, WEPENT_SET_NORMAL, \ { WriteByte(chan, this.m_switchweapon.m_id); }, \ - { (viewmodels[this.m_wepent_slot]).switchweapon = Weapons_from(ReadByte()); }) \ + { (viewmodels[this.m_wepent_slot]).switchweapon = REGISTRY_GET(Weapons, ReadByte()); }) \ \ PROP(false, m_switchingweapon, WEPENT_SET_NORMAL, \ { WriteByte(chan, this.m_switchingweapon.m_id); }, \ - { (viewmodels[this.m_wepent_slot]).switchingweapon = Weapons_from(ReadByte()); }) \ + { (viewmodels[this.m_wepent_slot]).switchingweapon = REGISTRY_GET(Weapons, ReadByte()); }) \ \ PROP(false, m_weapon, WEPENT_SET_NORMAL, \ { WriteByte(chan, this.m_weapon.m_id); }, \ - { (viewmodels[this.m_wepent_slot]).activeweapon = Weapons_from(ReadByte()); }) \ + { (viewmodels[this.m_wepent_slot]).activeweapon = REGISTRY_GET(Weapons, ReadByte()); }) \ \ PROP(false, m_alpha, WEPENT_SET_NORMAL, \ { WriteByte(chan, rint(bound(-1, 254 * this.m_alpha, 254) - -1)); }, \ diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index a6c363b8f..71950fb73 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -40,10 +40,11 @@ string _net_prevmsgstr; #define REGISTER_NET_S2C(id) REGISTER_NET_TEMP(id) REGISTRY(TempEntities, BITS(8) - 80) -#define TempEntities_from(i) _TempEntities_from(i, NULL) REGISTER_REGISTRY(TempEntities) REGISTRY_SORT(TempEntities) REGISTRY_CHECK(TempEntities) + +REGISTRY_DEFINE_GET(TempEntities, NULL) STATIC_INIT(TempEntities_renumber) { FOREACH(TempEntities, true, it.m_id = 80 + i); } @@ -72,10 +73,11 @@ STATIC_INIT(TempEntities_renumber) { FOREACH(TempEntities, true, it.m_id = 80 + #endif REGISTRY(LinkedEntities, BITS(8) - 1) -#define LinkedEntities_from(i) _LinkedEntities_from(i, NULL) REGISTER_REGISTRY(LinkedEntities) REGISTRY_SORT(LinkedEntities) REGISTRY_CHECK(LinkedEntities) + +REGISTRY_DEFINE_GET(LinkedEntities, NULL) STATIC_INIT(LinkedEntities_renumber) { FOREACH(LinkedEntities, true, it.m_id = 1 + i); } @@ -98,10 +100,11 @@ STATIC_INIT(LinkedEntities_renumber) { FOREACH(LinkedEntities, true, it.m_id = 1 #endif REGISTRY(C2S_Protocol, BITS(8) - 1) -#define C2S_Protocol_from(i) _C2S_Protocol_from(i, NULL) REGISTER_REGISTRY(C2S_Protocol) REGISTRY_SORT(C2S_Protocol) REGISTRY_CHECK(C2S_Protocol) + +REGISTRY_DEFINE_GET(C2S_Protocol, NULL) STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } #ifdef SVQC @@ -170,7 +173,7 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } STRING_ITERATOR_SET(g_buf, buf, 0); for (int C2S; (C2S = ReadByte()) >= 0; ) { - entity reader = C2S_Protocol_from(C2S); + entity reader = REGISTRY_GET(C2S_Protocol, C2S); if (reader && reader.m_read && reader.m_read(NULL, sender, true)) continue; LOG_SEVEREF("Net_ClientCommand() with malformed C2S=%d", C2S); return; @@ -283,7 +286,7 @@ MACRO_END // serialization: old -#define ReadRegistered(r) r##_from(Read_byte()) +#define ReadRegistered(r) REGISTRY_GET(r, Read_byte()) #define WriteRegistered(r, to, it) Write_byte(to, it.m_id) #define Read_byte() ReadByte() diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index 2db3ae34f..8f0d91ce9 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -35,7 +35,11 @@ noref entity id##_first, id##_last; \ _R_MAP(_##id, id##_MAX); \ SHUTDOWN(id) { _R_DEL(_##id); } \ - entity _##id##_from(int i, entity null) { if (i >= 0 && i < id##_COUNT) { entity e = _R_GET(_##id, i); if (e) return e; } return null; } + +#define REGISTRY_DEFINE_GET(id, null) \ + entity id##_from(int i) { if (i >= 0 && i < id##_COUNT) { entity e = _R_GET(_##id, i); if (e) return e; } return null; } + +#define REGISTRY_GET(id, i) id##_from(i) /** Add registry dependencies to a registry */ #define REGISTRY_DEPENDS(id, dep) void Register##dep(); void REGISTRY_DEPENDS_(id) { Register##dep(); } diff --git a/qcsrc/lib/stats.qh b/qcsrc/lib/stats.qh index 5a2b53b69..9bd4a3af9 100644 --- a/qcsrc/lib/stats.qh +++ b/qcsrc/lib/stats.qh @@ -168,6 +168,8 @@ REGISTRY(Stats, 256 - STATS_ENGINE_RESERVE) REGISTER_REGISTRY(Stats) REGISTRY_SORT(Stats) REGISTRY_CHECK(Stats) + +REGISTRY_DEFINE_GET(Stats, NULL) STATIC_INIT(Stats_renumber) { FOREACH(Stats, true, { diff --git a/qcsrc/menu/gamesettings.qh b/qcsrc/menu/gamesettings.qh index 80133b8b3..291b55b27 100644 --- a/qcsrc/menu/gamesettings.qh +++ b/qcsrc/menu/gamesettings.qh @@ -5,8 +5,9 @@ #include "xonotic/tab.qh" REGISTRY(Settings, BITS(3)) -#define Settings_from(i) _Settings_from(i, NULL) REGISTER_REGISTRY(Settings) + +REGISTRY_DEFINE_GET(Settings, NULL) #define REGISTER_SETTINGS(id, impl) \ LAZY_NEW(id, impl) \ REGISTER(Settings, MENU, id, m_id, NEW(Lazy, LAZY(id))) diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc index eac6f754d..e8dcd7999 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc @@ -255,7 +255,7 @@ void XonoticMutatorsDialog_fill(entity me) me.TDempty(me, 0.1); // fix initial position for(i = WEP_FIRST, j = 0; i <= WEP_LAST; ++i) { - w = Weapons_from(i); + w = REGISTRY_GET(Weapons, i); if (w.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK)) continue; if ((j % 3) == 0) diff --git a/qcsrc/menu/xonotic/dialog_settings_game.qc b/qcsrc/menu/xonotic/dialog_settings_game.qc index fc0790d4b..b617d4915 100644 --- a/qcsrc/menu/xonotic/dialog_settings_game.qc +++ b/qcsrc/menu/xonotic/dialog_settings_game.qc @@ -4,14 +4,14 @@ METHOD(SettingSource, getEntry, entity(entity this, int i, void(string name, string icon) returns)) { - Lazy l = Settings_from(i); + Lazy l = REGISTRY_GET(Settings, 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_from(i); + Lazy l = REGISTRY_GET(Settings, i); entity it = l.m_get(); if (returns) returns(it.titleTooltip); return it; diff --git a/qcsrc/menu/xonotic/serverlist.qc b/qcsrc/menu/xonotic/serverlist.qc index 21278f720..65797e2bf 100644 --- a/qcsrc/menu/xonotic/serverlist.qc +++ b/qcsrc/menu/xonotic/serverlist.qc @@ -623,7 +623,7 @@ void ServerList_TypeSort_Click(entity btn, entity me) // the type was found // choose the next one flag = true; - s = MapInfo_Type_ToString(Gametypes_from(it.m_id + 1)); + s = MapInfo_Type_ToString(REGISTRY_GET(Gametypes, it.m_id + 1)); if (s == "") s = MapInfo_Type_ToString(first); break; }); diff --git a/qcsrc/menu/xonotic/weaponslist.qc b/qcsrc/menu/xonotic/weaponslist.qc index 7b3d7375b..157d22ffe 100644 --- a/qcsrc/menu/xonotic/weaponslist.qc +++ b/qcsrc/menu/xonotic/weaponslist.qc @@ -76,7 +76,7 @@ string XonoticWeaponsList_toString(entity me) s = ""; for(i = 0; i < n; ++i) { - e = Weapons_from(stof(argv(i))); + e = REGISTRY_GET(Weapons, stof(argv(i))); s = strcat(s, e.m_name, ", "); } return substring(s, 0, strlen(s) - 2); @@ -91,7 +91,7 @@ void XonoticWeaponsList_drawListBoxItem(entity me, int i, vector absSize, bool i me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED); draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha); } - e = Weapons_from(stof(argv(i))); + e = REGISTRY_GET(Weapons, stof(argv(i))); string msg = e.m_name; if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED) msg = strcat(msg, "*"); diff --git a/qcsrc/server/bot/default/havocbot/havocbot.qc b/qcsrc/server/bot/default/havocbot/havocbot.qc index 3d744f7d9..d0c6da839 100644 --- a/qcsrc/server/bot/default/havocbot/havocbot.qc +++ b/qcsrc/server/bot/default/havocbot/havocbot.qc @@ -1478,11 +1478,11 @@ void havocbot_chooseweapon(entity this, .entity weaponentity) if ( distance > bot_distance_far ) { for(i=0; i < REGISTRY_COUNT(Weapons) && bot_weapons_far[i] != -1 ; ++i){ w = bot_weapons_far[i]; - if ( client_hasweapon(this, Weapons_from(w), weaponentity, true, false) ) + if ( client_hasweapon(this, REGISTRY_GET(Weapons, w), weaponentity, true, false) ) { if ((this.(weaponentity).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(this, weaponentity, w)) continue; - this.(weaponentity).m_switchweapon = Weapons_from(w); + this.(weaponentity).m_switchweapon = REGISTRY_GET(Weapons, w); return; } } @@ -1492,11 +1492,11 @@ void havocbot_chooseweapon(entity this, .entity weaponentity) if ( distance > bot_distance_close) { for(i=0; i < REGISTRY_COUNT(Weapons) && bot_weapons_mid[i] != -1 ; ++i){ w = bot_weapons_mid[i]; - if ( client_hasweapon(this, Weapons_from(w), weaponentity, true, false) ) + if ( client_hasweapon(this, REGISTRY_GET(Weapons, w), weaponentity, true, false) ) { if ((this.(weaponentity).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(this, weaponentity, w)) continue; - this.(weaponentity).m_switchweapon = Weapons_from(w); + this.(weaponentity).m_switchweapon = REGISTRY_GET(Weapons, w); return; } } @@ -1505,11 +1505,11 @@ void havocbot_chooseweapon(entity this, .entity weaponentity) // Choose weapons for close distance for(i=0; i < REGISTRY_COUNT(Weapons) && bot_weapons_close[i] != -1 ; ++i){ w = bot_weapons_close[i]; - if ( client_hasweapon(this, Weapons_from(w), weaponentity, true, false) ) + if ( client_hasweapon(this, REGISTRY_GET(Weapons, w), weaponentity, true, false) ) { if ((this.(weaponentity).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(this, weaponentity, w)) continue; - this.(weaponentity).m_switchweapon = Weapons_from(w); + this.(weaponentity).m_switchweapon = REGISTRY_GET(Weapons, w); return; } } diff --git a/qcsrc/server/bot/default/scripting.qc b/qcsrc/server/bot/default/scripting.qc index 9c2c6825d..955d15af6 100644 --- a/qcsrc/server/bot/default/scripting.qc +++ b/qcsrc/server/bot/default/scripting.qc @@ -588,10 +588,10 @@ float bot_cmd_select_weapon(entity this) if(this.(weaponentity).m_weapon == WEP_Null && slot != 0) continue; - if(client_hasweapon(this, Weapons_from(id), weaponentity, true, false)) + if(client_hasweapon(this, REGISTRY_GET(Weapons, id), weaponentity, true, false)) { success = true; - this.(weaponentity).m_switchweapon = Weapons_from(id); + this.(weaponentity).m_switchweapon = REGISTRY_GET(Weapons, id); } } diff --git a/qcsrc/server/command/common.qh b/qcsrc/server/command/common.qh index f03a815de..ea3af5469 100644 --- a/qcsrc/server/command/common.qh +++ b/qcsrc/server/command/common.qh @@ -2,10 +2,11 @@ #include REGISTRY(COMMON_COMMANDS, BITS(7)) -#define COMMON_COMMANDS_from(i) _COMMON_COMMANDS_from(i, NULL) REGISTER_REGISTRY(COMMON_COMMANDS) REGISTRY_SORT(COMMON_COMMANDS) +REGISTRY_DEFINE_GET(COMMON_COMMANDS, NULL) + #define COMMON_COMMAND(id, description) \ CLASS(commoncommand_##id, Command) \ ATTRIB(commoncommand_##id, m_name, string, #id); \ diff --git a/qcsrc/server/command/reg.qh b/qcsrc/server/command/reg.qh index 8115d712e..71ace677a 100644 --- a/qcsrc/server/command/reg.qh +++ b/qcsrc/server/command/reg.qh @@ -1,10 +1,11 @@ #pragma once REGISTRY(SERVER_COMMANDS, BITS(7)) -#define SERVER_COMMANDS_from(i) _SERVER_COMMANDS_from(i, NULL) REGISTER_REGISTRY(SERVER_COMMANDS) REGISTRY_SORT(SERVER_COMMANDS) +REGISTRY_DEFINE_GET(SERVER_COMMANDS, NULL) + #define SERVER_COMMAND(id, description) \ CLASS(servercommand_##id, Command) \ ATTRIB(servercommand_##id, m_name, string, #id); \ diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index 555a73472..e5363db77 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -129,7 +129,7 @@ void Obituary_SpecialDeath( return; } - entity deathent = Deathtypes_from(deathtype - DT_FIRST); + entity deathent = REGISTRY_GET(Deathtypes, deathtype - DT_FIRST); if (!deathent) { backtrace("Obituary_SpecialDeath: Could not find deathtype entity!\n"); diff --git a/qcsrc/server/impulse.qc b/qcsrc/server/impulse.qc index 49685d49d..62acd99d8 100644 --- a/qcsrc/server/impulse.qc +++ b/qcsrc/server/impulse.qc @@ -149,7 +149,7 @@ X(9, next) for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) \ { \ .entity weaponentity = weaponentities[slot]; \ - W_SwitchWeapon_TryOthers(this, Weapons_from(WEP_FIRST + i), weaponentity); \ + W_SwitchWeapon_TryOthers(this, REGISTRY_GET(Weapons, WEP_FIRST + i), weaponentity); \ if(autocvar_g_weaponswitch_debug != 1) \ break; \ } \ diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 9dd468c2d..6e2fe4b16 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -243,7 +243,7 @@ string WeaponNameFromWeaponentity(entity this, .entity weaponentity) return wepent.m_weapon.m_name; else if(wepent.m_switchweapon != WEP_Null) return wepent.m_switchweapon.m_name; - return "none"; //Weapons_from(wepent.cnt).m_name; + return "none"; //REGISTRY_GET(Weapons, wepent.cnt).m_name; } string formatmessage(entity this, string msg) diff --git a/qcsrc/server/weapons/common.qc b/qcsrc/server/weapons/common.qc index 06615c4ea..9486404b9 100644 --- a/qcsrc/server/weapons/common.qc +++ b/qcsrc/server/weapons/common.qc @@ -30,7 +30,7 @@ void W_GiveWeapon(entity e, int wep) { if (!wep) return; - STAT(WEAPONS, e) |= WepSet_FromWeapon(Weapons_from(wep)); + STAT(WEAPONS, e) |= WepSet_FromWeapon(REGISTRY_GET(Weapons, wep)); if (IS_PLAYER(e)) { Send_Notification(NOTIF_ONE, e, MSG_MULTI, ITEM_WEAPON_GOT, wep); diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index f1866eab0..3f821b44f 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -151,7 +151,7 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl while(rest != "") { weaponwant = stof(car(rest)); rest = cdr(rest); - wep = Weapons_from(weaponwant); + wep = REGISTRY_GET(Weapons, weaponwant); wepset = wep.m_wepset; if(imp >= 0) if(wep.impulse != imp) @@ -207,7 +207,7 @@ float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, fl while(rest != "") { weaponwant = stof(car(rest)); rest = cdr(rest); - wep = Weapons_from(weaponwant); + wep = REGISTRY_GET(Weapons, weaponwant); wepset = wep.m_wepset; if(imp >= 0) if(wep.impulse != imp) @@ -301,7 +301,7 @@ void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponent float w; w = W_GetCycleWeapon(this, weaponorder, dir, -1, 1, true, weaponentity); if(w > 0) - W_SwitchWeapon(this, Weapons_from(w), weaponentity); + W_SwitchWeapon(this, REGISTRY_GET(Weapons, w), weaponentity); } void W_NextWeaponOnImpulse(entity this, float imp, .entity weaponentity) @@ -309,7 +309,7 @@ void W_NextWeaponOnImpulse(entity this, float imp, .entity weaponentity) float w; w = W_GetCycleWeapon(this, CS(this).cvar_cl_weaponpriority, +1, imp, 1, (CS(this).cvar_cl_weaponimpulsemode == 0), weaponentity); if(w > 0) - W_SwitchWeapon(this, Weapons_from(w), weaponentity); + W_SwitchWeapon(this, REGISTRY_GET(Weapons, w), weaponentity); } // next weapon @@ -337,7 +337,7 @@ void W_PreviousWeapon(entity this, float list, .entity weaponentity) // previously used if exists and has ammo, (second) best otherwise void W_LastWeapon(entity this, .entity weaponentity) { - Weapon wep = Weapons_from(this.(weaponentity).cnt); + Weapon wep = REGISTRY_GET(Weapons, this.(weaponentity).cnt); if (client_hasweapon(this, wep, weaponentity, true, false)) W_SwitchWeapon(this, wep, weaponentity); else diff --git a/qcsrc/server/weapons/selection.qh b/qcsrc/server/weapons/selection.qh index dd21e6419..2fff84e4f 100644 --- a/qcsrc/server/weapons/selection.qh +++ b/qcsrc/server/weapons/selection.qh @@ -12,7 +12,7 @@ bool client_hasweapon(entity this, Weapon wpn, .entity weaponentity, float andam .int weaponcomplainindex; float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, float complain, float skipmissing, .entity weaponentity); -#define w_getbestweapon(ent,wepent) Weapons_from(W_GetCycleWeapon(ent, CS(ent).cvar_cl_weaponpriority, 0, -1, false, true, wepent)) +#define w_getbestweapon(ent,wepent) REGISTRY_GET(Weapons, W_GetCycleWeapon(ent, CS(ent).cvar_cl_weaponpriority, 0, -1, false, true, wepent)) void W_SwitchWeapon_Force(Player this, Weapon w, .entity weaponentity); diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index ba039fc10..e36bc68c6 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -36,7 +36,7 @@ void thrown_wep_think(entity this) // returns amount of ammo used, or -1 for failure, or 0 for no ammo count float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo, .entity weaponentity) { - Weapon info = Weapons_from(wpn); + Weapon info = REGISTRY_GET(Weapons, wpn); int ammotype = info.ammo_type; entity wep = spawn(); @@ -51,7 +51,7 @@ float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector W_DropEvent(wr_drop,own,wpn,wep,weaponentity); - if(WepSet_FromWeapon(Weapons_from(wpn)) & WEPSET_SUPERWEAPONS) + if(WepSet_FromWeapon(REGISTRY_GET(Weapons, wpn)) & WEPSET_SUPERWEAPONS) { Item_SetExpiring(wep, true); if(own.items & IT_UNLIMITED_SUPERWEAPONS) @@ -138,7 +138,7 @@ bool W_IsWeaponThrowable(entity this, int w) if (w == WEP_Null.m_id) return false; - return (Weapons_from(w)).weaponthrowable; + return (REGISTRY_GET(Weapons, w)).weaponthrowable; } // toss current weapon diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 5f4f6f833..a10274ab6 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -55,7 +55,7 @@ bool CL_Weaponentity_CustomizeEntityForClient(entity this, entity client) vector CL_Weapon_GetShotOrg(int wpn) { - entity wi = Weapons_from(wpn); + entity wi = REGISTRY_GET(Weapons, wpn); entity e = spawn(); CL_WeaponEntity_SetModel(e, wi.mdl, false); vector ret = e.movedir; @@ -846,7 +846,7 @@ void W_Reload(entity actor, .entity weaponentity, float sent_ammo_min, Sound sen void W_DropEvent(.void(Weapon, entity actor, .entity) event, entity player, float weapon_type, entity weapon_item, .entity weaponentity) { - Weapon w = Weapons_from(weapon_type); + Weapon w = REGISTRY_GET(Weapons, weapon_type); weapon_dropevent_item = weapon_item; w.event(w, player, weaponentity); }