Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Timer.stop() #1839

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/haxe/Timer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,7 @@ class Timer

public function stop():Void
{
if (mRunning)
{
mRunning = false;

for (i in 0...sRunningTimers.length)
{
if (sRunningTimers[i] == this)
{
sRunningTimers[i] = null;
break;
}
}
}
mRunning = false;
}

@:noCompletion private function __check(inTime:Float)
Expand Down
21 changes: 9 additions & 12 deletions src/lime/_internal/backend/native/NativeApplication.hx
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ class NativeApplication
if (pauseTimer > -1)
{
var offset = System.getTimer() - pauseTimer;
for (i in 0...Timer.sRunningTimers.length)
for (timer in Timer.sRunningTimers)
{
if (Timer.sRunningTimers[i] != null) Timer.sRunningTimers[i].mFireAt += offset;
if (timer.mRunning) timer.mFireAt += offset;
}
pauseTimer = -1;
}
Expand Down Expand Up @@ -578,32 +578,29 @@ class NativeApplication
if (Timer.sRunningTimers.length > 0)
{
var currentTime = System.getTimer();
var foundNull = false;
var timer;
var foundStopped = false;

for (i in 0...Timer.sRunningTimers.length)
for (timer in Timer.sRunningTimers)
{
timer = Timer.sRunningTimers[i];

if (timer != null)
if (timer.mRunning)
{
if (timer.mRunning && currentTime >= timer.mFireAt)
if (currentTime >= timer.mFireAt)
{
timer.mFireAt += timer.mTime;
timer.run();
}
}
else
{
foundNull = true;
foundStopped = true;
}
}

if (foundNull)
if (foundStopped)
{
Timer.sRunningTimers = Timer.sRunningTimers.filter(function(val)
{
return val != null;
return val.mRunning;
});
}
}
Expand Down
Loading