1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 19:32:55 +08:00

Add a preprocess method to BeatmapProcessor

This commit is contained in:
smoogipoo 2018-06-29 12:45:48 +09:00
parent 71b759841b
commit 756cabd5d0
4 changed files with 73 additions and 49 deletions

View File

@ -15,19 +15,26 @@ namespace osu.Game.Rulesets.Catch.Beatmaps
{ {
public class CatchBeatmapProcessor : BeatmapProcessor public class CatchBeatmapProcessor : BeatmapProcessor
{ {
public const int RNG_SEED = 1337;
public CatchBeatmapProcessor(IBeatmap beatmap) public CatchBeatmapProcessor(IBeatmap beatmap)
: base(beatmap) : base(beatmap)
{ {
} }
public override void PostProcess() public override void PreProcess()
{ {
applyPositionOffsets(); base.PreProcess();
initialiseHyperDash((List<CatchHitObject>)Beatmap.HitObjects); initialiseHyperDash((List<CatchHitObject>)Beatmap.HitObjects);
}
public override void PostProcess()
{
base.PostProcess(); base.PostProcess();
applyPositionOffsets();
int index = 0; int index = 0;
foreach (var obj in Beatmap.HitObjects.OfType<CatchHitObject>()) foreach (var obj in Beatmap.HitObjects.OfType<CatchHitObject>())
{ {
@ -37,41 +44,6 @@ namespace osu.Game.Rulesets.Catch.Beatmaps
} }
} }
public const int RNG_SEED = 1337;
private void applyPositionOffsets()
{
var rng = new FastRandom(RNG_SEED);
// todo: HardRock displacement should be applied here
foreach (var obj in Beatmap.HitObjects)
{
switch (obj)
{
case BananaShower bananaShower:
foreach (var nested in bananaShower.NestedHitObjects)
{
((BananaShower.Banana)nested).X = (float)rng.NextDouble();
rng.Next(); // osu!stable retrieved a random banana type
rng.Next(); // osu!stable retrieved a random banana rotation
rng.Next(); // osu!stable retrieved a random banana colour
}
break;
case JuiceStream juiceStream:
foreach (var nested in juiceStream.NestedHitObjects)
{
var hitObject = (CatchHitObject)nested;
if (hitObject is TinyDroplet)
hitObject.X += rng.Next(-20, 20) / CatchPlayfield.BASE_WIDTH;
else if (hitObject is Droplet)
rng.Next(); // osu!stable retrieved a random droplet rotation
hitObject.X = MathHelper.Clamp(hitObject.X, 0, 1);
}
break;
}
}
}
private void initialiseHyperDash(List<CatchHitObject> objects) private void initialiseHyperDash(List<CatchHitObject> objects)
{ {
// todo: add difficulty adjust. // todo: add difficulty adjust.
@ -115,5 +87,38 @@ namespace osu.Game.Rulesets.Catch.Beatmaps
lastDirection = thisDirection; lastDirection = thisDirection;
} }
} }
private void applyPositionOffsets()
{
var rng = new FastRandom(RNG_SEED);
// todo: HardRock displacement should be applied here
foreach (var obj in Beatmap.HitObjects)
{
switch (obj)
{
case BananaShower bananaShower:
foreach (var nested in bananaShower.NestedHitObjects)
{
((BananaShower.Banana)nested).X = (float)rng.NextDouble();
rng.Next(); // osu!stable retrieved a random banana type
rng.Next(); // osu!stable retrieved a random banana rotation
rng.Next(); // osu!stable retrieved a random banana colour
}
break;
case JuiceStream juiceStream:
foreach (var nested in juiceStream.NestedHitObjects)
{
var hitObject = (CatchHitObject)nested;
if (hitObject is TinyDroplet)
hitObject.X += rng.Next(-20, 20) / CatchPlayfield.BASE_WIDTH;
else if (hitObject is Droplet)
rng.Next(); // osu!stable retrieved a random droplet rotation
hitObject.X = MathHelper.Clamp(hitObject.X, 0, 1);
}
break;
}
}
}
} }
} }

