-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
910 additions
and
558 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/Tracker/AbstractTracker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Timing; | ||
using osu.Game.Graphics.Sprites; | ||
|
||
namespace osu.Game.Rulesets.IGPlayer.Feature.Gosumemory.Tracker; | ||
|
||
public partial class AbstractTracker : CompositeDrawable | ||
{ | ||
protected TrackerHub Hub { get; private set; } | ||
|
||
public AbstractTracker(TrackerHub hub) | ||
{ | ||
this.Hub = hub; | ||
AlwaysPresent = true; | ||
|
||
InternalChild = new OsuSpriteText | ||
{ | ||
Text = $"{this}", | ||
Margin = new MarginPadding(30) | ||
}; | ||
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
this.Clock = new FramedClock(null, false); | ||
} | ||
|
||
public virtual void UpdateValues() | ||
{ | ||
} | ||
} |
156 changes: 156 additions & 0 deletions
156
osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/Tracker/BeatmapStrainTracker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Extensions; | ||
using osu.Framework.Logging; | ||
using osu.Game.Beatmaps; | ||
using osu.Game.Rulesets.Objects; | ||
|
||
namespace osu.Game.Rulesets.IGPlayer.Feature.Gosumemory.Tracker; | ||
|
||
/// <summary> | ||
/// 计算pp/密度表 | ||
/// </summary> | ||
public partial class BeatmapStrainTracker : AbstractTracker | ||
{ | ||
public BeatmapStrainTracker(TrackerHub hub) | ||
: base(hub) | ||
{ | ||
} | ||
|
||
private double invokeTime = 0d; | ||
private WorkingBeatmap? beatmapOnInvoke; | ||
|
||
private CancellationTokenSource? ppStrainCancellationTokenSource; | ||
|
||
private bool scheduleStrainComputes; | ||
|
||
private readonly Bindable<WorkingBeatmap> working = new Bindable<WorkingBeatmap>(); | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(Bindable<WorkingBeatmap> globalWorking) | ||
{ | ||
this.working.BindTo(globalWorking); | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
working.BindValueChanged(e => | ||
{ | ||
this.UpdateStrain(e.NewValue); | ||
}); | ||
} | ||
|
||
protected override void Update() | ||
{ | ||
if (scheduleStrainComputes && beatmapOnInvoke == working.Value) | ||
UpdateStrain(this.working.Value); | ||
} | ||
|
||
public void UpdateStrain(WorkingBeatmap workingBeatmap) | ||
{ | ||
this.invokeTime = Clock.CurrentTime; | ||
beatmapOnInvoke = workingBeatmap; | ||
scheduleStrainComputes = false; | ||
|
||
ppStrainCancellationTokenSource?.Cancel(); | ||
ppStrainCancellationTokenSource = new CancellationTokenSource(); | ||
|
||
Task.Run(async () => await updateStrain(workingBeatmap), ppStrainCancellationTokenSource.Token) | ||
.ContinueWith(task => | ||
{ | ||
if (!task.IsCompleted) return; | ||
|
||
if (task.Exception != null) | ||
{ | ||
Logging.LogError(task.Exception, "Error occurred while updating strain"); | ||
return; | ||
} | ||
|
||
this.Schedule(() => | ||
{ | ||
float[] result = task.GetResultSafely(); | ||
Hub.GetDataRoot().MenuValues.pp.Strains = result; | ||
}); | ||
}); | ||
} | ||
|
||
private Task<float[]> updateStrain(WorkingBeatmap workingBeatmap) | ||
{ | ||
try | ||
{ | ||
double length = workingBeatmap.Track.Length; | ||
|
||
//WorkingBeatmap.TrackLoaded: true + WorkingBeatmap.Track.IsLoaded: false -> Track Length: 0 | ||
if (length <= 0) | ||
{ | ||
//持续5秒都没有音频,可能已经损坏,清空分布 | ||
//todo: 没有音频的时候使用谱面长度来计算并更新分布和进度 | ||
if (Clock.CurrentTime - invokeTime >= 10 * 1000) | ||
{ | ||
Hub.GetDataRoot().MenuValues.pp.Strains = new[] { 0f }; | ||
|
||
Logger.Log("谱面音频在10秒内都没有加载,将放弃计算物件分布...", level: LogLevel.Important); | ||
return Task.FromResult(new[] { 0f }); | ||
} | ||
|
||
scheduleStrainComputes = true; | ||
return Task.FromResult(new [] { 0f }); | ||
} | ||
|
||
scheduleStrainComputes = false; | ||
|
||
// 最大分段数和密度缩放 | ||
int maximumSegments = 512; | ||
double segmentScale = 1; | ||
|
||
// 根据歌曲长度分段,总共分为 (歌曲总时间(秒) * segScale) 段 | ||
int targetSegments = (int)(TimeSpan.FromMilliseconds(length).TotalSeconds * segmentScale); | ||
|
||
// 限制最大分段数量 | ||
targetSegments = Math.Min(maximumSegments, targetSegments); | ||
if (targetSegments <= 0) targetSegments = 1; | ||
|
||
// 尝试自动转谱 | ||
var converter = workingBeatmap.BeatmapInfo.Ruleset.CreateInstance().CreateBeatmapConverter(workingBeatmap.Beatmap); | ||
IBeatmap? beatmap = null; | ||
|
||
//Logger.Log($"Track length: {length} ~ Segments {targetSegments} ~ Conv? {converter.CanConvert()} ~ Loaded? {workingBeatmap.Track.IsLoaded} ~ Track? {workingBeatmap.Track}"); | ||
if (converter.CanConvert()) beatmap = converter.Convert(); | ||
var hitObjects = beatmap?.HitObjects ?? new HitObject[] { }; | ||
|
||
//获取每段的音频跨度 | ||
double audioStep = length / targetSegments; | ||
|
||
//Segment -> Count | ||
var segments = new Dictionary<int, float>(); | ||
|
||
for (int i = 0; i < targetSegments; i++) | ||
{ | ||
//此段的音频跨度 | ||
double startTime = i * audioStep; | ||
double endTime = (1 + i) * audioStep; | ||
|
||
//将跨度内的所有物件添加进来 | ||
//o -> [startTime, endTime) | ||
int count = hitObjects.Count(o => o.StartTime < endTime && o.StartTime >= startTime); | ||
|
||
segments.TryAdd(i, count); | ||
} | ||
|
||
//最后将其返回 | ||
return Task.FromResult(segments.Values.ToArray()); | ||
} | ||
catch (Exception e) | ||
{ | ||
return Task.FromException<float[]>(e); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
osu.Game.Rulesets.IGPlayer/Feature/Gosumemory/Tracker/BeatmapTracker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Logging; | ||
using osu.Game.Beatmaps; | ||
|
||
namespace osu.Game.Rulesets.IGPlayer.Feature.Gosumemory.Tracker; | ||
|
||
public partial class BeatmapTracker : AbstractTracker | ||
{ | ||
public BeatmapTracker(TrackerHub hub) | ||
: base(hub) | ||
{ | ||
} | ||
|
||
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>(); | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(Bindable<WorkingBeatmap> globalBeatmap) | ||
{ | ||
this.beatmap.BindTo(globalBeatmap); | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
Logger.Log("DDDLOADCOMPLETE"); | ||
base.LoadComplete(); | ||
|
||
this.beatmap.BindValueChanged(e => | ||
{ | ||
this.onBeatmapChanged(e.NewValue); | ||
}, true); | ||
} | ||
|
||
private void onBeatmapChanged(WorkingBeatmap newBeatmap) | ||
{ | ||
Hub.GetDataRoot().UpdateBeatmap(newBeatmap); | ||
} | ||
} |
Oops, something went wrong.