|
@@ -33,7 +33,11 @@ class System {
|
|
public static var allowTimeout(get, set) : Bool;
|
|
public static var allowTimeout(get, set) : Bool;
|
|
|
|
|
|
static var loopFunc : Void -> Void;
|
|
static var loopFunc : Void -> Void;
|
|
|
|
+ static var dismissErrors = false;
|
|
|
|
|
|
|
|
+ #if !usesys
|
|
|
|
+ static var sentinel : hl.UI.Sentinel;
|
|
|
|
+ #end
|
|
|
|
|
|
// -- HL
|
|
// -- HL
|
|
static var currentNativeCursor : hxd.Cursor = Default;
|
|
static var currentNativeCursor : hxd.Cursor = Default;
|
|
@@ -47,20 +51,40 @@ class System {
|
|
loopFunc = f;
|
|
loopFunc = f;
|
|
}
|
|
}
|
|
|
|
|
|
- static function mainLoop() : Void {
|
|
|
|
|
|
+ static function mainLoop() : Bool {
|
|
|
|
+ // process events
|
|
|
|
+ #if hldx
|
|
|
|
+ if( !dx.Loop.processEvents(@:privateAccess hxd.Stage.inst.onEvent) )
|
|
|
|
+ return false;
|
|
|
|
+ #elseif hlsdl
|
|
|
|
+ if( !sdl.Sdl.processEvents(@:privateAccess hxd.Stage.inst.onEvent) )
|
|
|
|
+ return false;
|
|
|
|
+ #elseif sys
|
|
|
|
+ if( !haxe.System.emitEvents(@:privateAccess hxd.Stage.inst.event) )
|
|
|
|
+ return false;
|
|
|
|
+ #end
|
|
|
|
+
|
|
|
|
+ // loop
|
|
|
|
+ timeoutTick();
|
|
if( loopFunc != null ) loopFunc();
|
|
if( loopFunc != null ) loopFunc();
|
|
|
|
+
|
|
|
|
+ // present
|
|
#if usesys
|
|
#if usesys
|
|
haxe.System.present();
|
|
haxe.System.present();
|
|
#elseif hlsdl
|
|
#elseif hlsdl
|
|
@:privateAccess hxd.Stage.inst.window.present();
|
|
@:privateAccess hxd.Stage.inst.window.present();
|
|
#end
|
|
#end
|
|
|
|
+
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
public static function start( init : Void -> Void ) : Void {
|
|
public static function start( init : Void -> Void ) : Void {
|
|
#if usesys
|
|
#if usesys
|
|
|
|
+
|
|
if( !haxe.System.init() ) return;
|
|
if( !haxe.System.init() ) return;
|
|
@:privateAccess Stage.inst = new Stage("", haxe.System.width, haxe.System.height);
|
|
@:privateAccess Stage.inst = new Stage("", haxe.System.width, haxe.System.height);
|
|
init();
|
|
init();
|
|
|
|
+
|
|
#else
|
|
#else
|
|
var width = 800;
|
|
var width = 800;
|
|
var height = 600;
|
|
var height = 600;
|
|
@@ -73,24 +97,67 @@ class System {
|
|
width = Std.parseInt(p[0]);
|
|
width = Std.parseInt(p[0]);
|
|
height = Std.parseInt(p[1]);
|
|
height = Std.parseInt(p[1]);
|
|
}
|
|
}
|
|
|
|
+ timeoutTick();
|
|
#if hlsdl
|
|
#if hlsdl
|
|
- sdl.Sdl.tick();
|
|
|
|
sdl.Sdl.init();
|
|
sdl.Sdl.init();
|
|
@:privateAccess Stage.initChars();
|
|
@:privateAccess Stage.initChars();
|
|
@:privateAccess Stage.inst = new Stage(title, width, height);
|
|
@:privateAccess Stage.inst = new Stage(title, width, height);
|
|
init();
|
|
init();
|
|
- sdl.Sdl.defaultEventHandler = @:privateAccess Stage.inst.onEvent;
|
|
|
|
#elseif hldx
|
|
#elseif hldx
|
|
@:privateAccess Stage.inst = new Stage(title, width, height);
|
|
@:privateAccess Stage.inst = new Stage(title, width, height);
|
|
init();
|
|
init();
|
|
- dx.Loop.defaultEventHandler = @:privateAccess Stage.inst.onEvent;
|
|
|
|
#else
|
|
#else
|
|
@:privateAccess Stage.inst = new Stage(title, width, height);
|
|
@:privateAccess Stage.inst = new Stage(title, width, height);
|
|
init();
|
|
init();
|
|
#end
|
|
#end
|
|
|
|
+ #end
|
|
|
|
+
|
|
|
|
+ timeoutTick();
|
|
|
|
+ haxe.Timer.delay(runMainLoop, 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static function runMainLoop() {
|
|
|
|
+ while( true ) {
|
|
|
|
+ try {
|
|
|
|
+ @:privateAccess haxe.MainLoop.tick();
|
|
|
|
+ if( !mainLoop() ) break;
|
|
|
|
+ } catch( e : Dynamic ) {
|
|
|
|
+ reportError(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Sys.exit(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public dynamic static function reportError( e : Dynamic ) {
|
|
|
|
+ var stack = haxe.CallStack.toString(haxe.CallStack.exceptionStack());
|
|
|
|
+ var err = try Std.string(e) catch( _ : Dynamic ) "????";
|
|
|
|
+ Sys.println(err + stack);
|
|
|
|
+ #if !usesys
|
|
|
|
+ if( dismissErrors )
|
|
|
|
+ return;
|
|
|
|
|
|
|
|
+ var f = new hl.UI.WinLog("Uncaught Exception", 500, 400);
|
|
|
|
+ f.setTextContent(err+"\n"+stack);
|
|
|
|
+ var but = new hl.UI.Button(f, "Continue");
|
|
|
|
+ but.onClick = function() {
|
|
|
|
+ hl.UI.stopLoop();
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ var but = new hl.UI.Button(f, "Dismiss all");
|
|
|
|
+ but.onClick = function() {
|
|
|
|
+ dismissErrors = true;
|
|
|
|
+ hl.UI.stopLoop();
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ var but = new hl.UI.Button(f, "Exit");
|
|
|
|
+ but.onClick = function() {
|
|
|
|
+ Sys.exit(0);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ while( hl.UI.loop(true) != Quit )
|
|
|
|
+ timeoutTick();
|
|
|
|
+ f.destroy();
|
|
#end
|
|
#end
|
|
- haxe.MainLoop.add(mainLoop);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public static function setNativeCursor( c : hxd.Cursor ) : Void {
|
|
public static function setNativeCursor( c : hxd.Cursor ) : Void {
|
|
@@ -209,30 +276,31 @@ class System {
|
|
static function get_screenDPI() : Int return 72; // TODO
|
|
static function get_screenDPI() : Int return 72; // TODO
|
|
|
|
|
|
public static function timeoutTick() : Void @:privateAccess {
|
|
public static function timeoutTick() : Void @:privateAccess {
|
|
- #if hldx
|
|
|
|
- dx.Loop.sentinel.tick();
|
|
|
|
- #elseif hlsdl
|
|
|
|
- sdl.Sdl.sentinel.tick();
|
|
|
|
|
|
+ #if !usesys
|
|
|
|
+ sentinel.tick();
|
|
#end
|
|
#end
|
|
}
|
|
}
|
|
|
|
|
|
static function get_allowTimeout() @:privateAccess {
|
|
static function get_allowTimeout() @:privateAccess {
|
|
- #if hldx
|
|
|
|
- return !dx.Loop.sentinel.pause;
|
|
|
|
- #elseif hlsdl
|
|
|
|
- return !sdl.Sdl.sentinel.pause;
|
|
|
|
- #else
|
|
|
|
|
|
+ #if usesys
|
|
return false;
|
|
return false;
|
|
|
|
+ #else
|
|
|
|
+ return !sentinel.pause;
|
|
#end
|
|
#end
|
|
}
|
|
}
|
|
|
|
|
|
static function set_allowTimeout(b) @:privateAccess {
|
|
static function set_allowTimeout(b) @:privateAccess {
|
|
- #if hldx
|
|
|
|
- return dx.Loop.sentinel.pause = !b;
|
|
|
|
- #elseif hlsdl
|
|
|
|
- return sdl.Sdl.sentinel.pause = !b;
|
|
|
|
- #else
|
|
|
|
|
|
+ #if usesys
|
|
return false;
|
|
return false;
|
|
|
|
+ #else
|
|
|
|
+ return sentinel.pause = !b;
|
|
|
|
+ #end
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static function __init__() {
|
|
|
|
+ #if !usesys
|
|
|
|
+ hl.Api.setErrorHandler(function(e) reportError(e)); // initialization error
|
|
|
|
+ sentinel = new hl.UI.Sentinel(30, function() throw "Program timeout (infinite loop?)");
|
|
#end
|
|
#end
|
|
}
|
|
}
|
|
|
|
|