Add a hack to fix the use of self in .predraw functions
authorMario <mario@smbclan.net>
Sun, 3 Jan 2016 14:45:04 +0000 (00:45 +1000)
committerMario <mario@smbclan.net>
Sun, 3 Jan 2016 14:45:04 +0000 (00:45 +1000)
qcsrc/client/main.qc
qcsrc/client/main.qh
qcsrc/client/wall.qc
qcsrc/common/t_items.qc
qcsrc/lib/csqcmodel/cl_model.qc
qcsrc/lib/warpzone/client.qc

index 304fc64..464ae68 100644 (file)
@@ -327,6 +327,19 @@ float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
 // --------------------------------------------------------------------------
 // BEGIN OPTIONAL CSQC FUNCTIONS
 
 // --------------------------------------------------------------------------
 // BEGIN OPTIONAL CSQC FUNCTIONS
 
+.void(entity) predraw_qc;
+void PreDraw_self()
+{
+       if(self.predraw_qc)
+               self.predraw_qc(self);
+}
+
+void setpredraw(entity this, void(entity) pdfunc)
+{
+       this.predraw = PreDraw_self;
+       this.predraw_qc = pdfunc;
+}
+
 void Ent_Remove(entity this);
 
 void Ent_RemovePlayerScore(entity this)
 void Ent_Remove(entity this);
 
 void Ent_RemovePlayerScore(entity this)
index 835acb9..31db3f8 100644 (file)
@@ -14,6 +14,8 @@ const float DATABUF_PING = 0;
 
 #define DATABUF_NEXT (5*maxclients)
 
 
 #define DATABUF_NEXT (5*maxclients)
 
+void setpredraw(entity this, void(entity) pdfunc);
+
 // --------------------------------------------------------------------------
 // Onslaught
 
 // --------------------------------------------------------------------------
 // Onslaught
 
index 7b610fb..b94fddd 100644 (file)
@@ -9,8 +9,8 @@
 .float scale;
 .vector movedir;
 
 .float scale;
 .vector movedir;
 
-void Ent_Wall_PreDraw()
-{SELFPARAM();
+void Ent_Wall_PreDraw(entity this)
+{
        if (this.inactive)
        {
                this.alpha = 0;
        if (this.inactive)
        {
                this.alpha = 0;
@@ -230,5 +230,5 @@ NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
 
        this.entremove = Ent_Wall_Remove;
        this.draw = Ent_Wall_Draw;
 
        this.entremove = Ent_Wall_Remove;
        this.draw = Ent_Wall_Draw;
-       this.predraw = Ent_Wall_PreDraw;
+       setpredraw(this, Ent_Wall_PreDraw);
 }
 }
index ce3bf35..87741a6 100644 (file)
@@ -114,30 +114,30 @@ void ItemDrawSimple(entity this)
     Item_SetAlpha(this);
 }
 
     Item_SetAlpha(this);
 }
 
-void Item_PreDraw()
-{SELFPARAM();
+void Item_PreDraw(entity this)
+{
        if(warpzone_warpzones_exist)
        {
                // just incase warpzones were initialized last, reset these
        if(warpzone_warpzones_exist)
        {
                // just incase warpzones were initialized last, reset these
-               //self.alpha = 1; // alpha is already set by the draw function
-               self.drawmask = MASK_NORMAL;
+               //this.alpha = 1; // alpha is already set by the draw function
+               this.drawmask = MASK_NORMAL;
                return;
        }
        float alph;
        vector org = getpropertyvec(VF_ORIGIN);
                return;
        }
        float alph;
        vector org = getpropertyvec(VF_ORIGIN);
-       if(!checkpvs(org, self)) // this makes sense as long as we don't support recursive warpzones
+       if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones
                alph = 0;
                alph = 0;
-       else if(self.fade_start)
-               alph = bound(0, (self.fade_end - vlen(org - self.origin - 0.5 * (self.mins + self.maxs))) / (self.fade_end - self.fade_start), 1);
+       else if(this.fade_start)
+               alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1);
        else
                alph = 1;
        else
                alph = 1;
-       //printf("%v <-> %v\n", view_origin, self.origin + 0.5 * (self.mins + self.maxs));
-       if(!hud && (self.ItemStatus & ITS_AVAILABLE))
-               self.alpha = alph;
+       //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs));
+       if(!hud && (this.ItemStatus & ITS_AVAILABLE))
+               this.alpha = alph;
        if(alph <= 0)
        if(alph <= 0)
-               self.drawmask = 0;
+               this.drawmask = 0;
        else
        else
-               self.drawmask = MASK_NORMAL;
+               this.drawmask = MASK_NORMAL;
 }
 
 void ItemRemove(entity this)
 }
 
 void ItemRemove(entity this)
