From a4a0b40fd664808ac28eb2259ec328e6854adc5e Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Jun 2018 16:59:33 +1000 Subject: [PATCH] Clean up g_subs a bit more --- qcsrc/common/mapobjects/subs.qc | 91 +++++++++++++++++++++++++++ qcsrc/common/mapobjects/subs.qh | 43 ++++++++++++- qcsrc/server/autocvars.qh | 1 - qcsrc/server/g_subs.qc | 106 -------------------------------- qcsrc/server/g_subs.qh | 60 ------------------ qcsrc/server/sv_main.qc | 12 ++++ qcsrc/server/sv_main.qh | 9 +++ 7 files changed, 153 insertions(+), 169 deletions(-) diff --git a/qcsrc/common/mapobjects/subs.qc b/qcsrc/common/mapobjects/subs.qc index bc6998131..4877d0fb4 100644 --- a/qcsrc/common/mapobjects/subs.qc +++ b/qcsrc/common/mapobjects/subs.qc @@ -437,6 +437,97 @@ void SetBrushEntityModelNoLOD(entity this) ApplyMinMaxScaleAngles(this); } +bool LOD_customize(entity this, entity client) +{ + if(autocvar_loddebug) + { + int d = autocvar_loddebug; + if(d == 1) + this.modelindex = this.lodmodelindex0; + else if(d == 2 || !this.lodmodelindex2) + this.modelindex = this.lodmodelindex1; + else // if(d == 3) + this.modelindex = this.lodmodelindex2; + return true; + } + + // TODO csqc network this so it only gets sent once + vector near_point = NearestPointOnBox(this, client.origin); + if(vdist(near_point - client.origin, <, this.loddistance1)) + this.modelindex = this.lodmodelindex0; + else if(!this.lodmodelindex2 || vdist(near_point - client.origin, <, this.loddistance2)) + this.modelindex = this.lodmodelindex1; + else + this.modelindex = this.lodmodelindex2; + + return true; +} + +void LOD_uncustomize(entity this) +{ + this.modelindex = this.lodmodelindex0; +} + +void LODmodel_attach(entity this) +{ + entity e; + + if(!this.loddistance1) + this.loddistance1 = 1000; + if(!this.loddistance2) + this.loddistance2 = 2000; + this.lodmodelindex0 = this.modelindex; + + if(this.lodtarget1 != "") + { + e = find(NULL, targetname, this.lodtarget1); + if(e) + { + this.lodmodel1 = e.model; + delete(e); + } + } + if(this.lodtarget2 != "") + { + e = find(NULL, targetname, this.lodtarget2); + if(e) + { + this.lodmodel2 = e.model; + delete(e); + } + } + + if(autocvar_loddebug < 0) + { + this.lodmodel1 = this.lodmodel2 = ""; // don't even initialize + } + + if(this.lodmodel1 != "") + { + vector mi, ma; + mi = this.mins; + ma = this.maxs; + + precache_model(this.lodmodel1); + _setmodel(this, this.lodmodel1); + this.lodmodelindex1 = this.modelindex; + + if(this.lodmodel2 != "") + { + precache_model(this.lodmodel2); + _setmodel(this, this.lodmodel2); + this.lodmodelindex2 = this.modelindex; + } + + this.modelindex = this.lodmodelindex0; + setsize(this, mi, ma); + } + + if(this.lodmodelindex1) + if (!getSendEntity(this)) + SetCustomizer(this, LOD_customize, LOD_uncustomize); +} + /* ================ InitTrigger diff --git a/qcsrc/common/mapobjects/subs.qh b/qcsrc/common/mapobjects/subs.qh index 3d265364c..0fa7db2f1 100644 --- a/qcsrc/common/mapobjects/subs.qh +++ b/qcsrc/common/mapobjects/subs.qh @@ -1,8 +1,30 @@ #pragma once #include "defs.qh" -void SUB_SetFade (entity ent, float when, float fading_time); -void SUB_VanishOrRemove (entity ent); +.float friction; +void SUB_Friction(entity this); + +void SUB_NullThink(entity this); + +/* +================== +SUB_VanishOrRemove + +Makes client invisible or removes non-client +================== +*/ +void SUB_VanishOrRemove(entity ent); + +void SUB_SetFade_Think(entity this); + +/* +================== +SUB_SetFade + +Fade 'ent' out when time >= 'when' +================== +*/ +void SUB_SetFade(entity ent, float when, float fading_time); .vector finaldest, finalangle; //plat.qc stuff .void(entity this) think1; @@ -95,6 +117,23 @@ void ApplyMinMaxScaleAngles(entity e); void SetBrushEntityModel(entity this); void SetBrushEntityModelNoLOD(entity this); + +int autocvar_loddebug; +.string lodtarget1; +.string lodtarget2; +.string lodmodel1; +.string lodmodel2; +.float lodmodelindex0; +.float lodmodelindex1; +.float lodmodelindex2; +.float loddistance1; +.float loddistance2; + +bool LOD_customize(entity this, entity client); + +void LOD_uncustomize(entity this); + +void LODmodel_attach(entity this); #endif /* diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index c1abd0041..7d73a73a8 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -257,7 +257,6 @@ bool autocvar_lastlevel; //int autocvar_leadlimit; int autocvar_leadlimit_and_fraglimit; int autocvar_leadlimit_override; -int autocvar_loddebug; int autocvar_minplayers; string autocvar_nextmap; string autocvar_quit_and_redirect; diff --git a/qcsrc/server/g_subs.qc b/qcsrc/server/g_subs.qc index dbbd6d2b4..1130f7810 100644 --- a/qcsrc/server/g_subs.qc +++ b/qcsrc/server/g_subs.qc @@ -8,21 +8,6 @@ #include "../lib/warpzone/common.qh" #include "../common/mapobjects/subs.qh" - -/* -================== -main - -unused but required by the engine -================== -*/ -void main () -{ - -} - -// Misc - /* ================== traceline_antilag @@ -217,94 +202,3 @@ vector findbetterlocation (vector org, float mindist) return org; } - -bool LOD_customize(entity this, entity client) -{ - if(autocvar_loddebug) - { - int d = autocvar_loddebug; - if(d == 1) - this.modelindex = this.lodmodelindex0; - else if(d == 2 || !this.lodmodelindex2) - this.modelindex = this.lodmodelindex1; - else // if(d == 3) - this.modelindex = this.lodmodelindex2; - return true; - } - - // TODO csqc network this so it only gets sent once - vector near_point = NearestPointOnBox(this, client.origin); - if(vdist(near_point - client.origin, <, this.loddistance1)) - this.modelindex = this.lodmodelindex0; - else if(!this.lodmodelindex2 || vdist(near_point - client.origin, <, this.loddistance2)) - this.modelindex = this.lodmodelindex1; - else - this.modelindex = this.lodmodelindex2; - - return true; -} - -void LOD_uncustomize(entity this) -{ - this.modelindex = this.lodmodelindex0; -} - -void LODmodel_attach(entity this) -{ - entity e; - - if(!this.loddistance1) - this.loddistance1 = 1000; - if(!this.loddistance2) - this.loddistance2 = 2000; - this.lodmodelindex0 = this.modelindex; - - if(this.lodtarget1 != "") - { - e = find(NULL, targetname, this.lodtarget1); - if(e) - { - this.lodmodel1 = e.model; - delete(e); - } - } - if(this.lodtarget2 != "") - { - e = find(NULL, targetname, this.lodtarget2); - if(e) - { - this.lodmodel2 = e.model; - delete(e); - } - } - - if(autocvar_loddebug < 0) - { - this.lodmodel1 = this.lodmodel2 = ""; // don't even initialize - } - - if(this.lodmodel1 != "") - { - vector mi, ma; - mi = this.mins; - ma = this.maxs; - - precache_model(this.lodmodel1); - _setmodel(this, this.lodmodel1); - this.lodmodelindex1 = this.modelindex; - - if(this.lodmodel2 != "") - { - precache_model(this.lodmodel2); - _setmodel(this, this.lodmodel2); - this.lodmodelindex2 = this.modelindex; - } - - this.modelindex = this.lodmodelindex0; - setsize(this, mi, ma); - } - - if(this.lodmodelindex1) - if (!getSendEntity(this)) - SetCustomizer(this, LOD_customize, LOD_uncustomize); -} diff --git a/qcsrc/server/g_subs.qh b/qcsrc/server/g_subs.qh index 2528786e7..92b33e054 100644 --- a/qcsrc/server/g_subs.qh +++ b/qcsrc/server/g_subs.qh @@ -1,48 +1,5 @@ #pragma once -void SUB_NullThink(entity this); - -/* -================== -SUB_Friction - -Applies some friction to this -================== -*/ -.float friction; -void SUB_Friction (entity this); - -/* -================== -SUB_VanishOrRemove - -Makes client invisible or removes non-client -================== -*/ -void SUB_VanishOrRemove (entity ent); - -void SUB_SetFade_Think (entity this); - -/* -================== -SUB_SetFade - -Fade 'ent' out when time >= 'when' -================== -*/ -void SUB_SetFade (entity ent, float when, float fadetime); - -/* -================== -main - -unused but required by the engine -================== -*/ -void main (); - -// Misc - /* ================== traceline_antilag @@ -73,20 +30,3 @@ Ripped from DPMod ================== */ vector findbetterlocation (vector org, float mindist); - - -.string lodtarget1; -.string lodtarget2; -.string lodmodel1; -.string lodmodel2; -.float lodmodelindex0; -.float lodmodelindex1; -.float lodmodelindex2; -.float loddistance1; -.float loddistance2; - -bool LOD_customize(entity this, entity client); - -void LOD_uncustomize(entity this); - -void LODmodel_attach(entity this); diff --git a/qcsrc/server/sv_main.qc b/qcsrc/server/sv_main.qc index 487ab1fc5..22ffa254a 100644 --- a/qcsrc/server/sv_main.qc +++ b/qcsrc/server/sv_main.qc @@ -383,3 +383,15 @@ void WarpZone_PostInitialize_Callback() } delete(tracetest_ent); } + +/* +================== +main + +unused but required by the engine +================== +*/ +void main () +{ + +} diff --git a/qcsrc/server/sv_main.qh b/qcsrc/server/sv_main.qh index 7f86d19c0..93480cf28 100644 --- a/qcsrc/server/sv_main.qh +++ b/qcsrc/server/sv_main.qh @@ -1,3 +1,12 @@ #pragma once bool expr_evaluate(string s); + +/* +================== +main + +unused but required by the engine +================== +*/ +void main (); -- 2.39.2