Ver código fonte

added pad and listeners

Nicolas Cannasse 5 anos atrás
pai
commit
24193f3d52
3 arquivos alterados com 25 adições e 0 exclusões
  1. 1 0
      common.hxml
  2. 9 0
      hide/Ide.hx
  3. 15 0
      hide/comp/Scene.hx

+ 1 - 0
common.hxml

@@ -11,4 +11,5 @@
 -D multidriver
 -D editor
 -D no-deprecation-warnings
+-D manual_sync_pad
 -cp libs

+ 9 - 0
hide/Ide.hx

@@ -23,6 +23,8 @@ class Ide {
 	public var isCDB = false;
 	public var isDebugger = false;
 
+	public var gamePad(default,null) : hxd.Pad;
+
 	var databaseFile : String;
 	var databaseDiff : String;
 	var pakFile : hxd.fmt.pak.FileSystem;
@@ -56,6 +58,7 @@ class Ide {
 	static var firstInit = true;
 
 	function new() {
+		initPad();
 		isCDB = Sys.getEnv("HIDE_START_CDB") == "1" || nw.App.manifest.name == "CDB";
 		isDebugger = Sys.getEnv("HIDE_DEBUG") == "1";
 		function wait() {
@@ -68,6 +71,11 @@ class Ide {
 		wait();
 	}
 
+	function initPad() {
+		gamePad = hxd.Pad.createDummy();
+		hxd.Pad.wait((p) -> gamePad = p);
+	}
+
 	function startup() {
 		inst = this;
 		window = nw.Window.get();
@@ -381,6 +389,7 @@ class Ide {
 
 	function mainLoop() {
 		hxd.Timer.update();
+		@:privateAccess hxd.Pad.syncPads();
 		for( f in updates )
 			f();
 	}

+ 15 - 0
hide/comp/Scene.hx

@@ -61,6 +61,7 @@ class Scene extends Component implements h3d.IDrawable {
 	var pathsMap = new Map<String, String>();
 	var cleanup = new Array<Void->Void>();
 	var defaultCamera : h3d.Camera;
+	var listeners = new Array<Float -> Void>();
 	public var config : hide.Config;
 	public var engine : h3d.Engine;
 	public var width(get, never) : Int;
@@ -98,6 +99,18 @@ class Scene extends Component implements h3d.IDrawable {
 		engine.dispose();
 	}
 
+	public function addListener(f) {
+		listeners.push(f);
+	}
+
+	public function removeListener(f) {
+		for( f2 in listeners )
+			if( Reflect.compareMethods(f,f2) ) {
+				listeners.remove(f2);
+				break;
+			}
+	}
+
 	function delayedInit() {
 		canvas.id = "webgl";
 		window = @:privateAccess new hxd.Window(canvas);
@@ -185,6 +198,8 @@ class Scene extends Component implements h3d.IDrawable {
 		var dt = hxd.Timer.tmod * speed / 60;
 		s2d.setElapsedTime(dt);
 		s3d.setElapsedTime(dt);
+		for( f in listeners )
+			f(dt);
 		onUpdate(dt);
 		engine.render(this);
 	}