From 0716ef2ec2ac4d429a7d6e9455d16ca56c410d65 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 13 Nov 2011 20:55:09 +0100 Subject: [PATCH] restructured it a lot --- qcsrc/client/progs.src | 10 +- qcsrc/csqcmodel/cl_model.qc | 159 ++++++++++++++++++ qcsrc/csqcmodel/cl_model.qh | 25 +++ .../csqcplayer.qc => csqcmodel/cl_player.qc} | 8 +- .../csqcplayer.qh => csqcmodel/cl_player.qh} | 0 qcsrc/csqcmodel/common.qc | 44 +++++ qcsrc/csqcmodel/settings.qh | 2 + .../csqcmodel.qc => csqcmodel/sv_model.qc} | 60 ------- .../csqcmodel.qh => csqcmodel/sv_model.qh} | 6 - qcsrc/server/progs.src | 6 +- 10 files changed, 244 insertions(+), 76 deletions(-) create mode 100644 qcsrc/csqcmodel/cl_model.qc create mode 100644 qcsrc/csqcmodel/cl_model.qh rename qcsrc/{common/csqcplayer.qc => csqcmodel/cl_player.qc} (96%) rename qcsrc/{common/csqcplayer.qh => csqcmodel/cl_player.qh} (100%) create mode 100644 qcsrc/csqcmodel/common.qc create mode 100644 qcsrc/csqcmodel/settings.qh rename qcsrc/{common/csqcmodel.qc => csqcmodel/sv_model.qc} (60%) rename qcsrc/{common/csqcmodel.qh => csqcmodel/sv_model.qh} (95%) diff --git a/qcsrc/client/progs.src b/qcsrc/client/progs.src index 48b52acbcd..f769f4ea23 100644 --- a/qcsrc/client/progs.src +++ b/qcsrc/client/progs.src @@ -35,8 +35,9 @@ tturrets.qh ../server/movelib.qc main.qh vehicles/vehicles.qh -../common/csqcmodel.qh -../common/csqcplayer.qh +../csqcmodel/settings.qh +../csqcmodel/cl_model.qh +../csqcmodel/cl_player.qh sortlist.qc miscfunctions.qc @@ -58,8 +59,9 @@ projectile.qc gibs.qc damage.qc casings.qc -../common/csqcmodel.qc -../common/csqcplayer.qc +../csqcmodel/common.qc +../csqcmodel/cl_model.qc +../csqcmodel/cl_player.qc effects.qc wall.qc modeleffects.qc diff --git a/qcsrc/csqcmodel/cl_model.qc b/qcsrc/csqcmodel/cl_model.qc new file mode 100644 index 0000000000..6fc076b865 --- /dev/null +++ b/qcsrc/csqcmodel/cl_model.qc @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2011 Rudolf Polzer + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +// generic CSQC model code + +var float autocvar_cl_lerpanim_maxdelta_framegroups = 0.1; +var float autocvar_cl_nolerp = 0; + +.float csqcmodel_lerpfrac; +.float csqcmodel_lerpfrac2; +.float csqcmodel_lerpfractime; + +void CSQCModel_InterpolateAnimation_PreNote(float sf) +{ +#ifdef CSQCMODELS_HAVE_TWO_FRAMES + if(sf & PROPERTY_FRAME) + { + self.frame3 = self.frame; + self.frame3time = self.frame1time; + } + if(sf & PROPERTY_FRAME2) + { + self.frame4 = self.frame2; + self.frame4time = self.frame2time; + } + if(sf & PROPERTY_LERPFRAC) + { + self.csqcmodel_lerpfrac2 = self.csqcmodel_lerpfrac; + self.lerpfrac = self.csqcmodel_lerpfrac; + } +#else + if(sf & PROPERTY_FRAME) + { + self.frame2 = self.frame; + self.frame2time = self.frame1time; + self.frame1time = time; + } +#endif +} + +void CSQCModel_InterpolateAnimation_Note(float sf) +{ +#ifdef CSQCMODELS_HAVE_TWO_FRAMES + if(sf & PROPERTY_FRAME) + { + self.frame1time = time; + } + if(sf & PROPERTY_FRAME2) + { + self.frame2time = time; + } + if(sf & PROPERTY_LERPFRAC) + { + self.csqcmodel_lerpfrac = self.lerpfrac; + self.csqcmodel_lerpfractime = time; + } +#else + if(sf & PROPERTY_FRAME) + { + self.frame2 = self.frame; + self.frame2time = self.frame1time; + self.frame1time = time; + } +#endif +} + +void CSQCModel_InterpolateAnimation_Do() +{ +#ifdef CSQCMODELS_HAVE_TWO_FRAMES + if(autocvar_cl_nolerp || (autocvar_cl_lerpanim_maxdelta_framegroups == 0)) + { + self.lerpfrac = self.csqcmodel_lerpfrac; + self.lerpfrac3 = 0; + self.lerpfrac4 = 0; + } + else + { + float l13, l24, llf; + float l24_13; + l13 = bound(0, (time - self.frame1time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1); + l24 = bound(0, (time - self.frame2time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1); + llf = bound(0, (time - self.csqcmodel_lerpfractime) / autocvar_cl_lerpanim_maxdelta_framegroups, 1); + l24_13 = self.csqcmodel_lerpfrac * llf + self.csqcmodel_lerpfrac2 * (1 - llf); + + self.lerpfrac = l24 * l24_13; + self.lerpfrac4 = (1 - l24) * l24_13; + self.lerpfrac3 = (1 - l13) * (1 - l24_13); + } +#else + if(autocvar_cl_nolerp || (autocvar_cl_lerpanim_maxdelta_framegroups == 0)) + { + self.lerpfrac = 0; + } + else + { + self.lerpfrac = 1 - bound(0, (time - self.frame1time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1); + } +#endif +} + +void CSQCModel_Draw() +{ + InterpolateOrigin_Do(); + CSQCModel_InterpolateAnimation_Do(); +} + +void CSQCModel_Read() +{ + float sf; + sf = ReadShort(); + + self.iflags |= IFLAG_ANGLES; // interpolate angles too + + CSQCPlayer_PreUpdate(); + InterpolateOrigin_Undo(); + CSQCModel_InterpolateAnimation_PreNote(sf); + +#define PROPERTY(flag,r,w,f) \ + if(sf & flag) \ + self.f = r(); +#define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) \ + if(sf & flag) \ + self.f = r() / s; + ALLPROPERTIES +#undef PROPERTY_SCALED +#undef PROPERTY + + CSQCModel_InterpolateAnimation_Note(sf); + InterpolateOrigin_Note(); + CSQCPlayer_PostUpdate(); + +#ifdef CSQCMODELS_SUPPORT_GETTAGINFO_BEFORE_DRAW + InterpolateOrigin_Do(); + CSQCModel_InterpolateAnimation_Do(); +#endif + + // draw it + self.drawmask = MASK_NORMAL; + self.predraw = CSQCModel_Draw; +} diff --git a/qcsrc/csqcmodel/cl_model.qh b/qcsrc/csqcmodel/cl_model.qh new file mode 100644 index 0000000000..e087ee6709 --- /dev/null +++ b/qcsrc/csqcmodel/cl_model.qh @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Rudolf Polzer + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +// generic CSQC model code + +void CSQCModel_Read(); diff --git a/qcsrc/common/csqcplayer.qc b/qcsrc/csqcmodel/cl_player.qc similarity index 96% rename from qcsrc/common/csqcplayer.qc rename to qcsrc/csqcmodel/cl_player.qc index 206789b4bd..eb1715c677 100644 --- a/qcsrc/common/csqcplayer.qc +++ b/qcsrc/csqcmodel/cl_player.qc @@ -20,10 +20,10 @@ * IN THE SOFTWARE. */ -float autocvar_cl_predictionerrorcompensation = 0; -float autocvar_cl_movement_replay; -float autocvar_chase_active; -float autocvar_chase_back; +var float autocvar_cl_predictionerrorcompensation = 0; +var float autocvar_cl_movement_replay; +var float autocvar_chase_active; +var float autocvar_chase_back; .float pmove_flags; diff --git a/qcsrc/common/csqcplayer.qh b/qcsrc/csqcmodel/cl_player.qh similarity index 100% rename from qcsrc/common/csqcplayer.qh rename to qcsrc/csqcmodel/cl_player.qh diff --git a/qcsrc/csqcmodel/common.qc b/qcsrc/csqcmodel/common.qc new file mode 100644 index 0000000000..5677f9a4cc --- /dev/null +++ b/qcsrc/csqcmodel/common.qc @@ -0,0 +1,44 @@ +.vector glowmod; +.vector view_ofs; +.float frame; +.float frame1time; +.float frame2; +.float frame2time; +.float lerpfrac; + +#define PROPERTY_FRAME 32768 +#define PROPERTY_FRAME2 16384 +#define PROPERTY_LERPFRAC 8192 + +#define ALLPROPERTIES_COMMON \ + PROPERTY(PROPERTY_FRAME, ReadByte, WriteByte, frame) \ + PROPERTY(1, ReadCoord, WriteCoord, origin_x) \ + PROPERTY(1, ReadCoord, WriteCoord, origin_y) \ + PROPERTY(1, ReadCoord, WriteCoord, origin_z) \ + PROPERTY(2, ReadAngle, WriteAngle, angles_x) \ + PROPERTY(2, ReadAngle, WriteAngle, angles_y) \ + PROPERTY(2, ReadAngle, WriteAngle, angles_z) \ + PROPERTY(4, ReadShort, WriteShort, modelindex) \ + PROPERTY(16, ReadByte, WriteByte, skin) \ + PROPERTY(32, ReadInt24_t, WriteInt24_t, effects) \ + PROPERTY_SCALED(64, ReadByte, WriteByte, alpha, 255, 0, 255) \ + PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_x, 32, 0, 255) \ + PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_y, 32, 0, 255) \ + PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_z, 32, 0, 255) \ + PROPERTY(256, ReadChar, WriteChar, view_ofs_z) \ + PROPERTY(512, ReadShort, WriteShort, colormap) + +#ifdef CSQCMODELS_HAVE_TWO_FRAMES +.float frame3; +.float frame3time; +.float lerpfrac3; +.float frame4; +.float frame4time; +.float lerpfrac4; +#define ALLPROPERTIES ALLPROPERTIES_COMMON \ + PROPERTY(PROPERTY_FRAME2, ReadByte, WriteByte, frame2) \ + PROPERTY_SCALED(PROPERTY_LERPFRAC, ReadByte, WriteByte, lerpfrac, 255, 0, 255) +#else +#define ALLPROPERTIES ALLPROPERTIES_COMMON +#endif + diff --git a/qcsrc/csqcmodel/settings.qh b/qcsrc/csqcmodel/settings.qh new file mode 100644 index 0000000000..e542bfa5d5 --- /dev/null +++ b/qcsrc/csqcmodel/settings.qh @@ -0,0 +1,2 @@ +//#define CSQCMODELS_HAVE_TWO_FRAMES +//#define CSQCMODELS_SUPPORT_GETTAGINFO_BEFORE_DRAW diff --git a/qcsrc/common/csqcmodel.qc b/qcsrc/csqcmodel/sv_model.qc similarity index 60% rename from qcsrc/common/csqcmodel.qc rename to qcsrc/csqcmodel/sv_model.qc index c03d0f5e9e..010258b10f 100644 --- a/qcsrc/common/csqcmodel.qc +++ b/qcsrc/csqcmodel/sv_model.qc @@ -22,29 +22,6 @@ // generic CSQC model code -.vector glowmod; -.vector view_ofs; - -#define ALLPROPERTIES \ - PROPERTY(1, ReadCoord, WriteCoord, origin_x) \ - PROPERTY(1, ReadCoord, WriteCoord, origin_y) \ - PROPERTY(1, ReadCoord, WriteCoord, origin_z) \ - PROPERTY(2, ReadAngle, WriteAngle, angles_x) \ - PROPERTY(2, ReadAngle, WriteAngle, angles_y) \ - PROPERTY(2, ReadAngle, WriteAngle, angles_z) \ - PROPERTY(4, ReadShort, WriteShort, modelindex) \ - PROPERTY(8, ReadByte, WriteByte, frame) \ - PROPERTY(16, ReadByte, WriteByte, skin) \ - PROPERTY(32, ReadInt24_t, WriteInt24_t, effects) \ - PROPERTY_SCALED(64, ReadByte, WriteByte, alpha, 255, 0, 255) \ - PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_x, 32, 0, 255) \ - PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_y, 32, 0, 255) \ - PROPERTY_SCALED(128, ReadByte, WriteByte, glowmod_z, 32, 0, 255) \ - PROPERTY(256, ReadChar, WriteChar, view_ofs_z) \ - PROPERTY(512, ReadShort, WriteShort, colormap) - -#ifdef SVQC - #define PROPERTY(flag,r,w,f) \ .float csqcmodel_##f; #define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) PROPERTY(flag,r,w,f) @@ -96,40 +73,3 @@ void CSQCModel_LinkEntity() { Net_LinkEntity(self, TRUE, 0, CSQCModel_Send); } - -#endif - -#ifdef CSQC - -void CSQCModel_Draw() -{ - InterpolateOrigin_Do(); -} - -void CSQCModel_Read() -{ - float sf; - sf = ReadShort(); - - CSQCPlayer_PreUpdate(); - InterpolateOrigin_Undo(); - -#define PROPERTY(flag,r,w,f) \ - if(sf & flag) \ - self.f = r(); -#define PROPERTY_SCALED(flag,r,w,f,s,mi,ma) \ - if(sf & flag) \ - self.f = r() / s; - ALLPROPERTIES -#undef PROPERTY_SCALED -#undef PROPERTY - - InterpolateOrigin_Note(); - CSQCPlayer_PostUpdate(); - - // draw it - self.drawmask = MASK_NORMAL; - self.predraw = CSQCModel_Draw; -} - -#endif diff --git a/qcsrc/common/csqcmodel.qh b/qcsrc/csqcmodel/sv_model.qh similarity index 95% rename from qcsrc/common/csqcmodel.qh rename to qcsrc/csqcmodel/sv_model.qh index bc054a8ec8..bb45a74b49 100644 --- a/qcsrc/common/csqcmodel.qh +++ b/qcsrc/csqcmodel/sv_model.qh @@ -22,11 +22,5 @@ // generic CSQC model code -#ifdef SVQC void CSQCModel_CheckUpdate(); void CSQCModel_LinkEntity(); -#endif - -#ifdef CSQC -void CSQCModel_Read(); -#endif diff --git a/qcsrc/server/progs.src b/qcsrc/server/progs.src index a602f32207..734ba840b1 100644 --- a/qcsrc/server/progs.src +++ b/qcsrc/server/progs.src @@ -40,7 +40,8 @@ campaign.qh accuracy.qh csqcprojectile.qh -../common/csqcmodel.qh +../csqcmodel/settings.qh +../csqcmodel/sv_model.qh csqceffects.qc anticheat.qh @@ -179,7 +180,8 @@ target_music.qc accuracy.qc -../common/csqcmodel.qc +../csqcmodel/common.qc +../csqcmodel/sv_model.qc csqcprojectile.qc playerdemo.qc -- 2.39.5