mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-22 09:22:18 -05:00
a5df9dddf0
* First batch some overlay
* Almost all overlay
* effect & gamestate
* kaleido stuffs
* more overlay
* more left over from code folder
* remaining hardcoded line and file
* Open & Close _DISP __FILE__ & __LINE__ clean up
* Some if (1) {} remove
* LOG_xxxx __FILE__ , __LINE__ cleaned
* ASSERT macro __FILE__ __LINE__
* mtx without line/file in functions
* " if (1) {} " & "if (0) {}" and tab/white place
* LogUtils as macro
* GameState_, GameAlloc_, SystemArena_ & ZeldaArena_
* Revert "GameState_, GameAlloc_, SystemArena_ & ZeldaArena_"
This reverts commit 0d85caaf7e
.
* Like last commit but as macro
* Fix matrix not using macros
* use function not macro
* DebugArena_* functions
GameAlloc_MallocDebug
BgCheck_PosErrorCheck as macros
removed issues with ; in macro file
81 lines
2.0 KiB
C
81 lines
2.0 KiB
C
#include "global.h"
|
|
|
|
void GameAlloc_Log(GameAlloc* this) {
|
|
GameAllocEntry* iter;
|
|
|
|
osSyncPrintf("this = %08x\n", this);
|
|
|
|
iter = this->base.next;
|
|
while (iter != &this->base) {
|
|
osSyncPrintf("ptr = %08x size = %d\n", iter, iter->size);
|
|
iter = iter->next;
|
|
}
|
|
}
|
|
|
|
void* GameAlloc_MallocDebug(GameAlloc* this, size_t size, const char* file, s32 line) {
|
|
GameAllocEntry* ptr = SystemArena_MallocDebug(size + sizeof(GameAllocEntry), __FILE__, __LINE__);
|
|
|
|
if (ptr != NULL) {
|
|
ptr->size = size;
|
|
ptr->prev = this->head;
|
|
this->head->next = ptr;
|
|
this->head = ptr;
|
|
ptr->next = &this->base;
|
|
this->base.prev = this->head;
|
|
return ptr + 1;
|
|
} else {
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
void* GameAlloc_Malloc(GameAlloc* this, size_t size) {
|
|
GameAllocEntry* ptr = SYSTEM_ARENA_MALLOC_DEBUG(size + sizeof(GameAllocEntry));
|
|
|
|
if (ptr != NULL) {
|
|
ptr->size = size;
|
|
ptr->prev = this->head;
|
|
this->head->next = ptr;
|
|
this->head = ptr;
|
|
ptr->next = &this->base;
|
|
this->base.prev = this->head;
|
|
return ptr + 1;
|
|
} else {
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
void GameAlloc_Free(GameAlloc* this, void* data) {
|
|
GameAllocEntry* ptr;
|
|
|
|
if (data != NULL) {
|
|
ptr = &((GameAllocEntry*)data)[-1];
|
|
LOG_CHECK_NULL_POINTER("ptr->prev", ptr->prev);
|
|
LOG_CHECK_NULL_POINTER("ptr->next", ptr->next);
|
|
ptr->prev->next = ptr->next;
|
|
ptr->next->prev = ptr->prev;
|
|
this->head = this->base.prev;
|
|
SYSTEM_ARENA_FREE_DEBUG(ptr);
|
|
}
|
|
}
|
|
|
|
void GameAlloc_Cleanup(GameAlloc* this) {
|
|
GameAllocEntry* next = this->base.next;
|
|
GameAllocEntry* cur;
|
|
|
|
while (&this->base != next) {
|
|
cur = next;
|
|
next = next->next;
|
|
SYSTEM_ARENA_FREE_DEBUG(cur);
|
|
}
|
|
|
|
this->head = &this->base;
|
|
this->base.next = &this->base;
|
|
this->base.prev = &this->base;
|
|
}
|
|
|
|
void GameAlloc_Init(GameAlloc* this) {
|
|
this->head = &this->base;
|
|
this->base.next = &this->base;
|
|
this->base.prev = &this->base;
|
|
}
|