Browse Source

added cpp build and openfl events

Nicolas Cannasse 12 năm trước cách đây
mục cha
commit
c48c167ae3
10 tập tin đã thay đổi với 133 bổ sung23 xóa
  1. 1 0
      .gitignore
  2. 14 0
      engine.hxml
  3. 2 1
      engine.hxproj
  4. 13 5
      h3d/Engine.hx
  5. 1 1
      h3d/impl/DebugGL.hx
  6. 1 1
      h3d/mat/PartMaterial.hx
  7. 1 1
      h3d/scene/Image.hx
  8. 42 4
      hxd/Stage.hx
  9. 28 9
      hxd/System.hx
  10. 30 1
      hxd/res/LocalFileSystem.hx

+ 1 - 0
.gitignore

@@ -9,3 +9,4 @@
 /engine.js
 /engine.js.map
 /samples/2d/demo.js
+/bin

+ 14 - 0
engine.hxml

@@ -18,3 +18,17 @@
 --macro include('h3d')
 --macro include('h2d')
 --macro include('hxd',true,['hxd.res.FileTree'])
+--next
+-cpp bin
+-lib format
+-lib openfl-native
+-debug
+--macro allowPackage('flash')
+-D h3d
+-D openfl
+-D resourcesPath=samples/res
+-cp samples/basic
+-main Test
+--macro include('h3d')
+--macro include('h2d')
+--macro include('hxd',true,['hxd.res.FileTree'])

+ 2 - 1
engine.hxproj

@@ -23,7 +23,7 @@
     <option flashStrict="True" />
     <option mainClass="Test" />
     <option enabledebug="False" />
-    <option additional="--macro include('h3d')&#xA;--macro include('h2d')&#xA;--macro include('hxd',true,['hxd.res.FileTree'])&#xA;-lib format&#xA;-D resourcesPath=samples/res&#xA;&#xA;--next&#xA;&#xA;-swf engine.swf&#xA;-swf-header 800:600:60:000000&#xA;-swf-version 11.6&#xA;-lib hxsl&#xA;-D h3d&#xA;-D resourcesPath=samples/res&#xA;-cp samples/basic&#xA;-main Test&#xA;--macro include('h3d')&#xA;--macro include('h2d')&#xA;--macro include('hxd',true,['hxd.res.FileTree'])" />
+    <option additional="--macro include('h3d')&#xA;--macro include('h2d')&#xA;--macro include('hxd',true,['hxd.res.FileTree'])&#xA;-lib format&#xA;-D resourcesPath=samples/res&#xA;&#xA;--next&#xA;&#xA;-swf engine.swf&#xA;-swf-header 800:600:60:000000&#xA;-swf-version 11.6&#xA;-lib hxsl&#xA;-D h3d&#xA;-D resourcesPath=samples/res&#xA;-cp samples/basic&#xA;-main Test&#xA;--macro include('h3d')&#xA;--macro include('h2d')&#xA;--macro include('hxd',true,['hxd.res.FileTree'])&#xA;&#xA;--next&#xA;-cpp bin&#xA;-lib format&#xA;-lib openfl-native&#xA;-debug&#xA;--macro allowPackage('flash')&#xA;-D h3d&#xA;-D openfl&#xA;-D resourcesPath=samples/res&#xA;-cp samples/basic&#xA;-main Test&#xA;--macro include('h3d')&#xA;--macro include('h2d')&#xA;--macro include('hxd',true,['hxd.res.FileTree'])" />
   </build>
   <!-- haxelib libraries -->
   <haxelib>
@@ -36,6 +36,7 @@
   <!-- Paths to exclude from the Project Explorer tree -->
   <hiddenPaths>
     <hidden path="engine.hxml" />
+    <hidden path="obj" />
   </hiddenPaths>
   <!-- Executed before build -->
   <preBuildCommand />

+ 13 - 5
h3d/Engine.hx

