From 92c1f12e66b7a42d575e8cb58466582a5af9641c Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Jun 2018 18:12:06 +1000 Subject: [PATCH] Move the client portion of client walls into the models file now that it's common --- qcsrc/client/_mod.inc | 1 - qcsrc/client/_mod.qh | 1 - qcsrc/client/main.qc | 1 - qcsrc/client/wall.qc | 226 ------------------------------ qcsrc/client/wall.qh | 20 --- qcsrc/common/mapobjects/models.qc | 218 ++++++++++++++++++++++++++++ qcsrc/common/mapobjects/models.qh | 21 +++ 7 files changed, 239 insertions(+), 249 deletions(-) delete mode 100644 qcsrc/client/wall.qc delete mode 100644 qcsrc/client/wall.qh diff --git a/qcsrc/client/_mod.inc b/qcsrc/client/_mod.inc index 240e07a4a..aa20961a2 100644 --- a/qcsrc/client/_mod.inc +++ b/qcsrc/client/_mod.inc @@ -9,7 +9,6 @@ #include #include #include -#include #include #include diff --git a/qcsrc/client/_mod.qh b/qcsrc/client/_mod.qh index 10482caaa..ecfa4ee1a 100644 --- a/qcsrc/client/_mod.qh +++ b/qcsrc/client/_mod.qh @@ -9,7 +9,6 @@ #include #include #include -#include #include #include diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index c22112541..22556e2ae 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -14,7 +14,6 @@ #include "hud/panel/quickmenu.qh" #include "shownames.qh" #include -#include "wall.qh" #include "weapons/projectile.qh" #include #include diff --git a/qcsrc/client/wall.qc b/qcsrc/client/wall.qc deleted file mode 100644 index 600bf5fa8..000000000 --- a/qcsrc/client/wall.qc +++ /dev/null @@ -1,226 +0,0 @@ -#include "wall.qh" - -#include "autocvars.qh" -#include "main.qh" -#include "bgmscript.qh" - - -#include "../lib/csqcmodel/interpolate.qh" - -.float alpha; -.float scale; -.vector movedir; - -void Ent_Wall_PreDraw(entity this) -{ - if (this.inactive) - { - this.alpha = 0; - } - else - { - vector org = getpropertyvec(VF_ORIGIN); - if(!checkpvs(org, this)) - this.alpha = 0; - else if(this.fade_start || this.fade_end) { - vector offset = '0 0 0'; - offset_z = this.fade_vertical_offset; - float player_dist = vlen(org - this.origin - 0.5 * (this.mins + this.maxs) + offset); - if (this.fade_end == this.fade_start) - { - if (player_dist >= this.fade_start) - this.alpha = 0; - else - this.alpha = 1; - } - else - { - this.alpha = (this.alpha_min + this.alpha_max * bound(0, - (this.fade_end - player_dist) - / (this.fade_end - this.fade_start), 1)) / 100.0; - } - } - else - { - this.alpha = 1; - } - } - if(this.alpha <= 0) - this.drawmask = 0; - else - this.drawmask = MASK_NORMAL; -} - -void Ent_Wall_Draw(entity this) -{ - float f; - var .vector fld; - - if(this.bgmscriptangular) - fld = angles; - else - fld = origin; - this.(fld) = this.saved; - - if(this.lodmodelindex1) - { - if(autocvar_cl_modeldetailreduction <= 0) - { - if(this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2) - this.modelindex = this.lodmodelindex2; - else if(autocvar_cl_modeldetailreduction <= -1) - this.modelindex = this.lodmodelindex1; - else - this.modelindex = this.lodmodelindex0; - } - else - { - float distance = vlen(NearestPointOnBox(this, view_origin) - view_origin); - f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction; - f *= 1.0 / bound(0.01, view_quality, 1); - if(this.lodmodelindex2 && f > this.loddistance2) - this.modelindex = this.lodmodelindex2; - else if(f > this.loddistance1) - this.modelindex = this.lodmodelindex1; - else - this.modelindex = this.lodmodelindex0; - } - } - - InterpolateOrigin_Do(this); - - this.saved = this.(fld); - - f = doBGMScript(this); - if(f >= 0) - { - if(this.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip) - this.alpha = 1 + this.lip * f; - else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip) - this.alpha = 1 - this.lip * (1 - f); - this.(fld) = this.(fld) + this.movedir * f; - } - else - this.alpha = 1; - - if(this.alpha >= ALPHA_MIN_VISIBLE) - this.drawmask = MASK_NORMAL; - else - this.drawmask = 0; -} - -void Ent_Wall_Remove(entity this) -{ - strfree(this.bgmscript); -} - -NET_HANDLE(ENT_CLIENT_WALL, bool isnew) -{ - int f; - var .vector fld; - - InterpolateOrigin_Undo(this); - this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN; - - if(this.bgmscriptangular) - fld = angles; - else - fld = origin; - this.(fld) = this.saved; - - f = ReadByte(); - - if(f & 1) - { - if(f & 0x40) - this.colormap = ReadShort(); - else - this.colormap = 0; - this.skin = ReadByte(); - } - - if(f & 2) - { - this.origin = ReadVector(); - setorigin(this, this.origin); - } - - if(f & 4) - { - if(f & 0x10) - { - this.angles_x = ReadAngle(); - this.angles_y = ReadAngle(); - this.angles_z = ReadAngle(); - } - else - this.angles = '0 0 0'; - } - - if(f & 8) - { - if(f & 0x80) - { - this.lodmodelindex0 = ReadShort(); - this.loddistance1 = ReadShort(); - this.lodmodelindex1 = ReadShort(); - this.loddistance2 = ReadShort(); - this.lodmodelindex2 = ReadShort(); - } - else - { - this.modelindex = ReadShort(); - this.loddistance1 = 0; - this.loddistance2 = 0; - } - this.solid = ReadByte(); - this.scale = ReadShort() / 256.0; - if(f & 0x20) - { - this.mins = ReadVector(); - this.maxs = ReadVector(); - } - else - this.mins = this.maxs = '0 0 0'; - setsize(this, this.mins, this.maxs); - - string s = ReadString(); - if(substring(s, 0, 1) == "<") - { - strcpy(this.bgmscript, substring(s, 1, -1)); - this.bgmscriptangular = 1; - } - else - { - strcpy(this.bgmscript, s); - this.bgmscriptangular = 0; - } - if(this.bgmscript != "") - { - this.bgmscriptattack = ReadByte() / 64.0; - this.bgmscriptdecay = ReadByte() / 64.0; - this.bgmscriptsustain = ReadByte() / 255.0; - this.bgmscriptrelease = ReadByte() / 64.0; - this.movedir = ReadVector(); - this.lip = ReadByte() / 255.0; - } - this.fade_start = ReadByte(); - this.fade_end = ReadByte(); - this.alpha_max = ReadByte(); - this.alpha_min = ReadByte(); - this.inactive = ReadByte(); - this.fade_vertical_offset = ReadShort(); - BGMScript_InitEntity(this); - } - - return = true; - - InterpolateOrigin_Note(this); - - this.saved = this.(fld); - - this.entremove = Ent_Wall_Remove; - this.draw = Ent_Wall_Draw; - if (isnew) IL_PUSH(g_drawables, this); - setpredraw(this, Ent_Wall_PreDraw); -} diff --git a/qcsrc/client/wall.qh b/qcsrc/client/wall.qh deleted file mode 100644 index e55bc489b..000000000 --- a/qcsrc/client/wall.qh +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -entityclass(Wall); -classfield(Wall) .float lip; -classfield(Wall) .float bgmscriptangular; -classfield(Wall) .int lodmodelindex0, lodmodelindex1, lodmodelindex2; -classfield(Wall) .float loddistance1, loddistance2; -classfield(Wall) .vector saved; - -// Needed for interactive clientwalls -.float inactive; // Clientwall disappears when inactive -.float alpha_max, alpha_min; -// If fade_start > fade_end, fadeout will be inverted -// fade_vertical_offset is a vertival offset for player position -.float fade_start, fade_end, fade_vertical_offset; -.float default_solid; - -void Ent_Wall_Draw(entity this); - -void Ent_Wall_Remove(entity this); diff --git a/qcsrc/common/mapobjects/models.qc b/qcsrc/common/mapobjects/models.qc index 7a3dbdfdb..92ff464b7 100644 --- a/qcsrc/common/mapobjects/models.qc +++ b/qcsrc/common/mapobjects/models.qc @@ -192,4 +192,222 @@ spawnfunc(func_static) { G_MODEL_INIT (this, SOLID_NOT) } // DEP // solid brush entities spawnfunc(func_wall) { G_MODEL_INIT (this, SOLID_BSP) } // Q1 name spawnfunc(func_clientwall) { G_CLIENTMODEL_INIT(this, SOLID_BSP) } // brush entity (WARNING: MISPREDICTED) +#elif defined(CSQC) +.float alpha; +.float scale; +.vector movedir; + +void Ent_Wall_PreDraw(entity this) +{ + if (this.inactive) + { + this.alpha = 0; + } + else + { + vector org = getpropertyvec(VF_ORIGIN); + if(!checkpvs(org, this)) + this.alpha = 0; + else if(this.fade_start || this.fade_end) { + vector offset = '0 0 0'; + offset_z = this.fade_vertical_offset; + float player_dist = vlen(org - this.origin - 0.5 * (this.mins + this.maxs) + offset); + if (this.fade_end == this.fade_start) + { + if (player_dist >= this.fade_start) + this.alpha = 0; + else + this.alpha = 1; + } + else + { + this.alpha = (this.alpha_min + this.alpha_max * bound(0, + (this.fade_end - player_dist) + / (this.fade_end - this.fade_start), 1)) / 100.0; + } + } + else + { + this.alpha = 1; + } + } + if(this.alpha <= 0) + this.drawmask = 0; + else + this.drawmask = MASK_NORMAL; +} + +void Ent_Wall_Draw(entity this) +{ + float f; + var .vector fld; + + if(this.bgmscriptangular) + fld = angles; + else + fld = origin; + this.(fld) = this.saved; + + if(this.lodmodelindex1) + { + if(autocvar_cl_modeldetailreduction <= 0) + { + if(this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2) + this.modelindex = this.lodmodelindex2; + else if(autocvar_cl_modeldetailreduction <= -1) + this.modelindex = this.lodmodelindex1; + else + this.modelindex = this.lodmodelindex0; + } + else + { + float distance = vlen(NearestPointOnBox(this, view_origin) - view_origin); + f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction; + f *= 1.0 / bound(0.01, view_quality, 1); + if(this.lodmodelindex2 && f > this.loddistance2) + this.modelindex = this.lodmodelindex2; + else if(f > this.loddistance1) + this.modelindex = this.lodmodelindex1; + else + this.modelindex = this.lodmodelindex0; + } + } + + InterpolateOrigin_Do(this); + + this.saved = this.(fld); + + f = doBGMScript(this); + if(f >= 0) + { + if(this.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip) + this.alpha = 1 + this.lip * f; + else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip) + this.alpha = 1 - this.lip * (1 - f); + this.(fld) = this.(fld) + this.movedir * f; + } + else + this.alpha = 1; + + if(this.alpha >= ALPHA_MIN_VISIBLE) + this.drawmask = MASK_NORMAL; + else + this.drawmask = 0; +} + +void Ent_Wall_Remove(entity this) +{ + strfree(this.bgmscript); +} + +NET_HANDLE(ENT_CLIENT_WALL, bool isnew) +{ + int f; + var .vector fld; + + InterpolateOrigin_Undo(this); + this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN; + + if(this.bgmscriptangular) + fld = angles; + else + fld = origin; + this.(fld) = this.saved; + + f = ReadByte(); + + if(f & 1) + { + if(f & 0x40) + this.colormap = ReadShort(); + else + this.colormap = 0; + this.skin = ReadByte(); + } + + if(f & 2) + { + this.origin = ReadVector(); + setorigin(this, this.origin); + } + + if(f & 4) + { + if(f & 0x10) + { + this.angles_x = ReadAngle(); + this.angles_y = ReadAngle(); + this.angles_z = ReadAngle(); + } + else + this.angles = '0 0 0'; + } + + if(f & 8) + { + if(f & 0x80) + { + this.lodmodelindex0 = ReadShort(); + this.loddistance1 = ReadShort(); + this.lodmodelindex1 = ReadShort(); + this.loddistance2 = ReadShort(); + this.lodmodelindex2 = ReadShort(); + } + else + { + this.modelindex = ReadShort(); + this.loddistance1 = 0; + this.loddistance2 = 0; + } + this.solid = ReadByte(); + this.scale = ReadShort() / 256.0; + if(f & 0x20) + { + this.mins = ReadVector(); + this.maxs = ReadVector(); + } + else + this.mins = this.maxs = '0 0 0'; + setsize(this, this.mins, this.maxs); + + string s = ReadString(); + if(substring(s, 0, 1) == "<") + { + strcpy(this.bgmscript, substring(s, 1, -1)); + this.bgmscriptangular = 1; + } + else + { + strcpy(this.bgmscript, s); + this.bgmscriptangular = 0; + } + if(this.bgmscript != "") + { + this.bgmscriptattack = ReadByte() / 64.0; + this.bgmscriptdecay = ReadByte() / 64.0; + this.bgmscriptsustain = ReadByte() / 255.0; + this.bgmscriptrelease = ReadByte() / 64.0; + this.movedir = ReadVector(); + this.lip = ReadByte() / 255.0; + } + this.fade_start = ReadByte(); + this.fade_end = ReadByte(); + this.alpha_max = ReadByte(); + this.alpha_min = ReadByte(); + this.inactive = ReadByte(); + this.fade_vertical_offset = ReadShort(); + BGMScript_InitEntity(this); + } + + return = true; + + InterpolateOrigin_Note(this); + + this.saved = this.(fld); + + this.entremove = Ent_Wall_Remove; + this.draw = Ent_Wall_Draw; + if (isnew) IL_PUSH(g_drawables, this); + setpredraw(this, Ent_Wall_PreDraw); +} #endif diff --git a/qcsrc/common/mapobjects/models.qh b/qcsrc/common/mapobjects/models.qh index 6f70f09be..50170e251 100644 --- a/qcsrc/common/mapobjects/models.qh +++ b/qcsrc/common/mapobjects/models.qh @@ -1 +1,22 @@ #pragma once + +#ifdef CSQC +entityclass(Wall); +classfield(Wall) .float lip; +classfield(Wall) .float bgmscriptangular; +classfield(Wall) .int lodmodelindex0, lodmodelindex1, lodmodelindex2; +classfield(Wall) .float loddistance1, loddistance2; +classfield(Wall) .vector saved; + +// Needed for interactive clientwalls +.float inactive; // Clientwall disappears when inactive +.float alpha_max, alpha_min; +// If fade_start > fade_end, fadeout will be inverted +// fade_vertical_offset is a vertival offset for player position +.float fade_start, fade_end, fade_vertical_offset; +.float default_solid; + +void Ent_Wall_Draw(entity this); + +void Ent_Wall_Remove(entity this); +#endif -- 2.39.2