Reorganising classes and structure, changing how render and update loops are accessed for clarity and better code

This commit is contained in:
underscorediscovery
2013-06-23 03:16:12 -02:30
parent 9d6eae9c02
commit 7911fae295
10 changed files with 53 additions and 72 deletions

View File

@@ -110,17 +110,29 @@ class Main {
// Init the shaders and view
init();
//Tell it to let us draw here
lib.set_render_function( on_render );
lib.set_update_function( on_update );
}
public function on_update() {
//called each frame by NMEGL for logic (called before render)
//called each frame by NMEGL for logic (called before render)
public function update() {
var time = haxe.Timer.stamp() - startTime;
if (time > maxTime && fragmentShaders.length > 1) {
//Pick a random example to show
if( include_slow_expensive_examples ) {
currentIndex = Std.random( fragmentShaders.length - 1 );
} else {
currentIndex = slow_end_index + Std.random( (fragmentShaders.length - slow_end_index - 1) );
}
compile ();
}
}
public function on_render() {
//Called each frame by NMEGL
public function render() {
GL.viewport( 0, 0, lib.config.width, lib.config.height );
@@ -145,18 +157,7 @@ class Main {
GL.clear (GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT );
GL.drawArrays (GL.TRIANGLES, 0, 6);
if (time > maxTime && fragmentShaders.length > 1) {
//Pick a random example to show
if( include_slow_expensive_examples ) {
currentIndex = Std.random( fragmentShaders.length - 1 );
} else {
currentIndex = slow_end_index + Std.random( (fragmentShaders.length - slow_end_index - 1) );
}
compile ();
}
}

View File

@@ -40,13 +40,10 @@ class Main {
// Init the shaders and view
init();
//Tell it to let us draw here
lib.set_render_function( on_render );
lib.set_update_function( on_update );
}
public function on_update() {
//called each frame by NMEGL for logic (called before render)
//Called each frame by NMEGL for logic (called before render)
public function update() {
//an awful magic number to change the value slowly
@@ -62,7 +59,8 @@ class Main {
}
public function on_render() {
//Called by NMEGL
public function render() {
//Set the viewport for GL
GL.viewport( 0, 0, lib.config.width, lib.config.height );

View File

@@ -1,4 +1,4 @@
package nmegl.core;
package nmegl;
//Window constants
class Window {

View File

@@ -1,4 +1,4 @@
package nmegl.core;
package nmegl;
import nmegl.NMEGL;

View File

@@ -1,11 +1,11 @@
package nmegl;
import nmegl.core.Constants;
import nmegl.core.Libs;
import nmegl.utils.Libs;
import nmegl.core.RenderHandler;
import nmegl.core.InputHandler;
import nmegl.core.WindowHandler;
import nmegl.Constants;
import nmegl.RenderHandler;
import nmegl.InputHandler;
import nmegl.WindowHandler;
import haxe.Timer;
@@ -21,9 +21,6 @@ class NMEGL {
public var render : RenderHandler;
public var window : WindowHandler;
//Set user update function
public var user_update_function : Void->Void;
//nme specifics
//the handle to the window from nme
@@ -96,17 +93,24 @@ class NMEGL {
//Since we are done...
window.set_active(true);
//Tell the host application
Reflect.callMethod( host , "ready", null);
_debug(':: NMEGL :: Ready.');
//Tell the host application we are ready
if(host.ready != null) {
host.ready();
}
} //on_main_frame_created
public function shutdown() {
shutting_down = true;
//tell the host game we are killing it
if(host.shutdown != null) {
host.shutdown();
}
//We don't want to process much now
window.set_active(false);
@@ -260,8 +264,8 @@ class NMEGL {
if(!has_shutdown) {
if(user_update_function != null) {
user_update_function();
if(host.update != null) {
host.update();
}
do_render(_event);
@@ -269,26 +273,6 @@ class NMEGL {
} //on_update
//the API to allow render hooks
public function set_render_function( _func:Void->Void ) {
if(_func != null) {
render.user_render_function = _func;
} else {
throw "Invalid render function passed to NMEGL";
}
}
//the API to allow update hooks
public function set_update_function( _func:Void->Void ) {
if(_func != null) {
user_update_function = _func;
} else {
throw "Invalid update function passed to NMEGL";
}
}
//Render the window
public function do_render( _event:Dynamic ) {
@@ -301,7 +285,7 @@ class NMEGL {
if( window.invalidated ) {
window.invalidated = false;
}
render.on_render();
nme_render_stage( stage_handle );
@@ -322,7 +306,7 @@ class NMEGL {
//temporary debugging with verbosity options
public var log : Bool = false;
public var verbose : Bool = true;
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) {

View File

@@ -1,7 +1,7 @@
package nmegl.core;
package nmegl;
import nmegl.NMEGL;
import nmegl.core.Libs;
import nmegl.utils.Libs;
//Import GL
import nmegl.gl.GL;
@@ -19,8 +19,6 @@ class RenderHandler {
public var lib : NMEGL;
public function new( _lib:NMEGL ) { lib = _lib; }
public var user_render_function : Void->Void;
//direct_renderer_handle for NME
public var direct_renderer_handle : Dynamic;
@@ -44,8 +42,8 @@ class RenderHandler {
}
public function on_render() {
if(user_render_function != null) {
user_render_function();
if( lib.host.render != null ) {
lib.host.render();
}
}

View File

@@ -1,13 +1,13 @@
package nmegl.core;
package nmegl;
import nmegl.NMEGL;
import nmegl.utils.Libs;
class WindowHandler {
public var lib : NMEGL;
public function new( _lib:NMEGL ) { lib = _lib; }
//if the core is active
public var active : Bool = false;
//if the window is invalidated

View File

@@ -1,6 +1,6 @@
package nmegl.gl;
import nmegl.core.Libs;
import nmegl.utils.Libs;
// import flash.display.BitmapData;
import nmegl.geometry.Matrix3D;

View File

@@ -1,7 +1,7 @@
package nmegl.utils;
#if (cpp || neko)
import nmegl.core.Libs;
import nmegl.utils.Libs;
import haxe.io.Bytes;
import haxe.io.BytesData;

View File

@@ -1,4 +1,4 @@
package nmegl.core;
package nmegl.utils;
import sys.io.Process;