]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Implement a qc version of copyentity that clears intrusive list data from the copied...
authorterencehill <piuntn@gmail.com>
Sun, 19 Mar 2023 17:17:05 +0000 (18:17 +0100)
committerterencehill <piuntn@gmail.com>
Sun, 19 Mar 2023 17:17:05 +0000 (18:17 +0100)
qcsrc/lib/intrusivelist.qh
qcsrc/lib/oo.qh
qcsrc/lib/spawnfunc.qh
qcsrc/server/weapons/spawning.qc
qcsrc/server/weapons/weaponsystem.qc

index 938a7f9630dd421e80675ddaa9c0ec379b89aad6..3dee9ca38823011ee7fc27313efcf23d01480f4e 100644 (file)
@@ -268,6 +268,15 @@ void IL_ENDFRAME()
 #endif
 }
 
+// clears any IL data from an entity (not an intrusive list)
+// it should be used only in very particular cases such as after a copyentity call
+void IL_REMOVE_RAW(entity it)
+{
+       it.il_lists = '0 0 0';
+       for (int i = 0; i < IL_MAX * 2; ++i)
+               it.il_links_flds[i] = nil;
+}
+
 // called when an entity is deleted with delete() / remove()
 // or when a player disconnects
 void ONREMOVE(entity this)
index a2cef664bad3b72f9936ab371b12087c1e362027..9048202fe28f1da4b5ce0fb753cda1b6aca830b1 100644 (file)
@@ -77,6 +77,13 @@ ACCUMULATE void ONREMOVE(entity this) {}
     /* this = NULL; */  \
 MACRO_END
 
+void IL_REMOVE_RAW(entity it);
+void copyentity_qc(entity src, entity dst)
+{
+       copyentity(src, dst); // builtin function
+       IL_REMOVE_RAW(dst);
+}
+
 entity _clearentity_ent;
 STATIC_INIT(clearentity)
 {
@@ -88,7 +95,7 @@ void clearentity(entity e)
                int n = e.entnum;
 #endif
        bool was_pure = is_pure(e);
-       copyentity(_clearentity_ent, e);
+       copyentity_qc(_clearentity_ent, e);
        if (!was_pure) make_impure(e);
 #ifdef CSQC
                e.entnum = n;
@@ -175,7 +182,7 @@ void clearentity(entity e)
        {                                                                                              \
                if (cname##_vtbl && !this.transmute)                                                       \
                {                                                                                          \
-                       copyentity(cname##_vtbl, this);                                                        \
+                       copyentity_qc(cname##_vtbl, this);                                                     \
                        return;                                                                                \
                }                                                                                          \
                spawn##base##_static(this);                                                                \
index c9bfebabd415c4414eea269638f686fbd4a94f6b..2d9392dada941f7f921fe839bcb67891a8c14148 100644 (file)
@@ -73,7 +73,7 @@ noref string __fullspawndata;
     void __spawnfunc_spawn(entity prototype)
     {
         entity e = new(clone);
-        copyentity(prototype, e);
+        copyentity_qc(prototype, e);
         IL_PUSH(g_map_entities, e);
         #define X(T, fld, def) { e.fld = e.__spawnfunc_##fld; e.__spawnfunc_##fld = def; }
         SPAWNFUNC_INTERNAL_FIELDS(X);
index 0685062f58787167e8a463576ba98638becf72eb..dc7b110e2cc2857da219b18290871de34cc515f0 100644 (file)
@@ -61,8 +61,6 @@ void weapon_defaultspawnfunc(entity this, Weapon wpn)
                                {
                                        entity replacement = spawn();
                                        Item_CopyFields(this, replacement);
-                                       // DO NOT USE, causes #2792
-                                       //copyentity(this, replacement);
                                        replacement.m_isreplaced = true;
                                        weapon_defaultspawnfunc(replacement, wep);
                                }
index fc2c3979c2b15226d5242fc95fdc641ad658b53e..df6490128aa993ac84239930a0a477336d078fc0 100644 (file)
@@ -670,7 +670,7 @@ void W_AttachToShotorg(entity actor, .entity weaponentity, entity flash, vector
        setorigin(flash, offset);
 
        entity xflash = spawn();
-       copyentity(flash, xflash);
+       copyentity_qc(flash, xflash);
 
        flash.viewmodelforclient = actor;