From eafe6b5cad25d6d3c063ff4a57693cf927cd24f2 Mon Sep 17 00:00:00 2001 From: Tunnelblick <38663241+Tunnelbliick@users.noreply.github.com> Date: Tue, 14 May 2024 23:07:12 +0200 Subject: [PATCH] 2.21 - Fixed Scaling code - Added option for lastPosition in RenderByEquation - Optimized Hitlighting -- Only Moving it if there is actually something to hit -- Decreasing the Fade commands by combining them effectively halfing the amount of commands per note --- Draw/Renderers/ByEquation.cs | 11 ++-- Draw/Renderers/RenderReceptor.cs | 11 +++- PlayField/Notes/Note.cs | 2 +- PlayField/Playfield.cs | 86 ++++++++++++++++++++++++-------- utility/Hitsounds.cs | 61 +++++++++------------- 5 files changed, 106 insertions(+), 65 deletions(-) diff --git a/Draw/Renderers/ByEquation.cs b/Draw/Renderers/ByEquation.cs index ed84b90..06a84cd 100644 --- a/Draw/Renderers/ByEquation.cs +++ b/Draw/Renderers/ByEquation.cs @@ -15,6 +15,7 @@ namespace StorybrewScripts public class EquationParameters { public Vector2 position; + public Vector2 lastPosition; public double time; public float progress; public OsbSprite sprite; @@ -116,7 +117,8 @@ public static string drawViaEquation(DrawInstance instance, double duration, Equ note.Scale(currentTime, currentTime, OsbEasing.None, column.origin.ScaleAt(currentTime), column.origin.ScaleAt(currentTime)); - double startRotation = note.getRotation(currentTime); + double startRotation = column.receptor.RotationAt(currentTime); + rotation.Add(currentTime, (float)startRotation, EasingFunctions.ToEasingFunction(easing)); do { @@ -193,6 +195,7 @@ public static string drawViaEquation(DrawInstance instance, double duration, Equ var par = new EquationParameters { position = newPosition, + lastPosition = currentPosition, time = currentTime, progress = easedProgress, sprite = note.noteSprite, @@ -217,7 +220,7 @@ public static string drawViaEquation(DrawInstance instance, double duration, Equ } theta = Math.Atan2(delta.X, delta.Y); } - + movement.Add(currentTime + localIterationRate, newPosition, EasingFunctions.ToEasingFunction(easing)); scale.Add(currentTime + localIterationRate, scaleProgress, EasingFunctions.ToEasingFunction(easing)); rotation.Add(currentTime + localIterationRate, (float)(startRotation - theta), EasingFunctions.ToEasingFunction(easing)); @@ -341,6 +344,7 @@ public static string drawViaEquation(DrawInstance instance, double duration, Equ var par = new EquationParameters { position = newPosition, + lastPosition = currentSliderPositon, time = sliderCurrentTime, progress = easedProgress, sprite = sprite, @@ -353,6 +357,7 @@ public static string drawViaEquation(DrawInstance instance, double duration, Equ var parNext = new EquationParameters { position = nextPosition, + lastPosition = currentSliderPositon, time = sliderCurrentTime, progress = easedNextProgress, sprite = null, @@ -413,9 +418,9 @@ public static string drawViaEquation(DrawInstance instance, double duration, Equ SliderMovement.Simplify(instance.HoldMovementPrecision); SliderScale.Simplify(instance.HoldScalePrecision); SliderRotation.Simplify(instance.HoldRotationPrecision); - SliderMovement.ForEachPair((start, end) => sprite.Move(OsbEasing.None, start.Time, end.Time, start.Value, end.Value)); SliderScale.ForEachPair((start, end) => sprite.ScaleVec(start.Time, end.Time, start.Value.X, start.Value.Y, end.Value.X, end.Value.Y)); SliderRotation.ForEachPair((start, end) => sprite.Rotate(OsbEasing.None, start.Time, end.Time, start.Value, end.Value)); + SliderMovement.ForEachPair((start, end) => sprite.Move(OsbEasing.None, start.Time, end.Time, start.Value, end.Value)); }); diff --git a/Draw/Renderers/RenderReceptor.cs b/Draw/Renderers/RenderReceptor.cs index c761eea..a2aaba3 100644 --- a/Draw/Renderers/RenderReceptor.cs +++ b/Draw/Renderers/RenderReceptor.cs @@ -60,12 +60,19 @@ public static void Render(DrawInstance instance, Column column, double duration) relativeTime += playfieldInstance.delta; } + Dictionary notes = instance.playfieldInstance.columnNotes[column.type]; + movement.Simplify(1); movement.ForEachPair((start, end) => { receptor.renderedSprite.Move(OsbEasing.None, start.Time, end.Time, start.Value, end.Value); - receptor.light.Move(OsbEasing.None, start.Time, end.Time, start.Value, end.Value); - receptor.hit.Move(OsbEasing.None, start.Time, end.Time, start.Value, end.Value); + + // Only move hitlighting if there is something to hit + if (notes.Any(ho => Math.Abs(ho.Value.starttime - start.Time) <= 151 + playfieldInstance.delta)) + { + receptor.light.Move(OsbEasing.None, start.Time, end.Time, start.Value, end.Value); + receptor.hit.Move(OsbEasing.None, start.Time, end.Time, start.Value, end.Value); + } }); diff --git a/PlayField/Notes/Note.cs b/PlayField/Notes/Note.cs index a5a189f..5ecf29c 100644 --- a/PlayField/Notes/Note.cs +++ b/PlayField/Notes/Note.cs @@ -262,7 +262,7 @@ public string ApplyHitLightingToNote(double startime, double endtime, double fad localCurrentTime += iterationRate; } - hold.Fade(renderEnd, 0); + hold.Fade(this.endtime, this.endtime + 50, 1, 0); } diff --git a/PlayField/Playfield.cs b/PlayField/Playfield.cs index 4663bf5..7e29e79 100644 --- a/PlayField/Playfield.cs +++ b/PlayField/Playfield.cs @@ -422,24 +422,31 @@ public void Scale(OsbEasing easing, double starttime, double endtime, Vector2 ne if (!keepPosition) { + // Determine scale factors based on the ratio of new to old scales + float scaleRatioX = newScale.X / receptorScale.X; + float scaleRatioY = newScale.Y / receptorScale.Y; - // Calculate the change in distance for receptor based on scale difference. - float receptorDistanceChangeX = (receptorPosition.X - center.X) * (newScale.X / receptorScale.X - 1); - float receptorDistanceChangeY = (center.Y - receptorPosition.Y) * (newScale.Y / receptorScale.Y - 1); + // Calculate the scaled positions by directly applying the scale ratios to the distances from the center + Vector2 receptorNewPosition = new Vector2( + center.X + (receptorPosition.X - center.X) * scaleRatioX, + center.Y + (receptorPosition.Y - center.Y) * scaleRatioY); - // Adjust using the new coordinate system's basis. - Vector2 receptorMovement = new Vector2(receptorDistanceChangeX, 0); + Vector2 originNewPosition = new Vector2( + center.X + (originPosition.X - center.X) * scaleRatioX, + center.Y + (originPosition.Y - center.Y) * scaleRatioY); - // Calculate the change in distance for origin based on scale difference. - float originDistanceChangeX = (originPosition.X - center.X) * (newScale.X / originScale.X - 1); - float originDistanceChangeY = (center.Y - originPosition.Y) * (newScale.Y / originPosition.Y - 1); - - Vector2 originMovement = new Vector2(originDistanceChangeX, 0); + // Calculate movement vectors + Vector2 receptorMovement = receptorNewPosition - receptorPosition; + Vector2 originMovement = originNewPosition - originPosition; + // Apply movements using an appropriate method that reflects position changes receptor.MoveReceptorRelative(easing, starttime, endtime, receptorMovement); origin.MoveOriginRelative(easing, starttime, endtime, originMovement); } + + + } } @@ -576,6 +583,44 @@ public void MoveOriginRelative(OsbEasing easing, double starttime, double endtim } + public void MoveOriginNormalized(OsbEasing easing, double starttime, double endtime, double movementMagnitude, ColumnType column) + { + if (column == ColumnType.all) + { + foreach (Column currentColumn in columns.Values) + { + Vector2 originPos = currentColumn.OriginPositionAt(starttime); + Vector2 receptorPos = currentColumn.ReceptorPositionAt(starttime); + + // Calculate the normalized direction from origin to receptor + Vector2 direction = Vector2.Normalize(receptorPos - originPos); + + // Scale the normalized direction by the movement magnitude + Vector2 movementVector = direction * (float)movementMagnitude; + + // Apply the movement + currentColumn.MoveOriginRelative(easing, starttime, endtime, movementVector); + } + } + else + { + Column currentColumn = columns[column]; + + Vector2 originPos = currentColumn.OriginPositionAt(starttime); + Vector2 receptorPos = currentColumn.ReceptorPositionAt(starttime); + + // Calculate the normalized direction from origin to receptor + Vector2 direction = Vector2.Normalize(receptorPos - originPos); + + // Scale the normalized direction by the movement magnitude + Vector2 movementVector = direction * (float)movementMagnitude; + + // Apply the movement + currentColumn.MoveOriginRelative(easing, starttime, endtime, movementVector); + } + } + + public void RotateReceptorRelative(OsbEasing easing, double starttime, double endtime, double rotation, ColumnType column = ColumnType.all) { if (column == ColumnType.all) @@ -887,21 +932,16 @@ public Vector2 calculatePlayFieldCenter(double currentTime) { Vector2 center; - Vector2 topLeft = new Vector2(0, 0); - Vector2 bottomRight = new Vector2(0, 0); + // Initialize to extreme values to correctly capture the extents + Vector2 topLeft = new Vector2(float.MaxValue, float.MaxValue); + Vector2 bottomRight = new Vector2(float.MinValue, float.MinValue); foreach (Column column in columns.Values) { - Vector2 receptor = column.ReceptorPositionAt(currentTime); Vector2 origin = column.OriginPositionAt(currentTime); - if (topLeft == new Vector2(0, 0)) - { - topLeft = receptor; - bottomRight = origin; - } - + // Adjust topLeft to the minimum extents if (receptor.X < topLeft.X) { topLeft.X = receptor.X; @@ -913,13 +953,14 @@ public Vector2 calculatePlayFieldCenter(double currentTime) if (receptor.Y < topLeft.Y) { - topLeft.Y = receptor.X; + topLeft.Y = receptor.Y; // Corrected from receptor.X to receptor.Y } if (origin.Y < topLeft.Y) { topLeft.Y = origin.Y; } + // Adjust bottomRight to the maximum extents if (receptor.X > bottomRight.X) { bottomRight.X = receptor.X; @@ -931,19 +972,20 @@ public Vector2 calculatePlayFieldCenter(double currentTime) if (receptor.Y > bottomRight.Y) { - bottomRight.Y = receptor.X; + bottomRight.Y = receptor.Y; // Corrected from receptor.X to receptor.Y } if (origin.Y > bottomRight.Y) { bottomRight.Y = origin.Y; } - } + // Calculate the center from the adjusted topLeft and bottomRight center.X = (topLeft.X + bottomRight.X) / 2; center.Y = (topLeft.Y + bottomRight.Y) / 2; return center; } + } } \ No newline at end of file diff --git a/utility/Hitsounds.cs b/utility/Hitsounds.cs index c0ad434..b899f35 100644 --- a/utility/Hitsounds.cs +++ b/utility/Hitsounds.cs @@ -12,6 +12,11 @@ namespace StorybrewScripts public static class HitSound { + public static double worstTiming(Playfield field) + { + return 151 - (3 * field.od); + } + public static void AddHitSound(Playfield field, Column column, List keysInRange, Dictionary notes) { @@ -42,7 +47,7 @@ public static void AddHitSound(Playfield field, Column column, List keys break; } - var fadeOut = 75; + var fadeOut = 151; foreach (var key in keysInRange) { @@ -50,60 +55,51 @@ public static void AddHitSound(Playfield field, Column column, List keys // Trigger for 300+ (±16ms) light.StartTriggerGroup(trigger, note.endtime - marv, note.endtime + marv); - light.Fade(0, 1); - light.Fade(fadeOut, 0); + light.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); light.Color(0, new Color4(104, 186, 207, 0)); light.EndGroup(); // Trigger for 300 (±46ms, excludes 300+ range) light.StartTriggerGroup(trigger, note.endtime - great, note.endtime - marv + 1); - light.Fade(0, 1); - light.Fade(fadeOut, 0); + light.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); light.Color(0, new Color4(223, 181, 96, 0)); light.EndGroup(); light.StartTriggerGroup(trigger, note.endtime + marv + 1, note.endtime + great); - light.Fade(0, 1); - light.Fade(fadeOut, 0); + light.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); light.Color(0, new Color4(223, 181, 96, 0)); light.EndGroup(); // Trigger for 200 (±79ms, excludes 300 range) light.StartTriggerGroup(trigger, note.endtime - good, note.endtime - great + 1); - light.Fade(0, 1); - light.Fade(fadeOut, 0); + light.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); light.Color(0, new Color4(95, 204, 95, 0)); light.EndGroup(); light.StartTriggerGroup(trigger, note.endtime + great + 1, note.endtime + good); - light.Fade(0, 1); - light.Fade(fadeOut, 0); + light.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); light.Color(0, new Color4(95, 204, 95, 0)); light.EndGroup(); // Trigger for 100 (±109ms, excludes 200 range) light.StartTriggerGroup(trigger, note.endtime - ok, note.endtime - good + 1); - light.Fade(0, 1); - light.Fade(fadeOut, 0); + light.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); light.Color(0, new Color4(206, 128, 224, 0)); light.EndGroup(); light.StartTriggerGroup(trigger, note.endtime + good + 1, note.endtime + ok); - light.Fade(0, 1); - light.Fade(fadeOut, 0); + light.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); light.Color(0, new Color4(206, 128, 224, 0)); light.EndGroup(); // Trigger for 50 (±133ms, excludes 100 range) light.StartTriggerGroup(trigger, note.endtime - bad, note.endtime - ok + 1); - light.Fade(0, 1); - light.Fade(fadeOut, 0); + light.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); light.Color(0, new Color4(198, 86, 37, 0)); light.EndGroup(); light.StartTriggerGroup(trigger, note.endtime + ok + 1, note.endtime + bad); - light.Fade(0, 1); - light.Fade(fadeOut, 0); + light.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); light.Color(0, new Color4(198, 86, 37, 0)); light.EndGroup(); @@ -112,52 +108,43 @@ public static void AddHitSound(Playfield field, Column column, List keys // Trigger for 300+ (±16ms) hit.StartTriggerGroup(trigger, note.endtime - marv, note.endtime + marv); - hit.Fade(0, 1); - hit.Fade(fadeOut, 0); + hit.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); hit.EndGroup(); // Trigger for 300 (±46ms, excludes 300+ range) hit.StartTriggerGroup(trigger, note.endtime - great, note.endtime - marv + 1); - hit.Fade(0, 1); - hit.Fade(fadeOut, 0); + hit.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); hit.EndGroup(); hit.StartTriggerGroup(trigger, note.endtime + marv + 1, note.endtime + great); - hit.Fade(0, 1); - hit.Fade(fadeOut, 0); + hit.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); hit.EndGroup(); // Trigger for 200 (±79ms, excludes 300 range) hit.StartTriggerGroup(trigger, note.endtime - good, note.endtime - great + 1); - hit.Fade(0, 1); - hit.Fade(fadeOut, 0); + hit.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); hit.EndGroup(); hit.StartTriggerGroup(trigger, note.endtime + great + 1, note.endtime + good); - hit.Fade(0, 1); - hit.Fade(fadeOut, 0); + hit.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); hit.EndGroup(); // Trigger for 100 (±109ms, excludes 200 range) hit.StartTriggerGroup(trigger, note.endtime - ok, note.endtime - good + 1); - hit.Fade(0, 1); - hit.Fade(fadeOut, 0); + hit.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); hit.EndGroup(); hit.StartTriggerGroup(trigger, note.endtime + good + 1, note.endtime + ok); - hit.Fade(0, 1); - hit.Fade(fadeOut, 0); + hit.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); hit.EndGroup(); // Trigger for 50 (±133ms, excludes 100 range) hit.StartTriggerGroup(trigger, note.endtime - bad, note.endtime - ok + 1); - hit.Fade(0, 1); - hit.Fade(fadeOut, 0); + hit.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); hit.EndGroup(); hit.StartTriggerGroup(trigger, note.endtime + ok + 1, note.endtime + bad); - hit.Fade(0, 1); - hit.Fade(fadeOut, 0); + hit.Fade(OsbEasing.InExpo, 0, fadeOut, 1, 0); hit.EndGroup(); }