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)