mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-21 08:55:04 -05:00
Tweak: Implement better extended culling options (#4285)
* implement better culling * change draw distance to a slider * remove testing code * tweak
This commit is contained in:
parent
3971e3696e
commit
16aaf2f939
@ -2460,6 +2460,8 @@ void Message_DrawText(PlayState* play, Gfx** gfxP);
|
||||
|
||||
void Interface_CreateQuadVertexGroup(Vtx* vtxList, s32 xStart, s32 yStart, s32 width, s32 height, u8 flippedH);
|
||||
void Interface_RandoRestoreSwordless(void);
|
||||
s32 Ship_CalcShouldDrawAndUpdate(PlayState* play, Actor* actor, Vec3f* projectedPos, f32 projectedW, bool* shouldDraw,
|
||||
bool* shouldUpdate);
|
||||
|
||||
// #endregion
|
||||
|
||||
|
@ -211,6 +211,8 @@ const std::vector<const char*> enhancementsCvars = {
|
||||
"gDisableLOD",
|
||||
"gDisableDrawDistance",
|
||||
"gDisableKokiriDrawDistance",
|
||||
"gEnhancements.WidescreenActorCulling",
|
||||
"gEnhancements.ExtendedCullingExcludeGlitchActors",
|
||||
"gLowResMode",
|
||||
"gDrawLineupTick",
|
||||
"gQuickBongoKill",
|
||||
|
@ -928,16 +928,39 @@ void DrawEnhancementsMenu() {
|
||||
}
|
||||
UIWidgets::PaddedEnhancementCheckbox("Disable LOD", "gDisableLOD", true, false);
|
||||
UIWidgets::Tooltip("Turns off the Level of Detail setting, making models use their higher-poly variants at any distance");
|
||||
if (UIWidgets::PaddedEnhancementCheckbox("Disable Draw Distance", "gDisableDrawDistance", true, false)) {
|
||||
if (CVarGetInteger("gDisableDrawDistance", 0) == 0) {
|
||||
if (UIWidgets::EnhancementSliderInt("Increase Actor Draw Distance: %dx", "##IncreaseActorDrawDistance",
|
||||
"gDisableDrawDistance", 1, 5, "", 1, true, false)) {
|
||||
if (CVarGetInteger("gDisableDrawDistance", 1) <= 1) {
|
||||
CVarSetInteger("gDisableKokiriDrawDistance", 0);
|
||||
}
|
||||
}
|
||||
UIWidgets::Tooltip("Turns off the objects draw distance, making objects being visible from a longer range");
|
||||
if (CVarGetInteger("gDisableDrawDistance", 0) == 1) {
|
||||
UIWidgets::Tooltip("Increases the range in which actors/objects are drawn");
|
||||
if (CVarGetInteger("gDisableDrawDistance", 1) > 1) {
|
||||
UIWidgets::PaddedEnhancementCheckbox("Kokiri Draw Distance", "gDisableKokiriDrawDistance", true, false);
|
||||
UIWidgets::Tooltip("The Kokiri are mystical beings that fade into view when approached\nEnabling this will remove their draw distance");
|
||||
UIWidgets::Tooltip("The Kokiri are mystical beings that fade into view when approached\nEnabling this "
|
||||
"will remove their draw distance");
|
||||
}
|
||||
UIWidgets::PaddedEnhancementCheckbox("Widescreen Actor Culling", "gEnhancements.WidescreenActorCulling",
|
||||
true, false);
|
||||
UIWidgets::Tooltip("Adjusts the horizontal culling plane to account for widescreen resolutions");
|
||||
UIWidgets::PaddedEnhancementCheckbox(
|
||||
"Cull Glitch Useful Actors", "gEnhancements.ExtendedCullingExcludeGlitchActors", true, false,
|
||||
!CVarGetInteger("gEnhancements.WidescreenActorCulling", 0) &&
|
||||
CVarGetInteger("gDisableDrawDistance", 1) <= 1,
|
||||
"Requires Actor Draw Distance to be increased or Widescreen Actor Culling enabled");
|
||||
UIWidgets::Tooltip(
|
||||
"Exclude actors that are useful for glitches from the extended culling ranges.\n"
|
||||
"Some actors may still draw in the extended ranges, but will not \"update\" so that certain "
|
||||
"glitches that leverage the original culling requirements will still work.\n"
|
||||
"\n"
|
||||
"The following actors are excluded:\n"
|
||||
"- White clothed Gerudos\n"
|
||||
"- King Zora\n"
|
||||
"- Gossip Stones\n"
|
||||
"- Boulders\n"
|
||||
"- Blue Warps\n"
|
||||
"- Darunia\n"
|
||||
"- Gold Skulltulas");
|
||||
UIWidgets::PaddedEnhancementCheckbox("N64 Mode", "gLowResMode", true, false);
|
||||
UIWidgets::Tooltip("Sets aspect ratio to 4:3 and lowers resolution to 240p, the N64's native resolution");
|
||||
UIWidgets::PaddedEnhancementCheckbox("Glitch line-up tick", "gDrawLineupTick", true, false);
|
||||
|
@ -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,34 +2849,93 @@ 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
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((arg2->z > -actor->uncullZoneScale) && (arg2->z < (actor->uncullZoneForward + actor->uncullZoneScale))) {
|
||||
var = (arg3 < 1.0f) ? 1.0f : 1.0f / arg3;
|
||||
|
||||
// #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;
|
||||
}
|
||||
|
||||
if ((((fabsf(arg2->x) - actor->uncullZoneScale) * var) < limit) &&
|
||||
(((arg2->y + actor->uncullZoneDownward) * var) > -limit) &&
|
||||
(((arg2->y - actor->uncullZoneScale) * var) < limit)) {
|
||||
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;
|
||||
}
|
||||
// #endregion
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Skip cutscne actors that depend on culling to hide from camera pans
|
||||
if (actor->id == ACTOR_EN_VIEWER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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(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;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
// #endregion
|
||||
|
||||
void func_800315AC(PlayState* play, ActorContext* actorCtx) {
|
||||
s32 invisibleActorCounter;
|
||||
Actor* invisibleActors[INVISIBLE_ACTOR_MAX];
|
||||
@ -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))) {
|
||||
|
@ -101,13 +101,18 @@ static f32 sSpawnSin;
|
||||
s32 EnWood02_SpawnZoneCheck(EnWood02* this, PlayState* play, Vec3f* pos) {
|
||||
f32 phi_f12;
|
||||
|
||||
if (CVarGetInteger("gDisableDrawDistance", 0) != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
SkinMatrix_Vec3fMtxFMultXYZW(&play->viewProjectionMtxF, pos, &this->actor.projectedPos,
|
||||
&this->actor.projectedW);
|
||||
|
||||
// #region SOH [Enhancement] Use the extended culling calculation
|
||||
if (CVarGetInteger("gDisableDrawDistance", 0) || CVarGetInteger("gEnhancements.WidescreenActorCulling", 0)) {
|
||||
bool shipShouldDraw = false;
|
||||
bool shipShouldUpdate = false;
|
||||
return Ship_CalcShouldDrawAndUpdate(play, &this->actor, &this->actor.projectedPos, this->actor.projectedW,
|
||||
&shipShouldDraw, &shipShouldUpdate);
|
||||
}
|
||||
// #endregion
|
||||
|
||||
phi_f12 = ((this->actor.projectedW == 0.0f) ? 1000.0f : fabsf(1.0f / this->actor.projectedW));
|
||||
|
||||
if ((-this->actor.uncullZoneScale < this->actor.projectedPos.z) &&
|
||||
|
@ -275,7 +275,12 @@ void ObjMure_InitialAction(ObjMure* this, PlayState* play) {
|
||||
}
|
||||
|
||||
void ObjMure_CulledState(ObjMure* this, PlayState* play) {
|
||||
if (fabsf(this->actor.projectedPos.z) < sZClip[this->type] || CVarGetInteger("gDisableDrawDistance", 0) != 0) {
|
||||
// #region SOH [Enhancements] Extended draw distance
|
||||
s32 distanceMultiplier = CVarGetInteger("gDisableDrawDistance", 1);
|
||||
distanceMultiplier = MAX(distanceMultiplier, 1);
|
||||
|
||||
if (fabsf(this->actor.projectedPos.z) < sZClip[this->type] * distanceMultiplier) {
|
||||
// #endregion
|
||||
this->actionFunc = ObjMure_ActiveState;
|
||||
this->actor.flags |= ACTOR_FLAG_UPDATE_WHILE_CULLED;
|
||||
ObjMure_SpawnActors(this, play);
|
||||
@ -398,8 +403,13 @@ static ObjMureActionFunc sTypeGroupBehaviorFunc[] = {
|
||||
|
||||
void ObjMure_ActiveState(ObjMure* this, PlayState* play) {
|
||||
ObjMure_CheckChildren(this, play);
|
||||
if (sZClip[this->type] + 40.0f <= fabsf(this->actor.projectedPos.z) &&
|
||||
CVarGetInteger("gDisableDrawDistance", 1) != 0) {
|
||||
|
||||
// #region SOH [Enhancements] Extended draw distance
|
||||
s32 distanceMultiplier = CVarGetInteger("gDisableDrawDistance", 1);
|
||||
distanceMultiplier = MAX(distanceMultiplier, 1);
|
||||
|
||||
if ((sZClip[this->type] + 40.0f) * distanceMultiplier <= fabsf(this->actor.projectedPos.z)) {
|
||||
// #endregion
|
||||
this->actionFunc = ObjMure_CulledState;
|
||||
this->actor.flags &= ~ACTOR_FLAG_UPDATE_WHILE_CULLED;
|
||||
ObjMure_KillActors(this, play);
|
||||
|
@ -190,8 +190,7 @@ void func_80B9A658(ObjMure2* this) {
|
||||
|
||||
void func_80B9A668(ObjMure2* this, PlayState* play) {
|
||||
if (Math3D_Dist1DSq(this->actor.projectedPos.x, this->actor.projectedPos.z) <
|
||||
(sDistSquared1[this->actor.params & 3] * this->unk_184) ||
|
||||
CVarGetInteger("gDisableDrawDistance", 0) != 0) {
|
||||
(sDistSquared1[this->actor.params & 3] * this->unk_184)) {
|
||||
this->actor.flags |= ACTOR_FLAG_UPDATE_WHILE_CULLED;
|
||||
ObjMure2_SpawnActors(this, play);
|
||||
func_80B9A6E8(this);
|
||||
@ -205,12 +204,8 @@ void func_80B9A6E8(ObjMure2* this) {
|
||||
void func_80B9A6F8(ObjMure2* this, PlayState* play) {
|
||||
func_80B9A534(this);
|
||||
|
||||
if (CVarGetInteger("gDisableDrawDistance", 0) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((sDistSquared2[this->actor.params & 3] * this->unk_184) <=
|
||||
Math3D_Dist1DSq(this->actor.projectedPos.x, this->actor.projectedPos.z)) {
|
||||
Math3D_Dist1DSq(this->actor.projectedPos.x, this->actor.projectedPos.z)) {
|
||||
this->actor.flags &= ~ACTOR_FLAG_UPDATE_WHILE_CULLED;
|
||||
ObjMure2_CleanupAndDie(this, play);
|
||||
func_80B9A658(this);
|
||||
@ -225,5 +220,20 @@ void ObjMure2_Update(Actor* thisx, PlayState* play) {
|
||||
} else {
|
||||
this->unk_184 = 4.0f;
|
||||
}
|
||||
|
||||
// SOH [Enhancements] Extended draw distance
|
||||
s32 distanceMultiplier = CVarGetInteger("gDisableDrawDistance", 1);
|
||||
if (CVarGetInteger("gEnhancements.WidescreenActorCulling", 0) || distanceMultiplier > 1) {
|
||||
f32 originalAspectRatio = 4.0f / 3.0f;
|
||||
f32 currentAspectRatio = OTRGetAspectRatio();
|
||||
// Adjust ratio difference based on field of view testing
|
||||
f32 ratioAdjusted = 1.0f + (MAX(currentAspectRatio / originalAspectRatio, 1.0f) / 1.5f);
|
||||
// Distance multiplier is squared due to the checks above for squared distances
|
||||
distanceMultiplier = SQ(MAX(distanceMultiplier, 1));
|
||||
|
||||
// Prefer the largest of the three values
|
||||
this->unk_184 = MAX(MAX((f32)distanceMultiplier, ratioAdjusted), this->unk_184);
|
||||
}
|
||||
|
||||
this->actionFunc(this, play);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user