osu/osu.Game/Screens/Play/SongProgressGraph.cs

51 lines
1.6 KiB
C#
Raw Normal View History

2018-01-05 11:21:19 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-02-07 17:26:17 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
2017-02-07 05:49:41 +00:00
using System.Collections.Generic;
using System.Diagnostics;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Objects;
2017-02-03 19:22:02 +00:00
namespace osu.Game.Screens.Play
{
public class SongProgressGraph : SquareGraph
2017-02-03 19:22:02 +00:00
{
private IEnumerable<HitObject> objects;
2017-02-07 05:49:41 +00:00
public IEnumerable<HitObject> Objects
{
set
{
objects = value;
2017-07-08 09:04:55 +00:00
const int granularity = 200;
Values = new int[granularity];
if (!objects.Any())
return;
2017-05-07 22:23:51 +00:00
var firstHit = objects.First().StartTime;
var lastHit = objects.Max(o => (o as IHasEndTime)?.EndTime ?? o.StartTime);
if (lastHit == 0)
lastHit = objects.Last().StartTime;
2017-05-07 22:23:51 +00:00
var interval = (lastHit - firstHit + 1) / granularity;
foreach (var h in objects)
2017-03-23 09:37:12 +00:00
{
2017-09-14 04:42:58 +00:00
var endTime = (h as IHasEndTime)?.EndTime ?? h.StartTime;
2017-09-14 04:13:54 +00:00
Debug.Assert(endTime >= h.StartTime);
2017-03-23 09:37:12 +00:00
int startRange = (int)((h.StartTime - firstHit) / interval);
int endRange = (int)((endTime - firstHit) / interval);
for (int i = startRange; i <= endRange; i++)
Values[i]++;
2017-03-23 09:37:12 +00:00
}
}
}
}
}