]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/csqcmodel/cl_model.qc
Add some missing parenthesis
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / csqcmodel / cl_model.qc
index e84294522280bbe2a88061abc62991df71dcf027..ccf6751171f82522181d75e529d103ac5b848847 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 Rudolf PolzerCSQCModel_InterpolateAnimation_2To4_PreNote
+ * 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
 #include "cl_player.qh"
 #include "common.qh"
 #include "interpolate.qh"
-#include "../../client/defs.qh"
-#include "../../common/animdecide.qh"
-#include "../../common/csqcmodel_settings.qh"
-#include "../../common/util.qh"
+#include <common/csqcmodel_settings.qh>
 
 float autocvar_cl_lerpanim_maxdelta_framegroups = 0.1;
 float autocvar_cl_nolerp = 0;
@@ -37,209 +34,221 @@ float autocvar_cl_nolerp = 0;
 .float csqcmodel_lerpfractime;
 .float csqcmodel_lerpfrac2time;
 
-void CSQCModel_InterpolateAnimation_2To4_PreNote(int sf)
-{SELFPARAM();
+void CSQCModel_InterpolateAnimation_2To4_PreNote(entity this, int sf)
+{
        if(sf & CSQCMODEL_PROPERTY_FRAME)
        {
-               self.frame3 = self.frame;
-               self.frame3time = self.frame1time;
+               this.frame3 = this.frame;
+               this.frame3time = this.frame1time;
        }
        if(sf & CSQCMODEL_PROPERTY_FRAME2)
        {
-               self.frame4 = self.frame2;
-               self.frame4time = self.frame2time;
+               this.frame4 = this.frame2;
+               this.frame4time = this.frame2time;
        }
        if(sf & CSQCMODEL_PROPERTY_LERPFRAC)
        {
-               self.csqcmodel_lerpfrac2 = self.csqcmodel_lerpfrac;
-               self.csqcmodel_lerpfrac2time = self.csqcmodel_lerpfractime;
-               self.lerpfrac = self.csqcmodel_lerpfrac;
+               this.csqcmodel_lerpfrac2 = this.csqcmodel_lerpfrac;
+               this.csqcmodel_lerpfrac2time = this.csqcmodel_lerpfractime;
+               this.lerpfrac = this.csqcmodel_lerpfrac;
        }
 }
-void CSQCModel_InterpolateAnimation_1To2_PreNote(int sf)
-{SELFPARAM();
+void CSQCModel_InterpolateAnimation_1To2_PreNote(entity this, int sf)
+{
        if(sf & CSQCMODEL_PROPERTY_FRAME)
        {
-               self.frame2 = self.frame;
-               self.frame2time = self.frame1time;
+               this.frame2 = this.frame;
+               this.frame2time = this.frame1time;
        }
 }
-void CSQCModel_InterpolateAnimation_PreNote(int sf)
+void CSQCModel_InterpolateAnimation_PreNote(entity this, int sf)
 {
 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
-       CSQCModel_InterpolateAnimation_2To4_PreNote(sf);
+       CSQCModel_InterpolateAnimation_2To4_PreNote(this, sf);
 #else
-       CSQCModel_InterpolateAnimation_1To2_PreNote(sf);
+       CSQCModel_InterpolateAnimation_1To2_PreNote(this, sf);
 #endif
 }
 
-void CSQCModel_InterpolateAnimation_2To4_Note(int sf, float set_times)
-{SELFPARAM();
+void CSQCModel_InterpolateAnimation_2To4_Note(entity this, int sf, bool set_times)
+{
        if(sf & CSQCMODEL_PROPERTY_FRAME)
        {
                if(set_times)
-                       self.frame1time = time;
+                       this.frame1time = time;
        }
        if(sf & CSQCMODEL_PROPERTY_FRAME2)
        {
                if(set_times)
-                       self.frame2time = time;
+                       this.frame2time = time;
        }
        if(sf & CSQCMODEL_PROPERTY_LERPFRAC)
        {
-               self.csqcmodel_lerpfrac = self.lerpfrac;
+               this.csqcmodel_lerpfrac = this.lerpfrac;
                if(set_times)
-                       self.csqcmodel_lerpfractime = time;
+                       this.csqcmodel_lerpfractime = time;
        }
 }
-void CSQCModel_InterpolateAnimation_1To2_Note(int sf, float set_times)
-{SELFPARAM();
+void CSQCModel_InterpolateAnimation_1To2_Note(entity this, int sf, bool set_times)
+{
        if(sf & CSQCMODEL_PROPERTY_FRAME)
        {
                if(set_times)
-                       self.frame1time = time;
+                       this.frame1time = time;
        }
 }
-void CSQCModel_InterpolateAnimation_Note(int sf)
+void CSQCModel_InterpolateAnimation_Note(entity this, int sf)
 {
 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
-       CSQCModel_InterpolateAnimation_2To4_Note(sf, true);
+       CSQCModel_InterpolateAnimation_2To4_Note(this, sf, true);
 #else
-       CSQCModel_InterpolateAnimation_1To2_Note(sf, true);
+       CSQCModel_InterpolateAnimation_1To2_Note(this, sf, true);
 #endif
 }
 
-void CSQCModel_InterpolateAnimation_2To4_Do()
-{SELFPARAM();
+void CSQCModel_InterpolateAnimation_2To4_Do(entity this)
+{
        if(autocvar_cl_nolerp || (autocvar_cl_lerpanim_maxdelta_framegroups == 0))
        {
-               self.lerpfrac = self.csqcmodel_lerpfrac;
-               self.lerpfrac3 = 0;
-               self.lerpfrac4 = 0;
+               this.lerpfrac = this.csqcmodel_lerpfrac;
+               this.lerpfrac3 = 0;
+               this.lerpfrac4 = 0;
        }
        else
        {
                float l13, l24, llf;
                float l24_13;
 
-               if(self.frame3time == 0) // if frame1/3 were not previously displayed, only frame1 can make sense
+               if(this.frame3time == 0) // if frame1/3 were not previously displayed, only frame1 can make sense
                        l13 = 1;
                else
-                       l13 = bound(0, (time - self.frame1time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
+                       l13 = bound(0, (time - this.frame1time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
 
-               if(self.frame4time == 0) // if frame2/4 were not previously displayed, only frame2 can make sense
+               if(this.frame4time == 0) // if frame2/4 were not previously displayed, only frame2 can make sense
                        l24 = 1;
                else
-                       l24 = bound(0, (time - self.frame2time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
+                       l24 = bound(0, (time - this.frame2time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
 
-               if(self.csqcmodel_lerpfrac2time == 0) // if there is no old lerpfrac (newly displayed model), only lerpfrac makes sense
+               if(this.csqcmodel_lerpfrac2time == 0) // if there is no old lerpfrac (newly displayed model), only lerpfrac makes sense
                        llf = 1;
                else
-                       llf = bound(0, (time - self.csqcmodel_lerpfractime) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
+                       llf = bound(0, (time - this.csqcmodel_lerpfractime) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
 
-               l24_13 = self.csqcmodel_lerpfrac * llf + self.csqcmodel_lerpfrac2 * (1 - llf);
+               l24_13 = this.csqcmodel_lerpfrac * llf + this.csqcmodel_lerpfrac2 * (1 - llf);
 
-               self.lerpfrac  = l24 * l24_13;
-               self.lerpfrac4 = (1 - l24) * l24_13;
-               self.lerpfrac3 = (1 - l13) * (1 - l24_13);
+               this.lerpfrac  = l24 * l24_13;
+               this.lerpfrac4 = (1 - l24) * l24_13;
+               this.lerpfrac3 = (1 - l13) * (1 - l24_13);
 
                if(l24_13 == 0) // if frames 2/4 are not displayed, clear their frametime
                {
-                       self.frame2time = 0;
-                       self.frame4time = 0;
+                       this.frame2time = 0;
+                       this.frame4time = 0;
                }
 
                if(l24_13 == 1) // if frames 1/3 are not displayed, clear their frametime
                {
-                       self.frame1time = 0;
-                       self.frame3time = 0;
+                       this.frame1time = 0;
+                       this.frame3time = 0;
                }
        }
 }
-void CSQCModel_InterpolateAnimation_1To2_Do()
-{SELFPARAM();
+void CSQCModel_InterpolateAnimation_1To2_Do(entity this)
+{
        if(autocvar_cl_nolerp || (autocvar_cl_lerpanim_maxdelta_framegroups == 0))
        {
-               self.lerpfrac = 0;
+               this.lerpfrac = 0;
        }
        else
        {
-               if(self.frame2time == 0) // if frame2 was not previously displayed, only frame1 can make sense
-                       self.lerpfrac = 0;
+               if(this.frame2time == 0) // if frame2 was not previously displayed, only frame1 can make sense
+                       this.lerpfrac = 0;
                else
-                       self.lerpfrac = 1 - bound(0, (time - self.frame1time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
+                       this.lerpfrac = 1 - bound(0, (time - this.frame1time) / autocvar_cl_lerpanim_maxdelta_framegroups, 1);
        }
 }
-void CSQCModel_InterpolateAnimation_Do()
+void CSQCModel_InterpolateAnimation_Do(entity this)
 {
 #ifdef CSQCMODEL_HAVE_TWO_FRAMES
-       CSQCModel_InterpolateAnimation_2To4_Do();
+       CSQCModel_InterpolateAnimation_2To4_Do(this);
 #else
-       CSQCModel_InterpolateAnimation_1To2_Do();
+       CSQCModel_InterpolateAnimation_1To2_Do(this);
 #endif
 }
 
-void CSQCModel_Draw()
-{SELFPARAM();
+void CSQCModel_Draw(entity this)
+{
        // some nice flags for CSQCMODEL_IF and the hooks
-       bool isplayer = (self.entnum >= 1 && self.entnum <= maxclients);
-       noref bool islocalplayer = (self.entnum == player_localnum + 1);
-       noref bool isnolocalplayer = (isplayer && (self.entnum != player_localnum + 1));
+       bool isplayer = (this.isplayermodel & ISPLAYER_CLIENT);
+       noref bool islocalplayer = (this.entnum == player_localnum + 1);
+       noref bool isnolocalplayer = (isplayer && (this.entnum != player_localnum + 1));
 
        // we don't do this for the local player as that one is already handled
        // by CSQCPlayer_SetCamera()
        if (!CSQCPlayer_IsLocalPlayer(this)) InterpolateOrigin_Do(this);
 
-       CSQCModel_InterpolateAnimation_Do();
+       CSQCModel_InterpolateAnimation_Do(this);
 
-       { CSQCMODEL_HOOK_PREDRAW }
+       CSQCModel_Hook_PreDraw(this, isplayer);
+
+       if(isplayer)
+       {
+               if(this.entnum == player_localentnum)
+                       this.renderflags |= RF_EXTERNALMODEL;
+               else
+                       this.renderflags &= ~RF_EXTERNALMODEL;
+       }
 
        // inherit draw flags easily
-       entity root = self;
+       entity root = this;
        while(root.tag_entity)
                root = root.tag_entity;
-       if(self != root)
+       if(this != root)
        {
-               self.renderflags &= ~(RF_EXTERNALMODEL | RF_VIEWMODEL);
-               self.renderflags |= (root.renderflags & (RF_EXTERNALMODEL | RF_VIEWMODEL));
+               this.renderflags &= ~(RF_EXTERNALMODEL | RF_VIEWMODEL);
+               this.renderflags |= (root.renderflags & (RF_EXTERNALMODEL | RF_VIEWMODEL));
        }
 
        // we're drawn, now teleporting is over
-       self.csqcmodel_teleported = 0;
+       this.csqcmodel_teleported = 0;
 }
 
 entity CSQCModel_players[255]; // 255 is engine limit on maxclients
 
-void CSQCModel_remove()
+void CSQCModel_remove(entity this)
 {
-       SELFPARAM();
        CSQCModel_players[this.entnum - 1] = NULL;
 }
 
 NET_HANDLE(ENT_CLIENT_MODEL, bool isnew)
 {
        int sf = ReadInt24_t();
+       int psf = ReadByte();
 
        // some nice flags for CSQCMODEL_IF and the hooks
-       bool isplayer = (this.entnum >= 1 && this.entnum <= maxclients);
+       bool isplayer = (psf & ISPLAYER_CLIENT) || (this.entnum >= 1 && this.entnum <= maxclients);
        if (isnew && isplayer)
        {
                CSQCModel_players[this.entnum - 1] = this;
                this.entremove = CSQCModel_remove;
        }
        bool islocalplayer = (this.entnum == player_localnum + 1);
-       noref bool isnolocalplayer = (isplayer && (this.entnum != player_localnum + 1));
+       noref bool isnolocalplayer = (isplayer && !islocalplayer);
+
+       this.isplayermodel = BITSET(this.isplayermodel, ISPLAYER_CLIENT, isplayer);
+       this.isplayermodel = BITSET(this.isplayermodel, ISPLAYER_LOCAL, islocalplayer);
+       this.isplayermodel = BITSET(this.isplayermodel, ISPLAYER_PLAYER, (psf & ISPLAYER_PLAYER));
 
        this.classname = "csqcmodel";
        this.iflags |= IFLAG_ORIGIN; // interpolate origin too
        this.iflags |= IFLAG_ANGLES; // interpolate angles too
        this.iflags |= IFLAG_VELOCITY | IFLAG_AUTOVELOCITY; // let's calculate velocity automatically
 
-       { CSQCMODEL_HOOK_PREUPDATE }
+       CSQCModel_Hook_PreUpdate(this, isnew, isplayer, islocalplayer);
 
        CSQCPlayer_PreUpdate(this);
        InterpolateOrigin_Undo(this);
-       CSQCModel_InterpolateAnimation_PreNote(sf);
+       CSQCModel_InterpolateAnimation_PreNote(this, sf);
 
 #define CSQCMODEL_IF(cond) if(cond) {
 #define CSQCMODEL_ENDIF }
@@ -268,15 +277,21 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew)
                this.csqcmodel_teleported = 1;
        }
 
-       CSQCModel_InterpolateAnimation_Note(sf);
+       if(sf & BIT(3))
+               this.alpha = this.m_alpha;
+
+       if(sf & BIT(14))
+               viewloc_SetTags(this);
+
+       CSQCModel_InterpolateAnimation_Note(this, sf);
        InterpolateOrigin_Note(this);
        CSQCPlayer_PostUpdate(this);
 
-       { CSQCMODEL_HOOK_POSTUPDATE }
+       CSQCModel_Hook_PostUpdate(this, isnew, isplayer, islocalplayer);
 
 #ifdef CSQCMODEL_SUPPORT_GETTAGINFO_BEFORE_DRAW
        InterpolateOrigin_Do(this);
-       CSQCModel_InterpolateAnimation_Do();
+       CSQCModel_InterpolateAnimation_Do(this);
 #endif
 
        // relink
@@ -290,7 +305,7 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew)
 
        // draw it
        this.drawmask = MASK_NORMAL;
-       this.predraw = CSQCModel_Draw;
+       setpredraw(this, CSQCModel_Draw);
        return true;
 }
 
@@ -301,6 +316,6 @@ entity CSQCModel_server2csqc(int i)
 {
        if (i < maxclients) return CSQCModel_players[i];
        ++i;
-       LOG_WARNINGF("player out of bounds: %d\n", i);
+       LOG_DEBUGF("player out of bounds: %d", i);
        return findfloat(NULL, entnum, i);
 }