Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sauraen committed Jun 7, 2024
1 parent c406642 commit 118f391
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,7 @@ void Play_DisableMotionBlur(void);

#if ENABLE_F3DEX3
void OcclusionPlane_NewScene(PlayState* play);
void OcclusionPlane_SceneCmd(PlayState* play, OcclusionPlaneCandidate* list, u8 count);
void OcclusionPlane_Draw_Phase(PlayState* play, OcclusionPlanePhase phase);
void OcclusionPlane_Draw_PostCamUpdate(PlayState* play);
#endif
Expand Down
24 changes: 23 additions & 1 deletion src/code/occlusionplanes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

static s32 OcclusionPlane_Choose(PlayState* play){
OcclusionPlaneContext* ctx = &play->occPlaneCtx;
if(ctx->list == NULL || ctx->count == 0) return 1;

Vec3f* camPos = &play->view.eye;
Vec3f camDir = (Vec3f){play->view.at.x - camPos->x, play->view.at.y - camPos->y, play->view.at.z - camPos->z};
Expand Down Expand Up @@ -542,11 +541,31 @@ static OcclusionPlane* ComputeOcclusionPlane(PlayState* play, Vec3f* worldBounds
return occ;
}

static bool ShouldBotherComputingOccPlanes(PlayState* play){
OcclusionPlaneContext* ctx = &play->occPlaneCtx;
if(ctx->list == NULL || ctx->count == 0) return false;
if(gF3DEX3OccMode == F3DEX3_OCC_MODE_NEVER) return false;
return true;
}

void OcclusionPlane_NewScene(PlayState* play){
play->occPlaneCtx.list = NULL;
if(gF3DEX3OccMode == F3DEX3_OCC_MODE_AUTO){
gF3DEX3NOCVersion = 1; // Enable NOC
}
}

void OcclusionPlane_SceneCmd(PlayState* play, OcclusionPlaneCandidate* list, u8 count){
play->occPlaneCtx.list = list;
play->occPlaneCtx.count = count;
if(gF3DEX3OccMode == F3DEX3_OCC_MODE_AUTO){
gF3DEX3NOCVersion = (count == 0); // NOC if no planes, otherwise normal
}
}

void OcclusionPlane_Draw_Phase(PlayState* play, OcclusionPlanePhase phase){
if(!ShouldBotherComputingOccPlanes(play)) return;

GraphicsContext* gfxCtx = play->state.gfxCtx;
OPEN_DISPS(gfxCtx, "occlusionplanes.c", __LINE__);
play->occPlaneCtx.planeCommands[phase] = POLY_OPA_DISP;
Expand All @@ -560,9 +579,12 @@ void OcclusionPlane_Draw_Phase(PlayState* play, OcclusionPlanePhase phase){
}

void OcclusionPlane_Draw_PostCamUpdate(PlayState* play){
if(!ShouldBotherComputingOccPlanes(play)) return;

OcclusionPlaneContext* ctx = &play->occPlaneCtx;
s32 result = OcclusionPlane_Choose(play);
if(result != 0) return;

OcclusionPlane* mainPlane = ComputeOcclusionPlane(play, ctx->selCandidate);
if(mainPlane != &sNoOcclusionPlane){
OcclusionPlane* skyPlane = mainPlane;
Expand Down
4 changes: 2 additions & 2 deletions src/code/sys_ucode.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ __attribute__((aligned(16))) u8 gF3DEX3DataBuffer[F3DEX3_DATA_MAX_SIZE];

volatile s8 gLoadedF3DEX3Version = -1;
volatile s8 gF3DEX3ProfVersion = 0;
volatile s8 gF3DEX3NOCVersion = 0;
s8 gF3DEX3OccMode = 0;
volatile s8 gF3DEX3NOCVersion = 1;
s8 gF3DEX3OccMode = F3DEX3_OCC_MODE_AUTO;

void SysUcode_LoadNewUcodeIfChanged() {
s8 ver = gF3DEX3ProfVersion | (gF3DEX3NOCVersion << 2);
Expand Down
4 changes: 2 additions & 2 deletions src/code/z_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ BAD_RETURN(s32) Scene_CommandMiscSettings(PlayState* play, SceneCmd* cmd) {

#if ENABLE_F3DEX3
BAD_RETURN(s32) Scene_CommandOccPlaneCandList(PlayState* play, SceneCmd* cmd){
play->occPlaneCtx.list = SEGMENTED_TO_VIRTUAL(cmd->occPlaneCandList.list);
play->occPlaneCtx.count = cmd->occPlaneCandList.count;
OcclusionPlane_SceneCmd(play, SEGMENTED_TO_VIRTUAL(cmd->occPlaneCandList.list),
cmd->occPlaneCandList.count);
}
#endif

Expand Down
4 changes: 4 additions & 0 deletions src/debug/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ void Menu_Update(Menu* this) {
u8 pressDRight = CHECK_BTN_ALL(pressBtn, BTN_DRIGHT);
u8 i;

if(!this->bShow && !isHoldingR && pressDLeft){
gF3DEX3NOCVersion ^= 1;
}

if (isHoldingR && CHECK_BTN_ALL(pressBtn, BTN_L)) {
this->bShow ^= 1;
}
Expand Down

0 comments on commit 118f391

Please sign in to comment.