View File

@ -15,10 +15,10 @@ namespace osu.Game.Rulesets.Osu.Beatmaps
{ {
} }
public override void PostProcess() public override void PreProcess()
{ {
base.PreProcess();
applyStacking((Beatmap<OsuHitObject>)Beatmap); applyStacking((Beatmap<OsuHitObject>)Beatmap);
base.PostProcess();
} }
private void applyStacking(Beatmap<OsuHitObject> beatmap) private void applyStacking(Beatmap<OsuHitObject> beatmap)

View File

@ -11,11 +11,27 @@ namespace osu.Game.Beatmaps
IBeatmap Beatmap { get; } IBeatmap Beatmap { get; }
/// <summary> /// <summary>
/// Post-processes <see cref="Beatmap"/> to add mode-specific components that aren't added during conversion. /// Processes the converted <see cref="Beatmap"/> prior to <see cref="HitObject.ApplyDefaults"/> being invoked.
/// <para> /// <para>
/// An example of such a usage is for combo colours. /// Nested <see cref="HitObject"/>s generated during <see cref="HitObject.ApplyDefaults"/> will not be present by this point,
/// and no mods will have been applied to the <see cref="HitObject"/>s.
/// </para> /// </para>
/// </summary> /// </summary>
/// <remarks>
/// This can only be used to add alterations to <see cref="HitObject"/>s generated directly through the conversion process.
/// </remarks>
void PreProcess();
/// <summary>
/// Processes the converted <see cref="Beatmap"/> after <see cref="HitObject.ApplyDefaults"/> has been invoked.
/// <para>
/// Nested <see cref="HitObject"/>s generated during <see cref="HitObject.ApplyDefaults"/> will be present by this point,
/// and mods will have been applied to all <see cref="HitObject"/>s.
/// </para>
/// </summary>
/// <remarks>
/// This should be used to add alterations to <see cref="HitObject"/>s while they are in their most playable state.
/// </remarks>
void PostProcess(); void PostProcess();
} }
@ -32,13 +48,7 @@ namespace osu.Game.Beatmaps
Beatmap = beatmap; Beatmap = beatmap;
} }
/// <summary> public virtual void PreProcess()
/// Post-processes a Beatmap to add mode-specific components that aren't added during conversion.
/// <para>
/// An example of such a usage is for combo colours.
/// </para>
/// </summary>
public virtual void PostProcess()
{ {
IHasComboInformation lastObj = null; IHasComboInformation lastObj = null;
@ -62,5 +72,9 @@ namespace osu.Game.Beatmaps
lastObj = obj; lastObj = obj;
} }
} }
public virtual void PostProcess()
{
}
} }
} }

View File

@ -116,6 +116,11 @@ namespace osu.Game.Beatmaps
mod.ApplyToDifficulty(converted.BeatmapInfo.BaseDifficulty); mod.ApplyToDifficulty(converted.BeatmapInfo.BaseDifficulty);
} }
IBeatmapProcessor processor = rulesetInstance.CreateBeatmapProcessor(converted);
// Pre-process
processor?.PreProcess();
// Compute default values for hitobjects, including creating nested hitobjects in-case they're needed // Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
foreach (var obj in converted.HitObjects) foreach (var obj in converted.HitObjects)
obj.ApplyDefaults(converted.ControlPointInfo, converted.BeatmapInfo.BaseDifficulty); obj.ApplyDefaults(converted.ControlPointInfo, converted.BeatmapInfo.BaseDifficulty);
@ -125,7 +130,7 @@ namespace osu.Game.Beatmaps
mod.ApplyToHitObject(obj); mod.ApplyToHitObject(obj);
// Post-process // Post-process
rulesetInstance.CreateBeatmapProcessor(converted)?.PostProcess(); processor?.PostProcess();
return converted; return converted;
} }