taisei/src/stageobjects.c
Andrei Alexeyev df6b97caf7
stageobjects,objectpool: simplify and reimplement on top of arenas
All pools now allocate from the same arena that is initialized once with
8MB of initial space and never deallocated, only reset between stages.
2023-04-07 16:08:49 +02:00

49 lines
1,014 B
C

/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
*/
#include "taisei.h"
#include "stageobjects.h"
#include "projectile.h"
#include "item.h"
#include "enemy.h"
#include "laser.h"
#include "stagetext.h"
#include "boss.h"
#include "aniplayer.h"
#define INIT_ARENA_SIZE (8 << 20)
StageObjectPools stage_object_pools;
static struct {
MemArena arena;
} stgobjs;
void stage_objpools_init(void) {
if(!stgobjs.arena.pages.first) {
marena_init(&stgobjs.arena, INIT_ARENA_SIZE - sizeof(MemArenaPage));
} else {
marena_reset(&stgobjs.arena);
}
#define OBJECT_POOL(type, field) \
objpool_init( \
&stage_object_pools.field, \
#type, \
&stgobjs.arena, \
sizeof(type), \
alignof(type));
OBJECT_POOLS
#undef OBJECT_POOL
}
void stage_objpools_shutdown(void) {
marena_deinit(&stgobjs.arena);
}