2
0
Pascal Peridont 9 жил өмнө
parent
commit
c1b39b3a82

+ 3 - 1
all.hxml

@@ -1,8 +1,10 @@
 -lib heaps
+-lib castle
+-lib stb_ogg_sound
 --macro include('h3d')
 --macro include('h2d')
 --macro include('hxsl',true,['hxsl.Macros'])
---macro include('hxd',true,['hxd.res.FileTree','hxd.Res','hxd.impl.BitsBuilder'])
+--macro include('hxd',true,['hxd.res.FileTree','hxd.Res','hxd.impl.BitsBuilder','hxd.impl.Air3File','hxd.fmt.pak.Build','hxd.fmt.hmd.MakeAll'])
 --no-output
 --each
 

+ 37 - 0
h2d/Scene3D.hx

@@ -13,4 +13,41 @@ class Scene3D extends Sprite {
 		scene.render(ctx.engine);
 	}
 
+}
+
+class ObjectFollower extends Sprite {
+	
+	public var follow : h3d.scene.Object;
+	
+	public function new( obj, ?parent ) {
+		super(parent);
+		this.follow = obj;
+	}
+	
+	function followObject() {
+		if( follow == null )
+			return;
+		var scene = @:privateAccess follow.getScene();
+		if( scene == null )
+			return;
+		var s2d = getScene();		
+		var width = s2d == null ? h3d.Engine.getCurrent().width : s2d.width;
+		var height = s2d == null ? h3d.Engine.getCurrent().height : s2d.height;
+		var absPos = follow.getAbsPos();
+		var p = scene.camera.project(absPos._41, absPos._42, absPos._43, width, height, true);
+		x = p.x;
+		y = p.y;
+		visible = p.z > 0;
+	}
+	
+	override function syncPos() {
+		followObject();
+		super.syncPos();
+	}
+	
+	override function sync(ctx) {
+		followObject();
+		super.sync(ctx);
+	}
+	
 }

+ 9 - 0
h2d/col/Point.hx

