Browse Source
More code organization; putting QuakeParms in its own file and encapsulating the nitty gritty unmanaged code details, to make things overall more readable.
console
More code organization; putting QuakeParms in its own file and encapsulating the nitty gritty unmanaged code details, to make things overall more readable.
console
3 changed files with 67 additions and 49 deletions
@ -0,0 +1,60 @@ |
|||||
|
using System; |
||||
|
using System.Runtime.InteropServices; |
||||
|
|
||||
|
[StructLayout(LayoutKind.Sequential, Pack = 0)] |
||||
|
public class QuakeParms |
||||
|
{ |
||||
|
private const int MaxArgs = 50; // Corresponds with MAX_NUM_ARGVS in engine
|
||||
|
|
||||
|
[MarshalAs(UnmanagedType.LPStr)] |
||||
|
public string baseDir; |
||||
|
|
||||
|
[MarshalAs(UnmanagedType.LPStr)] |
||||
|
public string cacheDir; |
||||
|
|
||||
|
public int argc; |
||||
|
|
||||
|
[MarshalAs(UnmanagedType.LPArray, SizeConst = MaxArgs)] |
||||
|
public IntPtr[] argv; |
||||
|
|
||||
|
public IntPtr memBase; |
||||
|
|
||||
|
public int memSize; |
||||
|
|
||||
|
public void SetArguments(string[] arguments) |
||||
|
{ |
||||
|
argc = arguments.Length; |
||||
|
argv = new IntPtr[MaxArgs]; |
||||
|
for (int i = 0; i < arguments.Length && i < MaxArgs; ++i) |
||||
|
{ |
||||
|
argv[i] = Marshal.StringToHGlobalAnsi(arguments[i]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void AllocateMemory(int memorySize) |
||||
|
{ |
||||
|
memSize = memorySize; |
||||
|
memBase = Marshal.AllocHGlobal(memorySize); |
||||
|
} |
||||
|
|
||||
|
public void Destroy() |
||||
|
{ |
||||
|
if (memBase != IntPtr.Zero) |
||||
|
{ |
||||
|
Marshal.FreeHGlobal(memBase); |
||||
|
memBase = IntPtr.Zero; |
||||
|
} |
||||
|
|
||||
|
if (argv != null) |
||||
|
{ |
||||
|
for (int i = 0; i < argv.Length; ++i) |
||||
|
{ |
||||
|
if (argv[i] != IntPtr.Zero) |
||||
|
{ |
||||
|
Marshal.FreeHGlobal(argv[i]); |
||||
|
argv[i] = IntPtr.Zero; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,3 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 88fe123889034941854842da9720545b |
||||
|
timeCreated: 1617028874 |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue