2
0
ncannasse 8 жил өмнө
parent
commit
822cca36b6
2 өөрчлөгдсөн 45 нэмэгдсэн , 10 устгасан
  1. 24 7
      hxd/Stage.hl.hx
  2. 21 3
      hxd/System.hl.hx

+ 24 - 7
hxd/Stage.hl.hx

@@ -14,8 +14,10 @@ class Stage {
 	public var mouseLock(get, set) : Bool;
 	public var vsync(get, set) : Bool;
 
+	#if !psgl
 	var window : sdl.Window;
 	var fullScreenMode : sdl.Window.DisplayMode = Borderless;
+	#end
 	var windowWidth = 800;
 	var windowHeight = 600;
 	var curMouseX = 0;
@@ -30,7 +32,9 @@ class Stage {
 		this.windowHeight = height;
 		eventTargets = new List();
 		resizeEvents = new List();
+		#if !psgl
 		window = new sdl.Window(title, width, height);
+		#end
 	}
 
 	public dynamic function onClose() : Bool {
@@ -72,11 +76,15 @@ class Stage {
 	}
 
 	public function resize( width : Int, height : Int ) : Void {
+		#if !psgl
 		window.resize(width, height);
+		#end
 	}
 
 	public function setFullScreen( v : Bool ) : Void {
+		#if !psgl
 		window.displayMode = v ? fullScreenMode : Windowed;
+		#end
 	}
 
 	function get_mouseX() : Int {
@@ -99,6 +107,21 @@ class Stage {
 		return false;
 	}
 
+	function set_mouseLock(v:Bool) : Bool {
+		if( v ) throw "Not implemented";
+		return false;
+	}
+
+	#if psgl
+
+	function get_vsync() : Bool return true;
+
+	function set_vsync( b : Bool ) : Bool {
+		return true;
+	}
+
+	#else
+
 	function get_vsync() : Bool return window.vsync;
 
 	function set_vsync( b : Bool ) : Bool {
@@ -180,13 +203,6 @@ class Stage {
 		if( eh != null ) event(eh);
 	}
 
-
-	function set_mouseLock(v:Bool) : Bool {
-		if( v ) throw "Not implemented";
-		return false;
-	}
-
-
 	static function initChars() : Void {
 
 		inline function addKey(sdl, keyCode, charCode=0) {
@@ -258,6 +274,7 @@ class Stage {
 		for( sdl in keys.keys() )
 			addKey(sdl, keys.get(sdl));
 	}
+	#end
 
 	static var inst : Stage = null;
 	public static function getInstance() : Stage {

+ 21 - 3
hxd/System.hl.hx

@@ -41,10 +41,19 @@ class System {
 
 	static function mainLoop() : Void {
 		if( loopFunc != null ) loopFunc();
+		#if psgl
+		psgl.Api.present();
+		#else
 		@:privateAccess hxd.Stage.inst.window.present();
+		#end
 	}
 
 	public static function start( init : Void -> Void ) : Void {
+		#if psgl
+		if( !psgl.Api.init() ) return;
+		@:privateAccess Stage.inst = new Stage("", psgl.Api.width, psgl.Api.height);
+		init();
+		#else
 		sdl.Sdl.tick();
 		sdl.Sdl.init();
 		var width = 800;
@@ -62,10 +71,12 @@ class System {
 		@:privateAccess Stage.inst = new Stage(title, width, height);
 		init();
 		sdl.Sdl.defaultEventHandler = @:privateAccess Stage.inst.onEvent;
+		#end
 		haxe.MainLoop.add(mainLoop);
 	}
 
 	public static function setNativeCursor( c : Cursor ) : Void {
+		#if !psgl
 		if( c.equals(currentNativeCursor) )
 			return;
 		currentNativeCursor = c;
@@ -103,10 +114,15 @@ class System {
 			cursorVisible = true;
 			sdl.Cursor.show(true);
 		}
+		#end
 	}
 
 	public static function getDeviceName() : String {
+		#if psgl
+		return psgl.Api.name;
+		#else
 		return "PC/" + sdl.Sdl.getDevices()[0];
+		#end
 	}
 
 	public static function getDefaultFrameRate() : Float {
@@ -115,8 +131,10 @@ class System {
 
 	public static function getValue( s : SystemValue ) : Bool {
 		return switch( s ) {
+		#if !psgl
 		case IsWindowed:
 			return true;
+		#end
 		default:
 			return false;
 		}
@@ -144,9 +162,9 @@ class System {
 
 	// getters
 
-	static function get_width() : Int return sdl.Sdl.getScreenWidth();
-	static function get_height() : Int return sdl.Sdl.getScreenHeight();
-	static function get_platform() : Platform return PC;
+	static function get_width() : Int return #if psgl psgl.Api.width #else sdl.Sdl.getScreenWidth() #end;
+	static function get_height() : Int return #if psgl psgl.Api.height #else sdl.Sdl.getScreenHeight() #end;
+	static function get_platform() : Platform return #if psgl Console #else PC #end;
 	static function get_screenDPI() : Int return 72; // TODO : SDL ?
 
 }