]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Testing simpler map reset. FIXME: Entity counts don't match yet TimePath/refactor
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 2 Sep 2017 04:33:23 +0000 (14:33 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 2 Sep 2017 04:33:23 +0000 (14:33 +1000)
qcsrc/lib/intrusivelist.qh
qcsrc/lib/spawnfunc.qh
qcsrc/server/cheats.qc
qcsrc/server/command/vote.qc

index fc0e080eae32fa103333559653d439a403895cb2..170924f27da2e28f2d737cd456c28938112841e8 100644 (file)
@@ -257,3 +257,12 @@ void ONREMOVE(entity this)
                }
        }
 }
+
+/**
+ * Remove an element from all lists when it was cloned from another entity
+ */
+ERASEABLE
+void IL_COPIED(entity this)
+{
+    this.il_lists = '0 0 0';
+}
index e30e565fd3259a6916d36d5c230d7165bae4dd1c..cdda19e8be0a71fb790d1c38a4de601cada71744 100644 (file)
@@ -55,18 +55,40 @@ noref bool require_spawnfunc_prefix;
     noref IntrusiveList g_map_entities;
     #define __spawnfunc_spawn_all() MACRO_BEGIN \
         g_map_entities = IL_NEW(); \
-        IL_EACH(g_spawn_queue, true, __spawnfunc_spawn(it)); \
+        int nkept = 0, nspawned = 0, nspawned2 = 0; \
+        IL_EACH(g_spawn_queue, true, {++nspawned; __spawnfunc_spawn(it);}); \
+        IL_EACH(g_map_entities, true, {++nkept;}); \
+        IL_EACH(g_spawn_queue, true, {++nspawned2;}); \
+        LOG_INFOF("XXX spawned %d / %d (%d)", nkept, nspawned, nspawned2); \
     MACRO_END
 
+    #define __spawnfunc_remove_all() MACRO_BEGIN \
+        int nspawned = 0; \
+        int nremoved = 0; \
+        IL_EACH(g_map_entities, true, {++nspawned;}); \
+        IL_EACH(g_map_entities, true, {++nremoved; delete(it);}); \
+        LOG_INFOF("XXX deleted %d / %d", nremoved, nspawned); \
+        IL_DELETE(g_map_entities); \
+        __spawnfunc_reset(); \
+    MACRO_END
+
+    [[accumulate]] void __spawnfunc_reset() {}
+       #define SPAWNFUNC_RESET(id) \
+           void __spawnfunc_reset_##id(); \
+           void __spawnfunc_reset() { __spawnfunc_reset_##id(); } \
+           void __spawnfunc_reset_##id() \
+
     void __spawnfunc_spawn(entity prototype)
     {
         entity e = new(clone);
         copyentity(prototype, e);
-        IL_PUSH(g_map_entities, e);
+        IL_COPIED(e);
         #define X(T, fld, def) { e.fld = e.__spawnfunc_##fld; e.__spawnfunc_##fld = def; }
         SPAWNFUNC_INTERNAL_FIELDS(X);
         #undef X
         e.__spawnfunc_constructor(e);
+        if (wasfreed(e)) return;
+        IL_PUSH(g_map_entities, e);
     }
 
        #define spawnfunc_1(id) spawnfunc_2(id, FIELDS_UNION)
index 3233a141dd9e1b14b71437c49e016ed77d6acf2e..7ed968b2da8f9a83b4da322f56c0d4697314bd6d 100644 (file)
@@ -123,6 +123,12 @@ void info_autoscreenshot_findtarget(entity this)
        this.angles_y = a.y;
        // we leave Rick Roll alone
 }
+
+SPAWNFUNC_RESET(info_autoscreenshot)
+{
+    num_autoscreenshot = 0;
+}
+
 spawnfunc(info_autoscreenshot)
 {
        if(++num_autoscreenshot > autocvar_g_max_info_autoscreenshot)
index 8cfed5bae4bb06e1c15e15ead247605aaa08481f..48e0dd968548f888f89521e2c81004a6d9ef1249 100644 (file)
@@ -366,6 +366,9 @@ void reset_map(bool dorespawn)
                if (it.reset2) it.reset2(it);
        });
 
+       __spawnfunc_remove_all();
+    __spawnfunc_spawn_all();
+
        FOREACH_CLIENT(IS_PLAYER(it) && STAT(FROZEN, it), { Unfreeze(it); });
 
        // Moving the player reset code here since the player-reset depends