1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:22:55 +08:00

Abstract follow points into a separate class.

This commit is contained in:
Damnae 2017-02-10 08:10:24 +01:00
parent 77ee161be8
commit 4e6b6ab794
5 changed files with 87 additions and 61 deletions

View File

@ -9,7 +9,7 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.Transformations;
namespace osu.Game.Modes.Osu.Objects.Drawables
namespace osu.Game.Modes.Osu.Objects.Drawables.Connections
{
public class FollowPoint : Container
{

View File

@ -0,0 +1,65 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Osu.Objects.Drawables.Connections;
using System;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Modes.Osu.Objects.Drawables
{
public class FollowPointConnection : HitObjectConnection
{
public int PointDistance = 32;
public int PreEmpt = 800;
public override void AddConnections(IEnumerable<DrawableHitObject> drawableHitObjects, int startIndex = 0, int endIndex = -1)
{
var hitObjects = new List<OsuHitObject>(drawableHitObjects
.Select(d => (OsuHitObject)d.HitObject)
.OrderBy(h => h.StartTime));
if (endIndex < 0)
endIndex = hitObjects.Count - 1;
for (int i = startIndex + 1; i <= endIndex; i++)
{
var prevHitObject = hitObjects[i - 1];
var currHitObject = hitObjects[i];
if (!currHitObject.NewCombo && !(prevHitObject is Spinner) && !(currHitObject is Spinner))
{
Vector2 startPosition = prevHitObject.EndPosition;
Vector2 endPosition = currHitObject.Position;
double startTime = prevHitObject.EndTime;
double endTime = currHitObject.StartTime;
Vector2 distanceVector = endPosition - startPosition;
int distance = (int)distanceVector.Length;
float rotation = (float)Math.Atan2(distanceVector.Y, distanceVector.X);
double duration = endTime - startTime;
for (int d = (int)(PointDistance * 1.5); d < distance - PointDistance; d += PointDistance)
{
float fraction = ((float)d / distance);
Vector2 pointStartPosition = startPosition + (fraction - 0.1f) * distanceVector;
Vector2 pointEndPosition = startPosition + fraction * distanceVector;
double fadeOutTime = startTime + fraction * duration;
double fadeInTime = fadeOutTime - PreEmpt;
Add(new FollowPoint()
{
StartTime = fadeInTime,
EndTime = fadeOutTime,
Position = pointStartPosition,
EndPosition = pointEndPosition,
Rotation = rotation,
});
}
}
}
}
}
}

View File

@ -0,0 +1,14 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics.Containers;
using osu.Game.Modes.Objects.Drawables;
using System.Collections.Generic;
namespace osu.Game.Modes.Osu.Objects.Drawables.Connections
{
public abstract class HitObjectConnection : Container
{
public abstract void AddConnections(IEnumerable<DrawableHitObject> drawableHitObjects, int startIndex = 0, int endIndex = -1);
}
}

View File

@ -7,10 +7,8 @@ using osu.Framework.Graphics.Containers;
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Osu.Objects;
using osu.Game.Modes.Osu.Objects.Drawables;
using osu.Game.Modes.Osu.Objects.Drawables.Connections;
using osu.Game.Modes.UI;
using System;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Modes.Osu.UI
{
@ -18,7 +16,7 @@ namespace osu.Game.Modes.Osu.UI
{
private Container approachCircles;
private Container judgementLayer;
private Container followPointsLayer;
private HitObjectConnection hitObjectConnection;
public override Vector2 Size
{
@ -40,7 +38,7 @@ namespace osu.Game.Modes.Osu.UI
Add(new Drawable[]
{
followPointsLayer = new Container
hitObjectConnection = new FollowPointConnection
{
RelativeSizeAxes = Axes.Both,
Depth = 1,
@ -74,7 +72,7 @@ namespace osu.Game.Modes.Osu.UI
public override void PostProcess()
{
AddFollowPoints();
hitObjectConnection.AddConnections(HitObjects.Children);
}
private void judgement(DrawableHitObject h, JudgementInfo j)
@ -83,58 +81,5 @@ namespace osu.Game.Modes.Osu.UI
judgementLayer.Add(explosion);
}
public void AddFollowPoints(int startIndex = 0, int endIndex = -1)
{
var followLineDistance = 32;
var followLinePreEmpt = 800;
var hitObjects = new List<OsuHitObject>(HitObjects.Children
.Select(d => (OsuHitObject)d.HitObject)
.OrderBy(h => h.StartTime));
if (endIndex < 0)
endIndex = hitObjects.Count - 1;
for (int i = startIndex + 1; i <= endIndex; i++)
{
var prevHitObject = hitObjects[i - 1];
var currHitObject = hitObjects[i];
if (prevHitObject.StartTime > currHitObject.StartTime)
throw new Exception();
if (!currHitObject.NewCombo && !(prevHitObject is Spinner) && !(currHitObject is Spinner))
{
Vector2 startPosition = prevHitObject.EndPosition;
Vector2 endPosition = currHitObject.Position;
double startTime = prevHitObject.EndTime;
double endTime = currHitObject.StartTime;
Vector2 distanceVector = endPosition - startPosition;
int distance = (int)distanceVector.Length;
float rotation = (float)Math.Atan2(distanceVector.Y, distanceVector.X);
double duration = endTime - startTime;
for (int d = (int)(followLineDistance * 1.5); d < distance - followLineDistance; d += followLineDistance)
{
float fraction = ((float)d / distance);
Vector2 pointStartPosition = startPosition + (fraction - 0.1f) * distanceVector;
Vector2 pointEndPosition = startPosition + fraction * distanceVector;
double fadeOutTime = startTime + fraction * duration;
double fadeInTime = fadeOutTime - followLinePreEmpt;
followPointsLayer.Add(new FollowPoint()
{
StartTime = fadeInTime,
EndTime = fadeOutTime,
Position = pointStartPosition,
EndPosition = pointEndPosition,
Rotation = rotation,
});
}
}
}
}
}
}

View File

@ -44,10 +44,12 @@
<Compile Include="Objects\BezierApproximator.cs" />
<Compile Include="Objects\CircularArcApproximator.cs" />
<Compile Include="Objects\Drawables\DrawableOsuHitObject.cs" />
<Compile Include="Objects\Drawables\Connections\HitObjectConnection.cs" />
<Compile Include="Objects\Drawables\Connections\FollowPointConnection.cs" />
<Compile Include="Objects\Drawables\Pieces\ApproachCircle.cs" />
<Compile Include="Objects\Drawables\Pieces\CirclePiece.cs" />
<Compile Include="Objects\Drawables\DrawableSlider.cs" />
<Compile Include="Objects\Drawables\FollowPoint.cs" />
<Compile Include="Objects\Drawables\Connections\FollowPoint.cs" />
<Compile Include="Objects\Drawables\Pieces\ExplodePiece.cs" />
<Compile Include="Objects\Drawables\Pieces\FlashPiece.cs" />
<Compile Include="Objects\Drawables\Pieces\GlowPiece.cs" />