@@ -40,12 +40,20 @@ namespace FDK;
4040public abstract class Game : IDisposable {
4141 public static GL Gl { get ; private set ; }
4242 public static Silk . NET . Core . Contexts . IGLContext Context { get ; private set ; }
43+
44+ private static string [ ] parameters ;
45+ private static string GetParameterValue ( string parameter = "" , string parameter_full = "" ) {
46+ if ( parameters . Length == 0 ) return "" ;
47+ int index = parameters . Contains ( parameter ) || parameters . Contains ( parameter_full )
48+ ? Array . FindIndex ( parameters , x => x . Equals ( parameter ) || x . Equals ( parameter_full ) )
49+ : - 1 ;
50+ return index > - 1 && parameters . Length > index ? parameters [ index + 1 ] : "" ;
51+ }
4352
4453 public static ImGuiController ImGuiController { get ; private set ; }
4554 public static ImGuiIOPtr ImGuiIO { get ; private set ; }
4655 private static CTexture ImGuiFontAtlas ;
4756
48- static string _test = "" ;
4957 public static void InitImGuiController ( IView window , IInputContext context ) {
5058 if ( ImGuiController != null ) return ;
5159
@@ -265,8 +273,9 @@ private RawImage GetIconData(string fileName) {
265273 /// <summary>
266274 /// Initializes a new instance of the <see cref="Game"/> class.
267275 /// </summary>
268- protected Game ( string iconFileName ) {
276+ protected Game ( string iconFileName , params string [ ] args ) {
269277 strIconFileName = iconFileName ;
278+ parameters = args ;
270279
271280 MainThreadID = Thread . CurrentThread . ManagedThreadId ;
272281 Configuration ( ) ;
@@ -287,15 +296,27 @@ protected Game(string iconFileName) {
287296 options . WindowBorder = WindowBorder . Resizable ;
288297 options . Title = Text ;
289298
299+ #region Override Windowing
300+ string windowing_override = GetParameterValue ( "-w" , "--windowing" ) ;
301+ #endregion
290302
291303 // Use SDL on Linux with Wayland, otherwise use GLFW for everything else
292- if ( OperatingSystem . IsLinux ( ) && Environment . GetEnvironmentVariable ( "XDG_SESSION_TYPE" ) == "wayland" ) {
293- Silk . NET . Windowing . Sdl . SdlWindowing . Use ( ) ;
304+ if ( ( OperatingSystem . IsLinux ( ) && Environment . GetEnvironmentVariable ( "XDG_SESSION_TYPE" ) == "wayland" && windowing_override != "glfw" )
305+ || windowing_override == "sdl" ) {
306+ Silk . NET . Windowing . Sdl . SdlWindowing . Use ( ) ;
307+ Console . WriteLine ( "SDL selected for Windowing" ) ;
294308 } else {
295- Silk . NET . Windowing . Glfw . GlfwWindowing . Use ( ) ;
309+ Silk . NET . Windowing . Glfw . GlfwWindowing . Use ( ) ;
310+ Console . WriteLine ( "GLFW selected for Windowing" ) ;
296311 }
297312
298- Window_ = Window . Create ( options ) ;
313+ try {
314+ Window_ = Window . Create ( options ) ;
315+ }
316+ catch {
317+ Console . WriteLine ( "The window failed to be created.\n You can attempt to fix this by overriding the default windowing.\n Try launching OpenTaiko with args, using '-w glfw' to force GLFW or '-w sdl' to force SDL." ) ;
318+ throw ;
319+ }
299320
300321 ViewPortSize . X = Window_ . Size . X ;
301322 ViewPortSize . Y = Window_ . Size . Y ;
@@ -416,7 +437,20 @@ public void Window_Load() {
416437
417438 Context = Window_ . GLContext ;
418439 } else {
419- Context = new AngleContext ( GraphicsDeviceType_ , Window_ ) ;
440+ #region Override Platform
441+ GraphicsDeviceType_ = GetParameterValue ( "-p" , "--platform" ) switch {
442+ "opengl" => AnglePlatformType . OpenGL ,
443+ "opengles" => AnglePlatformType . OpenGLES ,
444+ "d3d9" => AnglePlatformType . D3D9 ,
445+ "d3d11" => AnglePlatformType . D3D11 ,
446+ "vulkan" => AnglePlatformType . Vulkan ,
447+ "metal" => AnglePlatformType . Metal ,
448+ _ => GraphicsDeviceType_
449+ } ;
450+ Console . WriteLine ( "Platform set to " + GraphicsDeviceType_ ) ;
451+ #endregion
452+
453+ Context = new AngleContext ( GraphicsDeviceType_ , Window_ , GetParameterValue ( "-f" , "--flag" ) ) ;
420454
421455 Context . MakeCurrent ( ) ;
422456 }
0 commit comments