1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-12 02:44:54 +00:00

Merge branch 'main' into doc_pause_menu

This commit is contained in:
Dragorn421 2024-02-28 21:05:45 +01:00
commit 77d9a1ec7a
No known key found for this signature in database
GPG key ID: 381AEBAF3D429335
282 changed files with 8441 additions and 7222 deletions

View file

@ -681,6 +681,14 @@ void PreRender_AntiAliasFilter(PreRender* this, s32 x, s32 y) {
(((a2) >= (a1)) ? (((a3) >= (a2)) ? (a2) : (((a1) >= (a3)) ? (a1) : (a3))) \
: (((a2) >= (a3)) ? (a2) : (((a3) >= (a1)) ? (a1) : (a3))))
#if OOT_DEBUG
#define R_HREG_MODE_DEBUG R_HREG_MODE
#else
#define R_HREG_MODE_DEBUG ((void)0, 0)
#endif
#define PRERENDER_DIVOT_CONTROL (R_HREG_MODE_DEBUG == HREG_MODE_PRERENDER ? R_PRERENDER_DIVOT_CONTROL : 0)
/**
* Applies the Video Interface divot filter to an image.
*
@ -696,7 +704,7 @@ void PreRender_AntiAliasFilter(PreRender* this, s32 x, s32 y) {
void PreRender_DivotFilter(PreRender* this) {
s32 x;
s32 y;
s32 pad1;
s32 cvg;
u8* buffR = alloca(this->width);
u8* buffG = alloca(this->width);
u8* buffB = alloca(this->width);
@ -704,14 +712,14 @@ void PreRender_DivotFilter(PreRender* this) {
s32 pxR;
s32 pxG;
s32 pxB;
Color_RGBA16 pxIn;
Color_RGBA16 pxOut;
for (y = 0; y < this->height; y++) {
// The divot filter is applied row-by-row as it only needs to use pixels that are horizontally adjacent
// Decompose each pixel into color channels
for (x = 0; x < this->width; x++) {
Color_RGBA16 pxIn;
pxIn.rgba = this->fbufSave[x + y * this->width];
buffR[x] = pxIn.r;
buffG[x] = pxIn.g;
@ -721,8 +729,7 @@ void PreRender_DivotFilter(PreRender* this) {
// Apply the divot filter itself. For pixels with partial coverage, the filter selects the median value from a
// window of 3 pixels in a horizontal row and uses that as the value for the center pixel.
for (x = 1; x < this->width - 1; x++) {
Color_RGBA16 pxOut;
s32 cvg = this->cvgSave[x + y * this->width];
cvg = this->cvgSave[x + y * this->width];
// Reject pixels with full coverage. The hardware video filter divot circuit checks if all 3 pixels in the
// window have partial coverage, here only the center pixel is checked.
@ -732,11 +739,10 @@ void PreRender_DivotFilter(PreRender* this) {
}
// This condition is checked before entering this function, it will always pass if it runs.
if ((R_HREG_MODE == HREG_MODE_PRERENDER ? R_PRERENDER_DIVOT_CONTROL : 0) != 0) {
if ((R_HREG_MODE == HREG_MODE_PRERENDER ? R_PRERENDER_DIVOT_CONTROL : 0) != 0) {}
if (PRERENDER_DIVOT_CONTROL != 0) {
if (PRERENDER_DIVOT_CONTROL != 0) {}
if ((R_HREG_MODE == HREG_MODE_PRERENDER ? R_PRERENDER_DIVOT_CONTROL : 0) ==
PRERENDER_DIVOT_PARTIAL_CVG_RED) {
if (PRERENDER_DIVOT_CONTROL == PRERENDER_DIVOT_PARTIAL_CVG_RED) {
// Fill the pixel with full red, likely for debugging
pxR = 31;
pxG = 0;
@ -747,8 +753,7 @@ void PreRender_DivotFilter(PreRender* this) {
u8* windowG = &buffG[x - 1];
u8* windowB = &buffB[x - 1];
if ((R_HREG_MODE == HREG_MODE_PRERENDER ? R_PRERENDER_DIVOT_CONTROL : 0) ==
PRERENDER_DIVOT_PRINT_COLOR) {
if (PRERENDER_DIVOT_CONTROL == PRERENDER_DIVOT_PRINT_COLOR) {
PRINTF("red=%3d %3d %3d %3d grn=%3d %3d %3d %3d blu=%3d %3d %3d %3d \n", windowR[0], windowR[1],
windowR[2], MEDIAN3(windowR[0], windowR[1], windowR[2]), windowG[0], windowG[1],
windowG[2], MEDIAN3(windowG[0], windowG[1], windowG[2]), windowB[0], windowB[1],
@ -758,8 +763,7 @@ void PreRender_DivotFilter(PreRender* this) {
// Sample the median value from the 3 pixel wide window
// (Both blocks contain the same code)
if ((R_HREG_MODE == HREG_MODE_PRERENDER ? R_PRERENDER_DIVOT_CONTROL : 0) ==
PRERENDER_DIVOT_ALTERNATE_COLOR) {
if (PRERENDER_DIVOT_CONTROL == PRERENDER_DIVOT_ALTERNATE_COLOR) {
pxR = MEDIAN3(windowR[0], windowR[1], windowR[2]);
pxG = MEDIAN3(windowG[0], windowG[1], windowG[2]);
pxB = MEDIAN3(windowB[0], windowB[1], windowB[2]);
@ -803,11 +807,9 @@ void PreRender_ApplyFilters(PreRender* this) {
}
}
#if OOT_DEBUG
if ((R_HREG_MODE == HREG_MODE_PRERENDER ? R_PRERENDER_DIVOT_CONTROL : 0) != 0) {
if (PRERENDER_DIVOT_CONTROL != 0) {
// Apply divot filter
PreRender_DivotFilter(this);
}
#endif
}
}

View file

@ -100,7 +100,7 @@ void ArenaImpl_UnsetCheckFreeBlock(Arena* arena) {
arena->flag &= ~CHECK_FREE_BLOCK_FLAG;
}
void ArenaImpl_SetDebugInfo(ArenaNode* node, const char* file, s32 line, Arena* arena) {
void ArenaImpl_SetDebugInfo(ArenaNode* node, const char* file, int line, Arena* arena) {
node->filename = file;
node->line = line;
node->threadId = osGetThreadId(NULL);
@ -254,7 +254,7 @@ void __osMalloc_FreeBlockTest(Arena* arena, ArenaNode* node) {
}
}
void* __osMalloc_NoLockDebug(Arena* arena, u32 size, const char* file, s32 line) {
void* __osMalloc_NoLockDebug(Arena* arena, u32 size, const char* file, int line) {
ArenaNode* iter;
u32 blockSize;
ArenaNode* newNode;
@ -299,7 +299,7 @@ void* __osMalloc_NoLockDebug(Arena* arena, u32 size, const char* file, s32 line)
return alloc;
}
void* __osMallocDebug(Arena* arena, u32 size, const char* file, s32 line) {
void* __osMallocDebug(Arena* arena, u32 size, const char* file, int line) {
void* alloc;
ArenaImpl_Lock(arena);
@ -309,7 +309,7 @@ void* __osMallocDebug(Arena* arena, u32 size, const char* file, s32 line) {
return alloc;
}
void* __osMallocRDebug(Arena* arena, u32 size, const char* file, s32 line) {
void* __osMallocRDebug(Arena* arena, u32 size, const char* file, int line) {
ArenaNode* iter;
ArenaNode* newNode;
u32 blockSize;
@ -528,7 +528,7 @@ void __osFree(Arena* arena, void* ptr) {
}
#if OOT_DEBUG
void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) {
void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, int line) {
ArenaNode* node;
ArenaNode* next;
ArenaNode* prev;
@ -586,7 +586,7 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) {
}
}
void __osFreeDebug(Arena* arena, void* ptr, const char* file, s32 line) {
void __osFreeDebug(Arena* arena, void* ptr, const char* file, int line) {
ArenaImpl_Lock(arena);
__osFree_NoLockDebug(arena, ptr, file, line);
ArenaImpl_Unlock(arena);
@ -695,7 +695,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
}
#if OOT_DEBUG
void* __osReallocDebug(Arena* arena, void* ptr, u32 newSize, const char* file, s32 line) {
void* __osReallocDebug(Arena* arena, void* ptr, u32 newSize, const char* file, int line) {
return __osRealloc(arena, ptr, newSize);
}
#endif
@ -852,7 +852,11 @@ u32 __osCheckArena(Arena* arena) {
while (iter != NULL) {
if (iter && iter->magic == NODE_MAGIC) {
// "Oops!! (%08x %08x)"
#if OOT_DEBUG
osSyncPrintf(VT_COL(RED, WHITE) "おおっと!! (%08x %08x)\n" VT_RST, iter, iter->magic);
#else
osSyncPrintf("おおっと!! (%08x %08x)\n", iter, iter->magic);
#endif
error = 1;
break;
}

View file

@ -105,7 +105,7 @@ void AudioMgr_ThreadEntry(void* arg) {
IrqMgr_AddClient(audioMgr->irqMgr, &irqClient, &audioMgr->interruptQueue);
// Spin waiting for events
while (true) {
for (;;) {
osRecvMesg(&audioMgr->interruptQueue, (OSMesg*)&msg, OS_MESG_BLOCK);
switch (*msg) {

View file

@ -1,79 +0,0 @@
#include "global.h"
// The latest generated random number, used to generate the next number in the sequence.
static u32 sRandInt = 1;
// Space to store a value to be re-interpreted as a float.
static u32 sRandFloat;
/**
* Gets the next integer in the sequence of pseudo-random numbers.
*/
u32 Rand_Next(void) {
return sRandInt = (sRandInt * 1664525) + 1013904223;
}
/**
* Seeds the pseudo-random number generator by providing a starting value.
*/
void Rand_Seed(u32 seed) {
sRandInt = seed;
}
/**
* Returns a pseudo-random floating-point number between 0.0f and 1.0f, by generating
* the next integer and masking it to an IEEE-754 compliant floating-point number
* between 1.0f and 2.0f, returning the result subtract 1.0f.
*/
f32 Rand_ZeroOne(void) {
sRandInt = (sRandInt * 1664525) + 1013904223;
sRandFloat = ((sRandInt >> 9) | 0x3F800000);
return *((f32*)&sRandFloat) - 1.0f;
}
/**
* Returns a pseudo-random floating-point number between -0.5f and 0.5f by the same
* manner in which Rand_ZeroOne generates its result.
*/
f32 Rand_Centered(void) {
sRandInt = (sRandInt * 1664525) + 1013904223;
sRandFloat = ((sRandInt >> 9) | 0x3F800000);
return *((f32*)&sRandFloat) - 1.5f;
}
/**
* Seeds a pseudo-random number at rndNum with a provided seed.
*/
void Rand_Seed_Variable(u32* rndNum, u32 seed) {
*rndNum = seed;
}
/**
* Generates the next pseudo-random integer from the provided rndNum.
*/
u32 Rand_Next_Variable(u32* rndNum) {
return *rndNum = (*rndNum * 1664525) + 1013904223;
}
/**
* Generates the next pseudo-random floating-point number between 0.0f and
* 1.0f from the provided rndNum.
*/
f32 Rand_ZeroOne_Variable(u32* rndNum) {
u32 next = (*rndNum * 1664525) + 1013904223;
sRandFloat = ((*rndNum = next) >> 9) | 0x3F800000;
return *((f32*)&sRandFloat) - 1.0f;
}
/**
* Generates the next pseudo-random floating-point number between -0.5f and
* 0.5f from the provided rndNum.
*/
f32 Rand_Centered_Variable(u32* rndNum) {
u32 next = (*rndNum * 1664525) + 1013904223;
*rndNum = next;
sRandFloat = (next >> 9) | 0x3F800000;
return *((f32*)&sRandFloat) - 1.5f;
}

View file

@ -36,7 +36,7 @@ void* DebugArena_Malloc(u32 size) {
}
#if OOT_DEBUG
void* DebugArena_MallocDebug(u32 size, const char* file, s32 line) {
void* DebugArena_MallocDebug(u32 size, const char* file, int line) {
void* ptr = __osMallocDebug(&sDebugArena, size, file, line);
DEBUG_ARENA_CHECK_POINTER(ptr, size, "debug_malloc_DEBUG", "確保"); // "Secure"
@ -52,7 +52,7 @@ void* DebugArena_MallocR(u32 size) {
}
#if OOT_DEBUG
void* DebugArena_MallocRDebug(u32 size, const char* file, s32 line) {
void* DebugArena_MallocRDebug(u32 size, const char* file, int line) {
void* ptr = __osMallocRDebug(&sDebugArena, size, file, line);
DEBUG_ARENA_CHECK_POINTER(ptr, size, "debug_malloc_r_DEBUG", "確保"); // "Secure"
@ -67,7 +67,7 @@ void* DebugArena_Realloc(void* ptr, u32 newSize) {
}
#if OOT_DEBUG
void* DebugArena_ReallocDebug(void* ptr, u32 newSize, const char* file, s32 line) {
void* DebugArena_ReallocDebug(void* ptr, u32 newSize, const char* file, int line) {
ptr = __osReallocDebug(&sDebugArena, ptr, newSize, file, line);
DEBUG_ARENA_CHECK_POINTER(ptr, newSize, "debug_realloc_DEBUG", "再確保"); // "Re-securing"
return ptr;
@ -79,7 +79,7 @@ void DebugArena_Free(void* ptr) {
}
#if OOT_DEBUG
void DebugArena_FreeDebug(void* ptr, const char* file, s32 line) {
void DebugArena_FreeDebug(void* ptr, const char* file, int line) {
__osFreeDebug(&sDebugArena, ptr, file, line);
}
#endif

View file

@ -1322,7 +1322,7 @@ NORETURN void Fault_AddHungupAndCrashImpl(const char* exp1, const char* exp2) {
* Like `Fault_AddHungupAndCrashImpl`, however provides a fixed message containing
* filename and line number
*/
NORETURN void Fault_AddHungupAndCrash(const char* file, s32 line) {
NORETURN void Fault_AddHungupAndCrash(const char* file, int line) {
char msg[256];
sprintf(msg, "HungUp %s:%d", file, line);

View file

@ -102,11 +102,11 @@ FaultDrawer sFaultDrawerDefault = {
#ifndef NON_MATCHING
// TODO: match .bss (has reordering issues)
extern FaultDrawer sFaultDrawer;
extern char D_8016B6BC[0x24];
extern char D_8016B6C0[0x20];
#else
// Non-matching version for struct shiftability
FaultDrawer sFaultDrawer;
char D_8016B6BC[0x24];
char D_8016B6C0[0x20];
#endif
void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled) {

View file

@ -6,10 +6,11 @@ VisCvg sVisCvg;
VisZBuf sVisZBuf;
VisMono sVisMono;
ViMode sViMode;
#if OOT_DEBUG
FaultClient sGameFaultClient;
u16 sLastButtonPressed;
#if OOT_DEBUG
void GameState_FaultPrint(void) {
static char sBtnChars[] = "ABZSuldr*+LRudlr";
s32 i;
@ -408,7 +409,10 @@ void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* g
gameState->destroy = NULL;
gameState->running = 1;
startTime = osGetTime();
gameState->size = gameState->init = 0;
// Thse assignments must be written this way for matching and to avoid a warning due to casting a pointer to an
// integer without a cast. This assigns init = NULL and size = 0.
gameState->size = (u32)(gameState->init = NULL);
{
s32 requiredScopeTemp;
@ -494,7 +498,7 @@ u32 GameState_IsRunning(GameState* gameState) {
}
#if OOT_DEBUG
void* GameState_Alloc(GameState* gameState, size_t size, char* file, s32 line) {
void* GameState_Alloc(GameState* gameState, size_t size, const char* file, int line) {
void* ret;
if (THA_IsCrash(&gameState->tha)) {

View file

@ -13,7 +13,7 @@ void GameAlloc_Log(GameAlloc* this) {
}
#if OOT_DEBUG
void* GameAlloc_MallocDebug(GameAlloc* this, u32 size, const char* file, s32 line) {
void* GameAlloc_MallocDebug(GameAlloc* this, u32 size, const char* file, int line) {
GameAllocEntry* ptr = SystemArena_MallocDebug(size + sizeof(GameAllocEntry), file, line);
if (ptr != NULL) {

View file

@ -14,8 +14,13 @@ OSTime sGraphPrevUpdateEndTime;
*/
OSTime sGraphPrevTaskTimeStart;
#if OOT_DEBUG
FaultClient sGraphFaultClient;
#endif
CfbInfo sGraphCfbInfos[3];
#if OOT_DEBUG
FaultClient sGraphUcodeFaultClient;
UCodeInfo D_8012D230[3] = {
@ -30,7 +35,6 @@ UCodeInfo D_8012D248[3] = {
{ UCODE_S2DEX, gspS2DEX2d_fifoTextStart },
};
#if OOT_DEBUG
void Graph_FaultClient(void) {
void* nextFb = osViGetNextFramebuffer();
void* newFb = (SysCfb_GetFbPtr(0) != nextFb) ? SysCfb_GetFbPtr(0) : SysCfb_GetFbPtr(1);
@ -501,7 +505,7 @@ void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size) {
}
#if OOT_DEBUG
void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line) {
void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, int line) {
if (R_HREG_MODE == HREG_MODE_UCODE_DISAS && R_UCODE_DISAS_LOG_MODE != 4) {
dispRefs[0] = gfxCtx->polyOpa.p;
dispRefs[1] = gfxCtx->polyXlu.p;
@ -513,7 +517,7 @@ void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file,
}
}
void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line) {
void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, int line) {
if (R_HREG_MODE == HREG_MODE_UCODE_DISAS && R_UCODE_DISAS_LOG_MODE != 4) {
if (dispRefs[0] + 1 == gfxCtx->polyOpa.p) {
gfxCtx->polyOpa.p = dispRefs[0];

View file

@ -1,6 +1,8 @@
#include "global.h"
#include "terminal.h"
extern u8 _buffersSegmentEnd[];
s32 gScreenWidth = SCREEN_WIDTH;
s32 gScreenHeight = SCREEN_HEIGHT;
u32 gSystemHeapSize = 0;
@ -29,7 +31,8 @@ OSMesg sSerialMsgBuf[1];
void Main_LogSystemHeap(void) {
PRINTF(VT_FGCOL(GREEN));
// "System heap size% 08x (% dKB) Start address% 08x"
PRINTF("システムヒープサイズ %08x(%dKB) 開始アドレス %08x\n", gSystemHeapSize, gSystemHeapSize / 1024, gSystemHeap);
PRINTF("システムヒープサイズ %08x(%dKB) 開始アドレス %08x\n", gSystemHeapSize, gSystemHeapSize / 1024,
_buffersSegmentEnd);
PRINTF(VT_RST);
}
#endif
@ -48,7 +51,7 @@ void Main(void* arg) {
PreNmiBuff_Init(gAppNmiBufferPtr);
Fault_Init();
SysCfb_Init(0);
systemHeapStart = (uintptr_t)gSystemHeap;
systemHeapStart = (uintptr_t)_buffersSegmentEnd;
fb = (uintptr_t)SysCfb_GetFbPtr(0);
gSystemHeapSize = fb - systemHeapStart;
// "System heap initalization"

162
src/code/rand.c Normal file
View file

@ -0,0 +1,162 @@
/**
* @file rand.c
*
* This file implements the primary random number generator the game relies on. The generator is pseudo-random and
* implemented as a Linear Congruential Generator (LCG).
*
* A LCG computes random numbers sequentially via the relation
* X(n+1) = (a * X(n) + c) mod m
* where m is the modulus, a is the multiplier and c is the increment.
*
* These three parameters (a,c,m) completely specify the LCG and should be chosen such that
* - m > 0
* - 0 < a < m
* - 0 <= c < m
*
* The period of the LCG (a, c, m) is the smallest period p such that X(n + p) = X(n), past n=p the sequence will repeat
* itself in its outputs.
* A good LCG should have the maximum possible period, which will be equal to m as there are at most m possible values
* for X. This occurs when (Hull, T.E., & Dobell, A.R. (1962). Random Number Generators. Siam Review, 4, 230-254.):
* - m,c are relatively prime, that is the only integer that divides both m and c with no remainder is 1.
* - a - 1 is divisible by all prime factors of m.
* - a - 1 is divisible by 4 if m is divisible by 4.
*
* Ideally m is chosen to be a large power of 2 so that the modulo operation is inexpensive to compute. In this case the
* prime factors of m = 2^k are just k copies of 2. For k > 1 m is divisible by 4, so a - 1 must be divisible by 4. 2^k
* and c can easily be made relatively prime by making c an odd number.
* If we let k=32 to match the size of an integer, the modulo operation is made implicit by the width of the data type
* and becomes free to compute.
*
* The parameter a should be selected such that a-1 is divisible by 4 (and hence divisible by 2) and c should be any odd
* number. The precise values should fare well against the spectral test, a measure of "how random" a particular LCG is.
* A pair (a,c) that satisfies these requirements is (1664525, 1013904223), recommended by "Numerical Recipes in C: The
* Art of Scientific Computing" (p. 284).
*
* Therefore, the LCG with parameters (1664525, 1013904223, 2^32) that is implemented in this file has a maximal period
* of 2^32 and produces high-quality pseudo-random numbers.
*
* @note If sampling the LCG for a n-bit number it is important to use the upper n bits instead of the lower n bits of
* the LCG output. The lower n bits only have a period of 2^n which may significantly worsen the quality of the
* resulting random numbers compared to the quality of the full 32-bit result.
*
* @note Original name: qrand.c
*/
#include "ultra64.h"
#define RAND_MULTIPLIER 1664525
#define RAND_INCREMENT 1013904223
/**
* The latest generated random number, used to generate the next number in the sequence.
*
* @note Original name: __qrand_idum
*/
static u32 sRandInt = 1;
/**
* Space to store a value to be re-interpreted as a float.
*
* @note Orignal name: __qrand_itemp
*/
static fu sRandFloat;
/**
* Gets the next integer in the sequence of pseudo-random numbers.
*
* @note Original name: qrand
*/
u32 Rand_Next(void) {
return sRandInt = sRandInt * RAND_MULTIPLIER + RAND_INCREMENT;
}
/**
* Seeds the pseudo-random number generator by providing a starting value.
*
* @note Original name: sqrand
*/
void Rand_Seed(u32 seed) {
sRandInt = seed;
}
/**
* Returns a pseudo-random floating-point number between 0.0f and 1.0f, by generating the next integer and masking it
* to an IEEE-754 compliant floating-point number between 1.0f and 2.0f, returning the result subtract 1.0f.
*
* @note This technique for generating pseudo-random floats is recommended as a particularly fast but potentially
* non-portable generator in "Numerical Recipes in C: The Art of Scientic Computing", pp. 284-5.
*
* @note Original name: fqrand
*/
f32 Rand_ZeroOne(void) {
sRandInt = sRandInt * RAND_MULTIPLIER + RAND_INCREMENT;
// Samples the upper 23 bits to avoid effectively reducing the LCG period.
sRandFloat.i = (sRandInt >> 9) | 0x3F800000;
return sRandFloat.f - 1.0f;
}
/**
* Returns a pseudo-random floating-point number between -0.5f and 0.5f by the same manner in which Rand_ZeroOne
* generates its result.
*
* @see Rand_ZeroOne
*
* @note Original name: fqrand2
*/
f32 Rand_Centered(void) {
sRandInt = sRandInt * RAND_MULTIPLIER + RAND_INCREMENT;
sRandFloat.i = (sRandInt >> 9) | 0x3F800000;
return sRandFloat.f - 1.5f;
}
//! All functions below are unused variants of the above four, that use a provided random number variable instead of the
//! internal `sRandInt`
/**
* Seeds a pseudo-random number at rndNum with a provided starting value.
*
* @see Rand_Seed
*
* @note Original name: sqrand_r
*/
void Rand_Seed_Variable(u32* rndNum, u32 seed) {
*rndNum = seed;
}
/**
* Generates the next pseudo-random integer from the provided rndNum.
*
* @see Rand_Next
*
* @note Original name: qrand_r
*/
u32 Rand_Next_Variable(u32* rndNum) {
return *rndNum = (*rndNum) * RAND_MULTIPLIER + RAND_INCREMENT;
}
/**
* Generates the next pseudo-random floating-point number between 0.0f and 1.0f from the provided rndNum.
*
* @see Rand_ZeroOne
*
* @note Original name: fqrand_r
*/
f32 Rand_ZeroOne_Variable(u32* rndNum) {
u32 next = (*rndNum) * RAND_MULTIPLIER + RAND_INCREMENT;
sRandFloat.i = ((*rndNum = next) >> 9) | 0x3F800000;
return sRandFloat.f - 1.0f;
}
/**
* Generates the next pseudo-random floating-point number between -0.5f and 0.5f from the provided rndNum.
*
* @see Rand_ZeroOne, Rand_Centered
*
* @note Original name: fqrand2_r
*/
f32 Rand_Centered_Variable(u32* rndNum) {
u32 next = (*rndNum) * RAND_MULTIPLIER + RAND_INCREMENT;
sRandFloat.i = ((*rndNum = next) >> 9) | 0x3F800000;
return sRandFloat.f - 1.5f;
}

View file

@ -45,14 +45,14 @@
#define RDP_DONE_MSG 668
#define NOTIFY_MSG 670 // original name: ENTRY_MSG
vs32 sSchedDebugPrintfEnabled = false;
OSTime sRSPGfxTimeStart;
OSTime sRSPAudioTimeStart;
OSTime sRSPOtherTimeStart;
OSTime sRDPTimeStart;
#if OOT_DEBUG
vs32 sSchedDebugPrintfEnabled = false;
#define SCHED_DEBUG_PRINTF \
if (sSchedDebugPrintfEnabled) \
PRINTF

View file

@ -605,11 +605,11 @@ Mtx* Matrix_MtxFToMtx(MtxF* src, Mtx* dest) {
#if OOT_DEBUG
Mtx* Matrix_ToMtx(Mtx* dest, char* file, s32 line) {
Mtx* Matrix_ToMtx(Mtx* dest, const char* file, int line) {
return Matrix_MtxFToMtx(MATRIX_CHECK_FLOATS(sCurrentMatrix, file, line), dest);
}
Mtx* Matrix_NewMtx(GraphicsContext* gfxCtx, char* file, s32 line) {
Mtx* Matrix_NewMtx(GraphicsContext* gfxCtx, const char* file, int line) {
return Matrix_ToMtx(GRAPH_ALLOC(gfxCtx, sizeof(Mtx)), file, line);
}
@ -970,7 +970,7 @@ void Matrix_RotateAxis(f32 angle, Vec3f* axis, u8 mode) {
}
#if OOT_DEBUG
MtxF* Matrix_CheckFloats(MtxF* mf, char* file, s32 line) {
MtxF* Matrix_CheckFloats(MtxF* mf, const char* file, int line) {
s32 i, j;
for (i = 0; i < 4; i++) {

View file

@ -36,7 +36,7 @@ void* SystemArena_Malloc(u32 size) {
}
#if OOT_DEBUG
void* SystemArena_MallocDebug(u32 size, const char* file, s32 line) {
void* SystemArena_MallocDebug(u32 size, const char* file, int line) {
void* ptr = __osMallocDebug(&gSystemArena, size, file, line);
SYSTEM_ARENA_CHECK_POINTER(ptr, size, "malloc_DEBUG", "確保"); // "Secure"
@ -52,7 +52,7 @@ void* SystemArena_MallocR(u32 size) {
}
#if OOT_DEBUG
void* SystemArena_MallocRDebug(u32 size, const char* file, s32 line) {
void* SystemArena_MallocRDebug(u32 size, const char* file, int line) {
void* ptr = __osMallocRDebug(&gSystemArena, size, file, line);
SYSTEM_ARENA_CHECK_POINTER(ptr, size, "malloc_r_DEBUG", "確保"); // "Secure"
@ -67,7 +67,7 @@ void* SystemArena_Realloc(void* ptr, u32 newSize) {
}
#if OOT_DEBUG
void* SystemArena_ReallocDebug(void* ptr, u32 newSize, const char* file, s32 line) {
void* SystemArena_ReallocDebug(void* ptr, u32 newSize, const char* file, int line) {
ptr = __osReallocDebug(&gSystemArena, ptr, newSize, file, line);
SYSTEM_ARENA_CHECK_POINTER(ptr, newSize, "realloc_DEBUG", "再確保"); // "Re-securing"
return ptr;
@ -79,7 +79,7 @@ void SystemArena_Free(void* ptr) {
}
#if OOT_DEBUG
void SystemArena_FreeDebug(void* ptr, const char* file, s32 line) {
void SystemArena_FreeDebug(void* ptr, const char* file, int line) {
__osFreeDebug(&gSystemArena, ptr, file, line);
}
#endif

View file

@ -23,6 +23,8 @@
#undef DEFINE_ACTOR_UNSET
// Actor Overlay Table definition
#if OOT_DEBUG
#define DEFINE_ACTOR(name, _1, allocType, nameString) \
{ (uintptr_t)_ovl_##name##SegmentRomStart, \
(uintptr_t)_ovl_##name##SegmentRomEnd, \
@ -37,6 +39,24 @@
#define DEFINE_ACTOR_INTERNAL(name, _1, allocType, nameString) \
{ 0, 0, NULL, NULL, NULL, &name##_InitVars, nameString, allocType, 0 },
#else
// Actor name is set to NULL in retail builds
#define DEFINE_ACTOR(name, _1, allocType, _3) \
{ (uintptr_t)_ovl_##name##SegmentRomStart, \
(uintptr_t)_ovl_##name##SegmentRomEnd, \
_ovl_##name##SegmentStart, \
_ovl_##name##SegmentEnd, \
NULL, \
&name##_InitVars, \
NULL, \
allocType, \
0 },
#define DEFINE_ACTOR_INTERNAL(name, _1, allocType, _3) { 0, 0, NULL, NULL, NULL, &name##_InitVars, NULL, allocType, 0 },
#endif
#define DEFINE_ACTOR_UNSET(_0) { 0 },
ActorOverlay gActorOverlayTable[] = {

View file

@ -79,10 +79,11 @@ u16 sSurfaceMaterialToSfxOffset[SURFACE_MATERIAL_MAX] = {
SURFACE_SFX_OFFSET_CARPET, // SURFACE_MATERIAL_CARPET
};
#if OOT_DEBUG
/**
* original name: T_BGCheck_PosErrorCheck
*/
s32 BgCheck_PosErrorCheck(Vec3f* pos, char* file, s32 line) {
s32 BgCheck_PosErrorCheck(Vec3f* pos, const char* file, int line) {
if (pos->x >= BGCHECK_XYZ_ABSMAX || pos->x <= -BGCHECK_XYZ_ABSMAX || pos->y >= BGCHECK_XYZ_ABSMAX ||
pos->y <= -BGCHECK_XYZ_ABSMAX || pos->z >= BGCHECK_XYZ_ABSMAX || pos->z <= -BGCHECK_XYZ_ABSMAX) {
PRINTF(VT_FGCOL(RED));
@ -94,6 +95,7 @@ s32 BgCheck_PosErrorCheck(Vec3f* pos, char* file, s32 line) {
}
return false;
}
#endif
/**
* Set SSNode
@ -194,30 +196,24 @@ void BgCheck_Vec3fToVec3s(Vec3s* dst, Vec3f* src) {
* Get CollisionPoly's lowest y point
*/
s16 CollisionPoly_GetMinY(CollisionPoly* poly, Vec3s* vtxList) {
s32 a;
s32 b;
s32 c;
s16 min;
//! @bug Due to rounding errors, some polys with a slight slope have a y normal of 1.0f/-1.0f. As such, this
//! optimization returns the wrong minimum y for a subset of these polys.
if (poly->normal.y == COLPOLY_SNORMAL(1.0f) || poly->normal.y == COLPOLY_SNORMAL(-1.0f)) {
return vtxList[COLPOLY_VTX_INDEX(poly->flags_vIA)].y;
}
} else {
s32 a = COLPOLY_VTX_INDEX(poly->flags_vIA);
s32 b = COLPOLY_VTX_INDEX(poly->flags_vIB);
s32 c = poly->vIC;
s16 min = vtxList[a].y;
a = COLPOLY_VTX_INDEX(poly->flags_vIA);
b = COLPOLY_VTX_INDEX(poly->flags_vIB);
c = poly->vIC;
min = vtxList[a].y;
if (min > vtxList[b].y) {
min = vtxList[b].y;
if (min > vtxList[b].y) {
min = vtxList[b].y;
}
if (min < vtxList[c].y) {
return min;
}
return vtxList[c].y;
}
if (min < vtxList[c].y) {
return min;
}
return vtxList[c].y;
}
/**
@ -491,8 +487,8 @@ void StaticLookup_AddPolyToSSList(CollisionContext* colCtx, SSList* ssList, Coll
SSNode* curNode;
SSNode* nextNode;
s32 polyYMin;
u16 newNodeId;
s16 curPolyId;
u16 newNodeId;
// if list is null
if (ssList->head == SS_NULL) {
@ -514,6 +510,8 @@ void StaticLookup_AddPolyToSSList(CollisionContext* colCtx, SSList* ssList, Coll
while (true) {
// if at the end of the list
if (curNode->next == SS_NULL) {
s32 pad;
newNodeId = SSNodeList_GetNextNodeIdx(&colCtx->polyNodes);
SSNode_SetValue(&colCtx->polyNodes.tbl[newNodeId], &polyId, SS_NULL);
curNode->next = newNodeId;
@ -681,8 +679,8 @@ s32 BgCheck_ComputeWallDisplacement(CollisionContext* colCtx, CollisionPoly* pol
s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16 xpFlags, f32* outX, f32* outZ,
Vec3f* pos, f32 radius, CollisionPoly** outPoly) {
Vec3f resultPos;
f32 temp_f2;
f32 temp_f2_2;
f32 zTemp;
f32 xTemp;
f32 planeDist;
f32 intersect;
s32 result;
@ -690,17 +688,14 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
CollisionPoly* polyList;
SSNode* curNode;
f32 invNormalXZ;
f32 zTemp;
f32 xTemp;
s32 polyId;
f32 normalXZ;
f32 nx;
f32 ny;
f32 nz;
f32 temp_f16;
s32 pad;
Vec3s* vtxList;
u16 pad;
f32 temp_f16;
f32 zMin;
f32 zMax;
f32 xMin;
@ -780,8 +775,10 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
}
}
if (CollisionPoly_CheckZIntersectApprox(curPoly, vtxList, resultPos.x, pos->y, &intersect)) {
if (fabsf(intersect - resultPos.z) <= radius / temp_f16) {
if ((intersect - resultPos.z) * nz <= 4.0f) {
f32 zIntersectDist = intersect - resultPos.z;
if (fabsf(zIntersectDist) <= radius / temp_f16) {
if (zIntersectDist * nz <= 4.0f) {
BgCheck_ComputeWallDisplacement(colCtx, curPoly, &resultPos.x, &resultPos.z, nx, ny, nz,
invNormalXZ, planeDist, radius, outPoly);
result = true;
@ -790,9 +787,8 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
}
if (curNode->next == SS_NULL) {
break;
} else {
curNode = &colCtx->polyNodes.tbl[curNode->next];
}
curNode = &colCtx->polyNodes.tbl[curNode->next];
}
curNode = &colCtx->polyNodes.tbl[lookup->wall.head];
@ -861,8 +857,10 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
}
}
if (CollisionPoly_CheckXIntersectApprox(curPoly, vtxList, pos->y, resultPos.z, &intersect)) {
if (fabsf(intersect - resultPos.x) <= radius / temp_f16) {
if ((intersect - resultPos.x) * nx <= 4.0f) {
f32 xIntersectDist = intersect - resultPos.x;
if (fabsf(xIntersectDist) <= radius / temp_f16) {
if (xIntersectDist * nx <= 4.0f) {
BgCheck_ComputeWallDisplacement(colCtx, curPoly, &resultPos.x, &resultPos.z, nx, ny, nz,
invNormalXZ, planeDist, radius, outPoly);
result = true;
@ -871,10 +869,8 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
}
if (curNode->next == SS_NULL) {
break;
} else {
curNode = &colCtx->polyNodes.tbl[curNode->next];
continue;
}
curNode = &colCtx->polyNodes.tbl[curNode->next];
}
*outX = resultPos.x;
@ -909,6 +905,9 @@ s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionConte
*outY = pos->y;
while (true) {
f32 intersectDist;
f32 ny;
curPolyId = curNode->polyId;
if (COLPOLY_VTX_CHECK_FLAGS_ANY(colCtx->colHeader->polyList[curPolyId].flags_vIA, xpFlags)) {
if (curNode->next == SS_NULL) {
@ -921,8 +920,8 @@ s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionConte
curPoly = &polyList[curPolyId];
if (CollisionPoly_CheckYIntersectApprox2(curPoly, vtxList, pos->x, pos->z, &ceilingY)) {
f32 intersectDist = ceilingY - *outY;
f32 ny = COLPOLY_GET_NORMAL(curPoly->normal.y);
intersectDist = ceilingY - *outY;
ny = COLPOLY_GET_NORMAL(curPoly->normal.y);
if (intersectDist > 0.0f && intersectDist < checkHeight && intersectDist * ny <= 0) {
*outY = ceilingY - checkHeight;
@ -958,7 +957,6 @@ s32 BgCheck_CheckLineAgainstSSList(SSList* ssList, CollisionContext* colCtx, u16
s32 result;
f32 minY;
f32 distSq;
s16 polyId;
result = false;
polyList = colCtx->colHeader->polyList;
@ -968,7 +966,8 @@ s32 BgCheck_CheckLineAgainstSSList(SSList* ssList, CollisionContext* colCtx, u16
curNode = &colCtx->polyNodes.tbl[ssList->head];
while (true) {
polyId = curNode->polyId;
s16 polyId = curNode->polyId;
checkedPoly = &colCtx->polyNodes.polyCheckTbl[polyId];
if (*checkedPoly == true || COLPOLY_VTX_CHECK_FLAGS_ANY(polyList[polyId].flags_vIA, xpFlags1) ||
@ -1051,13 +1050,12 @@ s32 BgCheck_SphVsFirstStaticPolyList(SSNode* node, u16 xpFlags, CollisionContext
CollisionPoly** outPoly) {
CollisionPoly* polyList = colCtx->colHeader->polyList;
Vec3s* vtxList = colCtx->colHeader->vtxList;
CollisionPoly* curPoly;
u16 nextId;
s16 curPolyId;
while (true) {
curPolyId = node->polyId;
curPoly = &polyList[curPolyId];
u16 nextId;
s16 curPolyId = node->polyId;
CollisionPoly* curPoly = &polyList[curPolyId];
if (COLPOLY_VTX_CHECK_FLAGS_ANY(colCtx->colHeader->polyList[curPolyId].flags_vIA, xpFlags)) {
if (node->next == SS_NULL) {
break;
@ -1542,10 +1540,10 @@ void BgCheck_Allocate(CollisionContext* colCtx, PlayState* play, CollisionHeader
u32 tblMax;
u32 memSize;
u32 lookupTblMemSize;
SSNodeList* nodeList;
s32 useCustomSubdivisions;
u32 customMemSize;
s32 customNodeListMax;
SSNodeList* nodeList;
u32 customMemSize;
s32 useCustomSubdivisions;
s32 i;
colCtx->colHeader = colHeader;
@ -1717,11 +1715,15 @@ f32 BgCheck_RaycastDownImpl(PlayState* play, CollisionContext* colCtx, u16 xpFla
if (checkPos.y < colCtx->minBounds.y) {
break;
}
#if OOT_DEBUG
if (BgCheck_PosErrorCheck(&checkPos, "../z_bgcheck.c", 4410)) {
if (actor != NULL) {
PRINTF("こいつ,pself_actor->name %d\n", actor->id);
}
}
#endif
lookup = BgCheck_GetStaticLookup(colCtx, lookupTbl, &checkPos);
if (lookup == NULL) {
checkPos.y -= colCtx->subdivLength.y;
@ -1735,16 +1737,16 @@ f32 BgCheck_RaycastDownImpl(PlayState* play, CollisionContext* colCtx, u16 xpFla
checkPos.y -= colCtx->subdivLength.y;
}
dynaRaycastDown.play = play;
dynaRaycastDown.colCtx = colCtx;
dynaRaycastDown.xpFlags = xpFlags;
dynaRaycastDown.resultPoly = outPoly;
dynaRaycastDown.yIntersect = yIntersect;
dynaRaycastDown.pos = pos;
dynaRaycastDown.bgId = outBgId;
dynaRaycastDown.actor = actor;
dynaRaycastDown.downChkFlags = downChkFlags;
dynaRaycastDown.chkDist = chkDist;
dynaRaycastDown.play = play;
dynaRaycastDown.resultPoly = outPoly;
dynaRaycastDown.bgId = outBgId;
yIntersectDyna = BgCheck_RaycastDownDyna(&dynaRaycastDown);
@ -1951,11 +1953,11 @@ s32 BgCheck_CheckWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResul
Vec3f checkLinePrev;
f32 n2XZDist;
f32 n3XZDist;
f32 nx3, nz3;
s32 bccFlags;
f32 nx;
f32 nz;
Vec3f posIntersect2;
s32 bgId2;
f32 nx, ny, nz; // unit normal of polygon
result = false;
*outBgId = BGCHECK_SCENE;
@ -1966,12 +1968,14 @@ s32 BgCheck_CheckWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResul
dy = posNext->y - posPrev->y;
dz = posNext->z - posPrev->z;
#if OOT_DEBUG
if (BgCheck_PosErrorCheck(posNext, "../z_bgcheck.c", 4831) == true ||
BgCheck_PosErrorCheck(posPrev, "../z_bgcheck.c", 4832) == true) {
if (actor != NULL) {
PRINTF("こいつ,pself_actor->name %d\n", actor->id);
}
}
#endif
// if there's movement on the xz plane, and argA flag is 0,
if ((dx != 0.0f || dz != 0.0f) && (argA & 1) == 0) {
@ -1980,7 +1984,8 @@ s32 BgCheck_CheckWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResul
result = BgCheck_CheckLineImpl(colCtx, xpFlags, COLPOLY_IGNORE_NONE, posPrev, posNext, &posIntersect, &poly,
&bgId, actor, 1.0f, BGCHECK_CHECK_ALL & ~BGCHECK_CHECK_CEILING);
if (result) {
ny = COLPOLY_GET_NORMAL(poly->normal.y);
f32 ny = COLPOLY_GET_NORMAL(poly->normal.y);
// if poly is floor, push result underneath the floor
if (ny > 0.5f) {
posResult->x = posIntersect.x;
@ -2061,8 +2066,9 @@ s32 BgCheck_CheckWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResul
if (dynaPolyCollision == true || *outBgId != BGCHECK_SCENE) {
if (BgCheck_CheckLineImpl(colCtx, xpFlags, COLPOLY_IGNORE_NONE, posPrev, posResult, &posIntersect2, &poly,
&bgId2, actor, 1.0f, BGCHECK_CHECK_ONE_FACE | BGCHECK_CHECK_WALL)) {
nx3 = COLPOLY_GET_NORMAL(poly->normal.x);
nz3 = COLPOLY_GET_NORMAL(poly->normal.z);
f32 nx3 = COLPOLY_GET_NORMAL(poly->normal.x);
f32 nz3 = COLPOLY_GET_NORMAL(poly->normal.z);
n3XZDist = sqrtf(SQ(nx3) + SQ(nz3));
// if poly is not a "flat" floor or "flat" ceiling
@ -2155,11 +2161,15 @@ s32 BgCheck_CheckCeilingImpl(CollisionContext* colCtx, u16 xpFlags, f32* outY, V
*outBgId = BGCHECK_SCENE;
*outY = pos->y;
#if OOT_DEBUG
if (BgCheck_PosErrorCheck(pos, "../z_bgcheck.c", 5206) == true) {
if (actor != NULL) {
PRINTF("こいつ,pself_actor->name %d\n", actor->id);
}
}
#endif
lookupTbl = colCtx->lookupTbl;
if (!BgCheck_PosInStaticBoundingBox(colCtx, pos)) {
return false;
@ -2222,13 +2232,10 @@ s32 BgCheck_CheckLineImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2,
Vec3f posBTemp = *posB;
Vec3f sectorMin;
Vec3f sectorMax;
s32 k;
StaticLookup* lookup;
s32 j;
StaticLookup* jLookup;
s32 temp_lo;
*outBgId = BGCHECK_SCENE;
#if OOT_DEBUG
if (BgCheck_PosErrorCheck(posA, "../z_bgcheck.c", 5334) == true ||
BgCheck_PosErrorCheck(posB, "../z_bgcheck.c", 5335) == true) {
if (actor != NULL) {
@ -2237,6 +2244,7 @@ s32 BgCheck_CheckLineImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2,
PRINTF("pself_actor == NULLで犯人不明\n");
}
}
#endif
BgCheck_ResetPolyCheckTbl(&colCtx->polyNodes, colCtx->colHeader->numPolygons);
BgCheck_GetStaticLookupIndicesFromPos(colCtx, posA, (Vec3i*)&subdivMin);
@ -2247,6 +2255,10 @@ s32 BgCheck_CheckLineImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2,
*outPoly = NULL;
if (subdivMin[0] != subdivMax[0] || subdivMin[1] != subdivMax[1] || subdivMin[2] != subdivMax[2]) {
s32 k;
s32 temp_lo;
s32 j;
for (i = 0; i < 3; i++) {
if (subdivMax[i] < subdivMin[i]) {
j = subdivMax[i];
@ -2260,12 +2272,14 @@ s32 BgCheck_CheckLineImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2,
sectorMax.z = colCtx->subdivLength.z + sectorMin.z;
for (i = subdivMin[2]; i < subdivMax[2] + 1; i++) {
jLookup = iLookup + subdivMin[1] * colCtx->subdivAmount.x;
StaticLookup* jLookup = iLookup + subdivMin[1] * colCtx->subdivAmount.x;
sectorMin.y = subdivMin[1] * colCtx->subdivLength.y + colCtx->minBounds.y;
sectorMax.y = colCtx->subdivLength.y + sectorMin.y;
for (j = subdivMin[1]; j < subdivMax[1] + 1; j++) {
lookup = jLookup + subdivMin[0];
StaticLookup* lookup = jLookup + subdivMin[0];
sectorMin.x = subdivMin[0] * colCtx->subdivLength.x + colCtx->minBounds.x;
sectorMax.x = colCtx->subdivLength.x + sectorMin.x;
@ -2443,11 +2457,14 @@ s32 BgCheck_SphVsFirstPolyImpl(CollisionContext* colCtx, u16 xpFlags, CollisionP
StaticLookup* lookup;
*outBgId = BGCHECK_SCENE;
#if OOT_DEBUG
if (BgCheck_PosErrorCheck(center, "../z_bgcheck.c", 5852) == true) {
if (actor != NULL) {
PRINTF("こいつ,pself_actor->name %d\n", actor->id);
}
}
#endif
lookup = BgCheck_GetStaticLookup(colCtx, colCtx->lookupTbl, center);
if (lookup == NULL) {
@ -2784,12 +2801,12 @@ void DynaPoly_DeleteBgActor(PlayState* play, DynaCollisionContext* dyna, s32 bgI
PRINTF(VT_RST);
if (!DynaPoly_IsBgIdBgActor(bgId)) {
#if OOT_DEBUG
if (bgId == -1) {
PRINTF(VT_FGCOL(GREEN));
// "The index that should have been deleted(? ) was(== -1), processing aborted."
PRINTF("DynaPolyInfo_delReserve():削除されているはずの(?)\nインデックス(== -1)のため,処理を中止します。\n");
PRINTF(VT_RST);
return;
} else {
PRINTF(VT_FGCOL(RED));
// "Unable to deallocate index / index unallocated, processing aborted."
@ -2797,15 +2814,17 @@ void DynaPoly_DeleteBgActor(PlayState* play, DynaCollisionContext* dyna, s32 bgI
"確保していない出来なかったインデックスの解放のため、処理を中止します。index == %d\n",
bgId);
PRINTF(VT_RST);
return;
}
}
actor = DynaPoly_GetActor(&play->colCtx, bgId);
if (actor != NULL) {
#endif
actor->bgId = BGACTOR_NEG_ONE;
dyna->bgActors[bgId].actor = NULL;
dyna->bgActorFlags[bgId] |= BGACTOR_1;
} else {
actor = DynaPoly_GetActor(&play->colCtx, bgId);
if (actor != NULL) {
actor->bgId = BGACTOR_NEG_ONE;
dyna->bgActors[bgId].actor = NULL;
dyna->bgActorFlags[bgId] |= BGACTOR_1;
}
}
}
@ -2821,7 +2840,7 @@ void DynaPoly_AddBgActorToLookup(PlayState* play, DynaCollisionContext* dyna, s3
MtxF mtx;
Actor* actor;
s32 pad;
s32 pad2;
f32 radiusSq;
f32 numVtxInverse;
s32 i;
Vec3f pos;
@ -2851,6 +2870,7 @@ void DynaPoly_AddBgActorToLookup(PlayState* play, DynaCollisionContext* dyna, s3
return;
}
#if OOT_DEBUG
if (!(dyna->polyListMax >= *polyStartIndex + pbgdata->numPolygons)) {
PRINTF(VT_FGCOL(RED));
// "do not use if %d exceeds %d"
@ -2869,6 +2889,7 @@ void DynaPoly_AddBgActorToLookup(PlayState* play, DynaCollisionContext* dyna, s3
"pdyna_poly_info->poly_num >= *pstart_poly_index + pbgdata->poly_num", "../z_bgcheck.c", 6687);
ASSERT(dyna->vtxListMax >= *vtxStartIndex + pbgdata->numVertices,
"pdyna_poly_info->vert_num >= *pstart_vert_index + pbgdata->vtx_num", "../z_bgcheck.c", 6688);
#endif
if (!(dyna->bitFlag & DYNAPOLY_INVALIDATE_LOOKUP) &&
(BgActor_IsTransformUnchanged(&dyna->bgActors[bgId]) == true)) {
@ -2898,111 +2919,111 @@ void DynaPoly_AddBgActorToLookup(PlayState* play, DynaCollisionContext* dyna, s3
*polyStartIndex += pbgdata->numPolygons;
*vtxStartIndex += pbgdata->numVertices;
} else {
SkinMatrix_SetTranslateRotateYXZScale(
&mtx, dyna->bgActors[bgId].curTransform.scale.x, dyna->bgActors[bgId].curTransform.scale.y,
dyna->bgActors[bgId].curTransform.scale.z, dyna->bgActors[bgId].curTransform.rot.x,
dyna->bgActors[bgId].curTransform.rot.y, dyna->bgActors[bgId].curTransform.rot.z,
dyna->bgActors[bgId].curTransform.pos.x, dyna->bgActors[bgId].curTransform.pos.y,
dyna->bgActors[bgId].curTransform.pos.z);
numVtxInverse = 1.0f / pbgdata->numVertices;
newCenterPoint.x = newCenterPoint.y = newCenterPoint.z = 0.0f;
for (i = 0; i < pbgdata->numVertices; i++) {
Vec3f vtx;
Vec3f vtxT; // Vtx after mtx transform
Math_Vec3s_ToVec3f(&vtx, &pbgdata->vtxList[i]);
SkinMatrix_Vec3fMtxFMultXYZ(&mtx, &vtx, &vtxT);
BgCheck_Vec3fToVec3s(&dyna->vtxList[*vtxStartIndex + i], &vtxT);
if (i == 0) {
dyna->bgActors[bgId].minY = dyna->bgActors[bgId].maxY = vtxT.y;
} else if (vtxT.y < dyna->bgActors[bgId].minY) {
dyna->bgActors[bgId].minY = vtxT.y;
} else if (dyna->bgActors[bgId].maxY < vtxT.y) {
dyna->bgActors[bgId].maxY = vtxT.y;
}
newCenterPoint.x += vtxT.x;
newCenterPoint.y += vtxT.y;
newCenterPoint.z += vtxT.z;
}
newCenterPoint.x *= numVtxInverse;
newCenterPoint.y *= numVtxInverse;
newCenterPoint.z *= numVtxInverse;
sphere->center.x = newCenterPoint.x;
sphere->center.y = newCenterPoint.y;
sphere->center.z = newCenterPoint.z;
newRadiusSq = -SQ(10.0f);
for (i = 0; i < pbgdata->numVertices; i++) {
f32 radiusSq;
newVtx.x = dyna->vtxList[*vtxStartIndex + i].x;
newVtx.y = dyna->vtxList[*vtxStartIndex + i].y;
newVtx.z = dyna->vtxList[*vtxStartIndex + i].z;
radiusSq = Math3D_Vec3fDistSq(&newVtx, &newCenterPoint);
if (newRadiusSq < radiusSq) {
newRadiusSq = radiusSq;
}
}
sphere->radius = sqrtf(newRadiusSq) * 1.1f;
for (i = 0; i < pbgdata->numPolygons; i++) {
CollisionPoly* newPoly = &dyna->polyList[*polyStartIndex + i];
f32 newNormMagnitude;
*newPoly = pbgdata->polyList[i];
// Yeah, this is all kinds of fake, but my God, it matches.
newPoly->flags_vIA = (COLPOLY_VTX_INDEX(newPoly->flags_vIA) + *vtxStartIndex) |
COLPOLY_VTX_FLAGS_MASKED((*newPoly).flags_vIA);
newPoly->flags_vIB = (COLPOLY_VTX_INDEX(newPoly->flags_vIB) + *vtxStartIndex) |
COLPOLY_VTX_FLAGS_MASKED((*newPoly).flags_vIB);
newPoly->vIC = *vtxStartIndex + newPoly->vIC;
dVtxList = dyna->vtxList;
vtxA.x = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIA)].x;
vtxA.y = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIA)].y;
vtxA.z = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIA)].z;
vtxB.x = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIB)].x;
vtxB.y = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIB)].y;
vtxB.z = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIB)].z;
vtxC.x = dVtxList[newPoly->vIC].x;
vtxC.y = dVtxList[newPoly->vIC].y;
vtxC.z = dVtxList[newPoly->vIC].z;
Math3D_SurfaceNorm(&vtxA, &vtxB, &vtxC, &newNormal);
newNormMagnitude = Math3D_Vec3fMagnitude(&newNormal);
if (!IS_ZERO(newNormMagnitude)) {
newNormal.x *= (1.0f / newNormMagnitude);
newNormal.y *= (1.0f / newNormMagnitude);
newNormal.z *= (1.0f / newNormMagnitude);
newPoly->normal.x = COLPOLY_SNORMAL(newNormal.x);
newPoly->normal.y = COLPOLY_SNORMAL(newNormal.y);
newPoly->normal.z = COLPOLY_SNORMAL(newNormal.z);
}
newPoly->dist = -DOTXYZ(newNormal, dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIA)]);
if (newNormal.y > 0.5f) {
s16 polyId = *polyStartIndex + i;
DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.floor, &polyId);
} else if (newNormal.y < -0.8f) {
s16 polyId = *polyStartIndex + i;
DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.ceiling, &polyId);
} else {
s16 polyId = *polyStartIndex + i;
DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.wall, &polyId);
}
}
*polyStartIndex += pbgdata->numPolygons;
*vtxStartIndex += pbgdata->numVertices;
return;
}
SkinMatrix_SetTranslateRotateYXZScale(
&mtx, dyna->bgActors[bgId].curTransform.scale.x, dyna->bgActors[bgId].curTransform.scale.y,
dyna->bgActors[bgId].curTransform.scale.z, dyna->bgActors[bgId].curTransform.rot.x,
dyna->bgActors[bgId].curTransform.rot.y, dyna->bgActors[bgId].curTransform.rot.z,
dyna->bgActors[bgId].curTransform.pos.x, dyna->bgActors[bgId].curTransform.pos.y,
dyna->bgActors[bgId].curTransform.pos.z);
numVtxInverse = 1.0f / pbgdata->numVertices;
newCenterPoint.x = newCenterPoint.y = newCenterPoint.z = 0.0f;
for (i = 0; i < pbgdata->numVertices; i++) {
Vec3f vtx;
Vec3f vtxT; // Vtx after mtx transform
s32 pad2;
Math_Vec3s_ToVec3f(&vtx, &pbgdata->vtxList[i]);
SkinMatrix_Vec3fMtxFMultXYZ(&mtx, &vtx, &vtxT);
BgCheck_Vec3fToVec3s(&dyna->vtxList[*vtxStartIndex + i], &vtxT);
if (i == 0) {
dyna->bgActors[bgId].minY = dyna->bgActors[bgId].maxY = vtxT.y;
} else if (vtxT.y < dyna->bgActors[bgId].minY) {
dyna->bgActors[bgId].minY = vtxT.y;
} else if (dyna->bgActors[bgId].maxY < vtxT.y) {
dyna->bgActors[bgId].maxY = vtxT.y;
}
newCenterPoint.x += vtxT.x;
newCenterPoint.y += vtxT.y;
newCenterPoint.z += vtxT.z;
}
newCenterPoint.x *= numVtxInverse;
newCenterPoint.y *= numVtxInverse;
newCenterPoint.z *= numVtxInverse;
sphere->center.x = newCenterPoint.x;
sphere->center.y = newCenterPoint.y;
sphere->center.z = newCenterPoint.z;
newRadiusSq = -SQ(10.0f);
for (i = 0; i < pbgdata->numVertices; i++) {
newVtx.x = dyna->vtxList[*vtxStartIndex + i].x;
newVtx.y = dyna->vtxList[*vtxStartIndex + i].y;
newVtx.z = dyna->vtxList[*vtxStartIndex + i].z;
radiusSq = Math3D_Vec3fDistSq(&newVtx, &newCenterPoint);
if (newRadiusSq < radiusSq) {
newRadiusSq = radiusSq;
}
}
sphere->radius = sqrtf(newRadiusSq) * 1.1f;
for (i = 0; i < pbgdata->numPolygons; i++) {
CollisionPoly* newPoly = &dyna->polyList[*polyStartIndex + i];
f32 newNormMagnitude;
*newPoly = pbgdata->polyList[i];
// Yeah, this is all kinds of fake, but my God, it matches.
newPoly->flags_vIA =
(COLPOLY_VTX_INDEX(newPoly->flags_vIA) + *vtxStartIndex) | COLPOLY_VTX_FLAGS_MASKED((*newPoly).flags_vIA);
newPoly->flags_vIB =
(COLPOLY_VTX_INDEX(newPoly->flags_vIB) + *vtxStartIndex) | COLPOLY_VTX_FLAGS_MASKED((*newPoly).flags_vIB);
newPoly->vIC = *vtxStartIndex + newPoly->vIC;
dVtxList = dyna->vtxList;
vtxA.x = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIA)].x;
vtxA.y = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIA)].y;
vtxA.z = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIA)].z;
vtxB.x = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIB)].x;
vtxB.y = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIB)].y;
vtxB.z = dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIB)].z;
vtxC.x = dVtxList[newPoly->vIC].x;
vtxC.y = dVtxList[newPoly->vIC].y;
vtxC.z = dVtxList[newPoly->vIC].z;
Math3D_SurfaceNorm(&vtxA, &vtxB, &vtxC, &newNormal);
newNormMagnitude = Math3D_Vec3fMagnitude(&newNormal);
if (!IS_ZERO(newNormMagnitude)) {
newNormal.x *= (1.0f / newNormMagnitude);
newNormal.y *= (1.0f / newNormMagnitude);
newNormal.z *= (1.0f / newNormMagnitude);
newPoly->normal.x = COLPOLY_SNORMAL(newNormal.x);
newPoly->normal.y = COLPOLY_SNORMAL(newNormal.y);
newPoly->normal.z = COLPOLY_SNORMAL(newNormal.z);
}
newPoly->dist = -DOTXYZ(newNormal, dVtxList[(u32)COLPOLY_VTX_INDEX(newPoly->flags_vIA)]);
if (newNormal.y > 0.5f) {
s16 polyId = *polyStartIndex + i;
DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.floor, &polyId);
} else if (newNormal.y < -0.8f) {
s16 polyId = *polyStartIndex + i;
DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.ceiling, &polyId);
} else {
s16 polyId = *polyStartIndex + i;
DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.wall, &polyId);
}
}
*polyStartIndex += pbgdata->numPolygons;
*vtxStartIndex += pbgdata->numVertices;
}
void DynaPoly_UnsetAllInteractFlags(PlayState* play, DynaCollisionContext* dyna, Actor* actor) {
@ -3155,7 +3176,7 @@ f32 BgCheck_RaycastDownDyna(DynaRaycastDown* dynaRaycastDown) {
s32 i2;
s32 isPaused;
DynaPolyActor* dynaActor;
s32 pad;
CollisionPoly* poly;
Vec3f polyVtx[3];
Vec3f polyNorm;
u32 polyIndex;
@ -3167,7 +3188,6 @@ f32 BgCheck_RaycastDownDyna(DynaRaycastDown* dynaRaycastDown) {
Vec3f vtx;
f32 intersect;
ScaleRotPos* curTransform;
CollisionPoly* poly;
result = BGCHECK_Y_MIN;
*dynaRaycastDown->bgId = BGCHECK_SCENE;
@ -3239,9 +3259,12 @@ f32 BgCheck_RaycastDownDyna(DynaRaycastDown* dynaRaycastDown) {
vtxList = dynaRaycastDown->dyna->bgActors[*dynaRaycastDown->bgId].colHeader->vtxList;
for (i2 = 0; i2 < 3; i2++) {
s32 pad;
Math_Vec3s_ToVec3f(&vtx, &vtxList[COLPOLY_VTX_INDEX(poly->vtxData[i2])]);
SkinMatrix_Vec3fMtxFMultXYZ(&srpMtx, &vtx, &polyVtx[i2]);
}
Math3D_SurfaceNorm(&polyVtx[0], &polyVtx[1], &polyVtx[2], &polyNorm);
magnitude = Math3D_Vec3fMagnitude(&polyNorm);
@ -3290,8 +3313,6 @@ s32 BgCheck_SphVsDynaWallInBgActor(CollisionContext* colCtx, u16 xpFlags, DynaCo
f32 invNormalXZ;
f32 planeDist;
f32 temp_f18;
f32 zIntersectDist;
f32 xIntersectDist;
f32 zMin;
f32 zMax;
f32 xMin;
@ -3360,8 +3381,10 @@ s32 BgCheck_SphVsDynaWallInBgActor(CollisionContext* colCtx, u16 xpFlags, DynaCo
}
}
if (CollisionPoly_CheckZIntersectApprox(poly, dyna->vtxList, resultPos.x, pos->y, &intersect)) {
if (fabsf(intersect - resultPos.z) <= radius / temp_f18) {
if ((intersect - resultPos.z) * nz <= 4.0f) {
f32 zIntersectDist = intersect - resultPos.z;
if (fabsf(zIntersectDist) <= radius / temp_f18) {
if (zIntersectDist * nz <= 4.0f) {
if (BgCheck_ComputeWallDisplacement(colCtx, poly, &resultPos.x, &resultPos.z, nx, ny, nz,
invNormalXZ, planeDist, radius, outPoly)) {
*outBgId = bgId;
@ -3434,7 +3457,8 @@ s32 BgCheck_SphVsDynaWallInBgActor(CollisionContext* colCtx, u16 xpFlags, DynaCo
}
if (CollisionPoly_CheckXIntersectApprox(poly, dyna->vtxList, pos->y, resultPos.z, &intersect)) {
xIntersectDist = intersect - resultPos.x;
f32 xIntersectDist = intersect - resultPos.x;
if (fabsf(xIntersectDist) <= radius / temp_f18) {
if (xIntersectDist * nx <= 4.0f) {
if (BgCheck_ComputeWallDisplacement(colCtx, poly, &resultPos.x, &resultPos.z, nx, ny, nz,
@ -4223,6 +4247,8 @@ f32 sZorasDomainWaterBoxMaxZ = -967.0f;
s32 WaterBox_GetSurface1(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface,
WaterBox** outWaterBox) {
if (play->sceneId == SCENE_ZORAS_DOMAIN) {
s32 pad;
if (sZorasDomainWaterBoxMinX < x && x < sZorasDomainWaterBoxMaxX && sZorasDomainWaterBoxMinY < *ySurface &&
*ySurface < sZorasDomainWaterBoxMaxY && sZorasDomainWaterBoxMinZ < z && z < sZorasDomainWaterBoxMaxZ) {
*outWaterBox = &sZorasDomainWaterBox;

View file

@ -7048,12 +7048,16 @@ void Camera_Init(Camera* camera, View* view, CollisionContext* colCtx, PlayState
R_CAM_DATA(i) = sCamDataRegsInit[i];
}
#if OOT_DEBUG
DebugCamera_Reset(camera, &D_8015BD80);
#endif
sInitRegs = false;
PREG(88) = -1;
}
camera->play = D_8015BD7C = play;
#if OOT_DEBUG
DebugCamera_Init(&D_8015BD80, camera);
#endif
curUID = sNextUID;
sNextUID++;
while (curUID != 0) {
@ -7722,7 +7726,9 @@ Vec3s Camera_Update(Camera* camera) {
if (CHECK_BTN_ALL(D_8015BD7C->state.input[2].press.button, BTN_START)) {
gDebugCamEnabled ^= 1;
if (gDebugCamEnabled) {
#if OOT_DEBUG
DebugCamera_Enable(&D_8015BD80, camera);
#endif
} else if (camera->play->csCtx.state != CS_STATE_IDLE) {
Cutscene_StopManual(camera->play, &camera->play->csCtx);
}
@ -7731,7 +7737,9 @@ Vec3s Camera_Update(Camera* camera) {
// Debug cam update
if (gDebugCamEnabled) {
camera->play->view.fovy = D_8015BD80.fov;
#if OOT_DEBUG
DebugCamera_Update(&D_8015BD80, camera);
#endif
View_LookAt(&camera->play->view, &D_8015BD80.eye, &D_8015BD80.at, &D_8015BD80.unk_1C);
if (R_DEBUG_CAM_UPDATE) {
PRINTF("camera: debug out\n");

View file

@ -1,7 +1,6 @@
#include "global.h"
// The use of ALIGNED8 here is just a temporary solution until the SaveContext is re-structured
ALIGNED8 SaveContext gSaveContext;
ALIGNED(16) SaveContext gSaveContext;
u32 D_8015FA88;
u32 D_8015FA8C;

View file

@ -29,6 +29,7 @@ Color_RGBA8 sDebugCamTextColors[] = {
{ 128, 255, 32, 128 }, // DEBUG_CAM_TEXT_GREEN
};
#if OOT_DEBUG
InputCombo sRegGroupInputCombos[REG_GROUPS] = {
{ BTN_L, BTN_CUP }, // REG
{ BTN_L, BTN_CLEFT }, // SREG
@ -93,6 +94,7 @@ char sRegGroupChars[REG_GROUPS] = {
'k', // kREG
'b', // bREG
};
#endif
void Regs_Init(void) {
s32 i;

View file

@ -40,6 +40,22 @@ Gfx sTransTileSetupDL[] = {
gsSPEndDisplayList(),
};
#define SET_VERTEX(vtx, x, y, z, s, t, nx, ny, nz, alpha) \
{ \
Vtx_tn* vtxn = &(vtx)->n; \
vtxn->ob[0] = (x); \
vtxn->ob[1] = (y); \
vtxn->ob[2] = (z); \
vtxn->flag = 0; \
vtxn->tc[0] = (s); \
vtxn->tc[1] = (t); \
vtxn->n[0] = (nx); \
vtxn->n[1] = (ny); \
vtxn->n[2] = (nz); \
vtxn->a = (alpha); \
} \
(void)0
void TransitionTile_InitGraphics(TransitionTile* this) {
s32 frame;
s32 col;
@ -61,20 +77,7 @@ void TransitionTile_InitGraphics(TransitionTile* this) {
for (row = 0; row < this->rows + 1; row++) {
colTex = 0;
for (col = 0; col < this->cols + 1; col++) {
Vtx_tn* vtxn = &vtx->n;
vtx++;
vtxn->tc[0] = colTex << 6;
vtxn->ob[0] = col * 0x20;
vtxn->ob[1] = row * 0x20;
vtxn->ob[2] = -5;
vtxn->flag = 0;
vtxn->tc[1] = rowTex << 6;
vtxn->n[0] = 0;
vtxn->n[1] = 0;
vtxn->n[2] = 120;
vtxn->a = 255;
SET_VERTEX(vtx++, col * 0x20, row * 0x20, -5, colTex << 6, rowTex << 6, 0, 0, 120, 255);
colTex += 0x20;
}

View file

@ -62,7 +62,7 @@ void TransitionFade_Update(void* thisx, s32 updateRate) {
break;
case TRANS_FADE_TYPE_ONE_WAY:
this->timer += updateRate;
((TransitionFade*)thisx)->timer += updateRate;
if (this->timer >= gSaveContext.transFadeDuration) {
this->timer = gSaveContext.transFadeDuration;
this->isDone = true;

View file

@ -162,6 +162,8 @@ void SkelCurve_DrawLimb(PlayState* play, s32 limbIndex, SkelCurve* skelCurve, Ov
OPEN_DISPS(play->state.gfxCtx, "../z_fcurve_data_skelanime.c", 279);
if (1) {}
Matrix_Push();
if ((overrideLimbDraw == NULL) ||

View file

@ -80,9 +80,10 @@ void KaleidoManager_Destroy(void) {
void* KaleidoManager_GetRamAddr(void* vram) {
KaleidoMgrOverlay* iter = gKaleidoMgrCurOvl;
KaleidoMgrOverlay* ovl = iter;
u32 i;
if (ovl == NULL) {
u32 i;
iter = &gKaleidoMgrOverlayTable[0];
for (i = 0; i < ARRAY_COUNT(gKaleidoMgrOverlayTable); i++) {
if (((uintptr_t)vram >= (uintptr_t)iter->vramStart) && ((uintptr_t)iter->vramEnd >= (uintptr_t)vram)) {

View file

@ -56,19 +56,25 @@ void KaleidoScopeCall_Update(PlayState* play) {
KaleidoMgrOverlay* kaleidoScopeOvl = &gKaleidoMgrOverlayTable[KALEIDO_OVL_KALEIDO_SCOPE];
PauseContext* pauseCtx = &play->pauseCtx;
if (IS_PAUSED(pauseCtx)) {
if (IS_PAUSED(&play->pauseCtx)) {
if (pauseCtx->state == PAUSE_STATE_WAIT_LETTERBOX) {
if (Letterbox_GetSize() == 0) {
#if OOT_DEBUG
R_HREG_MODE = HREG_MODE_UCODE_DISAS;
R_UCODE_DISAS_LOG_MODE = 3;
#endif
R_PAUSE_BG_PRERENDER_STATE = PAUSE_BG_PRERENDER_SETUP;
pauseCtx->mainState = PAUSE_MAIN_STATE_IDLE;
pauseCtx->savePromptState = PAUSE_SAVE_PROMPT_STATE_APPEARING;
pauseCtx->state = (pauseCtx->state & 0xFFFF) + 1; // PAUSE_STATE_WAIT_BG_PRERENDER
}
} else if (pauseCtx->state == PAUSE_STATE_8) {
#if OOT_DEBUG
R_HREG_MODE = HREG_MODE_UCODE_DISAS;
R_UCODE_DISAS_LOG_MODE = 3;
#endif
R_PAUSE_BG_PRERENDER_STATE = PAUSE_BG_PRERENDER_SETUP;
pauseCtx->mainState = PAUSE_MAIN_STATE_IDLE;
pauseCtx->savePromptState = PAUSE_SAVE_PROMPT_STATE_APPEARING;

View file

@ -50,7 +50,7 @@ void KaleidoSetup_Update(PlayState* play) {
(play->sceneId != SCENE_BOMBCHU_BOWLING_ALLEY || !Flags_GetSwitch(play, 0x38))) {
if (CHECK_BTN_ALL(input->cur.button, BTN_L) && CHECK_BTN_ALL(input->press.button, BTN_CUP)) {
if (BREG(0)) {
if (OOT_DEBUG && BREG(0)) {
pauseCtx->debugState = 3;
}
} else if (CHECK_BTN_ALL(input->press.button, BTN_START)) {
@ -102,22 +102,23 @@ void KaleidoSetup_Update(PlayState* play) {
void KaleidoSetup_Init(PlayState* play) {
PauseContext* pauseCtx = &play->pauseCtx;
u64 temp = 0; // Necessary to match
pauseCtx->state = PAUSE_STATE_OFF;
pauseCtx->debugState = 0;
pauseCtx->alpha = 0;
pauseCtx->switchPageTimer = 0;
pauseCtx->mainState = PAUSE_MAIN_STATE_IDLE;
pauseCtx->nextPageMode = 0;
pauseCtx->pageIndex = PAUSE_ITEM;
pauseCtx->itemPageRoll = pauseCtx->equipPageRoll = pauseCtx->mapPageRoll = pauseCtx->questPageRoll = 160.0f;
// Setting the eye xz here is irrelevant, it's set on pausing in KaleidoSetup_Update
// x = -PAUSE_EYE_DIST * PAUSE_ITEM_X
pauseCtx->eye.x = pauseCtx->eye.y = 0.0f;
pauseCtx->eye.z = -PAUSE_EYE_DIST * PAUSE_ITEM_Z;
pauseCtx->eye.y = 0.0f;
pauseCtx->eye.x = 0.0f; // -PAUSE_EYE_DIST * PAUSE_ITEM_X
pauseCtx->savePromptOffsetDepth_ = 936.0f;
pauseCtx->itemPageRoll = pauseCtx->equipPageRoll = pauseCtx->mapPageRoll = pauseCtx->questPageRoll = 160.0f;
pauseCtx->alpha = 0;
// mainState = PAUSE_MAIN_STATE_IDLE , pageIndex = PAUSE_ITEM
pauseCtx->switchPageTimer = pauseCtx->mainState = pauseCtx->nextPageMode = pauseCtx->pageIndex = 0;
pauseCtx->rollRotSavePrompt_ = -314.0f;
pauseCtx->cursorPoint[PAUSE_ITEM] = 0;
@ -130,8 +131,8 @@ void KaleidoSetup_Init(PlayState* play) {
pauseCtx->cursorY[PAUSE_ITEM] = 0;
pauseCtx->cursorX[PAUSE_MAP] = 0;
pauseCtx->cursorY[PAUSE_MAP] = 0;
pauseCtx->cursorX[PAUSE_QUEST] = temp;
pauseCtx->cursorY[PAUSE_QUEST] = temp;
pauseCtx->cursorX[PAUSE_QUEST] = 0;
pauseCtx->cursorY[PAUSE_QUEST] = 0;
pauseCtx->cursorX[PAUSE_EQUIP] = EQUIP_VALUE_SWORD_KOKIRI;
pauseCtx->cursorY[PAUSE_EQUIP] = EQUIP_TYPE_SWORD;

View file

@ -9,8 +9,10 @@ void func_8006EE50(Font* font, u16 arg1, u16 arg2) {
* at `codePointIndex`. The value of `character` is the ASCII codepoint subtract ' '/0x20.
*/
void Font_LoadChar(Font* font, u8 character, u16 codePointIndex) {
u8 charTmp = character;
DMA_REQUEST_SYNC(&font->charTexBuf[codePointIndex],
(uintptr_t)_nes_font_staticSegmentRomStart + character * FONT_CHAR_TEX_SIZE, FONT_CHAR_TEX_SIZE,
(uintptr_t)_nes_font_staticSegmentRomStart + charTmp * FONT_CHAR_TEX_SIZE, FONT_CHAR_TEX_SIZE,
"../z_kanfont.c", 93);
}
@ -31,10 +33,7 @@ void Font_LoadMessageBoxIcon(Font* font, u16 icon) {
* the font buffer.
*/
void Font_LoadOrderedFont(Font* font) {
u8* fontBuf;
uintptr_t fontStatic;
s32 len;
s32 jj;
s32 codePointIndex;
s32 fontBufIndex;
u32 offset;
@ -44,23 +43,22 @@ void Font_LoadOrderedFont(Font* font) {
DMA_REQUEST_SYNC(font->msgBuf, (uintptr_t)_nes_message_data_staticSegmentRomStart + font->msgOffset, len,
"../z_kanfont.c", 122);
PRINTF("msg_data=%x, msg_data0=%x jj=%x\n", font->msgOffset, font->msgLength, jj = len);
len = jj;
for (fontBufIndex = 0, codePointIndex = 0; font->msgBuf[codePointIndex] != MESSAGE_END; codePointIndex++) {
if (codePointIndex > len) {
PRINTF("msg_data=%x, msg_data0=%x jj=%x\n", font->msgOffset, font->msgLength, len * 1);
fontBufIndex = 0;
for (codePointIndex = 0; font->msgBuf[codePointIndex] != MESSAGE_END; codePointIndex++) {
if (codePointIndex > (len * 1)) {
PRINTF(" エラー!!! error───\n");
return;
}
if (font->msgBuf[codePointIndex] != MESSAGE_NEWLINE) {
fontBuf = font->fontBuf + fontBufIndex * 8;
fontStatic = (uintptr_t)_nes_font_staticSegmentRomStart;
PRINTF("nes_mes_buf[%d]=%d\n", codePointIndex, font->msgBuf[codePointIndex]);
offset = (font->msgBuf[codePointIndex] - ' ') * FONT_CHAR_TEX_SIZE;
DMA_REQUEST_SYNC(fontBuf, fontStatic + offset, FONT_CHAR_TEX_SIZE, "../z_kanfont.c", 134);
DMA_REQUEST_SYNC(font->fontBuf + fontBufIndex * 8, (uintptr_t)_nes_font_staticSegmentRomStart + offset,
FONT_CHAR_TEX_SIZE, "../z_kanfont.c", 134);
fontBufIndex += FONT_CHAR_TEX_SIZE / 8;
}
}

View file

@ -252,7 +252,8 @@ void Environment_Init(PlayState* play2, EnvironmentContext* envCtx, s32 unused)
gSaveContext.sunsSongState = SUNSSONG_INACTIVE;
if (((void)0, gSaveContext.save.dayTime) > CLOCK_TIME(18, 0) ||
//! FAKE: (void)0 on CLOCK_TIME(18, 0)
if (((void)0, gSaveContext.save.dayTime) > ((void)0, CLOCK_TIME(18, 0)) ||
((void)0, gSaveContext.save.dayTime) < CLOCK_TIME(6, 30)) {
((void)0, gSaveContext.save.nightFlag = 1);
} else {
@ -335,12 +336,17 @@ void Environment_Init(PlayState* play2, EnvironmentContext* envCtx, s32 unused)
envCtx->lightSettingOverride = LIGHT_SETTING_OVERRIDE_NONE;
envCtx->lightBlendRateOverride = LIGHT_BLENDRATE_OVERRIDE_NONE;
R_ENV_TIME_SPEED_OLD = gTimeSpeed = envCtx->sceneTimeSpeed = 0;
envCtx->sceneTimeSpeed = 0;
gTimeSpeed = envCtx->sceneTimeSpeed;
#if OOT_DEBUG
R_ENV_TIME_SPEED_OLD = gTimeSpeed;
R_ENV_DISABLE_DBG = true;
if (CREG(3) != 0) {
gSaveContext.chamberCutsceneNum = CREG(3) - 1;
}
#endif
play->envCtx.precipitation[PRECIP_RAIN_MAX] = 0;
play->envCtx.precipitation[PRECIP_RAIN_CUR] = 0;
@ -405,6 +411,7 @@ void Environment_Init(PlayState* play2, EnvironmentContext* envCtx, s32 unused)
gSkyboxIsChanging = false;
gSaveContext.retainWeatherMode = false;
#if OOT_DEBUG
R_ENV_LIGHT1_DIR(0) = 80;
R_ENV_LIGHT1_DIR(1) = 80;
R_ENV_LIGHT1_DIR(2) = 80;
@ -419,6 +426,8 @@ void Environment_Init(PlayState* play2, EnvironmentContext* envCtx, s32 unused)
cREG(12) = 0;
cREG(13) = 0;
cREG(14) = 0;
#endif
gUseCutsceneCam = true;
for (i = 0; i < ARRAY_COUNT(sLightningBolts); i++) {
@ -512,10 +521,9 @@ u8 Environment_SmoothStepToS8(s8* pvalue, s8 target, u8 scale, u8 step, u8 minSt
f32 Environment_LerpWeight(u16 max, u16 min, u16 val) {
f32 diff = max - min;
f32 ret;
if (diff != 0.0f) {
ret = 1.0f - (max - val) / diff;
f32 ret = 1.0f - (max - val) / diff;
if (!(ret >= 1.0f)) {
return ret;
@ -700,10 +708,12 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon
}
}
#if OOT_DEBUG
if (newSkybox1Index == 0xFF) {
// "Environment VR data acquisition failed! Report to Sasaki!"
PRINTF(VT_COL(RED, WHITE) "\n環境VRデータ取得失敗! ささきまでご報告を!" VT_RST);
}
#endif
if ((envCtx->skybox1Index != newSkybox1Index) && (envCtx->skyboxDmaState == SKYBOX_DMA_INACTIVE)) {
envCtx->skyboxDmaState = SKYBOX_DMA_TEXTURE1_START;
@ -815,6 +825,7 @@ void Environment_DisableUnderwaterLights(PlayState* play) {
}
}
#if OOT_DEBUG
void Environment_PrintDebugInfo(PlayState* play, Gfx** gfx) {
GfxPrint printer;
s32 pad[2];
@ -869,6 +880,7 @@ void Environment_PrintDebugInfo(PlayState* play, Gfx** gfx) {
*gfx = GfxPrint_Close(&printer);
GfxPrint_Destroy(&printer);
}
#endif
void Environment_PlayTimeBasedSequence(PlayState* play);
void Environment_UpdateRain(PlayState* play);
@ -881,7 +893,7 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex
u16 j;
u16 time;
EnvLightSettings* lightSettingsList = play->envCtx.lightSettingsList;
s32 adjustment;
u8 blendRate;
if ((((void)0, gSaveContext.gameMode) != GAMEMODE_NORMAL) &&
(((void)0, gSaveContext.gameMode) != GAMEMODE_END_CREDITS)) {
@ -951,6 +963,7 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex
gSaveContext.save.nightFlag = 0;
}
#if OOT_DEBUG
if (R_ENABLE_ARENA_DBG != 0 || CREG(2) != 0) {
Gfx* displayList;
Gfx* prevDisplayList;
@ -967,249 +980,247 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex
if (1) {}
CLOSE_DISPS(play->state.gfxCtx, "../z_kankyo.c", 1690);
}
#endif
if ((envCtx->lightSettingOverride != LIGHT_SETTING_OVERRIDE_NONE) &&
(envCtx->lightBlendOverride != LIGHT_BLEND_OVERRIDE_FULL_CONTROL) &&
(envCtx->lightSetting != envCtx->lightSettingOverride) && (envCtx->lightBlend >= 1.0f) &&
(envCtx->lightSettingOverride <= LIGHT_SETTING_MAX)) {
envCtx->lightBlend = 0.0f;
envCtx->prevLightSetting = envCtx->lightSetting;
envCtx->lightSetting = envCtx->lightSettingOverride;
envCtx->lightBlend = 0.0f;
}
if (envCtx->lightSettingOverride != LIGHT_SETTING_OVERRIDE_FULL_CONTROL) {
if ((envCtx->lightMode == LIGHT_MODE_TIME) &&
(envCtx->lightSettingOverride == LIGHT_SETTING_OVERRIDE_NONE)) {
for (i = 0; i < ARRAY_COUNT(sTimeBasedLightConfigs[envCtx->lightConfig]); i++) {
if ((gSaveContext.skyboxTime >= sTimeBasedLightConfigs[envCtx->lightConfig][i].startTime) &&
((gSaveContext.skyboxTime < sTimeBasedLightConfigs[envCtx->lightConfig][i].endTime) ||
sTimeBasedLightConfigs[envCtx->lightConfig][i].endTime == 0xFFFF)) {
u8 blend8[2];
s16 blend16[2];
if (envCtx->lightSettingOverride == LIGHT_SETTING_OVERRIDE_FULL_CONTROL) {
// Do nothing; Skip updating lights based on time or light settings
} else if ((envCtx->lightMode == LIGHT_MODE_TIME) &&
(envCtx->lightSettingOverride == LIGHT_SETTING_OVERRIDE_NONE)) {
for (i = 0; i < ARRAY_COUNT(sTimeBasedLightConfigs[envCtx->lightConfig]); i++) {
if ((gSaveContext.skyboxTime >= sTimeBasedLightConfigs[envCtx->lightConfig][i].startTime) &&
((gSaveContext.skyboxTime < sTimeBasedLightConfigs[envCtx->lightConfig][i].endTime) ||
sTimeBasedLightConfigs[envCtx->lightConfig][i].endTime == 0xFFFF)) {
u8 blend8[2];
s16 blend16[2];
timeChangeBlend =
Environment_LerpWeight(sTimeBasedLightConfigs[envCtx->lightConfig][i].endTime,
sTimeBasedLightConfigs[envCtx->lightConfig][i].startTime,
((void)0, gSaveContext.skyboxTime));
timeChangeBlend = Environment_LerpWeight(sTimeBasedLightConfigs[envCtx->lightConfig][i].endTime,
sTimeBasedLightConfigs[envCtx->lightConfig][i].startTime,
((void)0, gSaveContext.skyboxTime));
sSandstormColorIndex = sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting & 3;
sNextSandstormColorIndex = sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting & 3;
sSandstormLerpScale = timeChangeBlend;
sSandstormColorIndex = sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting & 3;
sNextSandstormColorIndex = sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting & 3;
sSandstormLerpScale = timeChangeBlend;
if (envCtx->changeLightEnabled) {
configChangeBlend =
((f32)envCtx->changeDuration - envCtx->changeLightTimer) / envCtx->changeDuration;
envCtx->changeLightTimer--;
if (envCtx->changeLightEnabled) {
configChangeBlend =
((f32)envCtx->changeDuration - envCtx->changeLightTimer) / envCtx->changeDuration;
envCtx->changeLightTimer--;
if (envCtx->changeLightTimer <= 0) {
envCtx->changeLightEnabled = false;
envCtx->lightConfig = envCtx->changeLightNextConfig;
}
if (envCtx->changeLightTimer <= 0) {
envCtx->changeLightEnabled = false;
envCtx->lightConfig = envCtx->changeLightNextConfig;
}
}
for (j = 0; j < 3; j++) {
// blend ambient color
blend8[0] =
LERP(lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting]
.ambientColor[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting]
.ambientColor[j],
timeChangeBlend);
blend8[1] = LERP(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting]
.ambientColor[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i]
.nextLightSetting]
.ambientColor[j],
timeChangeBlend);
*(envCtx->lightSettings.ambientColor + j) = LERP(blend8[0], blend8[1], configChangeBlend);
}
// set light1 direction for the sun
envCtx->lightSettings.light1Dir[0] =
-(Math_SinS(((void)0, gSaveContext.save.dayTime) - CLOCK_TIME(12, 0)) * 120.0f);
envCtx->lightSettings.light1Dir[1] =
Math_CosS(((void)0, gSaveContext.save.dayTime) - CLOCK_TIME(12, 0)) * 120.0f;
envCtx->lightSettings.light1Dir[2] =
Math_CosS(((void)0, gSaveContext.save.dayTime) - CLOCK_TIME(12, 0)) * 20.0f;
// set light2 direction for the moon
envCtx->lightSettings.light2Dir[0] = -envCtx->lightSettings.light1Dir[0];
envCtx->lightSettings.light2Dir[1] = -envCtx->lightSettings.light1Dir[1];
envCtx->lightSettings.light2Dir[2] = -envCtx->lightSettings.light1Dir[2];
for (j = 0; j < 3; j++) {
// blend light1Color
blend8[0] =
LERP(lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting]
.light1Color[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting]
.light1Color[j],
timeChangeBlend);
blend8[1] = LERP(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting]
.light1Color[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i]
.nextLightSetting]
.light1Color[j],
timeChangeBlend);
*(envCtx->lightSettings.light1Color + j) = LERP(blend8[0], blend8[1], configChangeBlend);
// blend light2Color
blend8[0] =
LERP(lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting]
.light2Color[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting]
.light2Color[j],
timeChangeBlend);
blend8[1] = LERP(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting]
.light2Color[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i]
.nextLightSetting]
.light2Color[j],
timeChangeBlend);
*(envCtx->lightSettings.light2Color + j) = LERP(blend8[0], blend8[1], configChangeBlend);
}
// blend fogColor
for (j = 0; j < 3; j++) {
blend8[0] =
LERP(lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting]
.fogColor[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting]
.fogColor[j],
timeChangeBlend);
blend8[1] = LERP(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting]
.fogColor[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i]
.nextLightSetting]
.fogColor[j],
timeChangeBlend);
*(envCtx->lightSettings.fogColor + j) = LERP(blend8[0], blend8[1], configChangeBlend);
}
blend16[0] = LERP16(
ENV_LIGHT_SETTINGS_FOG_NEAR(
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting]
.blendRateAndFogNear),
ENV_LIGHT_SETTINGS_FOG_NEAR(
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting]
.blendRateAndFogNear),
timeChangeBlend);
blend16[1] = LERP16(
ENV_LIGHT_SETTINGS_FOG_NEAR(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting]
.blendRateAndFogNear),
ENV_LIGHT_SETTINGS_FOG_NEAR(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i]
.nextLightSetting]
.blendRateAndFogNear),
timeChangeBlend);
envCtx->lightSettings.fogNear = LERP16(blend16[0], blend16[1], configChangeBlend);
blend16[0] = LERP16(
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting].zFar,
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting].zFar,
timeChangeBlend);
blend16[1] = LERP16(
for (j = 0; j < 3; j++) {
// blend ambient color
blend8[0] =
LERP(lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting]
.ambientColor[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting]
.ambientColor[j],
timeChangeBlend);
blend8[1] = LERP(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting]
.zFar,
.ambientColor[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting]
.zFar,
.ambientColor[j],
timeChangeBlend);
envCtx->lightSettings.zFar = LERP16(blend16[0], blend16[1], configChangeBlend);
if (sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting >=
envCtx->numLightSettings) {
// "The color palette setting seems to be wrong!"
PRINTF(VT_COL(RED, WHITE) "\nカラーパレットの設定がおかしいようです!" VT_RST);
// "Palette setting = [] Last palette number = []"
PRINTF(VT_COL(RED, WHITE) "\n設定パレット=[%d] 最後パレット番号=[%d]\n" VT_RST,
sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting,
envCtx->numLightSettings - 1);
}
break;
}
}
} else {
if (!envCtx->lightBlendEnabled) {
for (i = 0; i < 3; i++) {
envCtx->lightSettings.ambientColor[i] = lightSettingsList[envCtx->lightSetting].ambientColor[i];
envCtx->lightSettings.light1Dir[i] = lightSettingsList[envCtx->lightSetting].light1Dir[i];
envCtx->lightSettings.light1Color[i] = lightSettingsList[envCtx->lightSetting].light1Color[i];
envCtx->lightSettings.light2Dir[i] = lightSettingsList[envCtx->lightSetting].light2Dir[i];
envCtx->lightSettings.light2Color[i] = lightSettingsList[envCtx->lightSetting].light2Color[i];
envCtx->lightSettings.fogColor[i] = lightSettingsList[envCtx->lightSetting].fogColor[i];
envCtx->lightSettings.ambientColor[j] = LERP(blend8[0], blend8[1], configChangeBlend);
}
envCtx->lightSettings.fogNear =
ENV_LIGHT_SETTINGS_FOG_NEAR(lightSettingsList[envCtx->lightSetting].blendRateAndFogNear);
envCtx->lightSettings.zFar = lightSettingsList[envCtx->lightSetting].zFar;
envCtx->lightBlend = 1.0f;
} else {
u8 blendRate =
ENV_LIGHT_SETTINGS_BLEND_RATE_U8(lightSettingsList[envCtx->lightSetting].blendRateAndFogNear);
// set light1 direction for the sun
envCtx->lightSettings.light1Dir[0] =
-(Math_SinS(((void)0, gSaveContext.save.dayTime) - CLOCK_TIME(12, 0)) * 120.0f);
envCtx->lightSettings.light1Dir[1] =
Math_CosS(((void)0, gSaveContext.save.dayTime) - CLOCK_TIME(12, 0)) * 120.0f;
envCtx->lightSettings.light1Dir[2] =
Math_CosS(((void)0, gSaveContext.save.dayTime) - CLOCK_TIME(12, 0)) * 20.0f;
if (blendRate == 0) {
blendRate++;
// set light2 direction for the moon
envCtx->lightSettings.light2Dir[0] = -envCtx->lightSettings.light1Dir[0];
envCtx->lightSettings.light2Dir[1] = -envCtx->lightSettings.light1Dir[1];
envCtx->lightSettings.light2Dir[2] = -envCtx->lightSettings.light1Dir[2];
for (j = 0; j < 3; j++) {
// blend light1Color
blend8[0] =
LERP(lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting]
.light1Color[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting]
.light1Color[j],
timeChangeBlend);
blend8[1] = LERP(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting]
.light1Color[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting]
.light1Color[j],
timeChangeBlend);
envCtx->lightSettings.light1Color[j] = LERP(blend8[0], blend8[1], configChangeBlend);
// blend light2Color
blend8[0] =
LERP(lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting]
.light2Color[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting]
.light2Color[j],
timeChangeBlend);
blend8[1] = LERP(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting]
.light2Color[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting]
.light2Color[j],
timeChangeBlend);
envCtx->lightSettings.light2Color[j] = LERP(blend8[0], blend8[1], configChangeBlend);
}
if (envCtx->lightBlendRateOverride != LIGHT_BLENDRATE_OVERRIDE_NONE) {
blendRate = envCtx->lightBlendRateOverride;
// blend fogColor
for (j = 0; j < 3; j++) {
blend8[0] = LERP(
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting].fogColor[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting]
.fogColor[j],
timeChangeBlend);
blend8[1] = LERP(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting]
.fogColor[j],
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting]
.fogColor[j],
timeChangeBlend);
envCtx->lightSettings.fogColor[j] = LERP(blend8[0], blend8[1], configChangeBlend);
}
if (envCtx->lightBlendOverride == LIGHT_BLEND_OVERRIDE_NONE) {
envCtx->lightBlend += blendRate / 255.0f;
blend16[0] =
LERP16(ENV_LIGHT_SETTINGS_FOG_NEAR(
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting]
.blendRateAndFogNear),
ENV_LIGHT_SETTINGS_FOG_NEAR(
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting]
.blendRateAndFogNear),
timeChangeBlend);
blend16[1] = LERP16(
ENV_LIGHT_SETTINGS_FOG_NEAR(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting]
.blendRateAndFogNear),
ENV_LIGHT_SETTINGS_FOG_NEAR(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting]
.blendRateAndFogNear),
timeChangeBlend);
envCtx->lightSettings.fogNear = LERP16(blend16[0], blend16[1], configChangeBlend);
blend16[0] =
LERP16(lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].lightSetting].zFar,
lightSettingsList[sTimeBasedLightConfigs[envCtx->lightConfig][i].nextLightSetting].zFar,
timeChangeBlend);
blend16[1] = LERP16(
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].lightSetting].zFar,
lightSettingsList[sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting]
.zFar,
timeChangeBlend);
envCtx->lightSettings.zFar = LERP16(blend16[0], blend16[1], configChangeBlend);
#if OOT_DEBUG
if (sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting >=
envCtx->numLightSettings) {
// "The color palette setting seems to be wrong!"
PRINTF(VT_COL(RED, WHITE) "\nカラーパレットの設定がおかしいようです!" VT_RST);
// "Palette setting = [] Last palette number = []"
PRINTF(VT_COL(RED, WHITE) "\n設定パレット=[%d] 最後パレット番号=[%d]\n" VT_RST,
sTimeBasedLightConfigs[envCtx->changeLightNextConfig][i].nextLightSetting,
envCtx->numLightSettings - 1);
}
#endif
if (envCtx->lightBlend > 1.0f) {
envCtx->lightBlend = 1.0f;
}
for (i = 0; i < 3; i++) {
envCtx->lightSettings.ambientColor[i] =
LERP(lightSettingsList[envCtx->prevLightSetting].ambientColor[i],
lightSettingsList[envCtx->lightSetting].ambientColor[i], envCtx->lightBlend);
envCtx->lightSettings.light1Dir[i] =
LERP16(lightSettingsList[envCtx->prevLightSetting].light1Dir[i],
lightSettingsList[envCtx->lightSetting].light1Dir[i], envCtx->lightBlend);
envCtx->lightSettings.light1Color[i] =
LERP(lightSettingsList[envCtx->prevLightSetting].light1Color[i],
lightSettingsList[envCtx->lightSetting].light1Color[i], envCtx->lightBlend);
envCtx->lightSettings.light2Dir[i] =
LERP16(lightSettingsList[envCtx->prevLightSetting].light2Dir[i],
lightSettingsList[envCtx->lightSetting].light2Dir[i], envCtx->lightBlend);
envCtx->lightSettings.light2Color[i] =
LERP(lightSettingsList[envCtx->prevLightSetting].light2Color[i],
lightSettingsList[envCtx->lightSetting].light2Color[i], envCtx->lightBlend);
envCtx->lightSettings.fogColor[i] =
LERP(lightSettingsList[envCtx->prevLightSetting].fogColor[i],
lightSettingsList[envCtx->lightSetting].fogColor[i], envCtx->lightBlend);
}
envCtx->lightSettings.fogNear = LERP16(
ENV_LIGHT_SETTINGS_FOG_NEAR(lightSettingsList[envCtx->prevLightSetting].blendRateAndFogNear),
ENV_LIGHT_SETTINGS_FOG_NEAR(lightSettingsList[envCtx->lightSetting].blendRateAndFogNear),
envCtx->lightBlend);
envCtx->lightSettings.zFar =
LERP16(lightSettingsList[envCtx->prevLightSetting].zFar,
lightSettingsList[envCtx->lightSetting].zFar, envCtx->lightBlend);
}
if (envCtx->lightSetting >= envCtx->numLightSettings) {
// "The color palette seems to be wrong!"
PRINTF("\n" VT_FGCOL(RED) "カラーパレットがおかしいようです!");
// "Palette setting = [] Last palette number = []"
PRINTF("\n" VT_FGCOL(YELLOW) "設定パレット=[%d] パレット数=[%d]\n" VT_RST, envCtx->lightSetting,
envCtx->numLightSettings);
break;
}
}
} else {
if (!envCtx->lightBlendEnabled) {
for (i = 0; i < 3; i++) {
envCtx->lightSettings.ambientColor[i] = lightSettingsList[envCtx->lightSetting].ambientColor[i];
envCtx->lightSettings.light1Dir[i] = lightSettingsList[envCtx->lightSetting].light1Dir[i];
envCtx->lightSettings.light1Color[i] = lightSettingsList[envCtx->lightSetting].light1Color[i];
envCtx->lightSettings.light2Dir[i] = lightSettingsList[envCtx->lightSetting].light2Dir[i];
envCtx->lightSettings.light2Color[i] = lightSettingsList[envCtx->lightSetting].light2Color[i];
envCtx->lightSettings.fogColor[i] = lightSettingsList[envCtx->lightSetting].fogColor[i];
}
envCtx->lightSettings.fogNear =
ENV_LIGHT_SETTINGS_FOG_NEAR(lightSettingsList[envCtx->lightSetting].blendRateAndFogNear);
envCtx->lightSettings.zFar = lightSettingsList[envCtx->lightSetting].zFar;
envCtx->lightBlend = 1.0f;
} else {
blendRate =
ENV_LIGHT_SETTINGS_BLEND_RATE_U8(lightSettingsList[envCtx->lightSetting].blendRateAndFogNear);
if (blendRate == 0) {
blendRate++;
}
if (envCtx->lightBlendRateOverride != LIGHT_BLENDRATE_OVERRIDE_NONE) {
blendRate = envCtx->lightBlendRateOverride;
}
if (envCtx->lightBlendOverride == LIGHT_BLEND_OVERRIDE_NONE) {
envCtx->lightBlend += blendRate / 255.0f;
}
if (envCtx->lightBlend > 1.0f) {
envCtx->lightBlend = 1.0f;
}
for (i = 0; i < 3; i++) {
envCtx->lightSettings.ambientColor[i] =
LERP(lightSettingsList[envCtx->prevLightSetting].ambientColor[i],
lightSettingsList[envCtx->lightSetting].ambientColor[i], envCtx->lightBlend);
envCtx->lightSettings.light1Dir[i] =
LERP16(lightSettingsList[envCtx->prevLightSetting].light1Dir[i],
lightSettingsList[envCtx->lightSetting].light1Dir[i], envCtx->lightBlend);
envCtx->lightSettings.light1Color[i] =
LERP(lightSettingsList[envCtx->prevLightSetting].light1Color[i],
lightSettingsList[envCtx->lightSetting].light1Color[i], envCtx->lightBlend);
envCtx->lightSettings.light2Dir[i] =
LERP16(lightSettingsList[envCtx->prevLightSetting].light2Dir[i],
lightSettingsList[envCtx->lightSetting].light2Dir[i], envCtx->lightBlend);
envCtx->lightSettings.light2Color[i] =
LERP(lightSettingsList[envCtx->prevLightSetting].light2Color[i],
lightSettingsList[envCtx->lightSetting].light2Color[i], envCtx->lightBlend);
envCtx->lightSettings.fogColor[i] =
LERP(lightSettingsList[envCtx->prevLightSetting].fogColor[i],
lightSettingsList[envCtx->lightSetting].fogColor[i], envCtx->lightBlend);
}
envCtx->lightSettings.fogNear =
LERP16(ENV_LIGHT_SETTINGS_FOG_NEAR(lightSettingsList[envCtx->prevLightSetting].blendRateAndFogNear),
ENV_LIGHT_SETTINGS_FOG_NEAR(lightSettingsList[envCtx->lightSetting].blendRateAndFogNear),
envCtx->lightBlend);
envCtx->lightSettings.zFar = LERP16(lightSettingsList[envCtx->prevLightSetting].zFar,
lightSettingsList[envCtx->lightSetting].zFar, envCtx->lightBlend);
}
#if OOT_DEBUG
if (envCtx->lightSetting >= envCtx->numLightSettings) {
// "The color palette seems to be wrong!"
PRINTF("\n" VT_FGCOL(RED) "カラーパレットがおかしいようです!");
// "Palette setting = [] Last palette number = []"
PRINTF("\n" VT_FGCOL(YELLOW) "設定パレット=[%d] パレット数=[%d]\n" VT_RST, envCtx->lightSetting,
envCtx->numLightSettings);
}
#endif
}
envCtx->lightBlendEnabled = true;
@ -1261,22 +1272,20 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex
envCtx->dirLight2.params.dir.z = envCtx->lightSettings.light2Dir[2];
// Adjust fog near and far if necessary
adjustment = envCtx->lightSettings.fogNear + envCtx->adjFogNear;
if (adjustment <= ENV_FOGNEAR_MAX) {
lightCtx->fogNear = adjustment;
if ((envCtx->lightSettings.fogNear + envCtx->adjFogNear) <= ENV_FOGNEAR_MAX) {
lightCtx->fogNear = envCtx->lightSettings.fogNear + envCtx->adjFogNear;
} else {
lightCtx->fogNear = ENV_FOGNEAR_MAX;
}
adjustment = envCtx->lightSettings.zFar + envCtx->adjZFar;
if (adjustment <= ENV_ZFAR_MAX) {
lightCtx->zFar = adjustment;
if ((envCtx->lightSettings.zFar + envCtx->adjZFar) <= ENV_ZFAR_MAX) {
lightCtx->zFar = envCtx->lightSettings.zFar + envCtx->adjZFar;
} else {
lightCtx->zFar = ENV_ZFAR_MAX;
}
#if OOT_DEBUG
// When environment debug is enabled, various environment related variables can be configured via the reg editor
if (R_ENV_DISABLE_DBG) {
R_ENV_AMBIENT_COLOR(0) = lightCtx->ambientColor[0];
@ -1357,6 +1366,7 @@ void Environment_Update(PlayState* play, EnvironmentContext* envCtx, LightContex
envCtx->windDirection.z = R_ENV_WIND_DIR(2);
envCtx->windSpeed = R_ENV_WIND_SPEED;
}
#endif
if ((envCtx->dirLight1.params.dir.x == 0) && (envCtx->dirLight1.params.dir.y == 0) &&
(envCtx->dirLight1.params.dir.z == 0)) {
@ -2366,9 +2376,6 @@ void Environment_DrawSandstorm(PlayState* play, u8 sandstormState) {
Color_RGBA8 envColor;
s32 pad;
f32 sp98;
u16 sp96;
u16 sp94;
u16 sp92;
switch (sandstormState) {
case SANDSTORM_ACTIVE:
@ -2475,25 +2482,27 @@ void Environment_DrawSandstorm(PlayState* play, u8 sandstormState) {
envColor.g = ((envColor.g * sp98) + ((6.0f - sp98) * primColor.g)) * (1.0f / 6.0f);
envColor.b = ((envColor.b * sp98) + ((6.0f - sp98) * primColor.b)) * (1.0f / 6.0f);
sp96 = (s32)(sSandstormScroll * (11.0f / 6.0f));
sp94 = (s32)(sSandstormScroll * (9.0f / 6.0f));
sp92 = (s32)(sSandstormScroll * (6.0f / 6.0f));
{
u16 sp96 = (s32)(sSandstormScroll * (11.0f / 6.0f));
u16 sp94 = (s32)(sSandstormScroll * (9.0f / 6.0f));
u16 sp92 = (s32)(sSandstormScroll * (6.0f / 6.0f));
OPEN_DISPS(play->state.gfxCtx, "../z_kankyo.c", 4044);
OPEN_DISPS(play->state.gfxCtx, "../z_kankyo.c", 4044);
POLY_XLU_DISP = Gfx_SetupDL_64(POLY_XLU_DISP);
POLY_XLU_DISP = Gfx_SetupDL_64(POLY_XLU_DISP);
gDPSetAlphaDither(POLY_XLU_DISP++, G_AD_NOISE);
gDPSetColorDither(POLY_XLU_DISP++, G_CD_NOISE);
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0x80, primColor.r, primColor.g, primColor.b, play->envCtx.sandstormPrimA);
gDPSetEnvColor(POLY_XLU_DISP++, envColor.r, envColor.g, envColor.b, play->envCtx.sandstormEnvA);
gSPSegment(POLY_XLU_DISP++, 0x08,
Gfx_TwoTexScroll(play->state.gfxCtx, G_TX_RENDERTILE, (u32)sp96 % 4096, 0, 512, 32, 1, (u32)sp94 % 4096,
4095 - ((u32)sp92 % 4096), 256, 64));
gDPSetTextureLUT(POLY_XLU_DISP++, G_TT_NONE);
gSPDisplayList(POLY_XLU_DISP++, gFieldSandstormDL);
gDPSetAlphaDither(POLY_XLU_DISP++, G_AD_NOISE);
gDPSetColorDither(POLY_XLU_DISP++, G_CD_NOISE);
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0x80, primColor.r, primColor.g, primColor.b, play->envCtx.sandstormPrimA);
gDPSetEnvColor(POLY_XLU_DISP++, envColor.r, envColor.g, envColor.b, play->envCtx.sandstormEnvA);
gSPSegment(POLY_XLU_DISP++, 0x08,
Gfx_TwoTexScroll(play->state.gfxCtx, G_TX_RENDERTILE, (u32)sp96 % 4096, 0, 512, 32, 1,
(u32)sp94 % 4096, 4095 - ((u32)sp92 % 4096), 256, 64));
gDPSetTextureLUT(POLY_XLU_DISP++, G_TT_NONE);
gSPDisplayList(POLY_XLU_DISP++, gFieldSandstormDL);
CLOSE_DISPS(play->state.gfxCtx, "../z_kankyo.c", 4068);
CLOSE_DISPS(play->state.gfxCtx, "../z_kankyo.c", 4068);
}
sSandstormScroll += (s32)sp98;
}

View file

@ -35,7 +35,7 @@ void* ZeldaArena_Malloc(u32 size) {
}
#if OOT_DEBUG
void* ZeldaArena_MallocDebug(u32 size, const char* file, s32 line) {
void* ZeldaArena_MallocDebug(u32 size, const char* file, int line) {
void* ptr = __osMallocDebug(&sZeldaArena, size, file, line);
ZELDA_ARENA_CHECK_POINTER(ptr, size, "zelda_malloc_DEBUG", "確保"); // "Secure"
@ -51,7 +51,7 @@ void* ZeldaArena_MallocR(u32 size) {
}
#if OOT_DEBUG
void* ZeldaArena_MallocRDebug(u32 size, const char* file, s32 line) {
void* ZeldaArena_MallocRDebug(u32 size, const char* file, int line) {
void* ptr = __osMallocRDebug(&sZeldaArena, size, file, line);
ZELDA_ARENA_CHECK_POINTER(ptr, size, "zelda_malloc_r_DEBUG", "確保"); // "Secure"
@ -66,7 +66,7 @@ void* ZeldaArena_Realloc(void* ptr, u32 newSize) {
}
#if OOT_DEBUG
void* ZeldaArena_ReallocDebug(void* ptr, u32 newSize, const char* file, s32 line) {
void* ZeldaArena_ReallocDebug(void* ptr, u32 newSize, const char* file, int line) {
ptr = __osReallocDebug(&sZeldaArena, ptr, newSize, file, line);
ZELDA_ARENA_CHECK_POINTER(ptr, newSize, "zelda_realloc_DEBUG", "再確保"); // "Re-securing"
return ptr;
@ -78,7 +78,7 @@ void ZeldaArena_Free(void* ptr) {
}
#if OOT_DEBUG
void ZeldaArena_FreeDebug(void* ptr, const char* file, s32 line) {
void ZeldaArena_FreeDebug(void* ptr, const char* file, int line) {
__osFreeDebug(&sZeldaArena, ptr, file, line);
}
#endif

View file

@ -118,8 +118,8 @@ void MapMark_DrawForDungeon(PlayState* play) {
markInfo->textureWidth, markInfo->textureHeight, 0, G_TX_NOMIRROR | G_TX_WRAP,
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
rectLeft = (GREG(94) + markPoint->x + 204) << 2;
rectTop = (GREG(95) + markPoint->y + 140) << 2;
rectLeft = ((OOT_DEBUG ? GREG(94) : 0) + markPoint->x + 204) << 2;
rectTop = ((OOT_DEBUG ? GREG(95) : 0) + markPoint->y + 140) << 2;
gSPTextureRectangle(OVERLAY_DISP++, rectLeft, rectTop, markInfo->rectWidth + rectLeft,
rectTop + markInfo->rectHeight, G_TX_RENDERTILE, 0, 0, markInfo->dsdx,
markInfo->dtdy);

View file

@ -291,17 +291,15 @@ void Message_GrowTextbox(MessageContext* msgCtx) {
void Message_FindMessage(PlayState* play, u16 textId) {
const char* foundSeg;
const char* nextSeg;
Font* font = &play->msgCtx.font;
MessageTableEntry* messageTableEntry = sNesMessageEntryTablePtr;
const char** languageSegmentTable;
Font* font;
const char* seg;
if (gSaveContext.language == LANGUAGE_ENG) {
seg = messageTableEntry->segment;
while (messageTableEntry->textId != 0xFFFF) {
font = &play->msgCtx.font;
if (messageTableEntry->textId == textId) {
foundSeg = messageTableEntry->segment;
font->charTexBuf[0] = messageTableEntry->typePos;
@ -323,8 +321,6 @@ void Message_FindMessage(PlayState* play, u16 textId) {
seg = messageTableEntry->segment;
while (messageTableEntry->textId != 0xFFFF) {
font = &play->msgCtx.font;
if (messageTableEntry->textId == textId) {
foundSeg = *languageSegmentTable;
font->charTexBuf[0] = messageTableEntry->typePos;
@ -344,7 +340,6 @@ void Message_FindMessage(PlayState* play, u16 textId) {
}
// "Message not found!!!"
PRINTF(" メッセージが,見つからなかった!!! = %x\n", textId);
font = &play->msgCtx.font;
messageTableEntry = sNesMessageEntryTablePtr;
if (gSaveContext.language == LANGUAGE_ENG) {
@ -368,13 +363,11 @@ void Message_FindCreditsMessage(PlayState* play, u16 textId) {
const char* foundSeg;
const char* nextSeg;
const char* seg;
Font* font = &play->msgCtx.font;
MessageTableEntry* messageTableEntry = sStaffMessageEntryTablePtr;
Font* font;
seg = messageTableEntry->segment;
while (messageTableEntry->textId != 0xFFFF) {
font = &play->msgCtx.font;
if (messageTableEntry->textId == textId) {
foundSeg = messageTableEntry->segment;
font->charTexBuf[0] = messageTableEntry->typePos;
@ -981,7 +974,8 @@ void Message_DrawText(PlayState* play, Gfx** gfxP) {
sMessageHasSetSfx = true;
// "Sound (SE)"
PRINTF("サウンド(SE)\n");
sfxHi = msgCtx->msgBufDecoded[i + 1] << 8;
sfxHi = msgCtx->msgBufDecoded[i + 1];
sfxHi <<= 8;
Audio_PlaySfxGeneral(sfxHi | msgCtx->msgBufDecoded[i + 2], &gSfxDefaultPos, 4,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
}
@ -1369,8 +1363,8 @@ void Message_Decode(PlayState* play) {
}
if (loadChar) {
Font_LoadChar(font, digits[i] + '0' - ' ', charTexIdx);
msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0';
charTexIdx += FONT_CHAR_TEX_SIZE;
msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0';
PRINTF("%x(%x) ", digits[i] + '0' - ' ', digits[i]);
decodedBufPos++;
}
@ -1390,8 +1384,8 @@ void Message_Decode(PlayState* play) {
for (i = 0; i < 2; i++) {
if (i == 1 || digits[i] != 0) {
Font_LoadChar(font, digits[i] + '0' - ' ', charTexIdx);
msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0';
charTexIdx += FONT_CHAR_TEX_SIZE;
msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0';
PRINTF("%x(%x) ", digits[i] + '0' - ' ', digits[i]);
decodedBufPos++;
}
@ -1579,9 +1573,10 @@ void Message_OpenText(PlayState* play, u16 textId) {
Font* font = &msgCtx->font;
s16 textBoxType;
if (msgCtx->msgMode == MSGMODE_NONE) {
gSaveContext.prevHudVisibilityMode = gSaveContext.hudVisibilityMode;
}
// clang-format off
if (msgCtx->msgMode == MSGMODE_NONE) { gSaveContext.prevHudVisibilityMode = gSaveContext.hudVisibilityMode; }
// clang-format on
if (R_SCENE_CAM_TYPE == SCENE_CAM_TYPE_FIXED_SHOP_VIEWPOINT) {
Interface_ChangeHudVisibilityMode(HUD_VISIBILITY_A_HEARTS_MAGIC_FORCE);
}
@ -1707,6 +1702,7 @@ void Message_StartTextbox(PlayState* play, u16 textId, Actor* actor) {
}
void Message_ContinueTextbox(PlayState* play, u16 textId) {
s32 pad;
MessageContext* msgCtx = &play->msgCtx;
PRINTF(VT_FGCOL(GREEN));
@ -2951,6 +2947,7 @@ void Message_DrawMain(PlayState* play, Gfx** p) {
*p = gfx;
}
#if OOT_DEBUG
/**
* If the s16 variable pointed to by `var` changes in value, a black bar and white box
* are briefly drawn onto the screen. It can only watch one variable per build due to
@ -3002,14 +2999,19 @@ void Message_DrawDebugText(PlayState* play, Gfx** p) {
*p = GfxPrint_Close(&printer);
GfxPrint_Destroy(&printer);
}
#endif
void Message_Draw(PlayState* play) {
Gfx* plusOne;
Gfx* polyOpaP;
#if OOT_DEBUG
s16 watchVar;
#endif
OPEN_DISPS(play->state.gfxCtx, "../z_message_PAL.c", 3554);
#if OOT_DEBUG
watchVar = gSaveContext.save.info.scarecrowLongSongSet;
Message_DrawDebugVariableChanged(&watchVar, play->state.gfxCtx);
if (BREG(0) != 0 && play->msgCtx.textId != 0) {
@ -3021,6 +3023,8 @@ void Message_Draw(PlayState* play) {
POLY_OPA_DISP = plusOne;
}
if (1) {}
#endif
plusOne = Gfx_Open(polyOpaP = POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, plusOne);
Message_DrawMain(play, &plusOne);
@ -3063,6 +3067,7 @@ void Message_Update(PlayState* play) {
s16 playerFocusScreenPosY;
s16 actorFocusScreenPosY;
#if OOT_DEBUG
if (BREG(0) != 0) {
if (CHECK_BTN_ALL(input->press.button, BTN_DDOWN) && CHECK_BTN_ALL(input->cur.button, BTN_L)) {
PRINTF("msgno=%d\n", D_80153D78);
@ -3088,256 +3093,257 @@ void Message_Update(PlayState* play) {
}
}
}
#endif
if (msgCtx->msgLength == 0) {
return;
}
if (msgCtx->msgLength != 0) {
switch (msgCtx->msgMode) {
case MSGMODE_TEXT_START:
D_8014B2F4++;
switch (msgCtx->msgMode) {
case MSGMODE_TEXT_START:
D_8014B2F4++;
var = false;
if (R_SCENE_CAM_TYPE == SCENE_CAM_TYPE_FIXED_MARKET) {
if (D_8014B2F4 >= 4) {
var = false;
if (R_SCENE_CAM_TYPE == SCENE_CAM_TYPE_FIXED_MARKET) {
if (D_8014B2F4 >= 4) {
var = true;
}
} else if (R_SCENE_CAM_TYPE != SCENE_CAM_TYPE_DEFAULT ||
play->sceneId == SCENE_CASTLE_COURTYARD_GUARDS_DAY) {
var = true;
} else if (D_8014B2F4 >= 4 || msgCtx->talkActor == NULL) {
var = true;
}
} else if (R_SCENE_CAM_TYPE != SCENE_CAM_TYPE_DEFAULT ||
play->sceneId == SCENE_CASTLE_COURTYARD_GUARDS_DAY) {
var = true;
} else if (D_8014B2F4 >= 4 || msgCtx->talkActor == NULL) {
var = true;
}
if (var) {
if (msgCtx->talkActor != NULL) {
Actor_GetScreenPos(play, &GET_PLAYER(play)->actor, &focusScreenPosX, &playerFocusScreenPosY);
Actor_GetScreenPos(play, msgCtx->talkActor, &focusScreenPosX, &actorFocusScreenPosY);
if (var) {
if (msgCtx->talkActor != NULL) {
Actor_GetScreenPos(play, &GET_PLAYER(play)->actor, &focusScreenPosX, &playerFocusScreenPosY);
Actor_GetScreenPos(play, msgCtx->talkActor, &focusScreenPosX, &actorFocusScreenPosY);
if (playerFocusScreenPosY >= actorFocusScreenPosY) {
averageY = ((playerFocusScreenPosY - actorFocusScreenPosY) / 2) + actorFocusScreenPosY;
if (playerFocusScreenPosY >= actorFocusScreenPosY) {
averageY = ((playerFocusScreenPosY - actorFocusScreenPosY) / 2) + actorFocusScreenPosY;
} else {
averageY = ((actorFocusScreenPosY - playerFocusScreenPosY) / 2) + playerFocusScreenPosY;
}
PRINTF("dxpos=%d dypos=%d dypos1 dypos2=%d\n", focusScreenPosX, averageY,
playerFocusScreenPosY, actorFocusScreenPosY);
} else {
averageY = ((actorFocusScreenPosY - playerFocusScreenPosY) / 2) + playerFocusScreenPosY;
R_TEXTBOX_X = R_TEXTBOX_X_TARGET;
R_TEXTBOX_Y = R_TEXTBOX_Y_TARGET;
}
PRINTF("dxpos=%d dypos=%d dypos1 dypos2=%d\n", focusScreenPosX, averageY, playerFocusScreenPosY,
actorFocusScreenPosY);
} else {
R_TEXTBOX_X = R_TEXTBOX_X_TARGET;
R_TEXTBOX_Y = R_TEXTBOX_Y_TARGET;
}
var = msgCtx->textBoxType;
var = msgCtx->textBoxType;
if (!msgCtx->textBoxPos) { // variable position
if (R_SCENE_CAM_TYPE != SCENE_CAM_TYPE_DEFAULT ||
play->sceneId == SCENE_CASTLE_COURTYARD_GUARDS_DAY) {
if (averageY < XREG(92)) {
R_TEXTBOX_Y_TARGET = sTextboxLowerYPositions[var];
if (!msgCtx->textBoxPos) { // variable position
if (R_SCENE_CAM_TYPE != SCENE_CAM_TYPE_DEFAULT ||
play->sceneId == SCENE_CASTLE_COURTYARD_GUARDS_DAY) {
if (averageY < XREG(92)) {
R_TEXTBOX_Y_TARGET = sTextboxLowerYPositions[var];
} else {
R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var];
}
} else if (play->sceneId == SCENE_MARKET_DAY || play->sceneId == SCENE_MARKET_NIGHT ||
play->sceneId == SCENE_MARKET_RUINS) {
if (averageY < XREG(93)) {
R_TEXTBOX_Y_TARGET = sTextboxLowerYPositions[var];
} else {
R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var];
}
} else {
R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var];
}
} else if (play->sceneId == SCENE_MARKET_DAY || play->sceneId == SCENE_MARKET_NIGHT ||
play->sceneId == SCENE_MARKET_RUINS) {
if (averageY < XREG(93)) {
R_TEXTBOX_Y_TARGET = sTextboxLowerYPositions[var];
} else {
R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var];
if (averageY < XREG(94)) {
R_TEXTBOX_Y_TARGET = sTextboxLowerYPositions[var];
} else {
R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var];
}
}
} else if (msgCtx->textBoxPos == TEXTBOX_POS_TOP) {
R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var];
} else if (msgCtx->textBoxPos == TEXTBOX_POS_MIDDLE) {
R_TEXTBOX_Y_TARGET = sTextboxMidYPositions[var];
} else {
if (averageY < XREG(94)) {
R_TEXTBOX_Y_TARGET = sTextboxLowerYPositions[var];
} else {
R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var];
}
R_TEXTBOX_Y_TARGET = sTextboxLowerYPositions[var];
}
} else if (msgCtx->textBoxPos == TEXTBOX_POS_TOP) {
R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var];
} else if (msgCtx->textBoxPos == TEXTBOX_POS_MIDDLE) {
R_TEXTBOX_Y_TARGET = sTextboxMidYPositions[var];
} else {
R_TEXTBOX_Y_TARGET = sTextboxLowerYPositions[var];
}
R_TEXTBOX_X_TARGET = sTextboxXPositions[var];
R_TEXTBOX_END_YPOS = sTextboxEndIconYOffset[var] + R_TEXTBOX_Y_TARGET;
R_TEXT_CHOICE_YPOS(0) = R_TEXTBOX_Y_TARGET + 20;
R_TEXT_CHOICE_YPOS(1) = R_TEXTBOX_Y_TARGET + 32;
R_TEXT_CHOICE_YPOS(2) = R_TEXTBOX_Y_TARGET + 44;
PRINTF("message->msg_disp_type=%x\n", msgCtx->textBoxProperties & 0xF0);
if (msgCtx->textBoxType == TEXTBOX_TYPE_NONE_BOTTOM ||
msgCtx->textBoxType == TEXTBOX_TYPE_NONE_NO_SHADOW) {
msgCtx->msgMode = MSGMODE_TEXT_STARTING;
R_TEXTBOX_X = R_TEXTBOX_X_TARGET;
R_TEXTBOX_Y = R_TEXTBOX_Y_TARGET;
R_TEXTBOX_WIDTH = 256;
R_TEXTBOX_HEIGHT = 64;
R_TEXTBOX_TEXWIDTH = 512;
R_TEXTBOX_TEXHEIGHT = 512;
} else {
Message_GrowTextbox(msgCtx);
Audio_PlaySfxIfNotInCutscene(NA_SE_NONE);
msgCtx->stateTimer = 0;
msgCtx->msgMode = MSGMODE_TEXT_BOX_GROWING;
R_TEXTBOX_X_TARGET = sTextboxXPositions[var];
R_TEXTBOX_END_YPOS = sTextboxEndIconYOffset[var] + R_TEXTBOX_Y_TARGET;
R_TEXT_CHOICE_YPOS(0) = R_TEXTBOX_Y_TARGET + 20;
R_TEXT_CHOICE_YPOS(1) = R_TEXTBOX_Y_TARGET + 32;
R_TEXT_CHOICE_YPOS(2) = R_TEXTBOX_Y_TARGET + 44;
PRINTF("message->msg_disp_type=%x\n", msgCtx->textBoxProperties & 0xF0);
if (msgCtx->textBoxType == TEXTBOX_TYPE_NONE_BOTTOM ||
msgCtx->textBoxType == TEXTBOX_TYPE_NONE_NO_SHADOW) {
msgCtx->msgMode = MSGMODE_TEXT_STARTING;
R_TEXTBOX_X = R_TEXTBOX_X_TARGET;
R_TEXTBOX_Y = R_TEXTBOX_Y_TARGET;
R_TEXTBOX_WIDTH = 256;
R_TEXTBOX_HEIGHT = 64;
R_TEXTBOX_TEXWIDTH = 512;
R_TEXTBOX_TEXHEIGHT = 512;
} else {
Message_GrowTextbox(msgCtx);
Audio_PlaySfxIfNotInCutscene(NA_SE_NONE);
msgCtx->stateTimer = 0;
msgCtx->msgMode = MSGMODE_TEXT_BOX_GROWING;
}
}
}
break;
case MSGMODE_TEXT_BOX_GROWING:
Message_GrowTextbox(msgCtx);
break;
case MSGMODE_TEXT_STARTING:
msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG;
if (YREG(31) == 0) {
Interface_SetDoAction(play, DO_ACTION_NEXT);
}
break;
case MSGMODE_TEXT_NEXT_MSG:
Message_Decode(play);
if (sTextFade) {
Interface_ChangeHudVisibilityMode(HUD_VISIBILITY_NOTHING);
}
if (D_80153D74 != 0) {
msgCtx->textDrawPos = msgCtx->decodedTextLen;
D_80153D74 = 0;
}
break;
case MSGMODE_TEXT_CONTINUING:
msgCtx->stateTimer--;
if (msgCtx->stateTimer == 0) {
break;
case MSGMODE_TEXT_BOX_GROWING:
Message_GrowTextbox(msgCtx);
break;
case MSGMODE_TEXT_STARTING:
msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG;
if (YREG(31) == 0) {
Interface_SetDoAction(play, DO_ACTION_NEXT);
}
break;
case MSGMODE_TEXT_NEXT_MSG:
Message_Decode(play);
}
break;
case MSGMODE_TEXT_DISPLAYING:
if (msgCtx->textBoxType != TEXTBOX_TYPE_NONE_BOTTOM && YREG(31) == 0 &&
CHECK_BTN_ALL(play->state.input[0].press.button, BTN_B) && !msgCtx->textUnskippable) {
sTextboxSkipped = true;
msgCtx->textDrawPos = msgCtx->decodedTextLen;
}
break;
case MSGMODE_TEXT_AWAIT_INPUT:
if (YREG(31) == 0 && Message_ShouldAdvance(play)) {
msgCtx->msgMode = MSGMODE_TEXT_DISPLAYING;
msgCtx->textDrawPos++;
}
break;
case MSGMODE_TEXT_DELAYED_BREAK:
msgCtx->stateTimer--;
if (msgCtx->stateTimer == 0) {
msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG;
}
break;
case MSGMODE_TEXT_AWAIT_NEXT:
if (Message_ShouldAdvance(play)) {
msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG;
msgCtx->textUnskippable = false;
msgCtx->msgBufPos++;
}
break;
case MSGMODE_TEXT_DONE:
if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_FADING) {
if (sTextFade) {
Interface_ChangeHudVisibilityMode(HUD_VISIBILITY_NOTHING);
}
if (D_80153D74 != 0) {
msgCtx->textDrawPos = msgCtx->decodedTextLen;
D_80153D74 = 0;
}
break;
case MSGMODE_TEXT_CONTINUING:
msgCtx->stateTimer--;
if (msgCtx->stateTimer == 0) {
Message_CloseTextbox(play);
Message_Decode(play);
}
} else if (msgCtx->textboxEndType != TEXTBOX_ENDTYPE_PERSISTENT &&
msgCtx->textboxEndType != TEXTBOX_ENDTYPE_EVENT && YREG(31) == 0) {
if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_2_CHOICE && play->msgCtx.ocarinaMode == OCARINA_MODE_01) {
if (Message_ShouldAdvance(play)) {
PRINTF("OCARINA_MODE=%d -> ", play->msgCtx.ocarinaMode);
play->msgCtx.ocarinaMode = (msgCtx->choiceIndex == 0) ? OCARINA_MODE_02 : OCARINA_MODE_04;
PRINTF("InRaceSeq=%d(%d) OCARINA_MODE=%d --> ", GET_EVENTINF_HORSES_STATE(), 1,
play->msgCtx.ocarinaMode);
Message_CloseTextbox(play);
PRINTF("OCARINA_MODE=%d\n", play->msgCtx.ocarinaMode);
}
} else if (Message_ShouldAdvanceSilent(play)) {
PRINTF("select=%d\n", msgCtx->textboxEndType);
if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_HAS_NEXT) {
Audio_PlaySfxGeneral(NA_SE_SY_MESSAGE_PASS, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
Message_ContinueTextbox(play, sNextTextId);
} else {
Audio_PlaySfxGeneral(NA_SE_SY_DECIDE, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
Message_CloseTextbox(play);
}
}
}
break;
case MSGMODE_TEXT_CLOSING:
msgCtx->stateTimer--;
if (msgCtx->stateTimer != 0) {
break;
}
if ((msgCtx->textId >= 0xC2 && msgCtx->textId < 0xC7) ||
(msgCtx->textId >= 0xFA && msgCtx->textId < 0xFE)) {
gSaveContext.healthAccumulator = 0x140; // Refill 20 hearts
}
if (msgCtx->textId == 0x301F || msgCtx->textId == 0xA || msgCtx->textId == 0xC || msgCtx->textId == 0xCF ||
msgCtx->textId == 0x21C || msgCtx->textId == 9 || msgCtx->textId == 0x4078 ||
msgCtx->textId == 0x2015 || msgCtx->textId == 0x3040) {
gSaveContext.prevHudVisibilityMode = HUD_VISIBILITY_ALL;
}
if (play->csCtx.state == 0) {
PRINTF(VT_FGCOL(GREEN));
PRINTF("day_time=%x active_camera=%d ", gSaveContext.save.cutsceneIndex, play->activeCamId);
if (msgCtx->textId != 0x2061 && msgCtx->textId != 0x2025 && msgCtx->textId != 0x208C &&
((msgCtx->textId < 0x88D || msgCtx->textId >= 0x893) || msgCtx->choiceIndex != 0) &&
(msgCtx->textId != 0x3055 && gSaveContext.save.cutsceneIndex < 0xFFF0)) {
PRINTF("=== day_time=%x ", ((void)0, gSaveContext.save.cutsceneIndex));
if (play->activeCamId == CAM_ID_MAIN) {
if (gSaveContext.prevHudVisibilityMode == HUD_VISIBILITY_NO_CHANGE ||
gSaveContext.prevHudVisibilityMode == HUD_VISIBILITY_NOTHING ||
gSaveContext.prevHudVisibilityMode == HUD_VISIBILITY_NOTHING_ALT) {
gSaveContext.prevHudVisibilityMode = HUD_VISIBILITY_ALL;
case MSGMODE_TEXT_DISPLAYING:
if (msgCtx->textBoxType != TEXTBOX_TYPE_NONE_BOTTOM && YREG(31) == 0 &&
CHECK_BTN_ALL(play->state.input[0].press.button, BTN_B) && !msgCtx->textUnskippable) {
sTextboxSkipped = true;
msgCtx->textDrawPos = msgCtx->decodedTextLen;
}
break;
case MSGMODE_TEXT_AWAIT_INPUT:
if (YREG(31) == 0 && Message_ShouldAdvance(play)) {
msgCtx->msgMode = MSGMODE_TEXT_DISPLAYING;
msgCtx->textDrawPos++;
}
break;
case MSGMODE_TEXT_DELAYED_BREAK:
msgCtx->stateTimer--;
if (msgCtx->stateTimer == 0) {
msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG;
}
break;
case MSGMODE_TEXT_AWAIT_NEXT:
if (Message_ShouldAdvance(play)) {
msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG;
msgCtx->textUnskippable = false;
msgCtx->msgBufPos++;
}
break;
case MSGMODE_TEXT_DONE:
if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_FADING) {
msgCtx->stateTimer--;
if (msgCtx->stateTimer == 0) {
Message_CloseTextbox(play);
}
} else if (msgCtx->textboxEndType != TEXTBOX_ENDTYPE_PERSISTENT &&
msgCtx->textboxEndType != TEXTBOX_ENDTYPE_EVENT && YREG(31) == 0) {
if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_2_CHOICE &&
play->msgCtx.ocarinaMode == OCARINA_MODE_01) {
if (Message_ShouldAdvance(play)) {
PRINTF("OCARINA_MODE=%d -> ", play->msgCtx.ocarinaMode);
play->msgCtx.ocarinaMode = (msgCtx->choiceIndex == 0) ? OCARINA_MODE_02 : OCARINA_MODE_04;
PRINTF("InRaceSeq=%d(%d) OCARINA_MODE=%d --> ", GET_EVENTINF_HORSES_STATE(), 1,
play->msgCtx.ocarinaMode);
Message_CloseTextbox(play);
PRINTF("OCARINA_MODE=%d\n", play->msgCtx.ocarinaMode);
}
} else if (Message_ShouldAdvanceSilent(play)) {
PRINTF("select=%d\n", msgCtx->textboxEndType);
if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_HAS_NEXT) {
Audio_PlaySfxGeneral(NA_SE_SY_MESSAGE_PASS, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
Message_ContinueTextbox(play, sNextTextId);
} else {
Audio_PlaySfxGeneral(NA_SE_SY_DECIDE, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
Message_CloseTextbox(play);
}
gSaveContext.hudVisibilityMode = HUD_VISIBILITY_NO_CHANGE;
Interface_ChangeHudVisibilityMode(gSaveContext.prevHudVisibilityMode);
}
}
}
PRINTF(VT_RST);
msgCtx->msgLength = 0;
msgCtx->msgMode = MSGMODE_NONE;
interfaceCtx->unk_1FA = interfaceCtx->unk_1FC = 0;
msgCtx->textId = msgCtx->stateTimer = 0;
break;
case MSGMODE_TEXT_CLOSING:
msgCtx->stateTimer--;
if (msgCtx->stateTimer != 0) {
break;
}
if ((msgCtx->textId >= 0xC2 && msgCtx->textId < 0xC7) ||
(msgCtx->textId >= 0xFA && msgCtx->textId < 0xFE)) {
gSaveContext.healthAccumulator = 0x140; // Refill 20 hearts
}
if (msgCtx->textId == 0x301F || msgCtx->textId == 0xA || msgCtx->textId == 0xC ||
msgCtx->textId == 0xCF || msgCtx->textId == 0x21C || msgCtx->textId == 9 ||
msgCtx->textId == 0x4078 || msgCtx->textId == 0x2015 || msgCtx->textId == 0x3040) {
gSaveContext.prevHudVisibilityMode = HUD_VISIBILITY_ALL;
}
if (play->csCtx.state == 0) {
PRINTF(VT_FGCOL(GREEN));
PRINTF("day_time=%x active_camera=%d ", gSaveContext.save.cutsceneIndex, play->activeCamId);
if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_PERSISTENT) {
msgCtx->textboxEndType = TEXTBOX_ENDTYPE_DEFAULT;
play->msgCtx.ocarinaMode = OCARINA_MODE_02;
} else {
msgCtx->textboxEndType = TEXTBOX_ENDTYPE_DEFAULT;
}
if ((s32)(gSaveContext.save.info.inventory.questItems & 0xF0000000) == (4 << QUEST_HEART_PIECE_COUNT)) {
gSaveContext.save.info.inventory.questItems ^= (4 << QUEST_HEART_PIECE_COUNT);
gSaveContext.save.info.playerData.healthCapacity += 0x10;
gSaveContext.save.info.playerData.health += 0x10;
}
if (msgCtx->ocarinaAction != OCARINA_ACTION_CHECK_NOWARP_DONE) {
if (sLastPlayedSong == OCARINA_SONG_SARIAS) {
//! @bug The last played song is not unset often, and if something interrupts the message system
// before it reaches this point after playing Saria's song, the song will be "stored".
// Later, if the ocarina has not been played and another textbox is closed, this handling
// for Saria's song will be carried out.
player->naviTextId = -0xE0;
player->naviActor->flags |= ACTOR_FLAG_16;
}
if (msgCtx->ocarinaAction == OCARINA_ACTION_FREE_PLAY_DONE &&
(play->msgCtx.ocarinaMode == OCARINA_MODE_01 || play->msgCtx.ocarinaMode == OCARINA_MODE_0B)) {
play->msgCtx.ocarinaMode = OCARINA_MODE_04;
if (msgCtx->unk_E3F2 == OCARINA_SONG_SUNS) {
play->msgCtx.ocarinaMode = OCARINA_MODE_01;
if (msgCtx->textId != 0x2061 && msgCtx->textId != 0x2025 && msgCtx->textId != 0x208C &&
((msgCtx->textId < 0x88D || msgCtx->textId >= 0x893) || msgCtx->choiceIndex != 0) &&
(msgCtx->textId != 0x3055 && gSaveContext.save.cutsceneIndex < 0xFFF0)) {
PRINTF("=== day_time=%x ", ((void)0, gSaveContext.save.cutsceneIndex));
if (play->activeCamId == CAM_ID_MAIN) {
if (gSaveContext.prevHudVisibilityMode == HUD_VISIBILITY_NO_CHANGE ||
gSaveContext.prevHudVisibilityMode == HUD_VISIBILITY_NOTHING ||
gSaveContext.prevHudVisibilityMode == HUD_VISIBILITY_NOTHING_ALT) {
gSaveContext.prevHudVisibilityMode = HUD_VISIBILITY_ALL;
}
gSaveContext.hudVisibilityMode = HUD_VISIBILITY_NO_CHANGE;
Interface_ChangeHudVisibilityMode(gSaveContext.prevHudVisibilityMode);
}
}
}
}
sLastPlayedSong = 0xFF;
PRINTF("OCARINA_MODE=%d chk_ocarina_no=%d\n", play->msgCtx.ocarinaMode, msgCtx->unk_E3F2);
break;
case MSGMODE_PAUSED:
break;
default:
msgCtx->lastOcarinaButtonIndex = OCARINA_BTN_INVALID;
break;
PRINTF(VT_RST);
msgCtx->msgLength = 0;
msgCtx->msgMode = MSGMODE_NONE;
interfaceCtx->unk_1FA = interfaceCtx->unk_1FC = 0;
msgCtx->textId = msgCtx->stateTimer = 0;
if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_PERSISTENT) {
msgCtx->textboxEndType = TEXTBOX_ENDTYPE_DEFAULT;
play->msgCtx.ocarinaMode = OCARINA_MODE_02;
} else {
msgCtx->textboxEndType = TEXTBOX_ENDTYPE_DEFAULT;
}
if ((s32)(gSaveContext.save.info.inventory.questItems & 0xF0000000) == (4 << QUEST_HEART_PIECE_COUNT)) {
gSaveContext.save.info.inventory.questItems ^= (4 << QUEST_HEART_PIECE_COUNT);
gSaveContext.save.info.playerData.healthCapacity += 0x10;
gSaveContext.save.info.playerData.health += 0x10;
}
if (msgCtx->ocarinaAction != OCARINA_ACTION_CHECK_NOWARP_DONE) {
if (sLastPlayedSong == OCARINA_SONG_SARIAS) {
//! @bug The last played song is not unset often, and if something interrupts the message system
// before it reaches this point after playing Saria's song, the song will be "stored".
// Later, if the ocarina has not been played and another textbox is closed, this handling
// for Saria's song will be carried out.
player->naviTextId = -0xE0;
player->naviActor->flags |= ACTOR_FLAG_16;
}
if (msgCtx->ocarinaAction == OCARINA_ACTION_FREE_PLAY_DONE &&
(play->msgCtx.ocarinaMode == OCARINA_MODE_01 || play->msgCtx.ocarinaMode == OCARINA_MODE_0B)) {
play->msgCtx.ocarinaMode = OCARINA_MODE_04;
if (msgCtx->unk_E3F2 == OCARINA_SONG_SUNS) {
play->msgCtx.ocarinaMode = OCARINA_MODE_01;
}
}
}
sLastPlayedSong = 0xFF;
PRINTF("OCARINA_MODE=%d chk_ocarina_no=%d\n", play->msgCtx.ocarinaMode, msgCtx->unk_E3F2);
break;
case MSGMODE_PAUSED:
break;
default:
msgCtx->lastOcarinaButtonIndex = OCARINA_BTN_INVALID;
break;
}
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -10,9 +10,12 @@ TransitionTile sTransitionTile;
s32 gTransitionTileState;
VisMono sPlayVisMono;
Color_RGBA8_u32 gVisMonoColor;
#if OOT_DEBUG
FaultClient D_801614B8;
#endif
s16 sTransitionFillTimer;
u64 sDebugCutsceneScriptBuf[0xA00];
void Play_SpawnScene(PlayState* this, s32 sceneId, s32 spawn);
@ -451,7 +454,10 @@ void Play_Init(GameState* thisx) {
AnimationContext_Update(this, &this->animationCtx);
gSaveContext.respawnFlag = 0;
if (OOT_DEBUG && R_USE_DEBUG_CUTSCENE) {
#if OOT_DEBUG
if (R_USE_DEBUG_CUTSCENE) {
static u64 sDebugCutsceneScriptBuf[0xA00];
gDebugCutsceneScript = sDebugCutsceneScriptBuf;
PRINTF("\nkawauso_data=[%x]", gDebugCutsceneScript);
@ -459,6 +465,7 @@ void Play_Init(GameState* thisx) {
// Presumably the ROM was larger at a previous point in development when this debug feature was used.
DmaMgr_DmaRomToRam(0x03FEB000, gDebugCutsceneScript, sizeof(sDebugCutsceneScriptBuf));
}
#endif
}
void Play_Update(PlayState* this) {

View file

@ -152,6 +152,7 @@ void SkelAnime_DrawFlexLimbLod(PlayState* play, s32 limbIndex, void** skeleton,
}
(*mtx)++;
} else if (limbDList != NULL) {
if (1) {}
MATRIX_TO_MTX(*mtx, "../z_skelanime.c", 954);
(*mtx)++;
}
@ -366,6 +367,7 @@ void SkelAnime_DrawFlexLimbOpa(PlayState* play, s32 limbIndex, void** skeleton,
gSPDisplayList(POLY_OPA_DISP++, newDList);
(*limbMatrices)++;
} else if (limbDList != NULL) {
if (1) {}
MATRIX_TO_MTX(*limbMatrices, "../z_skelanime.c", 1249);
(*limbMatrices)++;
}
@ -467,7 +469,7 @@ void SkelAnime_GetFrameData(AnimationHeader* animation, s32 frame, s32 limbCount
u16 staticIndexMax = animHeader->staticIndexMax;
s32 i;
for (i = 0; i < limbCount; i++, frameTable++, jointIndices++) {
for (i = 0; i < limbCount; i++) {
if ((frameTable == NULL) || (jointIndices == NULL) || (dynamicData == NULL) || (staticData == NULL)) {
LOG_ADDRESS("out", frameTable, "../z_skelanime.c", 1392);
LOG_ADDRESS("ref_tbl", jointIndices, "../z_skelanime.c", 1393);
@ -481,6 +483,8 @@ void SkelAnime_GetFrameData(AnimationHeader* animation, s32 frame, s32 limbCount
(jointIndices->y >= staticIndexMax) ? dynamicData[jointIndices->y] : staticData[jointIndices->y];
frameTable->z =
(jointIndices->z >= staticIndexMax) ? dynamicData[jointIndices->z] : staticData[jointIndices->z];
jointIndices++;
frameTable++;
}
}
@ -1024,10 +1028,11 @@ void AnimationContext_Update(PlayState* play, AnimationContext* animationCtx) {
AnimationContext_LoadFrame, AnimationContext_CopyAll, AnimationContext_Interp,
AnimationContext_CopyTrue, AnimationContext_CopyFalse, AnimationContext_MoveActor,
};
AnimationEntry* entry;
AnimationEntry* entry = animationCtx->entries;
for (entry = animationCtx->entries; animationCtx->animationCount != 0; entry++, animationCtx->animationCount--) {
for (; animationCtx->animationCount != 0; animationCtx->animationCount--) {
animFuncs[entry->type](play, &entry->data);
entry++;
}
sAnimQueueFlags = 1;

View file

@ -511,8 +511,7 @@ void Sram_WriteSave(SramContext* sramCtx) {
gSaveContext.save.info.checksum = 0;
ptr = (u16*)&gSaveContext;
checksum = 0;
j = 0;
checksum = j = 0;
for (offset = 0; offset < CHECKSUM_SIZE; offset++) {
if (++j == 0x20) {
@ -612,12 +611,15 @@ void Sram_VerifyAndLoadAllSaves(FileSelectState* fileSelect, SramContext* sramCt
bzero(&gSaveContext.save.entranceIndex, sizeof(s32));
bzero(&gSaveContext.save.linkAge, sizeof(s32));
bzero(&gSaveContext.save.cutsceneIndex, sizeof(s32));
// note that gSaveContext.save.dayTime is not actually the sizeof(s32)
//! @bug gSaveContext.save.dayTime is a u16 but is cleared as a 32-bit value. This is harmless as-is
//! since it is followed by nightFlag which is also reset here, but can become an issue if the save
//! layout is changed.
bzero(&gSaveContext.save.dayTime, sizeof(s32));
bzero(&gSaveContext.save.nightFlag, sizeof(s32));
bzero(&gSaveContext.save.totalDays, sizeof(s32));
bzero(&gSaveContext.save.bgsDayCount, sizeof(s32));
#if OOT_DEBUG
if (!slotNum) {
Sram_InitDebugSave();
gSaveContext.save.info.playerData.newf[0] = 'Z';
@ -633,6 +635,9 @@ void Sram_VerifyAndLoadAllSaves(FileSelectState* fileSelect, SramContext* sramCt
} else {
Sram_InitNewSave();
}
#else
Sram_InitNewSave();
#endif
ptr = (u16*)&gSaveContext;
PRINTF("\n--------------------------------------------------------------\n");
@ -718,20 +723,26 @@ void Sram_InitSave(FileSelectState* fileSelect, SramContext* sramCtx) {
u16* ptr;
u16 checksum;
#if OOT_DEBUG
if (fileSelect->buttonIndex != 0) {
Sram_InitNewSave();
} else {
Sram_InitDebugSave();
}
#else
Sram_InitNewSave();
#endif
gSaveContext.save.entranceIndex = ENTR_LINKS_HOUSE_0;
gSaveContext.save.linkAge = LINK_AGE_CHILD;
gSaveContext.save.dayTime = CLOCK_TIME(10, 0);
gSaveContext.save.cutsceneIndex = 0xFFF1;
#if OOT_DEBUG
if (fileSelect->buttonIndex == 0) {
gSaveContext.save.cutsceneIndex = 0;
}
#endif
for (offset = 0; offset < 8; offset++) {
gSaveContext.save.info.playerData.playerName[offset] = fileSelect->fileNames[fileSelect->buttonIndex][offset];
@ -753,10 +764,8 @@ void Sram_InitSave(FileSelectState* fileSelect, SramContext* sramCtx) {
PRINTF("\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
ptr = (u16*)&gSaveContext;
j = 0;
checksum = 0;
for (offset = 0; offset < CHECKSUM_SIZE; offset++) {
for (j = 0, checksum = 0, offset = 0; offset < CHECKSUM_SIZE; offset++) {
PRINTF("%x ", *ptr);
checksum += *ptr++;
if (++j == 0x20) {
@ -893,6 +902,7 @@ void Sram_InitSram(GameState* gameState, SramContext* sramCtx) {
Sram_WriteSramHeader(sramCtx);
}
#if OOT_DEBUG
if (CHECK_BTN_ANY(gameState->input[2].cur.button, BTN_DRIGHT)) {
bzero(sramCtx->readBuff, SRAM_SIZE);
for (i = 0; i < CHECKSUM_SIZE; i++) {
@ -901,6 +911,7 @@ void Sram_InitSram(GameState* gameState, SramContext* sramCtx) {
SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_WRITE);
PRINTF("SRAM破壊!!!!!!\n"); // "SRAM destruction! ! ! ! ! !"
}
#endif
// "GOOD! GOOD! Size = %d + %d = %d"
PRINTF(" サイズ=%d + %d %d\n", sizeof(SaveInfo), 4, sizeof(SaveInfo) + 4);

View file

@ -9,7 +9,7 @@ typedef struct {
SsSramContext sSsSramContext = { 0 };
void SsSram_Init(u32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8 handlePageSize, u8 handleRelDuration,
void SsSram_Init(s32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8 handlePageSize, u8 handleRelDuration,
u8 handlePulse, u32 handleSpeed) {
u32 prevInt;
OSPiHandle* handle = &sSsSramContext.piHandle;
@ -49,7 +49,7 @@ void SsSram_Dma(void* dramAddr, size_t size, s32 direction) {
osInvalDCache(dramAddr, size);
}
void SsSram_ReadWrite(u32 addr, void* dramAddr, size_t size, s32 direction) {
void SsSram_ReadWrite(s32 addr, void* dramAddr, size_t size, s32 direction) {
PRINTF("ssSRAMReadWrite:%08x %08x %08x %d\n", addr, dramAddr, size, direction);
SsSram_Init(addr, DEVICE_TYPE_SRAM, PI_DOMAIN2, 5, 0xD, 2, 0xC, 0);
SsSram_Dma(dramAddr, size, direction);

View file

@ -47,14 +47,18 @@ extern u16 D_0E000000[];
void VisZBuf_Init(VisZBuf* this) {
this->vis.type = VIS_ZBUF_TYPE_IA;
this->vis.scissorType = VIS_NO_SETSCISSOR;
this->vis.primColor.r = 255;
this->vis.primColor.g = 255;
this->vis.primColor.b = 255;
this->vis.primColor.a = 255;
// clang-format off
this->vis.envColor.r = 0; \
this->vis.envColor.g = 0; \
this->vis.envColor.b = 0; \
this->vis.envColor.a = 255;
this->vis.envColor.r = 0;
this->vis.envColor.g = 0;
this->vis.envColor.b = 0;
// clang-format on
}
void VisZBuf_Destroy(VisZBuf* this) {