create more realistic stairAllocSize

This commit is contained in:
inspectredc 2024-01-09 16:23:53 +00:00
parent 00ff6ae17f
commit b62231a3ca
9 changed files with 59 additions and 8 deletions

View File

@ -18,6 +18,9 @@ static const std::vector<ActorIdAllocTypePair> stairActorTable = {
#undef DEFINE_ACTOR_UNSET #undef DEFINE_ACTOR_UNSET
#undef DEFINE_ACTOR #undef DEFINE_ACTOR
size_t stairsAllocSize = 0x1D4790 - 0x26960 - 0x2200 - (0x55 * 0x60) - (3 * (48 * 16) / 2) - (4 * (32 * 32 * 4)) - 0x1000 - (20 * sizeof(MtxF));
Arena sStairsArena;
// using sizes from the debug rom // using sizes from the debug rom
std::unordered_map<u16, size_t> actorOverlaySizes = { std::unordered_map<u16, size_t> actorOverlaySizes = {
{ ACTOR_PLAYER, 0x0}, { ACTOR_PLAYER, 0x0},
@ -507,6 +510,17 @@ size_t Stairs_GetOverlaySize(u16 id) {
return actorOverlaySizes[id]; return actorOverlaySizes[id];
} }
size_t Stairs_GetSize() {
return stairsAllocSize;
}
s32 Stairs_DecreaseSize(size_t size) {
if (size > stairsAllocSize) {
return false;
}
stairsAllocSize -= size;
return true;
}
void* StairsArena_Malloc(size_t size) { void* StairsArena_Malloc(size_t size) {
void* ptr = __osMalloc(&sStairsArena, size); void* ptr = __osMalloc(&sStairsArena, size);
@ -647,6 +661,7 @@ void StairsArena_Cleanup() {
mallocRPtrMap.clear(); mallocRPtrMap.clear();
absolutePtr = nullptr; absolutePtr = nullptr;
absoluteSpaceFlag = 0; absoluteSpaceFlag = 0;
stairsAllocSize = 0x1D4790 - 0x26960 - 0x2200 - (0x55 * 0x60) - (3 * (48 * 16) / 2) - (4 * (32 * 32 * 4)) - 0x1000 - (20 * sizeof(MtxF));
} }
u8 StairsArena_IsInitalized() { u8 StairsArena_IsInitalized() {

View File

@ -3,14 +3,14 @@
#include "global.h" #include "global.h"
// This value is based on the ZeldaArena size created on play init with default GameAlloc size
#define STAIRS_ALLOC_SIZE 560064
#define STAIRS_ACTOROVL_ABSOLUTE_SPACE_SIZE 0x27A0 #define STAIRS_ACTOROVL_ABSOLUTE_SPACE_SIZE 0x27A0
#define STAIRS_ACTOROVL_ALLOC_ABSOLUTE (1 << 0) #define STAIRS_ACTOROVL_ALLOC_ABSOLUTE (1 << 0)
#define STAIRS_ACTOROVL_ALLOC_PERSISTENT (1 << 1) #define STAIRS_ACTOROVL_ALLOC_PERSISTENT (1 << 1)
Arena sStairsArena; // This value is based on the ZeldaArena size created on play init with default GameAlloc size
// #define STAIRS_ALLOC_SIZE 560064
// #define STAIRS_ALLOC_SIZE 0x88BC0
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -24,6 +24,9 @@ s32 Stairs_GetAbsoluteSpace();
s32 Stairs_UnregisterAbsoluteSpace(); s32 Stairs_UnregisterAbsoluteSpace();
size_t Stairs_GetOverlaySize(u16 id); size_t Stairs_GetOverlaySize(u16 id);
size_t Stairs_GetSize();
s32 Stairs_DecreaseSize(size_t size);
void* StairsArena_Malloc(size_t size); void* StairsArena_Malloc(size_t size);
void* StairsArena_MallocR(size_t size); void* StairsArena_MallocR(size_t size);
void* StairsArena_Realloc(void* ptr, size_t newSize); void* StairsArena_Realloc(void* ptr, size_t newSize);

View File

@ -1467,7 +1467,8 @@ extern std::shared_ptr<ValueViewerWindow> mValueViewerWindow;
void DrawDeveloperToolsMenu() { void DrawDeveloperToolsMenu() {
if (ImGui::BeginMenu("Developer Tools")) { if (ImGui::BeginMenu("Developer Tools")) {
ImGui::BeginDisabled(CVarGetInteger("gDisableChangingSettings", 0)); ImGui::BeginDisabled(CVarGetInteger("gDisableChangingSettings", 0));
UIWidgets::EnhancementCheckbox("Stairs heap display", "gStairsDisplay");
UIWidgets::Tooltip("Visualises the stair heap");
UIWidgets::EnhancementCheckbox("OoT Debug Mode", "gDebugEnabled"); UIWidgets::EnhancementCheckbox("OoT Debug Mode", "gDebugEnabled");
UIWidgets::Tooltip("Enables Debug Mode, allowing you to select maps with L + R + Z, noclip with L + D-pad Right, and open the debug menu with L on the pause screen"); UIWidgets::Tooltip("Enables Debug Mode, allowing you to select maps with L + R + Z, noclip with L + D-pad Right, and open the debug menu with L on the pause screen");
if (CVarGetInteger("gDebugEnabled", 0)) { if (CVarGetInteger("gDebugEnabled", 0)) {

View File

@ -4,6 +4,8 @@
#include <soh/OTRGlobals.h> #include <soh/OTRGlobals.h>
#include <assert.h> #include <assert.h>
#include "soh/Enhancements/stairs.h"
#define SS_NULL 0xFFFF #define SS_NULL 0xFFFF
// bccFlags // bccFlags
@ -2453,6 +2455,7 @@ void SSNodeList_Alloc(PlayState* play, SSNodeList* this, s32 tblMax, s32 numPoly
assert(this->tbl != NULL); assert(this->tbl != NULL);
this->polyCheckTbl = GAMESTATE_ALLOC_MC(&play->state, numPolys); this->polyCheckTbl = GAMESTATE_ALLOC_MC(&play->state, numPolys);
Stairs_DecreaseSize(numPolys);
assert(this->polyCheckTbl != NULL); assert(this->polyCheckTbl != NULL);
} }

View File

@ -2,6 +2,8 @@
#include <textures/do_action_static/do_action_static.h> #include <textures/do_action_static/do_action_static.h>
#include <assert.h> #include <assert.h>
#include "soh/Enhancements/stairs.h"
void func_80110990(PlayState* play) { void func_80110990(PlayState* play) {
Map_Destroy(play); Map_Destroy(play);
} }
@ -35,6 +37,7 @@ void func_801109B0(PlayState* play) {
osSyncPrintf("常駐PARAMETERセグメント=%x\n", parameterSize); osSyncPrintf("常駐PARAMETERセグメント=%x\n", parameterSize);
interfaceCtx->parameterSegment = GAMESTATE_ALLOC_MC(&play->state, parameterSize); interfaceCtx->parameterSegment = GAMESTATE_ALLOC_MC(&play->state, parameterSize);
Stairs_DecreaseSize(parameterSize);
osSyncPrintf("parameter->parameterSegment=%x\n", interfaceCtx->parameterSegment); osSyncPrintf("parameter->parameterSegment=%x\n", interfaceCtx->parameterSegment);

View File

@ -478,9 +478,10 @@ void Play_Init(GameState* thisx) {
//play->state.gfxCtx = NULL; //play->state.gfxCtx = NULL;
uintptr_t zAlloc; uintptr_t zAlloc;
uintptr_t stairsAlloc; uintptr_t stairsAlloc;
uintptr_t stairsAllocAligned;
uintptr_t zAllocAligned; uintptr_t zAllocAligned;
uintptr_t stairsAllocAligned;
size_t zAllocSize; size_t zAllocSize;
size_t stairsAllocSize;
Player* player; Player* player;
s32 playerStartCamId; s32 playerStartCamId;
s32 i; s32 i;
@ -672,9 +673,10 @@ void Play_Init(GameState* thisx) {
Flags_UnsetAllEnv(play); Flags_UnsetAllEnv(play);
// Stairs Heap // Stairs Heap
stairsAlloc = GAMESTATE_ALLOC_MC(&play->state, STAIRS_ALLOC_SIZE); stairsAllocSize = Stairs_GetSize();
stairsAlloc = GAMESTATE_ALLOC_MC(&play->state, stairsAllocSize);
stairsAllocAligned = (stairsAlloc + 8) & ~0xF; stairsAllocAligned = (stairsAlloc + 8) & ~0xF;
StairsArena_Init(stairsAllocAligned, STAIRS_ALLOC_SIZE - stairsAllocAligned + stairsAlloc); StairsArena_Init(stairsAllocAligned, stairsAllocSize - stairsAllocAligned + stairsAlloc);
osSyncPrintf("ZELDA ALLOC SIZE=%x\n", THA_GetSize(&play->state.tha)); osSyncPrintf("ZELDA ALLOC SIZE=%x\n", THA_GetSize(&play->state.tha));
zAllocSize = THA_GetSize(&play->state.tha); zAllocSize = THA_GetSize(&play->state.tha);
zAlloc = GAMESTATE_ALLOC_MC(&play->state, zAllocSize); zAlloc = GAMESTATE_ALLOC_MC(&play->state, zAllocSize);
@ -794,6 +796,11 @@ void Play_Update(PlayState* play) {
ZeldaArena_Display(); ZeldaArena_Display();
} }
if (CVarGetInteger("gStairs", 1) && CVarGetInteger("gStairsDisplay", 0)) {
// todo: implement drawing
StairsArena_Display();
}
if ((HREG(80) == 18) && (HREG(81) < 0)) { if ((HREG(80) == 18) && (HREG(81) < 0)) {
HREG(81) = 0; HREG(81) = 0;
osSyncPrintf("object_exchange_rom_address %u\n", gObjectTableSize); osSyncPrintf("object_exchange_rom_address %u\n", gObjectTableSize);

View File

@ -5,6 +5,7 @@
#include "global.h" #include "global.h"
#include "vt.h" #include "vt.h"
#include "soh/Enhancements/randomizer/randomizer_entrance.h" #include "soh/Enhancements/randomizer/randomizer_entrance.h"
#include "soh/Enhancements/stairs.h"
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
@ -564,6 +565,7 @@ u32 func_80096FE8(PlayState* play, RoomContext* roomCtx) {
// "Room buffer size=%08x(%5.1fK)" // "Room buffer size=%08x(%5.1fK)"
osSyncPrintf("部屋バッファサイズ=%08x(%5.1fK)\n", maxRoomSize, maxRoomSize / 1024.0f); osSyncPrintf("部屋バッファサイズ=%08x(%5.1fK)\n", maxRoomSize, maxRoomSize / 1024.0f);
roomCtx->bufPtrs[0] = GAMESTATE_ALLOC_MC(&play->state, maxRoomSize); roomCtx->bufPtrs[0] = GAMESTATE_ALLOC_MC(&play->state, maxRoomSize);
Stairs_DecreaseSize(maxRoomSize);
// "Room buffer initial pointer=%08x" // "Room buffer initial pointer=%08x"
osSyncPrintf("部屋バッファ開始ポインタ=%08x\n", roomCtx->bufPtrs[0]); osSyncPrintf("部屋バッファ開始ポインタ=%08x\n", roomCtx->bufPtrs[0]);
roomCtx->bufPtrs[1] = (void*)((intptr_t)roomCtx->bufPtrs[0] + maxRoomSize); roomCtx->bufPtrs[1] = (void*)((intptr_t)roomCtx->bufPtrs[0] + maxRoomSize);

View File

@ -3,6 +3,8 @@
#include "soh/ActorDB.h" #include "soh/ActorDB.h"
#include <assert.h> #include <assert.h>
#include "soh/Enhancements/stairs.h"
RomFile sNaviMsgFiles[]; RomFile sNaviMsgFiles[];
s32 Object_Spawn(ObjectContext* objectCtx, s16 objectId) { s32 Object_Spawn(ObjectContext* objectCtx, s16 objectId) {
@ -71,6 +73,7 @@ void Object_InitBank(PlayState* play, ObjectContext* objectCtx) {
objectCtx->spaceStart = objectCtx->status[0].segment = objectCtx->spaceStart = objectCtx->status[0].segment =
GAMESTATE_ALLOC_MC(&play->state, spaceSize); GAMESTATE_ALLOC_MC(&play->state, spaceSize);
Stairs_DecreaseSize(spaceSize);
objectCtx->spaceEnd = (void*)((uintptr_t)objectCtx->spaceStart + spaceSize); objectCtx->spaceEnd = (void*)((uintptr_t)objectCtx->spaceStart + spaceSize);
objectCtx->mainKeepIndex = Object_Spawn(objectCtx, OBJECT_GAMEPLAY_KEEP); objectCtx->mainKeepIndex = Object_Spawn(objectCtx, OBJECT_GAMEPLAY_KEEP);

View File

@ -71,6 +71,8 @@
#include "assets/textures/skyboxes/vr_holy1_static.h" #include "assets/textures/skyboxes/vr_holy1_static.h"
#include "assets/textures/skyboxes/vr_holy1_pal_static.h" #include "assets/textures/skyboxes/vr_holy1_pal_static.h"
#include "soh/Enhancements/stairs.h"
u32 D_8012AC90[4] = { u32 D_8012AC90[4] = {
0x00000000, 0x00000000,
@ -606,6 +608,13 @@ void Skybox_Setup(PlayState* play, SkyboxContext* skyboxCtx, s16 skyboxId) {
uintptr_t start; uintptr_t start;
s32 phi_v1; s32 phi_v1;
// todo: figure out correct 'size' rather than 0x10000 (which is far too large)
if (skyboxId == SKYBOX_NORMAL_SKY || skyboxId == SKYBOX_OVERCAST_SUNSET || skyboxId == SKYBOX_CUTSCENE_MAP) {
// Stairs_DecreaseSize(0x10000 * 4);
} else {
// Stairs_DecreaseSize(0x10000 * 2);
}
switch (skyboxId) switch (skyboxId)
{ {
case SKYBOX_NORMAL_SKY: case SKYBOX_NORMAL_SKY:
@ -968,23 +977,28 @@ void Skybox_Init(GameState* state, SkyboxContext* skyboxCtx, s16 skyboxId) {
if (skyboxCtx->unk_140 != 0) { if (skyboxCtx->unk_140 != 0) {
skyboxCtx->dListBuf = GAMESTATE_ALLOC_MC(state, 8 * 150 * sizeof(Gfx)); skyboxCtx->dListBuf = GAMESTATE_ALLOC_MC(state, 8 * 150 * sizeof(Gfx));
assert(skyboxCtx->dListBuf != NULL); assert(skyboxCtx->dListBuf != NULL);
Stairs_DecreaseSize(8 * 150 * sizeof(Gfx));
skyboxCtx->roomVtx = GAMESTATE_ALLOC_MC(state, 256 * sizeof(Vtx)); skyboxCtx->roomVtx = GAMESTATE_ALLOC_MC(state, 256 * sizeof(Vtx));
assert(skyboxCtx->roomVtx != NULL); assert(skyboxCtx->roomVtx != NULL);
Stairs_DecreaseSize(256 * sizeof(Vtx));
func_800AEFC8(skyboxCtx, skyboxId); func_800AEFC8(skyboxCtx, skyboxId);
} else { } else {
skyboxCtx->dListBuf = GAMESTATE_ALLOC_MC(state, 12 * 150 * sizeof(Gfx)); skyboxCtx->dListBuf = GAMESTATE_ALLOC_MC(state, 12 * 150 * sizeof(Gfx));
assert(skyboxCtx->dListBuf != NULL); assert(skyboxCtx->dListBuf != NULL);
Stairs_DecreaseSize(12 * 150 * sizeof(Gfx));
if (skyboxId == SKYBOX_CUTSCENE_MAP) { if (skyboxId == SKYBOX_CUTSCENE_MAP) {
skyboxCtx->roomVtx = GAMESTATE_ALLOC_MC(state, 192 * sizeof(Vtx)); skyboxCtx->roomVtx = GAMESTATE_ALLOC_MC(state, 192 * sizeof(Vtx));
assert(skyboxCtx->roomVtx != NULL); assert(skyboxCtx->roomVtx != NULL);
Stairs_DecreaseSize(192 * sizeof(Gfx));
func_800AF178(skyboxCtx, 6); func_800AF178(skyboxCtx, 6);
} else { } else {
skyboxCtx->roomVtx = GAMESTATE_ALLOC_MC(state, 160 * sizeof(Vtx)); skyboxCtx->roomVtx = GAMESTATE_ALLOC_MC(state, 160 * sizeof(Vtx));
assert(skyboxCtx->roomVtx != NULL); assert(skyboxCtx->roomVtx != NULL);
Stairs_DecreaseSize(160 * sizeof(Vtx));
func_800AF178(skyboxCtx, 5); func_800AF178(skyboxCtx, 5);
} }