From d4be8221fd6ad31ef6c752fd1bb55298353756a5 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 30 Dec 2024 22:46:14 +1000 Subject: [PATCH] Move client-side spawn point code to its own file --- qcsrc/client/_mod.inc | 1 + qcsrc/client/_mod.qh | 1 + qcsrc/client/main.qc | 108 ------------------------------------ qcsrc/client/main.qh | 5 -- qcsrc/client/spawnpoints.qc | 96 ++++++++++++++++++++++++++++++++ qcsrc/client/spawnpoints.qh | 6 ++ xonotic-client.cfg | 1 - 7 files changed, 104 insertions(+), 114 deletions(-) create mode 100644 qcsrc/client/spawnpoints.qc create mode 100644 qcsrc/client/spawnpoints.qh diff --git a/qcsrc/client/_mod.inc b/qcsrc/client/_mod.inc index feb5497d1..977258b79 100644 --- a/qcsrc/client/_mod.inc +++ b/qcsrc/client/_mod.inc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/qcsrc/client/_mod.qh b/qcsrc/client/_mod.qh index 7ef159d6c..b1dd2f256 100644 --- a/qcsrc/client/_mod.qh +++ b/qcsrc/client/_mod.qh @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 9b3cf34ce..e6402d7ba 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -820,114 +820,6 @@ NET_HANDLE(ENT_CLIENT_ACCURACY, bool isnew) return true; } -void Spawn_Draw(entity this) -{ - bool dodraw = autocvar_cl_spawn_point_particles; - if(dodraw && autocvar_cl_spawn_point_dist_max) - { - vector org = getpropertyvec(VF_ORIGIN); - dodraw = vdist(org - this.origin, <, autocvar_cl_spawn_point_dist_max); - } - - if(dodraw) - pointparticles(((!teamplay) ? EFFECT_SPAWNPOINT_NEUTRAL : EFFECT_SPAWNPOINT(this.team - 1)), this.origin + '0 0 28', '0 0 2', bound(0, frametime, 0.1)); -} - -NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new) -{ - float teamnum = (ReadByte() - 1); - vector spn_origin = ReadVector(); - - this.team = (teamnum + 1); - - //if(is_new) - //{ - this.origin = spn_origin; - setsize(this, PL_MIN_CONST, PL_MAX_CONST); - //droptofloor(); - - /*if(autocvar_cl_spawn_point_model) // needs a model first - { - this.mdl = "models/spawnpoint.md3"; - this.colormod = Team_ColorRGB(teamnum); - precache_model(this.mdl); - setmodel(this, this.mdl); - this.drawmask = MASK_NORMAL; - //this.move_movetype = MOVETYPE_NOCLIP; - //this.draw = Spawn_Draw; - IL_PUSH(g_drawables, this); - }*/ - this.draw = Spawn_Draw; - if (is_new) IL_PUSH(g_drawables, this); - //} - - //printf("Ent_ReadSpawnPoint(is_new = %d); origin = %s, team = %d, effect = %d\n", is_new, vtos(this.origin), teamnum, this.cnt); - return true; -} - -NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool is_new) -{ - // If entnum is 0, ONLY do the local spawn actions - // this way the server can disable the sending of - // spawn origin or such to clients if wanted. - float entnum = ReadByte(); - - if(entnum) - { - this.origin = ReadVector(); - - int teamnum = ReadByte() - 1; - int particlesAndOrSound = ReadByte(); - - if(is_new) - { - if(autocvar_cl_spawn_event_particles && (particlesAndOrSound & BIT(0))) - { - switch(teamnum) - { - case NUM_TEAM_1: pointparticles(EFFECT_SPAWN_RED, this.origin, '0 0 0', 1); break; - case NUM_TEAM_2: pointparticles(EFFECT_SPAWN_BLUE, this.origin, '0 0 0', 1); break; - case NUM_TEAM_3: pointparticles(EFFECT_SPAWN_YELLOW, this.origin, '0 0 0', 1); break; - case NUM_TEAM_4: pointparticles(EFFECT_SPAWN_PINK, this.origin, '0 0 0', 1); break; - default: pointparticles(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1); break; - } - } - - if(autocvar_cl_spawn_event_sound && (particlesAndOrSound & BIT(1))) - { - sound(this, CH_TRIGGER, SND_SPAWN, VOL_BASE, ATTEN_NORM); - } - } - } - return = true; - - // local spawn actions - if(is_new && (!entnum || (entnum == player_localentnum))) - { - if(!spectatee_status) - if(autocvar_cl_autodemo_delete_keepmatches >= 2 || (!warmup_stage && autocvar_cl_autodemo_delete_keepmatches == 1)) - { - float del = autocvar_cl_autodemo_delete; - del &= ~1; - cvar_set("cl_autodemo_delete", ftos(del)); // don't delete demo where the player joined the match - } - - if(autocvar_cl_spawnzoom && !autocvar_cl_lockview) - { - zoomin_effect = 1; - current_viewzoom = (1 / bound(1, autocvar_cl_spawnzoom_factor, 16)); - } - - if(autocvar_cl_unpress_zoom_on_spawn) - { - localcmd("-zoom\n"); - button_zoom = false; - } - HUD_Radar_Hide_Maximized(); - } - //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(this.origin), entnum, player_localentnum); -} - // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured. // The parameter isnew reflects if the entity is "new" to the client, meaning it just came into the client's PVS. void CSQC_Ent_Update(entity this, bool isnew) diff --git a/qcsrc/client/main.qh b/qcsrc/client/main.qh index c5efafb5e..447cf84a8 100644 --- a/qcsrc/client/main.qh +++ b/qcsrc/client/main.qh @@ -4,11 +4,6 @@ #include bool autocvar_cl_db_saveasdump; -bool autocvar_cl_spawn_event_particles; -bool autocvar_cl_spawn_event_sound = 1; -// float autocvar_cl_spawn_point_model; -bool autocvar_cl_spawn_point_particles; -float autocvar_cl_spawn_point_dist_max = 1200; bool autocvar_cl_unpress_zoom_on_spawn = true; bool autocvar_cl_unpress_zoom_on_death = true; bool autocvar_cl_unpress_zoom_on_weapon_switch = true; diff --git a/qcsrc/client/spawnpoints.qc b/qcsrc/client/spawnpoints.qc new file mode 100644 index 000000000..77002b2f8 --- /dev/null +++ b/qcsrc/client/spawnpoints.qc @@ -0,0 +1,96 @@ +#include "spawnpoints.qh" + +#include +#include +#include + +void Spawn_Draw(entity this) +{ + bool dodraw = autocvar_cl_spawn_point_particles; + if(dodraw && autocvar_cl_spawn_point_dist_max) + { + vector org = getpropertyvec(VF_ORIGIN); + dodraw = vdist(org - this.origin, <, autocvar_cl_spawn_point_dist_max); + } + + if(dodraw) + pointparticles(((!teamplay) ? EFFECT_SPAWNPOINT_NEUTRAL : EFFECT_SPAWNPOINT(this.team - 1)), this.origin + '0 0 28', '0 0 2', bound(0, frametime, 0.1)); +} + +NET_HANDLE(ENT_CLIENT_SPAWNPOINT, bool is_new) +{ + float teamnum = (ReadByte() - 1); + vector spn_origin = ReadVector(); + + this.team = (teamnum + 1); + + this.origin = spn_origin; + setsize(this, PL_MIN_CONST, PL_MAX_CONST); + + this.draw = Spawn_Draw; + if (is_new) IL_PUSH(g_drawables, this); + + return true; +} + +NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool is_new) +{ + // If entnum is 0, ONLY do the local spawn actions + // this way the server can disable the sending of + // spawn origin or such to clients if wanted. + float entnum = ReadByte(); + + if(entnum) + { + this.origin = ReadVector(); + + int teamnum = ReadByte() - 1; + int particlesAndOrSound = ReadByte(); + + if(is_new) + { + if(autocvar_cl_spawn_event_particles && (particlesAndOrSound & BIT(0))) + { + switch(teamnum) + { + case NUM_TEAM_1: pointparticles(EFFECT_SPAWN_RED, this.origin, '0 0 0', 1); break; + case NUM_TEAM_2: pointparticles(EFFECT_SPAWN_BLUE, this.origin, '0 0 0', 1); break; + case NUM_TEAM_3: pointparticles(EFFECT_SPAWN_YELLOW, this.origin, '0 0 0', 1); break; + case NUM_TEAM_4: pointparticles(EFFECT_SPAWN_PINK, this.origin, '0 0 0', 1); break; + default: pointparticles(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1); break; + } + } + + if(autocvar_cl_spawn_event_sound && (particlesAndOrSound & BIT(1))) + { + sound(this, CH_TRIGGER, SND_SPAWN, VOL_BASE, ATTEN_NORM); + } + } + } + return = true; + + // local spawn actions + if(is_new && (!entnum || (entnum == player_localentnum))) + { + if(!spectatee_status) + if(autocvar_cl_autodemo_delete_keepmatches >= 2 || (!warmup_stage && autocvar_cl_autodemo_delete_keepmatches == 1)) + { + float del = autocvar_cl_autodemo_delete; + del &= ~1; + cvar_set("cl_autodemo_delete", ftos(del)); // don't delete demo where the player joined the match + } + + if(autocvar_cl_spawnzoom && !autocvar_cl_lockview) + { + zoomin_effect = 1; + current_viewzoom = (1 / bound(1, autocvar_cl_spawnzoom_factor, 16)); + } + + if(autocvar_cl_unpress_zoom_on_spawn) + { + localcmd("-zoom\n"); + button_zoom = false; + } + HUD_Radar_Hide_Maximized(); + } +} diff --git a/qcsrc/client/spawnpoints.qh b/qcsrc/client/spawnpoints.qh new file mode 100644 index 000000000..463336bba --- /dev/null +++ b/qcsrc/client/spawnpoints.qh @@ -0,0 +1,6 @@ +#pragma once + +bool autocvar_cl_spawn_event_particles; +bool autocvar_cl_spawn_event_sound = true; +bool autocvar_cl_spawn_point_particles; +float autocvar_cl_spawn_point_dist_max = 1200; diff --git a/xonotic-client.cfg b/xonotic-client.cfg index 6668db2b4..fa8e94972 100644 --- a/xonotic-client.cfg +++ b/xonotic-client.cfg @@ -72,7 +72,6 @@ seta cl_weapon_switch_fallback_to_impulse 1 "When trying to switch to a weapon t seta cl_spawn_event_particles 1 "pointparticles effect whenever a player spawns (if allowed by the server)" seta cl_spawn_event_sound 1 "sound effect whenever a player spawns (if allowed by the server)" -//seta cl_spawn_point_model 0 "place a model at all spawn points" // still needs a model seta cl_spawn_point_particles 1 "pointparticles effect at all spawn points" // managed by effects-.cfg files seta cl_spawn_point_dist_max 1200 "maximum distance from which spawnpoint particles will be visible" -- 2.39.5