82 lines
2.8 KiB
C#
82 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Encompass
|
|
{
|
|
internal class TimeManager
|
|
{
|
|
private readonly List<TimeDilationData> timeDilationDatas = new List<TimeDilationData>(32);
|
|
|
|
private double Linear(double t, double b, double c, double d)
|
|
{
|
|
return (c * t / d) + b;
|
|
}
|
|
|
|
public double TimeDilationFactor
|
|
{
|
|
get
|
|
{
|
|
if (timeDilationDatas.Count == 0) { return 1; }
|
|
var average = 0.0;
|
|
foreach (var data in timeDilationDatas)
|
|
{
|
|
average += data.Factor;
|
|
}
|
|
return average / timeDilationDatas.Count;
|
|
}
|
|
}
|
|
|
|
public bool TimeDilationActive
|
|
{
|
|
get => timeDilationDatas.Count != 0;
|
|
}
|
|
|
|
public void Update(double dt)
|
|
{
|
|
for (var i = timeDilationDatas.Count - 1; i >= 0; i--)
|
|
{
|
|
var data = timeDilationDatas[i];
|
|
|
|
data.elapsedTime += dt;
|
|
|
|
if (data.elapsedTime > data.easeInTime + data.activeTime + data.easeOutTime)
|
|
{
|
|
timeDilationDatas.RemoveAt(i);
|
|
}
|
|
else
|
|
{
|
|
timeDilationDatas[i] = data;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime)
|
|
{
|
|
ActivateTimeDilation(factor, easeInTime, Linear, activeTime, easeOutTime, Linear);
|
|
}
|
|
|
|
public void ActivateTimeDilation(double factor, double easeInTime, System.Func<double, double, double, double, double> easeInFunction, double activeTime, double easeOutTime)
|
|
{
|
|
ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime, Linear);
|
|
}
|
|
|
|
public void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime, System.Func<double, double, double, double, double> easeOutFunction)
|
|
{
|
|
ActivateTimeDilation(factor, easeInTime, Linear, activeTime, easeOutTime, easeOutFunction);
|
|
}
|
|
|
|
public void ActivateTimeDilation(double factor, double easeInTime, System.Func<double, double, double, double, double> easeInFunction, double activeTime, double easeOutTime, System.Func<double, double, double, double, double> easeOutFunction)
|
|
{
|
|
timeDilationDatas.Add(new TimeDilationData
|
|
{
|
|
elapsedTime = 0,
|
|
easeInTime = easeInTime,
|
|
easeInFunction = easeInFunction,
|
|
activeTime = activeTime,
|
|
easeOutTime = easeOutTime,
|
|
easeOutFunction = easeOutFunction,
|
|
factor = factor
|
|
});
|
|
}
|
|
}
|
|
}
|