From 0b713ef0e41fbfd4e7df5e10f490b2f660f6c85e Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 30 Aug 2017 21:47:00 +1000 Subject: [PATCH] spawnfuncs: initial support for prototypical construction --- qcsrc/lib/spawnfunc.qh | 34 +++++++++++++++++++++++++++++++--- qcsrc/server/g_world.qc | 5 +---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/qcsrc/lib/spawnfunc.qh b/qcsrc/lib/spawnfunc.qh index 34b108304..98922d487 100644 --- a/qcsrc/lib/spawnfunc.qh +++ b/qcsrc/lib/spawnfunc.qh @@ -31,8 +31,37 @@ noref bool require_spawnfunc_prefix; noref entity __spawnfunc_expect; noref bool __spawnfunc_unreachable_workaround = true; - .void(entity) __spawnfunc_spawn; + .void(entity) __spawnfunc_constructor; noref IntrusiveList g_spawn_queue; + .string targetname, __spawnfunc_targetname; + #define SPAWNFUNC_INTERNAL_FIELDS(X) \ + X(targetname, string_null) \ + /**/ + void __spawnfunc_defer(entity prototype, void(entity) constructor) + { + IL_PUSH(g_spawn_queue, prototype); + #define X(fld, def) { prototype.__spawnfunc_##fld = prototype.fld; prototype.fld = def; } + SPAWNFUNC_INTERNAL_FIELDS(X); + #undef X + prototype.__spawnfunc_constructor = constructor; + } + + 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)); \ + MACRO_END + + void __spawnfunc_spawn(entity prototype) + { + entity e = new(clone); + copyentity(prototype, e); + IL_PUSH(g_map_entities, e); + #define X(fld, def) { e.fld = e.__spawnfunc_##fld; e.__spawnfunc_##fld = def; } + SPAWNFUNC_INTERNAL_FIELDS(X); + #undef X + e.__spawnfunc_constructor(e); + } #define spawnfunc_1(id) spawnfunc_2(id, FIELDS_UNION) #define spawnfunc_2(id, whitelist) \ @@ -69,8 +98,7 @@ noref bool require_spawnfunc_prefix; this.spawnfunc_checked = true; \ if (this) { \ /* not worldspawn, delay spawn */ \ - this.__spawnfunc_spawn = spawnfunc_##id; \ - IL_PUSH(g_spawn_queue, this); \ + __spawnfunc_defer(this, __spawnfunc_##id); \ } \ } \ if (dospawn) { __spawnfunc_##id(this); } \ diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 1b8685a62..c47952c5d 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -936,10 +936,7 @@ spawnfunc(worldspawn) WinningConditionHelper(this); // set worldstatus world_initialized = 1; - - IL_EACH(g_spawn_queue, true, { - it.__spawnfunc_spawn(it); - }); + __spawnfunc_spawn_all(); } spawnfunc(light) -- 2.39.2