From c594179ccabb9893ff984a2bad8dd629ac0dadd5 Mon Sep 17 00:00:00 2001 From: MysterD Date: Thu, 15 Jun 2023 19:40:34 -0700 Subject: [PATCH] Make surface pools infinite --- src/engine/surface_load.c | 50 +++++++++------------------------------ src/engine/surface_load.h | 1 - src/game/hud.c | 8 ------- 3 files changed, 11 insertions(+), 48 deletions(-) diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index 037e847e..29f08c8b 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -31,34 +31,17 @@ SpatialPartitionCell gDynamicSurfacePartition[NUM_CELLS][NUM_CELLS]; /** * Pools of data to contain either surface nodes or surfaces. */ -struct SurfaceNode *sSurfaceNodePool = NULL; -struct Surface *sSurfacePool = NULL; - -/** - * The size of the surface pool (2300). - */ -s16 sSurfacePoolSize = 0; -u8 gSurfacePoolError = 0; +struct GrowingPool* sSurfaceNodePool = NULL; +struct GrowingPool* sSurfacePool = NULL; /** * Allocate the part of the surface node pool to contain a surface node. */ -static struct SurfaceNode *alloc_surface_node(void) { - struct SurfaceNode *node = &sSurfaceNodePool[gSurfaceNodesAllocated]; - gSurfaceNodesAllocated++; - - //! A bounds check! If there's more surface nodes than 7000 allowed, - // we, um... - // Perhaps originally just debug feedback? - if (gSurfaceNodesAllocated >= SURFACE_NODE_POOL_SIZE) { - gSurfacePoolError |= NOT_ENOUGH_ROOM_FOR_NODES; - return NULL; - } else { - gSurfacePoolError &= ~NOT_ENOUGH_ROOM_FOR_NODES; - } - +static struct SurfaceNode* alloc_surface_node(void) { + struct SurfaceNode* node = (struct SurfaceNode*)growing_pool_alloc(sSurfaceNodePool, sizeof(struct SurfaceNode)); node->next = NULL; + gSurfaceNodesAllocated++; return node; } @@ -66,20 +49,8 @@ static struct SurfaceNode *alloc_surface_node(void) { * Allocate the part of the surface pool to contain a surface and * initialize the surface. */ -static struct Surface *alloc_surface(void) { - - struct Surface *surface = &sSurfacePool[gSurfacesAllocated]; - gSurfacesAllocated++; - - //! A bounds check! If there's more surfaces than the 2300 allowed, - // we, um... - // Perhaps originally just debug feedback? - if (gSurfacesAllocated >= sSurfacePoolSize) { - gSurfacePoolError |= NOT_ENOUGH_ROOM_FOR_SURFACES; - return NULL; - } else { - gSurfacePoolError &= ~NOT_ENOUGH_ROOM_FOR_SURFACES; - } +static struct Surface* alloc_surface(void) { + struct Surface* surface = (struct Surface*)growing_pool_alloc(sSurfacePool, sizeof(struct Surface)); surface->type = 0; surface->force = 0; @@ -87,6 +58,8 @@ static struct Surface *alloc_surface(void) { surface->room = 0; surface->object = NULL; + gSurfacesAllocated++; + return surface; } @@ -549,9 +522,8 @@ void alloc_surface_pools(void) { clear_static_surfaces(); clear_dynamic_surfaces(); - sSurfacePoolSize = SURFACE_POOL_SIZE; - if (!sSurfaceNodePool) { sSurfaceNodePool = calloc(1, SURFACE_NODE_POOL_SIZE * sizeof(struct SurfaceNode)); } - if (!sSurfacePool) { sSurfacePool = calloc(1, sSurfacePoolSize * sizeof(struct Surface)); } + sSurfaceNodePool = growing_pool_init(sSurfaceNodePool, sizeof(struct SurfaceNode) * 1000); + sSurfacePool = growing_pool_init(sSurfacePool, sizeof(struct Surface) * 1000); gEnvironmentRegions = NULL; gSurfaceNodesAllocated = 0; diff --git a/src/engine/surface_load.h b/src/engine/surface_load.h index a9029a38..30558132 100644 --- a/src/engine/surface_load.h +++ b/src/engine/surface_load.h @@ -26,7 +26,6 @@ typedef struct SurfaceNode SpatialPartitionCell[3]; extern SpatialPartitionCell gStaticSurfacePartition[NUM_CELLS][NUM_CELLS]; extern SpatialPartitionCell gDynamicSurfacePartition[NUM_CELLS][NUM_CELLS]; -extern u8 gSurfacePoolError; void alloc_surface_pools(void); diff --git a/src/game/hud.c b/src/game/hud.c index c50e7452..7b7078d4 100644 --- a/src/game/hud.c +++ b/src/game/hud.c @@ -678,14 +678,6 @@ void render_hud(void) { render_hud_timer(); } - if (gSurfacePoolError & NOT_ENOUGH_ROOM_FOR_SURFACES) { - print_text(10, 40, "SURFACE POOL FULL"); - } - - if (gSurfacePoolError & NOT_ENOUGH_ROOM_FOR_NODES) { - print_text(10, 60, "SURFACE NODE POOL FULL"); - } - #if defined(DEVELOPMENT) extern bool configLuaProfiler; if (configLuaProfiler) {