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

Syncing timers started in the same frame #121

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
59 changes: 27 additions & 32 deletions src/motion/actuators/SimpleActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class SimpleActuator<T, U> extends GenericActuator<T> {

private static var actuators = new Array<SimpleActuator<Dynamic, Dynamic>> ();
private static var actuatorsLength = 0;
private static var addedEvent = false;
private static var time:Float;
private static var timerInitialized: Bool;

#if (!flash && !nme && !openfl && !lime && !js)
private static var timer:Timer;
Expand All @@ -49,9 +50,31 @@ class SimpleActuator<T, U> extends GenericActuator<T> {
private var startTime:Float;
private var toggleVisible:Bool;

private static function setup()
{
if (timerInitialized)
return;

timerInitialized = true;

#if !actuate_manual_update
#if (flash || nme || openfl)
Lib.current.stage.addEventListener(Event.ENTER_FRAME, stage_onEnterFrame);
#elseif lime
Application.current.onUpdate.add(stage_onEnterFrame);
#elseif js
Browser.window.requestAnimationFrame(stage_onEnterFrame);
#else
timer = new Timer(Std.int(1000 / 30));
timer.run = stage_onEnterFrame;
#end
#end
}

public function new (target:T, duration:Float, properties:Dynamic) {

setup();

active = true;
propertyDetails = new Array ();
sendChange = false;
Expand All @@ -61,39 +84,9 @@ class SimpleActuator<T, U> extends GenericActuator<T> {
setVisible = false;
toggleVisible = false;

#if !actuate_manual_time
#if (flash || nme || openfl)
startTime = Lib.getTimer () / 1000;
#elseif lime
startTime = System.getTimer () / 1000;
#elseif js
startTime = Browser.window.performance.now () / 1000;
#else
startTime = Timer.stamp ();
#end
#else
startTime = getTime();
#end
startTime = time;

super (target, duration, properties);

if (!addedEvent) {

addedEvent = true;
#if !actuate_manual_update
#if (flash || nme || openfl)
Lib.current.stage.addEventListener (Event.ENTER_FRAME, stage_onEnterFrame);
#elseif lime
Application.current.onUpdate.add (stage_onEnterFrame);
#elseif js
Browser.window.requestAnimationFrame(stage_onEnterFrame);
#else
timer = new Timer (Std.int(1000 / 30));
timer.run = stage_onEnterFrame;
#end
#end
}

}

//For instant transition to start state without shaking
Expand Down Expand Up @@ -621,6 +614,8 @@ class SimpleActuator<T, U> extends GenericActuator<T> {
#else
var currentTime = getTime ();
#end

time = currentTime;

var actuator:SimpleActuator<Dynamic, Dynamic>;

Expand Down