Skip to content

Commit

Permalink
Fix occlusion planes affecting overlays (pause screen and A button) (#…
Browse files Browse the repository at this point in the history
…140)

* Fixed occlusion planes culling pause screen and A button

* lint

* Moved post 3D after goto overlay
  • Loading branch information
sauraen authored Jun 22, 2024
1 parent cda38b1 commit 3ebead3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
8 changes: 8 additions & 0 deletions include/occlusionplanes.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ typedef enum F3DEX3OccMode {
typedef enum OcclusionPlanePhase {
OCCLUSION_PLANE_PHASE_START,
OCCLUSION_PLANE_PHASE_POST_SKY,
OCCLUSION_PLANE_PHASE_POST_3D,
OCCLUSION_PLANE_PHASE_COUNT
} OcclusionPlanePhase;

typedef enum OcclusionPlaneStoredCmdType {
OCCLUSION_PLANE_STORED_CMD_SKY_OPA,
OCCLUSION_PLANE_STORED_CMD_3D_OPA,
OCCLUSION_PLANE_STORED_CMD_3D_XLU,
OCCLUSION_PLANE_STORED_CMD_COUNT
} OcclusionPlaneStoredCmdType;

#endif // OCCLUSIONPLANES_H
38 changes: 28 additions & 10 deletions src/code/occlusionplanes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#if ENABLE_F3DEX3

static Gfx* planeCommands[OCCLUSION_PLANE_PHASE_COUNT];
static Gfx* planeCommands[OCCLUSION_PLANE_STORED_CMD_COUNT];

static s32 OcclusionPlane_Choose(PlayState* play, Vec3f* selCandidate) {
Vec3f* camPos = &play->view.eye;
Expand Down Expand Up @@ -599,14 +599,31 @@ void OcclusionPlane_Draw_Phase(PlayState* play, OcclusionPlanePhase phase) {

GraphicsContext* gfxCtx = play->state.gfxCtx;
OPEN_DISPS(gfxCtx, "occlusionplanes.c", __LINE__);
planeCommands[phase] = POLY_OPA_DISP;
gSPOcclusionPlane(POLY_OPA_DISP++, &sNoOcclusionPlane);
CLOSE_DISPS(gfxCtx, "occlusionplanes.c", __LINE__);

if (phase == OCCLUSION_PLANE_PHASE_START) {
// Post sky might not happen in debug
planeCommands[OCCLUSION_PLANE_PHASE_POST_SKY] = NULL;
switch (phase) {
case OCCLUSION_PLANE_PHASE_START:
planeCommands[OCCLUSION_PLANE_STORED_CMD_SKY_OPA] = POLY_OPA_DISP;
gSPOcclusionPlane(POLY_OPA_DISP++, &sNoOcclusionPlane);

// Later phases might not happen if debug registers are set up certain way
planeCommands[OCCLUSION_PLANE_STORED_CMD_3D_OPA] = NULL;
planeCommands[OCCLUSION_PLANE_STORED_CMD_3D_XLU] = NULL;
break;
case OCCLUSION_PLANE_PHASE_POST_SKY:
planeCommands[OCCLUSION_PLANE_STORED_CMD_3D_OPA] = POLY_OPA_DISP;
gSPOcclusionPlane(POLY_OPA_DISP++, &sNoOcclusionPlane);
planeCommands[OCCLUSION_PLANE_STORED_CMD_3D_XLU] = POLY_XLU_DISP;
gSPOcclusionPlane(POLY_XLU_DISP++, &sNoOcclusionPlane);
break;
case OCCLUSION_PLANE_PHASE_POST_3D:
// Need to turn it off in OPA to draw the pause screen
gSPOcclusionPlane(POLY_OPA_DISP++, &sNoOcclusionPlane);
// Need to turn it off at the end of XLU (for OVL) for the HUD
gSPOcclusionPlane(POLY_XLU_DISP++, &sNoOcclusionPlane);
break;
}

CLOSE_DISPS(gfxCtx, "occlusionplanes.c", __LINE__);
}

void OcclusionPlane_Draw_PostCamUpdate(PlayState* play) {
Expand Down Expand Up @@ -638,10 +655,11 @@ void OcclusionPlane_Draw_PostCamUpdate(PlayState* play) {
skyPlane->o.ky = 0;
skyPlane->o.kz = 0;
skyPlane->o.kc = 0x7FFF;
((u32*)(planeCommands[OCCLUSION_PLANE_PHASE_START]))[1] = (u32)skyPlane;
((u32*)(planeCommands[OCCLUSION_PLANE_STORED_CMD_SKY_OPA]))[1] = (u32)skyPlane;
}
if (planeCommands[OCCLUSION_PLANE_PHASE_POST_SKY] != NULL) {
((u32*)(planeCommands[OCCLUSION_PLANE_PHASE_POST_SKY]))[1] = (u32)mainPlane;
if (planeCommands[OCCLUSION_PLANE_STORED_CMD_3D_OPA] != NULL) {
((u32*)(planeCommands[OCCLUSION_PLANE_STORED_CMD_3D_OPA]))[1] = (u32)mainPlane;
((u32*)(planeCommands[OCCLUSION_PLANE_STORED_CMD_3D_XLU]))[1] = (u32)mainPlane;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/code/z_play.c
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,10 @@ void Play_Draw(PlayState* this) {
}

Play_Draw_DrawOverlayElements:
#if ENABLE_F3DEX3
OcclusionPlane_Draw_Phase(this, OCCLUSION_PLANE_PHASE_POST_3D);
#endif

if (!IS_DEBUG || (R_HREG_MODE != HREG_MODE_PLAY) || R_PLAY_DRAW_OVERLAY_ELEMENTS) {
Play_DrawOverlayElements(this);
}
Expand Down

0 comments on commit 3ebead3

Please sign in to comment.