Skip to content

Commit

Permalink
Merge pull request #339 from andy840119/pooling-playfield
Browse files Browse the repository at this point in the history
Enable pooling for karaoke DHOs
  • Loading branch information
andy840119 authored Dec 24, 2020
2 parents fa1a568 + e30ddcc commit 7c078fe
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 141 deletions.
14 changes: 1 addition & 13 deletions osu.Game.Rulesets.Karaoke/Edit/DrawableKaraokeEditRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,7 @@ public DrawableKaraokeEditRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyLi
{
}

public override DrawableHitObject<KaraokeHitObject> CreateDrawableRepresentation(KaraokeHitObject h)
{
switch (h)
{
case Lyric lyric:
return new DrawableLyric(lyric);

case Note note:
return new DrawableNote(note);
}

return null;
}
public override DrawableHitObject<KaraokeHitObject> CreateDrawableRepresentation(KaraokeHitObject h) => null;

protected override bool OnKeyDown(KeyDownEvent e)
{
Expand Down
12 changes: 11 additions & 1 deletion osu.Game.Rulesets.Karaoke/Objects/BarLine.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Bindables;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;

namespace osu.Game.Rulesets.Karaoke.Objects
{
public class BarLine : KaraokeHitObject, IBarLine
{
public bool Major { get; set; }
public bool Major
{
get => MajorBindable.Value;
set => MajorBindable.Value = value;
}

public readonly Bindable<bool> MajorBindable = new BindableBool();

public override Judgement CreateJudgement() => new IgnoreJudgement();
}
}
116 changes: 85 additions & 31 deletions osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableBarLine.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osuTK;
using osuTK.Graphics;
Expand All @@ -24,46 +28,96 @@ public class DrawableBarLine : DrawableKaraokeScrollingHitObject<BarLine>
/// </summary>
private const float triangle_offset = 9;

public DrawableBarLine(BarLine barLine)
/// <summary>
/// The visual line tracker.
/// </summary>
private Box line;

/// <summary>
/// Container with triangles. Only visible for major lines.
/// </summary>
private Container triangleContainer;

private readonly Bindable<bool> major = new Bindable<bool>();

public DrawableBarLine()
: this(null)
{
}

public DrawableBarLine([CanBeNull] BarLine barLine)
: base(barLine)
{
}

[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.Y;
Width = 2f;

AddInternal(new Box
{
Name = "Bar line",
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
Colour = new Color4(255, 204, 33, 255),
});

if (barLine.Major)
AddRangeInternal(new Drawable[]
{
AddInternal(new EquilateralTriangle
line = new Box
{
Name = "Up triangle",
Anchor = Anchor.TopCentre,
Origin = Anchor.Centre,
Size = new Vector2(triangle_width),
Y = -triangle_offset,
Rotation = 180
});

AddInternal(new EquilateralTriangle
Name = "Bar line",
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
Colour = new Color4(255, 204, 33, 255),
},
triangleContainer = new Container
{
Name = "Down triangle",
Anchor = Anchor.BottomCentre,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(triangle_width),
Y = triangle_offset,
Rotation = 0
});
}

if (!barLine.Major)
Alpha = 0.2f;
RelativeSizeAxes = Axes.Both,
Children = new []
{
new EquilateralTriangle
{
Name = "Up triangle",
Anchor = Anchor.TopCentre,
Origin = Anchor.Centre,
Size = new Vector2(triangle_width),
Y = -triangle_offset,
Rotation = 180
},
new EquilateralTriangle
{
Name = "Down triangle",
Anchor = Anchor.BottomCentre,
Origin = Anchor.Centre,
Size = new Vector2(triangle_width),
Y = triangle_offset,
Rotation = 0
}
}
}
});
}

protected override void LoadComplete()
{
base.LoadComplete();
major.BindValueChanged(updateMajor, true);
}

private void updateMajor(ValueChangedEvent<bool> major)
{
line.Alpha = major.NewValue ? 1f : 0.75f;
triangleContainer.Alpha = major.NewValue ? 1 : 0;
}

