Use formatter for all Haxe code
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package haxe;
|
||||
|
||||
#if !lime_cffi
|
||||
|
||||
|
||||
// Original haxe.Timer class
|
||||
|
||||
/*
|
||||
* Copyright (C)2005-2018 Haxe Foundation
|
||||
*
|
||||
@@ -40,15 +38,15 @@ package haxe;
|
||||
It is also possible to extend this class and override its run() method in
|
||||
the child class.
|
||||
**/
|
||||
class Timer {
|
||||
|
||||
class Timer
|
||||
{
|
||||
#if (flash || js)
|
||||
private var id : Null<Int>;
|
||||
private var id:Null<Int>;
|
||||
#elseif java
|
||||
private var timer : java.util.Timer;
|
||||
private var task : java.util.TimerTask;
|
||||
private var timer:java.util.Timer;
|
||||
private var task:java.util.TimerTask;
|
||||
#elseif (haxe_ver >= "3.4.0")
|
||||
private var event : MainLoop.MainEvent;
|
||||
private var event:MainLoop.MainEvent;
|
||||
#end
|
||||
|
||||
/**
|
||||
@@ -62,23 +60,28 @@ class Timer {
|
||||
|
||||
The accuracy of this may be platform-dependent.
|
||||
**/
|
||||
public function new( time_ms : Int ){
|
||||
public function new(time_ms:Int)
|
||||
{
|
||||
#if flash
|
||||
var me = this;
|
||||
id = untyped __global__["flash.utils.setInterval"](function() { me.run(); },time_ms);
|
||||
var me = this;
|
||||
id = untyped __global__["flash.utils.setInterval"](function()
|
||||
{
|
||||
me.run();
|
||||
}, time_ms);
|
||||
#elseif js
|
||||
var me = this;
|
||||
id = untyped setInterval(function() me.run(),time_ms);
|
||||
var me = this;
|
||||
id = untyped setInterval(function() me.run(), time_ms);
|
||||
#elseif java
|
||||
timer = new java.util.Timer();
|
||||
timer.scheduleAtFixedRate(task = new TimerTask(this), haxe.Int64.ofInt(time_ms), haxe.Int64.ofInt(time_ms));
|
||||
timer = new java.util.Timer();
|
||||
timer.scheduleAtFixedRate(task = new TimerTask(this), haxe.Int64.ofInt(time_ms), haxe.Int64.ofInt(time_ms));
|
||||
#elseif (haxe_ver >= "3.4.0")
|
||||
var dt = time_ms / 1000;
|
||||
event = MainLoop.add(function() {
|
||||
@:privateAccess event.nextRun += dt;
|
||||
run();
|
||||
});
|
||||
event.delay(dt);
|
||||
var dt = time_ms / 1000;
|
||||
event = MainLoop.add(function()
|
||||
{
|
||||
@:privateAccess event.nextRun += dt;
|
||||
run();
|
||||
});
|
||||
event.delay(dt);
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -90,27 +93,29 @@ class Timer {
|
||||
|
||||
It is not possible to restart `this` Timer once stopped.
|
||||
**/
|
||||
public function stop() {
|
||||
public function stop()
|
||||
{
|
||||
#if (flash || js)
|
||||
if( id == null )
|
||||
return;
|
||||
#if flash
|
||||
untyped __global__["flash.utils.clearInterval"](id);
|
||||
#elseif js
|
||||
untyped clearInterval(id);
|
||||
#end
|
||||
id = null;
|
||||
if (id == null) return;
|
||||
#if flash
|
||||
untyped __global__["flash.utils.clearInterval"](id);
|
||||
#elseif js
|
||||
untyped clearInterval(id);
|
||||
#end
|
||||
id = null;
|
||||
#elseif java
|
||||
if(timer != null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
task = null;
|
||||
if (timer != null)
|
||||
{
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
task = null;
|
||||
#elseif (haxe_ver >= "3.4.0")
|
||||
if( event != null ) {
|
||||
event.stop();
|
||||
event = null;
|
||||
}
|
||||
if (event != null)
|
||||
{
|
||||
event.stop();
|
||||
event = null;
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -125,9 +130,7 @@ class Timer {
|
||||
Once bound, it can still be rebound to different functions until `this`
|
||||
Timer is stopped through a call to `this.stop`.
|
||||
**/
|
||||
public dynamic function run() {
|
||||
|
||||
}
|
||||
public dynamic function run() {}
|
||||
|
||||
/**
|
||||
Invokes `f` after `time_ms` milliseconds.
|
||||
@@ -138,9 +141,11 @@ class Timer {
|
||||
|
||||
If `f` is null, the result is unspecified.
|
||||
**/
|
||||
public static function delay( f : Void -> Void, time_ms : Int ) {
|
||||
public static function delay(f:Void->Void, time_ms:Int)
|
||||
{
|
||||
var t = new haxe.Timer(time_ms);
|
||||
t.run = function() {
|
||||
t.run = function()
|
||||
{
|
||||
t.stop();
|
||||
f();
|
||||
};
|
||||
@@ -158,7 +163,8 @@ class Timer {
|
||||
|
||||
If `f` is null, the result is unspecified.
|
||||
**/
|
||||
public static function measure<T>( f : Void -> T, ?pos : PosInfos ) : T {
|
||||
public static function measure<T>(f:Void->T, ?pos:PosInfos):T
|
||||
{
|
||||
var t0 = stamp();
|
||||
var r = f();
|
||||
Log.trace((stamp() - t0) + "s", pos);
|
||||
@@ -171,152 +177,121 @@ class Timer {
|
||||
The value itself might differ depending on platforms, only differences
|
||||
between two values make sense.
|
||||
**/
|
||||
public static inline function stamp() : Float {
|
||||
public static inline function stamp():Float
|
||||
{
|
||||
#if flash
|
||||
return flash.Lib.getTimer() / 1000;
|
||||
return flash.Lib.getTimer() / 1000;
|
||||
#elseif (neko || php)
|
||||
return Sys.time();
|
||||
return Sys.time();
|
||||
#elseif js
|
||||
return Date.now().getTime() / 1000;
|
||||
return Date.now().getTime() / 1000;
|
||||
#elseif cpp
|
||||
return untyped __global__.__time_stamp();
|
||||
return untyped __global__.__time_stamp();
|
||||
#elseif python
|
||||
return Sys.cpuTime();
|
||||
return Sys.cpuTime();
|
||||
#elseif sys
|
||||
return Sys.time();
|
||||
|
||||
return Sys.time();
|
||||
#else
|
||||
return 0;
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if java
|
||||
@:nativeGen
|
||||
private class TimerTask extends java.util.TimerTask {
|
||||
private class TimerTask extends java.util.TimerTask
|
||||
{
|
||||
var timer:Timer;
|
||||
public function new(timer:Timer):Void {
|
||||
|
||||
public function new(timer:Timer):Void
|
||||
{
|
||||
super();
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
@:overload override public function run():Void {
|
||||
@:overload override public function run():Void
|
||||
{
|
||||
timer.run();
|
||||
}
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
import lime.system.System;
|
||||
|
||||
|
||||
class Timer {
|
||||
|
||||
|
||||
private static var sRunningTimers:Array <Timer> = [];
|
||||
class Timer
|
||||
{
|
||||
private static var sRunningTimers:Array<Timer> = [];
|
||||
|
||||
private var mTime:Float;
|
||||
private var mFireAt:Float;
|
||||
private var mRunning:Bool;
|
||||
|
||||
|
||||
public function new (time:Float) {
|
||||
|
||||
public function new(time:Float)
|
||||
{
|
||||
mTime = time;
|
||||
sRunningTimers.push (this);
|
||||
mFireAt = getMS () + mTime;
|
||||
sRunningTimers.push(this);
|
||||
mFireAt = getMS() + mTime;
|
||||
mRunning = true;
|
||||
|
||||
}
|
||||
|
||||
public static function delay(f:Void->Void, time:Int)
|
||||
{
|
||||
var t = new Timer(time);
|
||||
|
||||
public static function delay (f:Void -> Void, time:Int) {
|
||||
|
||||
var t = new Timer (time);
|
||||
|
||||
t.run = function () {
|
||||
|
||||
t.stop ();
|
||||
f ();
|
||||
|
||||
t.run = function()
|
||||
{
|
||||
t.stop();
|
||||
f();
|
||||
};
|
||||
|
||||
return t;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static function getMS ():Float {
|
||||
|
||||
return System.getTimer ();
|
||||
|
||||
private static function getMS():Float
|
||||
{
|
||||
return System.getTimer();
|
||||
}
|
||||
|
||||
|
||||
public static function measure<T> (f:Void -> T, ?pos:PosInfos):T {
|
||||
|
||||
var t0 = stamp ();
|
||||
var r = f ();
|
||||
Log.trace ((stamp () - t0) + "s", pos);
|
||||
public static function measure<T>(f:Void->T, ?pos:PosInfos):T
|
||||
{
|
||||
var t0 = stamp();
|
||||
var r = f();
|
||||
Log.trace((stamp() - t0) + "s", pos);
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
dynamic public function run() {}
|
||||
|
||||
dynamic public function run () {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static inline function stamp ():Float {
|
||||
|
||||
var timer = System.getTimer ();
|
||||
public static inline function stamp():Float
|
||||
{
|
||||
var timer = System.getTimer();
|
||||
return (timer > 0 ? timer / 1000 : 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function stop ():Void {
|
||||
|
||||
if (mRunning) {
|
||||
|
||||
public function stop():Void
|
||||
{
|
||||
if (mRunning)
|
||||
{
|
||||
mRunning = false;
|
||||
|
||||
for (i in 0...sRunningTimers.length) {
|
||||
|
||||
if (sRunningTimers[i] == this) {
|
||||
|
||||
for (i in 0...sRunningTimers.length)
|
||||
{
|
||||
if (sRunningTimers[i] == this)
|
||||
{
|
||||
sRunningTimers[i] = null;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@:noCompletion private function __check (inTime:Float) {
|
||||
|
||||
if (inTime >= mFireAt) {
|
||||
|
||||
@:noCompletion private function __check(inTime:Float)
|
||||
{
|
||||
if (inTime >= mFireAt)
|
||||
{
|
||||
mFireAt += mTime;
|
||||
run ();
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#end
|
||||
#end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user