From 3b4382954a9c30d2344fb2d344ba48a390ca802d Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Mon, 5 Apr 2021 18:14:25 +0200 Subject: [PATCH] Some renaming and reorganization --- Assets/Scripts/Data.meta | 8 + .../Scripts/{DataDefs => Data}/QExtensions.cs | 0 .../{DataDefs => Data}/QExtensions.cs.meta | 0 Assets/Scripts/{DataDefs => Data}/QMath.cs | 0 .../Scripts/{DataDefs => Data}/QMath.cs.meta | 0 Assets/Scripts/{DataDefs => Data}/QModel.cs | 0 .../Scripts/{DataDefs => Data}/QModel.cs.meta | 0 Assets/Scripts/Modules.meta | 8 + .../{ModCalls.cs => Modules/RenderModule.cs} | 4 +- .../RenderModule.cs.meta} | 0 .../{SysCalls.cs => Modules/SystemModule.cs} | 4 +- .../SystemModule.cs.meta} | 0 Assets/Scripts/UniQuake.cs | 162 +++++++++--------- 13 files changed, 101 insertions(+), 85 deletions(-) create mode 100644 Assets/Scripts/Data.meta rename Assets/Scripts/{DataDefs => Data}/QExtensions.cs (100%) rename Assets/Scripts/{DataDefs => Data}/QExtensions.cs.meta (100%) rename Assets/Scripts/{DataDefs => Data}/QMath.cs (100%) rename Assets/Scripts/{DataDefs => Data}/QMath.cs.meta (100%) rename Assets/Scripts/{DataDefs => Data}/QModel.cs (100%) rename Assets/Scripts/{DataDefs => Data}/QModel.cs.meta (100%) create mode 100644 Assets/Scripts/Modules.meta rename Assets/Scripts/{ModCalls.cs => Modules/RenderModule.cs} (94%) rename Assets/Scripts/{ModCalls.cs.meta => Modules/RenderModule.cs.meta} (100%) rename Assets/Scripts/{SysCalls.cs => Modules/SystemModule.cs} (99%) rename Assets/Scripts/{SysCalls.cs.meta => Modules/SystemModule.cs.meta} (100%) diff --git a/Assets/Scripts/Data.meta b/Assets/Scripts/Data.meta new file mode 100644 index 0000000..8b5e3f0 --- /dev/null +++ b/Assets/Scripts/Data.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7749ced6f96975544a978f030980338c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/DataDefs/QExtensions.cs b/Assets/Scripts/Data/QExtensions.cs similarity index 100% rename from Assets/Scripts/DataDefs/QExtensions.cs rename to Assets/Scripts/Data/QExtensions.cs diff --git a/Assets/Scripts/DataDefs/QExtensions.cs.meta b/Assets/Scripts/Data/QExtensions.cs.meta similarity index 100% rename from Assets/Scripts/DataDefs/QExtensions.cs.meta rename to Assets/Scripts/Data/QExtensions.cs.meta diff --git a/Assets/Scripts/DataDefs/QMath.cs b/Assets/Scripts/Data/QMath.cs similarity index 100% rename from Assets/Scripts/DataDefs/QMath.cs rename to Assets/Scripts/Data/QMath.cs diff --git a/Assets/Scripts/DataDefs/QMath.cs.meta b/Assets/Scripts/Data/QMath.cs.meta similarity index 100% rename from Assets/Scripts/DataDefs/QMath.cs.meta rename to Assets/Scripts/Data/QMath.cs.meta diff --git a/Assets/Scripts/DataDefs/QModel.cs b/Assets/Scripts/Data/QModel.cs similarity index 100% rename from Assets/Scripts/DataDefs/QModel.cs rename to Assets/Scripts/Data/QModel.cs diff --git a/Assets/Scripts/DataDefs/QModel.cs.meta b/Assets/Scripts/Data/QModel.cs.meta similarity index 100% rename from Assets/Scripts/DataDefs/QModel.cs.meta rename to Assets/Scripts/Data/QModel.cs.meta diff --git a/Assets/Scripts/Modules.meta b/Assets/Scripts/Modules.meta new file mode 100644 index 0000000..da4844f --- /dev/null +++ b/Assets/Scripts/Modules.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 02f3a94369dd41d2852b32d5f9ed29f4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ModCalls.cs b/Assets/Scripts/Modules/RenderModule.cs similarity index 94% rename from Assets/Scripts/ModCalls.cs rename to Assets/Scripts/Modules/RenderModule.cs index f332d1a..b3cb490 100644 --- a/Assets/Scripts/ModCalls.cs +++ b/Assets/Scripts/Modules/RenderModule.cs @@ -5,11 +5,11 @@ using System.Runtime.InteropServices; using AOT; using UnityEngine; -public class ModCalls : CallbackHandler +public class RenderModule : CallbackHandler { private readonly UniQuake uq; - public ModCalls(UniQuake uniQuake) + public RenderModule(UniQuake uniQuake) { uq = uniQuake; diff --git a/Assets/Scripts/ModCalls.cs.meta b/Assets/Scripts/Modules/RenderModule.cs.meta similarity index 100% rename from Assets/Scripts/ModCalls.cs.meta rename to Assets/Scripts/Modules/RenderModule.cs.meta diff --git a/Assets/Scripts/SysCalls.cs b/Assets/Scripts/Modules/SystemModule.cs similarity index 99% rename from Assets/Scripts/SysCalls.cs rename to Assets/Scripts/Modules/SystemModule.cs index 2bf1b4b..6910210 100644 --- a/Assets/Scripts/SysCalls.cs +++ b/Assets/Scripts/Modules/SystemModule.cs @@ -4,7 +4,7 @@ using System.Runtime.InteropServices; using AOT; using UnityEngine; -public class SysCalls: CallbackHandler +public class SystemModule: CallbackHandler { private const int MaxFileHandles = 50; @@ -12,7 +12,7 @@ public class SysCalls: CallbackHandler private readonly FileStream[] fileHandles = new FileStream[MaxFileHandles]; - public SysCalls(UniQuake uniQuake) + public SystemModule(UniQuake uniQuake) { uq = uniQuake; diff --git a/Assets/Scripts/SysCalls.cs.meta b/Assets/Scripts/Modules/SystemModule.cs.meta similarity index 100% rename from Assets/Scripts/SysCalls.cs.meta rename to Assets/Scripts/Modules/SystemModule.cs.meta diff --git a/Assets/Scripts/UniQuake.cs b/Assets/Scripts/UniQuake.cs index 6a36e74..e2b0c57 100644 --- a/Assets/Scripts/UniQuake.cs +++ b/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; - /// - /// Time since startup for this particular instance of Quake + /// + /// Time since startup for this particular instance of Quake /// 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_Init"); - UniQuake_Update = LoadLibraryFunction("UniQuake_Update"); - UniQuake_Shutdown = LoadLibraryFunction("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_Init"); + UniQuake_Update = LoadLibraryFunction("UniQuake_Update"); + UniQuake_Shutdown = LoadLibraryFunction("UniQuake_Shutdown"); } - private TDelegate LoadLibraryFunction(string name) - { - IntPtr procAddress = SystemLibrary.GetProcAddress(libraryHandle, name); - if (procAddress == IntPtr.Zero) - { - throw new DllNotFoundException($"Could not find library function: {name}"); - } - - return Marshal.GetDelegateForFunctionPointer(procAddress); + private TDelegate LoadLibraryFunction(string name) + { + IntPtr procAddress = SystemLibrary.GetProcAddress(libraryHandle, name); + if (procAddress == IntPtr.Zero) + { + throw new DllNotFoundException($"Could not find library function: {name}"); + } + + return Marshal.GetDelegateForFunctionPointer(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; + } +}