Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for /world/proc/Tick() #1540

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Cyberboss marked this conversation as resolved.
Show resolved Hide resolved

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
Loading