From 1e67809cd898eb96b7c308a93884693685025921 Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 12 May 2023 20:39:42 -0700 Subject: [PATCH] Convert display lists to dynamic memory --- src/game/game_init.c | 2 ++ src/game/memory.c | 14 -------------- src/game/memory.h | 1 + src/game/memory_dynamic.c | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/game/game_init.c b/src/game/game_init.c index 59e6500f..2db690cf 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -279,6 +279,7 @@ void rendering_init(void) { gGfxSPTask = &gGfxPool->spTask; gDisplayListHead = gGfxPool->buffer; gGfxPoolEnd = (u8 *) (gGfxPool->buffer + GFX_POOL_SIZE); + alloc_display_list_reset(); init_render_image(); clear_frame_buffer(0); end_master_display_list(); @@ -294,6 +295,7 @@ void config_gfx_pool(void) { gGfxSPTask = &gGfxPool->spTask; gDisplayListHead = gGfxPool->buffer; gGfxPoolEnd = (u8 *) (gGfxPool->buffer + GFX_POOL_SIZE); + alloc_display_list_reset(); } /** Handles vsync. */ diff --git a/src/game/memory.c b/src/game/memory.c index 480f588b..93945380 100644 --- a/src/game/memory.c +++ b/src/game/memory.c @@ -391,17 +391,3 @@ s32 load_patchable_table(struct MarioAnimation *a, u32 index) { } return ret; } - - -void *alloc_display_list(u32 size) { - void *ptr = NULL; - - size = ALIGN8(size); - if (gGfxPoolEnd - size >= (u8 *) gDisplayListHead) { - gGfxPoolEnd -= size; - ptr = gGfxPoolEnd; - } else { - LOG_ERROR("Failed to alloc display list!"); - } - return ptr; -} \ No newline at end of file diff --git a/src/game/memory.h b/src/game/memory.h index fe623124..6fbfa07d 100644 --- a/src/game/memory.h +++ b/src/game/memory.h @@ -80,6 +80,7 @@ struct MemoryPool *mem_pool_init(u32 size, u32 side); void *mem_pool_alloc(struct MemoryPool *pool, u32 size); void mem_pool_free(struct MemoryPool *pool, void *addr); +void alloc_display_list_reset(void); void *alloc_display_list(u32 size); void func_80278A78(struct MarioAnimation *a, void *b, struct Animation *target); diff --git a/src/game/memory_dynamic.c b/src/game/memory_dynamic.c index 2b42ee3f..406d6374 100644 --- a/src/game/memory_dynamic.c +++ b/src/game/memory_dynamic.c @@ -122,3 +122,17 @@ void growing_pool_free_pool(struct GrowingPool *pool) { } free(pool); } + + /////////////////// + // display lists // +/////////////////// + +static struct GrowingPool* sDisplayListPool = NULL; + +void alloc_display_list_reset(void) { + sDisplayListPool = growing_pool_init(sDisplayListPool, 100000); +} + +void *alloc_display_list(u32 size) { + return growing_pool_alloc(sDisplayListPool, size); +} \ No newline at end of file