Fix Timer update code

This commit is contained in:
Joshua Granick
2015-03-25 19:33:27 -07:00
parent c8ae2b85d9
commit 64db93e44e
2 changed files with 43 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
package haxe;
#if (macro || (!neko && !cpp && !nodejs))
#if (macro || (!neko && !cpp))
// Original haxe.Timer class

View File

@@ -13,6 +13,7 @@ import lime.system.System;
import lime.ui.Gamepad;
import lime.ui.Window;
@:access(haxe.Timer)
@:access(lime.app.Application)
@:access(lime.graphics.Renderer)
@:access(lime.ui.Gamepad)
@@ -261,8 +262,7 @@ class NativeApplication {
private function handleUpdateEvent ():Void {
Timer.__checkTimers ();
updateTimer ();
parent.onUpdate.dispatch (updateEventInfo.deltaTime);
}
@@ -324,6 +324,46 @@ class NativeApplication {
}
private function updateTimer ():Void {
if (Timer.sRunningTimers.length > 0) {
var currentTime = System.getTimer ();
var foundNull = false;
var timer;
for (i in 0...Timer.sRunningTimers.length) {
timer = Timer.sRunningTimers[i];
if (timer != null) {
if (currentTime >= timer.mFireAt) {
timer.mFireAt += timer.mTime;
timer.run ();
}
} else {
foundNull = true;
}
}
if (foundNull) {
Timer.sRunningTimers = Timer.sRunningTimers.filter (function (val) { return val != null; });
}
}
}
private function __cleanup ():Void {
AudioManager.shutdown ();