forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
61
lib/aura/Sources/aura/Time.hx
Normal file
61
lib/aura/Sources/aura/Time.hx
Normal file
@ -0,0 +1,61 @@
|
||||
package aura;
|
||||
|
||||
import kha.Scheduler;
|
||||
|
||||
import aura.threading.BufferCache;
|
||||
|
||||
class Time {
|
||||
public static var lastTime(default, null): Float = 0.0;
|
||||
public static var delta(default, null): Float = 0.0;
|
||||
|
||||
#if AURA_UNIT_TESTS
|
||||
public static var overrideTime: Null<Float> = null;
|
||||
#end
|
||||
|
||||
#if AURA_BENCHMARK
|
||||
public static var times: Array<Float>;
|
||||
static var benchmarkStarted = false;
|
||||
static var currentIteration = 0;
|
||||
static var numIterations = 0;
|
||||
static var onBenchmarkDone: Array<Float>->Void;
|
||||
#end
|
||||
|
||||
public static inline function getTime():Float {
|
||||
#if AURA_UNIT_TESTS
|
||||
if (overrideTime != null) {
|
||||
return overrideTime;
|
||||
}
|
||||
#end
|
||||
return Scheduler.realTime();
|
||||
}
|
||||
|
||||
public static inline function update() {
|
||||
delta = getTime() - lastTime;
|
||||
lastTime = getTime();
|
||||
|
||||
BufferCache.updateTimer();
|
||||
}
|
||||
|
||||
#if AURA_BENCHMARK
|
||||
public static inline function endOfFrame() {
|
||||
if (benchmarkStarted) {
|
||||
times[currentIteration] = Scheduler.realTime() - lastTime;
|
||||
currentIteration++;
|
||||
if (currentIteration == numIterations) {
|
||||
onBenchmarkDone(times);
|
||||
benchmarkStarted = false;
|
||||
currentIteration = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function startBenchmark(numIterations: Int, onBenchmarkDone: Array<Float>->Void) {
|
||||
Time.numIterations = numIterations;
|
||||
Time.onBenchmarkDone = onBenchmarkDone;
|
||||
times = new Array();
|
||||
times.resize(numIterations);
|
||||
|
||||
benchmarkStarted = true;
|
||||
}
|
||||
#end
|
||||
}
|
||||
Reference in New Issue
Block a user