Browse Source

Some renaming and reorganization

console
Nico de Poel 5 years ago
parent
commit
3b4382954a
  1. 8
      Assets/Scripts/Data.meta
  2. 0
      Assets/Scripts/Data/QExtensions.cs
  3. 0
      Assets/Scripts/Data/QExtensions.cs.meta
  4. 0
      Assets/Scripts/Data/QMath.cs
  5. 0
      Assets/Scripts/Data/QMath.cs.meta
  6. 0
      Assets/Scripts/Data/QModel.cs
  7. 0
      Assets/Scripts/Data/QModel.cs.meta
  8. 8
      Assets/Scripts/Modules.meta
  9. 4
      Assets/Scripts/Modules/RenderModule.cs
  10. 0
      Assets/Scripts/Modules/RenderModule.cs.meta
  11. 4
      Assets/Scripts/Modules/SystemModule.cs
  12. 0
      Assets/Scripts/Modules/SystemModule.cs.meta
  13. 162
      Assets/Scripts/UniQuake.cs

8
Assets/Scripts/Data.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7749ced6f96975544a978f030980338c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

0
Assets/Scripts/DataDefs/QExtensions.cs → Assets/Scripts/Data/QExtensions.cs

0
Assets/Scripts/DataDefs/QExtensions.cs.meta → Assets/Scripts/Data/QExtensions.cs.meta

0
Assets/Scripts/DataDefs/QMath.cs → Assets/Scripts/Data/QMath.cs

0
Assets/Scripts/DataDefs/QMath.cs.meta → Assets/Scripts/Data/QMath.cs.meta

0
Assets/Scripts/DataDefs/QModel.cs → Assets/Scripts/Data/QModel.cs

0
Assets/Scripts/DataDefs/QModel.cs.meta → Assets/Scripts/Data/QModel.cs.meta

8
Assets/Scripts/Modules.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 02f3a94369dd41d2852b32d5f9ed29f4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

4
Assets/Scripts/ModCalls.cs → Assets/Scripts/Modules/RenderModule.cs

