diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000000..241e560df6
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,2 @@
+*
+
diff --git a/Dockerfile b/Dockerfile
index bea63cb110..edc487ef68 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM ubuntu:21.10 as build
+FROM ubuntu:22.04 as build
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
@@ -26,5 +26,7 @@ ENV LANG C.UTF-8
RUN mkdir /oot
WORKDIR /oot
+RUN git config --global --add safe.directory /oot
+
CMD ["/bin/sh", "-c", \
"echo 'usage:\n docker run --rm --mount type=bind,source=\"$(pwd)\",destination=/oot oot make -j$(nproc) setup\n docker run --rm --mount type=bind,source=\"$(pwd)\",destination=/oot oot make -j$(nproc)'"]
diff --git a/assets/xml/objects/object_ani.xml b/assets/xml/objects/object_ani.xml
index bb85f51a4a..25ad7af354 100644
--- a/assets/xml/objects/object_ani.xml
+++ b/assets/xml/objects/object_ani.xml
@@ -37,9 +37,9 @@
-
+
-
+
@@ -47,9 +47,9 @@
-
-
-
+
+
+
diff --git a/assets/xml/objects/object_md.xml b/assets/xml/objects/object_md.xml
index 0c80fb780b..717443537a 100644
--- a/assets/xml/objects/object_md.xml
+++ b/assets/xml/objects/object_md.xml
@@ -51,10 +51,10 @@
-
+
-
-
+
+
diff --git a/assets/xml/objects/object_oF1d_map.xml b/assets/xml/objects/object_oF1d_map.xml
index 079189319c..09a35dbd1c 100644
--- a/assets/xml/objects/object_oF1d_map.xml
+++ b/assets/xml/objects/object_oF1d_map.xml
@@ -21,15 +21,17 @@
+
+
-
-
-
-
+
+
+
+
-
-
+
+
diff --git a/assets/xml/objects/object_owl.xml b/assets/xml/objects/object_owl.xml
index e6fa5ca371..24be378985 100644
--- a/assets/xml/objects/object_owl.xml
+++ b/assets/xml/objects/object_owl.xml
@@ -57,9 +57,15 @@
+
+
+
+
+
+
-
-
-
+
+
+
diff --git a/assets/xml/objects/object_rl.xml b/assets/xml/objects/object_rl.xml
index 625ab83a10..bbe0246ac8 100644
--- a/assets/xml/objects/object_rl.xml
+++ b/assets/xml/objects/object_rl.xml
@@ -18,8 +18,8 @@
-
-
+
+
diff --git a/assets/xml/objects/object_shop_dungen.xml b/assets/xml/objects/object_shop_dungen.xml
index 594c43d390..027207402c 100644
--- a/assets/xml/objects/object_shop_dungen.xml
+++ b/assets/xml/objects/object_shop_dungen.xml
@@ -2,8 +2,8 @@
-
-
+
+
diff --git a/assets/xml/objects/object_tk.xml b/assets/xml/objects/object_tk.xml
index 6869280e6f..5b2fd13806 100644
--- a/assets/xml/objects/object_tk.xml
+++ b/assets/xml/objects/object_tk.xml
@@ -7,7 +7,7 @@
-
+
diff --git a/assets/xml/objects/object_xc.xml b/assets/xml/objects/object_xc.xml
index 030ae93941..7fae3a0875 100644
--- a/assets/xml/objects/object_xc.xml
+++ b/assets/xml/objects/object_xc.xml
@@ -8,6 +8,7 @@
+
@@ -21,10 +22,10 @@
-
-
-
-
+
+
+
+
diff --git a/assets/xml/overlays/ovl_Boss_Ganon.xml b/assets/xml/overlays/ovl_Boss_Ganon.xml
index ea546035a7..07507ae63d 100644
--- a/assets/xml/overlays/ovl_Boss_Ganon.xml
+++ b/assets/xml/overlays/ovl_Boss_Ganon.xml
@@ -14,7 +14,7 @@
-
+
diff --git a/assets/xml/scenes/dungeons/ddan.xml b/assets/xml/scenes/dungeons/ddan.xml
index 197839bde2..a42e97cfc9 100644
--- a/assets/xml/scenes/dungeons/ddan.xml
+++ b/assets/xml/scenes/dungeons/ddan.xml
@@ -3,15 +3,15 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/assets/xml/textures/icon_item_field_static.xml b/assets/xml/textures/icon_item_field_static.xml
index ed991406b5..1d94ffda11 100644
--- a/assets/xml/textures/icon_item_field_static.xml
+++ b/assets/xml/textures/icon_item_field_static.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/include/functions.h b/include/functions.h
index 7421c732de..6c199feaaf 100644
--- a/include/functions.h
+++ b/include/functions.h
@@ -1512,22 +1512,16 @@ void PreRender_SetValuesSave(PreRender* this, u32 width, u32 height, void* fbuf,
void PreRender_Init(PreRender* this);
void PreRender_SetValues(PreRender* this, u32 width, u32 height, void* fbuf, void* zbuf);
void PreRender_Destroy(PreRender* this);
-void func_800C0F28(PreRender* this, Gfx** gfxp, void* buf, void* bufSave);
-void func_800C1258(PreRender* this, Gfx** gfxp);
-void func_800C170C(PreRender* this, Gfx** gfxp, void* fbuf, void* fbufSave, u32 r, u32 g, u32 b, u32 a);
+void func_800C170C(PreRender* this, Gfx** gfxp, void* buf, void* bufSave, u32 r, u32 g, u32 b, u32 a);
void func_800C1AE8(PreRender* this, Gfx** gfxp, void* fbuf, void* fbufSave);
-void func_800C1B24(PreRender* this, Gfx** gfxp, void* fbuf, void* cvgSave);
-void func_800C1E9C(PreRender* this, Gfx** gfxp);
-void func_800C1F20(PreRender* this, Gfx** gfxp);
-void func_800C1FA4(PreRender* this, Gfx** gfxp);
-void func_800C20B4(PreRender* this, Gfx** gfxp);
-void func_800C2118(PreRender* this, Gfx** gfxp);
+void PreRender_SaveZBuffer(PreRender* this, Gfx** gfxp);
+void PreRender_SaveFramebuffer(PreRender* this, Gfx** gfxp);
+void PreRender_DrawCoverage(PreRender* this, Gfx** gfxp);
+void PreRender_RestoreZBuffer(PreRender* this, Gfx** gfxp);
void func_800C213C(PreRender* this, Gfx** gfxp);
-void func_800C24BC(PreRender* this, Gfx** gfxp);
-void func_800C24E0(PreRender* this, Gfx** gfxp);
-void func_800C2500(PreRender* this, s32 x, s32 y);
-void func_800C2FE4(PreRender* this);
-void PreRender_Calc(PreRender* this);
+void PreRender_RestoreFramebuffer(PreRender* this, Gfx** gfxp);
+void PreRender_CopyImageRegion(PreRender* this, Gfx** gfxp);
+void PreRender_ApplyFilters(PreRender* this);
void THGA_Ct(TwoHeadGfxArena* thga, Gfx* start, u32 size);
void THGA_Dt(TwoHeadGfxArena* thga);
u32 THGA_IsCrash(TwoHeadGfxArena* thga);
diff --git a/include/macros.h b/include/macros.h
index 09dddd40d8..7d0c37a6d4 100644
--- a/include/macros.h
+++ b/include/macros.h
@@ -27,9 +27,6 @@
#define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x))
#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x))
#define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x))
-#define MEDIAN3(a1, a2, a3) \
- (((a2) >= (a1)) ? (((a3) >= (a2)) ? (a2) : (((a1) >= (a3)) ? (a1) : (a3))) \
- : (((a2) >= (a3)) ? (a2) : (((a3) >= (a1)) ? (a1) : (a3))))
#define RGBA8(r, g, b, a) ((((r) & 0xFF) << 24) | (((g) & 0xFF) << 16) | (((b) & 0xFF) << 8) | (((a) & 0xFF) << 0))
diff --git a/include/variables.h b/include/variables.h
index 2e39bdf97e..f947ef989d 100644
--- a/include/variables.h
+++ b/include/variables.h
@@ -121,7 +121,7 @@ extern u8 gDefaultShortNoteGateTimeTable[16];
extern EnvelopePoint gDefaultEnvelope[4];
extern NoteSubEu gZeroNoteSub;
extern NoteSubEu gDefaultNoteSub;
-extern u16 gHeadsetPanQuantization[64];
+extern u16 gHaasEffectDelaySizes[64];
extern s16 D_8012FBA8[];
extern f32 gHeadsetPanVolume[128];
extern f32 gStereoPanVolume[128];
diff --git a/include/z64.h b/include/z64.h
index 834467b393..fab278cecd 100644
--- a/include/z64.h
+++ b/include/z64.h
@@ -74,6 +74,9 @@
#define STACK_TOP(stack) \
((u8*)(stack) + sizeof(stack))
+// Texture memory size, 4 KiB
+#define TMEM_SIZE 0x1000
+
// NOTE: Once we start supporting other builds, this can be changed with an ifdef
#define REGION_NATIVE REGION_EU
diff --git a/include/z64audio.h b/include/z64audio.h
index 4c09eae546..9d86bdd1bb 100644
--- a/include/z64audio.h
+++ b/include/z64audio.h
@@ -484,19 +484,19 @@ typedef struct SequenceLayer {
} SequenceLayer; // size = 0x80
typedef struct {
- /* 0x0000 */ s16 adpcmdecState[0x10];
- /* 0x0020 */ s16 finalResampleState[0x10];
- /* 0x0040 */ s16 mixEnvelopeState[0x28];
- /* 0x0090 */ s16 panResampleState[0x10];
- /* 0x00B0 */ s16 panSamplesBuffer[0x20];
- /* 0x00F0 */ s16 dummyResampleState[0x10];
-} NoteSynthesisBuffers; // size = 0x110
+ /* 0x000 */ s16 adpcmdecState[16];
+ /* 0x020 */ s16 finalResampleState[16];
+ /* 0x040 */ s16 mixEnvelopeState[32];
+ /* 0x080 */ s16 unusedState[16];
+ /* 0x0A0 */ s16 haasEffectDelayState[32];
+ /* 0x0E0 */ s16 unkState[128];
+} NoteSynthesisBuffers; // size = 0x1E0
typedef struct {
/* 0x00 */ u8 restart;
/* 0x01 */ u8 sampleDmaIndex;
- /* 0x02 */ u8 prevHeadsetPanRight;
- /* 0x03 */ u8 prevHeadsetPanLeft;
+ /* 0x02 */ u8 prevHaasEffectLeftDelaySize;
+ /* 0x03 */ u8 prevHaasEffectRightDelaySize;
/* 0x04 */ u8 reverbVol;
/* 0x05 */ u8 numParts;
/* 0x06 */ u16 samplePosFrac;
@@ -559,11 +559,11 @@ typedef struct {
/* 0x01 */ u8 bookOffset : 2;
/* 0x01 */ u8 isSyntheticWave : 1;
/* 0x01 */ u8 hasTwoParts : 1;
- /* 0x01 */ u8 usesHeadsetPanEffects2 : 1;
+ /* 0x01 */ u8 useHaasEffect : 1;
} bitField1;
/* 0x02 */ u8 gain; // Increases volume by a multiplicative scaling factor. Represented as a UQ4.4 number
- /* 0x03 */ u8 headsetPanRight;
- /* 0x04 */ u8 headsetPanLeft;
+ /* 0x03 */ u8 haasEffectLeftDelaySize;
+ /* 0x04 */ u8 haasEffectRightDelaySize;
/* 0x05 */ u8 reverbVol;
/* 0x06 */ u8 harmonicIndexCurAndPrev; // bits 3..2 store curHarmonicIndex, bits 1..0 store prevHarmonicIndex
/* 0x07 */ u8 unk_07;
diff --git a/src/code/PreRender.c b/src/code/PreRender.c
index 95ecc9e090..a8aa459581 100644
--- a/src/code/PreRender.c
+++ b/src/code/PreRender.c
@@ -1,3 +1,10 @@
+/**
+ * @file PreRender.c
+ *
+ * This file implements various routines important to framebuffer effects, such as RDP accelerated color and depth
+ * buffer copies and coverage drawing. Also contains software implementations of the Video Interface anti-aliasing and
+ * divot filters.
+ */
#include "global.h"
#include "alloca.h"
@@ -33,11 +40,18 @@ void PreRender_Destroy(PreRender* this) {
ListAlloc_FreeAll(&this->alloc);
}
-void func_800C0F28(PreRender* this, Gfx** gfxp, void* buf, void* bufSave) {
+/**
+ * Copies RGBA16 image `img` to `imgDst`
+ *
+ * @param gfxp Display list pointer
+ * @param img Image to copy from
+ * @param imgDst Buffer to copy to
+ */
+void PreRender_CopyImage(PreRender* this, Gfx** gfxp, void* img, void* imgDst) {
Gfx* gfx;
- s32 x;
- s32 x2;
- s32 dx;
+ s32 rowsRemaining;
+ s32 curRow;
+ s32 nRows;
LogUtils_CheckNullPointer("this", this, "../PreRender.c", 215);
LogUtils_CheckNullPointer("glistpp", gfxp, "../PreRender.c", 216);
@@ -45,35 +59,44 @@ void func_800C0F28(PreRender* this, Gfx** gfxp, void* buf, void* bufSave) {
LogUtils_CheckNullPointer("glistp", gfx, "../PreRender.c", 218);
gDPPipeSync(gfx++);
+ // Configure the cycle type to COPY mode, disable blending
gDPSetOtherMode(gfx++,
G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE |
G_TD_CLAMP | G_TP_NONE | G_CYC_COPY | G_PM_NPRIMITIVE,
G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2);
- gDPSetColorImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, bufSave);
+ // Set the destination buffer as the color image and set the scissoring region to the entire image
+ gDPSetColorImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, imgDst);
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, 0, 0, this->width, this->height);
- dx = 0x1000 / (this->width * 2);
+ // Calculate the max number of rows that can fit into TMEM at once
+ nRows = TMEM_SIZE / (this->width * G_IM_SIZ_16b_BYTES);
- x = this->height;
- x2 = 0;
- while (x > 0) {
+ rowsRemaining = this->height;
+ curRow = 0;
+ while (rowsRemaining > 0) {
s32 uls = 0;
s32 lrs = this->width - 1;
s32 ult;
s32 lrt;
- dx = CLAMP_MAX(dx, x);
- ult = x2;
- lrt = (ult + dx) - 1;
+ // Make sure that we don't load past the end of the source image
+ nRows = MIN(rowsRemaining, nRows);
- gDPLoadTextureTile(gfx++, buf, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, this->height, uls, ult, lrs, lrt, 0,
+ // Determine the upper and lower bounds of the rect to draw
+ ult = curRow;
+ lrt = ult + nRows - 1;
+
+ // Load a horizontal strip of the source image in RGBA16 format
+ gDPLoadTextureTile(gfx++, img, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, this->height, uls, ult, lrs, lrt, 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);
+
+ // Draw that horizontal strip to the destination image, dsdx is 4 << 10 for COPY mode
gSPTextureRectangle(gfx++, uls << 2, ult << 2, lrs << 2, lrt << 2, G_TX_RENDERTILE, uls << 5, ult << 5, 4 << 10,
1 << 10);
- x -= dx;
- x2 += dx;
+ rowsRemaining -= nRows;
+ curRow += nRows;
}
gDPPipeSync(gfx++);
@@ -81,11 +104,15 @@ void func_800C0F28(PreRender* this, Gfx** gfxp, void* buf, void* bufSave) {
*gfxp = gfx;
}
-void func_800C1258(PreRender* this, Gfx** gfxp) {
+/**
+ * Copies part of `this->fbufSave` in the region (this->ulx, this->uly), (this->lrx, this->lry) to the same location in
+ * `this->fbuf`.
+ */
+void PreRender_CopyImageRegionImpl(PreRender* this, Gfx** gfxp) {
Gfx* gfx;
- s32 y;
- s32 y2;
- s32 dy;
+ s32 rowsRemaining;
+ s32 curRow;
+ s32 nRows;
LogUtils_CheckNullPointer("this", this, "../PreRender.c", 278);
LogUtils_CheckNullPointer("glistpp", gfxp, "../PreRender.c", 279);
@@ -93,49 +120,62 @@ void func_800C1258(PreRender* this, Gfx** gfxp) {
LogUtils_CheckNullPointer("glistp", gfx, "../PreRender.c", 281);
gDPPipeSync(gfx++);
+ // Configure the cycle type to COPY mode, disable blending
gDPSetOtherMode(gfx++,
G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE |
G_TD_CLAMP | G_TP_NONE | G_CYC_COPY | G_PM_NPRIMITIVE,
G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2);
+ // Set the destination buffer as the color image and set the scissoring region to the destination region
gDPSetColorImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, this->fbuf);
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, this->ulx, this->uly, this->lrx + 1, this->lry + 1);
- dy = 0x1000 / ((this->lrxSave - this->ulxSave + 1) * 2);
+ // Calculate the max number of rows that can fit into TMEM at once
+ nRows = TMEM_SIZE / ((this->lrxSave - this->ulxSave + 1) * G_IM_SIZ_16b_BYTES);
- y = (this->lrySave - this->ulySave) + 1;
- y2 = 0;
- while (y > 0) {
+ rowsRemaining = (this->lrySave - this->ulySave) + 1;
+ curRow = 0;
+ while (rowsRemaining > 0) {
s32 ult;
s32 lrt;
s32 uly;
- dy = CLAMP_MAX(dy, y);
+ // Make sure that we don't load past the end of the source image
+ nRows = MIN(rowsRemaining, nRows);
- ult = this->ulySave + y2;
- lrt = (ult + dy) - 1;
- uly = this->uly + y2;
+ // Determine the upper and lower bounds of the rect to draw
+ ult = this->ulySave + curRow;
+ lrt = ult + nRows - 1;
+ uly = this->uly + curRow;
+ // Load a horizontal strip of the source image in RGBA16 format
gDPLoadTextureTile(gfx++, this->fbufSave, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->widthSave, this->height - 1,
this->ulxSave, ult, this->lrxSave, lrt, 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);
- gSPTextureRectangle(gfx++, this->ulx << 2, uly << 2, this->lrx << 2, (uly + dy - 1) << 2, G_TX_RENDERTILE,
+
+ // Draw that horizontal strip to the destination image, dsdx is 4 << 10 for COPY mode
+ gSPTextureRectangle(gfx++, this->ulx << 2, uly << 2, this->lrx << 2, (uly + nRows - 1) << 2, G_TX_RENDERTILE,
this->ulxSave << 5, ult << 5, 4 << 10, 1 << 10);
- y -= dy;
- y2 += dy;
+ rowsRemaining -= nRows;
+ curRow += nRows;
}
+ // Reset the color image and scissor
gDPPipeSync(gfx++);
gDPSetColorImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, this->fbuf);
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, 0, 0, this->width, this->height);
*gfxp = gfx;
}
-void func_800C170C(PreRender* this, Gfx** gfxp, void* fbuf, void* fbufSave, u32 r, u32 g, u32 b, u32 a) {
+/**
+ * Copies `buf` to `bufSave`, discarding the alpha channel and modulating the RGB channel by
+ * the color ('r', 'g', 'b', 'a')
+ */
+void func_800C170C(PreRender* this, Gfx** gfxp, void* buf, void* bufSave, u32 r, u32 g, u32 b, u32 a) {
Gfx* gfx;
- s32 x;
- s32 x2;
- s32 dx;
+ s32 rowsRemaining;
+ s32 curRow;
+ s32 nRows;
LogUtils_CheckNullPointer("this", this, "../PreRender.c", 343);
LogUtils_CheckNullPointer("glistpp", gfxp, "../PreRender.c", 344);
@@ -143,39 +183,51 @@ void func_800C170C(PreRender* this, Gfx** gfxp, void* fbuf, void* fbufSave, u32
LogUtils_CheckNullPointer("glistp", gfx, "../PreRender.c", 346);
gDPPipeSync(gfx++);
+ // Set the cycle type to 1-cycle mode to use the color combiner
gDPSetOtherMode(gfx++,
G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_NONE | G_TL_TILE |
G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE,
G_AC_NONE | G_ZS_PRIM | G_RM_OPA_SURF | G_RM_OPA_SURF2);
gDPSetEnvColor(gfx++, r, g, b, a);
+
+ // Redundant setting of color combiner, overwritten immediately
+ // Would preserve rgb exactly while replacing the alpha channel with full alpha
gDPSetCombineLERP(gfx++, 0, 0, 0, TEXEL0, 0, 0, 0, 1, 0, 0, 0, TEXEL0, 0, 0, 0, 1);
+ // Modulate TEXEL0 by ENVIRONMENT, replace alpha with full alpha
gDPSetCombineLERP(gfx++, TEXEL0, 0, ENVIRONMENT, 0, 0, 0, 0, 1, TEXEL0, 0, ENVIRONMENT, 0, 0, 0, 0, 1);
- gDPSetColorImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, fbufSave);
+ // Set the destination buffer as the color image and set the scissoring region to the entire image
+ gDPSetColorImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, bufSave);
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, 0, 0, this->width, this->height);
- dx = 0x1000 / (this->width * 2);
+ // Calculate the max number of rows that can fit into TMEM at once
+ nRows = TMEM_SIZE / (this->width * G_IM_SIZ_16b_BYTES);
- x = this->height;
- x2 = 0;
- while (x > 0) {
+ rowsRemaining = this->height;
+ curRow = 0;
+ while (rowsRemaining > 0) {
s32 uls = 0;
s32 lrs = this->width - 1;
s32 ult;
s32 lrt;
- dx = CLAMP_MAX(dx, x);
- ult = x2;
- lrt = x2 + dx - 1;
+ // Make sure that we don't load past the end of the source image
+ nRows = MIN(rowsRemaining, nRows);
- gDPLoadTextureTile(gfx++, fbuf, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, this->height, uls, ult, lrs, lrt, 0,
+ // Determine the upper and lower bounds of the rect to draw
+ ult = curRow;
+ lrt = curRow + nRows - 1;
+
+ // Load a horizontal strip of the source image in RGBA16 format
+ gDPLoadTextureTile(gfx++, buf, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, this->height, uls, ult, lrs, lrt, 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);
+ // Draw that horizontal strip to the destination image
gSPTextureRectangle(gfx++, uls << 2, ult << 2, (lrs + 1) << 2, (lrt + 1) << 2, G_TX_RENDERTILE, uls << 5,
ult << 5, 1 << 10, 1 << 10);
- x -= dx;
- x2 += dx;
+ rowsRemaining -= nRows;
+ curRow += nRows;
}
gDPPipeSync(gfx++);
@@ -183,15 +235,26 @@ void func_800C170C(PreRender* this, Gfx** gfxp, void* fbuf, void* fbufSave, u32
*gfxp = gfx;
}
+/**
+ * Copies `fbuf` to `fbufSave`, discarding the alpha channel and leaving the rgb channel unchanged
+ */
void func_800C1AE8(PreRender* this, Gfx** gfxp, void* fbuf, void* fbufSave) {
func_800C170C(this, gfxp, fbuf, fbufSave, 255, 255, 255, 255);
}
-void func_800C1B24(PreRender* this, Gfx** gfxp, void* fbuf, void* cvgSave) {
+/**
+ * Reads the coverage values stored in the RGBA16 format `img` with dimensions `this->width`, `this->height` and
+ * converts it to an 8-bpp intensity image.
+ *
+ * @param gfxp Display list pointer
+ * @param img Image to read coverage from
+ * @param cvgDst Buffer to store coverage into
+ */
+void PreRender_CoverageRgba16ToI8(PreRender* this, Gfx** gfxp, void* img, void* cvgDst) {
Gfx* gfx;
- s32 x;
- s32 x2;
- s32 dx;
+ s32 rowsRemaining;
+ s32 curRow;
+ s32 nRows;
LogUtils_CheckNullPointer("this", this, "../PreRender.c", 422);
LogUtils_CheckNullPointer("glistpp", gfxp, "../PreRender.c", 423);
@@ -203,49 +266,85 @@ void func_800C1B24(PreRender* this, Gfx** gfxp, void* fbuf, void* cvgSave) {
G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_NONE | G_TL_TILE |
G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE,
G_AC_NONE | G_ZS_PRIM | G_RM_PASS | G_RM_OPA_CI2);
+
+ // Set the combiner to draw the texture as-is, discarding alpha channel
gDPSetCombineLERP(gfx++, 0, 0, 0, TEXEL0, 0, 0, 0, 0, 0, 0, 0, TEXEL0, 0, 0, 0, 0);
- gDPSetColorImage(gfx++, G_IM_FMT_I, G_IM_SIZ_8b, this->width, cvgSave);
+ // Set the destination color image to the provided address
+ gDPSetColorImage(gfx++, G_IM_FMT_I, G_IM_SIZ_8b, this->width, cvgDst);
+ // Set up a scissor based on the source image
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, 0, 0, this->width, this->height);
- dx = 0x1000 / (this->width * 2);
+ // Calculate the max number of rows that can fit into TMEM at once
+ nRows = TMEM_SIZE / (this->width * G_IM_SIZ_16b_BYTES);
- x = this->height;
- x2 = 0;
- while (x > 0) {
+ // Set up the number of remaining rows
+ rowsRemaining = this->height;
+ curRow = 0;
+ while (rowsRemaining > 0) {
s32 uls = 0;
s32 lrs = this->width - 1;
s32 ult;
s32 lrt;
- dx = CLAMP_MAX(dx, x);
- ult = x2;
- lrt = x2 + dx - 1;
+ // Make sure that we don't load past the end of the source image
+ nRows = MIN(rowsRemaining, nRows);
- gDPLoadTextureTile(gfx++, fbuf, G_IM_FMT_IA, G_IM_SIZ_16b, this->width, this->height, uls, ult, lrs, lrt, 0,
+ // Determine the upper and lower bounds of the rect to draw
+ ult = curRow;
+ lrt = curRow + nRows - 1;
+
+ // Load a horizontal strip of the source image in IA16 format. Since the source image is stored in memory as
+ // RGBA16, the bits are reinterpreted into IA16:
+ //
+ // r g b a
+ // 11111 111 11 11111 1
+ // i a
+ // 11111 111 11 11111 1
+ //
+ // I = (r << 3) | (g >> 2)
+ // A = (g << 6) | (b << 1) | a
+ //
+ // Since it is expected that r = g = b = cvg in the source image, this results in
+ // I = (cvg << 3) | (cvg >> 2)
+ // This expands the 5-bit coverage into an 8-bit value
+ gDPLoadTextureTile(gfx++, img, G_IM_FMT_IA, G_IM_SIZ_16b, this->width, this->height, uls, ult, lrs, lrt, 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);
+ // Draw that horizontal strip to the destination image. With the combiner and blender configuration set above,
+ // the intensity (I) channel of the loaded IA16 texture will be written as-is to the I8 color image, each pixel
+ // in the final image is
+ // I = (cvg << 3) | (cvg >> 2)
gSPTextureRectangle(gfx++, uls << 2, ult << 2, (lrs + 1) << 2, (lrt + 1) << 2, G_TX_RENDERTILE, uls << 5,
ult << 5, 1 << 10, 1 << 10);
- x -= dx;
- x2 += dx;
+
+ // Update the number of rows remaining and index of the row being drawn
+ rowsRemaining -= nRows;
+ curRow += nRows;
}
+ // Reset the color image to the current framebuffer
gDPPipeSync(gfx++);
gDPSetColorImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width, this->fbuf);
*gfxp = gfx;
}
-void func_800C1E9C(PreRender* this, Gfx** gfxp) {
+/**
+ * Saves zbuf to zbufSave
+ */
+void PreRender_SaveZBuffer(PreRender* this, Gfx** gfxp) {
LogUtils_CheckNullPointer("this->zbuf_save", this->zbufSave, "../PreRender.c", 481);
LogUtils_CheckNullPointer("this->zbuf", this->zbuf, "../PreRender.c", 482);
if ((this->zbufSave != NULL) && (this->zbuf != NULL)) {
- func_800C0F28(this, gfxp, this->zbuf, this->zbufSave);
+ PreRender_CopyImage(this, gfxp, this->zbuf, this->zbufSave);
}
}
-void func_800C1F20(PreRender* this, Gfx** gfxp) {
+/**
+ * Saves fbuf to fbufSave
+ */
+void PreRender_SaveFramebuffer(PreRender* this, Gfx** gfxp) {
LogUtils_CheckNullPointer("this->fbuf_save", this->fbufSave, "../PreRender.c", 495);
LogUtils_CheckNullPointer("this->fbuf", this->fbuf, "../PreRender.c", 496);
@@ -254,40 +353,71 @@ void func_800C1F20(PreRender* this, Gfx** gfxp) {
}
}
-void func_800C1FA4(PreRender* this, Gfx** gfxp) {
+/**
+ * Fetches the coverage of the current framebuffer into an image of the same format as the current color image, storing
+ * it over the framebuffer in memory.
+ */
+void PreRender_FetchFbufCoverage(PreRender* this, Gfx** gfxp) {
Gfx* gfx = *gfxp;
gDPPipeSync(gfx++);
+ // Set the blend color to full white and set maximum depth
gDPSetBlendColor(gfx++, 255, 255, 255, 8);
gDPSetPrimDepth(gfx++, 0xFFFF, 0xFFFF);
+
+ // Uses G_RM_VISCVG to blit the coverage values to the framebuffer
+ //
+ // G_RM_VISCVG is the following special render mode:
+ // IM_RD : Allow read-modify-write operations on the framebuffer
+ // FORCE_BL : Apply the blender to all pixels rather than just edges
+ // (G_BL_CLR_IN * G_BL_0 + G_BL_CLR_BL * G_BL_A_MEM) / (G_BL_0 + G_BL_CLR_BL) = G_BL_A_MEM
+ //
+ // G_BL_A_MEM ("memory alpha") is coverage, therefore this blender configuration emits only the coverage
+ // and discards any pixel colors. For an RGBA16 framebuffer, each of the three color channels r,g,b will
+ // receive the coverage value individually.
+ //
+ // Also disables other modes such as alpha compare and texture perspective correction
gDPSetOtherMode(gfx++,
G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_NONE | G_TL_TILE |
G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE,
G_AC_NONE | G_ZS_PRIM | G_RM_VISCVG | G_RM_VISCVG2);
+ // Set up a scissor with the same dimensions as the framebuffer
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, 0, 0, this->width, this->height);
+ // Fill rectangle to obtain the coverage values as an RGBA16 image
gDPFillRectangle(gfx++, 0, 0, this->width, this->height);
gDPPipeSync(gfx++);
*gfxp = gfx;
}
-void func_800C20B4(PreRender* this, Gfx** gfxp) {
- func_800C1FA4(this, gfxp);
+/**
+ * Draws the coverage of the current framebuffer `this->fbuf` to an I8 image at `this->cvgSave`. Overwrites
+ * `this->fbuf` in the process.
+ */
+void PreRender_DrawCoverage(PreRender* this, Gfx** gfxp) {
+ PreRender_FetchFbufCoverage(this, gfxp);
LogUtils_CheckNullPointer("this->cvg_save", this->cvgSave, "../PreRender.c", 532);
if (this->cvgSave != NULL) {
- func_800C1B24(this, gfxp, this->fbuf, this->cvgSave);
+ PreRender_CoverageRgba16ToI8(this, gfxp, this->fbuf, this->cvgSave);
}
}
-void func_800C2118(PreRender* this, Gfx** gfxp) {
- func_800C0F28(this, gfxp, this->zbufSave, this->zbuf);
+/**
+ * Restores zbufSave to zbuf
+ */
+void PreRender_RestoreZBuffer(PreRender* this, Gfx** gfxp) {
+ PreRender_CopyImage(this, gfxp, this->zbufSave, this->zbuf);
}
+/**
+ * Draws a full-screen image to the current framebuffer, that sources the rgb channel from `this->fbufSave` and
+ * the alpha channel from `this->cvgSave` modulated by environment color.
+ */
void func_800C213C(PreRender* this, Gfx** gfxp) {
Gfx* gfx;
- s32 y;
- s32 y2;
- s32 dy;
+ s32 rowsRemaining;
+ s32 curRow;
+ s32 nRows;
s32 rtile = 1;
if (this->cvgSave != NULL) {
@@ -298,42 +428,52 @@ void func_800C213C(PreRender* this, Gfx** gfxp) {
gDPPipeSync(gfx++);
gDPSetEnvColor(gfx++, 255, 255, 255, 32);
+ // Effectively disable blending in both cycles. It's 2-cycle so that TEXEL1 can be used to point to a different
+ // texture tile.
gDPSetOtherMode(gfx++,
G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_NONE | G_TL_TILE |
G_TD_CLAMP | G_TP_NONE | G_CYC_2CYCLE | G_PM_NPRIMITIVE,
G_AC_NONE | G_ZS_PRIM | AA_EN | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA |
GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) |
GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1));
+
+ // Set up the color combiner: first cycle: TEXEL0, TEXEL1 + ENVIRONMENT; second cycle: G_CC_PASS2
gDPSetCombineLERP(gfx++, 0, 0, 0, TEXEL0, 1, 0, TEXEL1, ENVIRONMENT, 0, 0, 0, COMBINED, 0, 0, 0, COMBINED);
- dy = 4;
+ nRows = 4;
- y = this->height;
- y2 = 0;
- while (y > 0) {
+ rowsRemaining = this->height;
+ curRow = 0;
+ while (rowsRemaining > 0) {
s32 uls = 0;
s32 lrs = this->width - 1;
s32 ult;
s32 lrt;
- dy = CLAMP_MAX(dy, y);
+ // Make sure that we don't load past the end of the source image
+ nRows = MIN(rowsRemaining, nRows);
- ult = y2;
- lrt = (y2 + dy - 1);
+ // Determine the upper and lower bounds of the rect to draw
+ ult = curRow;
+ lrt = curRow + nRows - 1;
+ // Load the frame buffer line
gDPLoadMultiTile(gfx++, this->fbufSave, 0x0000, G_TX_RENDERTILE, G_IM_FMT_RGBA, G_IM_SIZ_16b, this->width,
this->height, uls, ult, lrs, lrt, 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);
+ // Load the coverage line
gDPLoadMultiTile(gfx++, this->cvgSave, 0x0160, rtile, G_IM_FMT_I, G_IM_SIZ_8b, this->width, this->height,
uls, ult, lrs, lrt, 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);
+ // Draw a texture for which the rgb channels come from the framebuffer and the alpha channel comes from
+ // coverage, modulated by env color
gSPTextureRectangle(gfx++, uls << 2, ult << 2, (lrs + 1) << 2, (lrt + 1) << 2, G_TX_RENDERTILE, uls << 5,
ult << 5, 1 << 10, 1 << 10);
- y -= dy;
- y2 += dy;
+ rowsRemaining -= nRows;
+ curRow += nRows;
}
gDPPipeSync(gfx++);
@@ -341,135 +481,207 @@ void func_800C213C(PreRender* this, Gfx** gfxp) {
}
}
-void func_800C24BC(PreRender* this, Gfx** gfxp) {
- func_800C0F28(this, gfxp, this->fbufSave, this->fbuf);
+/**
+ * Copies fbufSave to fbuf
+ */
+void PreRender_RestoreFramebuffer(PreRender* this, Gfx** gfxp) {
+ PreRender_CopyImage(this, gfxp, this->fbufSave, this->fbuf);
}
-void func_800C24E0(PreRender* this, Gfx** gfxp) {
- func_800C1258(this, gfxp);
+/**
+ * Copies part of `this->fbufSave` in the region (this->ulx, this->uly), (this->lrx, this->lry) to the same location in
+ * `this->fbuf`.
+ */
+void PreRender_CopyImageRegion(PreRender* this, Gfx** gfxp) {
+ PreRender_CopyImageRegionImpl(this, gfxp);
}
-void func_800C2500(PreRender* this, s32 x, s32 y) {
+/**
+ * Applies the Video Interface anti-aliasing of silhouette edges to an image.
+ *
+ * This filter performs a linear interpolation on partially covered pixels between the current pixel color (called
+ * foreground color) and a "background" pixel color obtained by sampling fully covered pixels at the six highlighted
+ * points in the following 5x3 neighborhood:
+ * _ _ _ _ _
+ * | o o |
+ * | o X o |
+ * | o o |
+ * ‾ ‾ ‾ ‾ ‾
+ * Whether a pixel is partially covered is determined by reading the coverage values associated with the image.
+ * Coverage is a measure of how many subpixels the last drawn primitive covered. A fully covered pixel is one with a
+ * full coverage value, the entire pixel was covered by the primitive.
+ * The background color is calculated as the average of the "penultimate" minimum and maximum colors in the 5x3
+ * neighborhood.
+ *
+ * The final color is calculated by interpolating the foreground and background color weighted by the coverage:
+ * OutputColor = cvg * ForeGround + (1.0 - cvg) * BackGround
+ *
+ * This is a software implementation of the same algorithm used in the Video Interface hardware when Anti-Aliasing is
+ * enabled in the VI Control Register.
+ *
+ * Patent describing the algorithm:
+ *
+ * Gossett, C. P., & van Hook, T. J. (Filed 1995, Published 1998)
+ * Antialiasing of silhouette edges (USOO5742277A)
+ * U.S. Patent and Trademark Office
+ * Expired 2015-10-06
+ * https://patents.google.com/patent/US5742277A/en
+ *
+ * @param this PreRender instance
+ * @param x Center pixel x
+ * @param y Center pixel y
+ */
+void PreRender_AntiAliasFilter(PreRender* this, s32 x, s32 y) {
s32 i;
s32 j;
- s32 buffA[3 * 5];
- s32 buffR[3 * 5];
- s32 buffG[3 * 5];
- s32 buffB[3 * 5];
- s32 x1;
- s32 y1;
+ s32 buffCvg[5 * 3];
+ s32 buffR[5 * 3];
+ s32 buffG[5 * 3];
+ s32 buffB[5 * 3];
+ s32 xi;
+ s32 yi;
s32 pad;
- s32 pxR;
- s32 pxG;
- s32 pxB;
- s32 pxR2;
- s32 pxG2;
- s32 pxB2;
+ s32 pmaxR;
+ s32 pmaxG;
+ s32 pmaxB;
+ s32 pminR;
+ s32 pminG;
+ s32 pminB;
Color_RGBA16 pxIn;
Color_RGBA16 pxOut;
- u32 pxR3;
- u32 pxG3;
- u32 pxB3;
+ u32 outR;
+ u32 outG;
+ u32 outB;
- /*
- Picture this as a 3x5 rectangle where the middle pixel (index 7) correspond to (x, y)
- _ _ _ _ _
- | 0 1 2 3 4 |
- | 5 6 7 8 9 |
- | A B C D E |
- ‾ ‾ ‾ ‾ ‾
- */
- for (i = 0; i < 3 * 5; i++) {
- x1 = (i % 5) + x - 2;
- y1 = (i / 5) + y - 1;
+ // Extract pixels in the 5x3 neighborhood
+ for (i = 0; i < 5 * 3; i++) {
+ xi = x + (i % 5) - 2;
+ yi = y + (i / 5) - 1;
- if (x1 < 0) {
- x1 = 0;
- } else if (x1 > (this->width - 1)) {
- x1 = this->width - 1;
+ // Clamp coordinates to the edges of the image
+ if (xi < 0) {
+ xi = 0;
+ } else if (xi > (this->width - 1)) {
+ xi = this->width - 1;
}
- if (y1 < 0) {
- y1 = 0;
- } else if (y1 > (this->height - 1)) {
- y1 = this->height - 1;
+ if (yi < 0) {
+ yi = 0;
+ } else if (yi > (this->height - 1)) {
+ yi = this->height - 1;
}
- pxIn.rgba = this->fbufSave[x1 + y1 * this->width];
+ // Extract color channels for each pixel, convert 5-bit color channels to 8-bit
+ pxIn.rgba = this->fbufSave[xi + yi * this->width];
buffR[i] = (pxIn.r << 3) | (pxIn.r >> 2);
buffG[i] = (pxIn.g << 3) | (pxIn.g >> 2);
buffB[i] = (pxIn.b << 3) | (pxIn.b >> 2);
- buffA[i] = this->cvgSave[x1 + y1 * this->width] >> 5; // A
+ buffCvg[i] = this->cvgSave[xi + yi * this->width] >> 5;
}
- if (buffA[7] == 7) {
+ if (buffCvg[7] == 7) {
osSyncPrintf("Error, should not be in here \n");
return;
}
- pxR = pxR2 = buffR[7];
- pxG = pxG2 = buffG[7];
- pxB = pxB2 = buffB[7];
+ pmaxR = pminR = buffR[7];
+ pmaxG = pminG = buffG[7];
+ pmaxB = pminB = buffB[7];
- for (i = 1; i < 3 * 5; i += 2) {
- if (buffA[i] == 7) {
- if (pxR < buffR[i]) {
- for (j = 1; j < 15; j += 2) {
- if ((i != j) && (buffR[j] >= buffR[i]) && (buffA[j] == 7)) {
- pxR = buffR[i];
+ // For each neighbor
+ for (i = 1; i < 5 * 3; i += 2) {
+ // Only sample fully covered pixels
+ if (buffCvg[i] == 7) {
+ // Determine "Penultimate Maximum" Value
+
+ // If current maximum is less than this neighbor
+ if (pmaxR < buffR[i]) {
+ // For each neighbor (again)
+ for (j = 1; j < 5 * 3; j += 2) {
+ // If not the neighbor we were at before, and this neighbor has a larger value and this pixel is
+ // fully covered, that means the neighbor at `i` is the "penultimate maximum"
+ if ((i != j) && (buffR[j] >= buffR[i]) && (buffCvg[j] == 7)) {
+ pmaxR = buffR[i];
}
}
}
- if (pxG < buffG[i]) {
- for (j = 1; j < 15; j += 2) {
- if ((i != j) && (buffG[j] >= buffG[i]) && (buffA[j] == 7)) {
- pxG = buffG[i];
+ if (pmaxG < buffG[i]) {
+ for (j = 1; j < 5 * 3; j += 2) {
+ if ((i != j) && (buffG[j] >= buffG[i]) && (buffCvg[j] == 7)) {
+ pmaxG = buffG[i];
}
}
}
- if (pxB < buffB[i]) {
- for (j = 1; j < 15; j += 2) {
- if ((i != j) && (buffB[j] >= buffB[i]) && (buffA[j] == 7)) {
- pxB = buffB[i];
+ if (pmaxB < buffB[i]) {
+ for (j = 1; j < 5 * 3; j += 2) {
+ if ((i != j) && (buffB[j] >= buffB[i]) && (buffCvg[j] == 7)) {
+ pmaxB = buffB[i];
}
}
}
+
if (1) {}
- if (pxR2 > buffR[i]) {
- for (j = 1; j < 15; j += 2) {
- if ((i != j) && (buffR[j] <= buffR[i]) && (buffA[j] == 7)) {
- pxR2 = buffR[i];
+
+ // Determine "Penultimate Minimum" Value
+
+ // Same as above with inverted conditions
+ if (pminR > buffR[i]) {
+ for (j = 1; j < 5 * 3; j += 2) {
+ if ((i != j) && (buffR[j] <= buffR[i]) && (buffCvg[j] == 7)) {
+ pminR = buffR[i];
}
}
}
- if (pxG2 > buffG[i]) {
- for (j = 1; j < 15; j += 2) {
- if ((i != j) && (buffG[j] <= buffG[i]) && (buffA[j] == 7)) {
- pxG2 = buffG[i];
+ if (pminG > buffG[i]) {
+ for (j = 1; j < 5 * 3; j += 2) {
+ if ((i != j) && (buffG[j] <= buffG[i]) && (buffCvg[j] == 7)) {
+ pminG = buffG[i];
}
}
}
- if (pxB2 > buffB[i]) {
- for (j = 1; j < 15; j += 2) {
- if ((i != j) && (buffB[j] <= buffB[i]) && (buffA[j] == 7)) {
- pxB2 = buffB[i];
+ if (pminB > buffB[i]) {
+ for (j = 1; j < 5 * 3; j += 2) {
+ if ((i != j) && (buffB[j] <= buffB[i]) && (buffCvg[j] == 7)) {
+ pminB = buffB[i];
}
}
}
}
}
- pxR3 = buffR[7] + ((s32)((7 - buffA[7]) * ((pxR + pxR2) - (buffR[7] << 1)) + 4) >> 3);
- pxG3 = buffG[7] + ((s32)((7 - buffA[7]) * ((pxG + pxG2) - (buffG[7] << 1)) + 4) >> 3);
- pxB3 = buffB[7] + ((s32)((7 - buffA[7]) * ((pxB + pxB2) - (buffB[7] << 1)) + 4) >> 3);
+ // The background color is determined by averaging the penultimate minimum and maximum pixels, and subtracting the
+ // ForeGround color:
+ // BackGround = (pMax + pMin) - (ForeGround) * 2
- pxOut.r = pxR3 >> 3;
- pxOut.g = pxG3 >> 3;
- pxOut.b = pxB3 >> 3;
+ // OutputColor = cvg * ForeGround + (1.0 - cvg) * BackGround
+ outR = buffR[7] + ((s32)((7 - buffCvg[7]) * (pmaxR + pminR - (buffR[7] * 2)) + 4) >> 3);
+ outG = buffG[7] + ((s32)((7 - buffCvg[7]) * (pmaxG + pminG - (buffG[7] * 2)) + 4) >> 3);
+ outB = buffB[7] + ((s32)((7 - buffCvg[7]) * (pmaxB + pminB - (buffB[7] * 2)) + 4) >> 3);
+
+ pxOut.r = outR >> 3;
+ pxOut.g = outG >> 3;
+ pxOut.b = outB >> 3;
pxOut.a = 1;
this->fbufSave[x + y * this->width] = pxOut.rgba;
}
-void func_800C2FE4(PreRender* this) {
+// Selects the median value from a1, a2, a3
+#define MEDIAN3(a1, a2, a3) \
+ (((a2) >= (a1)) ? (((a3) >= (a2)) ? (a2) : (((a1) >= (a3)) ? (a1) : (a3))) \
+ : (((a2) >= (a3)) ? (a2) : (((a3) >= (a1)) ? (a1) : (a3))))
+
+/**
+ * Applies the Video Interface divot filter to an image.
+ *
+ * This filter removes "divots" in an anti-aliased image, single-pixel holes created when many boundary edges all
+ * occupy a single pixel. The algorithm removes these by sliding a 3-pixel-wide window across each row of pixels and
+ * replaces the center pixel color with the median pixel color in the window.
+ *
+ * This is a software implementation of the same algorithm used in the Video Interface hardware when OS_VI_DIVOT_ON is
+ * set in the VI Control Register.
+ *
+ * @param this PreRender instance
+ */
+void PreRender_DivotFilter(PreRender* this) {
s32 x;
s32 y;
s32 pad1;
@@ -482,6 +694,9 @@ void func_800C2FE4(PreRender* this) {
s32 pxB;
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;
@@ -491,42 +706,52 @@ void func_800C2FE4(PreRender* this) {
buffB[x] = pxIn.b;
}
+ // 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 a = this->cvgSave[x + y * this->width];
+ s32 cvg = this->cvgSave[x + y * this->width];
- a >>= 5;
- if (a == 7) {
+ // 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.
+ cvg >>= 5;
+ if (cvg == 7) {
continue;
}
- if (((HREG(80) == 0xF) ? HREG(81) : 0) != 0) {
- if (((HREG(80) == 0xF) ? HREG(81) : 0) != 0) {}
+ // This condition is checked before entering this function, it will always pass if it runs.
+ if ((HREG(80) == 15 ? HREG(81) : 0) != 0) {
+ if ((HREG(80) == 15 ? HREG(81) : 0) != 0) {}
- if (((HREG(80) == 0xF) ? HREG(81) : 0) == 5) {
+ if ((HREG(80) == 15 ? HREG(81) : 0) == 5) {
+ // Fill the pixel with full red, likely for debugging
pxR = 31;
pxG = 0;
pxB = 0;
} else {
- u8* temp_s0 = &buffR[x - 1];
- u8* temp_s1 = &buffG[x - 1];
- u8* temp_s2 = &buffB[x - 1];
+ // Prepare sampling window
+ u8* windowR = &buffR[x - 1];
+ u8* windowG = &buffG[x - 1];
+ u8* windowB = &buffB[x - 1];
- if (((HREG(80) == 0xF) ? HREG(81) : 0) == 3) {
- osSyncPrintf("red=%3d %3d %3d %3d grn=%3d %3d %3d %3d blu=%3d %3d %3d %3d \n", temp_s0[0],
- temp_s0[1], temp_s0[2], MEDIAN3(temp_s0[0], temp_s0[1], temp_s0[2]), temp_s1[0],
- temp_s1[1], temp_s1[2], MEDIAN3(temp_s1[0], temp_s1[1], temp_s1[2]), temp_s2[0],
- temp_s2[1], temp_s2[2], MEDIAN3(temp_s2[0], temp_s2[1], temp_s2[2]));
+ if ((HREG(80) == 15 ? HREG(81) : 0) == 3) {
+ osSyncPrintf("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], windowB[2], MEDIAN3(windowB[0], windowB[1], windowB[2]));
}
- if (((HREG(80) == 0xF) ? HREG(81) : 0) == 1) {
- pxR = MEDIAN3(temp_s0[0], temp_s0[1], temp_s0[2]);
- pxG = MEDIAN3(temp_s1[0], temp_s1[1], temp_s1[2]);
- pxB = MEDIAN3(temp_s2[0], temp_s2[1], temp_s2[2]);
+ // Sample the median value from the 3 pixel wide window
+
+ // (Both blocks contain the same code)
+ if ((HREG(80) == 15 ? HREG(81) : 0) == 1) {
+ pxR = MEDIAN3(windowR[0], windowR[1], windowR[2]);
+ pxG = MEDIAN3(windowG[0], windowG[1], windowG[2]);
+ pxB = MEDIAN3(windowB[0], windowB[1], windowB[2]);
} else {
- pxR = MEDIAN3(temp_s0[0], temp_s0[1], temp_s0[2]);
- pxG = MEDIAN3(temp_s1[0], temp_s1[1], temp_s1[2]);
- pxB = MEDIAN3(temp_s2[0], temp_s2[1], temp_s2[2]);
+ pxR = MEDIAN3(windowR[0], windowR[1], windowR[2]);
+ pxG = MEDIAN3(windowG[0], windowG[1], windowG[2]);
+ pxB = MEDIAN3(windowB[0], windowB[1], windowB[2]);
}
}
pxOut.r = pxR;
@@ -539,26 +764,32 @@ void func_800C2FE4(PreRender* this) {
}
}
-void PreRender_Calc(PreRender* this) {
+/**
+ * Applies the Video Interface anti-aliasing filter and (optionally) the divot filter to `this->fbufSave` using
+ * `this->cvgSave`
+ */
+void PreRender_ApplyFilters(PreRender* this) {
s32 x;
s32 y;
if ((this->cvgSave != NULL) && (this->fbufSave != NULL)) {
-
+ // Apply AA filter
for (y = 0; y < this->height; y++) {
for (x = 0; x < this->width; x++) {
- s32 a = this->cvgSave[x + y * this->width];
+ s32 cvg = this->cvgSave[x + y * this->width];
- a >>= 5;
- a++;
- if (a != 8) {
- func_800C2500(this, x, y);
+ cvg >>= 5;
+ cvg++;
+ if (cvg != 8) {
+ // If this pixel has only partial coverage, perform the Video Filter interpolation on it
+ PreRender_AntiAliasFilter(this, x, y);
}
}
}
- if (HREG(80) == 0xF ? HREG(81) : 0) {
- func_800C2FE4(this);
+ if ((HREG(80) == 15 ? HREG(81) : 0) != 0) {
+ // Apply divot filter
+ PreRender_DivotFilter(this);
}
}
}
diff --git a/src/code/audio_data.c b/src/code/audio_data.c
index 7aec374940..10ddc4601e 100644
--- a/src/code/audio_data.c
+++ b/src/code/audio_data.c
@@ -556,7 +556,7 @@ NoteSubEu gDefaultNoteSub = {
{ 1, 1, 0, 0, 0, 0, 0, 0 }, { 0 }, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
-u16 gHeadsetPanQuantization[64] = {
+u16 gHaasEffectDelaySizes[64] = {
30 * SAMPLE_SIZE,
29 * SAMPLE_SIZE,
28 * SAMPLE_SIZE,
diff --git a/src/code/audio_playback.c b/src/code/audio_playback.c
index 571a3a0c45..87ad945a65 100644
--- a/src/code/audio_playback.c
+++ b/src/code/audio_playback.c
@@ -1,8 +1,9 @@
#include "global.h"
void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
- f32 volRight, volLeft;
- s32 smallPanIndex;
+ f32 volLeft;
+ f32 volRight;
+ s32 halfPanIndex;
u64 pad;
u8 strongLeft;
u8 strongRight;
@@ -31,22 +32,22 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
sub->bitField0.stereoHeadsetEffects = stereoData.stereoHeadsetEffects;
sub->bitField0.usesHeadsetPanEffects = stereoData.usesHeadsetPanEffects;
if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_HEADSET)) {
- smallPanIndex = pan >> 1;
- if (smallPanIndex > 0x3F) {
- smallPanIndex = 0x3F;
+ halfPanIndex = pan >> 1;
+ if (halfPanIndex > 0x3F) {
+ halfPanIndex = 0x3F;
}
- sub->headsetPanLeft = gHeadsetPanQuantization[smallPanIndex];
- sub->headsetPanRight = gHeadsetPanQuantization[0x3F - smallPanIndex];
- sub->bitField1.usesHeadsetPanEffects2 = true;
+ sub->haasEffectRightDelaySize = gHaasEffectDelaySizes[halfPanIndex];
+ sub->haasEffectLeftDelaySize = gHaasEffectDelaySizes[0x3F - halfPanIndex];
+ sub->bitField1.useHaasEffect = true;
volLeft = gHeadsetPanVolume[pan];
volRight = gHeadsetPanVolume[0x7F - pan];
} else if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_STEREO)) {
strongLeft = strongRight = 0;
- sub->headsetPanRight = 0;
- sub->headsetPanLeft = 0;
- sub->bitField1.usesHeadsetPanEffects2 = false;
+ sub->haasEffectLeftDelaySize = 0;
+ sub->haasEffectRightDelaySize = 0;
+ sub->bitField1.useHaasEffect = false;
volLeft = gStereoPanVolume[pan];
volRight = gStereoPanVolume[0x7F - pan];
@@ -945,6 +946,7 @@ void Audio_NoteInitAll(void) {
note->playbackState.portamento.speed = 0;
note->playbackState.stereoHeadsetEffects = false;
note->startSamplePos = 0;
- note->synthesisState.synthesisBuffers = AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, 0x1E0);
+ note->synthesisState.synthesisBuffers =
+ AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, sizeof(NoteSynthesisBuffers));
}
}
diff --git a/src/code/audio_synthesis.c b/src/code/audio_synthesis.c
index 851ae56d9b..a00c57ffae 100644
--- a/src/code/audio_synthesis.c
+++ b/src/code/audio_synthesis.c
@@ -4,7 +4,7 @@
// DMEM Addresses for the RSP
#define DMEM_TEMP 0x3C0
#define DMEM_UNCOMPRESSED_NOTE 0x580
-#define DMEM_NOTE_PAN_TEMP 0x5C0
+#define DMEM_HAAS_TEMP 0x5C0
#define DMEM_SCRATCH2 0x760 // = DMEM_TEMP + DMEM_2CH_SIZE + a bit more
#define DMEM_COMPRESSED_ADPCM_DATA 0x940 // = DMEM_LEFT_CH
#define DMEM_LEFT_CH 0x940
@@ -14,6 +14,12 @@
#define DMEM_WET_LEFT_CH 0xC80
#define DMEM_WET_RIGHT_CH 0xE20 // = DMEM_WET_LEFT_CH + DMEM_1CH_SIZE
+typedef enum {
+ /* 0 */ HAAS_EFFECT_DELAY_NONE,
+ /* 1 */ HAAS_EFFECT_DELAY_LEFT, // Delay left channel so that right channel is heard first
+ /* 2 */ HAAS_EFFECT_DELAY_RIGHT // Delay right channel so that left channel is heard first
+} HaasEffectDelaySide;
+
Acmd* AudioSynth_LoadRingBufferPart(Acmd* cmd, u16 dmem, u16 startPos, s32 size, SynthesisReverb* reverb);
Acmd* AudioSynth_SaveBufferOffset(Acmd* cmd, u16 dmem, u16 offset, s32 size, s16* buf);
Acmd* AudioSynth_SaveRingBufferPart(Acmd* cmd, u16 dmem, u16 startPos, s32 size, SynthesisReverb* reverb);
@@ -21,17 +27,25 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s16* aiBuf,
s32 aiBufLen, Acmd* cmd, s32 updateIndex);
Acmd* AudioSynth_LoadWaveSamples(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 numSamplesToLoad);
-Acmd* AudioSynth_NoteApplyHeadsetPanEffects(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 bufLen,
- s32 flags, s32 side);
+Acmd* AudioSynth_ApplyHaasEffect(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 size, s32 flags,
+ s32 haasEffectDelaySide);
Acmd* AudioSynth_ProcessEnvelope(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 aiBufLen,
- u16 inBuf, s32 headsetPanSettings, s32 flags);
+ u16 dmemSrc, s32 haasEffectDelaySide, s32 flags);
Acmd* AudioSynth_FinalResample(Acmd* cmd, NoteSynthesisState* synthState, s32 size, u16 pitch, u16 inpDmem,
s32 resampleFlags);
-u32 D_801304A0 = _SHIFTL(A_ENVMIXER, 24, 8);
-u32 D_801304A4 = MK_CMD(DMEM_NOTE_PAN_TEMP >> 4, DMEM_RIGHT_CH >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
-u32 D_801304A8 = MK_CMD(DMEM_LEFT_CH >> 4, DMEM_NOTE_PAN_TEMP >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
-u32 D_801304AC = MK_CMD(DMEM_LEFT_CH >> 4, DMEM_RIGHT_CH >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
+u32 sEnvMixerOp = _SHIFTL(A_ENVMIXER, 24, 8);
+
+// Store the left dry channel in a temp space to be delayed to produce the haas effect
+u32 sEnvMixerLeftHaasDmemDests =
+ MK_CMD(DMEM_HAAS_TEMP >> 4, DMEM_RIGHT_CH >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
+
+// Store the right dry channel in a temp space to be delayed to produce the haas effect
+u32 sEnvMixerRightHaasDmemDests =
+ MK_CMD(DMEM_LEFT_CH >> 4, DMEM_HAAS_TEMP >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
+
+u32 sEnvMixerDefaultDmemDests =
+ MK_CMD(DMEM_LEFT_CH >> 4, DMEM_RIGHT_CH >> 4, DMEM_WET_LEFT_CH >> 4, DMEM_WET_RIGHT_CH >> 4);
u16 D_801304B0[] = {
0x7FFF, 0xD001, 0x3FFF, 0xF001, 0x5FFF, 0x9001, 0x7FFF, 0x8001,
@@ -723,7 +737,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
s32 nParts;
s32 curPart;
s32 sampleDataStartPad;
- s32 side;
+ s32 haasEffectDelaySide;
s32 resampledTempLen;
u16 sampleDmemBeforeResampling;
s32 sampleDataOffset;
@@ -752,8 +766,8 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
synthState->samplePosFrac = 0;
synthState->curVolLeft = 0;
synthState->curVolRight = 0;
- synthState->prevHeadsetPanRight = 0;
- synthState->prevHeadsetPanLeft = 0;
+ synthState->prevHaasEffectLeftDelaySize = 0;
+ synthState->prevHaasEffectRightDelaySize = 0;
synthState->reverbVol = noteSubEu->reverbVol;
synthState->numParts = 0;
synthState->unk_1A = 1;
@@ -1078,7 +1092,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
unk7 = noteSubEu->unk_07;
unkE = noteSubEu->unk_0E;
- buf = &synthState->synthesisBuffers->panSamplesBuffer[0x18];
+ buf = synthState->synthesisBuffers->unkState;
if (unk7 != 0 && noteSubEu->unk_0E != 0) {
AudioSynth_DMemMove(cmd++, DMEM_TEMP, DMEM_SCRATCH2, aiBufLen * SAMPLE_SIZE);
thing = DMEM_SCRATCH2 - unk7;
@@ -1095,21 +1109,24 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
synthState->unk_1A = 1;
}
- if (noteSubEu->headsetPanRight != 0 || synthState->prevHeadsetPanRight != 0) {
- side = 1;
- } else if (noteSubEu->headsetPanLeft != 0 || synthState->prevHeadsetPanLeft != 0) {
- side = 2;
+ if ((noteSubEu->haasEffectLeftDelaySize != 0) || (synthState->prevHaasEffectLeftDelaySize != 0)) {
+ haasEffectDelaySide = HAAS_EFFECT_DELAY_LEFT;
+ } else if ((noteSubEu->haasEffectRightDelaySize != 0) || (synthState->prevHaasEffectRightDelaySize != 0)) {
+ haasEffectDelaySide = HAAS_EFFECT_DELAY_RIGHT;
} else {
- side = 0;
+ haasEffectDelaySide = HAAS_EFFECT_DELAY_NONE;
}
- cmd = AudioSynth_ProcessEnvelope(cmd, noteSubEu, synthState, aiBufLen, DMEM_TEMP, side, flags);
- if (noteSubEu->bitField1.usesHeadsetPanEffects2) {
+
+ cmd = AudioSynth_ProcessEnvelope(cmd, noteSubEu, synthState, aiBufLen, DMEM_TEMP, haasEffectDelaySide, flags);
+
+ if (noteSubEu->bitField1.useHaasEffect) {
if (!(flags & A_INIT)) {
flags = A_CONTINUE;
}
- cmd =
- AudioSynth_NoteApplyHeadsetPanEffects(cmd, noteSubEu, synthState, aiBufLen * (s32)SAMPLE_SIZE, flags, side);
+ cmd = AudioSynth_ApplyHaasEffect(cmd, noteSubEu, synthState, aiBufLen * (s32)SAMPLE_SIZE, flags,
+ haasEffectDelaySide);
}
+
return cmd;
}
@@ -1125,8 +1142,8 @@ Acmd* AudioSynth_FinalResample(Acmd* cmd, NoteSynthesisState* synthState, s32 si
}
Acmd* AudioSynth_ProcessEnvelope(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 aiBufLen,
- u16 inBuf, s32 headsetPanSettings, s32 flags) {
- u32 phi_a1;
+ u16 dmemSrc, s32 haasEffectDelaySide, s32 flags) {
+ u32 dmemDests;
u16 curVolLeft;
u16 targetVolLeft;
s32 phi_t1;
@@ -1171,30 +1188,36 @@ Acmd* AudioSynth_ProcessEnvelope(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisS
synthState->curVolLeft = curVolLeft + (rampLeft * (aiBufLen >> 3));
synthState->curVolRight = curVolRight + (rampRight * (aiBufLen >> 3));
- if (noteSubEu->bitField1.usesHeadsetPanEffects2) {
- AudioSynth_ClearBuffer(cmd++, DMEM_NOTE_PAN_TEMP, DMEM_1CH_SIZE);
+ if (noteSubEu->bitField1.useHaasEffect) {
+ AudioSynth_ClearBuffer(cmd++, DMEM_HAAS_TEMP, DMEM_1CH_SIZE);
AudioSynth_EnvSetup1(cmd++, phi_t1 * 2, rampReverb, rampLeft, rampRight);
AudioSynth_EnvSetup2(cmd++, curVolLeft, curVolRight);
- switch (headsetPanSettings) {
- case 1:
- phi_a1 = D_801304A4;
+
+ switch (haasEffectDelaySide) {
+ case HAAS_EFFECT_DELAY_LEFT:
+ // Store the left dry channel in a temp space to be delayed to produce the haas effect
+ dmemDests = sEnvMixerLeftHaasDmemDests;
break;
- case 2:
- phi_a1 = D_801304A8;
+
+ case HAAS_EFFECT_DELAY_RIGHT:
+ // Store the right dry channel in a temp space to be delayed to produce the haas effect
+ dmemDests = sEnvMixerRightHaasDmemDests;
break;
- default:
- phi_a1 = D_801304AC;
+
+ default: // HAAS_EFFECT_DELAY_NONE
+ dmemDests = sEnvMixerDefaultDmemDests;
break;
}
} else {
aEnvSetup1(cmd++, phi_t1 * 2, rampReverb, rampLeft, rampRight);
aEnvSetup2(cmd++, curVolLeft, curVolRight);
- phi_a1 = D_801304AC;
+ dmemDests = sEnvMixerDefaultDmemDests;
}
- aEnvMixer(cmd++, inBuf, aiBufLen, (sourceReverbVol & 0x80) >> 7, noteSubEu->bitField0.stereoHeadsetEffects,
+ aEnvMixer(cmd++, dmemSrc, aiBufLen, (sourceReverbVol & 0x80) >> 7, noteSubEu->bitField0.stereoHeadsetEffects,
noteSubEu->bitField0.usesHeadsetPanEffects, noteSubEu->bitField0.stereoStrongRight,
- noteSubEu->bitField0.stereoStrongLeft, phi_a1, D_801304A0);
+ noteSubEu->bitField0.stereoStrongLeft, dmemDests, sEnvMixerOp);
+
return cmd;
}
@@ -1242,61 +1265,75 @@ Acmd* AudioSynth_LoadWaveSamples(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisS
return cmd;
}
-Acmd* AudioSynth_NoteApplyHeadsetPanEffects(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 bufLen,
- s32 flags, s32 side) {
- u16 dest;
+/**
+ * The Haas Effect gives directionality to sound by appling a small (< 35ms) delay to either the left or right channel.
+ * The delay is small enough that the sound is still perceived as one sound, but the channel that is not delayed will
+ * reach our ear first and give a sense of directionality. The sound is directed towards the opposite side of the delay.
+ */
+Acmd* AudioSynth_ApplyHaasEffect(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s32 size, s32 flags,
+ s32 haasEffectDelaySide) {
+ u16 dmemDest;
u16 pitch;
- u8 prevPanShift;
- u8 panShift;
+ u8 prevHaasEffectDelaySize;
+ u8 haasEffectDelaySize;
- switch (side) {
- case 1:
- dest = DMEM_LEFT_CH;
- panShift = noteSubEu->headsetPanRight;
- prevPanShift = synthState->prevHeadsetPanRight;
- synthState->prevHeadsetPanLeft = 0;
- synthState->prevHeadsetPanRight = panShift;
+ switch (haasEffectDelaySide) {
+ case HAAS_EFFECT_DELAY_LEFT:
+ // Delay the sample on the left channel
+ // This allows the right channel to be heard first
+ dmemDest = DMEM_LEFT_CH;
+ haasEffectDelaySize = noteSubEu->haasEffectLeftDelaySize;
+ prevHaasEffectDelaySize = synthState->prevHaasEffectLeftDelaySize;
+ synthState->prevHaasEffectRightDelaySize = 0;
+ synthState->prevHaasEffectLeftDelaySize = haasEffectDelaySize;
break;
- case 2:
- dest = DMEM_RIGHT_CH;
- panShift = noteSubEu->headsetPanLeft;
- prevPanShift = synthState->prevHeadsetPanLeft;
- synthState->prevHeadsetPanLeft = panShift;
- synthState->prevHeadsetPanRight = 0;
+
+ case HAAS_EFFECT_DELAY_RIGHT:
+ // Delay the sample on the right channel
+ // This allows the left channel to be heard first
+ dmemDest = DMEM_RIGHT_CH;
+ haasEffectDelaySize = noteSubEu->haasEffectRightDelaySize;
+ prevHaasEffectDelaySize = synthState->prevHaasEffectRightDelaySize;
+ synthState->prevHaasEffectRightDelaySize = haasEffectDelaySize;
+ synthState->prevHaasEffectLeftDelaySize = 0;
break;
- default:
+
+ default: // HAAS_EFFECT_DELAY_NONE
return cmd;
}
if (flags != A_INIT) {
- // Slightly adjust the sample rate in order to fit a change in pan shift
- if (panShift != prevPanShift) {
- pitch = (((bufLen << 0xF) / 2) - 1) / ((bufLen + panShift - prevPanShift - 2) / 2);
- aSetBuffer(cmd++, 0, DMEM_NOTE_PAN_TEMP, DMEM_TEMP, bufLen + panShift - prevPanShift);
+ // Slightly adjust the sample rate in order to fit a change in sample delay
+ if (haasEffectDelaySize != prevHaasEffectDelaySize) {
+ pitch = (((size << 0xF) / 2) - 1) / ((size + haasEffectDelaySize - prevHaasEffectDelaySize - 2) / 2);
+ aSetBuffer(cmd++, 0, DMEM_HAAS_TEMP, DMEM_TEMP, size + haasEffectDelaySize - prevHaasEffectDelaySize);
aResampleZoh(cmd++, pitch, 0);
} else {
- aDMEMMove(cmd++, DMEM_NOTE_PAN_TEMP, DMEM_TEMP, bufLen);
+ aDMEMMove(cmd++, DMEM_HAAS_TEMP, DMEM_TEMP, size);
}
- if (prevPanShift != 0) {
- aLoadBuffer(cmd++, &synthState->synthesisBuffers->panResampleState[0x8], DMEM_NOTE_PAN_TEMP,
- ALIGN16(prevPanShift));
- aDMEMMove(cmd++, DMEM_TEMP, DMEM_NOTE_PAN_TEMP + prevPanShift, bufLen + panShift - prevPanShift);
+ if (prevHaasEffectDelaySize != 0) {
+ aLoadBuffer(cmd++, synthState->synthesisBuffers->haasEffectDelayState, DMEM_HAAS_TEMP,
+ ALIGN16(prevHaasEffectDelaySize));
+ aDMEMMove(cmd++, DMEM_TEMP, DMEM_HAAS_TEMP + prevHaasEffectDelaySize,
+ size + haasEffectDelaySize - prevHaasEffectDelaySize);
} else {
- aDMEMMove(cmd++, DMEM_TEMP, DMEM_NOTE_PAN_TEMP, bufLen + panShift);
+ aDMEMMove(cmd++, DMEM_TEMP, DMEM_HAAS_TEMP, size + haasEffectDelaySize);
}
} else {
- // Just shift right
- aDMEMMove(cmd++, DMEM_NOTE_PAN_TEMP, DMEM_TEMP, bufLen);
- aClearBuffer(cmd++, DMEM_NOTE_PAN_TEMP, panShift);
- aDMEMMove(cmd++, DMEM_TEMP, DMEM_NOTE_PAN_TEMP + panShift, bufLen);
+ // Just apply a delay directly
+ aDMEMMove(cmd++, DMEM_HAAS_TEMP, DMEM_TEMP, size);
+ aClearBuffer(cmd++, DMEM_HAAS_TEMP, haasEffectDelaySize);
+ aDMEMMove(cmd++, DMEM_TEMP, DMEM_HAAS_TEMP + haasEffectDelaySize, size);
}
- if (panShift) {
+ if (haasEffectDelaySize) { // != 0
// Save excessive samples for next iteration
- aSaveBuffer(cmd++, DMEM_NOTE_PAN_TEMP + bufLen, &synthState->synthesisBuffers->panResampleState[0x8],
- ALIGN16(panShift));
+ aSaveBuffer(cmd++, DMEM_HAAS_TEMP + size, synthState->synthesisBuffers->haasEffectDelayState,
+ ALIGN16(haasEffectDelaySize));
}
- aAddMixer(cmd++, ALIGN64(bufLen), DMEM_NOTE_PAN_TEMP, dest, 0x7FFF);
+
+ aAddMixer(cmd++, ALIGN64(size), DMEM_HAAS_TEMP, dmemDest, 0x7FFF);
+
return cmd;
}
diff --git a/src/code/z_play.c b/src/code/z_play.c
index aa9076619b..bf21fc5bed 100644
--- a/src/code/z_play.c
+++ b/src/code/z_play.c
@@ -357,8 +357,8 @@ void Play_Init(GameState* thisx) {
SREG(91) = -1;
R_PAUSE_MENU_MODE = PAUSE_MENU_REG_MODE_0;
PreRender_Init(&this->pauseBgPreRender);
- PreRender_SetValuesSave(&this->pauseBgPreRender, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0);
- PreRender_SetValues(&this->pauseBgPreRender, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
+ PreRender_SetValuesSave(&this->pauseBgPreRender, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, NULL);
+ PreRender_SetValues(&this->pauseBgPreRender, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL);
gTrnsnUnkState = 0;
this->transitionMode = TRANS_MODE_OFF;
FrameAdvance_Init(&this->frameAdvCtx);
@@ -1112,7 +1112,7 @@ void Play_Draw(PlayState* this) {
if (R_PAUSE_MENU_MODE == PAUSE_MENU_REG_MODE_2) {
Sched_FlushTaskQueue();
- PreRender_Calc(&this->pauseBgPreRender);
+ PreRender_ApplyFilters(&this->pauseBgPreRender);
R_PAUSE_MENU_MODE = PAUSE_MENU_REG_MODE_3;
} else if (R_PAUSE_MENU_MODE >= PAUSE_MENU_REG_MODE_MAX) {
R_PAUSE_MENU_MODE = PAUSE_MENU_REG_MODE_0;
@@ -1121,7 +1121,7 @@ void Play_Draw(PlayState* this) {
if (R_PAUSE_MENU_MODE == PAUSE_MENU_REG_MODE_3) {
Gfx* sp84 = POLY_OPA_DISP;
- func_800C24BC(&this->pauseBgPreRender, &sp84);
+ PreRender_RestoreFramebuffer(&this->pauseBgPreRender, &sp84);
POLY_OPA_DISP = sp84;
goto Play_Draw_DrawOverlayElements;
} else {
@@ -1238,10 +1238,10 @@ void Play_Draw(PlayState* this) {
this->pauseBgPreRender.fbuf = gfxCtx->curFrameBuffer;
this->pauseBgPreRender.fbufSave = (u16*)gZBuffer;
- func_800C1F20(&this->pauseBgPreRender, &sp70);
+ PreRender_SaveFramebuffer(&this->pauseBgPreRender, &sp70);
if (R_PAUSE_MENU_MODE == PAUSE_MENU_REG_MODE_1) {
this->pauseBgPreRender.cvgSave = (u8*)gfxCtx->curFrameBuffer;
- func_800C20B4(&this->pauseBgPreRender, &sp70);
+ PreRender_DrawCoverage(&this->pauseBgPreRender, &sp70);
R_PAUSE_MENU_MODE = PAUSE_MENU_REG_MODE_2;
} else {
gTrnsnUnkState = 2;
diff --git a/src/overlays/actors/ovl_En_Dodojr/z_en_dodojr.c b/src/overlays/actors/ovl_En_Dodojr/z_en_dodojr.c
index 7ad951decd..824964e707 100644
--- a/src/overlays/actors/ovl_En_Dodojr/z_en_dodojr.c
+++ b/src/overlays/actors/ovl_En_Dodojr/z_en_dodojr.c
@@ -15,21 +15,21 @@ void EnDodojr_Destroy(Actor* thisx, PlayState* play);
void EnDodojr_Update(Actor* thisx, PlayState* play);
void EnDodojr_Draw(Actor* thisx, PlayState* play);
-void func_809F73AC(EnDodojr* this, PlayState* play);
-void func_809F7BE4(EnDodojr* this, PlayState* play);
-void func_809F74C4(EnDodojr* this, PlayState* play);
-void func_809F758C(EnDodojr* this, PlayState* play);
-void func_809F786C(EnDodojr* this, PlayState* play);
-void func_809F799C(EnDodojr* this, PlayState* play);
-void func_809F78EC(EnDodojr* this, PlayState* play);
-void func_809F773C(EnDodojr* this, PlayState* play);
-void func_809F77AC(EnDodojr* this, PlayState* play);
-void func_809F784C(EnDodojr* this, PlayState* play);
-void func_809F7AB8(EnDodojr* this, PlayState* play);
-void func_809F7A00(EnDodojr* this, PlayState* play);
-void func_809F7B3C(EnDodojr* this, PlayState* play);
-void func_809F7C48(EnDodojr* this, PlayState* play);
-void func_809F768C(EnDodojr* this, PlayState* play);
+void EnDodojr_WaitUnderground(EnDodojr* this, PlayState* play);
+void EnDodojr_DropItem(EnDodojr* this, PlayState* play);
+void EnDodojr_EmergeFromGround(EnDodojr* this, PlayState* play);
+void EnDodojr_CrawlTowardsTarget(EnDodojr* this, PlayState* play);
+void EnDodojr_StunnedBounce(EnDodojr* this, PlayState* play);
+void EnDodojr_JumpAttackBounce(EnDodojr* this, PlayState* play);
+void EnDodojr_Stunned(EnDodojr* this, PlayState* play);
+void EnDodojr_SwallowBomb(EnDodojr* this, PlayState* play);
+void EnDodojr_SwallowedBombDeathBounce(EnDodojr* this, PlayState* play);
+void EnDodojr_SwallowedBombDeathSequence(EnDodojr* this, PlayState* play);
+void EnDodojr_StandardDeathBounce(EnDodojr* this, PlayState* play);
+void EnDodojr_Despawn(EnDodojr* this, PlayState* play);
+void EnDodojr_DeathSequence(EnDodojr* this, PlayState* play);
+void EnDodojr_WaitFreezeFrames(EnDodojr* this, PlayState* play);
+void EnDodojr_EatBomb(EnDodojr* this, PlayState* play);
const ActorInit En_Dodojr_InitVars = {
ACTOR_EN_DODOJR,
@@ -80,7 +80,7 @@ void EnDodojr_Init(Actor* thisx, PlayState* play) {
Actor_SetScale(&this->actor, 0.02f);
- this->actionFunc = func_809F73AC;
+ this->actionFunc = EnDodojr_WaitUnderground;
}
void EnDodojr_Destroy(Actor* thisx, PlayState* play) {
@@ -89,12 +89,12 @@ void EnDodojr_Destroy(Actor* thisx, PlayState* play) {
Collider_DestroyCylinder(play, &this->collider);
}
-void func_809F64D0(EnDodojr* this) {
+void EnDodojr_DoSwallowedBombEffects(EnDodojr* this) {
Audio_PlayActorSfx2(&this->actor, NA_SE_IT_BOMB_EXPLOSION);
Actor_SetColorFilter(&this->actor, 0x4000, 200, 0, 8);
}
-void func_809F6510(EnDodojr* this, PlayState* play, s32 count) {
+void EnDodojr_SpawnLargeDust(EnDodojr* this, PlayState* play, s32 count) {
Color_RGBA8 prim = { 170, 130, 90, 255 };
Color_RGBA8 env = { 100, 60, 20, 0 };
Vec3f velocity = { 0.0f, 0.0f, 0.0f };
@@ -116,7 +116,7 @@ void func_809F6510(EnDodojr* this, PlayState* play, s32 count) {
}
}
-void func_809F6730(EnDodojr* this, PlayState* play, Vec3f* arg2) {
+void EnDodojr_SpawnSmallDust(EnDodojr* this, PlayState* play, Vec3f* arg2) {
Color_RGBA8 prim = { 170, 130, 90, 255 };
Color_RGBA8 env = { 100, 60, 20, 0 };
Vec3f velocity = { 0.0f, 0.0f, 0.0f };
@@ -135,32 +135,32 @@ void func_809F6730(EnDodojr* this, PlayState* play, Vec3f* arg2) {
func_8002836C(play, &pos, &velocity, &accel, &prim, &env, 100, 60, 8);
}
-s32 func_809F68B0(EnDodojr* this, PlayState* play) {
+s32 EnDodojr_UpdateBounces(EnDodojr* this, PlayState* play) {
if (this->actor.velocity.y >= 0.0f) {
- return 0;
+ return false;
}
- if (this->unk_1FC == 0) {
- return 0;
+ if (this->counter == 0) {
+ return false;
}
if (this->actor.bgCheckFlags & BGCHECKFLAG_GROUND) {
Audio_PlayActorSfx2(&this->actor, NA_SE_EN_DODO_M_GND);
this->dustPos = this->actor.world.pos;
- func_809F6510(this, play, 10);
- this->actor.velocity.y = 10.0f / (4 - this->unk_1FC);
- this->unk_1FC--;
+ EnDodojr_SpawnLargeDust(this, play, 10);
+ this->actor.velocity.y = 10.0f / (4 - this->counter);
+ this->counter--;
- if (this->unk_1FC == 0) {
+ if (this->counter == 0) {
this->actor.velocity.y = 0.0f;
- return 1;
+ return true;
}
}
- return 0;
+ return false;
}
-void func_809F6994(EnDodojr* this) {
+void EnDodojr_SetupCrawlTowardsTarget(EnDodojr* this) {
f32 lastFrame = Animation_GetLastFrame(&object_dodojr_Anim_000860);
Animation_Change(&this->skelAnime, &object_dodojr_Anim_000860, 1.8f, 0.0f, lastFrame, ANIMMODE_LOOP_INTERP, -10.0f);
@@ -169,7 +169,7 @@ void func_809F6994(EnDodojr* this) {
this->actor.gravity = -0.8f;
}
-void func_809F6A20(EnDodojr* this) {
+void EnDodojr_SetupFlipBounce(EnDodojr* this) {
f32 lastFrame = Animation_GetLastFrame(&object_dodojr_Anim_0004A0);
Animation_Change(&this->skelAnime, &object_dodojr_Anim_0004A0, 1.0f, 0.0f, lastFrame, ANIMMODE_ONCE, -10.0f);
@@ -178,13 +178,13 @@ void func_809F6A20(EnDodojr* this) {
this->actor.velocity.z = 0.0f;
this->actor.gravity = -0.8f;
- if (this->unk_1FC == 0) {
- this->unk_1FC = 3;
+ if (this->counter == 0) {
+ this->counter = 3;
this->actor.velocity.y = 10.0f;
}
}
-void func_809F6AC4(EnDodojr* this) {
+void EnDodojr_SetupSwallowedBombDeathSequence(EnDodojr* this) {
f32 lastFrame = Animation_GetLastFrame(&object_dodojr_Anim_0005F0);
Animation_Change(&this->skelAnime, &object_dodojr_Anim_0005F0, 1.0f, 0.0f, lastFrame, ANIMMODE_LOOP, 0.0f);
@@ -192,26 +192,26 @@ void func_809F6AC4(EnDodojr* this) {
this->actor.gravity = -0.8f;
}
-void func_809F6B38(EnDodojr* this) {
+void EnDodojr_SetupJumpAttackBounce(EnDodojr* this) {
f32 lastFrame = Animation_GetLastFrame(&object_dodojr_Anim_000724);
Animation_Change(&this->skelAnime, &object_dodojr_Anim_000724, 1.0f, 0.0f, lastFrame, ANIMMODE_LOOP, -10.0f);
this->actor.gravity = -0.8f;
- this->unk_1FC = 3;
+ this->counter = 3;
this->actor.velocity.y = 10.0f;
}
-void func_809F6BBC(EnDodojr* this) {
+void EnDodojr_SetupDespawn(EnDodojr* this) {
this->actor.shape.shadowDraw = NULL;
this->actor.flags &= ~ACTOR_FLAG_0;
this->actor.home.pos = this->actor.world.pos;
this->actor.speedXZ = 0.0f;
this->actor.gravity = -0.8f;
- this->timer3 = 30;
+ this->timer = 30;
this->dustPos = this->actor.world.pos;
}
-void func_809F6C24(EnDodojr* this) {
+void EnDodojr_SetupEatBomb(EnDodojr* this) {
Animation_Change(&this->skelAnime, &object_dodojr_Anim_000724, 1.0f, 8.0f, 12.0f, ANIMMODE_ONCE, 0.0f);
Audio_PlayActorSfx2(&this->actor, NA_SE_EN_DODO_M_EAT);
this->actor.speedXZ = 0.0f;
@@ -220,10 +220,10 @@ void func_809F6C24(EnDodojr* this) {
this->actor.gravity = -0.8f;
}
-s32 func_809F6CA4(EnDodojr* this, PlayState* play) {
+s32 EnDodojr_CheckNearbyBombs(EnDodojr* this, PlayState* play) {
Actor* bomb;
- Vec3f unkVec = { 99999.0f, 99999.0f, 99999.0f };
- s32 retVar = 0;
+ Vec3f maxBombRange = { 99999.0f, 99999.0f, 99999.0f };
+ s32 foundBomb = false;
f32 xDist;
f32 yDist;
f32 zDist;
@@ -246,140 +246,140 @@ s32 func_809F6CA4(EnDodojr* this, PlayState* play) {
yDist = bomb->world.pos.y - this->actor.world.pos.y;
zDist = bomb->world.pos.z - this->actor.world.pos.z;
- if ((fabsf(xDist) >= fabsf(unkVec.x)) || (fabsf(yDist) >= fabsf(unkVec.y)) ||
- (fabsf(zDist) >= fabsf(unkVec.z))) {
+ if ((fabsf(xDist) >= fabsf(maxBombRange.x)) || (fabsf(yDist) >= fabsf(maxBombRange.y)) ||
+ (fabsf(zDist) >= fabsf(maxBombRange.z))) {
bomb = bomb->next;
continue;
}
this->bomb = bomb;
- unkVec = bomb->world.pos;
- retVar = 1;
+ maxBombRange = bomb->world.pos;
+ foundBomb = true;
bomb = bomb->next;
}
- return retVar;
+ return foundBomb;
}
-s32 func_809F6DD0(EnDodojr* this) {
+s32 EnDodojr_TryEatBomb(EnDodojr* this) {
if (this->bomb == NULL) {
- return 0;
+ return false;
} else if (this->bomb->parent != NULL) {
- return 0;
+ return false;
} else if (Math_Vec3f_DistXYZ(&this->actor.world.pos, &this->bomb->world.pos) > 30.0f) {
- return 0;
+ return false;
} else {
this->bomb->parent = &this->actor;
- return 1;
+ return true;
}
}
-void func_809F6E54(EnDodojr* this, PlayState* play) {
+void EnDodojr_UpdateCrawl(EnDodojr* this, PlayState* play) {
f32 angles[] = { 0.0f, 210.0f, 60.0f, 270.0f, 120.0f, 330.0f, 180.0f, 30.0f, 240.0f, 90.0f, 300.0f, 150.0f };
s32 pad;
Player* player = GET_PLAYER(play);
- Vec3f pos;
+ Vec3f crawlTargetPos;
s16 angleIndex;
if ((this->bomb == NULL) || (this->bomb->update == NULL) ||
((this->bomb != NULL) && (this->bomb->parent != NULL))) {
- func_809F6CA4(this, play);
+ EnDodojr_CheckNearbyBombs(this, play);
}
if (this->bomb != NULL) {
- pos = this->bomb->world.pos;
+ crawlTargetPos = this->bomb->world.pos;
} else {
- pos = player->actor.world.pos;
+ crawlTargetPos = player->actor.world.pos;
}
- if (Math_Vec3f_DistXYZ(&this->actor.world.pos, &pos) > 80.0f) {
+ if (Math_Vec3f_DistXYZ(&this->actor.world.pos, &crawlTargetPos) > 80.0f) {
angleIndex =
(s16)(this->actor.home.pos.x + this->actor.home.pos.y + this->actor.home.pos.z + play->state.frames / 30) %
12;
angleIndex = ABS(angleIndex);
- pos.x += 80.0f * sinf(angles[angleIndex]);
- pos.z += 80.0f * cosf(angles[angleIndex]);
+ crawlTargetPos.x += 80.0f * sinf(angles[angleIndex]);
+ crawlTargetPos.z += 80.0f * cosf(angles[angleIndex]);
}
- Math_SmoothStepToS(&this->actor.world.rot.y, Math_Vec3f_Yaw(&this->actor.world.pos, &pos), 10, 1000, 1);
+ Math_SmoothStepToS(&this->actor.world.rot.y, Math_Vec3f_Yaw(&this->actor.world.pos, &crawlTargetPos), 10, 1000, 1);
this->actor.shape.rot.y = this->actor.world.rot.y;
}
-s32 func_809F706C(EnDodojr* this) {
+s32 EnDodojr_IsPlayerWithinAttackRange(EnDodojr* this) {
if (this->actor.xzDistToPlayer > 40.0f) {
- return 0;
+ return false;
} else {
- return 1;
+ return true;
}
}
-void func_809F709C(EnDodojr* this) {
+void EnDodojr_SetupStandardDeathBounce(EnDodojr* this) {
Audio_PlayActorSfx2(&this->actor, NA_SE_EN_DODO_M_DEAD);
this->actor.flags &= ~ACTOR_FLAG_0;
- func_809F6A20(this);
- this->actionFunc = func_809F7AB8;
+ EnDodojr_SetupFlipBounce(this);
+ this->actionFunc = EnDodojr_StandardDeathBounce;
}
-s32 func_809F70E8(EnDodojr* this, PlayState* play) {
- if ((this->actionFunc == func_809F773C) || (this->actionFunc == func_809F77AC) ||
- (this->actionFunc == func_809F784C) || (this->actionFunc == func_809F7A00) ||
- (this->actionFunc == func_809F7AB8) || (this->actionFunc == func_809F7B3C) ||
- (this->actionFunc == func_809F7BE4)) {
- return 0;
+s32 EnDodojr_CheckDamaged(EnDodojr* this, PlayState* play) {
+ if ((this->actionFunc == EnDodojr_SwallowBomb) || (this->actionFunc == EnDodojr_SwallowedBombDeathBounce) ||
+ (this->actionFunc == EnDodojr_SwallowedBombDeathSequence) || (this->actionFunc == EnDodojr_Despawn) ||
+ (this->actionFunc == EnDodojr_StandardDeathBounce) || (this->actionFunc == EnDodojr_DeathSequence) ||
+ (this->actionFunc == EnDodojr_DropItem)) {
+ return false;
}
if (play->actorCtx.unk_02 != 0) {
- if (this->actionFunc != func_809F73AC) {
- if (this->actionFunc == func_809F74C4) {
+ if (this->actionFunc != EnDodojr_WaitUnderground) {
+ if (this->actionFunc == EnDodojr_EmergeFromGround) {
this->actor.shape.shadowDraw = ActorShadow_DrawCircle;
}
- func_809F709C(this);
+ EnDodojr_SetupStandardDeathBounce(this);
}
- return 0;
+ return false;
}
if (!(this->collider.base.acFlags & AC_HIT)) {
- return 0;
+ return false;
} else {
this->collider.base.acFlags &= ~AC_HIT;
- if ((this->actionFunc == func_809F73AC) || (this->actionFunc == func_809F74C4)) {
+ if ((this->actionFunc == EnDodojr_WaitUnderground) || (this->actionFunc == EnDodojr_EmergeFromGround)) {
this->actor.shape.shadowDraw = ActorShadow_DrawCircle;
}
if ((this->actor.colChkInfo.damageEffect == 0) && (this->actor.colChkInfo.damage != 0)) {
Enemy_StartFinishingBlow(play, &this->actor);
- this->timer2 = 2;
- this->actionFunc = func_809F7C48;
- return 1;
+ this->freezeFrameTimer = 2;
+ this->actionFunc = EnDodojr_WaitFreezeFrames;
+ return true;
}
- if ((this->actor.colChkInfo.damageEffect == 1) && (this->actionFunc != func_809F78EC) &&
- (this->actionFunc != func_809F786C)) {
+ if ((this->actor.colChkInfo.damageEffect == 1) && (this->actionFunc != EnDodojr_Stunned) &&
+ (this->actionFunc != EnDodojr_StunnedBounce)) {
Audio_PlayActorSfx2(&this->actor, NA_SE_EN_GOMA_JR_FREEZE);
- this->timer1 = 120;
+ this->stunTimer = 120;
Actor_SetColorFilter(&this->actor, 0, 200, 0, 120);
- func_809F6A20(this);
- this->actionFunc = func_809F786C;
+ EnDodojr_SetupFlipBounce(this);
+ this->actionFunc = EnDodojr_StunnedBounce;
}
- return 0;
+ return false;
}
}
-void func_809F72A4(EnDodojr* this, PlayState* play) {
+void EnDodojr_UpdateCollider(EnDodojr* this, PlayState* play) {
Collider_UpdateCylinder(&this->actor, &this->collider);
- if ((this->actionFunc != func_809F73AC) && (this->actionFunc != func_809F7BE4)) {
- if ((this->actionFunc == func_809F74C4) || (this->actionFunc == func_809F758C) ||
- (this->actionFunc == func_809F799C)) {
+ if ((this->actionFunc != EnDodojr_WaitUnderground) && (this->actionFunc != EnDodojr_DropItem)) {
+ if ((this->actionFunc == EnDodojr_EmergeFromGround) || (this->actionFunc == EnDodojr_CrawlTowardsTarget) ||
+ (this->actionFunc == EnDodojr_JumpAttackBounce)) {
CollisionCheck_SetAT(play, &play->colChkCtx, &this->collider.base);
}
- if ((this->actionFunc == func_809F74C4) || (this->actionFunc == func_809F758C) ||
- (this->actionFunc == func_809F786C) || (this->actionFunc == func_809F78EC) ||
- (this->actionFunc == func_809F799C)) {
+ if ((this->actionFunc == EnDodojr_EmergeFromGround) || (this->actionFunc == EnDodojr_CrawlTowardsTarget) ||
+ (this->actionFunc == EnDodojr_StunnedBounce) || (this->actionFunc == EnDodojr_Stunned) ||
+ (this->actionFunc == EnDodojr_JumpAttackBounce)) {
CollisionCheck_SetAC(play, &play->colChkCtx, &this->collider.base);
}
@@ -387,7 +387,7 @@ void func_809F72A4(EnDodojr* this, PlayState* play) {
}
}
-void func_809F73AC(EnDodojr* this, PlayState* play) {
+void EnDodojr_WaitUnderground(EnDodojr* this, PlayState* play) {
f32 lastFrame = Animation_GetLastFrame(&object_dodojr_Anim_000860);
Player* player = GET_PLAYER(play);
f32 dist;
@@ -404,60 +404,61 @@ void func_809F73AC(EnDodojr* this, PlayState* play) {
this->actor.world.rot.x -= 0x4000;
this->actor.shape.rot.x = this->actor.world.rot.x;
this->dustPos = this->actor.world.pos;
+ //! @bug floorHeight is always 0 at this point, so the dust is consistently drawn at y=0
this->dustPos.y = this->actor.floorHeight;
- this->actionFunc = func_809F74C4;
+ this->actionFunc = EnDodojr_EmergeFromGround;
}
}
}
-void func_809F74C4(EnDodojr* this, PlayState* play) {
+void EnDodojr_EmergeFromGround(EnDodojr* this, PlayState* play) {
f32 sp2C;
Math_SmoothStepToS(&this->actor.shape.rot.x, 0, 4, 0x3E8, 0x64);
sp2C = this->actor.shape.rot.x;
sp2C /= 16384.0f;
this->actor.world.pos.y = this->actor.home.pos.y + (60.0f * sp2C);
- func_809F6510(this, play, 3);
+ EnDodojr_SpawnLargeDust(this, play, 3);
if (sp2C == 0.0f) {
this->actor.shape.shadowDraw = ActorShadow_DrawCircle;
this->actor.world.rot.x = this->actor.shape.rot.x;
this->actor.speedXZ = 2.6f;
- this->actionFunc = func_809F758C;
+ this->actionFunc = EnDodojr_CrawlTowardsTarget;
}
}
-void func_809F758C(EnDodojr* this, PlayState* play) {
+void EnDodojr_CrawlTowardsTarget(EnDodojr* this, PlayState* play) {
func_8002D868(&this->actor);
- func_809F6730(this, play, &this->actor.world.pos);
+ EnDodojr_SpawnSmallDust(this, play, &this->actor.world.pos);
- if (DECR(this->timer4) == 0) {
+ if (DECR(this->crawlSfxTimer) == 0) {
Audio_PlayActorSfx2(&this->actor, NA_SE_EN_DODO_M_MOVE);
- this->timer4 = 5;
+ this->crawlSfxTimer = 5;
}
- if (func_809F6DD0(this) != 0) {
- func_809F6C24(this);
- this->actionFunc = func_809F768C;
+ if (EnDodojr_TryEatBomb(this)) {
+ EnDodojr_SetupEatBomb(this);
+ this->actionFunc = EnDodojr_EatBomb;
return;
}
- func_809F6E54(this, play);
+ EnDodojr_UpdateCrawl(this, play);
- if (func_809F706C(this) != 0) {
+ if (EnDodojr_IsPlayerWithinAttackRange(this)) {
Audio_PlayActorSfx2(&this->actor, NA_SE_EN_DODO_M_CRY);
- func_809F6B38(this);
- this->actionFunc = func_809F799C;
+ EnDodojr_SetupJumpAttackBounce(this);
+ this->actionFunc = EnDodojr_JumpAttackBounce;
}
if (this->actor.bgCheckFlags & BGCHECKFLAG_WALL) {
Audio_PlayActorSfx2(&this->actor, NA_SE_EN_DODO_M_DOWN);
- func_809F6BBC(this);
- this->actionFunc = func_809F7A00;
+ EnDodojr_SetupDespawn(this);
+ this->actionFunc = EnDodojr_Despawn;
}
}
-void func_809F768C(EnDodojr* this, PlayState* play) {
+void EnDodojr_EatBomb(EnDodojr* this, PlayState* play) {
EnBom* bomb;
if (((s16)this->skelAnime.curFrame - 8) < 4) {
@@ -467,55 +468,57 @@ void func_809F768C(EnDodojr* this, PlayState* play) {
} else {
Audio_PlayActorSfx2(&this->actor, NA_SE_EN_DODO_K_DRINK);
Actor_Kill(this->bomb);
- this->timer3 = 24;
- this->unk_1FC = 0;
- this->actionFunc = func_809F773C;
+ this->timer = 24;
+ this->counter = 0;
+ this->actionFunc = EnDodojr_SwallowBomb;
}
}
-void func_809F773C(EnDodojr* this, PlayState* play) {
- if (DECR(this->timer3) == 0) {
- func_809F64D0(this);
+void EnDodojr_SwallowBomb(EnDodojr* this, PlayState* play) {
+ if (DECR(this->timer) == 0) {
+ EnDodojr_DoSwallowedBombEffects(this);
this->actor.flags &= ~ACTOR_FLAG_0;
- func_809F6A20(this);
- this->actionFunc = func_809F77AC;
+ EnDodojr_SetupFlipBounce(this);
+ this->actionFunc = EnDodojr_SwallowedBombDeathBounce;
}
}
-void func_809F77AC(EnDodojr* this, PlayState* play) {
+void EnDodojr_SwallowedBombDeathBounce(EnDodojr* this, PlayState* play) {
+ // Scale up briefly to expand from the swallowed bomb exploding.
this->rootScale = 1.2f;
this->rootScale *= ((f32)this->actor.colorFilterTimer / 8);
func_8002D868(&this->actor);
- if (func_809F68B0(this, play) != 0) {
- this->timer3 = 60;
- func_809F6AC4(this);
- this->unk_1FC = 7;
- this->actionFunc = func_809F784C;
+ if (EnDodojr_UpdateBounces(this, play)) {
+ this->timer = 60;
+ EnDodojr_SetupSwallowedBombDeathSequence(this);
+ this->counter = 7;
+ this->actionFunc = EnDodojr_SwallowedBombDeathSequence;
}
}
-void func_809F784C(EnDodojr* this, PlayState* play) {
- func_809F7B3C(this, play);
+void EnDodojr_SwallowedBombDeathSequence(EnDodojr* this, PlayState* play) {
+ EnDodojr_DeathSequence(this, play);
}
-void func_809F786C(EnDodojr* this, PlayState* play) {
+void EnDodojr_StunnedBounce(EnDodojr* this, PlayState* play) {
func_8002D868(&this->actor);
- if (func_809F68B0(this, play) != 0) {
- func_809F6AC4(this);
- this->actionFunc = func_809F78EC;
+ if (EnDodojr_UpdateBounces(this, play)) {
+ EnDodojr_SetupSwallowedBombDeathSequence(this);
+ this->actionFunc = EnDodojr_Stunned;
}
Math_SmoothStepToS(&this->actor.shape.rot.y, 0, 4, 1000, 10);
this->actor.world.rot.x = this->actor.shape.rot.x;
- this->actor.colorFilterTimer = this->timer1;
+ this->actor.colorFilterTimer = this->stunTimer;
}
-void func_809F78EC(EnDodojr* this, PlayState* play) {
- if (DECR(this->timer1) != 0) {
- if (this->timer1 < 30) {
- if ((this->timer1 & 1) != 0) {
+void EnDodojr_Stunned(EnDodojr* this, PlayState* play) {
+ if (DECR(this->stunTimer) != 0) {
+ if (this->stunTimer < 30) {
+ // Shake back and forth to indicate recovering from stun.
+ if ((this->stunTimer & 1) != 0) {
this->actor.world.pos.x += 1.5f;
this->actor.world.pos.z += 1.5f;
} else {
@@ -526,56 +529,56 @@ void func_809F78EC(EnDodojr* this, PlayState* play) {
return;
}
} else {
- func_809F6994(this);
- this->actionFunc = func_809F758C;
+ EnDodojr_SetupCrawlTowardsTarget(this);
+ this->actionFunc = EnDodojr_CrawlTowardsTarget;
}
}
-void func_809F799C(EnDodojr* this, PlayState* play) {
+void EnDodojr_JumpAttackBounce(EnDodojr* this, PlayState* play) {
this->actor.flags |= ACTOR_FLAG_24;
func_8002D868(&this->actor);
- if (func_809F68B0(this, play) != 0) {
- func_809F6994(this);
- this->actionFunc = func_809F758C;
+ if (EnDodojr_UpdateBounces(this, play)) {
+ EnDodojr_SetupCrawlTowardsTarget(this);
+ this->actionFunc = EnDodojr_CrawlTowardsTarget;
}
}
-void func_809F7A00(EnDodojr* this, PlayState* play) {
- f32 tmp;
+void EnDodojr_Despawn(EnDodojr* this, PlayState* play) {
+ f32 burrowStep;
Math_SmoothStepToS(&this->actor.shape.rot.x, 0x4000, 4, 1000, 100);
- if (DECR(this->timer3) != 0) {
- tmp = (30 - this->timer3) / 30.0f;
- this->actor.world.pos.y = this->actor.home.pos.y - (60.0f * tmp);
+ if (DECR(this->timer) != 0) {
+ burrowStep = (30 - this->timer) / 30.0f;
+ this->actor.world.pos.y = this->actor.home.pos.y - (60.0f * burrowStep);
} else {
Actor_Kill(&this->actor);
}
- func_809F6510(this, play, 3);
+ EnDodojr_SpawnLargeDust(this, play, 3);
}
-void func_809F7AB8(EnDodojr* this, PlayState* play) {
+void EnDodojr_StandardDeathBounce(EnDodojr* this, PlayState* play) {
func_8002D868(&this->actor);
Math_SmoothStepToS(&this->actor.shape.rot.y, 0, 4, 1000, 10);
this->actor.world.rot.x = this->actor.shape.rot.x;
- if (func_809F68B0(this, play) != 0) {
- this->timer3 = 60;
- func_809F6AC4(this);
- this->unk_1FC = 7;
- this->actionFunc = func_809F7B3C;
+ if (EnDodojr_UpdateBounces(this, play)) {
+ this->timer = 60;
+ EnDodojr_SetupSwallowedBombDeathSequence(this);
+ this->counter = 7;
+ this->actionFunc = EnDodojr_DeathSequence;
}
}
-void func_809F7B3C(EnDodojr* this, PlayState* play) {
+void EnDodojr_DeathSequence(EnDodojr* this, PlayState* play) {
EnBom* bomb;
- if (this->unk_1FC != 0) {
+ if (this->counter != 0) {
if (this->actor.colorFilterTimer == 0) {
- Actor_SetColorFilter(&this->actor, 0x4000, 200, 0, this->unk_1FC);
- this->unk_1FC--;
+ Actor_SetColorFilter(&this->actor, 0x4000, 200, 0, this->counter);
+ this->counter--;
}
} else {
bomb = (EnBom*)Actor_Spawn(&play->actorCtx, play, ACTOR_EN_BOM, this->actor.world.pos.x,
@@ -585,21 +588,21 @@ void func_809F7B3C(EnDodojr* this, PlayState* play) {
bomb->timer = 0;
}
- this->timer3 = 8;
- this->actionFunc = func_809F7BE4;
+ this->timer = 8;
+ this->actionFunc = EnDodojr_DropItem;
}
}
-void func_809F7BE4(EnDodojr* this, PlayState* play) {
- if (DECR(this->timer3) == 0) {
+void EnDodojr_DropItem(EnDodojr* this, PlayState* play) {
+ if (DECR(this->timer) == 0) {
Item_DropCollectibleRandom(play, NULL, &this->actor.world.pos, 0x40);
Actor_Kill(&this->actor);
}
}
-void func_809F7C48(EnDodojr* this, PlayState* play) {
- if (DECR(this->timer2) == 0) {
- func_809F709C(this);
+void EnDodojr_WaitFreezeFrames(EnDodojr* this, PlayState* play) {
+ if (DECR(this->freezeFrameTimer) == 0) {
+ EnDodojr_SetupStandardDeathBounce(this);
}
}
@@ -608,19 +611,19 @@ void EnDodojr_Update(Actor* thisx, PlayState* play) {
SkelAnime_Update(&this->skelAnime);
Actor_MoveForward(&this->actor);
- func_809F70E8(this, play);
+ EnDodojr_CheckDamaged(this, play);
- if (this->actionFunc != func_809F73AC) {
+ if (this->actionFunc != EnDodojr_WaitUnderground) {
Actor_UpdateBgCheckInfo(play, &this->actor, this->collider.dim.radius, this->collider.dim.height, 0.0f,
UPDBGCHECKINFO_FLAG_0 | UPDBGCHECKINFO_FLAG_2);
}
this->actionFunc(this, play);
Actor_SetFocus(&this->actor, 10.0f);
- func_809F72A4(this, play);
+ EnDodojr_UpdateCollider(this, play);
}
-s32 func_809F7D50(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx) {
+s32 EnDodojr_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx) {
EnDodojr* this = (EnDodojr*)thisx;
Vec3f D_809F7F64 = { 480.0f, 620.0f, 0.0f };
@@ -636,15 +639,15 @@ s32 func_809F7D50(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s
return false;
}
-void func_809F7DFC(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void* thisx) {
+void EnDodojr_PostLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void* thisx) {
}
void EnDodojr_Draw(Actor* thisx, PlayState* play) {
EnDodojr* this = (EnDodojr*)thisx;
- if ((this->actionFunc != func_809F73AC) && (this->actionFunc != func_809F7BE4)) {
+ if ((this->actionFunc != EnDodojr_WaitUnderground) && (this->actionFunc != EnDodojr_DropItem)) {
Gfx_SetupDL_25Opa(play->state.gfxCtx);
- SkelAnime_DrawOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, func_809F7D50, func_809F7DFC,
- &this->actor);
+ SkelAnime_DrawOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, EnDodojr_OverrideLimbDraw,
+ EnDodojr_PostLimbDraw, &this->actor);
}
}
diff --git a/src/overlays/actors/ovl_En_Dodojr/z_en_dodojr.h b/src/overlays/actors/ovl_En_Dodojr/z_en_dodojr.h
index e202095980..bef171c584 100644
--- a/src/overlays/actors/ovl_En_Dodojr/z_en_dodojr.h
+++ b/src/overlays/actors/ovl_En_Dodojr/z_en_dodojr.h
@@ -16,11 +16,11 @@ typedef struct EnDodojr {
/* 0x01E0 */ Actor* bomb;
/* 0x01E4 */ Vec3f headPos;
/* 0x01F0 */ Vec3f dustPos;
- /* 0x01FC */ s16 unk_1FC;
- /* 0x01FE */ s16 timer1;
- /* 0x0200 */ s16 timer2;
- /* 0x0202 */ s16 timer3;
- /* 0x0204 */ s16 timer4;
+ /* 0x01FC */ s16 counter; // Used for bouncing and flashing when dying.
+ /* 0x01FE */ s16 stunTimer;
+ /* 0x0200 */ s16 freezeFrameTimer;
+ /* 0x0202 */ s16 timer; // Used for burrowing/despawning, bomb swallowing, and dying.
+ /* 0x0204 */ s16 crawlSfxTimer;
/* 0x0208 */ f32 rootScale; // scale used with the root limb
/* 0x020C */ Vec3s jointTable[15];
/* 0x0266 */ Vec3s morphTable[15];
diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c
index fe322c0f4f..b0bb7919fc 100644
--- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c
+++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c
@@ -266,8 +266,8 @@ void KaleidoScope_SetupPlayerPreRender(PlayState* play) {
gSPDisplayList(WORK_DISP++, gfx);
PreRender_SetValues(&sPlayerPreRender, PAUSE_EQUIP_PLAYER_WIDTH, PAUSE_EQUIP_PLAYER_HEIGHT, fbuf, NULL);
- func_800C1F20(&sPlayerPreRender, &gfx);
- func_800C20B4(&sPlayerPreRender, &gfx);
+ PreRender_SaveFramebuffer(&sPlayerPreRender, &gfx);
+ PreRender_DrawCoverage(&sPlayerPreRender, &gfx);
gSPEndDisplayList(gfx++);
Graph_BranchDlist(gfxRef, gfx);
@@ -280,7 +280,7 @@ void KaleidoScope_SetupPlayerPreRender(PlayState* play) {
void KaleidoScope_ProcessPlayerPreRender(void) {
Sleep_Msec(50);
- PreRender_Calc(&sPlayerPreRender);
+ PreRender_ApplyFilters(&sPlayerPreRender);
PreRender_Destroy(&sPlayerPreRender);
}