@@ -40,6 +40,15 @@ class Point {
 	public inline function dot( p : Point ) {
 		return x * p.x + y * p.y;
 	}
+	
+	public inline function rotate( angle : Float ) {
+		var c = Math.cos(angle);
+		var s = Math.sin(angle);
+		var x2 = x * c - y * s;
+		var y2 = x * s + y * c;
+		x = x2;
+		y = y2;
+	}
 
 	public inline function lengthSq() {
 		return x * x + y * y;

+ 3 - 3
h3d/impl/Driver.hx

@@ -21,9 +21,9 @@ typedef IndexBuffer = sdl.GL.Buffer;
 typedef VertexBuffer = { b : sdl.GL.Buffer, stride : Int };
 typedef Texture = { t : sdl.GL.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, ?fb : sdl.GL.Framebuffer, ?rb : sdl.GL.Renderbuffer };
 #else
-typedef IndexBuffer = Int;
-typedef VertexBuffer = Int;
-typedef Texture = Int;
+typedef IndexBuffer = {};
+typedef VertexBuffer = {};
+typedef Texture = {};
 #end
 
 enum Feature {

+ 13 - 2
h3d/scene/Object.hx

@@ -185,12 +185,15 @@ class Object {
 		Transform a point from the global coordinates to the object local ones. The point is modified and returned.
 	**/
 	public function globalToLocal( pt : h3d.Vector ) {
-		syncPos();
 		pt.transform3x4(getInvPos());
 		return pt;
 	}
 
-	function getInvPos() {
+	/**
+		Returns the updated inverse position matrix. Please note that this is not a copy and should not be modified.
+	**/
+	public function getInvPos() {
+		syncPos();
 		if( invPos == null ) {
 			invPos = new h3d.Matrix();
 			invPos._44 = 0;
@@ -333,6 +336,14 @@ class Object {
 		while( p.parent != null ) p = p.parent;
 		return Std.instance(p, Scene);
 	}
+	
+	/**
+		Returns the updated absolute position matrix. Please note that this is not a copy so it should not be modified.
+	**/
+	public function getAbsPos() {
+		syncPos();
+		return absPos;
+	}
 
 	public inline function isMesh() {
 		return Std.instance(this, Mesh) != null;

+ 689 - 634
hxd/System.hx

@@ -1,634 +1,689 @@
-package hxd;
-
-#if hxsdl
-import hxd.Key in K;
-#end
-
-enum Cursor {
-	Default;
-	Button;
-	Move;
-	TextInput;
-	Hide;
-	Custom( frames : Array<hxd.BitmapData>, speed : Float, offsetX : Int, offsetY : Int );
-}
-
-class System {
-
-	public static var width(get,never) : Int;
-	public static var height(get,never) : Int;
-	public static var isTouch(get,never) : Bool;
-	public static var isWindowed(get,never) : Bool;
-	public static var lang(get,never) : String;
-	public static var isAndroid(get, never) : Bool;
-	public static var isIOS(get, never) : Bool;
-
-	public static var screenDPI(get,never) : Float;
-
-	public static var setCursor = setNativeCursor;
-
-	#if (flash || nme || openfl)
-
-	static function get_isWindowed() {
-		#if cpp
-		return true;
-		#else
-		var p = flash.system.Capabilities.playerType;
-		return p == "ActiveX" || p == "PlugIn" || p == "StandAlone" || p == "Desktop";
-		#end
-	}
-
-	static function get_isTouch() {
-		#if cpp
-		return false;
-		#else
-		return flash.system.Capabilities.touchscreenType == flash.system.TouchscreenType.FINGER;
-		#end
-	}
-
-	static function get_width() {
-		var Cap = flash.system.Capabilities;
-		return isWindowed ? flash.Lib.current.stage.stageWidth : Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionX : Cap.screenResolutionY);
-	}
-
-	static function get_height() {
-		var Cap = flash.system.Capabilities;
-		return isWindowed ? flash.Lib.current.stage.stageHeight : Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionY : Cap.screenResolutionX);
-	}
-
-	static function get_isAndroid() {
-		#if cpp
-		return #if android true #else false #end;
-		#else
-		return flash.system.Capabilities.manufacturer.indexOf('Android') != -1;
-		#end
-	}
-
-	static function get_isIOS() {
-		#if cpp
-		return #if ios true #else false #end;
-		#else
-		return flash.system.Capabilities.manufacturer.indexOf('iOS') != -1;
-		#end
-	}
-
-	static function get_screenDPI() {
-		return flash.system.Capabilities.screenDPI;
-	}
-
-	static var loop = null;
-	static var loopFunc = null;
-	#if (nme || openfl)
-	static var VIEW = null;
-	#end
-
-	public static function getCurrentLoop() {
-		return loopFunc;
-	}
-
-	public static function setLoop( f : Void -> Void ) {
-		loopFunc = f;
-		#if nme
-		if( VIEW == null ) {
-			VIEW = new nme.display.OpenGLView();
-			VIEW.name = "glView";
-			flash.Lib.current.addChildAt(VIEW,0);
-		}
-		VIEW.render = function(_) if ( f != null ) f();
-		#elseif openfl
-		if( openfl.display.OpenGLView.isSupported ){
-			if( VIEW == null ) {
-				VIEW = new openfl.display.OpenGLView();
-				VIEW.name = "glView";
-				flash.Lib.current.addChildAt(VIEW, 0);
-			}
-			VIEW.render = function(_) if ( f != null ) f();
-		}
-		#else
-		if( loop != null )
-			flash.Lib.current.removeEventListener(flash.events.Event.ENTER_FRAME, loop);
-		if( f == null )
-			loop = null;
-		else {
-			loop = function(_) f();
-			flash.Lib.current.addEventListener(flash.events.Event.ENTER_FRAME, loop);
-		}
-		#end
-	}
-
-	public static function start(callb) {
-		#if nme
-		var windowSize = haxe.macro.Compiler.getDefine("window");
-		if( windowSize == null ) windowSize = "800x600";
-		var windowSize = windowSize.split("x");
-		var width = Std.parseInt(windowSize[0]), height = Std.parseInt(windowSize[1]);
-		if( width < 100 ) width = 100;
-		if( height < 100 ) height = 100;
-		nme.Lib.create(function() {
-            nme.Lib.current.stage.align = nme.display.StageAlign.TOP_LEFT;
-            nme.Lib.current.stage.scaleMode = nme.display.StageScaleMode.NO_SCALE;
-            nme.Lib.current.loaderInfo = nme.display.LoaderInfo.create(null);
-			try {
-				callb();
-			} catch( e : Dynamic ) {
-				Sys.println(e);
-				#if debug
-				Sys.println(haxe.CallStack.toString(haxe.CallStack.exceptionStack()));
-				#end
-			}
-         },
-         width, height,
-         120, // using 60 FPS with no vsync gives a fps ~= 50
-         0xFFFFFF,
-         (true ? nme.Lib.HARDWARE : 0) |
-         nme.Lib.ALLOW_SHADERS | nme.Lib.REQUIRE_SHADERS |
-         (true ? nme.Lib.DEPTH_BUFFER : 0) |
-         (false ? nme.Lib.STENCIL_BUFFER : 0) |
-         (true ? nme.Lib.RESIZABLE : 0) |
-         (false ? nme.Lib.BORDERLESS : 0) |
-         (true ? nme.Lib.VSYNC : 0) |
-         (false ? nme.Lib.FULLSCREEN : 0) |
-         (0 == 4 ? nme.Lib.HW_AA_HIRES : 0) |
-         (0 == 2 ? nme.Lib.HW_AA : 0),
-         "Heaps Application"
-		);
-		#else
-		callb();
-		#end
-	}
-
-	#if flash
-	static function isAir() {
-		return flash.system.Capabilities.playerType == "Desktop";
-	}
-	#end
-
-	public static function getClipboard() : String {
-		#if flash
-		return flash.desktop.Clipboard.generalClipboard.getData(flash.desktop.ClipboardFormats.TEXT_FORMAT);
-		#else
-		return "";
-		#end
-	}
-
-	public static function exit() {
-		#if flash
-		if( isAir() ) {
-			var d : Dynamic = flash.Lib.current.loaderInfo.applicationDomain.getDefinition("flash.desktop.NativeApplication");
-			Reflect.field(Reflect.field(d,"nativeApplication"),"exit")();
-		} else
-		#end
-			flash.system.System.exit(0);
-	}
-
-	public static function setNativeCursor( c : Cursor ) {
-		#if cpp
-		// TODO
-		#else
-		flash.ui.Mouse.cursor = switch( c ) {
-		case Default: "auto";
-		case Button: "button";
-		case Move: "hand";
-		case TextInput: "ibeam";
-		case Hide: "auto";
-		case Custom(frames, speed, offsetX, offsetY):
-			#if cpp
-				throw "not supported on openFL for now";
-			#else
-				var customCursor = new flash.ui.MouseCursorData();
-				var v = new flash.Vector();
-				for( f in frames ) v.push(f.toNative());
-				customCursor.data = v;
-				customCursor.frameRate = speed;
-				customCursor.hotSpot = new flash.geom.Point(offsetX, offsetY);
-				flash.ui.Mouse.registerCursor("custom", customCursor);
-				"custom";
-			#end
-		}
-		#end
-		if( c == Hide ) flash.ui.Mouse.hide() else flash.ui.Mouse.show();
-	}
-
-
-	/**
-		Returns the device name:
-			"PC" for a desktop computer
-			Or the android device name
-			(will add iPad/iPhone/iPod soon)
-	**/
-	static var CACHED_NAME = null;
-	public static function getDeviceName() {
-		if( CACHED_NAME != null )
-			return CACHED_NAME;
-		var name;
-		#if flash
-		if( isAndroid && isAir() ) {
-			try {
-				var f : Dynamic = Type.createInstance(flash.Lib.current.loaderInfo.applicationDomain.getDefinition("flash.filesystem.File"), ["/system/build.prop"]);
-				var fs : flash.utils.IDataInput = Type.createInstance(flash.Lib.current.loaderInfo.applicationDomain.getDefinition("flash.filesystem.FileStream"), []);
-				Reflect.callMethod(fs, Reflect.field(fs, "open"), [f, "read"]);
-				var content = fs.readUTFBytes(fs.bytesAvailable);
-				name = StringTools.trim(content.split("ro.product.model=")[1].split("\n")[0]);
-			} catch( e : Dynamic ) {
-				name = "Android";
-			}
-		} else
-		#end
-		if( isIOS ) {
-			name = switch( [width, height, screenDPI] ) {
-			case [960, 640, 326]: "iPhone4";
-			case [1136, 640, 326]: "iPhone5";
-			case [1334, 750, 326]: "iPhone6";
-			case [1920, 1080, 401]: "iPhone6+";
-			case [2048, 1536, 264]: "iPad"; // 3/4/Air
-			case [2048, 1536, 326]: "iPadMini2";
-			case [1024, 768, 163]: "iPadMini";
-			case [w, h, dpi]: "IOS Unknown " + w + "x" + h + "@" + dpi;
-			}
-		} else
-			name = "PC";
-		CACHED_NAME = name;
-		return name;
-	}
-
-	static function get_lang() {
-		return flash.system.Capabilities.language;
-	}
-
-	#elseif lime
-
-	static function get_isWindowed() {
-		return true;
-	}
-
-	static function get_isTouch() {
-		#if desktop
-		return false;
-		#else
-		return true;
-		#end
-	}
-
-	static function get_width() {
-		var win = lime.app.Application.current.window;
-		return Std.int(win.width * win.scale);
-	}
-
-	static function get_height() {
-		var win = lime.app.Application.current.window;
-		return Std.int(win.height * win.scale);
-	}
-
-	static function get_isAndroid() {
-		return #if android true #else false #end;
-	}
-
-	static function get_isIOS() {
-		return #if ios true #else false #end;
-	}
-
-	static function get_screenDPI() {
-		return 0; // TODO
-	}
-
-	@:allow(hxd.impl.LimeStage)
-	static var loopFunc = null;
-
-	public static function getCurrentLoop() {
-		return loopFunc;
-	}
-
-	public static function setLoop( f : Void -> Void ) {
-		loopFunc = f;
-	}
-
-	public static function start(callb) {
-		callb();
-	}
-
-	public static function getClipboard() : String {
-		return lime.system.Clipboard.text;
-	}
-
-	public static function exit() {
-		return lime.system.System.exit( 0 );
-	}
-
-	public static function setNativeCursor( c : Cursor ) {
-		lime.ui.Mouse.cursor = switch( c ){
-		case Default: DEFAULT;
-		case Button: POINTER;
-		case Move: MOVE;
-		case TextInput: TEXT;
-		case Hide: DEFAULT;
-		case Custom(_,_,_,_):
-			throw "not supported";
-		}
-		if( c == Hide ) lime.ui.Mouse.hide() else lime.ui.Mouse.show();
-	}
-
-
-	/**
-		Returns the device name:
-			"PC" for a desktop computer
-			Or the android device name
-			(will add iPad/iPhone/iPod soon)
-	**/
-	static var CACHED_NAME = null;
-	public static function getDeviceName() {
-		if( CACHED_NAME != null )
-			return CACHED_NAME;
-		var name;
-		name = "Unknown"; // TODO
-		CACHED_NAME = name;
-		return name;
-	}
-
-	static function get_lang() {
-		return null; // TODO
-	}	
-
-	#elseif js
-
-	static var LOOP = null;
-	static var LOOP_INIT = false;
-
-	static function loopFunc() {
-		var window : Dynamic = js.Browser.window;
-		var rqf : Dynamic = window.requestAnimationFrame ||
-			window.webkitRequestAnimationFrame ||
-			window.mozRequestAnimationFrame;
-		rqf(loopFunc);
-		if( LOOP != null ) LOOP();
-	}
-
-	public static function getCurrentLoop() {
-		return LOOP;
-	}
-
-	public static function setLoop( f : Void -> Void ) {
-		if( !LOOP_INIT ) {
-			LOOP_INIT = true;
-			loopFunc();
-		}
-		LOOP = f;
-	}
-
-	public static function start( callb ) {
-		callb();
-	}
-
-	public static function getClipboard() : String {
-		return "";
-	}
-
-	public static function setNativeCursor( c : Cursor ) {
-		var canvas = js.Browser.document.getElementById("webgl");
-		if( canvas != null ) {
-			canvas.style.cursor = switch( c ) {
-			case Default: "default";
-			case Button: "pointer";
-			case Move: "move";
-			case TextInput: "text";
-			case Hide: "none";
-			case Custom(_): throw "Custom cursor not supported";
-			};
-		}
-	}
-
-	static function get_lang() {
-		return "en";
-	}
-
-	static function get_screenDPI() {
-		return 72.;
-	}
-
-	static function get_isAndroid() {
-		return false;
-	}
-
-	static function get_isIOS() {
-		return false;
-	}
-
-	static function get_isWindowed() {
-		return true;
-	}
-
-	static function get_isTouch() {
-		return false;
-	}
-
-	static function get_width() {
-		return Math.round(js.Browser.document.body.clientWidth * js.Browser.window.devicePixelRatio);
-	}
-
-	static function get_height() {
-		return Math.round(js.Browser.document.body.clientHeight  * js.Browser.window.devicePixelRatio);
-	}
-
-	#elseif hxsdl
-
-	public static function setNativeCursor( c : Cursor ) {
-		trace("TODO " + c);
-	}
-
-	static function get_screenDPI() {
-		return 72; // not implemented in SDL ???
-	}
-
-	static function get_isIOS() {
-		return false;
-	}
-
-	static function get_isAndroid() {
-		return false;
-	}
-
-	static function get_isWindowed() {
-		return true;
-	}
-
-	static function get_isTouch() {
-		return false;
-	}
-
-	static function get_lang() {
-		return "en";
-	}
-
-	static function get_width() {
-		return sdl.Sdl.getScreenWidth();
-	}
-
-	static function get_height() {
-		return sdl.Sdl.getScreenHeight();
-	}
-
-	public static function exit() {
-		Sys.exit(0);
-	}
-
-	public static function getClipboard() : String {
-		return "";
-	}
-
-	static var win : sdl.Window;
-	static var windowWidth = 800;
-	static var windowHeight = 600;
-	static var mouseX = 0;
-	static var mouseY = 0;
-	static var currentLoop = null;
-	static var CODEMAP = [for( i in 0...2048 ) i];
-	static var CHARMAP = [for( i in 0...2048 ) 0];
-
-	public static function setLoop( f : Void -> Void ) {
-		currentLoop = f;
-	}
-
-	static function mainLoop() {
-		if( currentLoop != null ) currentLoop();
-		win.present();
-	}
-
-	static function onEvent( e : sdl.Event ) {
-		var eh = null;
-		switch( e.type ) {
-		case WindowState:
-			switch( e.state ) {
-			case Resize:
-				windowWidth = win.width;
-				windowHeight = win.height;
-				@:privateAccess Stage.getInstance().onResize(null);
-			default:
-			}
-		case MouseDown:
-			mouseX = e.mouseX;
-			mouseY = e.mouseY;
-			eh = new Event(EPush, e.mouseX, e.mouseY);
-		case MouseUp:
-			mouseX = e.mouseX;
-			mouseY = e.mouseY;
-			eh = new Event(ERelease, e.mouseX, e.mouseY);
-		case MouseMove:
-			mouseX = e.mouseX;
-			mouseY = e.mouseY;
-			eh = new Event(EMove, e.mouseX, e.mouseY);
-		case KeyDown:
-			eh = new Event(EKeyDown);
-			if( e.keyCode & (1 << 30) != 0 ) e.keyCode = (e.keyCode & ((1 << 30) - 1)) + 1000;
-			eh.keyCode = CODEMAP[e.keyCode];
-			eh.charCode = CHARMAP[e.keyCode];
-			if( eh.keyCode & (K.LOC_LEFT | K.LOC_RIGHT) != 0 ) {
-				e.keyCode = eh.keyCode & 0xFF;
-				onEvent(e);
-			}
-		case KeyUp:
-			eh = new Event(EKeyUp);
-			if( e.keyCode & (1 << 30) != 0 ) e.keyCode = (e.keyCode & ((1 << 30) - 1)) + 1000;
-			eh.keyCode = CODEMAP[e.keyCode];
-			eh.charCode = CHARMAP[e.keyCode];
-			if( eh.keyCode & (K.LOC_LEFT | K.LOC_RIGHT) != 0 ) {
-				e.keyCode = eh.keyCode & 0xFF;
-				onEvent(e);
-			}
-		case MouseWheel:
-			eh = new Event(EWheel, mouseX, mouseY);
-			eh.wheelDelta = -e.wheelDelta;
-		default:
-		}
-		if( eh != null ) Stage.getInstance().event(eh);
-	}
-
-	public static function start( init : Void -> Void ) {
-		inline function addKey(sdl, keyCode, charCode=0) {
-			CODEMAP[sdl] = keyCode;
-			if( charCode != 0 ) CHARMAP[sdl] = charCode;
-		}
-		var keys = [
-			//K.BACKSPACE
-			//K.TAB
-			//K.ENTER
-			1225 => K.LSHIFT,
-			1229 => K.RSHIFT,
-			1224 => K.LCTRL,
-			1228 => K.RCTRL,
-			1226 => K.LALT,
-			1230 => K.RALT,
-			// K.ESCAPE
-			// K.SPACE
-			1075 => K.PGUP,
-			1078 => K.PGDOWN,
-			1077 => K.END,
-			1074 => K.HOME,
-			1080 => K.LEFT,
-			1082 => K.UP,
-			1079 => K.RIGHT,
-			1081 => K.DOWN,
-			1073 => K.INSERT,
-			127 => K.DELETE,
-			//K.NUMBER_0-9
-			1098 => K.NUMPAD_0,
-			//K.A-Z
-			//K.F1-F12
-			1085 => K.NUMPAD_MULT,
-			1087 => K.NUMPAD_ADD,
-			1088 => K.NUMPAD_ENTER,
-			1086 => K.NUMPAD_SUB,
-			1099 => K.NUMPAD_DOT,
-			1084 => K.NUMPAD_DIV,
-		];
-
-		/*
-			SDL 2.0 does not allow to get the charCode from a key event.
-			let's for now do a simple mapping, even if not very efficient
-		*/
-		CHARMAP[1098] = "0".code;
-		CHARMAP[1085] = "*".code;
-		CHARMAP[1087] = "+".code;
-		CHARMAP[1088] = 13;
-		CHARMAP[1086] = "-".code;
-		CHARMAP[1084] = "/".code;
-		CHARMAP[1099] = ".".code;
-		CHARMAP[K.BACKSPACE] = 8;
-		CHARMAP[K.TAB] = 9;
-		CHARMAP[K.ENTER] = 13;
-		CHARMAP[K.SPACE] = 32;
-
-		for( i in 0...10 )
-			CHARMAP[K.NUMBER_0 + i] = "0".code + i;
-
-		for( i in 0...9 )
-			addKey(1089 + i, K.NUMPAD_1 + i, "1".code + i);
-		for( i in 0...26 )
-			addKey(97 + i, K.A + i, "a".code + i);
-		for( i in 0...12 )
-			addKey(1058 + i, K.F1 + i);
-		for( sdl in keys.keys() )
-			addKey(sdl, keys.get(sdl));
-		sdl.Sdl.init();
-		var size = haxe.macro.Compiler.getDefine("windowSize");
-		if( size != null ) {
-			var p = size.split("x");
-			windowWidth = Std.parseInt(p[0]);
-			windowHeight = Std.parseInt(p[1]);
-		}
-		win = new sdl.Window("", windowWidth, windowHeight);
-		init();
-		sdl.Sdl.loop(mainLoop,onEvent);
-		sdl.Sdl.quit();
-	}
-
-
-	#end
-
-	public static function getDefaultFrameRate() : Float {
-		#if (flash || openfl)
-		return flash.Lib.current.stage.frameRate;
-		#else
-		return 60.;
-		#end
-	}
-
-}
+package hxd;
+
+#if hxsdl
+import hxd.Key in K;
+#end
+
+enum Cursor {
+	Default;
+	Button;
+	Move;
+	TextInput;
+	Hide;
+	Custom( frames : Array<hxd.BitmapData>, speed : Float, offsetX : Int, offsetY : Int );
+}
+
+class System {
+
+	public static var width(get,never) : Int;
+	public static var height(get,never) : Int;
+	public static var isTouch(get,never) : Bool;
+	public static var isWindowed(get,never) : Bool;
+	public static var lang(get,never) : String;
+	public static var isAndroid(get, never) : Bool;
+	public static var isIOS(get, never) : Bool;
+
+	public static var screenDPI(get,never) : Float;
+
+	public static var setCursor = setNativeCursor;
+
+	#if (flash || nme || openfl)
+
+	static function get_isWindowed() {
+		#if cpp
+		return true;
+		#else
+		var p = flash.system.Capabilities.playerType;
+		return p == "ActiveX" || p == "PlugIn" || p == "StandAlone" || p == "Desktop";
+		#end
+	}
+
+	static function get_isTouch() {
+		#if cpp
+		return false;
+		#else
+		return flash.system.Capabilities.touchscreenType == flash.system.TouchscreenType.FINGER;
+		#end
+	}
+
+	static function get_width() {
+		var Cap = flash.system.Capabilities;
+		return isWindowed ? flash.Lib.current.stage.stageWidth : Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionX : Cap.screenResolutionY);
+	}
+
+	static function get_height() {
+		var Cap = flash.system.Capabilities;
+		return isWindowed ? flash.Lib.current.stage.stageHeight : Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionY : Cap.screenResolutionX);
+	}
+
+	static function get_isAndroid() {
+		#if cpp
+		return #if android true #else false #end;
+		#else
+		return flash.system.Capabilities.manufacturer.indexOf('Android') != -1;
+		#end
+	}
+
+	static function get_isIOS() {
+		#if cpp
+		return #if ios true #else false #end;
+		#else
+		return flash.system.Capabilities.manufacturer.indexOf('iOS') != -1;
+		#end
+	}
+
+	static function get_screenDPI() {
+		return flash.system.Capabilities.screenDPI;
+	}
+
+	static var loop = null;
+	static var loopFunc = null;
+	#if (nme || openfl)
+	static var VIEW = null;
+	#end
+
+	public static function getCurrentLoop() {
+		return loopFunc;
+	}
+
+	public static function setLoop( f : Void -> Void ) {
+		loopFunc = f;
+		#if nme
+		if( VIEW == null ) {
+			VIEW = new nme.display.OpenGLView();
+			VIEW.name = "glView";
+			flash.Lib.current.addChildAt(VIEW,0);
+		}
+		VIEW.render = function(_) if ( f != null ) f();
+		#elseif openfl
+		if( openfl.display.OpenGLView.isSupported ){
+			if( VIEW == null ) {
+				VIEW = new openfl.display.OpenGLView();
+				VIEW.name = "glView";
+				flash.Lib.current.addChildAt(VIEW, 0);
+			}
+			VIEW.render = function(_) if ( f != null ) f();
+		}
+		#else
+		if( loop != null )
+			flash.Lib.current.removeEventListener(flash.events.Event.ENTER_FRAME, loop);
+		if( f == null )
+			loop = null;
+		else {
+			loop = function(_) f();
+			flash.Lib.current.addEventListener(flash.events.Event.ENTER_FRAME, loop);
+		}
+		#end
+	}
+
+	public static function start(callb) {
+		#if nme
+		var windowSize = haxe.macro.Compiler.getDefine("window");
+		if( windowSize == null ) windowSize = "800x600";
+		var windowSize = windowSize.split("x");
+		var width = Std.parseInt(windowSize[0]), height = Std.parseInt(windowSize[1]);
+		if( width < 100 ) width = 100;
+		if( height < 100 ) height = 100;
+		nme.Lib.create(function() {
+            nme.Lib.current.stage.align = nme.display.StageAlign.TOP_LEFT;
+            nme.Lib.current.stage.scaleMode = nme.display.StageScaleMode.NO_SCALE;
+            nme.Lib.current.loaderInfo = nme.display.LoaderInfo.create(null);
+			try {
+				callb();
+			} catch( e : Dynamic ) {
+				Sys.println(e);
+				#if debug
+				Sys.println(haxe.CallStack.toString(haxe.CallStack.exceptionStack()));
+				#end
+			}
+         },
+         width, height,
+         120, // using 60 FPS with no vsync gives a fps ~= 50
+         0xFFFFFF,
+         (true ? nme.Lib.HARDWARE : 0) |
+         nme.Lib.ALLOW_SHADERS | nme.Lib.REQUIRE_SHADERS |
+         (true ? nme.Lib.DEPTH_BUFFER : 0) |
+         (false ? nme.Lib.STENCIL_BUFFER : 0) |
+         (true ? nme.Lib.RESIZABLE : 0) |
+         (false ? nme.Lib.BORDERLESS : 0) |
+         (true ? nme.Lib.VSYNC : 0) |
+         (false ? nme.Lib.FULLSCREEN : 0) |
+         (0 == 4 ? nme.Lib.HW_AA_HIRES : 0) |
+         (0 == 2 ? nme.Lib.HW_AA : 0),
+         "Heaps Application"
+		);
+		#else
+		callb();
+		#end
+	}
+
+	#if flash
+	static function isAir() {
+		return flash.system.Capabilities.playerType == "Desktop";
+	}
+	#end
+
+	public static function getClipboard() : String {
+		#if flash
+		return flash.desktop.Clipboard.generalClipboard.getData(flash.desktop.ClipboardFormats.TEXT_FORMAT);
+		#else
+		return "";
+		#end
+	}
+
+	public static function exit() {
+		#if flash
+		if( isAir() ) {
+			var d : Dynamic = flash.Lib.current.loaderInfo.applicationDomain.getDefinition("flash.desktop.NativeApplication");
+			Reflect.field(Reflect.field(d,"nativeApplication"),"exit")();
+		} else
+		#end
+			flash.system.System.exit(0);
+	}
+
+	public static function setNativeCursor( c : Cursor ) {
+		#if cpp
+		// TODO
+		#else
+		flash.ui.Mouse.cursor = switch( c ) {
+		case Default: "auto";
+		case Button: "button";
+		case Move: "hand";
+		case TextInput: "ibeam";
+		case Hide: "auto";
+		case Custom(frames, speed, offsetX, offsetY):
+			#if cpp
+				throw "not supported on openFL for now";
+			#else
+				var customCursor = new flash.ui.MouseCursorData();
+				var v = new flash.Vector();
+				for( f in frames ) v.push(f.toNative());
+				customCursor.data = v;
+				customCursor.frameRate = speed;
+				customCursor.hotSpot = new flash.geom.Point(offsetX, offsetY);
+				flash.ui.Mouse.registerCursor("custom", customCursor);
+				"custom";
+			#end
+		}
+		#end
+		if( c == Hide ) flash.ui.Mouse.hide() else flash.ui.Mouse.show();
+	}
+
+
+	/**
+		Returns the device name:
+			"PC" for a desktop computer
+			Or the android device name
+			(will add iPad/iPhone/iPod soon)
+	**/
+	static var CACHED_NAME = null;
+	public static function getDeviceName() {
+		if( CACHED_NAME != null )
+			return CACHED_NAME;
+		var name;
+		#if flash
+		if( isAndroid && isAir() ) {
+			try {
+				var f : Dynamic = Type.createInstance(flash.Lib.current.loaderInfo.applicationDomain.getDefinition("flash.filesystem.File"), ["/system/build.prop"]);
+				var fs : flash.utils.IDataInput = Type.createInstance(flash.Lib.current.loaderInfo.applicationDomain.getDefinition("flash.filesystem.FileStream"), []);
+				Reflect.callMethod(fs, Reflect.field(fs, "open"), [f, "read"]);
+				var content = fs.readUTFBytes(fs.bytesAvailable);
+				name = StringTools.trim(content.split("ro.product.model=")[1].split("\n")[0]);
+			} catch( e : Dynamic ) {
+				name = "Android";
+			}
+		} else
+		#end
+		if( isIOS ) {
+			name = switch( [width, height, screenDPI] ) {
+			case [960, 640, 326]: "iPhone4";
+			case [1136, 640, 326]: "iPhone5";
+			case [1334, 750, 326]: "iPhone6";
+			case [1920, 1080, 401]: "iPhone6+";
+			case [2048, 1536, 264]: "iPad"; // 3/4/Air
+			case [2048, 1536, 326]: "iPadMini2";
+			case [1024, 768, 163]: "iPadMini";
+			case [w, h, dpi]: "IOS Unknown " + w + "x" + h + "@" + dpi;
+			}
+		} else
+			name = "PC";
+		CACHED_NAME = name;
+		return name;
+	}
+
+	static function get_lang() {
+		return flash.system.Capabilities.language;
+	}
+
+	#elseif lime
+
+	static function get_isWindowed() {
+		return true;
+	}
+
+	static function get_isTouch() {
+		#if desktop
+		return false;
+		#else
+		return true;
+		#end
+	}
+
+	static function get_width() {
+		var win = lime.app.Application.current.window;
+		return Std.int(win.width * win.scale);
+	}
+
+	static function get_height() {
+		var win = lime.app.Application.current.window;
+		return Std.int(win.height * win.scale);
+	}
+
+	static function get_isAndroid() {
+		return #if android true #else false #end;
+	}
+
+	static function get_isIOS() {
+		return #if ios true #else false #end;
+	}
+
+	static function get_screenDPI() {
+		return 0; // TODO
+	}
+
+	@:allow(hxd.impl.LimeStage)
+	static var loopFunc = null;
+
+	public static function getCurrentLoop() {
+		return loopFunc;
+	}
+
+	public static function setLoop( f : Void -> Void ) {
+		loopFunc = f;
+	}
+
+	public static function start(callb) {
+		callb();
+	}
+
+	public static function getClipboard() : String {
+		return lime.system.Clipboard.text;
+	}
+
+	public static function exit() {
+		return lime.system.System.exit( 0 );
+	}
+
+	public static function setNativeCursor( c : Cursor ) {
+		lime.ui.Mouse.cursor = switch( c ){
+		case Default: DEFAULT;
+		case Button: POINTER;
+		case Move: MOVE;
+		case TextInput: TEXT;
+		case Hide: DEFAULT;
+		case Custom(_,_,_,_):
+			throw "not supported";
+		}
+		if( c == Hide ) lime.ui.Mouse.hide() else lime.ui.Mouse.show();
+	}
+
+
+	/**
+		Returns the device name:
+			"PC" for a desktop computer
+			Or the android device name
+			(will add iPad/iPhone/iPod soon)
+	**/
+	static var CACHED_NAME = null;
+	public static function getDeviceName() {
+		if( CACHED_NAME != null )
+			return CACHED_NAME;
+		var name;
+		name = "Unknown"; // TODO
+		CACHED_NAME = name;
+		return name;
+	}
+
+	static function get_lang() {
+		return null; // TODO
+	}	
+
+	#elseif js
+
+	static var LOOP = null;
+	static var LOOP_INIT = false;
+
+	static function loopFunc() {
+		var window : Dynamic = js.Browser.window;
+		var rqf : Dynamic = window.requestAnimationFrame ||
+			window.webkitRequestAnimationFrame ||
+			window.mozRequestAnimationFrame;
+		rqf(loopFunc);
+		if( LOOP != null ) LOOP();
+	}
+
+	public static function getCurrentLoop() {
+		return LOOP;
+	}
+
+	public static function setLoop( f : Void -> Void ) {
+		if( !LOOP_INIT ) {
+			LOOP_INIT = true;
+			loopFunc();
+		}
+		LOOP = f;
+	}
+
+	public static function start( callb ) {
+		callb();
+	}
+
+	public static function getClipboard() : String {
+		return "";
+	}
+
+	public static function setNativeCursor( c : Cursor ) {
+		var canvas = js.Browser.document.getElementById("webgl");
+		if( canvas != null ) {
+			canvas.style.cursor = switch( c ) {
+			case Default: "default";
+			case Button: "pointer";
+			case Move: "move";
+			case TextInput: "text";
+			case Hide: "none";
+			case Custom(_): throw "Custom cursor not supported";
+			};
+		}
+	}
+
+	static function get_lang() {
+		return "en";
+	}
+
+	static function get_screenDPI() {
+		return 72.;
+	}
+
+	static function get_isAndroid() {
+		return false;
+	}
+
+	static function get_isIOS() {
+		return false;
+	}
+
+	static function get_isWindowed() {
+		return true;
+	}
+
+	static function get_isTouch() {
+		return false;
+	}
+
+	static function get_width() {
+		return Math.round(js.Browser.document.body.clientWidth * js.Browser.window.devicePixelRatio);
+	}
+
+	static function get_height() {
+		return Math.round(js.Browser.document.body.clientHeight  * js.Browser.window.devicePixelRatio);
+	}
+
+	#elseif hxsdl
+
+	public static function setNativeCursor( c : Cursor ) {
+		trace("TODO " + c);
+	}
+
+	static function get_screenDPI() {
+		return 72; // not implemented in SDL ???
+	}
+
+	static function get_isIOS() {
+		return false;
+	}
+
+	static function get_isAndroid() {
+		return false;
+	}
+
+	static function get_isWindowed() {
+		return true;
+	}
+
+	static function get_isTouch() {
+		return false;
+	}
+
+	static function get_lang() {
+		return "en";
+	}
+
+	static function get_width() {
+		return sdl.Sdl.getScreenWidth();
+	}
+
+	static function get_height() {
+		return sdl.Sdl.getScreenHeight();
+	}
+
+	public static function exit() {
+		Sys.exit(0);
+	}
+
+	public static function getClipboard() : String {
+		return "";
+	}
+
+	static var win : sdl.Window;
+	static var windowWidth = 800;
+	static var windowHeight = 600;
+	static var mouseX = 0;
+	static var mouseY = 0;
+	static var currentLoop = null;
+	static var CODEMAP = [for( i in 0...2048 ) i];
+	static var CHARMAP = [for( i in 0...2048 ) 0];
+
+	public static function setLoop( f : Void -> Void ) {
+		currentLoop = f;
+	}
+
+	static function mainLoop() {
+		if( currentLoop != null ) currentLoop();
+		win.present();
+	}
+
+	static function onEvent( e : sdl.Event ) {
+		var eh = null;
+		switch( e.type ) {
+		case WindowState:
+			switch( e.state ) {
+			case Resize:
+				windowWidth = win.width;
+				windowHeight = win.height;
+				@:privateAccess Stage.getInstance().onResize(null);
+			default:
+			}
+		case MouseDown:
+			mouseX = e.mouseX;
+			mouseY = e.mouseY;
+			eh = new Event(EPush, e.mouseX, e.mouseY);
+		case MouseUp:
+			mouseX = e.mouseX;
+			mouseY = e.mouseY;
+			eh = new Event(ERelease, e.mouseX, e.mouseY);
+		case MouseMove:
+			mouseX = e.mouseX;
+			mouseY = e.mouseY;
+			eh = new Event(EMove, e.mouseX, e.mouseY);
+		case KeyDown:
+			eh = new Event(EKeyDown);
+			if( e.keyCode & (1 << 30) != 0 ) e.keyCode = (e.keyCode & ((1 << 30) - 1)) + 1000;
+			eh.keyCode = CODEMAP[e.keyCode];
+			eh.charCode = CHARMAP[e.keyCode];
+			if( eh.keyCode & (K.LOC_LEFT | K.LOC_RIGHT) != 0 ) {
+				e.keyCode = eh.keyCode & 0xFF;
+				onEvent(e);
+			}
+		case KeyUp:
+			eh = new Event(EKeyUp);
+			if( e.keyCode & (1 << 30) != 0 ) e.keyCode = (e.keyCode & ((1 << 30) - 1)) + 1000;
+			eh.keyCode = CODEMAP[e.keyCode];
+			eh.charCode = CHARMAP[e.keyCode];
+			if( eh.keyCode & (K.LOC_LEFT | K.LOC_RIGHT) != 0 ) {
+				e.keyCode = eh.keyCode & 0xFF;
+				onEvent(e);
+			}
+		case MouseWheel:
+			eh = new Event(EWheel, mouseX, mouseY);
+			eh.wheelDelta = -e.wheelDelta;
+		default:
+		}
+		if( eh != null ) Stage.getInstance().event(eh);
+	}
+
+	public static function start( init : Void -> Void ) {
+		inline function addKey(sdl, keyCode, charCode=0) {
+			CODEMAP[sdl] = keyCode;
+			if( charCode != 0 ) CHARMAP[sdl] = charCode;
+		}
+		var keys = [
+			//K.BACKSPACE
+			//K.TAB
+			//K.ENTER
+			1225 => K.LSHIFT,
+			1229 => K.RSHIFT,
+			1224 => K.LCTRL,
+			1228 => K.RCTRL,
+			1226 => K.LALT,
+			1230 => K.RALT,
+			// K.ESCAPE
+			// K.SPACE
+			1075 => K.PGUP,
+			1078 => K.PGDOWN,
+			1077 => K.END,
+			1074 => K.HOME,
+			1080 => K.LEFT,
+			1082 => K.UP,
+			1079 => K.RIGHT,
+			1081 => K.DOWN,
+			1073 => K.INSERT,
+			127 => K.DELETE,
+			//K.NUMBER_0-9
+			1098 => K.NUMPAD_0,
+			//K.A-Z
+			//K.F1-F12
+			1085 => K.NUMPAD_MULT,
+			1087 => K.NUMPAD_ADD,
+			1088 => K.NUMPAD_ENTER,
+			1086 => K.NUMPAD_SUB,
+			1099 => K.NUMPAD_DOT,
+			1084 => K.NUMPAD_DIV,
+		];
+
+		/*
+			SDL 2.0 does not allow to get the charCode from a key event.
+			let's for now do a simple mapping, even if not very efficient
+		*/
+		CHARMAP[1098] = "0".code;
+		CHARMAP[1085] = "*".code;
+		CHARMAP[1087] = "+".code;
+		CHARMAP[1088] = 13;
+		CHARMAP[1086] = "-".code;
+		CHARMAP[1084] = "/".code;
+		CHARMAP[1099] = ".".code;
+		CHARMAP[K.BACKSPACE] = 8;
+		CHARMAP[K.TAB] = 9;
+		CHARMAP[K.ENTER] = 13;
+		CHARMAP[K.SPACE] = 32;
+
+		for( i in 0...10 )
+			CHARMAP[K.NUMBER_0 + i] = "0".code + i;
+
+		for( i in 0...9 )
+			addKey(1089 + i, K.NUMPAD_1 + i, "1".code + i);
+		for( i in 0...26 )
+			addKey(97 + i, K.A + i, "a".code + i);
+		for( i in 0...12 )
+			addKey(1058 + i, K.F1 + i);
+		for( sdl in keys.keys() )
+			addKey(sdl, keys.get(sdl));
+		sdl.Sdl.init();
+		var size = haxe.macro.Compiler.getDefine("windowSize");
+		if( size != null ) {
+			var p = size.split("x");
+			windowWidth = Std.parseInt(p[0]);
+			windowHeight = Std.parseInt(p[1]);
+		}
+		win = new sdl.Window("", windowWidth, windowHeight);
+		init();
+		sdl.Sdl.loop(mainLoop,onEvent);
+		sdl.Sdl.quit();
+	}
+
+	#elseif hl
+
+	static var LOOP = null;
+
+	public static function exit() {
+		Sys.exit(0);
+	}
+
+	public static function start( init : Void -> Void ) {
+		init();
+		while( LOOP != null ) LOOP();
+	}
+
+	public static function setLoop( f : Void -> Void ) {
+		LOOP = f;
+	}
+
+	public static function setNativeCursor( c : Cursor ) {
+	}
+
+	static function get_screenDPI() {
+		return 72.;
+	}
+
+	static function get_lang() {
+		return "en";
+	}
+
+	static function get_isAndroid() {
+		return false;
+	}
+
+	public static function getClipboard() {
+		return "";
+	}
+
+	static function get_isIOS() {
+		return false;
+	}
+
+	static function get_isWindowed() {
+		return true;
+	}
+
+	static function get_isTouch() {
+		return false;
+	}
+
+	static function get_width() {
+		return 800;
+	}
+
+	static function get_height() {
+		return 600;
+	}
+
+	#end
+
+	public static function getDefaultFrameRate() : Float {
+		#if (flash || openfl)
+		return flash.Lib.current.stage.frameRate;
+		#else
+		return 60.;
+		#end
+	}
+
+}

+ 0 - 1
hxd/fmt/pak/Loader.hx

@@ -23,7 +23,6 @@ class Loader extends h2d.Sprite {
 	}
 
 	function render() {
-		s2d.checkEvents();
 		h3d.Engine.getCurrent().render(s2d);
 	}
 

+ 20 - 22
hxd/fmt/scn/Reader.hx

@@ -30,35 +30,33 @@ class Reader {
 				bits & 2 == 0 ? null : i.readFloat(),
 				bits & 4 == 0 ? null : i.readInt32()
 			);
-		case 3:
-			Reset;
-		case 4:
-			Resize(i.readInt32(), i.readInt32());
 		case 5:
+			Resize(i.readInt32(), i.readInt32());
+		case 6:
 			var id = i.readInt32();
 			var len = i.readInt32();
 			SelectShader(id, len == 0 ? null : i.read(len));
-		case 6:
-			Material(i.readInt32());
 		case 7:
-			UploadShaderBuffers(i.readByte() == 1, [for( k in 0...i.readInt32() ) i.readFloat()], [for( k in 0...i.readInt32() ) i.readFloat()]);
+			Material(i.readInt32());
 		case 8:
-			UploadShaderTextures([for( k in 0...i.readByte() ) i.readInt32()], [for( k in 0...i.readByte() ) i.readInt32()]);
+			UploadShaderBuffers(i.readByte() == 1, [for( k in 0...i.readInt32() ) i.readFloat()], [for( k in 0...i.readInt32() ) i.readFloat()]);
 		case 9:
+			UploadShaderTextures([for( k in 0...i.readByte() ) i.readInt32()], [for( k in 0...i.readByte() ) i.readInt32()]);
+		case 10:
 			var id = i.readInt32();
 			var len = i.readInt32();
 			AllocTexture(id, len < 0 ? null : i.readString(len), i.readInt32(), i.readInt32(), haxe.EnumFlags.ofInt(i.readInt32()));
-		case 10:
-			AllocIndexes(i.readInt32(), i.readInt32());
 		case 11:
-			AllocVertexes(i.readInt32(), i.readInt32(), i.readInt32(), haxe.EnumFlags.ofInt(i.readInt32()) );
+			AllocIndexes(i.readInt32(), i.readInt32());
 		case 12:
-			DisposeTexture(i.readInt32());
+			AllocVertexes(i.readInt32(), i.readInt32(), i.readInt32(), haxe.EnumFlags.ofInt(i.readInt32()) );
 		case 13:
-			DisposeIndexes(i.readInt32());
+			DisposeTexture(i.readInt32());
 		case 14:
-			DisposeVertexes(i.readInt32());
+			DisposeIndexes(i.readInt32());
 		case 15:
+			DisposeVertexes(i.readInt32());
+		case 16:
 			var id = i.readInt32();
 			var w = i.readInt32();
 			var h = i.readInt32();
@@ -67,21 +65,21 @@ class Reader {
 			var pixels = new hxd.Pixels(w, h, i.read(w * h * 4), format);
 			pixels.flags = flags;
 			UploadTexture(id, pixels, i.readInt32(), i.readByte());
-		case 16:
-			UploadIndexes(i.readInt32(), i.readInt32(), i.readInt32(), i.read(i.readInt32()) );
 		case 17:
-			UploadVertexes(i.readInt32(), i.readInt32(), i.readInt32(), i.read(i.readInt32()) );
+			UploadIndexes(i.readInt32(), i.readInt32(), i.readInt32(), i.read(i.readInt32()) );
 		case 18:
-			SelectBuffer(i.readInt32(), i.readByte() != 0 );
+			UploadVertexes(i.readInt32(), i.readInt32(), i.readInt32(), i.read(i.readInt32()) );
 		case 19:
-			SelectMultiBuffer([for( k in 0...i.readByte() ) { vbuf : i.readInt32(), offset : i.readByte() } ]);
+			SelectBuffer(i.readInt32(), i.readByte() != 0 );
 		case 20:
-			Draw(i.readInt32(), i.readInt32(), i.readInt32());
+			SelectMultiBuffer([for( k in 0...i.readByte() ) { vbuf : i.readInt32(), offset : i.readByte() } ]);
 		case 21:
-			RenderZone(i.readInt32(), i.readInt32(), i.readInt32(), i.readInt32());
+			Draw(i.readInt32(), i.readInt32(), i.readInt32());
 		case 22:
-			RenderTarget(i.readInt32());
+			RenderZone(i.readInt32(), i.readInt32(), i.readInt32(), i.readInt32());
 		case 23:
+			RenderTarget(i.readInt32());
+		case 24:
 			Present;
 		case x:
 			throw "Invalid SCN tag " + x;

+ 1 - 1
hxd/fs/BytesFileSystem.hx

@@ -54,7 +54,7 @@ class BytesFileEntry extends FileEntry {
 	override function exists( name : String ) : Bool return false;
 	override function get( name : String ) : FileEntry return null;
 
-	override function iterator() : hxd.impl.ArrayIterator<FileEntry> return new hxd.impl.ArrayIterator([]);
+	override function iterator() : hxd.impl.ArrayIterator<FileEntry> return new hxd.impl.ArrayIterator(new Array<FileEntry>());
 
 	override function get_size() return bytes.length;
 

+ 3 - 2
hxd/impl/Air3File.hx

@@ -1,7 +1,5 @@
 package hxd.impl;
 
-typedef File = Air3File;
-
 enum FileSeek {
 	SeekBegin;
 	SeekCur;
@@ -9,6 +7,9 @@ enum FileSeek {
 }
 
 #if air3
+
+typedef File = Air3File;
+
 class FileInput extends haxe.io.Input {
 
 	var fs : flash.filesystem.FileStream;

+ 1 - 1
hxd/res/Atlas.hx

@@ -40,7 +40,7 @@ class Atlas extends Resource {
 			var cont = getContents().keys();
 			name = cont.next();
 			if( cont.hasNext() )
-				throw "Altas has several items in it " + Lambda.array( { iterator : contents.keys } );
+				throw "Altas has several items in it " + Lambda.array( contents );
 		}
 		var c = getContents().get(name);
 		if( c == null )

+ 1 - 1
hxd/snd/Convert.hx

@@ -3,7 +3,7 @@ package hxd.snd;
 
 class Convert {
 
-	#if flash
+	#if (flash && air3)
 	static var processing = new Map();
 	#end
 

+ 31 - 0
samples/All.hx

@@ -0,0 +1,31 @@
+class All {
+	static function main() {
+		var cwd = Sys.getCwd();
+		var errored = [];
+		for( f in sys.FileSystem.readDirectory(".") ) {
+			if( !sys.FileSystem.isDirectory(f) )
+				continue;
+			var dir = cwd+"/"+f;
+			Sys.setCwd(dir);
+			for( d in sys.FileSystem.readDirectory(dir) ) {
+				if( !StringTools.endsWith(d,".hxml") ) continue;
+				var name = d.substr(0,-5);
+				if( f != name ) name = f+"/"+name;
+				var pass = false;
+				Sys.println(name);
+				try {
+					if( Sys.command("haxe "+d) == 0 ) pass = true;
+				} catch( e : Dynamic ) {
+					Sys.println(e);
+				}
+				if( !pass ) errored.push(name);
+			}
+			Sys.setCwd(cwd);
+		}
+		if( errored.length > 0 ) {
+			Sys.println(errored.length+" ERRORED : "+errored);
+			Sys.exit(1);
+		}
+		Sys.println("DONE");
+	}
+}

+ 1 - 60
samples/all.hxml

@@ -1,60 +1 @@
---macro Sys.println('2d')
---cwd 2d
-2d_swf.hxml
---next
-2d_swf.hxml
-
---next
---macro Sys.println('basic')
---cwd ../basic
-basic_swf.hxml
---next
-basic_wgl.hxml
-
---next
---macro Sys.println('bounds')
---cwd ../bounds
-bounds.hxml
-
---next
---macro Sys.println('col')
---cwd ../col
-col.hxml
-
---next
---macro Sys.println('comps')
---cwd ../comps
-comps.hxml
-
---next
---macro Sys.println('draw')
---cwd ../draw
-draw.hxml
-
---next
---macro Sys.println('lights')
---cwd ../lights
-lights.hxml
-
---next
---macro Sys.println('quat')
---cwd ../quat
-quat.hxml
-
---next
---macro Sys.println('sao')
---cwd ../sao
-sao.hxml
-
---next
---macro Sys.println('shadows')
---cwd ../shadows
-shadows.hxml
-
---next
---macro Sys.println('skin')
---cwd ../skin
-skin.hxml
-
---next
---macro Sys.println('done')
+--macro All.main()

+ 1 - 1
samples/col/TestCol.hx

@@ -63,7 +63,7 @@ class TestCol extends hxd.App {
 		var px = s2d.mouseX;
 		var py = s2d.mouseY;
 		#if js
-		new js.JQuery("#log").html(px+","+py+","+s2d.width+","+s2d.height);
+		new js.jquery.JQuery("#log").html(px+","+py+","+s2d.width+","+s2d.height);
 		#end
 
 		var r = new h2d.col.RoundRect(rrect.x, rrect.y, RW * 2, RH * 2, rrect.rotation);

+ 0 - 1
samples/comps/Comps.hx

@@ -22,7 +22,6 @@ class Comps {
 
 	function update() {
 		engine.render(scene);
-		scene.checkEvents();
 	}
 
 	static function main() {

+ 0 - 16
samples/interact/Main.hx

@@ -1,19 +1,3 @@
-class OptimizedIntersect implements h3d.col.RayCollider {
-
-	var sphere : h3d.col.Sphere;
-	// triangles
-
-	public function new( mesh : h3d.scene.Mesh ) {
-	}
-
-	public function rayIntersection( r : h3d.col.Ray, ?p : h3d.col.Point ) : Null<h3d.col.Point> {
-		//if( !checkRaySphere(r, sphere) )
-		//	return null;
-		// check triangles
-		// ...
-		return null;
-	}
-}
 
 class Main extends hxd.App {
 

+ 22 - 14
samples/network/Main.hx

@@ -2,19 +2,25 @@
 class Cursor implements hxd.net.NetworkSerializable {
 
 	@:s var color : Int;
+	@:s public var uid : Int;
 	@:s public var x(default, set) : Float;
 	@:s public var y(default, set) : Float;
 
 	var main : Main;
 	var bmp : h2d.Graphics;
 
-	public function new( color ) {
+	public function new( color, uid=0 ) {
 		this.color = color;
+		this.uid = uid;
 		init();
 		x = 0;
 		y = 0;
 	}
 
+	public function networkGetOwner() {
+		return this;
+	}
+
 	function set_x( v : Float ) {
 		if( v == x ) return v;
 		if( bmp != null ) bmp.x = v;
@@ -65,6 +71,10 @@ class Cursor implements hxd.net.NetworkSerializable {
 		// refresh bmp
 		this.x = x;
 		this.y = y;
+		if( uid == Main.inst.uid ) {
+			Main.inst.cursor = this;
+			Main.inst.host.self.ownerObject = this;
+		}
 	}
 
 }
@@ -76,7 +86,8 @@ class Main extends hxd.App {
 
 	public var host : hxd.net.LocalHost;
 	public var event : hxd.WaitEvent;
-	var cursor : Cursor;
+	public var uid : Int;
+	public var cursor : Cursor;
 
 	override function init() {
 		event = new hxd.WaitEvent();
@@ -84,12 +95,14 @@ class Main extends hxd.App {
 		host.setLogger(function(msg) log(msg));
 		try {
 			host.wait(HOST, PORT, function(c) {
-				log("Client Connected, sending data");
-
-				var cursorClient = new Cursor(0x0000FF);
-				c.fullSync(cursorClient);
-
+				log("Client Connected");
 			});
+			host.onMessage = function(c,uid:Int) {
+				log("Client identified ("+uid+")");
+				var cursorClient = new Cursor(0x0000FF, uid);
+				c.ownerObject = cursorClient;
+				c.sync();
+			};
 			log("Server Started");
 
 			start();
@@ -100,19 +113,14 @@ class Main extends hxd.App {
 			// we could not start the server
 			log("Connecting");
 
+			uid = 1 + Std.random(1000);
 			host.connect(HOST, PORT, function(b) {
 				if( !b ) {
 					log("Failed to connect to server");
 					return;
 				}
 				log("Connected to server");
-				host.onSync = function(c) {
-					log("Received " + c + " from server");
-					cursor = cast c;
-
-					log("Live");
-					host.makeAlive();
-				};
+				host.sendMessage(uid);
 			});
 		}
 	}

+ 2 - 2
samples/shadows/Main.hx

@@ -34,9 +34,9 @@ class Main extends hxd.App {
 		s3d.lightSystem.ambientLight.set(0.5, 0.5, 0.5);
 
 		dir = new h3d.scene.DirLight(new h3d.Vector(-0.3, -0.2, -1), s3d);
-
+		s3d.lightSystem.shadowLight = dir;
+		
 		shadow = cast(s3d.renderer.getPass("shadow"), h3d.pass.ShadowMap);
-		shadow.lightDirection = dir.direction;
 		shadow.blur.passes = 3;
 	}