protected override void OnApply()
{
base.OnApply();
major.BindTo(HitObject.MajorBindable);
}

protected override void OnFree()
{
base.OnFree();
major.UnbindFrom(HitObject.MajorBindable);
}

protected override void UpdateInitialTransforms()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ protected override void UpdateInitialTransforms()
public abstract class DrawableKaraokeScrollingHitObject<TObject> : DrawableKaraokeScrollingHitObject
where TObject : KaraokeHitObject
{
public new readonly TObject HitObject;
public new TObject HitObject => base.HitObject as TObject;

protected DrawableKaraokeScrollingHitObject(TObject hitObject)
: base(hitObject)
{
HitObject = hitObject;
}
}
}
55 changes: 10 additions & 45 deletions osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,14 @@ private void load()
{
Scale = new Vector2(2f);
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
KaraokeText = new KarakeSpriteText(),
translateText = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft,
}
};

LifetimeEnd = HitObject.EndTime + 1000;

AddInternal(KaraokeText = new KarakeSpriteText());
AddInternal(translateText = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft,
});

TextBindable.BindValueChanged(text => { KaraokeText.Text = text.NewValue; });
TimeTagsBindable.BindValueChanged(timeTags => { KaraokeText.TimeTags = TimeTagsUtils.ToDictionary(timeTags.NewValue); });
RubyTagsBindable.BindValueChanged(rubyTags => { ApplyRuby(); });
Expand Down Expand Up @@ -106,18 +102,6 @@ protected override void OnFree()
TranslateTextBindable.UnbindFrom(HitObject.TranslateTextBindable);
}

protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();

// Manually set to reduce the number of future alive objects to a bare minimum.
LifetimeStart = HitObject.StartTime - HitObject.TimePreempt;
}

protected override void ClearInternal(bool disposeChildren = true)
{
}

protected virtual void ApplyRuby()
{
KaraokeText.Rubies = DisplayRuby ? HitObject.RubyTags?.Select(x => new PositionText(x.Text, x.StartIndex, x.EndIndex)).ToArray() : null;
Expand Down Expand Up @@ -148,6 +132,9 @@ protected override void ApplySkin(ISkinSource skin, bool allowFallback)
if (CurrentSkin == null)
return;

if (HitObject == null)
return;

skin.GetConfig<KaraokeSkinLookup, KaraokeFont>(new KaraokeSkinLookup(KaraokeSkinConfiguration.LyricStyle, HitObject.Singers))?.BindValueChanged(karaokeFont =>
{
if (karaokeFont.NewValue != null)
Expand Down Expand Up @@ -254,28 +241,6 @@ protected override void UpdateStartTimeStateTransforms()
}
}

public override double LifetimeStart
{
get => base.LifetimeStart;
set
{
base.LifetimeStart = value;
KaraokeText.LifetimeStart = value;
translateText.LifetimeStart = value;
}
}

public override double LifetimeEnd
{
get => base.LifetimeEnd;
set
{
base.LifetimeEnd = value;
KaraokeText.LifetimeEnd = value;
translateText.LifetimeEnd = value;
}
}

private bool displayRuby;

public bool DisplayRuby
Expand Down
53 changes: 44 additions & 9 deletions osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// See the LICENCE file in the repository root for full licence text.

using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Input.Bindings;
Expand All @@ -22,7 +24,7 @@ namespace osu.Game.Rulesets.Karaoke.Objects.Drawables
/// </summary>
public class DrawableNote : DrawableKaraokeScrollingHitObject<Note>, IKeyBindingHandler<KaraokeSaitenAction>
{
private readonly OsuSpriteText textPiece;
private OsuSpriteText textPiece;

/// <summary>
/// Time at which the user started holding this hold note. Null if the user is not holding this hold note.
Expand All @@ -33,12 +35,19 @@ public class DrawableNote : DrawableKaraokeScrollingHitObject<Note>, IKeyBinding

private readonly Bindable<bool> isHitting = new Bindable<bool>();

public IBindable<bool> Display => HitObject.DisplayBindable;
public readonly IBindable<string> TextBindable = new Bindable<string>();
public readonly IBindable<string> AlternativeTextBindable = new Bindable<string>();
public readonly IBindable<int[]> SingersBindable = new Bindable<int[]>();
public readonly IBindable<bool> DisplayBindable = new Bindable<bool>();
public readonly IBindable<Tone> ToneBindable = new Bindable<Tone>();

public IBindable<int[]> Singers => HitObject.SingersBindable;
public DrawableNote()
: this(null)
{
}

public DrawableNote(Note note)
: base(note)
public DrawableNote([CanBeNull] Note hitObject)
: base(hitObject)
{
Height = DefaultColumnBackground.COLUMN_HEIGHT;

Expand All @@ -55,14 +64,37 @@ public DrawableNote(Note note)
bodyPiece.AccentColour = colour.NewValue;
}, true);
*/
}

