From: TimePath Date: Sat, 2 Sep 2017 04:33:23 +0000 (+1000) Subject: Testing simpler map reset. FIXME: Entity counts don't match yet X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=737521df014036fb5c633505c53518bf6f4b8574;p=xonotic%2Fxonotic-data.pk3dir.git Testing simpler map reset. FIXME: Entity counts don't match yet --- diff --git a/qcsrc/lib/intrusivelist.qh b/qcsrc/lib/intrusivelist.qh index fc0e080ea..170924f27 100644 --- a/qcsrc/lib/intrusivelist.qh +++ b/qcsrc/lib/intrusivelist.qh @@ -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'; +} diff --git a/qcsrc/lib/spawnfunc.qh b/qcsrc/lib/spawnfunc.qh index e30e565fd..cdda19e8b 100644 --- a/qcsrc/lib/spawnfunc.qh +++ b/qcsrc/lib/spawnfunc.qh @@ -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) diff --git a/qcsrc/server/cheats.qc b/qcsrc/server/cheats.qc index 3233a141d..7ed968b2d 100644 --- a/qcsrc/server/cheats.qc +++ b/qcsrc/server/cheats.qc @@ -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) diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index 8cfed5bae..48e0dd968 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -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