Fast addition of exit event

This commit is contained in:
Joshua Granick
2015-08-13 17:13:31 -07:00
parent de217c291c
commit e4179d1474
5 changed files with 37 additions and 2 deletions

View File

@@ -95,7 +95,8 @@ class NativeApplication {
var result = lime_application_quit (handle);
__cleanup ();
Sys.exit (result);
System.exit (result);
}
@@ -110,6 +111,9 @@ class NativeApplication {
var result = lime_application_exec (handle);
__cleanup ();
parent.onExit.dispatch (result);
return result;
#else

View File

@@ -26,6 +26,11 @@ class Application extends Module {
public var frameRate (get, set):Float;
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)
*/
@@ -55,6 +60,7 @@ class Application extends Module {
windows = new Array ();
backend = new ApplicationBackend (this);
onExit.add (onApplicationExit);
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 {
for (module in modules) {

View File

@@ -21,6 +21,9 @@ interface IModule {
public function init (context:RenderContext):Void;
public function onApplicationExit (code:Int):Void;
/**
* Called when a gamepad axis move event is fired
* @param gamepad The current gamepad

View File

@@ -28,6 +28,9 @@ class Module implements IModule {
public function init (context:RenderContext):Void { }
public function onApplicationExit (code:Int):Void { }
public function onGamepadAxisMove (gamepad:Gamepad, axis:GamepadAxis, value:Float):Void { }
public function onGamepadButtonDown (gamepad:Gamepad, button:GamepadButton):Void { }
public function onGamepadButtonUp (gamepad:Gamepad, button:GamepadButton):Void { }

View File

@@ -118,7 +118,15 @@ class System {
public static function exit (code:Int):Void {
#if sys
// TODO: Clean shutdown?
#if !macro
if (Application.current != null) {
// TODO: Clean exit?
Application.current.onExit.dispatch (code);
}
#end
Sys.exit (code);
#end