Fast addition of exit event
This commit is contained in:
@@ -95,7 +95,8 @@ class NativeApplication {
|
|||||||
|
|
||||||
var result = lime_application_quit (handle);
|
var result = lime_application_quit (handle);
|
||||||
__cleanup ();
|
__cleanup ();
|
||||||
Sys.exit (result);
|
|
||||||
|
System.exit (result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +111,9 @@ class NativeApplication {
|
|||||||
|
|
||||||
var result = lime_application_exec (handle);
|
var result = lime_application_exec (handle);
|
||||||
__cleanup ();
|
__cleanup ();
|
||||||
|
|
||||||
|
parent.onExit.dispatch (result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ class Application extends Module {
|
|||||||
public var frameRate (get, set):Float;
|
public var frameRate (get, set):Float;
|
||||||
public var modules (default, null):Array<IModule>;
|
public var modules (default, null):Array<IModule>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit events are dispatched when the application is closing
|
||||||
|
*/
|
||||||
|
public var onExit = new Event<Int->Void> ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update events are dispatched each frame (usually just before rendering)
|
* Update events are dispatched each frame (usually just before rendering)
|
||||||
*/
|
*/
|
||||||
@@ -55,6 +60,7 @@ class Application extends Module {
|
|||||||
windows = new Array ();
|
windows = new Array ();
|
||||||
backend = new ApplicationBackend (this);
|
backend = new ApplicationBackend (this);
|
||||||
|
|
||||||
|
onExit.add (onApplicationExit);
|
||||||
onUpdate.add (update);
|
onUpdate.add (update);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -181,6 +187,17 @@ class Application extends Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override function onApplicationExit (code:Int):Void {
|
||||||
|
|
||||||
|
for (module in modules) {
|
||||||
|
|
||||||
|
module.onApplicationExit (code);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override function onGamepadAxisMove (gamepad:Gamepad, axis:GamepadAxis, value:Float):Void {
|
public override function onGamepadAxisMove (gamepad:Gamepad, axis:GamepadAxis, value:Float):Void {
|
||||||
|
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ interface IModule {
|
|||||||
public function init (context:RenderContext):Void;
|
public function init (context:RenderContext):Void;
|
||||||
|
|
||||||
|
|
||||||
|
public function onApplicationExit (code:Int):Void;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a gamepad axis move event is fired
|
* Called when a gamepad axis move event is fired
|
||||||
* @param gamepad The current gamepad
|
* @param gamepad The current gamepad
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ class Module implements IModule {
|
|||||||
public function init (context:RenderContext):Void { }
|
public function init (context:RenderContext):Void { }
|
||||||
|
|
||||||
|
|
||||||
|
public function onApplicationExit (code:Int):Void { }
|
||||||
|
|
||||||
|
|
||||||
public function onGamepadAxisMove (gamepad:Gamepad, axis:GamepadAxis, value:Float):Void { }
|
public function onGamepadAxisMove (gamepad:Gamepad, axis:GamepadAxis, value:Float):Void { }
|
||||||
public function onGamepadButtonDown (gamepad:Gamepad, button:GamepadButton):Void { }
|
public function onGamepadButtonDown (gamepad:Gamepad, button:GamepadButton):Void { }
|
||||||
public function onGamepadButtonUp (gamepad:Gamepad, button:GamepadButton):Void { }
|
public function onGamepadButtonUp (gamepad:Gamepad, button:GamepadButton):Void { }
|
||||||
|
|||||||
@@ -118,7 +118,15 @@ class System {
|
|||||||
public static function exit (code:Int):Void {
|
public static function exit (code:Int):Void {
|
||||||
|
|
||||||
#if sys
|
#if sys
|
||||||
// TODO: Clean shutdown?
|
#if !macro
|
||||||
|
if (Application.current != null) {
|
||||||
|
|
||||||
|
// TODO: Clean exit?
|
||||||
|
|
||||||
|
Application.current.onExit.dispatch (code);
|
||||||
|
|
||||||
|
}
|
||||||
|
#end
|
||||||
Sys.exit (code);
|
Sys.exit (code);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user