diff --git a/DMCompiler/DMStandard/Types/World.dm b/DMCompiler/DMStandard/Types/World.dm index d7137e0137..57a22f7e7e 100644 --- a/DMCompiler/DMStandard/Types/World.dm +++ b/DMCompiler/DMStandard/Types/World.dm @@ -113,3 +113,7 @@ proc/PayCredits(player, credits, note) set opendream_unimplemented = TRUE return 0 + + proc/Tick() + set waitfor = FALSE + return null diff --git a/OpenDreamRuntime/DreamManager.cs b/OpenDreamRuntime/DreamManager.cs index 3ee77cf2c7..efcd580904 100644 --- a/OpenDreamRuntime/DreamManager.cs +++ b/OpenDreamRuntime/DreamManager.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.Diagnostics.CodeAnalysis; +using System.IO; using System.Linq; using System.Text.Json; using DMCompiler.Bytecode; @@ -51,11 +52,15 @@ public sealed partial class DreamManager { private int _dreamObjectRefIdCounter; private DreamCompiledJson _compiledJson; + + [MemberNotNullWhen(true, nameof(_worldTickProc))] public bool Initialized { get; private set; } public GameTick InitializedTick { get; private set; } private ISawmill _sawmill = default!; + private DreamProc? _worldTickProc; + //TODO This arg is awful and temporary until RT supports cvar overrides in unit tests public void PreInitialize(string? jsonPath) { _sawmill = Logger.GetSawmill("opendream"); @@ -95,7 +100,10 @@ public void Update() { if (!Initialized) return; - _procScheduler.Process(); + _procScheduler.Process(true); + DreamThread.Run(_worldTickProc, WorldInstance, null); + _procScheduler.Process(false); + UpdateStat(); _dreamMapManager.UpdateTiles(); @@ -132,6 +140,8 @@ public bool LoadJson(string? jsonPath) { // Call /world/. This is an IMPLEMENTATION DETAIL and non-DMStandard should NOT be run here. WorldInstance.InitSpawn(new()); + _worldTickProc = WorldInstance.GetProc("Tick"); + if (_compiledJson.Globals is GlobalListJson jsonGlobals) { Globals = new DreamValue[jsonGlobals.GlobalCount]; GlobalNames = jsonGlobals.Names; diff --git a/OpenDreamRuntime/Procs/ProcScheduler.cs b/OpenDreamRuntime/Procs/ProcScheduler.cs index f4ae1566d5..0a9d292f3a 100644 --- a/OpenDreamRuntime/Procs/ProcScheduler.cs +++ b/OpenDreamRuntime/Procs/ProcScheduler.cs @@ -42,8 +42,10 @@ async Task Foo() { return task; } - public void Process() { - UpdateDelays(); + public void Process(bool updateDelays) { + if (updateDelays) { + UpdateDelays(); + } // Update all asynchronous tasks that have finished waiting and are ready to resume. //