summaryrefslogtreecommitdiff
path: root/soh/src/code
diff options
context:
space:
mode:
authorArchez <Archez@users.noreply.github.com>2024-08-12 19:39:44 -0400
committerGitHub <noreply@github.com>2024-08-12 19:39:44 -0400
commit16aaf2f93995d421d3a17a77106811f552f02012 (patch)
treeb56d6e47d87972eccfb466da608dc7be1dc5e638 /soh/src/code
parent3971e3696ea022be0eb50c4f0a19f3c5a4806fe6 (diff)
Tweak: Implement better extended culling options (#4285)
* implement better culling * change draw distance to a slider * remove testing code * tweak
Diffstat (limited to 'soh/src/code')
-rw-r--r--soh/src/code/z_actor.c122
1 files changed, 95 insertions, 27 deletions
diff --git a/soh/src/code/z_actor.c b/soh/src/code/z_actor.c
index 0accb49d0..3ccb62bd7 100644
--- a/soh/src/code/z_actor.c
+++ b/soh/src/code/z_actor.c
@@ -1208,14 +1208,6 @@ void Actor_Init(Actor* actor, PlayState* play) {
actor->uncullZoneForward = 1000.0f;
actor->uncullZoneScale = 350.0f;
actor->uncullZoneDownward = 700.0f;
- if (CVarGetInteger("gDisableDrawDistance", 0) != 0 && actor->id != ACTOR_EN_TORCH2 && actor->id != ACTOR_EN_BLKOBJ // Extra check for Dark Link and his room
- && actor->id != ACTOR_EN_HORSE // Check for Epona, else if we call her she will spawn at the other side of the map + we can hear her during the title screen sequence
- && actor->id != ACTOR_EN_HORSE_GANON && actor->id != ACTOR_EN_HORSE_ZELDA // check for Zelda's and Ganondorf's horses that will always be scene during cinematic whith camera paning
- && (play->sceneNum != SCENE_DODONGOS_CAVERN && actor->id != ACTOR_EN_ZF)) { // Check for DC and Lizalfos for the case where the miniboss music would still play under certains conditions and changing room
- actor->uncullZoneForward = 32767.0f;
- actor->uncullZoneScale = 32767.0f;
- actor->uncullZoneDownward = 32767.0f;
- }
CollisionCheck_InitInfo(&actor->colChkInfo);
actor->floorBgId = BGCHECK_SCENE;
ActorShape_Init(&actor->shape, 0.0f, NULL, 0.0f);
@@ -2857,33 +2849,92 @@ s32 func_800314B0(PlayState* play, Actor* actor) {
s32 func_800314D4(PlayState* play, Actor* actor, Vec3f* arg2, f32 arg3) {
f32 var;
- if (CVarGetInteger("gDisableDrawDistance", 0) != 0 && actor->id != ACTOR_EN_TORCH2 && actor->id != ACTOR_EN_BLKOBJ // Extra check for Dark Link and his room
- && actor->id != ACTOR_EN_HORSE // Check for Epona, else if we call her she will spawn at the other side of the map + we can hear her during the title screen sequence
- && actor->id != ACTOR_EN_HORSE_GANON && actor->id != ACTOR_EN_HORSE_ZELDA // check for Zelda's and Ganondorf's horses that will always be scene during cinematic whith camera paning
- && (play->sceneNum != SCENE_DODONGOS_CAVERN && actor->id != ACTOR_EN_ZF)) { // Check for DC and Lizalfos for the case where the miniboss music would still play under certains conditions and changing room
+ if ((arg2->z > -actor->uncullZoneScale) && (arg2->z < (actor->uncullZoneForward + actor->uncullZoneScale))) {
+ var = (arg3 < 1.0f) ? 1.0f : 1.0f / arg3;
+
+ if ((((fabsf(arg2->x) - actor->uncullZoneScale) * var) < 1.0f) &&
+ (((arg2->y + actor->uncullZoneDownward) * var) > -1.0f) &&
+ (((arg2->y - actor->uncullZoneScale) * var) < 1.0f)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// #region SOH [Enhancements] Allows us to increase the draw and update distance independently,
+// mostly a modified version of the function above and additional tweaks for some specfic actors
+s32 Ship_CalcShouldDrawAndUpdate(PlayState* play, Actor* actor, Vec3f* projectedPos, f32 projectedW, bool* shouldDraw,
+ bool* shouldUpdate) {
+ f32 clampedProjectedW;
+
+ // Check if the actor passes its original/vanilla culling requirements
+ if (func_800314D4(play, actor, projectedPos, projectedW)) {
+ *shouldUpdate = true;
+ *shouldDraw = true;
return true;
}
- if ((arg2->z > -actor->uncullZoneScale) && (arg2->z < (actor->uncullZoneForward + actor->uncullZoneScale))) {
- var = (arg3 < 1.0f) ? 1.0f : 1.0f / arg3;
+ // Skip cutscne actors that depend on culling to hide from camera pans
+ if (actor->id == ACTOR_EN_VIEWER) {
+ return false;
+ }
- // #region SoH [Widescreen support]
- // Doors will cull quite noticeably on wider screens. For these actors the zone is increased
- f32 limit = 1.0f;
- if (((actor->id == ACTOR_EN_DOOR) || (actor->id == ACTOR_DOOR_SHUTTER)) && CVarGetInteger("gIncreaseDoorUncullZones", 1)) {
- limit = 2.0f;
+ s32 multiplier = CVarGetInteger("gDisableDrawDistance", 1);
+ multiplier = MAX(multiplier, 1);
+
+ // Some actors have a really short forward value, so we need to add to it before the multiplier to increase the
+ // final strength of the forward culling
+ f32 adder = (actor->uncullZoneForward < 500) ? 1000.0f : 0.0f;
+
+ if ((projectedPos->z > -actor->uncullZoneScale) &&
+ (projectedPos->z < (((actor->uncullZoneForward + adder) * multiplier) + actor->uncullZoneScale))) {
+ clampedProjectedW = (projectedW < 1.0f) ? 1.0f : 1.0f / projectedW;
+
+ f32 ratioAdjusted = 1.0f;
+
+ if (CVarGetInteger("gEnhancements.WidescreenActorCulling", 0)) {
+ f32 originalAspectRatio = 4.0f / 3.0f;
+ f32 currentAspectRatio = OTRGetAspectRatio();
+ ratioAdjusted = MAX(currentAspectRatio / originalAspectRatio, 1.0f);
}
- if ((((fabsf(arg2->x) - actor->uncullZoneScale) * var) < limit) &&
- (((arg2->y + actor->uncullZoneDownward) * var) > -limit) &&
- (((arg2->y - actor->uncullZoneScale) * var) < limit)) {
+ if ((((fabsf(projectedPos->x) - actor->uncullZoneScale) * (clampedProjectedW / ratioAdjusted)) < 1.0f) &&
+ (((projectedPos->y + actor->uncullZoneDownward) * clampedProjectedW) > -1.0f) &&
+ (((projectedPos->y - actor->uncullZoneScale) * clampedProjectedW) < 1.0f)) {
+
+ if (CVarGetInteger("gEnhancements.ExtendedCullingExcludeGlitchActors", 0)) {
+ // These actors are safe to draw without impacting glitches
+ if ((actor->id == ACTOR_OBJ_BOMBIWA || actor->id == ACTOR_OBJ_HAMISHI ||
+ actor->id == ACTOR_EN_ISHI) || // Boulders (hookshot through collision)
+ actor->id == ACTOR_EN_GS || // Gossip stones (text delay)
+ actor->id == ACTOR_EN_GE1 || // White gerudos (gate clip/archery room transition)
+ actor->id == ACTOR_EN_KZ || // King Zora (unfreeze glitch)
+ actor->id == ACTOR_EN_DU || // Darunia (Fire temple BK skip)
+ actor->id == ACTOR_DOOR_WARP1 // Blue warps (wrong warps)
+ ) {
+ *shouldDraw = true;
+ return true;
+ }
+
+ // Skip these actors entirely as their draw funcs impacts glitches
+ if ((actor->id == ACTOR_EN_SW &&
+ (((actor->params & 0xE000) >> 0xD) == 1 ||
+ ((actor->params & 0xE000) >> 0xD) == 2)) // Gold Skulltulas (hitbox at 0,0)
+ ) {
+ return false;
+ }
+ }
+
+ *shouldDraw = true;
+ *shouldUpdate = true;
return true;
}
- // #endregion
}
return false;
}
+// #endregion
void func_800315AC(PlayState* play, ActorContext* actorCtx) {
s32 invisibleActorCounter;
@@ -2920,18 +2971,35 @@ void func_800315AC(PlayState* play, ActorContext* actorCtx) {
}
}
+ // #region SOH [Enhancement] Extended culling updates
+ bool shipShouldDraw = false;
+ bool shipShouldUpdate = false;
if ((HREG(64) != 1) || ((HREG(65) != -1) && (HREG(65) != HREG(66))) || (HREG(70) == 0)) {
- if (func_800314B0(play, actor)) {
- actor->flags |= ACTOR_FLAG_ACTIVE;
+ if (CVarGetInteger("gDisableDrawDistance", 1) > 1 ||
+ CVarGetInteger("gEnhancements.WidescreenActorCulling", 0)) {
+ Ship_CalcShouldDrawAndUpdate(play, actor, &actor->projectedPos, actor->projectedW, &shipShouldDraw,
+ &shipShouldUpdate);
+
+ if (shipShouldUpdate) {
+ actor->flags |= ACTOR_FLAG_ACTIVE;
+ } else {
+ actor->flags &= ~ACTOR_FLAG_ACTIVE;
+ }
} else {
- actor->flags &= ~ACTOR_FLAG_ACTIVE;
+ if (func_800314B0(play, actor)) {
+ actor->flags |= ACTOR_FLAG_ACTIVE;
+ } else {
+ actor->flags &= ~ACTOR_FLAG_ACTIVE;
+ }
}
}
actor->isDrawn = false;
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_DRAW_WHILE_CULLED | ACTOR_FLAG_ACTIVE))) {
+ if ((actor->init == NULL) && (actor->draw != NULL) &&
+ ((actor->flags & (ACTOR_FLAG_DRAW_WHILE_CULLED | ACTOR_FLAG_ACTIVE)) || shipShouldDraw)) {
+ // #endregion
if ((actor->flags & ACTOR_FLAG_LENS) &&
((play->roomCtx.curRoom.lensMode == LENS_MODE_HIDE_ACTORS) ||
play->actorCtx.lensActive || (actor->room != play->roomCtx.curRoom.num))) {