Skip to content

Commit

Permalink
Add support for /world/proc/Tick()
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Nov 27, 2023
1 parent b2920f6 commit 5f471df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions DMCompiler/DMStandard/Types/World.dm
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,7 @@
proc/PayCredits(player, credits, note)
set opendream_unimplemented = TRUE
return 0

proc/Tick()
set waitfor = FALSE
return null
14 changes: 12 additions & 2 deletions OpenDreamRuntime/DreamManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text.Json;
using DMCompiler.Bytecode;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -132,6 +140,8 @@ public bool LoadJson(string? jsonPath) {
// Call /world/<init>. 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;
Expand Down
6 changes: 4 additions & 2 deletions OpenDreamRuntime/Procs/ProcScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down

0 comments on commit 5f471df

Please sign in to comment.