Improved naming and documentation

This commit is contained in:
LubieKakao1212 2022-12-19 15:23:50 +01:00
parent c60b15dc51
commit 927d835d2e

View File

@ -12,32 +12,38 @@ namespace NEG.Utils.Timing
} }
/// <summary> /// <summary>
/// Adds time int this TimeMachine /// Adds time into the TimeMachine
/// </summary> /// </summary>
/// <param name="time">Amount of time to be added</param> /// <param name="time">Amount of time to be added</param>
public void Forward(double time) public void Accumulate(double time)
{ {
this.time += time; this.time += time;
} }
/// <summary> /// <summary>
/// Decreeses the amount of time in this TimeMashine by up to given amount /// Retrieves given amount of time from the TimeMachine
/// </summary> /// </summary>
/// <param name="maxTime"></param> /// <param name="maxTime"></param>
/// <returns>Amount of time decressed</returns> /// <returns>Amount of time retrievend</returns>
public double Warp(double maxTime) public double Retrieve(double maxTime)
{ {
if(!Double.IsFinite(maxTime))
{
double timeRetrieved = time;
time = 0;
return timeRetrieved;
}
double timeLeft = time - maxTime; double timeLeft = time - maxTime;
time = Math.Max(timeLeft, 0); time = Math.Max(timeLeft, 0);
return Math.Min(maxTime + timeLeft, maxTime); return Math.Min(maxTime + timeLeft, maxTime);
} }
/// <summary> /// <summary>
/// Attempts to decrese the amount of time in this TimeMachine <br/> /// Attempts to retrieves given amount of time from the TimeMachine <br/>
/// If there is at least <paramref name="time"/> time accumulated in this machine subtructs that amount and returns true, otherwise returns false /// If there is enough <paramref name="time"/> accumulated in this machine subtructs that amount and returns true, otherwise returns false
/// </summary> /// </summary>
/// <param name="time"></param> /// <param name="time"></param>
public bool TryWarp(double time) public bool TryRetrieve(double time)
{ {
if (this.time >= time) if (this.time >= time)
{ {
@ -48,12 +54,12 @@ namespace NEG.Utils.Timing
} }
/// <summary> /// <summary>
/// Result is equivalent to calling <see cref="TryWarp(double)"/> as many times as possible, but is faster fo larger <paramref name="limit"/> values /// Result is equivalent to calling <see cref="TryRetrieve(double)"/> as many times as possible, but is faster for larger <paramref name="limit"/> values
/// </summary> /// </summary>
/// <param name="interval">Single unit of warp time, must be non negative/param> /// <param name="interval">Single unit of warp time, must be positive/param>
/// <param name="limit">Maximum amount of warps, must be non negative</param> /// <param name="limit">Maximum amount of warps, must be positive</param>
/// <returns>Amount of warps</returns> /// <returns>Amount of warps</returns>
public int MultiWarp(double interval, int limit = int.MaxValue) public int RetrieveAll(double interval, int limit = int.MaxValue)
{ {
int result = (int)Math.Floor(time / interval); int result = (int)Math.Floor(time / interval);
result = Math.Clamp(result, 0, limit); result = Math.Clamp(result, 0, limit);