Skip to content

Commit

Permalink
Refactor opacity computation algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed May 12, 2022
1 parent ce095d6 commit 4463a26
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Osu.Objects;
using osuTK;

Expand Down Expand Up @@ -85,19 +86,33 @@ public OsuDifficultyHitObject(HitObject hitObject, HitObject lastLastObject, Hit
setDistances(clockRate);
}

public double Opacity(double mapTime, bool hidden)
public double OpacityAt(double time, bool hidden)
{
double ms = BaseObject.StartTime - mapTime;
if (ms < 0)
if (time > BaseObject.StartTime)
{
// Consider a hitobject as being invisible when its start time is passed.
// In reality the hitobject will be visible beyond its start time up until its hittable window has passed,
// but this is an approximation and such a case is unlikely to be hit where this function is used.
return 0.0;
}

double preemptTime = BaseObject.TimePreempt;
double fadeInTime = BaseObject.TimeFadeIn;
double fadeInStartTime = BaseObject.StartTime - BaseObject.TimePreempt;
double fadeInDuration = BaseObject.TimeFadeIn;

if (hidden)
return Math.Clamp(Math.Min((1.0 - ms / preemptTime) * 2.5, (ms / preemptTime - 0.3) * (1.0 / 0.3)), 0.0, 1.0);
else
return Math.Clamp((preemptTime - ms) / fadeInTime, 0.0, 1.0);
{
// Taken from OsuModHidden.
double fadeOutStartTime = BaseObject.StartTime - BaseObject.TimePreempt + BaseObject.TimeFadeIn;
double fadeOutDuration = BaseObject.TimePreempt * OsuModHidden.FADE_OUT_DURATION_MULTIPLIER;

return Math.Min
(
Math.Clamp((time - fadeInStartTime) / fadeInDuration, 0.0, 1.0),
1.0 - Math.Clamp((time - fadeOutStartTime) / fadeOutDuration, 0.0, 1.0)
);
}

return Math.Clamp((time - fadeInStartTime) / fadeInDuration, 0.0, 1.0);
}

private void setDistances(double clockRate)
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Difficulty/Skills/Flashlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private double strainValueOf(DifficultyHitObject current)
double stackNerf = Math.Min(1.0, (currentObj.LazyJumpDistance / scalingFactor) / 25.0);

// Bonus based on how visible the object is.
double opacityBonus = 1.0 + max_opacity_bonus * (1.0 - osuCurrent.Opacity(currentHitObject.StartTime, hidden));
double opacityBonus = 1.0 + max_opacity_bonus * (1.0 - osuCurrent.OpacityAt(currentHitObject.StartTime, hidden));

result += stackNerf * opacityBonus * scalingFactor * jumpDistance / cumulativeStrainTime;
}
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class OsuModHidden : ModHidden, IHidesApproachCircles

public override Type[] IncompatibleMods => new[] { typeof(IRequiresApproachCircles), typeof(OsuModSpinIn) };

private const double fade_in_duration_multiplier = 0.4;
private const double fade_out_duration_multiplier = 0.3;
public const double FADE_IN_DURATION_MULTIPLIER = 0.4;
public const double FADE_OUT_DURATION_MULTIPLIER = 0.3;

protected override bool IsFirstAdjustableObject(HitObject hitObject) => !(hitObject is Spinner || hitObject is SpinnerTick);

Expand All @@ -41,7 +41,7 @@ public override void ApplyToBeatmap(IBeatmap beatmap)

static void applyFadeInAdjustment(OsuHitObject osuObject)
{
osuObject.TimeFadeIn = osuObject.TimePreempt * fade_in_duration_multiplier;
osuObject.TimeFadeIn = osuObject.TimePreempt * FADE_IN_DURATION_MULTIPLIER;
foreach (var nested in osuObject.NestedHitObjects.OfType<OsuHitObject>())
applyFadeInAdjustment(nested);
}
Expand Down Expand Up @@ -156,7 +156,7 @@ private void applyHiddenState(DrawableHitObject drawableObject, bool increaseVis
static (double fadeStartTime, double fadeDuration) getParameters(OsuHitObject hitObject)
{
double fadeOutStartTime = hitObject.StartTime - hitObject.TimePreempt + hitObject.TimeFadeIn;
double fadeOutDuration = hitObject.TimePreempt * fade_out_duration_multiplier;
double fadeOutDuration = hitObject.TimePreempt * FADE_OUT_DURATION_MULTIPLIER;

// new duration from completed fade in to end (before fading out)
double longFadeDuration = hitObject.GetEndTime() - fadeOutStartTime;
Expand Down

0 comments on commit 4463a26

Please sign in to comment.