diff --git a/config/sym_ovl_export.us.txt b/config/sym_ovl_export.us.txt index ddf91d64..2e1a246b 100644 --- a/config/sym_ovl_export.us.txt +++ b/config/sym_ovl_export.us.txt @@ -1886,7 +1886,7 @@ func_801D3260 = 0x801d3260; g_MateriaPriority = 0x801d3834; g_MateriaStealLoot = 0x801d3f60; WmSetRenderBuffers = 0x800a0b48; -func_800A0BE4 = 0x800a0be4; +AllocPrims = 0x800a0be4; WmLoadTxzFile = 0x800a0c54; WmLoadTxzDataAndInit = 0x800a0d2c; func_800A12AC = 0x800a12ac; @@ -1907,7 +1907,7 @@ func_800A21A4 = 0x800a21a4; WmHandleButtons = 0x800a21b4; func_800A31C0 = 0x800a31c0; func_800A31E8 = 0x800a31e8; -func_800A31F8 = 0x800a31f8; +UpdateFogRanges = 0x800a31f8; func_800A32F4 = 0x800a32f4; func_800A3304 = 0x800a3304; func_800A368C = 0x800a368c; @@ -1925,9 +1925,9 @@ WmResetGame = 0x800a4008; func_800A4080 = 0x800a4080; func_800A40B8 = 0x800a40b8; func_800A40F0 = 0x800a40f0; -func_800A4138 = 0x800a4138; +InitSpritePrims = 0x800a4138; func_800A41E8 = 0x800a41e8; -func_800A4268 = 0x800a4268; +UpdateFadeOverlay = 0x800a4268; func_800A4494 = 0x800a4494; func_800A44A4 = 0x800a44a4; func_800A44B4 = 0x800a44b4; @@ -1941,27 +1941,27 @@ WmInitLoadMapFileStruct = 0x800a4ddc; WmGetBlockIdByXZForPlanet = 0x800a4f08; func_800A4F78 = 0x800a4f78; func_800A5208 = 0x800a5208; -func_800A52A4 = 0x800a52a4; -func_800A5348 = 0x800a5348; +AllocRegionNode = 0x800a52a4; +FreeListNode = 0x800a5348; WmLoadClosestMapFileBlock = 0x800a53a8; WmStartLoadingMapFileBlock = 0x800a54f0; -func_800A57C8 = 0x800a57c8; +UpdateRegionLoad = 0x800a57c8; WmMapLoadFinishedCallback = 0x800a5924; WmGetNumberOfMapToLoad = 0x800a5970; -func_800A59A0 = 0x800a59a0; +InitChunkNodePool = 0x800a59a0; WmGetElementWithBlockIdAndSetItFirst = 0x800a5a20; -func_800A5A94 = 0x800a5a94; +IsRegionLoading = 0x800a5a94; func_800A5AD8 = 0x800a5ad8; -func_800A5B88 = 0x800a5b88; +RegisterChunksForNode = 0x800a5b88; func_800A5C08 = 0x800a5c08; func_800A5D00 = 0x800a5d00; func_800A5E28 = 0x800a5e28; -func_800A5FB4 = 0x800a5fb4; -func_800A60D8 = 0x800a60d8; +ExpireChunks = 0x800a5fb4; +InitChunkPool = 0x800a60d8; func_800A6168 = 0x800a6168; func_800A63FC = 0x800a63fc; func_800A64AC = 0x800a64ac; -func_800A67A8 = 0x800a67a8; +AllocChunk = 0x800a67a8; WmExtractLoopCoordsTopBottomParts = 0x800a6884; WmLoopCoordsAroundWorld = 0x800a692c; func_800A6994 = 0x800a6994; @@ -1971,12 +1971,12 @@ func_800A6C00 = 0x800a6c00; func_800A6C3C = 0x800a6c3c; func_800A6FC0 = 0x800a6fc0; func_800A71E8 = 0x800a71e8; -func_800A7EA4 = 0x800a7ea4; +InitWorldState = 0x800a7ea4; WmAbortMapLoadingWrapper = 0x800a7f18; WmAbortMapLoading = 0x800a7f38; func_800A806C = 0x800a806c; func_800A82F0 = 0x800a82f0; -func_800A8300 = 0x800a8300; +IsChunkLoaded = 0x800a8300; func_800A835C = 0x800a835c; func_800A86C4 = 0x800a86c4; func_800A886C = 0x800a886c; @@ -2019,7 +2019,7 @@ func_800A94F4 = 0x800a94f4; func_800A9520 = 0x800a9520; func_800A9678 = 0x800a9678; func_800A96A4 = 0x800a96a4; -func_800A96D0 = 0x800a96d0; +BlendActorFacing = 0x800a96d0; func_800A97A8 = 0x800a97a8; WmGetPcEntityTotalRot = 0x800a97e4; func_800A9820 = 0x800a9820; @@ -2051,7 +2051,7 @@ func_800AA1B8 = 0x800aa1b8; func_800AA238 = 0x800aa238; func_800AA2B8 = 0x800aa2b8; func_800AA304 = 0x800aa304; -func_800AA580 = 0x800aa580; +FindCollidingActor = 0x800aa580; func_800AA640 = 0x800aa640; func_800AA684 = 0x800aa684; func_800AA6A4 = 0x800aa6a4; @@ -2081,9 +2081,9 @@ WmScriptOpcode200Handle = 0x800ac484; WmScriptOpcode300Handle = 0x800ac700; WmScriptRunOne = 0x800ad63c; WmScriptRunAll = 0x800ad788; -func_800AD804 = 0x800ad804; +UpdateSurfaceEffect = 0x800ad804; WmScriptIsAnyScriptRuns = 0x800ad928; -func_800AD970 = 0x800ad970; +SaveActorState = 0x800ad970; func_800ADA08 = 0x800ada08; WmRestoreEntityPosAndDirFromSavemap = 0x800ada64; func_800ADB30 = 0x800adb30; @@ -2133,21 +2133,21 @@ func_800B075C = 0x800b075c; func_800B0794 = 0x800b0794; func_800B0810 = 0x800b0810; func_800B0BF4 = 0x800b0bf4; -func_800B0D98 = 0x800b0d98; +UpdateZolomGroundHeight = 0x800b0d98; func_800B0E84 = 0x800b0e84; func_800B104C = 0x800b104c; -func_800B10AC = 0x800b10ac; +RegisterChunk = 0x800b10ac; func_800B11C4 = 0x800b11c4; func_800B1650 = 0x800b1650; func_800B190C = 0x800b190c; func_800B1C80 = 0x800b1c80; -func_800B21E4 = 0x800b21e4; +SetCurrentTriangle = 0x800b21e4; func_800B2304 = 0x800b2304; -func_800B2638 = 0x800b2638; +GetTriangleCenter = 0x800b2638; func_800B271C = 0x800b271c; func_800B28CC = 0x800b28cc; func_800B29CC = 0x800b29cc; -func_800B2E90 = 0x800b2e90; +UpdateWorldMode = 0x800b2e90; func_800B2FA4 = 0x800b2fa4; func_800B2FD0 = 0x800b2fd0; func_800B3018 = 0x800b3018; @@ -2159,13 +2159,13 @@ func_800B338C = 0x800b338c; func_800B3418 = 0x800b3418; func_800B37E0 = 0x800b37e0; func_800B3828 = 0x800b3828; -func_800B392C = 0x800b392c; +InitEffectPool = 0x800b392c; func_800B39B4 = 0x800b39b4; func_800B3C40 = 0x800b3c40; func_800B40B4 = 0x800b40b4; func_800B4244 = 0x800b4244; func_800B45DC = 0x800b45dc; -func_800B5274 = 0x800b5274; +ResetEffectState = 0x800b5274; func_800B5314 = 0x800b5314; func_800B579C = 0x800b579c; func_800B57C0 = 0x800b57c0; @@ -2177,20 +2177,20 @@ WmSetCalculateAllPartsLighting = 0x800b5dd8; WmUpdateModelByAnimationFrame = 0x800b5e28; func_800B624C = 0x800b624c; func_800B6348 = 0x800b6348; -func_800B63F0 = 0x800b63f0; +PlayMusicTrack = 0x800b63f0; func_800B64A0 = 0x800b64a0; func_800B64D8 = 0x800b64d8; func_800B650C = 0x800b650c; WmSetMusicVolume = 0x800b6570; func_800B65A4 = 0x800b65a4; -func_800B65E0 = 0x800b65e0; +ToggleAmbientSound = 0x800b65e0; WmInitModelVariablesAndArray = 0x800b667c; WmCalculateBonesAndLighting = 0x800b6724; WmLoadPcCharModelFile = 0x800b69a4; WmLoadPcCharModelIntoMemory = 0x800b6a4c; WmPcCharModelLoadFileCallback = 0x800b6aec; func_800B6B28 = 0x800b6b28; -func_800B6C84 = 0x800b6c84; +StartStreamRead = 0x800b6c84; func_800B6D10 = 0x800b6d10; WmPackModelLoadFileCallback = 0x800b6dcc; func_800B6E08 = 0x800b6e08; @@ -2202,7 +2202,7 @@ func_800B717C = 0x800b717c; func_800B7200 = 0x800b7200; func_800B7228 = 0x800b7228; func_800B7480 = 0x800b7480; -func_800B7620 = 0x800b7620; +GetSavedParams = 0x800b7620; func_800B76A8 = 0x800b76a8; WmSetFieldToLoad = 0x800b7714; func_800B77A8 = 0x800b77a8; @@ -2214,7 +2214,7 @@ func_800B786C = 0x800b786c; func_800B787C = 0x800b787c; WmGetPcCharModelIdFromParty = 0x800b79b8; func_800B7A40 = 0x800b7a40; -func_800B7AC0 = 0x800b7ac0; +CopyAreaName = 0x800b7ac0; func_800B7B1C = 0x800b7b1c; func_800B7B3C = 0x800b7b3c; func_800B7B54 = 0x800b7b54; diff --git a/config/symbols.world.txt b/config/symbols.world.txt index 3808386d..523d744f 100644 --- a/config/symbols.world.txt +++ b/config/symbols.world.txt @@ -1,5 +1,6 @@ WmSetRenderBuffers = 0x800A0B48; WmGetCurrRenderBufferId = 0x800A0BD4; +AllocPrims = 0x800A0BE4; WmLoadTxzFile = 0x800A0C54; WmLoadTxzDataAndInit = 0x800A0D2C; WmPrepareForRender = 0x800A1370; @@ -13,21 +14,35 @@ WmGetWmId = 0x800A1DE0; WmSetTranslationVectorInScreenSpace = 0x800A1FAC; WmSetCamView = 0x800A2088; WmHandleButtons = 0x800A21B4; +UpdateFogRanges = 0x800A31F8; WmSubmarineFloatToPlanet = 0x800A3DFC; WmSubmarineSubmergeUnderwater = 0x800A3E4C; WmResetGame = 0x800A4008; +InitSpritePrims = 0x800A4138; +UpdateFadeOverlay = 0x800A4268; WmMain = 0x800A460C; WmInitLoadMapFileStruct = 0x800A4DDC; WmGetBlockIdByXZForPlanet = 0x800A4F08; +AllocRegionNode = 0x800A52A4; +FreeListNode = 0x800A5348; WmLoadClosestMapFileBlock = 0x800A53A8; WmStartLoadingMapFileBlock = 0x800A54F0; +UpdateRegionLoad = 0x800A57C8; WmMapLoadFinishedCallback = 0x800A5924; WmGetNumberOfMapToLoad = 0x800A5970; +InitChunkNodePool = 0x800A59A0; WmGetElementWithBlockIdAndSetItFirst = 0x800A5A20; +IsRegionLoading = 0x800A5A94; +RegisterChunksForNode = 0x800A5B88; +ExpireChunks = 0x800A5FB4; +InitChunkPool = 0x800A60D8; +AllocChunk = 0x800A67A8; WmExtractLoopCoordsTopBottomParts = 0x800A6884; WmLoopCoordsAroundWorld = 0x800A692C; +InitWorldState = 0x800A7EA4; WmAbortMapLoadingWrapper = 0x800A7F18; WmAbortMapLoading = 0x800A7F38; +IsChunkLoaded = 0x800A8300; WmSetWorldProgress = 0x800A8888; WmInitAllEntityStructs = 0x800A891C; WmInsertInEntityStructList = 0x800A8A1C; @@ -46,6 +61,7 @@ WmGetModelIdFromPcEntity = 0x800A9174; WmIsPcEntityModelInMask = 0x800A91A4; WmInitActiveEntityStruct = 0x800A9334; WmSetActiveEntityDirectionAndRot = 0x800A9480; +BlendActorFacing = 0x800A96D0; WmGetPcEntityTotalRot = 0x800A97E4; WmIsPcEntityPosNeedRecalculation = 0x800A98E4; WmGetPcEntityOriginalY = 0x800A9910; @@ -56,6 +72,7 @@ WmGetPosFromActiveEntity = 0x800AA098; WmGetPosFromPcEntity = 0x800AA0E0; WmGetPos2FromActiveEntity = 0x800AA128; WmGetPos2FromPcEntity = 0x800AA170; +FindCollidingActor = 0x800AA580; WmMoveActiveEntity = 0x800AA7DC; WmGetBuggyMoveAnimationId = 0x800AAA00; WmPrepareEntities = 0x800AB4F4; @@ -70,7 +87,9 @@ WmScriptOpcode200Handle = 0x800AC484; WmScriptOpcode300Handle = 0x800AC700; WmScriptRunOne = 0x800AD63C; WmScriptRunAll = 0x800AD788; +UpdateSurfaceEffect = 0x800AD804; WmScriptIsAnyScriptRuns = 0x800AD928; +SaveActorState = 0x800AD970; WmRestoreEntityPosAndDirFromSavemap = 0x800ADA64; WmAddMutexPriority = 0x800ADC80; WmRemoveMutexPriority = 0x800ADD4C; @@ -99,22 +118,34 @@ WmFadeInSnow = 0x800B017C; WmFadeOutSnow = 0x800B01C4; WmFadeStartSnow = 0x800B0200; WmFadeIsStopped = 0x800B0240; +UpdateZolomGroundHeight = 0x800B0D98; +RegisterChunk = 0x800B10AC; +SetCurrentTriangle = 0x800B21E4; +GetTriangleCenter = 0x800B2638; +UpdateWorldMode = 0x800B2E90; WmSnowReset = 0x800B3044; WmSnowUpdate = 0x800B307C; +InitEffectPool = 0x800B392C; +ResetEffectState = 0x800B5274; WmCreateShadowPacket = 0x800B58F8; WmSetCalculateAllPartsLighting = 0x800B5DD8; WmUpdateModelByAnimationFrame = 0x800B5E28; +PlayMusicTrack = 0x800B63F0; WmSetMusicVolume = 0x800B6570; +ToggleAmbientSound = 0x800B65E0; WmInitModelVariablesAndArray = 0x800B667C; WmCalculateBonesAndLighting = 0x800B6724; WmLoadPcCharModelFile = 0x800B69A4; WmLoadPcCharModelIntoMemory = 0x800B6A4C; WmPcCharModelLoadFileCallback = 0x800B6AEC; +StartStreamRead = 0x800B6C84; WmPackModelLoadFileCallback = 0x800B6DCC; WmGetModelDataByModelId = 0x800B6EFC; WmAbortModelLoading = 0x800B7134; +GetSavedParams = 0x800B7620; WmSetFieldToLoad = 0x800B7714; WmGetPcCharModelIdFromParty = 0x800B79B8; +CopyAreaName = 0x800B7AC0; WmDialogsInit = 0x800B8488; WmDialogSetMessageToShowForId0 = 0x800B84D8; WmDialogSetAskToShowForId0 = 0x800B851C; @@ -178,3 +209,6 @@ WmUpdatePacketForModelPartWithMatrixes = 0x800C4FB4; WmUpdateModelLighting = 0x800C5CD4; WmUpdatePartLighting = 0x800C6104; WmGetModelTotalRenderPacketSize = 0x800C6598; +D_800C6768 = 0x800C6768; +D_800C676C = 0x800C676C; +D_8010B434 = 0x8010B434; // size:0x24 diff --git a/src/world/world.c b/src/world/world.c index 5807b752..718c6df7 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -7,7 +7,7 @@ void WmGetPosFromPcEntity(VECTOR* arg0); void WmRestoreEntityPosAndDirFromSavemap(WorldActor*); s32 func_800ADFC0(void); static s32 func_800B0800(void); -void WmCreateShadowPacket(u8*, RECT*); +void WmCreateShadowPacket(POLY_FT4*, RECT*); static s32 func_800B716C(void); static s32 func_800B7B2C(void); s32 func_800B7B3C(void); @@ -54,7 +54,21 @@ void WmSetRenderBuffers(void) { static s32 WmGetCurrRenderBufferId(void) { return D_800D05E8; } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A0BE4); +u32* AllocPrims(s32 arg0) { + u32* cur; + u32* next; + u32* ret; + + cur = D_800D05E0; + next = (u32*)((arg0 * 0x28) + (s32)cur); + if (next < (u32*)((u8*)D_800D05DC + 0x20800)) { + D_800D05E0 = next; + ret = cur; + } else { + func_800A0B40(1); + } + return ret; +} INCLUDE_ASM("asm/us/world/nonmatchings/world", WmLoadTxzFile); @@ -125,7 +139,20 @@ static s32 WmGetWmId(void) { return D_800E5634; } INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A1DF0); -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmSetTranslationVectorInScreenSpace); +void WmSetTranslationVectorInScreenSpace(SVECTOR* arg0) { + MATRIX m; + SVECTOR v; + VECTOR out; + int flag; + + v = *arg0; + v.vy = -D_80116508; + SetRotMatrix(&D_800E5698); + SetTransMatrix(&D_800E56B8); + RotTrans(&v, &out, &flag); + TransMatrix(&m, &out); + SetTransMatrix(&m); +} void func_800A2040(void) { SetRotMatrix(&D_800E5698); @@ -171,7 +198,19 @@ void func_800A31C0(s16 arg0) { D_800E5668 = arg0 - 0x800 + D_800E5608; } s32 func_800A31E8(void) { return !D_800E5628; } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A31F8); +void UpdateFogRanges(void) { + s32 level; + + if (D_800E5650 == 0) { + level = 120 - ((D_800E5660 * 30) >> 8); + } else { + level = 160 - ((D_800E5660 * 70) >> 8); + } + D_800E55F0 = level; + D_800C65EC = 400 - ((D_800E5660 * 200) >> 8); + D_800E5614 = 10000 - ((D_800E5660 * 6000) >> 8); + D_800E5678 = 5000 - ((D_800E5660 * 2500) >> 8); +} s32 func_800A32F4(void) { return D_800E5678; } @@ -296,7 +335,21 @@ s32 func_800A40F0(s16 arg0) { return (s32)D_800BE5F0 + D_800BE5F0[arg0 + 1]; } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A4138); +void InitSpritePrims(void) { + s32 i; + s32 tpage; + + D_800E56F4 = 0; + for (i = 0; i < 2; i++) { + setSprt(&D_800C6648[i]); + if (GetGraphType() == 1 || GetGraphType() == 2) { + tpage = 0x29; + } else { + tpage = 0x19; + } + SetDrawMode((DR_MODE*)((i * 0xC) + (s32)D_800E56DC), 0, 0, tpage, NULL); + } +} void func_800A41E8(s32 arg0) { switch (arg0) { @@ -313,7 +366,34 @@ void func_800A41E8(s32 arg0) { D_800E56F4 = arg0; } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A4268); +void UpdateFadeOverlay(void) { + s32 slot; + s32 vsync; + + slot = WmGetCurrRenderBufferId(); + switch (D_800E56F4) { + case 1: + if (WmFadeIsStopped() != 0) { + D_800E56F4 = 2; + } + break; + case 2: + vsync = VSync(-1); + D_800C6648[slot].v0 = ((vsync >> 2) & 0x10) - 128; + addPrim(D_800BD130, &D_800C6648[slot]); + addPrim(D_800BD130, &D_800E56DC[slot]); + if ((vsync - D_800C84F0) >= 4 && (vsync - D_800C84F0) <= 5) { + D_800E56F4 = 3; + } + D_800C84F0 = vsync; + break; + case 3: + D_800C6648[slot].v0 = 160; + addPrim(D_800BD130, &D_800C6648[slot]); + addPrim(D_800BD130, &D_800E56DC[slot]); + break; + } +} void func_800A4494(s32 arg0) { D_800E561C = arg0; } @@ -386,28 +466,150 @@ INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A4F78); INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A5208); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A52A4); +WorldListNode* AllocRegionNode(void) { + WorldListNode* node; + WorldListNode* prev; + WorldListNode* head; + + if (D_800E5760 != NULL) { + node = D_800E5760; + D_800E5760 = node->next; + } else { + node = D_800E5764; + if (node != NULL) { + prev = NULL; + while (node->next != NULL) { + prev = node; + node = node->next; + } + if (prev != NULL) { + prev->next = NULL; + } else { + node = NULL; + } + } + } + if (node != NULL) { + head = D_800E5768; + D_800E5768 = node; + node->next = head; + } + return node; +} -void func_800A5348(void* arg0, void** arg1) { - void* tmp; +void FreeListNode(WorldListNode* arg0, WorldListNode* arg1) { + WorldListNode* tmp; if (arg1 != NULL) { - *arg1 = *(void**)arg0; + arg1->next = arg0->next; } else { - D_800E5810 = *(s32*)arg0; + D_800E5810 = arg0->next; } WmStartLoadingMapFileBlock(arg0); tmp = D_800E580C; D_800E580C = arg0; - *(void**)arg0 = tmp; + arg0->next = tmp; +} + +void WmLoadClosestMapFileBlock(s16 arg0, s16 arg1) { + WorldListNode* node; + WorldListNode* prev; + WorldListNode* best; + WorldListNode* bestPrev; + s32 bestDist; + s32 dist; + s32 dx; + s32 dz; + s32 row; + s32 col; + s16 idx; + + if (D_800E5814 != 0 || D_800E5810 == NULL) { + return; + } + if (WmAddMutexPriority(0) == 0) { + return; + } + bestPrev = NULL; + best = NULL; + bestDist = 0x7FFF; + node = D_800E5810; + prev = NULL; + while (node != NULL) { + idx = node->unk4; + row = idx / 4; + col = idx - row * 4; + dx = col - arg0; + if (dx <= 0) { + dx = arg0 - col; + } + if (dx >= 0x13) { + dx = 0x24 - dx; + } + dz = row - arg1; + if (dz <= 0) { + dz = arg1 - row; + } + if (dz >= 0xF) { + dz = 0x1C - dz; + } + dist = dx + dz; + if (dist < bestDist) { + bestDist = dist; + best = node; + bestPrev = prev; + } + prev = node; + node = node->next; + } + if (best == NULL) { + func_800A0B40(0x22); + } + FreeListNode(best, bestPrev); } -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmLoadClosestMapFileBlock); - INCLUDE_ASM("asm/us/world/nonmatchings/world", WmStartLoadingMapFileBlock); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A57C8); +void UpdateRegionLoad(void) { + WorldListNode* node; + WorldListNode* prev; + WorldListNode* head; + s32 tick; + + if (D_800E5814 >= D_8011650C * 5) { + SystemCdromReadChain(); + } + if (D_800E5814 < D_8011650C * 5 && D_800E5820 >= 0) { + node = D_800E5768; + prev = NULL; + while (node != NULL) { + if (node == &D_800E5718[D_800E5820]) { + break; + } + prev = node; + node = node->next; + } + if (node == NULL) { + func_800A0B40(0xB); + } + if (prev != NULL) { + prev->next = node->next; + } else { + D_800E5768 = node->next; + } + head = D_800E5764; + D_800E5764 = node; + node->next = head; + RegisterChunksForNode(node); + D_800E5820 = -1; + } + tick = 0; + if (D_800E5814 != 0) { + tick = D_800E5814 < D_8011650C * 5; + } + D_800E5814 -= tick; +} void WmMapLoadFinishedCallback(void) { if (D_800E5820 >= 0) { @@ -432,15 +634,69 @@ s16 WmGetNumberOfMapToLoad(void) { return count; } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A59A0); +void InitChunkNodePool(void) { + s16 i; -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmGetElementWithBlockIdAndSetItFirst); + for (i = 0; i < 0x3F; i++) { + D_800E582C[i].next = &D_800E582C[i + 1]; + } + D_800E582C[i].next = NULL; + D_800E5A30 = D_800E582C; + D_800E5A2C = 0; + D_800E5A34 = 0; +} -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A5A94); +WorldListNode* WmGetElementWithBlockIdAndSetItFirst(s16 arg0) { + WorldListNode* node; + WorldListNode* prev; + WorldListNode* head; + WorldListNode* next; + + node = D_800E5764; + prev = NULL; + while (node != NULL) { + if (node->unk4 == arg0) { + break; + } + prev = node; + node = node->next; + } + if (node != NULL && prev != NULL) { + next = node->next; + head = D_800E5764; + D_800E5764 = node; + prev->next = next; + node->next = head; + } + return node; +} + +s32 IsRegionLoading(s16 arg0) { + WorldListNode* node; + + node = D_800E5768; + while (node != NULL) { + if (node->unk4 == arg0) { + break; + } + node = node->next; + } + return node != NULL; +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A5AD8); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A5B88); +void RegisterChunksForNode(WorldListNode* arg0) { + WorldChunkHeader* c; + + c = D_80109D40; + while (c != NULL) { + if ((((c->z >> 2) * 9) + (c->x >> 2)) == arg0->unk4) { + func_800A5AD8(c); + } + c = c->next; + } +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A5C08); @@ -448,9 +704,75 @@ INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A5D00); INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A5E28); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A5FB4); +s32 ExpireChunks(void) { + WorldChunkHeader* chunk; + WorldChunkHeader* prev; + WorldChunkNode* node; + WorldChunkNode* nodePrev; + WorldChunkHeader* freeChunk; + WorldChunkNode* freeNode; + s32 live; + u16 age; + + live = 0; + chunk = D_80109D40; + prev = NULL; + while (chunk != NULL) { + age = chunk->numVerts; + chunk->numVerts = age + 1; + if ((s16)age >= 0x96) { + if (prev != NULL) { + prev->next = chunk->next; + } else { + D_80109D40 = chunk->next; + } + node = D_800E5A2C; + freeChunk = D_80109D38; + nodePrev = NULL; + D_80109D38 = chunk; + chunk->next = freeChunk; + while (node != NULL) { + if (node->chunk == chunk) { + break; + } + nodePrev = node; + node = node->next; + } + if (node != NULL) { + if (nodePrev != NULL) { + nodePrev->next = node->next; + } else { + D_800E5A2C = node->next; + } + freeNode = D_800E5A30; + D_800E5A30 = node; + node->next = freeNode; + } + if (prev != NULL) { + chunk = prev->next; + } else { + chunk = D_80109D40; + } + } else { + prev = chunk; + chunk = chunk->next; + live++; + } + } + return live; +} + +void InitChunkPool(void) { + s16 i; -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A60D8); + for (i = 0; i < 0x1F; i++) { + D_80109A38[i].next = &D_80109A38[i + 1]; + } + D_80109A38[i].next = NULL; + D_80109D38 = D_80109A38; + D_80109D40 = NULL; + D_80109D3C = 0; +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A6168); @@ -458,7 +780,37 @@ INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A63FC); INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A64AC); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A67A8); +WorldChunkHeader* AllocChunk(void) { + WorldChunkHeader* chunk; + WorldChunkHeader* prev; + WorldChunkHeader* head; + + chunk = NULL; + if (D_80109D38 != NULL) { + chunk = D_80109D38; + D_80109D38 = chunk->next; + } else if (D_80109D3C != NULL) { + chunk = D_80109D3C; + prev = NULL; + while (chunk->next != NULL) { + prev = chunk; + chunk = chunk->next; + } + if (prev != NULL) { + prev->next = NULL; + } else { + D_80109D3C = NULL; + } + func_800A9064(chunk->x, chunk->z); + } + if (chunk != NULL) { + head = D_80109D40; + D_80109D40 = chunk; + chunk->numVerts = 0; + chunk->next = head; + } + return chunk; +} void WmExtractLoopCoordsTopBottomParts(VECTOR* arg0, SVECTOR* arg1, s16* arg2, s16* arg3) { if (arg2 != NULL) { @@ -557,11 +909,56 @@ static void func_800A7E8C(s32 arg0) { D_80109D6C = arg0; } static void func_800A7E9C(void) {} -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A7EA4); +void InitWorldState(void) { + WmInitLoadMapFileStruct(); + InitChunkNodePool(); + InitChunkPool(); + D_80109D54 = 0; + D_80109D58 = 0; + D_80109D5C = NULL; + D_80109D60 = NULL; + D_800E5828 = 1; + D_80109D64 = 0; + D_80109D68 = 0; + D_80109D6C = 0; +} void WmAbortMapLoadingWrapper(void) { WmAbortMapLoading(); } -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmAbortMapLoading); +void WmAbortMapLoading(void) { + WorldListNode* node; + WorldListNode* prev; + WorldListNode* head; + + D_800E5828 = 0; + if (D_800E5820 >= 0) { + if (D_800E5814 >= D_8011650C * 5) { + prev = NULL; + SystemCdromAbortLoading(); + node = D_800E5768; + while (node != NULL) { + if (node == &D_800E5718[D_800E5820]) { + break; + } + prev = node; + node = node->next; + } + if (node == NULL) { + func_800A0B40(0xD); + } + if (prev != NULL) { + prev->next = node->next; + } else { + D_800E5768 = node->next; + } + head = D_800E5760; + D_800E5760 = node; + D_800E5814 = 0; + D_800E5820 = -1; + node->next = head; + } + } +} static void func_800A8048(void) { D_800E5828 = 1; } @@ -573,7 +970,18 @@ static void func_800A82DC(void) { D_80109D54 = 1; } s32 func_800A82F0(void) { return D_80109D58; } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A8300); +s32 IsChunkLoaded(s16 arg0, s16 arg1) { + WorldChunkHeader* chunk; + + chunk = D_80109D3C; + while (chunk != NULL) { + if (chunk->x == arg0 && chunk->z == arg1) { + break; + } + chunk = chunk->next; + } + return chunk != NULL; +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A835C); @@ -926,7 +1334,27 @@ void func_800A9678(s16 arg0) { func_800A9520(D_8010AD3C, arg0); } void func_800A96A4(s16 arg0) { func_800A9520(D_8010AD40, arg0); } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800A96D0); +void BlendActorFacing(s16 arg0) { + WorldActor* actor; + u32 blend; + + if (D_8010AD3C == NULL) { + return; + } + actor = D_8010AD3C; + if (D_8011650C == 1) { + if (actor->flags1 & 1) { + blend = (u32)(((s16)actor->unk3E * 15) + arg0) >> 4; + } else { + blend = (u32)(((s16)actor->unk3E * 3) + arg0) >> 2; + } + } else if (actor->flags1 & 1) { + blend = (u32)(((s16)actor->unk3E * 7) + arg0) >> 3; + } else { + blend = (u32)((s16)actor->unk3E + arg0) >> 1; + } + actor->unk3E = blend; +} s16 func_800A97A8(void) { return D_8010AD3C == NULL ? 0 : D_8010AD3C->unk3C + D_8010AD3C->unk3E; } @@ -1108,13 +1536,35 @@ static void func_800AA2E4(s8 arg0) { INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800AA304); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800AA580); +WorldActor* FindCollidingActor(WorldActor* arg0) { + WorldActor* hit; + s32 rc; + + rc = 0; + hit = NULL; + if (D_8010AD3C != NULL) { + if (D_8010AD3C->actorType != 0xD || WmGetWmId() != 0) { + hit = D_8010AD38; + while (hit != NULL) { + rc = func_800AA304(D_8010AD3C, hit); + if (rc != 0) { + break; + } + hit = hit->next; + } + if (hit != NULL) { + D_8010AD3C->collide = hit; + } + } + } + return rc < 2 ? hit : NULL; +} s32 func_800AA640(void) { - s32 temp_v0; + WorldActor* temp_v0; - temp_v0 = func_800AA580(D_8010AD3C); - if (temp_v0 != 0) + temp_v0 = FindCollidingActor(D_8010AD3C); + if (temp_v0 != NULL) func_800AA1B8(); return temp_v0; } @@ -1145,7 +1595,7 @@ void func_800AA6D0(WorldChunkHeader* arg0) { } } - func_800B0D98(arg0); + UpdateZolomGroundHeight(arg0); func_800B1C80(arg0); } @@ -1173,7 +1623,42 @@ void func_800AA8D8(s16 arg0, s16 arg1, s16 arg2) { INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800AA8F8); -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmGetBuggyMoveAnimationId); +s32 WmGetBuggyMoveAnimationId(u8* arg0) { + s32 prev; + s32 event; + + prev = D_80109D70; + event = WmGetPcEntityTerrainId(); + switch (D_80109D70) { + case 1: + if (event == 0xB) { + D_80109D70 = 2; + } + break; + case 2: + if (*arg0 >= 6) { + D_80109D70 = 3; + } + break; + case 3: + if (event != 4 && event != 0xB) { + D_80109D70 = 4; + } + break; + case 4: + if (*arg0 >= 6) { + D_80109D70 = 1; + } + break; + default: + D_80109D70 = 1; + break; + } + if (D_80109D70 != prev) { + *arg0 = 0; + } + return D_80109D70; +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800AAB18); @@ -1723,21 +2208,104 @@ void WmScriptRunAll(void) { WmScriptRunOne(D_8010ADE4 = D_8010AD3C = var_s0); } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800AD804); +void UpdateSurfaceEffect(void) { + s32 kind; + + if (D_8010ADEC != 0 || (D_8010AD40->flags1 & 8)) { + return; + } + if (WmIsPcEntityModelInMask(0x2000) != 0) { + if ((D_8010AD40->pos.vy - D_8010AD40->unk42) >= 0x1F4) { + return; + } + } else if (D_8010AD40->flags1 & 0x80) { + return; + } + kind = func_800A9AD0(); + if (kind >= 3) { + if (D_8010ADF0 != kind) { + D_8010ADF0 = kind; + func_800ABA78(kind - 3, 0); + } + if (kind == 7 && WmIsPcEntityModelInMask(0x2000) == 0) { + func_800AA238(); + } + } else { + D_8010ADF0 = 0; + } +} + +s32 WmScriptIsAnyScriptRuns(void) { + WorldActor* a; + s32 flag; + + flag = D_80109DBA != 0; + a = D_8010AD38; + while (a != NULL && flag == 0) { + flag |= a->scriptIdx != 0; + a = a->next; + } + return flag; +} -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmScriptIsAnyScriptRuns); +void SaveActorState(WorldActor* actor) { + u8 type; + u8 slot; + s32* out; -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800AD970); + type = actor->actorType; + slot = D_800C6748[type]; + if (slot < 6) { + out = (s32*)((slot * 8) + D_8010AD50); + out[0] = (actor->altPos.vx & 0x7FFFF) | ((type << 19) & 0xF80000) | ((actor->direction << 20) & 0xFF000000); + out[1] = (actor->altPos.vz & 0x3FFFF) | (actor->altPos.vy << 18); + } +} void func_800ADA08(void) { WorldActor* var_s0; for (var_s0 = D_8010AD38; var_s0 != NULL; var_s0 = var_s0->next) if (!(var_s0->flags1 & 8)) - func_800AD970(var_s0); + SaveActorState(var_s0); } -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmRestoreEntityPosAndDirFromSavemap); +void WmRestoreEntityPosAndDirFromSavemap(WorldActor* arg0) { + s32* p; + s32* end; + s32 t; + s16 f; + s32 type; + + p = (s32*)D_8010AD50; + end = (s32*)(D_8010AD50 + 0x30); + if (p >= end) { + return; + } + type = arg0->actorType; + while (p < end) { + if (((*p >> 19) & 0x1F) == type) { + break; + } + p += 2; + } + if (p < (s32*)(D_8010AD50 + 0x30) && arg0 != NULL) { + t = p[0] & 0x7FFFF; + arg0->altPos.vx = t; + arg0->pos.vx = t; + t = p[1] >> 18; + arg0->altPos.vy = t; + arg0->pos.vy = t; + t = p[1] & 0x3FFFF; + arg0->altPos.vz = t; + arg0->pos.vz = t; + f = (p[0] >> 20) & 0xFF0; + arg0->unk3E = 0; + arg0->direction = f; + arg0->unk3C = f; + arg0->facing = f; + } +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800ADB30); @@ -1745,7 +2313,23 @@ void func_800ADC3C(VECTOR* arg0) { D_8010AE34 = *arg0; } void func_800ADC70(void) { D_8010AE54 = 0; } -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmAddMutexPriority); +s32 WmAddMutexPriority(s16 arg0) { + if ((D_8010AE54 >> arg0) & 1) { + if (!((-1 << (arg0 + 1)) & D_8010AE54)) { + return 1; + } + } + if (D_8010AE54 < (1 << arg0)) { + if (D_8010AE54 == 1) { + WmAbortMapLoading(); + } else if (D_8010AE54 & 4) { + WmAbortModelLoading(); + } + D_8010AE54 |= 1 << arg0; + return 1; + } + return 0; +} void WmRemoveMutexPriority(s16 arg0) { u32 var_v1; @@ -1853,9 +2437,32 @@ s16 WmGetRotFromEntityToEntity(VECTOR* arg0, VECTOR* arg1) { return WmGetRotFromVector(arg1->vx - arg0->vx, arg1->vz - arg0->vz, arg1->vx); } -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmCreateSkyboxOverlayRenderBuffers); +void WmCreateSkyboxOverlayRenderBuffers(void) { + CVECTOR* a; + CVECTOR* b; + POLY_G4* p; + s32 i; -void* WmGetSkyboxOverlayCurrRenderBuffer(void) { return (WmGetCurrRenderBufferId() * 0x24) + &D_800C6770; } + i = 0; + a = &D_800C6768; + b = &D_800C676C; + do { + p = &D_800C6770[i]; + p->r0 = p->r1 = a->r; + p->g0 = p->g1 = a->g; + p->b0 = p->b1 = a->b; + p->r2 = p->r3 = b->r; + p->g2 = p->g3 = b->g; + p->b2 = p->b3 = b->b; + setlen(p, 8); + setcode(p, 0x38); + SetDrawMode((DR_MODE*)((i * 0xC) + (s32)D_8010B068), 0, 1, 0, NULL); + i++; + } while (i < 2); + D_8010B080 = 0; +} + +void* WmGetSkyboxOverlayCurrRenderBuffer(void) { return &D_800C6770[WmGetCurrRenderBufferId()]; } void* WmGetSkyboxOverlayCurrTextureSettingBuffer(void) { return (WmGetCurrRenderBufferId() * 0xC) + D_8010B068; } @@ -1886,7 +2493,25 @@ void func_800AF0B0(void) { WmSetGteColourSettings(); } -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmSetGteColourSettings); +void WmSetGteColourSettings(void) { + MATRIX* m; + s32 mode; + + mode = 2; + if (WmGetWmId() == mode) { + m = &D_800C6828; + } else { + m = &D_800C6808; + } + SetLightMatrix(m); + if (WmGetWmId() == mode) { + SetBackColor(0x20, 0x20, 0x30); + } else { + SetBackColor(0x40, 0x40, 0x40); + } + SetColorMatrix(&D_800C6848); + SetFarColor(0, 0, 0); +} void func_800AF1A8(u32 arg0, s32 arg1) { Unk8010B178* temp_v1; @@ -1964,9 +2589,55 @@ INCLUDE_ASM("asm/us/world/nonmatchings/world", WmFadeInit); INCLUDE_ASM("asm/us/world/nonmatchings/world", WmFadeRender); -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmSetFadeIn); +void WmSetFadeIn(s32 arg0, s32 arg1) { + s32 i; + s32 tpage; + + if (D_8010B488[0] > 0) { + D_8010B47C = -arg0; + for (i = 0; i < 2; i++) { + if (GetGraphType() == 1 || GetGraphType() == 2) { + tpage = 0xA6; + if (arg1 == 1) { + tpage = 0x126; + } + } else { + tpage = 0x36; + if (arg1 == 1) { + tpage = 0x56; + } + } + SetDrawMode(&D_8010B434[i].mode, 0, 1, tpage, NULL); + } + } else { + D_8010B47C = 0; + } +} -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmSetFadeOut); +void WmSetFadeOut(s32 arg0, s32 arg1) { + s32 i; + s32 tpage; + + if (D_8010B488[0] < D_8010B494[0]) { + D_8010B47C = arg0; + for (i = 0; i < 2; i++) { + if (GetGraphType() == 1 || GetGraphType() == 2) { + tpage = 0xA6; + if (arg1 == 1) { + tpage = 0x126; + } + } else { + tpage = 0x36; + if (arg1 == 1) { + tpage = 0x56; + } + } + SetDrawMode(&D_8010B434[i].mode, 0, 1, tpage, NULL); + } + } else { + D_8010B47C = 0; + } +} void WmFadeInSnow(s32 arg0) { (&D_8010B47C)[arg0] = (D_8010B488[arg0] < D_8010B494[arg0]) << 4; } @@ -2028,7 +2699,27 @@ INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B0810); INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B0BF4); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B0D98); +void UpdateZolomGroundHeight(WorldChunkHeader* arg0) { + VECTOR pos; + SVECTOR dir; + s16 chunkX; + s16 chunkZ; + s32 hit; + + if (func_800B0794() == 0) { + return; + } + pos.vx = D_8010C42C->x + 0x34000; + pos.vz = D_8010C42C->z + 0x20000; + WmExtractLoopCoordsTopBottomParts(&pos, &dir, &chunkX, &chunkZ); + if (chunkX == arg0->x && chunkZ == arg0->z) { + hit = func_800A19FC(arg0, &dir, D_8010C80C, &D_8010C42C->z2, 0, NULL, 0x64); + D_8010C800 = hit; + if (hit == 0) { + D_8010C42C->z2 = 0; + } + } +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B0E84); @@ -2046,7 +2737,33 @@ void func_800B104C(void) { D_8010CAF4 = 0; } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B10AC); +void RegisterChunk(WorldChunkHeader* arg0) { + WorldChunkHeader** slot; + WorldTriangle* t; + + if (arg0 == NULL) { + return; + } + slot = D_8010CA24; + while (slot < D_8010CA74) { + if (*slot == arg0) { + break; + } + slot++; + } + if (slot < D_8010CA74) { + return; + } + if (D_8010CA74 >= &D_8010CA24[20]) { + func_800A0B40(0x47); + } + slot = D_8010CA74; + D_8010CA74 = slot + 1; + *slot = arg0; + for (t = arg0->tris; t < arg0->tris + arg0->numTris; t++) { + *((u8*)&t->textureAndLocationAndFlags + 1) &= ~0x40; + } +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B11C4); @@ -2056,13 +2773,56 @@ INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B190C); INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B1C80); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B21E4); +void SetCurrentTriangle(WorldChunkHeader* arg0, WorldTriangle* arg1) { + VECTOR pos; + s32 inside; + s32 zoff; + + if (D_8010CA8C != 0 && D_8010CA8C != 2 && D_8010CA8C != 3) { + return; + } + D_8010CA1C = &D_8010C83C; + D_8010C83C.chunk = arg0; + D_8010C83C.tri = arg1; + D_8010C83C.unk8 = 0; + D_8010CA20 = 0; + D_8010CA78 = 0; + D_8010CA74 = D_8010CA24; + RegisterChunk(arg0); + if (arg1 != NULL) { + *((u8*)&arg1->textureAndLocationAndFlags + 1) |= 0x40; + } + D_800BD144 = 0; + D_8010CA8C = 1; + WmGetPosFromPcEntity(&pos); + inside = 0; + if (pos.vx >= 0x36000 && pos.vx <= 0x3FFFF) { + zoff = pos.vz - 0x1C000; + inside = (u32)zoff <= 0x9FFF; + } + D_8010CAF8 = inside; +} static void func_800B22E4(void) { func_800B190C(); } INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B2304); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B2638); +void GetTriangleCenter(WorldTriangleRef* arg0, VECTOR* arg1) { + WorldTriangle* tri; + WorldChunkHeader* chunk; + SVECTOR* verts; + + if (arg1 == NULL) { + return; + } + tri = arg0->tri; + chunk = arg0->chunk; + verts = chunk->verts; + arg1->vx = ((verts[tri->vert[0]].vx + verts[tri->vert[1]].vx + verts[tri->vert[2]].vx) / 3) + (chunk->x << 13); + arg1->vy = 0; + arg1->vz = + ((verts[tri->vert[0]].vz + verts[tri->vert[1]].vz + verts[tri->vert[2]].vz) / 3) + (arg0->chunk->z << 13); +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B271C); @@ -2100,7 +2860,26 @@ void func_800B28CC(s32 arg0) { INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B29CC); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B2E90); +void UpdateWorldMode(void) { + func_800B22E4(); + if (D_8010CAF4 != 0) { + if (D_8010CA8C == 3) { + D_8010CAF4 = 0; + D_8010CA8C = 0; + func_800A2108(1, 5); + } else if (D_8010CA8C == 2) { + func_800A1D54(1); + func_800A45C4(6000); + func_800A45D4(1500); + func_800ABA18(8); + D_8010CAF4 = 0; + } + } + if (D_8010CAF0 == 3 && (D_8010CA8C == 2 || D_8010CA8C == 3) && D_8010CACC == 0 && D_8010CAD0 == 0) { + func_800B271C(3); + } + func_800B29CC(); +} static void func_800B2F94(s32 arg0) { D_8010CAF0 = arg0; } @@ -2153,7 +2932,31 @@ void func_800B37E0(s32* arg0, s32* arg1) { INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B3828); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B392C); +void InitEffectPool(void) { + s32 off; + s32 next; + s32 i; + + next = (s32)&D_8010D930; + off = 0xD98; + do { + *(s32*)&D_8010CB24[off] = next; + off -= 0x74; + next -= 0x74; + } while (off >= 0); + + i = 4; + D_8010D930 = 0; + D_8010D9A4 = D_8010CB24; + D_8010D9B0 = 0; + D_8010D9AC = 0; + D_8010D9A8 = 0; + D_8010D9B4 = 0; + do { + D_8010D9BA[i] = 0; + i -= 4; + } while (i >= 0); +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B39B4); @@ -2167,7 +2970,22 @@ INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B4244); INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B45DC); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B5274); +void ResetEffectState(void) { + u8* p; + + *(s16*)0x1F800010 = 0; + *(s16*)0x1F800012 = 0x32; + *(s16*)0x1F800014 = 0; + *(s16*)0x1F800020 = 0; + WmGetPosFromPcEntity(0x1F800000); + *(s16*)0x1F80001C = 0; + *(s16*)0x1F80001A = 0; + *(s16*)0x1F800018 = 0; + func_800B39B4(0, 0, 7, 0); + p = &D_800C6A10[D_800C6940 * 0xC]; + p[3] = 0x10; + p[2] = 0x10; +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B5314); @@ -2184,7 +3002,32 @@ void func_800B57C0(s32 arg0) { D_8010D9BA[arg0 * 4] = 0; } INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B57DC); -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmCreateShadowPacket); +void WmCreateShadowPacket(POLY_FT4* prims, RECT* rect) { + s32 i; + s32 tpage; + + if (prims != NULL && rect != NULL) { + i = 0; + do { + setlen(prims, 9); + setcode(prims, 0x2E); + prims->r0 = prims->g0 = prims->b0 = 0x20; + prims->clut = 0x7CC4; + if (GetGraphType() == 1 || GetGraphType() == 2) { + tpage = 0x129; + } else { + tpage = 0x59; + } + prims->tpage = tpage; + prims->u0 = prims->u2 = rect->x; + prims->v0 = prims->v1 = rect->y; + prims->u1 = prims->u3 = rect->x + rect->w; + prims->v2 = prims->v3 = rect->y + rect->h; + prims++; + i++; + } while (i < 2); + } +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B59F4); @@ -2200,9 +3043,31 @@ INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B6348); static void func_800B63E0(s32 arg0) { D_801159DC = arg0; } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B63F0); +void PlayMusicTrack(s32 arg0) { + s16* cmd; + s32 prev; + + if (D_801159DC != 0) { + cmd = D_8009A000; + if (arg0 != 1) { + s16 mode = 0x10; + if (D_801159E0 == 1) { + mode = 0x14; + } + *cmd = mode; + } else { + *cmd = 0x18; + } + D_8009A004[0] = D_801159BC[arg0]; + D_8009A008[0] = 4; + SystemAkaoExecute(); + } + prev = D_801159E0; + D_801159E0 = arg0; + D_80116510 = prev; +} -void func_800B64A0(void) { func_800B63F0(D_801159E0); } +void func_800B64A0(void) { PlayMusicTrack(D_801159E0); } static s32 func_800B64C8(void) { return D_801159E0; } @@ -2227,9 +3092,43 @@ void func_800B65A4(u32 arg0, s32 arg1) { SystemAkaoExecute(); } -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B65E0); +void ToggleAmbientSound(s32 arg0) { + if (D_8010CB20 < arg0) { + D_8009A000[0] = 0x20; + D_8010CB20 = arg0; + D_8009A004[0] = 0x40; + D_8009A008[0] = arg0; + SystemAkaoExecute(); + } else if (arg0 == -D_8010CB20) { + D_8010CB20 = 0; + D_8009A000[0] = 0xF1; + SystemAkaoExecute(); + D_8009A000[0] = 0xBC; + D_8009A004[0] = 0; + SystemAkaoExecute(); + } +} -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmInitModelVariablesAndArray); +void WmInitModelVariablesAndArray(void) { + s32 i; + + for (i = 0; i < 0x2B; i++) { + D_801159E8[i] = -1; + D_80115A14[i] = 0; + } + D_80115A40 = NULL; + D_80115A44 = 0; + D_80115A50 = 0; + D_80115A4C = 0; + D_80115A48 = 0; + D_80115A54 = 0; + D_80115A64 = 0; + D_80115A5C = 0; + D_80115A60 = 0; + D_80115A58 = 0; + D_80115A68 = 0; + D_800C80BC = D_80115A6C; +} INCLUDE_ASM("asm/us/world/nonmatchings/world", WmCalculateBonesAndLighting); @@ -2247,7 +3146,19 @@ void WmPcCharModelLoadFileCallback(void) { INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B6B28); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B6C84); +void StartStreamRead(void) { + if (D_80115A60 != 0) { + return; + } + WmAbortMapLoading(); + D_80115A40 = (u_long*)func_800A86C4(2); + if (WmAddMutexPriority(2) != 0) { + D_80115A60 = 1; + D_80115A50 = 0; + SysCdromStartLoadLzs(D_800C74DC, D_800C74E0, D_80115A40, WmPackModelLoadFileCallback); + SystemCdromReadChain(); + } +} INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B6D10); @@ -2332,7 +3243,27 @@ INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B7228); INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B7480); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B7620); +void GetSavedParams(s32* arg0, s32* arg1, s32* arg2) { + u16* p; + s32 flags; + + if (arg0 != NULL) { + *arg0 = D_8011626C; + } + if (arg1 != NULL) { + *arg1 = D_80116270; + } + if (arg2 != NULL) { + flags = D_80116274; + if (D_80116278 != 0) { + flags |= 0x20000000; + } + *arg2 = flags; + } + p = &D_8009D2A6; + *p |= 0x300; + func_800B7480(); +} void func_800B76A8(void) { u32 var_a0; @@ -2418,7 +3349,24 @@ s32 WmGetPcCharModelIdFromParty(void) { INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B7A40); -INCLUDE_ASM("asm/us/world/nonmatchings/world", func_800B7AC0); +void CopyAreaName(s16 arg0) { + u8* src; + u8* base; + u8* dst; + u8* end; + s32 term; + u8 c; + + src = (u8*)func_800A40F0(arg0); + term = 0xFF; + base = (u8*)D_8009D288; + dst = base + 0x368; + end = base + 0x380; + do { + c = *src++; + *dst++ = c; + } while (c != term && (s32)dst < (s32)end); +} void func_800B7B1C(u8 arg0) { D_8009D684 = arg0; } @@ -2531,7 +3479,13 @@ void WmDialogSetMessageToShowForId0(u8 arg0) { } } -INCLUDE_ASM("asm/us/world/nonmatchings/world", WmDialogSetAskToShowForId0); +void WmDialogSetAskToShowForId0(s32 arg0, s16 arg1, s16 arg2) { + if (g_WindowData[0].state == WSTATE_INIT) { + D_80116288 = arg1; + D_8011628C = arg2; + WmDialogSetAskToShow(0, arg0, D_80116288, D_8011628C, &D_80116290); + } +} static s32 WmDialogIsWindowWithId0Showing(void) { return g_WindowData[0].state != WSTATE_INIT; } @@ -3633,7 +4587,7 @@ static void func_800BBA5C(void) { WmScriptPushToStoreStack(WmGetModelIdFromPcEntity()); if (func_800A929C()) { WmLinkPcToActiveEntity(); - func_800B63F0(2); + PlayMusicTrack(2); return; } WmUnlinkPcLinkedEntityFromAll(); @@ -3643,13 +4597,13 @@ static void func_800BBA5C(void) { case 3: func_800A98A4(1); func_800A368C(1); - func_800B5274(); + ResetEffectState(); if (func_800B64C8() < 6) { - func_800B63F0(func_800B7200() ? 1 : 3); + PlayMusicTrack(func_800B7200() ? 1 : 3); } break; case 6: - func_800B65E0(0x1EC); + ToggleAmbientSound(0x1EC); break; } } @@ -3764,7 +4718,7 @@ void func_800BBD20(s32 arg0) { func_800AA2E4(2); WmSetActiveEntityDirectionAndRot(temp_v0); - func_800B63F0(1); + PlayMusicTrack(1); func_800A2108(0, 6); if (temp_s1 == 4) func_800A82DC(); @@ -3790,14 +4744,14 @@ void func_800BBD20(s32 arg0) { } func_800A9DB4(&sp10); if (func_800A9240() != 0) - func_800B63F0(2); + PlayMusicTrack(2); else - func_800B63F0(1); + PlayMusicTrack(1); if (temp_s1 == 6) - func_800B65E0(-0x1EC); + ToggleAmbientSound(-0x1EC); else if (temp_s1 == 5) - func_800B65E0(-0x1ED); + ToggleAmbientSound(-0x1ED); func_800A6994(&sp10, 1); } diff --git a/src/world/world.h b/src/world/world.h index 122fcb73..29e4b531 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -36,6 +36,17 @@ typedef struct WorldChunkHeader { /* 0x16 */ s16 numVerts; } WorldChunkHeader; // size: 0x18 +typedef struct { + /* 0x0 */ WorldChunkHeader* chunk; + /* 0x4 */ WorldTriangle* tri; + /* 0x8 */ s8 unk8; +} WorldTriangleRef; // size: 0xC + +typedef struct WorldChunkNode { + /* 0x0 */ struct WorldChunkNode* next; + /* 0x4 */ WorldChunkHeader* chunk; +} WorldChunkNode; // size: 0x8 + typedef struct { /* 0x00 */ s16 scriptIdx; /* 0x02 */ u8 waitFrames; @@ -79,8 +90,8 @@ typedef struct WorldActor { } WorldActor; // size: 0xE0 typedef struct { - /* 0x00 */ s16 x; - /* 0x02 */ s16 z; + /* 0x00 */ u16 x; + /* 0x02 */ u16 z; /* 0x04 */ s16 x2; /* 0x06 */ s16 z2; } WorldZolomSegment; // size: 0x8 @@ -127,11 +138,13 @@ typedef struct { } Unk8010AD70; void WmSetRenderBuffers(); -void func_800A19FC(WorldChunkHeader*, SVECTOR*, WorldStoredTriangle*, s16*, s32, s16*, s32); +s32 GetGraphType(void); +s32 func_800A19FC(WorldChunkHeader*, SVECTOR*, WorldStoredTriangle*, s16*, s32, s16*, s32); void func_800A31C0(s16); void func_800A368C(s32); void WmExtractLoopCoordsTopBottomParts(VECTOR*, SVECTOR*, s16*, s16*); void WmLoopCoordsAroundWorld(VECTOR*); +void func_800A5AD8(WorldChunkHeader*); void func_800A6994(VECTOR*, s32); void WmCleanEntityStruct(WorldActor*); void WmUnlinkEntityFromAll(WorldActor*); @@ -151,7 +164,7 @@ s32 WmGetPcEntityTerrainId(void); s32 func_800A9B04(s16, u8); void func_800A9C64(WorldActor*, VECTOR*); s32 func_800AA304(WorldActor*, WorldActor*); -s32 func_800AA580(WorldActor*); +WorldActor* FindCollidingActor(WorldActor*); void func_800AAB18(WorldActor*); void func_800AB398(WorldActor*); void func_800AB48C(WorldActor*); @@ -165,19 +178,27 @@ void WmScriptRunOne(WorldActor*); void func_800AD970(WorldActor*); void WmRemoveMutexPriority(s16); s16 WmGetRotFromVector(s32, s32, s32); -void func_800B0D98(WorldChunkHeader*); +void SaveActorState(WorldActor*); +s32 WmFadeIsStopped(void); +void UpdateZolomGroundHeight(WorldChunkHeader*); +void func_800B271C(s32); +void func_800B29CC(void); +void WmPcCharModelLoadFileCallback(void); +void WmPackModelLoadFileCallback(void); +s32 WmDialogSetAskToShow(u8, u8, u8, u8, s16*); void func_800B1C80(WorldChunkHeader*); -void func_800B5274(); +void ResetEffectState(); void func_800B5C7C(WorldActor*); void func_800B624C(u16, s32); -void func_800B63F0(s32); -void func_800B65E0(s32); +void PlayMusicTrack(s32); +void ToggleAmbientSound(s32); void func_800B6B28(s16); void func_800B6E08(); s32 func_800B7200(); void WmSetFieldToLoad(s32); void func_800B77A8(s32); s32 WmGetPcCharModelIdFromParty(); +void WmScriptSetFirstToStoreStack(s32); static void func_800B7C44(void); s32 func_800B7C7C(); void func_800B7838(); @@ -195,7 +216,9 @@ extern s32 D_800BE1E8[1]; // TODO: size unknown extern s32 D_800C65EC; extern s32 D_800C6628; extern s32 D_800C6638; -extern u8 D_800C6770[1]; // TODO: size unknown +extern CVECTOR D_800C6768; +extern CVECTOR D_800C676C; +extern POLY_G4 D_800C6770[1]; extern s16 D_800C68EE; extern s16 D_800C6902; extern s16 D_800C6916; @@ -222,12 +245,14 @@ extern s32 D_800E5630; // WM earthquake extern s32 D_800E5634; extern s32 D_800E5638; extern s32 D_800E563C; +extern s32 D_800E5614; extern s32 D_800E5644; extern s32 D_800E5648; extern s32 D_800E564C; extern s32 D_800E5650; extern s32 D_800E5654; extern s32 D_800E5658; +extern s32 D_800E5660; extern s32 D_800E5668; extern s32 D_800E566C; extern s32 D_800E5670; @@ -236,6 +261,7 @@ extern s32 D_800E5678; extern MATRIX D_800E5698; extern MATRIX D_800E56B8; extern s16 D_800E56D8; +extern DR_MODE D_800E56DC[]; extern s32 D_800E56F4; extern s32 D_800E56F8; extern s32 D_800E5814; @@ -247,9 +273,11 @@ extern VECTOR D_80109D44; extern s32 D_80109D54; extern s32 D_80109D58; extern s32 D_80109D6C; +extern s32 D_80109D70; extern WorldActor D_80109D74[0x10]; // World map actor heap, TODO: Confirm size extern WorldActor D_80109E54; extern WorldActor* D_8010AD34; +extern s16 D_80109DBA; extern WorldActor* D_8010AD38; extern WorldActor* D_8010AD3C; // Active Actor extern WorldActor* D_8010AD40; // Player Actor @@ -269,6 +297,7 @@ extern Unk8010AD70 D_8010AD70[1]; // todo: size extern Unk8010AD70* D_8010AD90; extern u8* D_8010AD94[4]; extern s32 D_8010ADEC; +extern s16 D_8010ADF0; extern s32 D_8010AE24; extern s32 D_8010AE28; extern s32 D_8010AE2C; @@ -282,17 +311,28 @@ extern s32 D_8010B080; extern s32 D_8010B174; extern Unk8010B178 D_8010B178[1]; // TODO: determine size extern Unk8010B3B8* D_8010B3B8; +typedef struct { + /* 0x00 */ DR_MODE mode; + /* 0x0C */ u8 unk0C[0x18]; +} Unk8010B434; // size:0x24 + +extern Unk8010B434 D_8010B434[2]; extern s32 D_8010B47C; extern WorldZolomSegment D_8010C2AC[0x30]; extern WorldZolomSegment* D_8010C42C; extern s16 D_8010C7F0; +extern s32 D_8010C800; extern s32 D_8010C804; extern s32 D_8010C808; -extern s32 D_8010CA1C; +extern WorldStoredTriangle D_8010C80C[]; +extern WorldTriangleRef D_8010C83C; +extern WorldTriangleRef* D_8010CA1C; extern s32 D_8010CA20; -extern s32 D_8010CA74; +extern WorldChunkHeader* D_8010CA24[20]; +extern WorldChunkHeader** D_8010CA74; extern s32 D_8010CA78; extern s32 D_8010CA8C; +extern s32 D_8010CAF8; extern s32 D_8010CAC0; extern s32 D_8010CAC4; extern s32 D_8010CAC8; @@ -310,8 +350,14 @@ extern s16 D_8010CB10; extern u32 D_8010CB14; extern s32 D_8010CB18; extern s32 D_8010CB1C; +extern s32 D_801159BC[]; extern s32 D_801159DC; extern s32 D_801159E0; +extern u16 D_80116508; +extern s32 D_80116510; +extern s32 D_800C74DC; +extern s32 D_800C74E0; +extern u_long* D_80115A40; extern s32 D_80115A50; extern s32 D_80115A58; extern s32 D_80115A60; @@ -322,6 +368,20 @@ typedef struct WorldListNode { /* 0x4 */ s16 unk4; } WorldListNode; +extern u8 D_800C68E8[]; +extern u8 D_800C68FC[]; +extern u8 D_800C6910[]; +extern WorldChunkHeader D_80109A38[0x20]; +extern WorldChunkHeader* D_80109D38; +extern WorldChunkHeader* D_80109D3C; +extern WorldChunkHeader* D_80109D40; +extern WorldChunkNode D_800E582C[0x40]; +extern WorldChunkNode* D_800E5A2C; +extern WorldChunkNode* D_800E5A30; + +extern WorldListNode D_800E5718[]; +extern WorldListNode* D_800E5760; +extern WorldListNode* D_800E5764; extern WorldListNode* D_800E5768; extern s16 D_800BE5F0[]; extern s32 D_8010B488[]; @@ -337,14 +397,16 @@ extern u8 D_800C752C; extern u8* D_80109D60; extern u8* D_80109D5C; extern u8 D_800BF5F0[]; +extern SPRT D_800C6648[]; +extern s32 D_800C84F0; extern s16 D_8009ABF6; extern s16 D_8009ABF8; extern s16 D_8009ABFA; extern s16 D_8009AC16; extern s16 D_8009AC18; extern u8* D_8009C6DC; -extern s32 D_800E5810; -extern void* D_800E580C; +extern WorldListNode* D_800E5810; +extern WorldListNode* D_800E580C; extern u16 D_80083278[]; extern u16 D_8008327A[]; extern s16 D_80083286[]; @@ -356,6 +418,33 @@ extern s16 D_800832A2[]; extern s32 D_80109D64; extern s32 D_80109D68; extern u8 D_8010D9B8[]; +extern u16 D_8009D2A6; +extern u8 D_800C6748[]; +extern MATRIX D_800C6808; +extern MATRIX D_800C6828; +extern MATRIX D_800C6848; +extern u8 D_800C6940; +extern u8 D_800C6A10[]; +extern s32 D_800C74C4[][2]; +extern u8* D_800C80BC; +extern s32 D_8010AD50; +extern s32 D_8010CB20; +extern u8 D_8010CB24[]; +extern s32 D_8010D930; +extern u8* D_8010D9A4; +extern s32 D_8010D9A8; +extern s32 D_8010D9AC; +extern s32 D_8010D9B0; +extern s32 D_8010D9B4; +extern s32 D_80115A44; +extern s32 D_80115A48; +extern s32 D_80115A4C; +extern s32 D_80115A54; +extern s32 D_80115A5C; +extern u8 D_80115A6C[]; +extern s16 D_80116290; +extern u32 D_8014A608; +extern s32 D_8014A610; extern u8 D_8010D9BA[]; extern s32 D_80116274; extern s16 D_80116288;