@@ -205,7 +205,7 @@ NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
         self.fade_end = ReadShort();
         self.fade_start = ReadShort();
         if(self.fade_start && !autocvar_cl_items_nofade)
         self.fade_end = ReadShort();
         self.fade_start = ReadShort();
         if(self.fade_start && !autocvar_cl_items_nofade)
-               self.predraw = Item_PreDraw;
+               setpredraw(self, Item_PreDraw);
 
         if(self.mdl)
             strunzone(self.mdl);
 
         if(self.mdl)
             strunzone(self.mdl);
index f3497fe..c07f949 100644 (file)
@@ -179,33 +179,33 @@ void CSQCModel_InterpolateAnimation_Do()
 #endif
 }
 
 #endif
 }
 
-void CSQCModel_Draw()
-{SELFPARAM();
+void CSQCModel_Draw(entity this)
+{
        // some nice flags for CSQCMODEL_IF and the hooks
        // 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(this)) InterpolateOrigin_Do(this);
 
 
        // 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();
+       WITH(entity, self, this, CSQCModel_InterpolateAnimation_Do());
 
        { CSQCMODEL_HOOK_PREDRAW }
 
        // inherit draw flags easily
 
        { CSQCMODEL_HOOK_PREDRAW }
 
        // inherit draw flags easily
-       entity root = self;
+       entity root = this;
        while(root.tag_entity)
                root = root.tag_entity;
        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
        }
 
        // 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
 }
 
 entity CSQCModel_players[255]; // 255 is engine limit on maxclients
@@ -289,7 +289,7 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew)
 
        // draw it
        this.drawmask = MASK_NORMAL;
 
        // draw it
        this.drawmask = MASK_NORMAL;
-       this.predraw = CSQCModel_Draw;
+       setpredraw(this, CSQCModel_Draw);
        return true;
 }
 
        return true;
 }
 
index a036692..89f6b84 100644 (file)
@@ -8,21 +8,21 @@
 #elif defined(SVQC)
 #endif
 
 #elif defined(SVQC)
 #endif
 
-void WarpZone_Fade_PreDraw()
-{SELFPARAM();
+void WarpZone_Fade_PreDraw(entity this)
+{
        vector org;
        org = getpropertyvec(VF_ORIGIN);
        vector org;
        org = getpropertyvec(VF_ORIGIN);
-       if(!checkpvs(org, self)) // this makes sense as long as we don't support recursive warpzones
-               self.alpha = 0;
-       else if(self.warpzone_fadestart)
-               self.alpha = bound(0, (self.warpzone_fadeend - vlen(org - self.origin - 0.5 * (self.mins + self.maxs))) / (self.warpzone_fadeend - self.warpzone_fadestart), 1);
+       if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones
+               this.alpha = 0;
+       else if(this.warpzone_fadestart)
+               this.alpha = bound(0, (this.warpzone_fadeend - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.warpzone_fadeend - this.warpzone_fadestart), 1);
        else
        else
-               self.alpha = 1;
-       //printf("%v <-> %v\n", view_origin, self.origin + 0.5 * (self.mins + self.maxs));
-       if(self.alpha <= 0)
-               self.drawmask = 0;
+               this.alpha = 1;
+       //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs));
+       if(this.alpha <= 0)
+               this.drawmask = 0;
        else
        else
-               self.drawmask = MASK_NORMAL;
+               this.drawmask = MASK_NORMAL;
 }
 
 void WarpZone_Touch ();
 }
 
 void WarpZone_Touch ();
@@ -87,7 +87,7 @@ NET_HANDLE(ENT_CLIENT_WARPZONE, bool isnew)
 
        // how to draw
        // engine currently wants this
 
        // how to draw
        // engine currently wants this
-       self.predraw = WarpZone_Fade_PreDraw;
+       setpredraw(self, WarpZone_Fade_PreDraw);
 
        //self.move_touch = WarpZone_Touch;
        return true;
 
        //self.move_touch = WarpZone_Touch;
        return true;
@@ -146,7 +146,7 @@ NET_HANDLE(ENT_CLIENT_WARPZONE_CAMERA, bool isnew)
 
        // how to draw
        // engine currently wants this
 
        // how to draw
        // engine currently wants this
-       self.predraw = WarpZone_Fade_PreDraw;
+       setpredraw(self, WarpZone_Fade_PreDraw);
        return true;
 }
 
        return true;
 }