2017-12-20 19:53:09 +01:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2017-12-20 19:53:09 +01:00
|
|
|
* See COPYING for further information.
|
|
|
|
* ---
|
2024-05-16 23:30:41 +02:00
|
|
|
* Copyright (c) 2011-2024, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2024, Andrei Alexeyev <akari@taisei-project.org>.
|
2017-12-20 19:53:09 +01:00
|
|
|
*/
|
2017-12-13 20:05:12 +01:00
|
|
|
|
2021-08-12 23:09:01 +02:00
|
|
|
#pragma once
|
2017-12-20 19:57:29 +01:00
|
|
|
#include "taisei.h"
|
2017-12-13 20:05:12 +01:00
|
|
|
|
2024-06-05 18:35:08 +02:00
|
|
|
#include "memory/mempool.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
#include "aniplayer.h" // IWYU pragma: export
|
|
|
|
#include "projectile.h" // IWYU pragma: export
|
|
|
|
#include "item.h" // IWYU pragma: export
|
|
|
|
#include "enemy.h" // IWYU pragma: export
|
|
|
|
#include "lasers/laser.h" // IWYU pragma: export
|
|
|
|
#include "stagetext.h" // IWYU pragma: export
|
|
|
|
#include "boss.h" // IWYU pragma: export
|
2017-12-13 20:05:12 +01:00
|
|
|
|
2024-06-05 21:58:58 +02:00
|
|
|
#define OBJECT_POOLS(X) \
|
|
|
|
X(Projectile, projectiles) \
|
|
|
|
X(Item, items) \
|
|
|
|
X(Enemy, enemies) \
|
|
|
|
X(Laser, lasers) \
|
|
|
|
X(StageText, stagetext) \
|
|
|
|
X(Boss, bosses) \
|
2023-04-03 03:49:39 +02:00
|
|
|
|
2024-06-05 21:58:58 +02:00
|
|
|
enum {
|
|
|
|
#define COUNT_POOL(...) 1 +
|
|
|
|
NUM_STAGE_OBJECT_POOLS = OBJECT_POOLS(COUNT_POOL) 0,
|
|
|
|
#undef COUNT_POOL
|
|
|
|
};
|
2023-04-03 03:49:39 +02:00
|
|
|
|
2024-06-05 21:58:58 +02:00
|
|
|
typedef struct StageObjects {
|
|
|
|
MemArena arena;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
#define DECLARE_POOL(type, field) \
|
|
|
|
MEMPOOL(type) field;
|
2017-12-13 20:05:12 +01:00
|
|
|
|
2024-06-05 21:58:58 +02:00
|
|
|
OBJECT_POOLS(DECLARE_POOL)
|
|
|
|
#undef DECLARE_POOL
|
|
|
|
};
|
|
|
|
MemPool as_array[NUM_STAGE_OBJECT_POOLS];
|
|
|
|
} pools;
|
|
|
|
} StageObjects;
|
2017-12-13 20:05:12 +01:00
|
|
|
|
2024-06-05 21:58:58 +02:00
|
|
|
extern StageObjects stage_objects;
|
|
|
|
|
|
|
|
#define STAGE_OBJPOOL_GENERIC_DISPATCH(_type, _field) \
|
|
|
|
_type*: &stage_objects.pools._field,
|
|
|
|
|
|
|
|
#define STAGE_OBJPOOL_BY_VARTYPE(_p_obj) \
|
|
|
|
_Generic((_p_obj), \
|
|
|
|
OBJECT_POOLS(STAGE_OBJPOOL_GENERIC_DISPATCH) \
|
|
|
|
struct {}: abort())
|
|
|
|
|
|
|
|
#define STAGE_OBJPOOL_BY_TYPE(type) \
|
|
|
|
STAGE_OBJPOOL_BY_VARTYPE(&(type) {})
|
2023-04-03 03:49:39 +02:00
|
|
|
|
|
|
|
// Can be called many times to reinitialize the pools while reusing allocated arena memory.
|
|
|
|
void stage_objpools_init(void);
|
|
|
|
|
|
|
|
// Frees the arena
|
|
|
|
void stage_objpools_shutdown(void);
|
2024-06-05 21:58:58 +02:00
|
|
|
|
|
|
|
#define STAGE_ACQUIRE_OBJ(_type) \
|
2024-06-05 22:07:17 +02:00
|
|
|
mempool_acquire(STAGE_OBJPOOL_BY_TYPE(_type), &stage_objects.arena)
|
2024-06-05 21:58:58 +02:00
|
|
|
|
|
|
|
#define STAGE_RELEASE_OBJ(_p_obj) \
|
|
|
|
mempool_release(STAGE_OBJPOOL_BY_VARTYPE(_p_obj), (_p_obj))
|