summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorlouist103 <35883445+louist103@users.noreply.github.com>2022-01-24 18:42:36 -0500
committerGitHub <noreply@github.com>2022-01-25 00:42:36 +0100
commitd1ac7eb80d540be5086b7c1d1cddb02481554b12 (patch)
tree2d811c4ffece0fe87187b58351555245e28e88c5 /src/code
parent1f300f4a797476fe669b2dbd2ed0df28d91ae73b (diff)
Document the lens system (#1079)
* merge master * A little bit * start docs on lens * Delete Jenkinsfile * Make sense of the numbers in `Actor_DrawLensOfTruthMask` f3dzex commands * More comments on `Actor_DrawLens` f3dzex usage * remove padding * renames * Simplify gfx comments * Add some line breaks * Remove undef Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com> Co-authored-by: Louis <louist103@pop-os.localdomain>
Diffstat (limited to 'src/code')
-rw-r--r--src/code/z_actor.c59
-rw-r--r--src/code/z_parameter.c10
2 files changed, 48 insertions, 21 deletions
diff --git a/src/code/z_actor.c b/src/code/z_actor.c
index 235702d20..39db8cafa 100644
--- a/src/code/z_actor.c
+++ b/src/code/z_actor.c
@@ -1944,9 +1944,9 @@ void func_80030488(GlobalContext* globalCtx) {
LightContext_RemoveLight(globalCtx, &globalCtx->lightCtx, D_8015BC10);
}
-void func_800304B0(GlobalContext* globalCtx) {
- if (globalCtx->actorCtx.unk_03 != 0) {
- globalCtx->actorCtx.unk_03 = 0;
+void Actor_DisableLens(GlobalContext* globalCtx) {
+ if (globalCtx->actorCtx.lensActive) {
+ globalCtx->actorCtx.lensActive = false;
func_800876C8(globalCtx);
}
}
@@ -2245,20 +2245,32 @@ void func_80030ED8(Actor* actor) {
}
}
-void func_80030FA8(GraphicsContext* gfxCtx) {
- OPEN_DISPS(gfxCtx, "../z_actor.c", 6161);
+#define LENS_MASK_WIDTH 64
+#define LENS_MASK_HEIGHT 64
+// 26 and 6 are for padding between the mask texture and the screen borders
+#define LENS_MASK_OFFSET_S ((SCREEN_WIDTH / 2 - LENS_MASK_WIDTH) - 26)
+#define LENS_MASK_OFFSET_T ((SCREEN_HEIGHT / 2 - LENS_MASK_HEIGHT) - 6)
- gDPLoadTextureBlock(POLY_XLU_DISP++, gLensOfTruthMaskTex, G_IM_FMT_I, G_IM_SIZ_8b, 64, 64, 0,
- G_TX_MIRROR | G_TX_CLAMP, G_TX_MIRROR | G_TX_CLAMP, 6, 6, G_TX_NOLOD, G_TX_NOLOD);
+void Actor_DrawLensOverlay(GraphicsContext* gfxCtx) {
+ OPEN_DISPS(gfxCtx, "../z_actor.c", 6161);
- gDPSetTileSize(POLY_XLU_DISP++, G_TX_RENDERTILE, 384, 224, 892, 732);
- gSPTextureRectangle(POLY_XLU_DISP++, 0, 0, 1280, 960, G_TX_RENDERTILE, 2240, 1600, 576, 597);
+ gDPLoadTextureBlock(POLY_XLU_DISP++, gLensOfTruthMaskTex, G_IM_FMT_I, G_IM_SIZ_8b, LENS_MASK_WIDTH,
+ LENS_MASK_HEIGHT, 0, G_TX_MIRROR | G_TX_CLAMP, G_TX_MIRROR | G_TX_CLAMP, 6, 6, G_TX_NOLOD,
+ G_TX_NOLOD);
+
+ gDPSetTileSize(POLY_XLU_DISP++, G_TX_RENDERTILE, (SCREEN_WIDTH / 2 - LENS_MASK_WIDTH) << 2,
+ (SCREEN_HEIGHT / 2 - LENS_MASK_HEIGHT) << 2, (SCREEN_WIDTH / 2 + LENS_MASK_WIDTH - 1) << 2,
+ (SCREEN_HEIGHT / 2 + LENS_MASK_HEIGHT - 1) << 2);
+ gSPTextureRectangle(POLY_XLU_DISP++, 0, 0, SCREEN_WIDTH << 2, SCREEN_HEIGHT << 2, G_TX_RENDERTILE,
+ LENS_MASK_OFFSET_S << 5, LENS_MASK_OFFSET_T << 5,
+ (1 << 10) * (SCREEN_WIDTH - 2 * LENS_MASK_OFFSET_S) / SCREEN_WIDTH,
+ (1 << 10) * (SCREEN_HEIGHT - 2 * LENS_MASK_OFFSET_T) / SCREEN_HEIGHT);
gDPPipeSync(POLY_XLU_DISP++);
CLOSE_DISPS(gfxCtx, "../z_actor.c", 6183);
}
-void func_8003115C(GlobalContext* globalCtx, s32 numInvisibleActors, Actor** invisibleActors) {
+void Actor_DrawLensActors(GlobalContext* globalCtx, s32 numInvisibleActors, Actor** invisibleActors) {
Actor** invisibleActor;
GraphicsContext* gfxCtx;
s32 i;
@@ -2272,27 +2284,40 @@ void func_8003115C(GlobalContext* globalCtx, s32 numInvisibleActors, Actor** inv
gDPPipeSync(POLY_XLU_DISP++);
if (globalCtx->roomCtx.curRoom.showInvisActors == 0) {
+ // Update both the color frame buffer and the z-buffer
gDPSetOtherMode(POLY_XLU_DISP++,
G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE |
G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE,
G_AC_THRESHOLD | G_ZS_PRIM | Z_UPD | G_RM_CLD_SURF | G_RM_CLD_SURF2);
+
gDPSetCombineMode(POLY_XLU_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM);
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 255, 0, 0, 255);
+
+ // the z-buffer will later only allow drawing inside the lens circle
} else {
+ // Update the z-buffer but not the color frame buffer
gDPSetOtherMode(POLY_XLU_DISP++,
G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE |
G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE,
G_AC_THRESHOLD | G_ZS_PRIM | Z_UPD | IM_RD | CVG_DST_SAVE | ZMODE_OPA | FORCE_BL |
GBL_c1(G_BL_CLR_BL, G_BL_0, G_BL_CLR_MEM, G_BL_1MA) |
GBL_c2(G_BL_CLR_BL, G_BL_0, G_BL_CLR_MEM, G_BL_1MA));
+
+ // inverts the mask image, which initially is 0 inner and 74 outer,
+ // by setting the combiner to draw 74 - image instead of the image
gDPSetCombineLERP(POLY_XLU_DISP++, PRIMITIVE, TEXEL0, PRIM_LOD_FRAC, 0, PRIMITIVE, TEXEL0, PRIM_LOD_FRAC, 0,
PRIMITIVE, TEXEL0, PRIM_LOD_FRAC, 0, PRIMITIVE, TEXEL0, PRIM_LOD_FRAC, 0);
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0xFF, 74, 74, 74, 74);
+
+ // the z-buffer will later only allow drawing outside the lens circle
}
+ // Together with the depth source set above, this sets the depth to the closest.
+ // For a pixel with such a depth value, the z-buffer will reject drawing to that pixel.
gDPSetPrimDepth(POLY_XLU_DISP++, 0, 0);
- func_80030FA8(gfxCtx);
+ // The z-buffer will be updated where the mask is not fully transparent.
+ Actor_DrawLensOverlay(gfxCtx);
// "Magic lens invisible Actor display START"
gDPNoOpString(POLY_OPA_DISP++, "魔法のメガネ 見えないActor表示 START", numInvisibleActors);
@@ -2308,6 +2333,8 @@ void func_8003115C(GlobalContext* globalCtx, s32 numInvisibleActors, Actor** inv
gDPNoOpString(POLY_OPA_DISP++, "魔法のメガネ 見えないActor表示 END", numInvisibleActors);
if (globalCtx->roomCtx.curRoom.showInvisActors != 0) {
+ // Draw the lens overlay to the color frame buffer
+
gDPNoOpString(POLY_OPA_DISP++, "青い眼鏡(外側)", 0); // "Blue spectacles (exterior)"
gDPPipeSync(POLY_XLU_DISP++);
@@ -2319,7 +2346,7 @@ void func_8003115C(GlobalContext* globalCtx, s32 numInvisibleActors, Actor** inv
gDPSetCombineMode(POLY_XLU_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM);
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 255, 0, 0, 255);
- func_80030FA8(gfxCtx);
+ Actor_DrawLensOverlay(gfxCtx);
gDPNoOpString(POLY_OPA_DISP++, "青い眼鏡(外側)", 1); // "Blue spectacles (exterior)"
}
@@ -2398,7 +2425,7 @@ void func_800315AC(GlobalContext* globalCtx, ActorContext* actorCtx) {
if ((HREG(64) != 1) || ((HREG(65) != -1) && (HREG(65) != HREG(66))) || (HREG(71) == 0)) {
if ((actor->init == NULL) && (actor->draw != NULL) && (actor->flags & (ACTOR_FLAG_5 | ACTOR_FLAG_6))) {
if ((actor->flags & ACTOR_FLAG_7) &&
- ((globalCtx->roomCtx.curRoom.showInvisActors == 0) || (globalCtx->actorCtx.unk_03 != 0) ||
+ ((globalCtx->roomCtx.curRoom.showInvisActors == 0) || globalCtx->actorCtx.lensActive ||
(actor->room != globalCtx->roomCtx.curRoom.num))) {
ASSERT(invisibleActorCounter < INVISIBLE_ACTOR_MAX,
"invisible_actor_counter < INVISIBLE_ACTOR_MAX", "../z_actor.c", 6464);
@@ -2426,10 +2453,10 @@ void func_800315AC(GlobalContext* globalCtx, ActorContext* actorCtx) {
}
if ((HREG(64) != 1) || (HREG(72) != 0)) {
- if (globalCtx->actorCtx.unk_03 != 0) {
- func_8003115C(globalCtx, invisibleActorCounter, invisibleActors);
+ if (globalCtx->actorCtx.lensActive) {
+ Actor_DrawLensActors(globalCtx, invisibleActorCounter, invisibleActors);
if ((globalCtx->csCtx.state != CS_STATE_IDLE) || Player_InCsMode(globalCtx)) {
- func_800304B0(globalCtx);
+ Actor_DisableLens(globalCtx);
}
}
}
diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c
index b3de2f763..c4f70d881 100644
--- a/src/code/z_parameter.c
+++ b/src/code/z_parameter.c
@@ -2272,7 +2272,7 @@ s32 func_80087708(GlobalContext* globalCtx, s16 arg1, s16 arg2) {
case 2:
if ((gSaveContext.unk_13F0 == 0) || (gSaveContext.unk_13F0 == 7)) {
if (gSaveContext.unk_13F0 == 7) {
- globalCtx->actorCtx.unk_03 = 0;
+ globalCtx->actorCtx.lensActive = false;
}
gSaveContext.unk_13F8 = gSaveContext.magic - arg1;
gSaveContext.unk_13F0 = 1;
@@ -2284,7 +2284,7 @@ s32 func_80087708(GlobalContext* globalCtx, s16 arg1, s16 arg2) {
case 1:
if ((gSaveContext.unk_13F0 == 0) || (gSaveContext.unk_13F0 == 7)) {
if (gSaveContext.unk_13F0 == 7) {
- globalCtx->actorCtx.unk_03 = 0;
+ globalCtx->actorCtx.lensActive = false;
}
gSaveContext.unk_13F8 = gSaveContext.magic - arg1;
gSaveContext.unk_13F0 = 6;
@@ -2312,7 +2312,7 @@ s32 func_80087708(GlobalContext* globalCtx, s16 arg1, s16 arg2) {
case 4:
if ((gSaveContext.unk_13F0 == 0) || (gSaveContext.unk_13F0 == 7)) {
if (gSaveContext.unk_13F0 == 7) {
- globalCtx->actorCtx.unk_03 = 0;
+ globalCtx->actorCtx.lensActive = false;
}
gSaveContext.unk_13F8 = gSaveContext.magic - arg1;
gSaveContext.unk_13F0 = 4;
@@ -2459,8 +2459,8 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) {
((gSaveContext.equips.buttonItems[1] != ITEM_LENS) &&
(gSaveContext.equips.buttonItems[2] != ITEM_LENS) &&
(gSaveContext.equips.buttonItems[3] != ITEM_LENS)) ||
- (globalCtx->actorCtx.unk_03 == 0)) {
- globalCtx->actorCtx.unk_03 = 0;
+ !globalCtx->actorCtx.lensActive) {
+ globalCtx->actorCtx.lensActive = false;
Audio_PlaySoundGeneral(NA_SE_SY_GLASSMODE_OFF, &D_801333D4, 4, &D_801333E0, &D_801333E0,
&D_801333E8);
gSaveContext.unk_13F0 = 0;