Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor OsuDifficultyHitObject for readability/understandability #15774

Merged
merged 15 commits into from
Dec 9, 2021

Conversation

smoogipoo
Copy link
Contributor

I recommend going through this PR per-commit as the diff is a little bit of a mess.

  • The primary issue I had is that TravelDistance and TravelTime stored information about the previous hitobject, in the current hitobject. I've made these two store information about the current hitobject only.
  • The rest is a bit of refactoring to clean things up - property ordering, naming (American vs British English), and expanding on the comment describing how MovementDistance is calculated.

I've tested that SR and difficulty attributes don't change compared to current master.

@@ -50,7 +50,7 @@ private double strainValueOf(DifficultyHitObject current)
if (osuLastObj.BaseObject is Slider && withSliders)
Copy link
Member

@peppy peppy Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirm that this is still correct as osuLastObj here? Looks weird with the changes inside this conditional now reading from one index back while the conditional itself isn't.

(it probably is, just a hard change to read due to how complex things are)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the reasons for me changing it, because it was using osuCurrObj.TravelDistance to access the travel distance of osuLastObj.

So yes, this condition is still fine as it is, the only change is that the properties apply directly to the relevant hitobject now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add on as to why - all these blocks of code try to do (perhaps not explained enough in the leading comments?) is to calculate the velocity through a previous slider into the current object. One part is stored in the previous object (travel), and the other is stored in the current object (jump / movement, however you want to think about it).

peppy
peppy previously approved these changes Nov 24, 2021
@peppy peppy requested a review from bdach November 24, 2021 05:34
@smoogipoo
Copy link
Contributor Author

Don't merge this yet as I realised my testing was flawed. Will unblock after re-confirming SR is unaffected.

@smoogipoo smoogipoo added the blocked Don't merge this. label Nov 24, 2021
@smoogipoo smoogipoo removed the blocked Don't merge this. label Nov 24, 2021
@smoogipoo
Copy link
Contributor Author

Found an issue and re-tested, looks okay now.

/// <remarks>
/// This is bounded by <see cref="JumpDistance"/>, but may be smaller if a more natural path is able to be taken through a preceding slider.
/// </remarks>
public double MovementDistance { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename it to something like MinimumMovementDistance? Overall distance/time fields could use better naming so that it can be more obvious which does what without reading docs every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to MinimumJumpDistance.

Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't looked at diffcalc for a while but the transformation generally looks correct to me. Just want to clarify one xmldoc (there's also a nitpick in this review but I don't care about it very much)

@smoogipoo
Copy link
Contributor Author

I've applied some renames + documented a bit more thoroughly. Let me know if this is understandable now.

@stanriders
Copy link
Member

Yep, seems much better to me now

@bdach
Copy link
Collaborator

bdach commented Dec 7, 2021

The latest update to docs/names looks good to me now, but there is a merge conflict here and I'm unsure whether my resolution is correct... I think this would be the correct one?

diff --cc osu.Game.Rulesets.Osu/Difficulty/Skills/Speed.cs
index 75a9b13bdf,4f87767fa7..ca89236258
--- a/osu.Game.Rulesets.Osu/Difficulty/Skills/Speed.cs
+++ b/osu.Game.Rulesets.Osu/Difficulty/Skills/Speed.cs
@@@ -154,8 -154,7 +154,7 @@@ namespace osu.Game.Rulesets.Osu.Difficu
              if (strainTime < min_speed_bonus)
                  speedBonus = 1 + 0.75 * Math.Pow((min_speed_bonus - strainTime) / speed_balancing_factor, 2);
  
-             double travelDistance = osuPrevObj?.TravelDistance ?? 0;
-             double distance = Math.Min(single_spacing_threshold, travelDistance + osuCurrObj.LazyJumpDistance);
 -            double distance = Math.Min(single_spacing_threshold, osuCurrObj.TravelDistance + osuCurrObj.MovementDistance);
++            double distance = Math.Min(single_spacing_threshold, osuCurrObj.TravelDistance + osuCurrObj.MinimumJumpDistance);
  
              return (speedBonus + speedBonus * Math.Pow(distance / single_spacing_threshold, 3.5)) / strainTime;
          }

// 2. <======o==>---o
// |______|
//
// Where "<==>" represents a slider, and "o" represents where the cursor needs to be for either hitobject (for a slider, this is the lazy cursor position).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend representing the cursor location with something that isn't a "o". This reads as if it's hitobjects, which can make for confusion here. How about using a * or x or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

// | /
// o
// x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't quite understand what this diagram is trying to explain, but as long as others can maybe it's okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diagrams show how the natural movement path of a player changes depending on what the angle of a follow-up circle is, and how using the lazy cursor end is completely fine in diagram 1 ("players will cut the slider short in order to move to the next object"), but will overestimate the perceived jump distance in diagram 2 ("players will follow the slider through to its visual extent").

I don't know how to better explain it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I supposed to know that there's a second object below the slider in the first diagram? So the "x" represents the position of the slider ball and also the position of the next object here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it represents the final position your cursor needs to be in a slider given the most lazy movements (following at the edge of the follow circle at all times) + the -36ms offset for the last slider tick.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the downwards movement implies there's something beneath it right? If so it's be nice to show that next object to give more context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misunderstood what you meant, I thought you were referring to the "x" on the slider track.

How should I show that the "x" below the slider is another hitobject? Any suggestions? Would this be better?
image
I can't easily add the same text to the second diagram...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe they should be shown using o after all, and the documentation should not mention anything about the cursor position. The cursor movement is shown by the single-width line, which should be ample to explain the concept here.

Might help to split the diagram out into two versions beside each other: one with the "lazy" movement and one with the "correct" movement (ie the one denoted by /). Feels weird showing both on the same diagram.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've restructured it, see if it's better now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, much better.

@smoogipoo
Copy link
Contributor Author

@bdach I've resolved conflicts, note that your patch is slightly incorrect because this PR moves TravelDistance to the hitobject which is actually being traveled.

@bdach bdach requested a review from peppy December 8, 2021 18:20
@peppy peppy merged commit 603ba61 into ppy:master Dec 9, 2021
smoogipoo added a commit to smoogipoo/osu that referenced this pull request Jan 17, 2022
…iculty-hit-object"

This reverts commit 603ba61, reversing
changes made to b393f83.
@smoogipoo smoogipoo deleted the refactor-osu-difficulty-hit-object branch September 11, 2023 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants