Wrapper; Input; fixing neko mouse position being completely wrong. Problem due to stage scale mode not being set, meaning mStageScale was scaling the input event x/y according to that, blowing it up.

Wrapper; Debug; general cleanup of _debug prints, these are now limited to debug builds so they don't allocate strings constantly or anything like that in release builds.
Wrapper; Audio; making sure audio is shutdown accordingly so it doesn't try update in the background
Wrapper; Lime; More cleanup, strict typing the lime config values as it hasn't fluxed in a long time, and is better typed.
Wrapper; template; updating to use typed lime config and stricter typing on items passed in
This commit is contained in:
underscorediscovery
2014-01-28 03:00:39 -03:30
parent 69e74babc9
commit 935df78fbf
6 changed files with 137 additions and 67 deletions

View File

@@ -45,11 +45,13 @@ class AudioHandler {
sounds = new Map();
#if (!audio_thread_disabled && lime_native)
audio_state = new AudioThreadState ();
audio_thread_running = true;
audio_thread_is_idle = false;
audio_state.main_thread = Thread.current ();
audio_state.audio_thread = Thread.create( audio_thread_handler );
#end //#(!audio_thread_disabled && lime_native)
#if lime_html5
@@ -70,6 +72,12 @@ class AudioHandler {
} //startup
@:noCompletion public function shutdown() {
audio_thread_running = false;
}
@:noCompletion public function update() {
#if lime_native
@@ -132,11 +140,16 @@ class AudioHandler {
#if (!audio_thread_disabled && lime_native)
public function audio_thread_handler() {
#if debug
lib._debug("lime: Audio background thread started.");
#end //debug
var thread_message : Dynamic;
while (audio_thread_running) {
var thread_message:Dynamic = Thread.readMessage (false);
thread_message = Thread.readMessage (false);
if (thread_message == audio_message_check_complete) {
audio_state.check();
}
@@ -152,6 +165,10 @@ class AudioHandler {
audio_thread_running = false;
audio_thread_is_idle = true;
#if debug
lib._debug("lime: Audio background thread shutdown.");
#end //debug
}

View File

@@ -53,7 +53,9 @@ class InputHandler {
@:noCompletion public function startup() {
lib._debug(':: lime :: \t InputHandler Initialized.');
#if debug
lib._debug(':: lime :: \t InputHandler Initialized.');
#end //debug
touches_active = new Map<Int, Dynamic>();
keys_down = new Map();
@@ -68,7 +70,9 @@ class InputHandler {
@:noCompletion public function shutdown() {
lib._debug(':: lime :: \t InputHandler shut down.');
#if debug
lib._debug(':: lime :: \t InputHandler shut down.');
#end //debug
} //shutdown

View File

@@ -10,12 +10,30 @@ import lime.WindowHandler;
import haxe.Timer;
typedef LimeConfig = {
? host : Dynamic,
? fullscreen : Bool,
? resizable : Bool,
? borderless : Bool,
? antialiasing : Int,
? stencil_buffer : Bool,
? depth_buffer : Bool,
? vsync : Bool,
? multitouch_supported : Bool,
? multitouch : Bool,
? fps : Int,
? width : Int,
? height : Int,
? title : String,
? orientation : String
}
class Lime {
//The host class of the application
public var host : Dynamic;
//the config passed to us on creation
public var config : Dynamic;
public var config : LimeConfig;
//The handlers for the messages from lime
public var audio : AudioHandler;
@@ -43,7 +61,9 @@ class Lime {
frame_rate = value;
frame_period = (frame_rate <= 0 ? frame_rate : 1.0 / frame_rate);
#if debug
_debug(':: lime :: frame rate set to ' + frame_rate);
#end
return value;
@@ -59,21 +79,19 @@ class Lime {
public function new() {} //new
//Initialize
public function init( _main_, _config : Dynamic ) {
public function init( _main_, _config : LimeConfig ) {
config = _config;
host = _main_;
_debug(':: lime :: initializing - ');
_debug(':: lime :: Creating window at ' + config.width + 'x' + config.height);
#if debug
_debug(':: lime :: initializing - ');
_debug(':: lime :: Creating window at ' + config.width + 'x' + config.height);
#end
//default to 60 fps
if( config.fps != null ) {
if(Std.is(config.fps, String)) {
frame_rate = Std.parseFloat( config.fps );
} else {
frame_rate = config.fps;
}
frame_rate = config.fps;
} else { //config.fps
frame_rate = 60;
}
@@ -121,7 +139,9 @@ class Lime {
//Since we are done...
window.set_active(true);
_debug(':: lime :: Ready.');
#if debug
_debug(':: lime :: Ready.');
#end
//Tell the host application we are ready
if(host.ready != null) {
@@ -147,7 +167,7 @@ class Lime {
window.set_active(false);
//Order is imporant here too
audio.shutdown();
render.shutdown();
input.shutdown();
window.shutdown();
@@ -155,7 +175,9 @@ class Lime {
//Flag it
has_shutdown = true;
_debug(':: lime :: Goodbye.');
#if debug
_debug(':: lime :: Goodbye.');
#end
}
public function cleanup() {
@@ -169,9 +191,11 @@ class Lime {
var result = 0.0;
var event_type:Int = Std.int(Reflect.field(_event, "type"));
if(event_type != SystemEvents.poll) {
_debug('event_from_stage : ' + event_type, true, true);
}
#if debug
if(event_type != SystemEvents.poll) {
_debug('event_from_stage : ' + event_type, true, true);
}
#end
switch(event_type) {
@@ -287,23 +311,30 @@ class Lime {
}
return __updateNextWake();
__updateNextWake();
return null;
} //on_lime_event
//Handle system/window messages
public function on_syswm(ev:Dynamic) {
_debug('syswm event');
#if debug
_debug('syswm event');
#end
} //on_syswm
public function on_change(ev:Dynamic) {
_debug('change event');
#if debug
_debug('change event');
#end
} //on_syswm
public function on_update(_event) {
_debug('on_update ' + Timer.stamp(), true, false);
#if debug
_debug('on_update ' + Timer.stamp(), true, false);
#end //debug
#if lime_native
Timer.__checkTimers();
@@ -321,7 +352,7 @@ class Lime {
//process any audio
// :todo: this might want to be outside the loop like before
audio.update();
audio.update();
//process any input state
input.update();
@@ -392,12 +423,12 @@ class Lime {
return nextWake;
#else
#else //lime_native
return null;
#end
#end //!lime_native
}
} //__updateNextWake
@:noCompletion private function __nextFrameDue( _otherTimers:Float ) {
@@ -424,31 +455,37 @@ class Lime {
//Noisy stuff
#if lime_native
private static var lime_stage_request_render = Libs.load("lime","lime_stage_request_render", 0);
private static var lime_stage_set_next_wake = Libs.load("lime","lime_stage_set_next_wake", 2);
#end //lime_native
//temporary debugging with verbosity options
public var log : Bool = false;
public var verbose : Bool = false;
public var more_verbose : Bool = false;
public function _debug(value:Dynamic, _verbose:Bool = false, _more_verbose:Bool = false) {
if(log) {
if(verbose && _verbose && !_more_verbose) {
trace(value);
} else
if(more_verbose && _more_verbose) {
trace(value);
} else {
if(!_verbose && !_more_verbose) {
#if debug
public var log : Bool = false;
public var verbose : Bool = false;
public var more_verbose : Bool = false;
public function _debug(value:Dynamic, _verbose:Bool = false, _more_verbose:Bool = false) {
if(log) {
if(verbose && _verbose && !_more_verbose) {
trace(value);
}
} //elses
} //log
} //_debug
} else
if(more_verbose && _more_verbose) {
trace(value);
} else {
if(!_verbose && !_more_verbose) {
trace(value);
}
} //elses
} //log
} //_debug
#if lime_native
private static var lime_stage_request_render = Libs.load("lime","lime_stage_request_render", 0);
private static var lime_stage_set_next_wake = Libs.load("lime","lime_stage_set_next_wake", 2);
#end
}
#end //debug
} //Lime

View File

@@ -114,12 +114,16 @@ class RenderHandler {
#end //lime_html5
//Done.
lib._debug(':: lime :: \t RenderHandler Initialized.');
#if debug
lib._debug(':: lime :: \t RenderHandler Initialized.');
#end //debug
}
public function shutdown() {
lib._debug(':: lime :: \t RenderHandler shut down.');
#if debug
lib._debug(':: lime :: \t RenderHandler shut down.');
#end //debug
}
public function on_resize(_event:Dynamic) {

View File

@@ -21,7 +21,9 @@ class WindowHandler {
public function startup() {
lib._debug(':: lime :: \t WindowHandler Initializing...');
#if debug
lib._debug(':: lime :: \t WindowHandler Initializing...');
#end //debug
#if lime_native
@@ -76,7 +78,9 @@ class WindowHandler {
lime_close();
#end
lib._debug(':: lime :: \t WindowHandler shut down.');
#if debug
lib._debug(':: lime :: \t WindowHandler shut down.');
#end //debug
}
public function ready() {
@@ -84,16 +88,17 @@ class WindowHandler {
#if lime_native
//Fetch the stage handle
lib.view_handle = lime_get_frame_stage( lib.window_handle );
//Make sure nothing silly is happening to the stage scale
lime_stage_set_scale_mode(lib.view_handle, 1);
//Make sure that our configs are up to date with the actual screen resolution
//not just the specified resolution in the project file
lib.config.width = lime_stage_get_stage_width(lib.view_handle);
lib.config.height = lime_stage_get_stage_height(lib.view_handle);
//move the window based on xml flags
if(lib.config.x != null && lib.config.y != null) {
set_window_position(lib.config.x, lib.config.y);
}
// if(lib.config.x != null && lib.config.y != null) {
// set_window_position(lib.config.x, lib.config.y);
// }
//Update the touch support
lib.config.multitouch_supported = lime_stage_get_multitouch_supported(lib.view_handle);
@@ -103,7 +108,6 @@ class WindowHandler {
#end //lime_native
}
public function post_ready() {
@@ -119,7 +123,9 @@ class WindowHandler {
lib.render.render();
#end
lib._debug(':: lime :: \t WindowHandler Initialized.');
#if debug
lib._debug(':: lime :: \t WindowHandler Initialized.');
#end //debug
}
//Invalidate the window (forcing a redraw on next update)
@@ -312,7 +318,7 @@ class WindowHandler {
//lime functions
#if lime_native
private static var lime_stage_set_scale_mode = Libs.load ("lime", "lime_stage_set_scale_mode", 2);
private static var lime_stage_get_stage_width = Libs.load("lime","lime_stage_get_stage_width", 1);
private static var lime_stage_get_stage_height = Libs.load("lime","lime_stage_get_stage_height", 1);
private static var lime_set_stage_handler = Libs.load("lime","lime_set_stage_handler", 4);

View File

@@ -10,21 +10,23 @@ class ApplicationMain {
public static function main () {
//Create the runtime
_lime = new Lime();
//Create the game class, give it the runtime
//Create the app class, give it to the bootstrapper
_main_ = new ::APP_MAIN::();
var config = {
var config : LimeConfig = {
host : _main_,
fullscreen : ::WIN_FULLSCREEN::,
resizable : ::WIN_RESIZABLE::,
borderless : ::WIN_BORDERLESS::,
antialiasing : ::WIN_ANTIALIASING::,
antialiasing : Std.int(::WIN_ANTIALIASING::),
stencil_buffer : ::WIN_STENCIL_BUFFER::,
depth_buffer : ::WIN_DEPTH_BUFFER::,
vsync : ::WIN_VSYNC::,
fps : ::WIN_FPS::,
width : ::WIN_WIDTH::,
height : ::WIN_HEIGHT::,
title : "::APP_TITLE::"
fps : Std.int(::WIN_FPS::),
width : Std.int(::WIN_WIDTH::),
height : Std.int(::WIN_HEIGHT::),
orientation : "::WIN_ORIENTATION::",
title : "::APP_TITLE::",
};
//Start up