Merge branch 'master' into fix-background-loading

This commit is contained in:
Dean Herbert 2019-03-19 16:00:09 +09:00 committed by GitHub
commit 3327e2841a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 45 deletions

View File

@ -15,77 +15,100 @@ namespace osu.Game.Rulesets.Catch.Mods
public override double ScoreMultiplier => 1.12; public override double ScoreMultiplier => 1.12;
public override bool Ranked => true; public override bool Ranked => true;
private float lastStartX; private float? lastPosition;
private int lastStartTime; private double lastStartTime;
public void ApplyToHitObject(HitObject hitObject) public void ApplyToHitObject(HitObject hitObject)
{ {
if (!(hitObject is Fruit))
return;
var catchObject = (CatchHitObject)hitObject; var catchObject = (CatchHitObject)hitObject;
float position = catchObject.X; float position = catchObject.X;
int startTime = (int)hitObject.StartTime; double startTime = hitObject.StartTime;
if (lastStartX == 0) if (lastPosition == null)
{ {
lastStartX = position; lastPosition = position;
lastStartTime = startTime; lastStartTime = startTime;
return; return;
} }
float diff = lastStartX - position; float positionDiff = position - lastPosition.Value;
int timeDiff = startTime - lastStartTime; double timeDiff = startTime - lastStartTime;
if (timeDiff > 1000) if (timeDiff > 1000)
{ {
lastStartX = position; lastPosition = position;
lastStartTime = startTime; lastStartTime = startTime;
return; return;
} }
if (diff == 0) if (positionDiff == 0)
{ {
bool right = RNG.NextBool(); applyRandomOffset(ref position, timeDiff / 4d);
float rand = Math.Min(20, (float)RNG.NextDouble(0, timeDiff / 4d)) / CatchPlayfield.BASE_WIDTH;
if (right)
{
if (position + rand <= 1)
position += rand;
else
position -= rand;
}
else
{
if (position - rand >= 0)
position -= rand;
else
position += rand;
}
catchObject.X = position; catchObject.X = position;
return; return;
} }
if (Math.Abs(diff) < timeDiff / 3d) if (Math.Abs(positionDiff * CatchPlayfield.BASE_WIDTH) < timeDiff / 3d)
{ applyOffset(ref position, positionDiff);
if (diff > 0)
{
if (position - diff > 0)
position -= diff;
}
else
{
if (position - diff < 1)
position -= diff;
}
}
catchObject.X = position; catchObject.X = position;
lastStartX = position; lastPosition = position;
lastStartTime = startTime; lastStartTime = startTime;
} }
/// <summary>
/// Applies a random offset in a random direction to a position, ensuring that the final position remains within the boundary of the playfield.
/// </summary>
/// <param name="position">The position which the offset should be applied to.</param>
/// <param name="maxOffset">The maximum offset, cannot exceed 20px.</param>
private void applyRandomOffset(ref float position, double maxOffset)
{
bool right = RNG.NextBool();
float rand = Math.Min(20, (float)RNG.NextDouble(0, maxOffset)) / CatchPlayfield.BASE_WIDTH;
if (right)
{
// Clamp to the right bound
if (position + rand <= 1)
position += rand;
else
position -= rand;
}
else
{
// Clamp to the left bound
if (position - rand >= 0)
position -= rand;
else
position += rand;
}
}
/// <summary>
/// Applies an offset to a position, ensuring that the final position remains within the boundary of the playfield.
/// </summary>
/// <param name="position">The position which the offset should be applied to.</param>
/// <param name="amount">The amount to offset by.</param>
private void applyOffset(ref float position, float amount)
{
if (amount > 0)
{
// Clamp to the right bound
if (position + amount < 1)
position += amount;
}
else
{
// Clamp to the left bound
if (position + amount > 0)
position += amount;
}
}
} }
} }

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Screens.Play;
namespace osu.Game.Storyboards.Drawables namespace osu.Game.Storyboards.Drawables
{ {
@ -55,9 +56,12 @@ namespace osu.Game.Storyboards.Drawables
}); });
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader(true)]
private void load(FileStore fileStore) private void load(FileStore fileStore, GameplayClock clock)
{ {
if (clock != null)
Clock = clock;
dependencies.Cache(new TextureStore(new TextureLoaderStore(fileStore.Store), false, scaleAdjust: 1)); dependencies.Cache(new TextureStore(new TextureLoaderStore(fileStore.Store), false, scaleAdjust: 1));
foreach (var layer in Storyboard.Layers) foreach (var layer in Storyboard.Layers)