@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
using AOT;
using UnityEngine;
public class ModCalls : CallbackHandler<ModCalls>
public class RenderModule : CallbackHandler<RenderModule>
{
private readonly UniQuake uq;
public ModCalls(UniQuake uniQuake)
public RenderModule(UniQuake uniQuake)
{
uq = uniQuake;

0
Assets/Scripts/ModCalls.cs.meta → Assets/Scripts/Modules/RenderModule.cs.meta

4
Assets/Scripts/SysCalls.cs → Assets/Scripts/Modules/SystemModule.cs

@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
using AOT;
using UnityEngine;
public class SysCalls: CallbackHandler<SysCalls>
public class SystemModule: CallbackHandler<SystemModule>
{
private const int MaxFileHandles = 50;
@ -12,7 +12,7 @@ public class SysCalls: CallbackHandler<SysCalls>
private readonly FileStream[] fileHandles = new FileStream[MaxFileHandles];
public SysCalls(UniQuake uniQuake)
public SystemModule(UniQuake uniQuake)
{
uq = uniQuake;

0
Assets/Scripts/SysCalls.cs.meta → Assets/Scripts/Modules/SystemModule.cs.meta

162
Assets/Scripts/UniQuake.cs

@ -4,9 +4,9 @@ using System.Runtime.InteropServices;
using UnityEngine;
public class UniQuake: MonoBehaviour
{
#if UNITY_EDITOR
private const string DllPath = "Plugins/windows/x86_64/uniquake.dll";
{
#if UNITY_EDITOR
private const string DllPath = "Plugins/windows/x86_64/uniquake.dll";
#elif UNITY_STANDALONE_WIN
#if UNITY_64
private const string DllPath = "Plugins/x86_64/uniquake.dll";
@ -20,21 +20,21 @@ public class UniQuake: MonoBehaviour
private IntPtr libraryHandle;
private QuakeParms quakeParms;
private SysCalls sysCalls;
private ModCalls modCalls;
private SystemModule systemModule;
private RenderModule renderModule;
private bool initialized = false;
private double startTime;
/// <summary>
/// Time since startup for this particular instance of Quake
/// <summary>
/// Time since startup for this particular instance of Quake
/// </summary>
public double CurrentTime => Time.timeAsDouble - startTime;
void Start()
{
sysCalls = new SysCalls(this);
modCalls = new ModCalls(this);
{
systemModule = new SystemModule(this);
renderModule = new RenderModule(this);
LoadLibrary();
@ -57,24 +57,24 @@ public class UniQuake: MonoBehaviour
startTime = Time.timeAsDouble;
try
try
{
UniQuake_Init(quakeParms, sysCalls.ToIntPtr, modCalls.ToIntPtr);
initialized = true;
}
UniQuake_Init(quakeParms, systemModule.ToIntPtr, renderModule.ToIntPtr);
initialized = true;
}
catch (QuakeException ex)
{
if (ex.ExitCode == 0)
Debug.Log(ex.Message);
else
Debug.LogException(ex);
Shutdown();
{
if (ex.ExitCode == 0)
Debug.Log(ex.Message);
else
Debug.LogException(ex);
Shutdown();
}
catch (Exception ex)
{
Debug.LogException(ex);
Shutdown();
{
Debug.LogException(ex);
Shutdown();
}
}
@ -83,37 +83,37 @@ public class UniQuake: MonoBehaviour
if (!initialized)
return;
try
try
{
UniQuake_Update(Time.deltaTime);
UniQuake_Update(Time.deltaTime);
}
catch (QuakeException ex)
{
if (ex.ExitCode == 0)
Debug.Log(ex.Message);
else
Debug.LogException(ex);
Shutdown();
{
if (ex.ExitCode == 0)
Debug.Log(ex.Message);
else
Debug.LogException(ex);
Shutdown();
}
catch (Exception ex)
{
Debug.LogException(ex);
Shutdown();
{
Debug.LogException(ex);
Shutdown();
}
}
private void Shutdown()
{
initialized = false;
UniQuake_Shutdown();
Destroy(this);
private void Shutdown()
{
initialized = false;
UniQuake_Shutdown();
Destroy(this);
}
private void OnDestroy()
{
modCalls.Destroy();
sysCalls.Destroy();
renderModule.Destroy();
systemModule.Destroy();
if (quakeParms != null)
{
@ -136,48 +136,48 @@ public class UniQuake: MonoBehaviour
private delegate void UniQuake_ShutdownFunc();
private UniQuake_ShutdownFunc UniQuake_Shutdown;
private void LoadLibrary()
{
string dllFile = Path.Combine(Application.dataPath, DllPath);
libraryHandle = SystemLibrary.LoadLibrary(dllFile);
if (libraryHandle == IntPtr.Zero)
{
throw new DllNotFoundException($"Failed to load UniQuake library from path: {dllFile}, last error = {Marshal.GetLastWin32Error()}");
}
UniQuake_Init = LoadLibraryFunction<UniQuake_InitFunc>("UniQuake_Init");
UniQuake_Update = LoadLibraryFunction<UniQuake_UpdateFunc>("UniQuake_Update");
UniQuake_Shutdown = LoadLibraryFunction<UniQuake_ShutdownFunc>("UniQuake_Shutdown");
private void LoadLibrary()
{
string dllFile = Path.Combine(Application.dataPath, DllPath);
libraryHandle = SystemLibrary.LoadLibrary(dllFile);
if (libraryHandle == IntPtr.Zero)
{
throw new DllNotFoundException($"Failed to load UniQuake library from path: {dllFile}, last error = {Marshal.GetLastWin32Error()}");
}
UniQuake_Init = LoadLibraryFunction<UniQuake_InitFunc>("UniQuake_Init");
UniQuake_Update = LoadLibraryFunction<UniQuake_UpdateFunc>("UniQuake_Update");
UniQuake_Shutdown = LoadLibraryFunction<UniQuake_ShutdownFunc>("UniQuake_Shutdown");
}
private TDelegate LoadLibraryFunction<TDelegate>(string name)
{
IntPtr procAddress = SystemLibrary.GetProcAddress(libraryHandle, name);
if (procAddress == IntPtr.Zero)
{
throw new DllNotFoundException($"Could not find library function: {name}");
}
return Marshal.GetDelegateForFunctionPointer<TDelegate>(procAddress);
private TDelegate LoadLibraryFunction<TDelegate>(string name)
{
IntPtr procAddress = SystemLibrary.GetProcAddress(libraryHandle, name);
if (procAddress == IntPtr.Zero)
{
throw new DllNotFoundException($"Could not find library function: {name}");
}
return Marshal.GetDelegateForFunctionPointer<TDelegate>(procAddress);
}
private void FreeLibrary()
{
if (libraryHandle != IntPtr.Zero)
{
SystemLibrary.FreeLibrary(libraryHandle);
libraryHandle = IntPtr.Zero;
}
private void FreeLibrary()
{
if (libraryHandle != IntPtr.Zero)
{
SystemLibrary.FreeLibrary(libraryHandle);
libraryHandle = IntPtr.Zero;
}
}
}
public class QuakeException: Exception
{
public int ExitCode { get; }
public QuakeException(string message, int exitCode = 0)
: base(message)
{
ExitCode = exitCode;
}
}
public class QuakeException: Exception
{
public int ExitCode { get; }
public QuakeException(string message, int exitCode = 0)
: base(message)
{
ExitCode = exitCode;
}
}
Loading…
Cancel
Save