Skip to content

Commit

Permalink
Several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Memorix101 committed Apr 28, 2019
1 parent c508617 commit fd6f650
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "SDL2-CS"]
path = SDL2-CS
url = https://github.com/flibitijibibo/SDL2-CS
4 changes: 2 additions & 2 deletions Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void ActivateMouse()

//SetCapture(mainwindow);

//Cursor.Clip = MainForm.Instance.Bounds;
//Cursor.Clip = MainWindow.Instance.Bounds;

_IsMouseActive = true;
}
Expand Down
95 changes: 63 additions & 32 deletions MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using SDL2;

namespace SharpQuake
{
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion QuakeDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 `<project root>/Quake`).**
- See link "OpenTK Dependencies" under Dependencies header above
3) **Add ld1, hipnotic, and rogue (minimum ld1) data directories to `<project root>/Quake`.**
2) **Initialize git submodules**

3) **Add dependencies for your target architecture in your output directory (defaults to `<project root>/Quake`).**
- See links under dependencies header above
4) **Add ld1, hipnotic, and rogue (minimum ld1) data directories to `<project root>/Quake`.**
- You only need the `<mod>\pak0.pak`, etc. and `<mod>\config.cfg` files of each directory if copying from a steam install.

4) **Build solution.**
5) **Build solution.**

### Running

Expand Down
1 change: 1 addition & 0 deletions SDL2-CS
Submodule SDL2-CS added at 162bbe
20 changes: 19 additions & 1 deletion SharpQuake.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0FC3229A-25C5-49F9-80C6-237A3BC319B1}</ProjectGuid>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SharpQuake</RootNamespace>
<AssemblyName>SharpQuake</AssemblyName>
Expand Down Expand Up @@ -119,6 +119,10 @@
<Compile Include="Sbar.cs" />
<Compile Include="Screen.cs" />
<Compile Include="ScreenDraw.cs" />
<Compile Include="SDL2-CS\src\SDL2.cs" />
<Compile Include="SDL2-CS\src\SDL2_image.cs" />
<Compile Include="SDL2-CS\src\SDL2_mixer.cs" />
<Compile Include="SDL2-CS\src\SDL2_ttf.cs" />
<Compile Include="Server.cs" />
<Compile Include="ServerMain.cs" />
<Compile Include="ServerMove.cs" />
Expand Down Expand Up @@ -161,6 +165,17 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="SDL2-CS\.gitignore" />
<None Include="SDL2-CS\.gitlab-ci.yml" />
<None Include="SDL2-CS\gitlab-ci\build-net461.sh" />
<None Include="SDL2-CS\gitlab-ci\build-netcore.sh" />
<None Include="SDL2-CS\gitlab-ci\deploy.sh" />
<None Include="SDL2-CS\gitlab-ci\package.sh" />
<None Include="SDL2-CS\gitlab-ci\SDL2-CS.nuspec" />
<None Include="SDL2-CS\LICENSE" />
<None Include="SDL2-CS\Makefile" />
<None Include="SDL2-CS\README" />
<None Include="SDL2-CS\SDL2-CS.dll.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
Expand All @@ -176,6 +191,9 @@
</ItemGroup>
<ItemGroup>
<Content Include="quake.ico" />
<Content Include="SDL2-CS\SDL2-CS.Core.csproj" />
<Content Include="SDL2-CS\SDL2-CS.csproj" />
<Content Include="SDL2-CS\SDL2-CS.sln" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
13 changes: 12 additions & 1 deletion Vid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,19 @@ public static void SetMode( int modenum, byte[] palette )
MainWindow form = MainWindow.Instance;
if( _Windowed )
{
try
{
dev.ChangeResolution(mode.width, mode.height, mode.bpp, mode.refreshRate);
}
catch (Exception ex)
{
Sys.Error("Couldn't set video mode: " + ex.Message);
}
form.WindowState = WindowState.Normal;
form.WindowBorder = WindowBorder.Fixed;

/*form.WindowState = WindowState.Normal;
form.WindowBorder = WindowBorder.Fixed;
form.Location = new Point( ( mode.width - form.Width ) / 2, ( mode.height - form.Height ) / 2 );
if( _WindowedMouse.Value != 0 && Key.Destination == keydest_t.key_game )
{
Expand All @@ -360,7 +371,7 @@ public static void SetMode( int modenum, byte[] palette )
{
Input.DeactivateMouse();
Input.ShowMouse();
}
}*/
}
else
{
Expand Down

0 comments on commit fd6f650

Please sign in to comment.