mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 14:12:55 +08:00
Make RandomSeed a property, not a bindable
This commit is contained in:
parent
5936a8ffb4
commit
fdcfa81e46
@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Rulesets.Catch.Objects;
|
||||
using osu.Game.Rulesets.Catch.Objects.Drawables;
|
||||
using osu.Game.Tests.Visual;
|
||||
@ -12,7 +11,6 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
{
|
||||
public class TestSceneFruitRandomness : OsuTestScene
|
||||
{
|
||||
private readonly Bindable<int> randomSeed = new Bindable<int>();
|
||||
private readonly TestDrawableFruit drawableFruit;
|
||||
private readonly TestDrawableBanana drawableBanana;
|
||||
|
||||
@ -21,27 +19,30 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
drawableFruit = new TestDrawableFruit(new Fruit());
|
||||
drawableBanana = new TestDrawableBanana(new Banana());
|
||||
|
||||
drawableFruit.RandomSeed.BindTo(randomSeed);
|
||||
drawableBanana.RandomSeed.BindTo(randomSeed);
|
||||
|
||||
Add(new TestDrawableCatchHitObjectSpecimen(drawableFruit) { X = -200 });
|
||||
Add(new TestDrawableCatchHitObjectSpecimen(drawableBanana));
|
||||
|
||||
AddSliderStep("random seed", 0, 100, 0, x => randomSeed.Value = x);
|
||||
AddSliderStep("start time", 500, 600, 0, x =>
|
||||
{
|
||||
drawableFruit.HitObject.StartTime = drawableBanana.HitObject.StartTime = x;
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFruitRandomness()
|
||||
{
|
||||
// Use values such that the banana colour changes (2/3 of the integers are okay)
|
||||
const int initial_start_time = 500;
|
||||
const int another_start_time = 501;
|
||||
|
||||
float fruitRotation = 0;
|
||||
float bananaRotation = 0;
|
||||
float bananaScale = 0;
|
||||
Color4 bananaColour = new Color4();
|
||||
|
||||
AddStep("set random seed to 0", () =>
|
||||
AddStep("Initialize start time", () =>
|
||||
{
|
||||
drawableFruit.HitObject.StartTime = 500;
|
||||
randomSeed.Value = 0;
|
||||
drawableFruit.HitObject.StartTime = drawableBanana.HitObject.StartTime = initial_start_time;
|
||||
|
||||
fruitRotation = drawableFruit.InnerRotation;
|
||||
bananaRotation = drawableBanana.InnerRotation;
|
||||
@ -49,10 +50,9 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
bananaColour = drawableBanana.AccentColour.Value;
|
||||
});
|
||||
|
||||
AddStep("change random seed", () =>
|
||||
AddStep("change start time", () =>
|
||||
{
|
||||
// Use a seed value such that the banana colour is different (2/3 of the seed values are okay).
|
||||
randomSeed.Value = 10;
|
||||
drawableFruit.HitObject.StartTime = drawableBanana.HitObject.StartTime = another_start_time;
|
||||
});
|
||||
|
||||
AddAssert("fruit rotation is changed", () => drawableFruit.InnerRotation != fruitRotation);
|
||||
@ -60,9 +60,9 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
AddAssert("banana scale is changed", () => drawableBanana.InnerScale != bananaScale);
|
||||
AddAssert("banana colour is changed", () => drawableBanana.AccentColour.Value != bananaColour);
|
||||
|
||||
AddStep("reset random seed", () =>
|
||||
AddStep("reset start time", () =>
|
||||
{
|
||||
randomSeed.Value = 0;
|
||||
drawableFruit.HitObject.StartTime = drawableBanana.HitObject.StartTime = initial_start_time;
|
||||
});
|
||||
|
||||
AddAssert("rotation and scale restored", () =>
|
||||
@ -70,13 +70,6 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
drawableBanana.InnerRotation == bananaRotation &&
|
||||
drawableBanana.InnerScale == bananaScale &&
|
||||
drawableBanana.AccentColour.Value == bananaColour);
|
||||
|
||||
AddStep("change start time", () =>
|
||||
{
|
||||
drawableFruit.HitObject.StartTime = 1000;
|
||||
});
|
||||
|
||||
AddAssert("random seed is changed", () => randomSeed.Value == 1000);
|
||||
}
|
||||
|
||||
private class TestDrawableFruit : DrawableFruit
|
||||
|
@ -33,7 +33,7 @@ namespace osu.Game.Rulesets.Catch.Objects
|
||||
|
||||
private Color4 getBananaColour()
|
||||
{
|
||||
switch (StatelessRNG.NextInt(3, RandomSeed.Value))
|
||||
switch (StatelessRNG.NextInt(3, RandomSeed))
|
||||
{
|
||||
default:
|
||||
return new Color4(255, 240, 0, 255);
|
||||
|
@ -99,9 +99,9 @@ namespace osu.Game.Rulesets.Catch.Objects
|
||||
|
||||
/// <summary>
|
||||
/// The seed value used for visual randomness such as fruit rotation.
|
||||
/// By default, <see cref="HitObject.StartTime"/> truncated to an integer is used.
|
||||
/// The value is <see cref="HitObject.StartTime"/> truncated to an integer.
|
||||
/// </summary>
|
||||
public Bindable<int> RandomSeed = new Bindable<int>();
|
||||
public int RandomSeed => (int)StartTime;
|
||||
|
||||
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
|
||||
{
|
||||
@ -117,10 +117,6 @@ namespace osu.Game.Rulesets.Catch.Objects
|
||||
protected CatchHitObject()
|
||||
{
|
||||
XBindable.BindValueChanged(x => originalX = x.NewValue - xOffset);
|
||||
StartTimeBindable.BindValueChanged(change =>
|
||||
{
|
||||
RandomSeed.Value = (int)change.NewValue;
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
RandomSeed.BindValueChanged(_ =>
|
||||
{
|
||||
UpdateComboColour();
|
||||
UpdateInitialTransforms();
|
||||
});
|
||||
// start time affects the random seed which is used to determine the banana colour
|
||||
StartTimeBindable.BindValueChanged(_ => UpdateComboColour());
|
||||
}
|
||||
|
||||
protected override void UpdateInitialTransforms()
|
||||
|
@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
||||
|
||||
protected override float SamplePlaybackPosition => HitObject.X / CatchPlayfield.WIDTH;
|
||||
|
||||
public Bindable<int> RandomSeed = new Bindable<int>();
|
||||
public int RandomSeed => HitObject?.RandomSeed ?? 0;
|
||||
|
||||
protected DrawableCatchHitObject([CanBeNull] CatchHitObject hitObject)
|
||||
: base(hitObject)
|
||||
@ -32,14 +32,13 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
||||
/// <summary>
|
||||
/// Get a random number in range [0,1) based on seed <see cref="RandomSeed"/>.
|
||||
/// </summary>
|
||||
public float RandomSingle(int series) => StatelessRNG.NextSingle(RandomSeed.Value, series);
|
||||
public float RandomSingle(int series) => StatelessRNG.NextSingle(RandomSeed, series);
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
base.OnApply();
|
||||
|
||||
XBindable.BindTo(HitObject.XBindable);
|
||||
RandomSeed.BindTo(HitObject.RandomSeed);
|
||||
}
|
||||
|
||||
protected override void OnFree()
|
||||
@ -47,7 +46,6 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
||||
base.OnFree();
|
||||
|
||||
XBindable.UnbindFrom(HitObject.XBindable);
|
||||
RandomSeed.UnbindFrom(HitObject.RandomSeed);
|
||||
}
|
||||
|
||||
public Func<CatchHitObject, bool> CheckPosition;
|
||||
|
@ -36,11 +36,13 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
|
||||
|
||||
VisualRepresentation.BindValueChanged(_ => updatePiece());
|
||||
HyperDash.BindValueChanged(_ => updatePiece(), true);
|
||||
}
|
||||
|
||||
RandomSeed.BindValueChanged(_ =>
|
||||
{
|
||||
ScaleContainer.Rotation = (RandomSingle(1) - 0.5f) * 40;
|
||||
}, true);
|
||||
protected override void UpdateInitialTransforms()
|
||||
{
|
||||
base.UpdateInitialTransforms();
|
||||
|
||||
ScaleContainer.Rotation = (RandomSingle(1) - 0.5f) * 40;
|
||||
}
|
||||
|
||||
private void updatePiece()
|
||||
|
Loading…
Reference in New Issue
Block a user