mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 20:12:57 +08:00
Use DrawablePool for DrawableJudgements
This commit is contained in:
parent
7e48df3a0d
commit
ffec4298a7
@ -24,10 +24,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrawableOsuJudgement()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager config)
|
private void load(OsuConfigManager config)
|
||||||
{
|
{
|
||||||
if (config.Get<bool>(OsuSetting.HitLighting) && Result.Type != HitResult.Miss)
|
if (config.Get<bool>(OsuSetting.HitLighting))
|
||||||
{
|
{
|
||||||
AddInternal(lighting = new SkinnableSprite("lighting")
|
AddInternal(lighting = new SkinnableSprite("lighting")
|
||||||
{
|
{
|
||||||
@ -36,16 +40,23 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
Blending = BlendingParameters.Additive,
|
Blending = BlendingParameters.Additive,
|
||||||
Depth = float.MaxValue
|
Depth = float.MaxValue
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (JudgedObject != null)
|
protected override void PrepareForUse()
|
||||||
{
|
{
|
||||||
lightingColour = JudgedObject.AccentColour.GetBoundCopy();
|
base.PrepareForUse();
|
||||||
lightingColour.BindValueChanged(colour => lighting.Colour = colour.NewValue, true);
|
|
||||||
}
|
lightingColour?.UnbindAll();
|
||||||
else
|
|
||||||
{
|
if (JudgedObject != null)
|
||||||
lighting.Colour = Color4.White;
|
{
|
||||||
}
|
lightingColour = JudgedObject.AccentColour.GetBoundCopy();
|
||||||
|
lightingColour.BindValueChanged(colour => lighting.Colour = Result.Type == HitResult.Miss ? Color4.Transparent : colour.NewValue, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lighting.Colour = Color4.White;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,13 +66,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
{
|
{
|
||||||
if (lighting != null)
|
if (lighting != null)
|
||||||
{
|
{
|
||||||
JudgementBody.Delay(FadeInDuration).FadeOut(400);
|
JudgementBody.FadeIn().Delay(FadeInDuration).FadeOut(400);
|
||||||
|
|
||||||
lighting.ScaleTo(0.8f).ScaleTo(1.2f, 600, Easing.Out);
|
lighting.ScaleTo(0.8f).ScaleTo(1.2f, 600, Easing.Out);
|
||||||
lighting.FadeIn(200).Then().Delay(200).FadeOut(1000);
|
lighting.FadeIn(200).Then().Delay(200).FadeOut(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
JudgementText?.TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint);
|
JudgementText?.TransformSpacingTo(Vector2.Zero).Then().TransformSpacingTo(new Vector2(14, 0), 1800, Easing.OutQuint);
|
||||||
base.ApplyHitAnimations();
|
base.ApplyHitAnimations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
using osuTK;
|
using osuTK;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Pooling;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||||
@ -26,10 +28,13 @@ namespace osu.Game.Rulesets.Osu.UI
|
|||||||
|
|
||||||
protected override GameplayCursorContainer CreateCursor() => new OsuCursorContainer();
|
protected override GameplayCursorContainer CreateCursor() => new OsuCursorContainer();
|
||||||
|
|
||||||
|
private readonly DrawablePool<DrawableOsuJudgement> judgementPool;
|
||||||
|
|
||||||
public OsuPlayfield()
|
public OsuPlayfield()
|
||||||
{
|
{
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
|
judgementPool = new DrawablePool<DrawableOsuJudgement>(20),
|
||||||
followPoints = new FollowPointRenderer
|
followPoints = new FollowPointRenderer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -91,12 +96,17 @@ namespace osu.Game.Rulesets.Osu.UI
|
|||||||
if (!judgedObject.DisplayResult || !DisplayJudgements.Value)
|
if (!judgedObject.DisplayResult || !DisplayJudgements.Value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DrawableOsuJudgement explosion = new DrawableOsuJudgement(result, judgedObject)
|
DrawableOsuJudgement explosion = judgementPool.Get(doj =>
|
||||||
{
|
{
|
||||||
Origin = Anchor.Centre,
|
if (doj.Result != null)
|
||||||
Position = ((OsuHitObject)judgedObject.HitObject).StackedEndPosition,
|
Logger.Log("reused!");
|
||||||
Scale = new Vector2(((OsuHitObject)judgedObject.HitObject).Scale)
|
doj.Result = result;
|
||||||
};
|
doj.JudgedObject = judgedObject;
|
||||||
|
|
||||||
|
doj.Origin = Anchor.Centre;
|
||||||
|
doj.Position = ((OsuHitObject)judgedObject.HitObject).StackedEndPosition;
|
||||||
|
doj.Scale = new Vector2(((OsuHitObject)judgedObject.HitObject).Scale);
|
||||||
|
});
|
||||||
|
|
||||||
judgementLayer.Add(explosion);
|
judgementLayer.Add(explosion);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Caching;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Pooling;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
@ -18,16 +21,31 @@ namespace osu.Game.Rulesets.Judgements
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A drawable object which visualises the hit result of a <see cref="Judgements.Judgement"/>.
|
/// A drawable object which visualises the hit result of a <see cref="Judgements.Judgement"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DrawableJudgement : CompositeDrawable
|
public class DrawableJudgement : PoolableDrawable
|
||||||
{
|
{
|
||||||
private const float judgement_size = 128;
|
private const float judgement_size = 128;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; }
|
private OsuColour colours { get; set; }
|
||||||
|
|
||||||
protected readonly JudgementResult Result;
|
private readonly Cached drawableCache = new Cached();
|
||||||
|
|
||||||
public readonly DrawableHitObject JudgedObject;
|
private JudgementResult result;
|
||||||
|
|
||||||
|
public JudgementResult Result
|
||||||
|
{
|
||||||
|
get => result;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (result?.Type == value.Type)
|
||||||
|
return;
|
||||||
|
|
||||||
|
result = value;
|
||||||
|
drawableCache.Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawableHitObject JudgedObject;
|
||||||
|
|
||||||
protected Container JudgementBody;
|
protected Container JudgementBody;
|
||||||
protected SpriteText JudgementText;
|
protected SpriteText JudgementText;
|
||||||
@ -48,29 +66,15 @@ namespace osu.Game.Rulesets.Judgements
|
|||||||
/// <param name="result">The judgement to visualise.</param>
|
/// <param name="result">The judgement to visualise.</param>
|
||||||
/// <param name="judgedObject">The object which was judged.</param>
|
/// <param name="judgedObject">The object which was judged.</param>
|
||||||
public DrawableJudgement(JudgementResult result, DrawableHitObject judgedObject)
|
public DrawableJudgement(JudgementResult result, DrawableHitObject judgedObject)
|
||||||
|
: this()
|
||||||
{
|
{
|
||||||
Result = result;
|
Result = result;
|
||||||
JudgedObject = judgedObject;
|
JudgedObject = judgedObject;
|
||||||
|
|
||||||
Size = new Vector2(judgement_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
public DrawableJudgement()
|
||||||
private void load()
|
|
||||||
{
|
{
|
||||||
InternalChild = JudgementBody = new Container
|
Size = new Vector2(judgement_size);
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Child = new SkinnableDrawable(new GameplaySkinComponent<HitResult>(Result.Type), _ => JudgementText = new OsuSpriteText
|
|
||||||
{
|
|
||||||
Text = Result.Type.GetDescription().ToUpperInvariant(),
|
|
||||||
Font = OsuFont.Numeric.With(size: 20),
|
|
||||||
Colour = colours.ForHitResult(Result.Type),
|
|
||||||
Scale = new Vector2(0.85f, 1),
|
|
||||||
}, confineMode: ConfineMode.NoScaling)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void ApplyHitAnimations()
|
protected virtual void ApplyHitAnimations()
|
||||||
@ -81,11 +85,25 @@ namespace osu.Game.Rulesets.Judgements
|
|||||||
this.Delay(FadeOutDelay).FadeOut(400);
|
this.Delay(FadeOutDelay).FadeOut(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
prepareDrawables();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void PrepareForUse()
|
||||||
|
{
|
||||||
|
base.PrepareForUse();
|
||||||
|
|
||||||
|
Debug.Assert(Result != null);
|
||||||
|
|
||||||
|
if (!drawableCache.IsValid)
|
||||||
|
prepareDrawables();
|
||||||
|
|
||||||
this.FadeInFromZero(FadeInDuration, Easing.OutQuint);
|
this.FadeInFromZero(FadeInDuration, Easing.OutQuint);
|
||||||
|
JudgementBody.ScaleTo(1);
|
||||||
|
JudgementBody.RotateTo(0);
|
||||||
|
JudgementBody.MoveTo(Vector2.Zero);
|
||||||
|
|
||||||
switch (Result.Type)
|
switch (Result.Type)
|
||||||
{
|
{
|
||||||
@ -109,5 +127,26 @@ namespace osu.Game.Rulesets.Judgements
|
|||||||
|
|
||||||
Expire(true);
|
Expire(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void prepareDrawables()
|
||||||
|
{
|
||||||
|
var type = Result?.Type ?? HitResult.Perfect; //TODO: better default type from ruleset
|
||||||
|
|
||||||
|
InternalChild = JudgementBody = new Container
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Child = new SkinnableDrawable(new GameplaySkinComponent<HitResult>(type), _ => JudgementText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Text = type.GetDescription().ToUpperInvariant(),
|
||||||
|
Font = OsuFont.Numeric.With(size: 20),
|
||||||
|
Colour = colours.ForHitResult(type),
|
||||||
|
Scale = new Vector2(0.85f, 1),
|
||||||
|
}, confineMode: ConfineMode.NoScaling)
|
||||||
|
};
|
||||||
|
|
||||||
|
drawableCache.Validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user