]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/main.qc
Add a hack to fix the use of self in .predraw functions
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / main.qc
index 6b5cf6463fcd6bf2f393f0aac3880b28dc66c982..464ae689a14186f20486fb35ad9de835eb72d418 100644 (file)
@@ -1,28 +1,26 @@
 #include "main.qh"
 
-#include "../common/effects/qc/all.qh"
-#include "hook.qh"
+#include <common/effects/qc/all.qh>
 #include "hud/all.qh"
 #include "mapvoting.qh"
 #include "mutators/events.qh"
 #include "quickmenu.qh"
 #include "scoreboard.qh"
 #include "shownames.qh"
-#include "tuba.qh"
-#include "t_items.qh"
+#include <common/t_items.qh>
 #include "wall.qh"
 #include "weapons/projectile.qh"
-#include "../common/deathtypes/all.qh"
-#include "../common/items/all.qh"
-#include "../common/mapinfo.qh"
-#include "../common/minigames/cl_minigames.qh"
-#include "../common/minigames/cl_minigames_hud.qh"
-#include "../common/net_notice.qh"
-#include "../common/triggers/include.qh"
-#include "../common/vehicles/all.qh"
-#include "../lib/csqcmodel/cl_model.qh"
-#include "../lib/csqcmodel/interpolate.qh"
-#include "../lib/warpzone/client.qh"
+#include <common/deathtypes/all.qh>
+#include <common/items/all.qh>
+#include <common/mapinfo.qh>
+#include <common/minigames/cl_minigames.qh>
+#include <common/minigames/cl_minigames_hud.qh>
+#include <common/net_notice.qh>
+#include <common/triggers/include.qh>
+#include <common/vehicles/all.qh>
+#include <lib/csqcmodel/cl_model.qh>
+#include <lib/csqcmodel/interpolate.qh>
+#include <lib/warpzone/client.qh>
 
 // --------------------------------------------------------------------------
 // BEGIN REQUIRED CSQC FUNCTIONS
@@ -329,11 +327,23 @@ float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
 // --------------------------------------------------------------------------
 // BEGIN OPTIONAL CSQC FUNCTIONS
 
-void Ent_Remove();
+.void(entity) predraw_qc;
+void PreDraw_self()
+{
+       if(self.predraw_qc)
+               self.predraw_qc(self);
+}
 
-void Ent_RemovePlayerScore()
+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)
 {
-       SELFPARAM();
        if(this.owner) {
                SetTeam(this.owner, -1);
                this.owner.gotscores = 0;
@@ -361,7 +371,7 @@ NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
                //print("A CSQC entity changed its owner!\n");
                LOG_INFOF("A CSQC entity changed its owner! (edict: %d, classname: %s)\n", etof(this), this.classname);
                isNew = true;
-               Ent_Remove();
+               Ent_Remove(this);
        }
 #endif
 
@@ -716,8 +726,7 @@ NET_HANDLE(ENT_CLIENT_SPAWNEVENT, bool is_new)
 void CSQC_Ent_Update(bool isnew)
 {
        SELFPARAM();
-       this.sourceLocLine = __LINE__;
-       this.sourceLocFile = __FILE__;
+       this.sourceLoc = __FILE__ ":" STR(__LINE__);
        int t = ReadByte();
 
        // set up the "time" global for received entities to be correct for interpolation purposes
@@ -739,7 +748,7 @@ void CSQC_Ent_Update(bool isnew)
                if (t != this.enttype || isnew)
                {
                        LOG_INFOF("A CSQC entity changed its type! (edict: %d, server: %d, type: %d -> %d)\n", etof(this), this.entnum, this.enttype, t);
-                       Ent_Remove();
+                       Ent_Remove(this);
                        clearentity(this);
                        isnew = true;
                }
@@ -759,7 +768,7 @@ void CSQC_Ent_Update(bool isnew)
                if (isnew) this.classname = it.netname;
                if (autocvar_developer_csqcentities)
             LOG_INFOF("CSQC_Ent_Update(%d) at %f with this=%i {.entnum=%d, .enttype=%d} t=%s (%d)\n", isnew, savetime, this, this.entnum, this.enttype, this.classname, t);
-               done = it.m_read(this, isnew);
+               done = it.m_read(this, NULL, isnew);
                break;
        ));
        time = savetime;
@@ -772,10 +781,9 @@ void CSQC_Ent_Update(bool isnew)
 // Destructor, but does NOT deallocate the entity by calling remove(). Also
 // used when an entity changes its type. For an entity that someone interacts
 // with others, make sure it can no longer do so.
-void Ent_Remove()
+void Ent_Remove(entity this)
 {
-       SELFPARAM();
-       if(this.entremove) this.entremove();
+       if(this.entremove) this.entremove(this);
 
        if(this.skeletonindex)
        {
@@ -805,7 +813,7 @@ void CSQC_Ent_Remove()
                LOG_WARNING("CSQC_Ent_Remove called for already removed entity. Packet loss?\n");
                return;
        }
-       if (this.enttype) Ent_Remove();
+       if (this.enttype) Ent_Remove(this);
        remove(this);
 }
 
@@ -849,7 +857,7 @@ bool CSQC_Parse_TempEntity()
        FOREACH(TempEntities, it.m_id == nTEID, LAMBDA(
                if (autocvar_developer_csqcentities)
                        LOG_INFOF("CSQC_Parse_TempEntity() nTEID=%s (%d)\n", it.netname, nTEID);
-               return it.m_read(NULL, true);
+               return it.m_read(NULL, NULL, true);
        ));
 
        if (autocvar_developer_csqcentities)
@@ -1099,8 +1107,6 @@ NET_HANDLE(TE_CSQC_PINGPLREPORT, bool isNew)
 NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew)
 {
        complain_weapon = ReadByte();
-       if (complain_weapon_name) strunzone(complain_weapon_name);
-       complain_weapon_name = strzone(Weapons_from(complain_weapon).m_name);
        complain_weapon_type = ReadByte();
        return = true;