From 57b06e3e0927bd82e53ab6d60f5de145a7483aab Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 12 May 2023 18:53:25 -0700 Subject: [PATCH] Rename AllocOnlyPool to DynamicPool, add GrowingPool --- data/dynos_mgr_models.cpp | 8 +-- src/engine/geo_layout.c | 6 +- src/engine/geo_layout.h | 6 +- src/engine/graph_node.c | 88 +++++++++++++-------------- src/engine/graph_node.h | 46 +++++++------- src/engine/level_script.c | 30 +++++----- src/engine/surface_load.c | 11 ++-- src/engine/surface_load.h | 3 - src/game/camera.c | 4 +- src/game/memory.c | 14 +++++ src/game/memory.h | 32 +++++++--- src/game/memory_dynamic.c | 103 +++++++++++++++++++++++++++++--- src/game/rendering_graph_node.c | 17 +++--- src/game/rendering_graph_node.h | 2 +- 14 files changed, 240 insertions(+), 130 deletions(-) diff --git a/data/dynos_mgr_models.cpp b/data/dynos_mgr_models.cpp index f3fecbb9f..002a56c0c 100644 --- a/data/dynos_mgr_models.cpp +++ b/data/dynos_mgr_models.cpp @@ -6,7 +6,7 @@ extern "C" { #include "engine/graph_node.h" } -static struct AllocOnlyPool* sModelPools[MODEL_POOL_MAX] = { 0 }; +static struct DynamicPool* sModelPools[MODEL_POOL_MAX] = { 0 }; static std::map sModelMap[MODEL_POOL_MAX]; struct GraphNode* DynOS_Model_LoadGeo(enum ModelPool aModelPool, void* aAsset) { @@ -15,7 +15,7 @@ struct GraphNode* DynOS_Model_LoadGeo(enum ModelPool aModelPool, void* aAsset) { // allocate pool if (!sModelPools[aModelPool]) { - sModelPools[aModelPool] = alloc_only_pool_init(); + sModelPools[aModelPool] = dynamic_pool_init(); } // check map @@ -38,7 +38,7 @@ struct GraphNode* DynOS_Model_LoadDl(enum ModelPool aModelPool, u8 aLayer, void* // allocate pool if (!sModelPools[aModelPool]) { - sModelPools[aModelPool] = alloc_only_pool_init(); + sModelPools[aModelPool] = dynamic_pool_init(); } // check map @@ -59,7 +59,7 @@ void DynOS_Model_ClearPool(enum ModelPool aModelPool) { if (!sModelPools[aModelPool]) { return; } // free and realloc pool - alloc_only_pool_free(sModelPools[aModelPool]); + dynamic_pool_free_pool(sModelPools[aModelPool]); sModelPools[aModelPool] = NULL; // clear map diff --git a/src/engine/geo_layout.c b/src/engine/geo_layout.c index 7ddacaf2d..09f7501ae 100644 --- a/src/engine/geo_layout.c +++ b/src/engine/geo_layout.c @@ -48,7 +48,7 @@ GeoLayoutCommandProc GeoLayoutJumpTable[] = { }; struct GraphNode gObjParentGraphNode; -struct AllocOnlyPool *gGraphNodePool = NULL; +struct DynamicPool *gGraphNodePool = NULL; struct GraphNode *gCurRootGraphNode = NULL; UNUSED s32 D_8038BCA8; @@ -219,7 +219,7 @@ void geo_layout_cmd_node_root(void) { graphNode = init_graph_node_root(gGraphNodePool, NULL, 0, x, y, width, height); // TODO: check type - gGeoViews = alloc_only_pool_alloc(gGraphNodePool, gGeoNumViews * sizeof(struct GraphNode *)); + gGeoViews = dynamic_pool_alloc(gGraphNodePool, gGeoNumViews * sizeof(struct GraphNode *)); graphNode->views = gGeoViews; graphNode->numViews = gGeoNumViews; @@ -790,7 +790,7 @@ void geo_layout_cmd_node_background_ext(void) { gGeoLayoutCommand += 0x0C << CMD_SIZE_SHIFT; } -struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr) { +struct GraphNode *process_geo_layout(struct DynamicPool *pool, void *segptr) { // set by register_scene_graph_node when gCurGraphNodeIndex is 0 // and gCurRootGraphNode is NULL gCurRootGraphNode = NULL; diff --git a/src/engine/geo_layout.h b/src/engine/geo_layout.h index f7d408b10..033919a6f 100644 --- a/src/engine/geo_layout.h +++ b/src/engine/geo_layout.h @@ -29,7 +29,7 @@ #define cur_geo_cmd_ptr(offset) \ (*(void **) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)]) -extern struct AllocOnlyPool *gGraphNodePool; +extern struct DynamicPool *gGraphNodePool; extern struct GraphNode *gCurRootGraphNode; extern UNUSED s32 D_8038BCA8; extern struct GraphNode **gGeoViews; @@ -43,7 +43,7 @@ extern s16 gGeoLayoutReturnIndex; extern u8 *gGeoLayoutCommand; extern struct GraphNode gObjParentGraphNode; -extern struct AllocOnlyPool *D_8038BCA0; +extern struct DynamicPool *D_8038BCA0; extern struct GraphNode *D_8038BCA4; extern s16 D_8038BD78; extern struct GraphNode *D_8038BCF8[]; @@ -83,6 +83,6 @@ void geo_layout_cmd_node_held_obj(void); void geo_layout_cmd_node_culling_radius(void); void geo_layout_cmd_node_background_ext(void); -struct GraphNode *process_geo_layout(struct AllocOnlyPool *a0, void *segptr); +struct GraphNode *process_geo_layout(struct DynamicPool *a0, void *segptr); #endif // GEO_LAYOUT_H diff --git a/src/engine/graph_node.c b/src/engine/graph_node.c index d966f42b8..cdd727330 100644 --- a/src/engine/graph_node.c +++ b/src/engine/graph_node.c @@ -38,10 +38,10 @@ void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type) { /** * Allocated and returns a newly created root node */ -struct GraphNodeRoot *init_graph_node_root(struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode, +struct GraphNodeRoot *init_graph_node_root(struct DynamicPool *pool, struct GraphNodeRoot *graphNode, s16 areaIndex, s16 x, s16 y, s16 width, s16 height) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeRoot)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeRoot)); } if (graphNode != NULL) { @@ -64,10 +64,10 @@ struct GraphNodeRoot *init_graph_node_root(struct AllocOnlyPool *pool, struct Gr * Allocates and returns a newly created otrhographic projection node */ struct GraphNodeOrthoProjection * -init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrthoProjection *graphNode, +init_graph_node_ortho_projection(struct DynamicPool *pool, struct GraphNodeOrthoProjection *graphNode, f32 scale) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeOrthoProjection)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeOrthoProjection)); } if (graphNode != NULL) { @@ -81,12 +81,12 @@ init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrt /** * Allocates and returns a newly created perspective node */ -struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *pool, +struct GraphNodePerspective *init_graph_node_perspective(struct DynamicPool *pool, struct GraphNodePerspective *graphNode, f32 fov, s16 near, s16 far, GraphNodeFunc nodeFunc, s32 unused) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodePerspective)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodePerspective)); } if (graphNode != NULL) { @@ -109,10 +109,10 @@ struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *p /** * Allocates and returns a newly created start node */ -struct GraphNodeStart *init_graph_node_start(struct AllocOnlyPool *pool, +struct GraphNodeStart *init_graph_node_start(struct DynamicPool *pool, struct GraphNodeStart *graphNode) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeStart)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeStart)); } if (graphNode != NULL) { @@ -125,10 +125,10 @@ struct GraphNodeStart *init_graph_node_start(struct AllocOnlyPool *pool, /** * Allocates and returns a newly created master list node */ -struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *pool, +struct GraphNodeMasterList *init_graph_node_master_list(struct DynamicPool *pool, struct GraphNodeMasterList *graphNode, s16 on) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeMasterList)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeMasterList)); } if (graphNode != NULL) { @@ -145,11 +145,11 @@ struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *po /** * Allocates and returns a newly created render range node */ -struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct AllocOnlyPool *pool, +struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct DynamicPool *pool, struct GraphNodeLevelOfDetail *graphNode, s16 minDistance, s16 maxDistance) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeLevelOfDetail)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeLevelOfDetail)); } if (graphNode != NULL) { @@ -164,12 +164,12 @@ struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct AllocOnlyPool /** * Allocates and returns a newly created switch case node */ -struct GraphNodeSwitchCase *init_graph_node_switch_case(struct AllocOnlyPool *pool, +struct GraphNodeSwitchCase *init_graph_node_switch_case(struct DynamicPool *pool, struct GraphNodeSwitchCase *graphNode, s16 numCases, s16 selectedCase, GraphNodeFunc nodeFunc, s32 unused) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeSwitchCase)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeSwitchCase)); } if (graphNode != NULL) { @@ -190,11 +190,11 @@ struct GraphNodeSwitchCase *init_graph_node_switch_case(struct AllocOnlyPool *po /** * Allocates and returns a newly created camera node */ -struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool, +struct GraphNodeCamera *init_graph_node_camera(struct DynamicPool *pool, struct GraphNodeCamera *graphNode, f32 *pos, f32 *focus, GraphNodeFunc func, s32 mode) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeCamera)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeCamera)); graphNode->config.camera = NULL; } @@ -219,11 +219,11 @@ struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool, * Allocates and returns a newly created translation rotation node */ struct GraphNodeTranslationRotation * -init_graph_node_translation_rotation(struct AllocOnlyPool *pool, +init_graph_node_translation_rotation(struct DynamicPool *pool, struct GraphNodeTranslationRotation *graphNode, s32 drawingLayer, void *displayList, Vec3s translation, Vec3s rotation) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeTranslationRotation)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeTranslationRotation)); } if (graphNode != NULL) { @@ -241,12 +241,12 @@ init_graph_node_translation_rotation(struct AllocOnlyPool *pool, /** * Allocates and returns a newly created translation node */ -struct GraphNodeTranslation *init_graph_node_translation(struct AllocOnlyPool *pool, +struct GraphNodeTranslation *init_graph_node_translation(struct DynamicPool *pool, struct GraphNodeTranslation *graphNode, s32 drawingLayer, void *displayList, Vec3s translation) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeTranslation)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeTranslation)); } if (graphNode != NULL) { @@ -263,12 +263,12 @@ struct GraphNodeTranslation *init_graph_node_translation(struct AllocOnlyPool *p /** * Allocates and returns a newly created rotation node */ -struct GraphNodeRotation *init_graph_node_rotation(struct AllocOnlyPool *pool, +struct GraphNodeRotation *init_graph_node_rotation(struct DynamicPool *pool, struct GraphNodeRotation *graphNode, s32 drawingLayer, void *displayList, Vec3s rotation) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeRotation)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeRotation)); } if (graphNode != NULL) { @@ -284,11 +284,11 @@ struct GraphNodeRotation *init_graph_node_rotation(struct AllocOnlyPool *pool, /** * Allocates and returns a newly created scaling node */ -struct GraphNodeScale *init_graph_node_scale(struct AllocOnlyPool *pool, +struct GraphNodeScale *init_graph_node_scale(struct DynamicPool *pool, struct GraphNodeScale *graphNode, s32 drawingLayer, void *displayList, f32 scale) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeScale)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeScale)); } if (graphNode != NULL) { @@ -305,12 +305,12 @@ struct GraphNodeScale *init_graph_node_scale(struct AllocOnlyPool *pool, /** * Allocates and returns a newly created object node */ -struct GraphNodeObject *init_graph_node_object(struct AllocOnlyPool *pool, +struct GraphNodeObject *init_graph_node_object(struct DynamicPool *pool, struct GraphNodeObject *graphNode, struct GraphNode *sharedChild, Vec3f pos, Vec3s angle, Vec3f scale) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeObject)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeObject)); } if (graphNode != NULL) { @@ -336,11 +336,11 @@ struct GraphNodeObject *init_graph_node_object(struct AllocOnlyPool *pool, /** * Allocates and returns a newly created frustum culling radius node */ -struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct AllocOnlyPool *pool, +struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct DynamicPool *pool, struct GraphNodeCullingRadius *graphNode, s16 radius) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeCullingRadius)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeCullingRadius)); } if (graphNode != NULL) { @@ -354,12 +354,12 @@ struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct AllocOnlyPo /** * Allocates and returns a newly created animated part node */ -struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct AllocOnlyPool *pool, +struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct DynamicPool *pool, struct GraphNodeAnimatedPart *graphNode, s32 drawingLayer, void *displayList, Vec3s translation) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeAnimatedPart)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeAnimatedPart)); } if (graphNode != NULL) { @@ -375,12 +375,12 @@ struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct AllocOnlyPool /** * Allocates and returns a newly created billboard node */ -struct GraphNodeBillboard *init_graph_node_billboard(struct AllocOnlyPool *pool, +struct GraphNodeBillboard *init_graph_node_billboard(struct DynamicPool *pool, struct GraphNodeBillboard *graphNode, s32 drawingLayer, void *displayList, Vec3s translation) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeBillboard)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeBillboard)); } if (graphNode != NULL) { @@ -396,11 +396,11 @@ struct GraphNodeBillboard *init_graph_node_billboard(struct AllocOnlyPool *pool, /** * Allocates and returns a newly created displaylist node */ -struct GraphNodeDisplayList *init_graph_node_display_list(struct AllocOnlyPool *pool, +struct GraphNodeDisplayList *init_graph_node_display_list(struct DynamicPool *pool, struct GraphNodeDisplayList *graphNode, s32 drawingLayer, void *displayList) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeDisplayList)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeDisplayList)); } if (graphNode != NULL) { @@ -415,11 +415,11 @@ struct GraphNodeDisplayList *init_graph_node_display_list(struct AllocOnlyPool * /** * Allocates and returns a newly created shadow node */ -struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool, +struct GraphNodeShadow *init_graph_node_shadow(struct DynamicPool *pool, struct GraphNodeShadow *graphNode, s16 shadowScale, u8 shadowSolidity, u8 shadowType) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeShadow)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeShadow)); } if (graphNode != NULL) { @@ -435,11 +435,11 @@ struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool, /** * Allocates and returns a newly created object parent node */ -struct GraphNodeObjectParent *init_graph_node_object_parent(struct AllocOnlyPool *pool, +struct GraphNodeObjectParent *init_graph_node_object_parent(struct DynamicPool *pool, struct GraphNodeObjectParent *graphNode, struct GraphNode *sharedChild) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeObjectParent)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeObjectParent)); } if (graphNode != NULL) { @@ -454,11 +454,11 @@ struct GraphNodeObjectParent *init_graph_node_object_parent(struct AllocOnlyPool /** * Allocates and returns a newly created generated node */ -struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool, +struct GraphNodeGenerated *init_graph_node_generated(struct DynamicPool *pool, struct GraphNodeGenerated *graphNode, GraphNodeFunc gfxFunc, s32 parameter) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeGenerated)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeGenerated)); } if (graphNode != NULL) { @@ -477,12 +477,12 @@ struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool, /** * Allocates and returns a newly created background node */ -struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *pool, +struct GraphNodeBackground *init_graph_node_background(struct DynamicPool *pool, struct GraphNodeBackground *graphNode, u16 background, GraphNodeFunc backgroundFunc, s32 zero) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeBackground)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeBackground)); } if (graphNode != NULL) { @@ -508,13 +508,13 @@ struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *poo /** * Allocates and returns a newly created held object node */ -struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *pool, +struct GraphNodeHeldObject *init_graph_node_held_object(struct DynamicPool *pool, struct GraphNodeHeldObject *graphNode, struct Object *objNode, Vec3s translation, GraphNodeFunc nodeFunc, s32 playerIndex) { if (pool != NULL) { - graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeHeldObject)); + graphNode = dynamic_pool_alloc(pool, sizeof(struct GraphNodeHeldObject)); } if (graphNode != NULL) { diff --git a/src/engine/graph_node.h b/src/engine/graph_node.h index c8d548d00..d2a41895c 100644 --- a/src/engine/graph_node.h +++ b/src/engine/graph_node.h @@ -66,7 +66,7 @@ // The signature for a function stored in a geo node // The context argument depends on the callContext: -// - for GEO_CONTEXT_CREATE it is the AllocOnlyPool from which the node was allocated +// - for GEO_CONTEXT_CREATE it is the DynamicPool from which the node was allocated // - for GEO_CONTEXT_RENDER or GEO_CONTEXT_HELD_OBJ it is the top of the float matrix stack with type Mat4 // - for GEO_CONTEXT_AREA_* it is the root geo node typedef Gfx *(*GraphNodeFunc)(s32 callContext, struct GraphNode *node, void *context); @@ -386,45 +386,45 @@ extern Vec3s gVec3sOne; void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type); -struct GraphNodeRoot *init_graph_node_root(struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode, +struct GraphNodeRoot *init_graph_node_root(struct DynamicPool *pool, struct GraphNodeRoot *graphNode, s16 areaIndex, s16 x, s16 y, s16 width, s16 height); -struct GraphNodeOrthoProjection *init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrthoProjection *graphNode, f32 scale); -struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *pool, struct GraphNodePerspective *graphNode, +struct GraphNodeOrthoProjection *init_graph_node_ortho_projection(struct DynamicPool *pool, struct GraphNodeOrthoProjection *graphNode, f32 scale); +struct GraphNodePerspective *init_graph_node_perspective(struct DynamicPool *pool, struct GraphNodePerspective *graphNode, f32 fov, s16 near, s16 far, GraphNodeFunc nodeFunc, s32 unused); -struct GraphNodeStart *init_graph_node_start(struct AllocOnlyPool *pool, struct GraphNodeStart *graphNode); -struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *pool, struct GraphNodeMasterList *graphNode, s16 on); -struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct AllocOnlyPool *pool, struct GraphNodeLevelOfDetail *graphNode, +struct GraphNodeStart *init_graph_node_start(struct DynamicPool *pool, struct GraphNodeStart *graphNode); +struct GraphNodeMasterList *init_graph_node_master_list(struct DynamicPool *pool, struct GraphNodeMasterList *graphNode, s16 on); +struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct DynamicPool *pool, struct GraphNodeLevelOfDetail *graphNode, s16 minDistance, s16 maxDistance); -struct GraphNodeSwitchCase *init_graph_node_switch_case(struct AllocOnlyPool *pool, struct GraphNodeSwitchCase *graphNode, +struct GraphNodeSwitchCase *init_graph_node_switch_case(struct DynamicPool *pool, struct GraphNodeSwitchCase *graphNode, s16 numCases, s16 selectedCase, GraphNodeFunc nodeFunc, s32 unused); -struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool, struct GraphNodeCamera *graphNode, +struct GraphNodeCamera *init_graph_node_camera(struct DynamicPool *pool, struct GraphNodeCamera *graphNode, f32 *pos, f32 *focus, GraphNodeFunc func, s32 mode); -struct GraphNodeTranslationRotation *init_graph_node_translation_rotation(struct AllocOnlyPool *pool, struct GraphNodeTranslationRotation *graphNode, +struct GraphNodeTranslationRotation *init_graph_node_translation_rotation(struct DynamicPool *pool, struct GraphNodeTranslationRotation *graphNode, s32 drawingLayer, void *displayList, Vec3s translation, Vec3s rotation); -struct GraphNodeTranslation *init_graph_node_translation(struct AllocOnlyPool *pool, struct GraphNodeTranslation *graphNode, +struct GraphNodeTranslation *init_graph_node_translation(struct DynamicPool *pool, struct GraphNodeTranslation *graphNode, s32 drawingLayer, void *displayList, Vec3s translation); -struct GraphNodeRotation *init_graph_node_rotation(struct AllocOnlyPool *pool, struct GraphNodeRotation *graphNode, +struct GraphNodeRotation *init_graph_node_rotation(struct DynamicPool *pool, struct GraphNodeRotation *graphNode, s32 drawingLayer, void *displayList, Vec3s rotation); -struct GraphNodeScale *init_graph_node_scale(struct AllocOnlyPool *pool, struct GraphNodeScale *graphNode, +struct GraphNodeScale *init_graph_node_scale(struct DynamicPool *pool, struct GraphNodeScale *graphNode, s32 drawingLayer, void *displayList, f32 scale); -struct GraphNodeObject *init_graph_node_object(struct AllocOnlyPool *pool, struct GraphNodeObject *graphNode, +struct GraphNodeObject *init_graph_node_object(struct DynamicPool *pool, struct GraphNodeObject *graphNode, struct GraphNode *sharedChild, Vec3f pos, Vec3s angle, Vec3f scale); -struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct AllocOnlyPool *pool, struct GraphNodeCullingRadius *graphNode, s16 radius); -struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct AllocOnlyPool *pool, struct GraphNodeAnimatedPart *graphNode, +struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct DynamicPool *pool, struct GraphNodeCullingRadius *graphNode, s16 radius); +struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct DynamicPool *pool, struct GraphNodeAnimatedPart *graphNode, s32 drawingLayer, void *displayList, Vec3s translation); -struct GraphNodeBillboard *init_graph_node_billboard(struct AllocOnlyPool *pool, struct GraphNodeBillboard *graphNode, +struct GraphNodeBillboard *init_graph_node_billboard(struct DynamicPool *pool, struct GraphNodeBillboard *graphNode, s32 drawingLayer, void *displayList, Vec3s translation); -struct GraphNodeDisplayList *init_graph_node_display_list(struct AllocOnlyPool *pool, struct GraphNodeDisplayList *graphNode, +struct GraphNodeDisplayList *init_graph_node_display_list(struct DynamicPool *pool, struct GraphNodeDisplayList *graphNode, s32 drawingLayer, void *displayList); -struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool, struct GraphNodeShadow *graphNode, +struct GraphNodeShadow *init_graph_node_shadow(struct DynamicPool *pool, struct GraphNodeShadow *graphNode, s16 shadowScale, u8 shadowSolidity, u8 shadowType); -struct GraphNodeObjectParent *init_graph_node_object_parent(struct AllocOnlyPool *pool, struct GraphNodeObjectParent *sp1c, +struct GraphNodeObjectParent *init_graph_node_object_parent(struct DynamicPool *pool, struct GraphNodeObjectParent *sp1c, struct GraphNode *sharedChild); -struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool, struct GraphNodeGenerated *sp1c, +struct GraphNodeGenerated *init_graph_node_generated(struct DynamicPool *pool, struct GraphNodeGenerated *sp1c, GraphNodeFunc gfxFunc, s32 parameter); -struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *pool, struct GraphNodeBackground *sp1c, +struct GraphNodeBackground *init_graph_node_background(struct DynamicPool *pool, struct GraphNodeBackground *sp1c, u16 background, GraphNodeFunc backgroundFunc, s32 zero); -struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *pool, struct GraphNodeHeldObject *sp1c, +struct GraphNodeHeldObject *init_graph_node_held_object(struct DynamicPool *pool, struct GraphNodeHeldObject *sp1c, struct Object *objNode, Vec3s translation, GraphNodeFunc nodeFunc, s32 playerIndex); struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *childNode); diff --git a/src/engine/level_script.c b/src/engine/level_script.c index ad75527b7..08f86f515 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -51,7 +51,7 @@ LevelScript* gLevelScriptActive = NULL; static uintptr_t sStack[32]; -static struct AllocOnlyPool *sLevelPool = NULL; +static struct DynamicPool *sLevelPool = NULL; static u16 sDelayFrames = 0; static u16 sDelayFrames2 = 0; @@ -107,7 +107,7 @@ static s32 eval_script_op(s8 op, s32 arg) { struct ObjectWarpNode *area_create_warp_node(u8 id, u8 destLevel, u8 destArea, u8 destNode, u8 checkpoint, struct Object *o) { if (sCurrAreaIndex != -1) { - struct ObjectWarpNode *warpNode = alloc_only_pool_alloc(sLevelPool, sizeof(struct ObjectWarpNode)); + struct ObjectWarpNode *warpNode = dynamic_pool_alloc(sLevelPool, sizeof(struct ObjectWarpNode)); warpNode->node.id = id; warpNode->node.destLevel = destLevel + checkpoint; @@ -396,14 +396,14 @@ static void level_cmd_alloc_level_pool(void) { // free previous level pool if (sLevelPool != NULL) { - alloc_only_pool_free(sLevelPool); + dynamic_pool_free_pool(sLevelPool); sLevelPool = NULL; } dynos_model_clear_pool(MODEL_POOL_LEVEL); // allocate new level pool if (sLevelPool == NULL) { - sLevelPool = alloc_only_pool_init(); + sLevelPool = dynamic_pool_init(); } sCurrentCmd = CMD_NEXT; @@ -547,7 +547,7 @@ static void level_cmd_place_object(void) { if (sCurrAreaIndex != -1 && (gLevelValues.disableActs || (CMD_GET(u8, 2) & val7) || CMD_GET(u8, 2) == 0x1F)) { model = CMD_GET(u8, 3); if (model >= MAX_LOADED_GRAPH_NODES) { model = MODEL_NONE; } - spawnInfo = alloc_only_pool_alloc(sLevelPool, sizeof(struct SpawnInfo)); + spawnInfo = dynamic_pool_alloc(sLevelPool, sizeof(struct SpawnInfo)); spawnInfo->startPos[0] = CMD_GET(s16, 4); spawnInfo->startPos[1] = CMD_GET(s16, 6); @@ -578,7 +578,7 @@ static void level_cmd_place_object(void) { static void level_cmd_create_warp_node(void) { if (sCurrAreaIndex != -1) { struct ObjectWarpNode *warpNode = - alloc_only_pool_alloc(sLevelPool, sizeof(struct ObjectWarpNode)); + dynamic_pool_alloc(sLevelPool, sizeof(struct ObjectWarpNode)); warpNode->node.id = CMD_GET(u8, 2); warpNode->node.destLevel = CMD_GET(u8, 3) + CMD_GET(u8, 6); @@ -601,7 +601,7 @@ static void level_cmd_create_instant_warp(void) { if (sCurrAreaIndex != -1) { if (gAreas[sCurrAreaIndex].instantWarps == NULL) { gAreas[sCurrAreaIndex].instantWarps = - alloc_only_pool_alloc(sLevelPool, 4 * sizeof(struct InstantWarp)); + dynamic_pool_alloc(sLevelPool, 4 * sizeof(struct InstantWarp)); for (i = INSTANT_WARP_INDEX_START; i < INSTANT_WARP_INDEX_STOP; i++) { gAreas[sCurrAreaIndex].instantWarps[i].id = 0; @@ -636,7 +636,7 @@ static void level_cmd_create_painting_warp_node(void) { if (sCurrAreaIndex != -1) { if (gAreas[sCurrAreaIndex].paintingWarpNodes == NULL) { gAreas[sCurrAreaIndex].paintingWarpNodes = - alloc_only_pool_alloc(sLevelPool, MAX_PAINTING_WARP_NODES * sizeof(struct WarpNode)); + dynamic_pool_alloc(sLevelPool, MAX_PAINTING_WARP_NODES * sizeof(struct WarpNode)); for (i = 0; i < MAX_PAINTING_WARP_NODES; i++) { gAreas[sCurrAreaIndex].paintingWarpNodes[i].id = 0; @@ -660,7 +660,7 @@ static void level_cmd_3A(void) { if (sCurrAreaIndex != -1) { if ((val4 = gAreas[sCurrAreaIndex].unused28) == NULL) { val4 = gAreas[sCurrAreaIndex].unused28 = - alloc_only_pool_alloc(sLevelPool, sizeof(struct UnusedArea28)); + dynamic_pool_alloc(sLevelPool, sizeof(struct UnusedArea28)); } val4->unk00 = CMD_GET(s16, 2); @@ -683,7 +683,7 @@ static void level_cmd_create_whirlpool(void) { || (CMD_GET(u8, 3) == 2 && beatBowser2) || (CMD_GET(u8, 3) == 3 && gCurrActNum >= 2)) { if (sCurrAreaIndex != -1 && index < 2) { if ((whirlpool = gAreas[sCurrAreaIndex].whirlpools[index]) == NULL) { - whirlpool = alloc_only_pool_alloc(sLevelPool, sizeof(struct Whirlpool)); + whirlpool = dynamic_pool_alloc(sLevelPool, sizeof(struct Whirlpool)); gAreas[sCurrAreaIndex].whirlpools[index] = whirlpool; } @@ -713,7 +713,7 @@ static void level_cmd_set_terrain_data(void) { // The game modifies the terrain data and must be reset upon level reload. data = segmented_to_virtual(CMD_GET(void *, 4)); size = get_area_terrain_size(data) * sizeof(Collision); - gAreas[sCurrAreaIndex].terrainData = alloc_only_pool_alloc(sLevelPool, size); + gAreas[sCurrAreaIndex].terrainData = dynamic_pool_alloc(sLevelPool, size); memcpy(gAreas[sCurrAreaIndex].terrainData, data, size); } sCurrentCmd = CMD_NEXT; @@ -736,10 +736,10 @@ static void level_cmd_set_macro_objects(void) { area_check_red_coin_or_secret(&data[len - 1], true); len += 4; } - gAreas[sCurrAreaIndex].macroObjects = alloc_only_pool_alloc(sLevelPool, len * sizeof(MacroObject)); + gAreas[sCurrAreaIndex].macroObjects = dynamic_pool_alloc(sLevelPool, len * sizeof(MacroObject)); memcpy(gAreas[sCurrAreaIndex].macroObjects, data, len * sizeof(MacroObject)); - gAreas[sCurrAreaIndex].macroObjectsAltered = alloc_only_pool_alloc(sLevelPool, len * sizeof(u8)); + gAreas[sCurrAreaIndex].macroObjectsAltered = dynamic_pool_alloc(sLevelPool, len * sizeof(u8)); memset(gAreas[sCurrAreaIndex].macroObjectsAltered, 0, len); } sCurrentCmd = CMD_NEXT; @@ -946,7 +946,7 @@ static void level_cmd_place_object_ext(void) { if (sCurrAreaIndex != -1 && (gLevelValues.disableActs || (CMD_GET(u8, 2) & val7) || CMD_GET(u8, 2) == 0x1F)) { u16 model = CMD_GET(u8, 3); if (model >= MAX_LOADED_GRAPH_NODES) { model = MODEL_NONE; } - spawnInfo = alloc_only_pool_alloc(sLevelPool, sizeof(struct SpawnInfo)); + spawnInfo = dynamic_pool_alloc(sLevelPool, sizeof(struct SpawnInfo)); spawnInfo->startPos[0] = CMD_GET(s16, 4); spawnInfo->startPos[1] = CMD_GET(s16, 6); @@ -1016,7 +1016,7 @@ static void level_cmd_place_object_ext2(void) { } if (sCurrAreaIndex != -1 && (gLevelValues.disableActs || (CMD_GET(u8, 2) & val7) || CMD_GET(u8, 2) == 0x1F)) { - spawnInfo = alloc_only_pool_alloc(sLevelPool, sizeof(struct SpawnInfo)); + spawnInfo = dynamic_pool_alloc(sLevelPool, sizeof(struct SpawnInfo)); spawnInfo->startPos[0] = CMD_GET(s16, 4); spawnInfo->startPos[1] = CMD_GET(s16, 6); diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index c820a6c5f..bd61efd41 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -31,13 +31,13 @@ SpatialPartitionCell gDynamicSurfacePartition[NUM_CELLS][NUM_CELLS]; /** * Pools of data to contain either surface nodes or surfaces. */ -struct AllocOnlyPool* sSurfacePool = NULL; +struct DynamicPool* 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 = alloc_only_pool_alloc(sSurfacePool, sizeof(struct SurfaceNode)); + struct SurfaceNode *node = dynamic_pool_alloc(sSurfacePool, sizeof(struct SurfaceNode)); gSurfaceNodesAllocated++; node->next = NULL; @@ -50,7 +50,7 @@ static struct SurfaceNode *alloc_surface_node(void) { * initialize the surface. */ static struct Surface *alloc_surface(void) { - struct Surface *surface = alloc_only_pool_alloc(sSurfacePool, sizeof(struct Surface)); + struct Surface *surface = dynamic_pool_alloc(sSurfacePool, sizeof(struct Surface)); gSurfacesAllocated++; surface->type = 0; @@ -523,8 +523,8 @@ static void load_environmental_regions(s16 **data) { * Allocate some of the main pool for surfaces (2300 surf) and for surface nodes (7000 nodes). */ void alloc_surface_pools(void) { - if (sSurfacePool) { alloc_only_pool_free(sSurfacePool); } - sSurfacePool = alloc_only_pool_init(); + if (sSurfacePool) { dynamic_pool_free_pool(sSurfacePool); } + sSurfacePool = dynamic_pool_init(); gSurfaceNodesAllocated = 0; gSurfacesAllocated = 0; @@ -591,7 +591,6 @@ void load_area_terrain(s16 index, s16 *data, s8 *surfaceRooms, s16 *macroObjects // Initialize the data for this. gEnvironmentRegions = NULL; - unused8038BE90 = 0; clear_static_surfaces(); diff --git a/src/engine/surface_load.h b/src/engine/surface_load.h index 6cc7ccc23..30558132b 100644 --- a/src/engine/surface_load.h +++ b/src/engine/surface_load.h @@ -24,9 +24,6 @@ enum typedef struct SurfaceNode SpatialPartitionCell[3]; -// Needed for bs bss reordering memes. -extern s32 unused8038BE90; - extern SpatialPartitionCell gStaticSurfacePartition[NUM_CELLS][NUM_CELLS]; extern SpatialPartitionCell gDynamicSurfacePartition[NUM_CELLS][NUM_CELLS]; diff --git a/src/game/camera.c b/src/game/camera.c index 9c784731c..a88d7ce11 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -3642,10 +3642,10 @@ void select_mario_cam_mode(void) { /** * Allocate the GraphNodeCamera's config.camera, and copy `c`'s focus to the Camera's area center point. */ -void create_camera(struct GraphNodeCamera *gc, struct AllocOnlyPool *pool) { +void create_camera(struct GraphNodeCamera *gc, struct DynamicPool *pool) { if (!gc) { return; } s16 mode = gc->config.mode; - struct Camera *c = alloc_only_pool_alloc(pool, sizeof(struct Camera)); + struct Camera *c = dynamic_pool_alloc(pool, sizeof(struct Camera)); gc->config.camera = c; c->mode = mode; diff --git a/src/game/memory.c b/src/game/memory.c index 939453801..480f588bc 100644 --- a/src/game/memory.c +++ b/src/game/memory.c @@ -391,3 +391,17 @@ 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 eccb2e0df..fe623124b 100644 --- a/src/game/memory.h +++ b/src/game/memory.h @@ -11,16 +11,30 @@ #define GFX_POOL_SIZE 0x400000 // 4MB (Vanilla: 512kB) #define DEFAULT_POOL_SIZE 0x2000000 // 32MB (Vanilla: ~11MB) -struct AllocOnlyPool +struct DynamicPool { u32 usedSpace; - struct AllocOnlyNode* tail; + struct DynamicPoolNode* tail; }; -struct AllocOnlyNode +struct DynamicPoolNode { void* ptr; - struct AllocOnlyNode* prev; + struct DynamicPoolNode* prev; +}; + +struct GrowingPool +{ + u32 usedSpace; + u32 nodeSize; + struct GrowingPoolNode* tail; +}; + +struct GrowingPoolNode +{ + u32 usedSpace; + void* ptr; + struct GrowingPoolNode* prev; }; struct MemoryPool; @@ -54,9 +68,13 @@ u32 main_pool_pop_state(void); #define load_segment_decompress_heap(...) #define load_engine_code_segment(...) -struct AllocOnlyPool* alloc_only_pool_init(void); -void* alloc_only_pool_alloc(struct AllocOnlyPool *pool, u32 size); -void alloc_only_pool_free(struct AllocOnlyPool *pool); +struct DynamicPool* dynamic_pool_init(void); +void* dynamic_pool_alloc(struct DynamicPool *pool, u32 size); +void dynamic_pool_free_pool(struct DynamicPool *pool); + +struct GrowingPool* growing_pool_init(struct GrowingPool* pool, u32 nodeSize); +void* growing_pool_alloc(struct GrowingPool *pool, u32 size); +void growing_pool_free_pool(struct GrowingPool *pool); struct MemoryPool *mem_pool_init(u32 size, u32 side); void *mem_pool_alloc(struct MemoryPool *pool, u32 size); diff --git a/src/game/memory_dynamic.c b/src/game/memory_dynamic.c index c6507956a..2b42ee3fb 100644 --- a/src/game/memory_dynamic.c +++ b/src/game/memory_dynamic.c @@ -2,17 +2,23 @@ #include "memory.h" #include "rendering_graph_node.h" -struct AllocOnlyPool* alloc_only_pool_init(void) { - struct AllocOnlyPool* pool = calloc(1, sizeof(struct AllocOnlyPool)); +#define ALIGN16(val) (((val) + 0xF) & ~0xF) + + ////////////////// + // dynamic pool // +////////////////// + +struct DynamicPool* dynamic_pool_init(void) { + struct DynamicPool* pool = calloc(1, sizeof(struct DynamicPool)); pool->usedSpace = 0; pool->tail = NULL; return pool; } -void* alloc_only_pool_alloc(struct AllocOnlyPool *pool, u32 size) { +void* dynamic_pool_alloc(struct DynamicPool *pool, u32 size) { if (!pool) { return NULL; } - struct AllocOnlyNode* node = calloc(1, sizeof(struct AllocOnlyNode)); + struct DynamicPoolNode* node = calloc(1, sizeof(struct DynamicPoolNode)); node->ptr = calloc(1, size); node->prev = pool->tail; @@ -22,11 +28,11 @@ void* alloc_only_pool_alloc(struct AllocOnlyPool *pool, u32 size) { return node->ptr; } -void alloc_only_pool_free(struct AllocOnlyPool *pool) { +void dynamic_pool_free_pool(struct DynamicPool *pool) { if (!pool) { return; } - struct AllocOnlyNode* node = pool->tail; + struct DynamicPoolNode* node = pool->tail; while (node) { - struct AllocOnlyNode* prev = node->prev; + struct DynamicPoolNode* prev = node->prev; free(node->ptr); free(node); node = prev; @@ -34,6 +40,85 @@ void alloc_only_pool_free(struct AllocOnlyPool *pool) { free(pool); } -void *alloc_display_list(u32 size) { - return alloc_only_pool_alloc(gDisplayListHeap, size); + ////////////////// + // growing pool // +////////////////// + +struct GrowingPool* growing_pool_init(struct GrowingPool* pool, u32 nodeSize) { + if (pool) { + // clear existing pool + struct GrowingPoolNode* node = pool->tail; + while (node) { + node->usedSpace = 0; + node = node->prev; + } + pool->usedSpace = 0; + } else { + // allocate a new pool + pool = calloc(1, sizeof(struct GrowingPool)); + pool->usedSpace = 0; + pool->nodeSize = nodeSize; + pool->tail = NULL; + } + return pool; +} + +void* growing_pool_alloc(struct GrowingPool *pool, u32 size) { + if (!pool) { return NULL; } + + // maintain alignment + size = ALIGN16(size); + + // check if it's too big for a node + if (size >= pool->nodeSize) { + // create a node just for this + struct GrowingPoolNode* node = calloc(1, sizeof(struct GrowingPoolNode)); + node->ptr = calloc(1, size); + node->prev = pool->tail; + node->usedSpace = size; + + pool->tail = node; + pool->usedSpace += size; + + return node->ptr; + } + + // search for space in nodes + struct GrowingPoolNode* node = pool->tail; + u32 depth = 0; + while (node) { + depth++; + s64 freeSpace = (s64)pool->nodeSize - (s64)node->usedSpace; + if (freeSpace > size) { break; } + node = node->prev; + } + + // allocate new node + if (!node) { + node = calloc(1, sizeof(struct GrowingPoolNode)); + node->usedSpace = 0; + node->ptr = calloc(1, pool->nodeSize); + node->prev = pool->tail; + pool->tail = node; + } + + // retrieve pointer + void* ptr = ((u8*)node->ptr + node->usedSpace); + memset(ptr, 0, size); + node->usedSpace += size; + pool->usedSpace += size; + + return ptr; +} + +void growing_pool_free_pool(struct GrowingPool *pool) { + if (!pool) { return; } + struct GrowingPoolNode* node = pool->tail; + while (node) { + struct GrowingPoolNode* prev = node->prev; + free(node->ptr); + free(node); + node = prev; + } + free(pool); } diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index e0bad6209..b5a899f1d 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -43,6 +43,7 @@ */ #define MATRIX_STACK_SIZE 64 +#define DISPLAY_LIST_HEAP_SIZE 32000 f32 gProjectionMaxNearValue = 5; s16 gProjectionVanillaNearValue = 100; @@ -91,7 +92,7 @@ f32 gCurAnimTranslationMultiplier; u16 *gCurrAnimAttribute = NULL; s16 *gCurAnimData = NULL; -struct AllocOnlyPool* gDisplayListHeap = NULL; +struct GrowingPool* gDisplayListHeap = NULL; struct RenderModeContainer { u32 modes[8]; @@ -404,8 +405,7 @@ static void geo_append_display_list(void *displayList, s16 layer) { gSPLookAt(gDisplayListHead++, &lookAt); #endif if (gCurGraphNodeMasterList != 0) { - struct DisplayListNode *listNode = - alloc_only_pool_alloc(gDisplayListHeap, sizeof(struct DisplayListNode)); + struct DisplayListNode *listNode = growing_pool_alloc(gDisplayListHeap, sizeof(struct DisplayListNode)); listNode->transform = gMatStackFixed[gMatStackIndex]; listNode->transformPrev = gMatStackPrevFixed[gMatStackIndex]; @@ -782,7 +782,7 @@ static void geo_process_display_list(struct GraphNodeDisplayList *node) { static void geo_process_generated_list(struct GraphNodeGenerated *node) { if (node->fnNode.func != NULL) { Gfx *list = node->fnNode.func(GEO_CONTEXT_RENDER, &node->fnNode.node, - (struct AllocOnlyPool *) gMatStack[gMatStackIndex]); + (struct DynamicPool *) gMatStack[gMatStackIndex]); if (list != NULL) { geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(list), node->fnNode.node.flags >> 8); @@ -1431,7 +1431,7 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { scalePrev); if (node->fnNode.func != NULL) { - node->fnNode.func(GEO_CONTEXT_HELD_OBJ, &node->fnNode.node, (struct AllocOnlyPool *) gMatStack[gMatStackIndex + 1]); + node->fnNode.func(GEO_CONTEXT_HELD_OBJ, &node->fnNode.node, (struct DynamicPool *) gMatStack[gMatStackIndex + 1]); } // Increment the matrix stack, If we fail to do so. Just return. @@ -1620,8 +1620,7 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) geo_clear_interp_variables(); if (node->node.flags & GRAPH_RENDER_ACTIVE) { - if (gDisplayListHeap) { alloc_only_pool_free(gDisplayListHeap); } - gDisplayListHeap = alloc_only_pool_init(); + gDisplayListHeap = growing_pool_init(gDisplayListHeap, DISPLAY_LIST_HEAP_SIZE); Vp *viewport = alloc_display_list(sizeof(*viewport)); if (viewport == NULL) { return; } @@ -1665,9 +1664,7 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) if (node->node.children != NULL) { geo_process_node_and_siblings(node->node.children); } + gCurGraphNodeRoot = NULL; - //if (gShowDebugText) { - // print_text_fmt_int(180, 36, "MEM %d", gDisplayListHeap->totalSpace - gDisplayListHeap->usedSpace); - //} } } \ No newline at end of file diff --git a/src/game/rendering_graph_node.h b/src/game/rendering_graph_node.h index 38a8d1cdb..1e9889689 100644 --- a/src/game/rendering_graph_node.h +++ b/src/game/rendering_graph_node.h @@ -9,7 +9,7 @@ extern f32 gProjectionMaxNearValue; extern s16 gProjectionVanillaNearValue; extern s16 gProjectionVanillaFarValue; -extern struct AllocOnlyPool *gDisplayListHeap; +extern struct GrowingPool *gDisplayListHeap; extern struct GraphNodeRoot *gCurGraphNodeRoot; extern struct GraphNodeMasterList *gCurGraphNodeMasterList; extern struct GraphNodePerspective *gCurGraphNodeCamFrustum;