Display.BindValueChanged(e => { (Result.Judgement as KaraokeNoteJudgement).Saitenable = e.NewValue; });
[BackgroundDependencyLoader]
private void load()
{
TextBindable.BindValueChanged(_ => { changeText(HitObject); });
AlternativeTextBindable.BindValueChanged(_ => { changeText(HitObject); });
SingersBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); });
DisplayBindable.BindValueChanged(e => { (Result.Judgement as KaraokeNoteJudgement).Saitenable = e.NewValue; });
}

note.TextBindable.BindValueChanged(_ => { changeText(note); }, true);
protected override void OnApply()
{
base.OnApply();

note.AlternativeTextBindable.BindValueChanged(_ => { changeText(note); }, true);
TextBindable.BindTo(HitObject.TextBindable);
AlternativeTextBindable.BindTo(HitObject.AlternativeTextBindable);
SingersBindable.BindTo(HitObject.SingersBindable);
DisplayBindable.BindTo(HitObject.DisplayBindable);
ToneBindable.BindTo(HitObject.ToneBindable);
}

protected override void OnFree()
{
base.OnFree();

note.SingersBindable.BindValueChanged(index => { ApplySkin(CurrentSkin, false); }, true);
TextBindable.UnbindFrom(HitObject.TextBindable);
AlternativeTextBindable.UnbindFrom(HitObject.AlternativeTextBindable);
SingersBindable.UnbindFrom(HitObject.SingersBindable);
DisplayBindable.UnbindFrom(HitObject.DisplayBindable);
ToneBindable.UnbindFrom(HitObject.ToneBindable);
}

protected override void ApplySkin(ISkinSource skin, bool allowFallback)
Expand All @@ -72,6 +104,9 @@ protected override void ApplySkin(ISkinSource skin, bool allowFallback)
if (CurrentSkin == null)
return;

if (HitObject == null)
return;

var noteSkin = skin.GetConfig<KaraokeSkinLookup, NoteSkin>(new KaraokeSkinLookup(KaraokeSkinConfiguration.NoteStyle, HitObject.Singers))?.Value;
if (noteSkin == null)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private void load([CanBeNull] DrawableHitObject drawableObject, ISkinSource skin
var holdNote = (DrawableNote)drawableObject;

isHitting.BindTo(holdNote.IsHitting);
display.BindTo(holdNote.Display);
singer.BindTo(holdNote.Singers);
display.BindTo(holdNote.DisplayBindable);
singer.BindTo(holdNote.SingersBindable);
}

AccentColour.BindValueChanged(onAccentChanged);
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/Skinning/LegacyNotePiece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private void load(DrawableHitObject drawableObject, ISkinSource skin, IScrolling
var holdNote = (DrawableNote)drawableObject;

isHitting.BindTo(holdNote.IsHitting);
display.BindTo(holdNote.Display);
singer.BindTo(holdNote.Singers);
display.BindTo(holdNote.DisplayBindable);
singer.BindTo(holdNote.SingersBindable);
}

AccentColour.BindValueChanged(onAccentChanged);
Expand Down
Loading

0 comments on commit 7c078fe

Please sign in to comment.