Browse Source
Added Unity code to interop with Quake DLL and test initialization from a Unity scene.
console
Added Unity code to interop with Quake DLL and test initialization from a Unity scene.
console
11 changed files with 366 additions and 26 deletions
-
1.gitignore
-
118Assets/Scenes/Default.unity
-
63Assets/Scenes/DefaultSettings.lighting
-
8Assets/Scenes/DefaultSettings.lighting.meta
-
8Assets/Scripts.meta
-
20Assets/Scripts/Bootstrap.cs
-
11Assets/Scripts/Bootstrap.cs.meta
-
124Assets/Scripts/Uniquake.cs
-
11Assets/Scripts/Uniquake.cs.meta
-
9ProjectSettings/ProjectSettings.asset
-
19ProjectSettings/QualitySettings.asset
@ -0,0 +1,63 @@ |
|||||
|
%YAML 1.1 |
||||
|
%TAG !u! tag:unity3d.com,2011: |
||||
|
--- !u!850595691 &4890085278179872738 |
||||
|
LightingSettings: |
||||
|
m_ObjectHideFlags: 0 |
||||
|
m_CorrespondingSourceObject: {fileID: 0} |
||||
|
m_PrefabInstance: {fileID: 0} |
||||
|
m_PrefabAsset: {fileID: 0} |
||||
|
m_Name: DefaultSettings |
||||
|
serializedVersion: 3 |
||||
|
m_GIWorkflowMode: 1 |
||||
|
m_EnableBakedLightmaps: 1 |
||||
|
m_EnableRealtimeLightmaps: 0 |
||||
|
m_RealtimeEnvironmentLighting: 1 |
||||
|
m_BounceScale: 1 |
||||
|
m_AlbedoBoost: 1 |
||||
|
m_IndirectOutputScale: 1 |
||||
|
m_UsingShadowmask: 1 |
||||
|
m_BakeBackend: 1 |
||||
|
m_LightmapMaxSize: 1024 |
||||
|
m_BakeResolution: 40 |
||||
|
m_Padding: 2 |
||||
|
m_TextureCompression: 1 |
||||
|
m_AO: 0 |
||||
|
m_AOMaxDistance: 1 |
||||
|
m_CompAOExponent: 1 |
||||
|
m_CompAOExponentDirect: 0 |
||||
|
m_ExtractAO: 0 |
||||
|
m_MixedBakeMode: 2 |
||||
|
m_LightmapsBakeMode: 1 |
||||
|
m_FilterMode: 1 |
||||
|
m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0} |
||||
|
m_ExportTrainingData: 0 |
||||
|
m_TrainingDataDestination: TrainingData |
||||
|
m_RealtimeResolution: 2 |
||||
|
m_ForceWhiteAlbedo: 0 |
||||
|
m_ForceUpdates: 0 |
||||
|
m_FinalGather: 0 |
||||
|
m_FinalGatherRayCount: 256 |
||||
|
m_FinalGatherFiltering: 1 |
||||
|
m_PVRCulling: 1 |
||||
|
m_PVRSampling: 1 |
||||
|
m_PVRDirectSampleCount: 32 |
||||
|
m_PVRSampleCount: 500 |
||||
|
m_PVREnvironmentSampleCount: 500 |
||||
|
m_PVREnvironmentReferencePointCount: 2048 |
||||
|
m_LightProbeSampleCountMultiplier: 4 |
||||
|
m_PVRBounces: 2 |
||||
|
m_PVRMinBounces: 2 |
||||
|
m_PVREnvironmentMIS: 0 |
||||
|
m_PVRFilteringMode: 2 |
||||
|
m_PVRDenoiserTypeDirect: 0 |
||||
|
m_PVRDenoiserTypeIndirect: 0 |
||||
|
m_PVRDenoiserTypeAO: 0 |
||||
|
m_PVRFilterTypeDirect: 0 |
||||
|
m_PVRFilterTypeIndirect: 0 |
||||
|
m_PVRFilterTypeAO: 0 |
||||
|
m_PVRFilteringGaussRadiusDirect: 1 |
||||
|
m_PVRFilteringGaussRadiusIndirect: 5 |
||||
|
m_PVRFilteringGaussRadiusAO: 2 |
||||
|
m_PVRFilteringAtrousPositionSigmaDirect: 0.5 |
||||
|
m_PVRFilteringAtrousPositionSigmaIndirect: 2 |
||||
|
m_PVRFilteringAtrousPositionSigmaAO: 1 |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: f0ed978cba596434485fe01a320af46a |
||||
|
NativeFormatImporter: |
||||
|
externalObjects: {} |
||||
|
mainObjectFileID: 4890085278179872738 |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: f3717bba6e3a67242954142d71e05e10 |
||||
|
folderAsset: yes |
||||
|
DefaultImporter: |
||||
|
externalObjects: {} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,20 @@ |
|||||
|
using System; |
||||
|
using System.Collections; |
||||
|
using System.Collections.Generic; |
||||
|
using UnityEngine; |
||||
|
|
||||
|
public class Bootstrap : MonoBehaviour |
||||
|
{ |
||||
|
private void Start() |
||||
|
{ |
||||
|
Debug.Log($"Running in {IntPtr.Size * 8}-bit mode"); |
||||
|
} |
||||
|
|
||||
|
private void OnGUI() |
||||
|
{ |
||||
|
if (GUILayout.Button("Start Quake!")) |
||||
|
{ |
||||
|
gameObject.AddComponent<Uniquake>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 941b1c44c09860d4fa2547fa7c914d55 |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: 0 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,124 @@ |
|||||
|
using System; |
||||
|
using System.Collections; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using UnityEngine; |
||||
|
using UnityEngine.Events; |
||||
|
|
||||
|
public class Uniquake: MonoBehaviour |
||||
|
{ |
||||
|
private const string DllName = "uniquake.dll"; |
||||
|
private const int MemSize = 0x4000000; // 64 MB of heap space
|
||||
|
|
||||
|
private UnityCallbacks callbacks; |
||||
|
private QuakeParms quakeParms; |
||||
|
|
||||
|
void Start() |
||||
|
{ |
||||
|
callbacks = new UnityCallbacks |
||||
|
{ |
||||
|
DebugLog = Callback_DebugLog, |
||||
|
DebugLogError = Callback_DebugLogError, |
||||
|
ApplicationQuit = Callback_ApplicationQuit, |
||||
|
RealtimeSinceStartup = Callback_RealtimeSinceStartup, |
||||
|
}; |
||||
|
|
||||
|
string[] args = Environment.GetCommandLineArgs(); |
||||
|
|
||||
|
quakeParms = new QuakeParms |
||||
|
{ |
||||
|
baseDir = Application.dataPath, |
||||
|
cacheDir = null, |
||||
|
argc = 0,//args.Length,
|
||||
|
argv = null,//args, // TODO: marshaling of string arrays is still tricky
|
||||
|
memBase = Marshal.AllocHGlobal(MemSize), |
||||
|
memSize = MemSize, |
||||
|
}; |
||||
|
|
||||
|
Uniquake_Init(callbacks, quakeParms); |
||||
|
} |
||||
|
|
||||
|
void Update() |
||||
|
{ |
||||
|
Uniquake_Update(Time.deltaTime); |
||||
|
} |
||||
|
|
||||
|
private void OnDestroy() |
||||
|
{ |
||||
|
if (quakeParms != null && quakeParms.memBase != IntPtr.Zero) |
||||
|
{ |
||||
|
Marshal.FreeHGlobal(quakeParms.memBase); |
||||
|
quakeParms.memBase = IntPtr.Zero; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] |
||||
|
private static extern void Uniquake_Echo(UnityCallbacks.DebugLogCallback logCallback, [MarshalAs(UnmanagedType.LPStr)] string message); |
||||
|
|
||||
|
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] |
||||
|
private static extern void Uniquake_Init(UnityCallbacks callbacks, QuakeParms parms); |
||||
|
|
||||
|
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] |
||||
|
private static extern void Uniquake_Update(float deltaTime); |
||||
|
|
||||
|
[AOT.MonoPInvokeCallback(typeof(UnityCallbacks.DebugLogCallback))] |
||||
|
private static void Callback_DebugLog(string message) |
||||
|
{ |
||||
|
Debug.Log(message); |
||||
|
} |
||||
|
|
||||
|
[AOT.MonoPInvokeCallback(typeof(UnityCallbacks.DebugLogErrorCallback))] |
||||
|
private static void Callback_DebugLogError(string message) |
||||
|
{ |
||||
|
Debug.LogError(message); |
||||
|
} |
||||
|
|
||||
|
[AOT.MonoPInvokeCallback(typeof(UnityCallbacks.ApplicationQuitCallback))] |
||||
|
private static void Callback_ApplicationQuit(int exitCode) |
||||
|
{ |
||||
|
Debug.Log($"Quitting application with exit code: {exitCode}"); |
||||
|
// TODO: kill execution of the DLL entirely (Sys_Quit expects immediate exit, which Application.Quit doesn't do)
|
||||
|
Application.Quit(exitCode); |
||||
|
} |
||||
|
|
||||
|
[AOT.MonoPInvokeCallback(typeof(UnityCallbacks.RealtimeSinceStartupCallback))] |
||||
|
private static double Callback_RealtimeSinceStartup() |
||||
|
{ |
||||
|
return Time.realtimeSinceStartupAsDouble; |
||||
|
} |
||||
|
|
||||
|
[StructLayout(LayoutKind.Sequential, Pack = 0)] |
||||
|
private class UnityCallbacks |
||||
|
{ |
||||
|
public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)] string message); |
||||
|
public DebugLogCallback DebugLog; |
||||
|
|
||||
|
public delegate void DebugLogErrorCallback([MarshalAs(UnmanagedType.LPStr)] string message); |
||||
|
public DebugLogErrorCallback DebugLogError; |
||||
|
|
||||
|
public delegate void ApplicationQuitCallback(int exitCode); |
||||
|
public ApplicationQuitCallback ApplicationQuit; |
||||
|
|
||||
|
public delegate double RealtimeSinceStartupCallback(); |
||||
|
public RealtimeSinceStartupCallback RealtimeSinceStartup; |
||||
|
} |
||||
|
|
||||
|
[StructLayout(LayoutKind.Sequential, Pack = 0)] |
||||
|
private class QuakeParms |
||||
|
{ |
||||
|
[MarshalAs(UnmanagedType.LPStr)] |
||||
|
public string baseDir; |
||||
|
|
||||
|
[MarshalAs(UnmanagedType.LPStr)] |
||||
|
public string cacheDir; |
||||
|
|
||||
|
public int argc; |
||||
|
|
||||
|
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] |
||||
|
public string[] argv; |
||||
|
|
||||
|
public IntPtr memBase; |
||||
|
|
||||
|
public int memSize; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 218ace1bd91705a43b9ce8c3211de4bf |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: 0 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue