Skip to content

Commit

Permalink
2.21
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Tunnelbliick committed May 14, 2024
1 parent 6300e3d commit eafe6b5
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 65 deletions.
11 changes: 8 additions & 3 deletions Draw/Renderers/ByEquation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace StorybrewScripts
public class EquationParameters
{
public Vector2 position;
public Vector2 lastPosition;
public double time;
public float progress;
public OsbSprite sprite;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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,
Expand All @@ -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));
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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));
});
Expand Down
11 changes: 9 additions & 2 deletions Draw/Renderers/RenderReceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,19 @@ public static void Render(DrawInstance instance, Column column, double duration)
relativeTime += playfieldInstance.delta;
}

Dictionary<double, Note> 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);
}
});


Expand Down
2 changes: 1 addition & 1 deletion PlayField/Notes/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down
86 changes: 64 additions & 22 deletions PlayField/Playfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}




}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

}
}
61 changes: 24 additions & 37 deletions utility/Hitsounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> keysInRange, Dictionary<double, Note> notes)
{

Expand Down Expand Up @@ -42,68 +47,59 @@ public static void AddHitSound(Playfield field, Column column, List<double> keys
break;
}

var fadeOut = 75;
var fadeOut = 151;

foreach (var key in keysInRange)
{
Note note = notes[key];

// 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();

Expand All @@ -112,52 +108,43 @@ public static void AddHitSound(Playfield field, Column column, List<double> 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();
}

Expand Down

0 comments on commit eafe6b5

Please sign in to comment.