@@ -36,10 +36,19 @@ class Engine {
 	@:allow(h3d)
 	var curProjMatrix : h3d.Matrix;
 
+	@:access(hxd.Stage)
 	public function new( hardware = true, aa = 0 ) {
 		this.hardware = hardware;
 		this.antiAlias = aa;
 		this.autoResize = true;
+		#if openfl
+		hxd.Stage.openFLBoot(start);
+		#else
+		start();
+		#end
+	}
+	
+	function start() {
 		fullScreen = !hxd.System.isWindowed;
 		var stage = hxd.Stage.getInstance();
 		realFps = stage.getFrameRate();
@@ -185,7 +194,7 @@ class Engine {
 		hardware = driver.isHardware();
 		set_debug(debug);
 		set_fullScreen(fullScreen);
-		resize(width, height, antiAlias);
+		resize(width, height);
 		if( disposed )
 			onContextLost();
 		else
@@ -202,7 +211,7 @@ class Engine {
 		if( autoResize && !driver.isDisposed() ) {
 			var w = hxd.System.width, h = hxd.System.height;
 			if( w != width || h != height )
-				resize(w, h, antiAlias);
+				resize(w, h);
 			onResized();
 		}
 	}
@@ -217,14 +226,13 @@ class Engine {
 	public dynamic function onResized() {
 	}
 
-	public function resize(width, height, aa = 0) {
+	public function resize(width, height) {
 		// minimum 32x32 size
 		if( width < 32 ) width = 32;
 		if( height < 32 ) height = 32;
 		this.width = width;
 		this.height = height;
-		this.antiAlias = aa;
-		if( !driver.isDisposed() ) driver.resize(width, height, aa);
+		if( !driver.isDisposed() ) driver.resize(width, height);
 	}
 
 	public function begin() {

+ 1 - 1
h3d/impl/DebugGL.hx

@@ -6,7 +6,7 @@ private typedef GL = js.html.webgl.GL;
 import openfl.gl.GL;
 #end
 
-#if !macro
+#if (!macro && (js || cpp))
 @:build(h3d.impl.DebugGL.buildProxy())
 #end
 class DebugGL {

+ 1 - 1
h3d/mat/PartMaterial.hx

@@ -72,7 +72,7 @@ private class PartShader extends h3d.impl.Shader {
 	public var hasRotation : Bool;
 	public var hasSize : Bool;
 	public var partSize : h3d.Vector;
-	public var frameCount : Float;
+	public var frameCount : Null<Float>;
 	public var tex : h3d.mat.Texture;
 
 #end

+ 1 - 1
h3d/scene/Image.hx

@@ -16,7 +16,7 @@ private class ImageShader extends h3d.impl.Shader {
 			out = tex.get(tuv);
 		}
 	}
-	#elseif js
+	#elseif (js || cpp)
 	static var VERTEX = "TODO";
 	static var FRAGMENT = "TODO";
 	public var tex : h3d.mat.Texture;

+ 42 - 4
hxd/Stage.hx

@@ -2,7 +2,7 @@ package hxd;
 
 class Stage {
 	
-	#if flash
+	#if (flash || openfl)
 	var stage : flash.display.Stage;
 	var fsDelayed : Bool;
 	#end
@@ -17,7 +17,7 @@ class Stage {
 	function new() {
 		eventTargets = new List();
 		resizeEvents = new List();
-		#if flash
+		#if (flash || openfl)
 		stage = flash.Lib.current.stage;
 		stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
 		stage.addEventListener(flash.events.Event.RESIZE, onResize);
@@ -67,7 +67,7 @@ class Stage {
 	}
 	
 	public function getFrameRate() : Float {
-		#if flash
+		#if (flash || openfl)
 		return stage.frameRate;
 		#else
 		return 60.;
@@ -98,7 +98,7 @@ class Stage {
 		return inst;
 	}
 	
-#if flash
+#if (flash || openfl)
 
 	inline function get_mouseX() {
 		return stage.mouseX;
@@ -251,4 +251,42 @@ class Stage {
 
 #end
 
+#if openfl
+
+	static function openFLBoot(callb) {
+		// init done with OpenFL ApplicationMain
+		if( flash.Lib.current.stage != null ) {
+			callb();
+			return;
+		}
+		// init done by hand
+		var width = 750, height = 450, fps = 60, bgColor = 0x808080;
+		flash.Lib.create(
+			function() {
+				flash.Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
+				flash.Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
+				flash.Lib.current.loaderInfo = flash.display.LoaderInfo.create (null);
+				callb();
+			},
+			width, height, fps, bgColor,
+			(true ? flash.Lib.HARDWARE : 0) |
+			(true ? flash.Lib.ALLOW_SHADERS : 0) |
+			(true ? flash.Lib.REQUIRE_SHADERS : 0) |
+			(false ? flash.Lib.DEPTH_BUFFER : 0) |
+			(false ? flash.Lib.STENCIL_BUFFER : 0) |
+			(true ? flash.Lib.RESIZABLE : 0) |
+			(false ? flash.Lib.BORDERLESS : 0) |
+			(false ? flash.Lib.VSYNC : 0) |
+			(false ? flash.Lib.FULLSCREEN : 0) |
+			(0 == 4 ? flash.Lib.HW_AA_HIRES : 0) |
+			(0 == 2 ? flash.Lib.HW_AA : 0),
+			"h3d", null
+			#if mobile
+			, null /* ScaledStage : TODO? */
+			#end
+		);
+	}
+
+#end
+
 }

+ 28 - 9
hxd/System.hx

@@ -3,7 +3,7 @@ package hxd;
 enum Cursor {
 	Default;
 	Button;
-	Hand;
+	Move;
 	TextInput;
 }
 
@@ -76,7 +76,7 @@ class System {
 		flash.ui.Mouse.cursor = switch( c ) {
 		case Default: "auto";
 		case Button: "button";
-		case Hand: "hand";
+		case Move: "hand";
 		case TextInput: "ibeam";
 		}
 	}
@@ -137,7 +137,14 @@ class System {
 	}
 
 	public static function setCursor( c : Cursor ) {
-		throw "TODO";
+		var canvas = js.Browser.document.getElementById("webgl");
+		if( canvas != null )
+			canvas.style.cursor = switch( c ) {
+			case Default: "auto";
+			case Button: "pointer";
+			case Move: "move";
+			case TextInput: "text";
+			};
 	}
 	
 	static function get_lang() {
@@ -181,19 +188,29 @@ class System {
 	}
 
 	public static function setCursor( c : Cursor ) {
-		throw "TODO";
+		/* not supported by openFL
+		flash.ui.Mouse.cursor = switch( c ) {
+		case Default: "auto";
+		case Button: "button";
+		case Move: "hand";
+		case TextInput: "ibeam";
+		}*/
 	}
 	
 	static function get_lang() {
-		return "en";
+		return flash.system.Capabilities.language.split("-")[0];
 	}
 	
 	static function get_screenDPI() {
-		return 72.;
+		return flash.system.Capabilities.screenDPI;
 	}
 	
 	static function get_isAndroid() {
+		#if android
+		return true;
+		#else
 		return false;
+		#end
 	}
 	
 	static function get_isWindowed() {
@@ -205,11 +222,13 @@ class System {
 	}
 	
 	static function get_width() {
-		return 100;
+		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() {
-		return 100;
+		var Cap = flash.system.Capabilities;
+		return isWindowed ? flash.Lib.current.stage.stageHeight : Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionY : Cap.screenResolutionX);
 	}
 
 	#end

+ 30 - 1
hxd/res/LocalFileSystem.hx

@@ -1,5 +1,7 @@
 package hxd.res;
 
+#if (air3 || sys)
+
 @:allow(hxd.res.LocalFileSystem)
 @:access(hxd.res.LocalFileSystem)
 private class LocalEntry extends FileEntry {
@@ -298,4 +300,31 @@ class LocalFileSystem implements FileSystem {
 		#end
 	}
 	
-}
+}
+
+#else
+
+class LocalFileSystem implements FileSystem {
+	
+	public function new( dir : String ) {
+		#if flash
+		if( flash.system.Capabilities.playerType == "Desktop" )
+			throw "Please compile with -lib air3";
+		#end
+		throw "Local file system is not supported for this platform";
+	}
+	
+	public function exists(path:String) {
+		return false;
+	}
+	
+	public function get(path:String) : FileEntry {
+		return null;
+	}
+
+	public function getRoot() : FileEntry {
+		return null;
+	}
+}
+
+#end