diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..eeb01fb2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "SDL2-CS"] + path = SDL2-CS + url = https://github.com/flibitijibibo/SDL2-CS diff --git a/Common.cs b/Common.cs index 8dbfa9e2..49696d2c 100644 --- a/Common.cs +++ b/Common.cs @@ -1029,7 +1029,7 @@ private static void AddGameDirectory( string dir ) // for( int i = 0; ; i++ ) { - string pakfile = String.Format( "{0}/pak{1}.pak", dir, i ); + string pakfile = String.Format( "{0}/PAK{1}.PAK", dir, i ); pack_t pak = LoadPackFile( pakfile ); if( pak == null ) break; @@ -1769,7 +1769,7 @@ internal class searchpath_t public searchpath_t( string path ) { - if( path.EndsWith( ".pak" ) ) + if( path.EndsWith( ".PAK" ) ) { this.pack = Common.LoadPackFile( path ); if( this.pack == null ) diff --git a/Console.cs b/Console.cs index b1143fcf..09471cae 100644 --- a/Console.cs +++ b/Console.cs @@ -225,6 +225,8 @@ public static void Print( string fmt, params object[] args ) { string msg = ( args.Length > 0 ? String.Format( fmt, args ) : fmt ); + Console.WriteLine(msg); // Debug stuff + // log all messages to file if( _DebugLog ) DebugLog( msg ); diff --git a/Input.cs b/Input.cs index b81a2e8a..b49d4802 100644 --- a/Input.cs +++ b/Input.cs @@ -111,7 +111,7 @@ public static void ActivateMouse() //SetCapture(mainwindow); - //Cursor.Clip = MainForm.Instance.Bounds; + //Cursor.Clip = MainWindow.Instance.Bounds; _IsMouseActive = true; } diff --git a/MainWindow.cs b/MainWindow.cs index de29b463..491a5366 100644 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -24,6 +24,7 @@ using OpenTK; using OpenTK.Graphics; using OpenTK.Input; +using SDL2; namespace SharpQuake { @@ -106,11 +107,42 @@ protected override void OnFocusedChanged(EventArgs e) protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { + // Turned this of as I hate this prompt so much /*if (this.ConfirmExit) { - e.Cancel = (MessageBox.Show("Are you sure you want to quit?", - "Confirm Exit", MessageBoxButtons.YesNo) != DialogResult.Yes); - }*/ + int button_id; + SDL.SDL_MessageBoxButtonData[] buttons = new SDL.SDL_MessageBoxButtonData[2]; + + buttons[0].flags = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT; + buttons[0].buttonid = 0; + buttons[0].text = "cancel"; + + buttons[1].flags = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT; + buttons[1].buttonid = 1; + buttons[1].text = "yes"; + + SDL.SDL_MessageBoxData messageBoxData = new SDL.SDL_MessageBoxData(); + messageBoxData.flags = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION; + messageBoxData.window = IntPtr.Zero; + messageBoxData.title = "test"; + messageBoxData.message = "test"; + messageBoxData.numbuttons = 2; + messageBoxData.buttons = buttons; + SDL.SDL_ShowMessageBox(ref messageBoxData, out button_id); + + if (button_id == -1) + { + "error displaying message box" + } + else + { + "selection was %s" + } + + // e.Cancel = (MessageBox.Show("Are you sure you want to quit?", + //"Confirm Exit", MessageBoxButtons.YesNo) != DialogResult.Yes); + } + */ base.OnClosing(e); } @@ -137,7 +169,7 @@ private static MainWindow CreateInstance(Size size, GraphicsMode mode, bool full { if (_Instance != null) { - throw new Exception("MainForm instance is already created!"); + throw new Exception("Game instance is already created!"); } return new MainWindow(size, mode, fullScreen); } @@ -193,55 +225,54 @@ private static void HandleException(Exception ex) throw new Exception("Fatal error!", ex); Instance.CursorVisible = true; - //SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, "Fatal error!", ex.Message, IntPtr.Zero); //MessageBox.Show(ex.Message); + SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR, "Fatal error!", ex.Message, IntPtr.Zero); //MessageBox.Show(ex.Message); SafeShutdown(); } [STAThread] private static int Main(string[] args) { - //workaround for SDL2 mouse input issues + //Workaround for SDL2 mouse input issues var options = new ToolkitOptions(); options.Backend = PlatformBackend.PreferNative; - options.EnableHighResolution = true; //just for testing + options.EnableHighResolution = true; //Just for testing Toolkit.Init(options); - #if !DEBUG try { #endif - // select display device - _DisplayDevice = DisplayDevice.Default; + // select display device + _DisplayDevice = DisplayDevice.Default; - if (File.Exists(DumpFilePath)) - File.Delete(DumpFilePath); + if (File.Exists(DumpFilePath)) + File.Delete(DumpFilePath); - quakeparms_t parms = new quakeparms_t(); + quakeparms_t parms = new quakeparms_t(); - parms.basedir = AppDomain.CurrentDomain.BaseDirectory; //Application.StartupPath; + parms.basedir = AppDomain.CurrentDomain.BaseDirectory; //Application.StartupPath; - string[] args2 = new string[args.Length + 1]; - args2[0] = String.Empty; - args.CopyTo(args2, 1); + string[] args2 = new string[args.Length + 1]; + args2[0] = String.Empty; + args.CopyTo(args2, 1); - Common.InitArgv(args2); + Common.InitArgv(args2); - parms.argv = new string[Common.Argc]; - Common.Args.CopyTo(parms.argv, 0); + parms.argv = new string[Common.Argc]; + Common.Args.CopyTo(parms.argv, 0); - if (Common.HasParam("-dedicated")) - throw new QuakeException("Dedicated server mode not supported!"); + if (Common.HasParam("-dedicated")) + throw new QuakeException("Dedicated server mode not supported!"); - Size size = new Size(1280, 720); - GraphicsMode mode = new GraphicsMode(); - using (MainWindow form = MainWindow.CreateInstance(size, mode, false)) - { - Con.DPrint("Host.Init\n"); - Host.Init(parms); - Instance.CursorVisible = false; //hides mouse cursor during main menu on start up - form.Run(); - } - Host.Shutdown(); + Size size = new Size(1280, 720); + GraphicsMode mode = new GraphicsMode(); + using (MainWindow form = MainWindow.CreateInstance(size, mode, false)) + { + Con.DPrint("Host.Init\n"); + Host.Init(parms); + Instance.CursorVisible = false; //Hides mouse cursor during main menu on start up + form.Run(); + } + Host.Shutdown(); #if !DEBUG } catch (QuakeSystemError se) diff --git a/QuakeDef.cs b/QuakeDef.cs index 34b25fdf..deed046b 100644 --- a/QuakeDef.cs +++ b/QuakeDef.cs @@ -144,7 +144,7 @@ internal static class QDef public const float LINUX_VERSION = 1.30f; public const float X11_VERSION = 1.10f; - public const string GAMENAME = "id1"; // directory to look in by default + public const string GAMENAME = "Id1"; // directory to look in by default public const int MAX_NUM_ARGVS = 50; diff --git a/README.md b/README.md index f60cac6d..f15739e6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ SharpQuake is [GLQuake](https://github.com/dpteam/GLQuake3D) rewritten in C# usi ### Dependencies * OpenTK 3.0.1 -* [OpenTK Dependencies](https://github.com/opentk/opentk-dependencies/tree/master) (for target architecture) +* [OpenAL](https://www.openal.org/downloads/) (Windows) / libopenal on Linux +* [SDL2](https://www.libsdl.org/download-2.0.php) (Windows and macOS) / libsdl2-2.0 on Linux (Runtime binaries) ### Building @@ -15,12 +16,14 @@ SharpQuake is [GLQuake](https://github.com/dpteam/GLQuake3D) rewritten in C# usi 1) **Add the OpenTK nuget package with the package manager console in visual studio.** - `Install-Package OpenTK -Version 3.0.1` -2) **Add openal32.dll and libEGL.dll for your target architecture in your output directory (defaults to `/Quake`).** - - See link "OpenTK Dependencies" under Dependencies header above -3) **Add ld1, hipnotic, and rogue (minimum ld1) data directories to `/Quake`.** +2) **Initialize git submodules** + +3) **Add dependencies for your target architecture in your output directory (defaults to `/Quake`).** + - See links under dependencies header above +4) **Add ld1, hipnotic, and rogue (minimum ld1) data directories to `/Quake`.** - You only need the `\pak0.pak`, etc. and `\config.cfg` files of each directory if copying from a steam install. -4) **Build solution.** +5) **Build solution.** ### Running diff --git a/SDL2-CS b/SDL2-CS new file mode 160000 index 00000000..162bbe0b --- /dev/null +++ b/SDL2-CS @@ -0,0 +1 @@ +Subproject commit 162bbe0ba4adaff178210e331e87941e15298b4b diff --git a/SharpQuake.csproj b/SharpQuake.csproj index 017c74d4..65b12efa 100644 --- a/SharpQuake.csproj +++ b/SharpQuake.csproj @@ -6,7 +6,7 @@ 8.0.30703 2.0 {0FC3229A-25C5-49F9-80C6-237A3BC319B1} - WinExe + Exe Properties SharpQuake SharpQuake @@ -119,6 +119,10 @@ + + + + @@ -161,6 +165,17 @@ Settings.settings True + + + + + + + + + + + @@ -176,6 +191,9 @@ + + +