]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/csqcmodel/cl_model.qc
Add a hack to fix the use of self in .predraw functions
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / csqcmodel / cl_model.qc
index 2057c881e53bacef2128325dffb6a76be2c5ec5c..c07f94954bc97a4682f7e458e8947d31edddb853 100644 (file)
 #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 <client/defs.qh>
+#include <common/animdecide.qh>
+#include <common/csqcmodel_settings.qh>
+#include <common/util.qh>
 
 float autocvar_cl_lerpanim_maxdelta_framegroups = 0.1;
 float autocvar_cl_nolerp = 0;
@@ -179,41 +179,39 @@ void CSQCModel_InterpolateAnimation_Do()
 #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.entnum >= 1 && this.entnum <= maxclients);
+       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())
-               InterpolateOrigin_Do();
+       if (!CSQCPlayer_IsLocalPlayer(this)) InterpolateOrigin_Do(this);
 
-       CSQCModel_InterpolateAnimation_Do();
+       WITH(entity, self, this, CSQCModel_InterpolateAnimation_Do());
 
        { CSQCMODEL_HOOK_PREDRAW }
 
        // 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;
 }
 
@@ -238,8 +236,8 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew)
 
        { CSQCMODEL_HOOK_PREUPDATE }
 
-       CSQCPlayer_PreUpdate();
-       InterpolateOrigin_Undo();
+       CSQCPlayer_PreUpdate(this);
+       InterpolateOrigin_Undo(this);
        CSQCModel_InterpolateAnimation_PreNote(sf);
 
 #define CSQCMODEL_IF(cond) if(cond) {
@@ -270,13 +268,13 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew)
        }
 
        CSQCModel_InterpolateAnimation_Note(sf);
-       InterpolateOrigin_Note();
-       CSQCPlayer_PostUpdate();
+       InterpolateOrigin_Note(this);
+       CSQCPlayer_PostUpdate(this);
 
        { CSQCMODEL_HOOK_POSTUPDATE }
 
 #ifdef CSQCMODEL_SUPPORT_GETTAGINFO_BEFORE_DRAW
-       InterpolateOrigin_Do();
+       InterpolateOrigin_Do(this);
        CSQCModel_InterpolateAnimation_Do();
 #endif
 
@@ -291,13 +289,17 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew)
 
        // draw it
        this.drawmask = MASK_NORMAL;
-       this.predraw = CSQCModel_Draw;
+       setpredraw(this, CSQCModel_Draw);
        return true;
 }
 
-entity CSQCModel_server2csqc(int pl)
+/**
+ * @param i zero indexed player
+ */
+entity CSQCModel_server2csqc(int i)
 {
-       if (pl <= maxclients) return CSQCModel_players[pl - 1];
-       LOG_WARNINGF("player out of bounds: %d\n", pl);
-       return findfloat(NULL, entnum, pl);
+       if (i < maxclients) return CSQCModel_players[i];
+       ++i;
+       LOG_DEBUGF("player out of bounds: %d\n", i);
+       return findfloat(NULL, entnum, i);
 }