From 6a06621b90c2037421d8413ca860d1d1dbe24d74 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Mon, 29 Mar 2021 12:23:15 +0200 Subject: [PATCH] Added some fun stuff that allows you to play with the time scale in Quake, either speeding it up or slowing it down from Unity. --- Assets/Scripts/Bootstrap.cs | 10 ++++++++++ Assets/Scripts/Uniquake.cs | 6 +++++- engine/projects/uniquake/uniquake.c | 5 ++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Bootstrap.cs b/Assets/Scripts/Bootstrap.cs index f4f2afb..99f145b 100644 --- a/Assets/Scripts/Bootstrap.cs +++ b/Assets/Scripts/Bootstrap.cs @@ -5,6 +5,8 @@ using UnityEngine; public class Bootstrap : MonoBehaviour { + private float speed = 1.0f; + private void Start() { Debug.Log($"Running in {IntPtr.Size * 8}-bit mode"); @@ -16,5 +18,13 @@ public class Bootstrap : MonoBehaviour { gameObject.AddComponent(); } + + GUILayout.Label("Time scale:"); + speed = GUILayout.HorizontalSlider(speed, 0.1f, 5.0f, GUILayout.Width(250)); + GUILayout.Label($"{speed:0.00}"); + if (!Mathf.Approximately(speed, Time.timeScale)) + { + Time.timeScale = speed; + } } } diff --git a/Assets/Scripts/Uniquake.cs b/Assets/Scripts/Uniquake.cs index 19ef280..a47b82d 100644 --- a/Assets/Scripts/Uniquake.cs +++ b/Assets/Scripts/Uniquake.cs @@ -13,8 +13,12 @@ public class Uniquake: MonoBehaviour private QuakeParms quakeParms; private UnityCallbacks callbacks = new UnityCallbacks(); + private static double startTime; // TODO: this should be an instance field, but it requires a reference back to this object in the callbacks + void Start() { + startTime = Time.timeAsDouble; + string[] arguments = { "", @@ -113,7 +117,7 @@ public class Uniquake: MonoBehaviour [AOT.MonoPInvokeCallback(typeof(RealtimeSinceStartupCallback))] private static double Callback_RealtimeSinceStartup() { - return Time.realtimeSinceStartupAsDouble; + return Time.timeAsDouble - startTime; } private class UnityCallbacks diff --git a/engine/projects/uniquake/uniquake.c b/engine/projects/uniquake/uniquake.c index a918cab..e040d13 100644 --- a/engine/projects/uniquake/uniquake.c +++ b/engine/projects/uniquake/uniquake.c @@ -63,9 +63,8 @@ UNIQUAKE_API void Uniquake_Init(const unity_callbacks_t *callbacks, quakeparms_t unity_callbacks = callbacks; COM_InitArgv(parms->argc, parms->argv); - // TODO winquake writes com_argc/argv back to parms.argc/argv, is this necessary? - - isDedicated = true; + parms->argc = com_argc; + parms->argv = com_argv; Host_Init(parms); }