瀏覽代碼

added timeout/sentinel control cross platform support

Nicolas Cannasse 8 年之前
父節點
當前提交
5567405ab0
共有 4 個文件被更改,包括 56 次插入0 次删除
  1. 7 0
      hxd/System.flash.hx
  2. 30 0
      hxd/System.hl.hx
  3. 13 0
      hxd/System.hx
  4. 6 0
      hxd/System.js.hx

+ 7 - 0
hxd/System.flash.hx

@@ -23,6 +23,10 @@ class System {
 	public static var platform(get, never) : Platform;
 	public static var screenDPI(get,never) : Float;
 	public static var setCursor = setNativeCursor;
+	public static var allowTimeout(get, set) : Bool;
+
+	public static function timeoutTick() : Void {
+	}
 
 	static var loopFunc : Void -> Void;
 
@@ -162,5 +166,8 @@ class System {
 		return Std.int(flash.system.Capabilities.screenDPI);
 	}
 
+	static function get_allowTimeout() return true;
+	static function set_allowTimeout(b) return true; // can't be disabled
+
 }
 

+ 30 - 0
hxd/System.hl.hx

@@ -30,9 +30,11 @@ class System {
 	public static var platform(get, never) : Platform;
 	public static var screenDPI(get,never) : Float;
 	public static var setCursor = setNativeCursor;
+	public static var allowTimeout(get, set) : Bool;
 
 	static var loopFunc : Void -> Void;
 
+
 	// -- HL
 	static var currentNativeCursor : hxd.Cursor = Default;
 	static var cursorVisible = true;
@@ -201,4 +203,32 @@ class System {
 
 	static function get_screenDPI() : Int return 72; // TODO
 
+	public static function timeoutTick() : Void @:privateAccess {
+		#if hldx
+		dx.Loop.sentinel.tick();
+		#elseif hlsdl
+		sdl.Sdl.sentinel.tick();
+		#end
+	}
+
+	static function get_allowTimeout() @:privateAccess {
+		#if hldx
+		return dx.Loop.sentinel.pause;
+		#elseif hlsdl
+		return sdl.Sdl.sentinel.pause;
+		#else
+		return false;
+		#end
+	}
+
+	static function set_allowTimeout(b) @:privateAccess {
+		#if hldx
+		return dx.Loop.sentinel.pause = b;
+		#elseif hlsdl
+		return sdl.Sdl.sentinel.pause = b;
+		#else
+		return false;
+		#end
+	}
+
 }

+ 13 - 0
hxd/System.hx

@@ -24,6 +24,17 @@ class System {
 	public static var screenDPI(get,never) : Float;
 	public static var setCursor = setNativeCursor;
 
+	/**
+		Can be used to temporarly disable infinite loop check
+	**/
+	public static var allowTimeout(get, set) : Bool;
+
+	/**
+		If you have a time consuming calculus that might trigger a timeout, you can either disable timeouts with [allowTimeout] or call timeoutTick() frequently.
+	**/
+	public static function timeoutTick() : Void {
+	}
+
 	static var loopFunc : Void -> Void;
 
 	public static function getCurrentLoop() : Void -> Void {
@@ -62,5 +73,7 @@ class System {
 	static function get_lang() : String return "en";
 	static function get_platform() : Platform return PC;
 	static function get_screenDPI() : Int return 72;
+	static function get_allowTimeout() return false;
+	static function set_allowTimeout(b) return false;
 
 }

+ 6 - 0
hxd/System.js.hx

@@ -23,7 +23,11 @@ class System {
 	public static var platform(get, never) : Platform;
 	public static var screenDPI(get,never) : Float;
 	public static var setCursor = setNativeCursor;
+	public static var allowTimeout(get, set) : Bool;
 
+	public static function timeoutTick() : Void {
+	}
+	
 	static var loopFunc : Void -> Void;
 
 	// JS
@@ -90,5 +94,7 @@ class System {
 	static function get_lang() : String return "en";
 	static function get_platform() : Platform return PC;
 	static function get_screenDPI() : Int return 72;
+	static function get_allowTimeout() return false;
+	static function set_allowTimeout(b) return false;
 
 }