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) \
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); } \