Freeing display list allocations
This commit is contained in:
@@ -217,8 +217,8 @@ 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 is unused in libsm64
|
||||
gGeoViews = NULL; // alloc_only_pool_alloc(gGraphNodePool, gGeoNumViews * sizeof(struct GraphNode *));
|
||||
|
||||
graphNode->views = gGeoViews;
|
||||
graphNode->numViews = gGeoNumViews;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "../include/PR/gbi.h"
|
||||
|
||||
#include "../include/types.h"
|
||||
#include "../../memory.h"
|
||||
#include "../memory.h"
|
||||
|
||||
#define GRAPH_RENDER_ACTIVE (1 << 0)
|
||||
#define GRAPH_RENDER_CHILDREN_FIRST (1 << 1)
|
||||
|
||||
@@ -67,7 +67,7 @@ s32 is_anim_past_end(struct MarioState *m) {
|
||||
s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) {
|
||||
struct Object *o = m->marioObj;
|
||||
|
||||
hack_load_mario_animation_ex(m->animation, targetAnimID);
|
||||
shim_load_mario_animation(m->animation, targetAnimID);
|
||||
struct Animation *targetAnim = m->animation->targetAnim;
|
||||
//if (load_patchable_table(m->animation, targetAnimID)) {
|
||||
// targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values);
|
||||
@@ -101,7 +101,7 @@ s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) {
|
||||
s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel) {
|
||||
struct Object *o = m->marioObj;
|
||||
|
||||
hack_load_mario_animation_ex(m->animation, targetAnimID);
|
||||
shim_load_mario_animation(m->animation, targetAnimID);
|
||||
struct Animation *targetAnim = m->animation->targetAnim;
|
||||
//if (load_patchable_table(m->animation, targetAnimID)) {
|
||||
// targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values);
|
||||
|
||||
@@ -1125,6 +1125,8 @@ void geo_process_root_hack_single_node(struct GraphNode *node)
|
||||
{
|
||||
gDisplayListHead = NULL; // Currently unused, but referenced
|
||||
|
||||
display_list_pool_reset();
|
||||
|
||||
Mtx *initialMatrix;
|
||||
|
||||
gDisplayListHeap = alloc_only_pool_init();
|
||||
@@ -1162,5 +1164,5 @@ void geo_process_root_hack_single_node(struct GraphNode *node)
|
||||
|
||||
gMarioObject->header.gfx.throwMatrix = NULL;
|
||||
|
||||
main_pool_free(gDisplayListHeap);
|
||||
alloc_only_pool_free(gDisplayListHeap);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "memory.h"
|
||||
|
||||
// TODO don't handle every individual allocation with malloc, it sucks on windows
|
||||
|
||||
struct AllocOnlyPool
|
||||
{
|
||||
size_t allocatedCount;
|
||||
void **allocatedBlocks;
|
||||
};
|
||||
|
||||
struct AllocOnlyPool *s_display_list_pool;
|
||||
|
||||
void memory_init(void)
|
||||
{
|
||||
s_display_list_pool = alloc_only_pool_init();
|
||||
}
|
||||
|
||||
void memory_terminate(void)
|
||||
{
|
||||
alloc_only_pool_free( s_display_list_pool );
|
||||
}
|
||||
|
||||
struct AllocOnlyPool *alloc_only_pool_init(void)
|
||||
{
|
||||
struct AllocOnlyPool *newPool = malloc( sizeof( struct AllocOnlyPool ));
|
||||
newPool->allocatedCount = 0;
|
||||
newPool->allocatedBlocks = NULL;
|
||||
return newPool;
|
||||
}
|
||||
|
||||
void *alloc_only_pool_alloc(struct AllocOnlyPool *pool, s32 size)
|
||||
{
|
||||
pool->allocatedCount++;
|
||||
pool->allocatedBlocks = realloc( pool->allocatedBlocks, pool->allocatedCount * sizeof( void * ));
|
||||
pool->allocatedBlocks[ pool->allocatedCount - 1 ] = malloc( size );
|
||||
return pool->allocatedBlocks[ pool->allocatedCount - 1 ];
|
||||
}
|
||||
|
||||
void alloc_only_pool_free(struct AllocOnlyPool *pool)
|
||||
{
|
||||
for( int i = 0; i < pool->allocatedCount; ++i )
|
||||
free( pool->allocatedBlocks[i] );
|
||||
free( pool->allocatedBlocks );
|
||||
free( pool );
|
||||
}
|
||||
|
||||
void display_list_pool_reset(void)
|
||||
{
|
||||
alloc_only_pool_free( s_display_list_pool );
|
||||
s_display_list_pool = alloc_only_pool_init();
|
||||
}
|
||||
|
||||
void *alloc_display_list(u32 size)
|
||||
{
|
||||
return alloc_only_pool_alloc( s_display_list_pool, (s32)size );
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "include/types.h"
|
||||
|
||||
struct AllocOnlyPool;
|
||||
|
||||
extern void memory_init(void);
|
||||
extern void memory_terminate(void);
|
||||
|
||||
extern struct AllocOnlyPool *alloc_only_pool_init(void);
|
||||
extern void *alloc_only_pool_alloc(struct AllocOnlyPool *pool, s32 size);
|
||||
extern void alloc_only_pool_free(struct AllocOnlyPool *pool);
|
||||
|
||||
extern void display_list_pool_reset(void);
|
||||
extern void *alloc_display_list(u32 size);
|
||||
+5
-30
@@ -22,37 +22,12 @@ struct MarioState gMarioStateVal;
|
||||
struct MarioState *gMarioState = &gMarioStateVal;
|
||||
SM64DebugPrintFunctionPtr gDebugPrint = NULL;
|
||||
|
||||
void hack_load_mario_animation_ex(struct MarioAnimation *a, u32 index)
|
||||
void shim_load_mario_animation(struct MarioAnimation *a, u32 index)
|
||||
{
|
||||
if ((u32)a->currentAnimAddr == 1 + index)
|
||||
return;
|
||||
|
||||
a->currentAnimAddr = (u8*)(1 + index);
|
||||
a->targetAnim = &gLibSm64MarioAnimations[index];
|
||||
}
|
||||
|
||||
void hack_load_mario_animation(struct MarioAnimation *a, u32 index)
|
||||
{
|
||||
// struct MarioAnimDmaRelatedThing *sp20 = a->animDmaTable;
|
||||
// u8 *addr;
|
||||
// u32 size;
|
||||
//
|
||||
// if (index < sp20->count) {
|
||||
// addr = sp20->srcAddr + sp20->anim[index].offset;
|
||||
// size = sp20->anim[index].size;
|
||||
//
|
||||
// if (a->currentAnimAddr != addr) {
|
||||
// u32 a0 = sp20->anim[index].offset;
|
||||
// u32 b0 = sp20->anim[index].size;
|
||||
//
|
||||
// memcpy( (u8*)a->targetAnim, (u8*)sp20 + a0, b0 );
|
||||
// a->currentAnimAddr = addr;
|
||||
//
|
||||
// struct Animation *targetAnim = a->targetAnim;
|
||||
// targetAnim->values =(void*)( (u8 *)targetAnim + (uintptr_t)targetAnim->values );
|
||||
// targetAnim->index = (void*)( (u8 *)targetAnim + (uintptr_t)targetAnim->index );
|
||||
// }
|
||||
// }
|
||||
if ((u32)a->currentAnimAddr != 1 + index) {
|
||||
a->currentAnimAddr = (u8*)(1 + index);
|
||||
a->targetAnim = &g_libsm64_mario_animations[index];
|
||||
}
|
||||
}
|
||||
|
||||
void *segmented_to_virtual(const void *addr)
|
||||
|
||||
+2
-2
@@ -69,8 +69,8 @@ extern SM64DebugPrintFunctionPtr gDebugPrint;
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
extern void hack_load_mario_animation_ex(struct MarioAnimation *a, u32 index);
|
||||
extern void hack_load_mario_animation(struct MarioAnimation *a, u32 index);
|
||||
extern void shim_load_mario_animation(struct MarioAnimation *a, u32 index);
|
||||
|
||||
extern void *segmented_to_virtual(const void *addr);
|
||||
extern void *virtual_to_segmented(u32 segment, const void *addr);
|
||||
extern void func_80320A4C(u8 bankIndex, u8 arg1);
|
||||
|
||||
Reference in New Issue
Block a user