From eb77ee40c24fd00c38627ed2cfea725a5971bb26 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 22 Aug 2015 14:02:49 +1000 Subject: [PATCH] Load vehicles in the menu with the registry system --- qcsrc/client/main.qc | 1 - qcsrc/client/progs.src | 7 ++-- qcsrc/common/vehicles/all.qc | 7 ++-- qcsrc/common/vehicles/all.qh | 46 ++++++++++--------------- qcsrc/common/vehicles/unit/bumblebee.qc | 2 +- qcsrc/common/vehicles/unit/racer.qc | 5 +-- qcsrc/common/vehicles/unit/raptor.qc | 2 +- qcsrc/common/vehicles/unit/spiderbot.qc | 2 +- qcsrc/common/vehicles/vehicle.qh | 10 ++++++ qcsrc/menu/progs.src | 5 ++- qcsrc/server/g_world.qc | 2 -- qcsrc/server/progs.src | 6 ++-- 12 files changed, 44 insertions(+), 51 deletions(-) create mode 100644 qcsrc/common/vehicles/vehicle.qh diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 84358c4f9..752b518ba 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -147,7 +147,6 @@ void CSQC_Init(void) CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes); CALL_ACCUMULATED_FUNCTION(RegisterHUD_Panels); CALL_ACCUMULATED_FUNCTION(RegisterEffects); - CALL_ACCUMULATED_FUNCTION(RegisterVehicles); WaypointSprite_Load(); diff --git a/qcsrc/client/progs.src b/qcsrc/client/progs.src index b80d787ca..1c739ab76 100644 --- a/qcsrc/client/progs.src +++ b/qcsrc/client/progs.src @@ -57,10 +57,9 @@ weapons/projectile.qc // TODO ../common/viewloc.qc ../common/items/all.qc - ../common/monsters/all.qc - -../common/weapons/all.qc // TODO +../common/vehicles/all.qc +../common/weapons/all.qc ../common/triggers/include.qc @@ -68,8 +67,6 @@ weapons/projectile.qc // TODO ../csqcmodellib/cl_player.qc ../csqcmodellib/interpolate.qc -../common/vehicles/all.qc - ../server/mutators/mutator_multijump.qc ../warpzonelib/anglestransform.qc diff --git a/qcsrc/common/vehicles/all.qc b/qcsrc/common/vehicles/all.qc index 2c45308b4..4923c1b01 100644 --- a/qcsrc/common/vehicles/all.qc +++ b/qcsrc/common/vehicles/all.qc @@ -14,7 +14,6 @@ #undef IMPLEMENTATION // VEHICLE PLUGIN SYSTEM -entity vehicle_info[VEH_MAXCOUNT]; entity dummy_vehicle_info; void vehicles_common_initialize() @@ -48,10 +47,9 @@ void vehicles_common_initialize() #endif // SVQC } -void register_vehicle(float id, float(float) func, float vehicleflags, vector min_s, vector max_s, string modelname, string headmodelname, string hudmodelname, string headtag, string hudtag, string viewtag, string shortname, string vname) +void register_vehicle(entity e, float id, float(float) func, float vehicleflags, vector min_s, vector max_s, string modelname, string headmodelname, string hudmodelname, string headtag, string hudtag, string viewtag, string shortname, string vname) { - entity e; - vehicle_info[id - 1] = e = spawn(); + vehicle_info[id - 1] = e; e.classname = "vehicle_info"; e.vehicleid = id; e.netname = shortname; @@ -72,7 +70,6 @@ void register_vehicle(float id, float(float) func, float vehicleflags, vector mi vehicles_common_initialize(); #endif } -float v_null(float dummy) { return 0; } void register_vehicles_done() { dummy_vehicle_info = spawn(); diff --git a/qcsrc/common/vehicles/all.qh b/qcsrc/common/vehicles/all.qh index 03be2127f..dbb7b0e39 100644 --- a/qcsrc/common/vehicles/all.qh +++ b/qcsrc/common/vehicles/all.qh @@ -65,38 +65,30 @@ entity get_vehicleinfo(float id); // Vehicle Registration // ===================== -int v_null(int dummy); -void register_vehicle(int id, int(int) func, float vehicleflags, vector min_s, vector max_s, string modelname, string headmodelname, string hudmodelname, string headtag, string hudtag, string viewtag, string shortname, string vname); -void register_vehicles_done(); - +void RegisterVehicles(); const int VEH_MAXCOUNT = 24; -#define VEH_FIRST 1 +entity vehicle_info[VEH_MAXCOUNT], vehicle_info_first, vehicle_info_last; int VEH_COUNT; -int VEH_LAST; - -#define REGISTER_VEHICLE_2(id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname) \ - int id; \ - int func(int); \ - void RegisterVehicles_##id() \ - { \ - VEH_LAST = (id = VEH_FIRST + VEH_COUNT); \ - ++VEH_COUNT; \ - register_vehicle(id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname); \ - } \ - ACCUMULATE_FUNCTION(RegisterVehicles, RegisterVehicles_##id) -#ifdef MENUQC -#define REGISTER_VEHICLE(id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname) \ - REGISTER_VEHICLE_2(VEH_##id,v_null,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname) -#else -#define REGISTER_VEHICLE(id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname) \ - REGISTER_VEHICLE_2(VEH_##id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname) -#endif +const int VEH_FIRST = 1; +#define VEH_LAST (VEH_FIRST + VEH_COUNT - 1) +/** If you register a new vehicle, make sure to add it to all.inc */ +#define REGISTER_VEHICLE(id, class) REGISTER(RegisterVehicles, vehicle_info, vehicle_info, VEH_COUNT, id, m_id, NEW(class)) +#include "vehicle.qh" +#define REGISTER_VEHICLE_SIMPLE(id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname) \ + int VEH_##id; \ + int func(int); \ + REGISTER_VEHICLE(id, Vehicle) { \ + VEH_##id = VEH_LAST; \ + register_vehicle(this,VEH_##id,func,vehicleflags,min_s,max_s,modelname,headmodelname,hudmodelname,headtag,hudtag,viewtag,shortname,vname); \ + } \ + REGISTER_INIT(vehicle_info, id) +REGISTER_REGISTRY(RegisterVehicles) + +void register_vehicle(entity e, int id, int(int) func, float vehicleflags, vector min_s, vector max_s, string modelname, string headmodelname, string hudmodelname, string headtag, string hudtag, string viewtag, string shortname, string vname); +void register_vehicles_done(); #include "all.inc" -#undef REGISTER_VEHICLE ACCUMULATE_FUNCTION(RegisterVehicles, register_vehicles_done); -#include "all.inc" - #endif diff --git a/qcsrc/common/vehicles/unit/bumblebee.qc b/qcsrc/common/vehicles/unit/bumblebee.qc index 859a89e13..7d338d3e7 100644 --- a/qcsrc/common/vehicles/unit/bumblebee.qc +++ b/qcsrc/common/vehicles/unit/bumblebee.qc @@ -1,7 +1,7 @@ #ifndef VEHICLE_BUMBLEBEE #define VEHICLE_BUMBLEBEE #include "bumblebee.qh" -REGISTER_VEHICLE( +REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ BUMBLEBEE, /* function */ v_bumblebee, /* spawnflags */ VHF_DMGSHAKE, diff --git a/qcsrc/common/vehicles/unit/racer.qc b/qcsrc/common/vehicles/unit/racer.qc index 6c1f30cc1..3549150d5 100644 --- a/qcsrc/common/vehicles/unit/racer.qc +++ b/qcsrc/common/vehicles/unit/racer.qc @@ -1,6 +1,6 @@ #ifndef VEHICLE_RACER #define VEHICLE_RACER -REGISTER_VEHICLE( +REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ RACER, /* function */ v_racer, /* spawnflags */ VHF_DMGSHAKE | VHF_DMGROLL, @@ -859,9 +859,10 @@ bool v_racer(int req) precache_model ("models/vhshield.md3"); #endif - + #ifndef MENUQC precache_model ("models/vehicles/wakizashi.dpm"); precache_model ("models/vehicles/wakizashi_cockpit.dpm"); + #endif return true; } } diff --git a/qcsrc/common/vehicles/unit/raptor.qc b/qcsrc/common/vehicles/unit/raptor.qc index 4624835a2..8eaa0c93c 100644 --- a/qcsrc/common/vehicles/unit/raptor.qc +++ b/qcsrc/common/vehicles/unit/raptor.qc @@ -1,7 +1,7 @@ #ifndef VEHICLE_RAPTOR #define VEHICLE_RAPTOR #include "raptor.qh" -REGISTER_VEHICLE( +REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ RAPTOR, /* function */ v_raptor, /* spawnflags */ VHF_DMGSHAKE | VHF_DMGROLL, diff --git a/qcsrc/common/vehicles/unit/spiderbot.qc b/qcsrc/common/vehicles/unit/spiderbot.qc index 511f9964a..7c23205ec 100644 --- a/qcsrc/common/vehicles/unit/spiderbot.qc +++ b/qcsrc/common/vehicles/unit/spiderbot.qc @@ -1,6 +1,6 @@ #ifndef VEHICLE_SPIDERBOT #define VEHICLE_SPIDERBOT -REGISTER_VEHICLE( +REGISTER_VEHICLE_SIMPLE( /* VEH_##id */ SPIDERBOT, /* function */ v_spiderbot, /* spawnflags */ VHF_DMGSHAKE, diff --git a/qcsrc/common/vehicles/vehicle.qh b/qcsrc/common/vehicles/vehicle.qh new file mode 100644 index 000000000..65b1397ab --- /dev/null +++ b/qcsrc/common/vehicles/vehicle.qh @@ -0,0 +1,10 @@ +#ifndef VEHICLE_H +#define VEHICLE_H + +int v_null(int) { return 0; } + +CLASS(Vehicle, Object) + ATTRIB(Vehicle, m_id, int, 0) +ENDCLASS(Vehicle) + +#endif diff --git a/qcsrc/menu/progs.src b/qcsrc/menu/progs.src index 64f12478d..2bde451f8 100644 --- a/qcsrc/menu/progs.src +++ b/qcsrc/menu/progs.src @@ -23,10 +23,9 @@ xonotic/util.qc ../common/util.qc ../common/items/all.qc - ../common/monsters/all.qc - -../common/weapons/all.qc // TODO +../common/vehicles/all.qc +../common/weapons/all.qc ../warpzonelib/mathlib.qc diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 0a3462dca..2df126d4b 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -565,7 +565,6 @@ void spawnfunc___init_dedicated_server(void) CALL_ACCUMULATED_FUNCTION(RegisterNotifications); CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes); CALL_ACCUMULATED_FUNCTION(RegisterEffects); - CALL_ACCUMULATED_FUNCTION(RegisterVehicles); MapInfo_Enumerate(); MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0); @@ -614,7 +613,6 @@ void spawnfunc_worldspawn (void) CALL_ACCUMULATED_FUNCTION(RegisterNotifications); CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes); CALL_ACCUMULATED_FUNCTION(RegisterEffects); - CALL_ACCUMULATED_FUNCTION(RegisterVehicles); ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid)); diff --git a/qcsrc/server/progs.src b/qcsrc/server/progs.src index cda751fa7..e13a760cb 100644 --- a/qcsrc/server/progs.src +++ b/qcsrc/server/progs.src @@ -87,7 +87,6 @@ weapons/weaponsystem.qc ../common/campaign_setup.qc ../common/effects.qc ../common/mapinfo.qc -../common/monsters/all.qc ../common/monsters/spawn.qc ../common/monsters/sv_monsters.qc ../common/movetypes/include.qc @@ -102,12 +101,13 @@ weapons/weaponsystem.qc ../common/triggers/include.qc ../common/urllib.qc ../common/util.qc -../common/vehicles/all.qc ../common/items/all.qc +../common/monsters/all.qc +../common/vehicles/all.qc +../common/weapons/all.qc // TODO ../common/weapons/config.qc -../common/weapons/all.qc // TODO ../csqcmodellib/sv_model.qc -- 2.39.2