daily update on 20240610 by nitload youmu
This commit is contained in:
@@ -36,10 +36,13 @@ namespace StgSharp
|
||||
{
|
||||
public class TimeFunction
|
||||
{
|
||||
|
||||
private float _beginning, _ending;
|
||||
private Func<float, float> _timeRelatedCalculation;
|
||||
private TimeSpanProvider _timeProvider;
|
||||
|
||||
internal TimeFunction() { }
|
||||
|
||||
public TimeFunction(
|
||||
TimeSpanProvider timeSpanProvider,
|
||||
Func<float, float> timeRelatedCalculation,
|
||||
@@ -55,13 +58,16 @@ namespace StgSharp
|
||||
_ending = _timeProvider.CurrentSecond + range;
|
||||
}
|
||||
|
||||
internal TimeFunction() { }
|
||||
|
||||
public bool IsComplete
|
||||
public virtual bool IsComplete
|
||||
{
|
||||
get => _timeProvider.CurrentSecond > _ending;
|
||||
}
|
||||
|
||||
public static TimeFunction One
|
||||
{
|
||||
get => new TimeFunctionOne();
|
||||
}
|
||||
|
||||
public Func<float, float> TimeRelatedCalculation
|
||||
{
|
||||
get { return _timeRelatedCalculation; }
|
||||
@@ -74,7 +80,7 @@ namespace StgSharp
|
||||
set { _timeProvider = value; }
|
||||
}
|
||||
|
||||
public float Calculate()
|
||||
public virtual float Calculate()
|
||||
{
|
||||
if (_timeProvider.CurrentSecond < _ending)
|
||||
{
|
||||
@@ -83,64 +89,66 @@ namespace StgSharp
|
||||
return _timeRelatedCalculation(_timeProvider.CurrentSecond - _beginning);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
float range = _ending - _beginning;
|
||||
_beginning = _timeProvider.CurrentSecond;
|
||||
_ending = _beginning + range;
|
||||
}
|
||||
|
||||
public TimeFunction Renew(Func<float,float> func,float range)
|
||||
{
|
||||
return new TimeFunction(_timeProvider,func,range);
|
||||
}
|
||||
|
||||
public TimeFunction Renew((Func<float, float> func, float range) funcPair)
|
||||
{
|
||||
return new TimeFunction(_timeProvider, funcPair.func, funcPair.range);
|
||||
}
|
||||
|
||||
public static TimeFunction One
|
||||
{
|
||||
get => new TimeFunctionOne();
|
||||
}
|
||||
|
||||
public static TimeFunction Proportional(TimeSpanProvider time,float begin, float range)
|
||||
public static TimeFunction Proportional(TimeSpanProvider time, float begin, float range)
|
||||
{
|
||||
return new TimeFunction(
|
||||
time, (float t) => t + begin, range
|
||||
);
|
||||
}
|
||||
|
||||
public virtual TimeFunction Renew((Func<float, float> func, float range) funcPair)
|
||||
{
|
||||
return new TimeFunction(_timeProvider, funcPair.func, funcPair.range);
|
||||
}
|
||||
|
||||
public virtual TimeFunction Renew(Func<float, float> func, float range)
|
||||
{
|
||||
return new TimeFunction(_timeProvider, func, range);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
float range = _ending - _beginning;
|
||||
_beginning = _timeProvider.CurrentSecond;
|
||||
_ending = _beginning + range;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class TimeFunctionOne : TimeFunction
|
||||
public sealed class TimeFunctionOne : TimeFunction
|
||||
{
|
||||
|
||||
internal TimeFunctionOne() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public new bool IsCompleted
|
||||
public override bool IsComplete
|
||||
{
|
||||
get => true;
|
||||
}
|
||||
|
||||
public new void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
public new TimeFunction Renew(Func<float, float> func, float range)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public new TimeFunction Renew((Func<float, float> func, float range) funcPair)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public float Calculate()
|
||||
public override float Calculate()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public override TimeFunction Renew((Func<float, float> func, float range) funcPair)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override TimeFunction Renew(Func<float, float> func, float range)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
#pragma warning disable CA1822
|
||||
public new void Reset()
|
||||
#pragma warning restore CA1822
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user