Skip to content

Commit

Permalink
Merge branch 'ioc' into icon_blend_additions
Browse files Browse the repository at this point in the history
# Conflicts:
#	OpenDreamRuntime/DreamManager.cs
#	OpenDreamRuntime/Objects/DreamIcon.cs
#	OpenDreamRuntime/Objects/DreamObjectTree.cs
#	OpenDreamRuntime/Procs/DMProc.cs
  • Loading branch information
wixoaGit committed Dec 15, 2022
2 parents 7640e98 + a746646 commit b3de91c
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 21 deletions.
2 changes: 1 addition & 1 deletion OpenDreamRuntime/AtomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public IconAppearance CreateAppearanceFromDefinition(DreamObjectDefinition def)
}
}

internal interface IAtomManager {
public interface IAtomManager {
public Dictionary<DreamList, DreamObject> OverlaysListToAtom { get; }
public Dictionary<DreamList, DreamObject> UnderlaysListToAtom { get; }

Expand Down
13 changes: 10 additions & 3 deletions OpenDreamRuntime/DreamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Objects.MetaObjects;
using OpenDreamRuntime.Procs;
using OpenDreamRuntime.Procs.DebugAdapter;
using OpenDreamRuntime.Procs.Native;
using OpenDreamRuntime.Resources;
using OpenDreamShared;
Expand All @@ -20,9 +21,12 @@ partial class DreamManager : IDreamManager {
[Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IDreamMapManager _dreamMapManager = default!;
[Dependency] private readonly IDreamDebugManager _dreamDebugManager = default!;
[Dependency] private readonly IProcScheduler _procScheduler = default!;
[Dependency] private readonly DreamResourceManager _dreamResourceManager = default!;
[Dependency] private readonly IDreamObjectTree _objectTree = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;

public DreamObject WorldInstance { get; private set; }
public Exception? LastDMException { get; set; }
Expand All @@ -48,18 +52,21 @@ public void PreInitialize(string jsonPath) {
_dreamResourceManager.Initialize();

if (!LoadJson(jsonPath)) {
IoCManager.Resolve<ITaskManager>().RunOnMainThread(() => { IoCManager.Resolve<IBaseServer>().Shutdown("Error while loading the compiled json. The opendream.json_path CVar may be empty, or points to a file that doesn't exist"); });
_taskManager.RunOnMainThread(() => { IoCManager.Resolve<IBaseServer>().Shutdown("Error while loading the compiled json. The opendream.json_path CVar may be empty, or points to a file that doesn't exist"); });
}
}

public void StartWorld() {
// It is now OK to call user code, like /New procs.
Initialized = true;
InitializedTick = IoCManager.Resolve<IGameTiming>().CurTick;
InitializedTick = _gameTiming.CurTick;

// Call global <init> with waitfor=FALSE
if (_compiledJson.GlobalInitProc is ProcDefinitionJson initProcDef) {
var globalInitProc = new DMProc(DreamPath.Root, "(global init)", null, null, null, initProcDef.Bytecode, initProcDef.MaxStackSize, initProcDef.Attributes, initProcDef.VerbName, initProcDef.VerbCategory, initProcDef.VerbDesc, initProcDef.Invisibility, _objectTree, _dreamResourceManager);
var globalInitProc = new DMProc(DreamPath.Root, "(global init)", null, null, null, initProcDef.Bytecode,
initProcDef.MaxStackSize, initProcDef.Attributes, initProcDef.VerbName, initProcDef.VerbCategory,
initProcDef.VerbDesc, initProcDef.Invisibility, this, _objectTree, _dreamMapManager, _dreamDebugManager,
_dreamResourceManager);
globalInitProc.Spawn(WorldInstance, new DreamProcArguments());
}

Expand Down
7 changes: 7 additions & 0 deletions OpenDreamRuntime/DreamThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Threading.Tasks;
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Procs;
using OpenDreamRuntime.Procs.DebugAdapter;
using OpenDreamRuntime.Resources;
using OpenDreamShared.Dream;
using OpenDreamShared.Dream.Procs;

Expand Down Expand Up @@ -31,6 +33,11 @@ public abstract class DreamProc {
public string? VerbDesc { get; }
public sbyte? Invisibility { get; }

internal abstract IDreamManager DreamManager { get; }
internal abstract IDreamMapManager DreamMapManager { get; }
internal abstract IDreamDebugManager DreamDebugManager { get; }
internal abstract DreamResourceManager DreamResourceManager { get; }

protected DreamProc(DreamPath owningType, string name, DreamProc superProc, ProcAttributes attributes, List<String>? argumentNames, List<DMValueType>? argumentTypes, string? verbName, string? verbCategory, string? verbDesc, sbyte? invisibility) {
OwningType = owningType;
Name = name;
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamRuntime/Objects/DreamIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public sealed class DreamIconOperationBlendImage : DreamIconOperationBlend {

public DreamIconOperationBlendImage(BlendType type, int xOffset, int yOffset, DreamValue blending) : base(type, xOffset, yOffset) {
var objectTree = IoCManager.Resolve<IDreamObjectTree>();
var resourceManager = IoCManager.Resolve<DreamResourceManager>();
var resourceManager = IoCManager.Resolve<DreamResourceManager>(); //TODO: Find a way to get rid of this!
(var blendingResource, _blendingDescription) = DreamMetaObjectIcon.GetIconResourceAndDescription(objectTree, resourceManager, blending);
_blending = resourceManager.LoadImage(blendingResource);
}
Expand Down
10 changes: 9 additions & 1 deletion OpenDreamRuntime/Objects/DreamObjectTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using OpenDreamRuntime.Objects.MetaObjects;
using OpenDreamRuntime.Procs;
using OpenDreamRuntime.Procs.DebugAdapter;
using OpenDreamRuntime.Resources;
using OpenDreamShared.Dream;
using OpenDreamShared.Dream.Procs;
Expand Down Expand Up @@ -39,6 +40,10 @@ public sealed class DreamObjectTree : IDreamObjectTree {
private Dictionary<string, int> _globalProcIds;

[Dependency] private readonly DreamResourceManager _resourceManager = default!;
[Dependency] private readonly IDreamManager DreamManager = default!;
[Dependency] private readonly IDreamMapManager DreamMapManager = default!;
[Dependency] private readonly IDreamDebugManager DreamDebugManager = default!;
[Dependency] private readonly DreamResourceManager DreamResourceManager = default!;

public void LoadJson(DreamCompiledJson json) {
Strings = json.Strings;
Expand Down Expand Up @@ -298,7 +303,10 @@ public DreamProc LoadProcJson(DreamTypeJson[] types, ProcDefinitionJson procDefi
}

DreamPath owningType = new DreamPath(types[procDefinition.OwningTypeId].Path);
var proc = new DMProc(owningType, procDefinition.Name, null, argumentNames, argumentTypes, bytecode, procDefinition.MaxStackSize, procDefinition.Attributes, procDefinition.VerbName, procDefinition.VerbCategory, procDefinition.VerbDesc, procDefinition.Invisibility, this, _resourceManager);
var proc = new DMProc(owningType, procDefinition.Name, null, argumentNames, argumentTypes, bytecode,
procDefinition.MaxStackSize, procDefinition.Attributes, procDefinition.VerbName,
procDefinition.VerbCategory, procDefinition.VerbDesc, procDefinition.Invisibility, DreamManager,
this, DreamMapManager, DreamDebugManager, DreamResourceManager);
proc.Source = procDefinition.Source;
proc.Line = procDefinition.Line;
return proc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OpenDreamRuntime.Rendering;
using OpenDreamRuntime.Resources;
using OpenDreamShared.Dream;
using Robust.Shared.Serialization.Manager;

namespace OpenDreamRuntime.Objects.MetaObjects {
sealed class DreamMetaObjectAtom : IDreamMetaObject {
Expand Down
15 changes: 12 additions & 3 deletions OpenDreamRuntime/Procs/AsyncNativeProc.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Text;
using System.Threading.Tasks;
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Procs.DebugAdapter;
using OpenDreamRuntime.Resources;
using OpenDreamShared.Dream;
using OpenDreamShared.Dream.Procs;

Expand Down Expand Up @@ -151,15 +153,22 @@ public override void AppendStackFrame(StringBuilder builder)
private Dictionary<string, DreamValue> _defaultArgumentValues;
private Func<State, Task<DreamValue>> _taskFunc;

private AsyncNativeProc()
: base(DreamPath.Root, "<anonymous async proc>", null, ProcAttributes.DisableWaitfor, null, null, null, null, null, null)
{}
[Dependency] private readonly IDreamManager _dreamManager;
internal override IDreamManager DreamManager => _dreamManager;
[Dependency] private readonly IDreamMapManager _dreamMapManager;
internal override IDreamMapManager DreamMapManager => _dreamMapManager;
[Dependency] private readonly IDreamDebugManager _dreamDebugManager;
internal override IDreamDebugManager DreamDebugManager => _dreamDebugManager;
[Dependency] private readonly DreamResourceManager _dreamResourceManager;
internal override DreamResourceManager DreamResourceManager => _dreamResourceManager;

public AsyncNativeProc(DreamPath owningType, string name, DreamProc superProc, List<String> argumentNames, List<DMValueType> argumentTypes, Dictionary<string, DreamValue> defaultArgumentValues, Func<State, Task<DreamValue>> taskFunc, string? verbName, string? verbCategory, string? verbDesc, sbyte? invisibility)
: base(owningType, name, superProc, ProcAttributes.None, argumentNames, argumentTypes, verbName, verbCategory, verbDesc, invisibility)
{
IoCManager.InjectDependencies(this); // i gave up on passing in the iocs as args here due to access related issues, IDreamDebugManager is internal.
_defaultArgumentValues = defaultArgumentValues;
_taskFunc = taskFunc;

}

public override ProcState CreateState(DreamThread thread, DreamObject src, DreamObject usr, DreamProcArguments arguments)
Expand Down
9 changes: 4 additions & 5 deletions OpenDreamRuntime/Procs/DMOpcodeHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ private static DreamValue[] GetEnumerableContents(IDreamObjectTree objectTree, D
if (!loc.TryGetValueAsDreamObjectOfType(state.Proc.ObjectTree.Turf, out var turf))
throw new Exception($"Invalid turf loc {loc}");

IDreamMapManager dreamMapManager = IoCManager.Resolve<IDreamMapManager>();
dreamMapManager.SetTurf(turf, objectDef, arguments);
state.Proc.DreamMapManager.SetTurf(turf, objectDef, arguments);

state.Push(loc);
return null;
Expand Down Expand Up @@ -545,7 +544,7 @@ private static void HandleSuffixPronoun(ref StringBuilder formattedString, ReadO
public static ProcStatus? PushResource(DMProcState state) {
string resourcePath = state.ReadString();

state.Push(new DreamValue(IoCManager.Resolve<DreamResourceManager>().LoadResource(resourcePath)));
state.Push(new DreamValue(state.Proc.DreamResourceManager.LoadResource(resourcePath)));
return null;
}

Expand Down Expand Up @@ -1338,7 +1337,7 @@ private static void HandleSuffixPronoun(ref StringBuilder formattedString, ReadO
throw new Exception($"{popProc} is not a valid proc name");
}
// DLL Invoke
var entryPoint = DllHelper.ResolveDllTarget(IoCManager.Resolve<DreamResourceManager>(), dllName, procName);
var entryPoint = DllHelper.ResolveDllTarget(state.Proc.DreamResourceManager, dllName, procName);

Span<nint> argV = stackalloc nint[arguments.ArgumentCount];
argV.Fill(0);
Expand Down Expand Up @@ -1749,7 +1748,7 @@ private static void PerformOutput(DreamValue a, DreamValue b) {
if (x.TryGetValueAsInteger(out var xInt) && y.TryGetValueAsInteger(out var yInt) &&
z.TryGetValueAsInteger(out var zInt))
{
IoCManager.Resolve<IDreamMapManager>().TryGetTurfAt((xInt, yInt), zInt, out var turf);
state.Proc.DreamMapManager.TryGetTurfAt((xInt, yInt), zInt, out var turf);
state.Push(new DreamValue(turf));
}
else
Expand Down
20 changes: 14 additions & 6 deletions OpenDreamRuntime/Procs/DMProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@

namespace OpenDreamRuntime.Procs {
sealed class DMProc : DreamProc {
public readonly IDreamObjectTree ObjectTree;
public readonly DreamResourceManager ResourceManager;
public byte[] Bytecode { get; }

private readonly int _maxStackSize;

public string? Source { get; set; }
public int Line { get; set; }

public DMProc(DreamPath owningType, string name, DreamProc superProc, List<String> argumentNames, List<DMValueType> argumentTypes, byte[] bytecode, int maxStackSize, ProcAttributes attributes, string? verbName, string? verbCategory, string? verbDesc, sbyte? invisibility, IDreamObjectTree objectTree, DreamResourceManager resourceManager)
public readonly IDreamManager DreamManager;
public readonly IDreamObjectTree ObjectTree;
public readonly IDreamMapManager DreamMapManager;
public readonly IDreamDebugManager DreamDebugManager;
public readonly DreamResourceManager ResourceManager;

public DMProc(DreamPath owningType, string name, DreamProc superProc, List<String> argumentNames, List<DMValueType> argumentTypes, byte[] bytecode, int maxStackSize, ProcAttributes attributes, string? verbName, string? verbCategory, string? verbDesc, sbyte? invisibility, IDreamManager dreamManager, IDreamObjectTree objectTree, IDreamMapManager dreamMapManager, IDreamDebugManager dreamDebugManager, DreamResourceManager dreamResourceManager)
: base(owningType, name, superProc, attributes, argumentNames, argumentTypes, verbName, verbCategory, verbDesc, invisibility) {

DreamManager = dreamManager;
ObjectTree = objectTree;
ResourceManager = resourceManager;
DreamMapManager = dreamMapManager;
DreamDebugManager = dreamDebugManager;
ResourceManager = dreamResourceManager;
Bytecode = bytecode;
_maxStackSize = maxStackSize;
}
Expand Down Expand Up @@ -143,8 +151,8 @@ sealed class DMProcState : ProcState
};
#endregion

public readonly IDreamManager DreamManager = IoCManager.Resolve<IDreamManager>();
public readonly IDreamDebugManager DebugManager = IoCManager.Resolve<IDreamDebugManager>();
public IDreamManager DreamManager => _proc.DreamManager;
public IDreamDebugManager DebugManager => _proc.DreamDebugManager;

/// <summary> This stores our 'src' value. May be null!</summary>
public DreamObject? Instance;
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamRuntime/Procs/DebugAdapter/DreamDebugManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ private void HandleRequestVariables(DebugAdapterClient client, RequestVariables
}
}

interface IDreamDebugManager {
internal interface IDreamDebugManager {
bool Stopped { get; }

public void Initialize(int port);
Expand Down
13 changes: 13 additions & 0 deletions OpenDreamRuntime/Procs/NativeProc.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Reflection;
using System.Text;
using OpenDreamRuntime.Objects;
using OpenDreamRuntime.Procs.DebugAdapter;
using OpenDreamRuntime.Resources;
using OpenDreamShared.Dream;
using OpenDreamShared.Dream.Procs;

Expand Down Expand Up @@ -69,9 +71,20 @@ public override void AppendStackFrame(StringBuilder builder)
private Dictionary<string, DreamValue> _defaultArgumentValues;
public HandlerFn Handler { get; }

[Dependency] private readonly IDreamManager _dreamManager;
internal override IDreamManager DreamManager => _dreamManager;
[Dependency] private readonly IDreamMapManager _dreamMapManager;
internal override IDreamMapManager DreamMapManager => _dreamMapManager;
[Dependency] private readonly IDreamDebugManager _dreamDebugManager;
internal override IDreamDebugManager DreamDebugManager => _dreamDebugManager;
[Dependency] private readonly DreamResourceManager _dreamResourceManager;
internal override DreamResourceManager DreamResourceManager => _dreamResourceManager;


public NativeProc(DreamPath owningType, string name, DreamProc superProc, List<String> argumentNames, List<DMValueType> argumentTypes, Dictionary<string, DreamValue> defaultArgumentValues, HandlerFn handler, string? verbName, string? verbCategory, string? verbDesc, sbyte? invisibility)
: base(owningType, name, superProc, ProcAttributes.None, argumentNames, argumentTypes, verbName, verbCategory, verbDesc, invisibility)
{
IoCManager.InjectDependencies(this); // i gave up on passing in the iocs as args here due to access related issues, IDreamDebugManager is internal.
_defaultArgumentValues = defaultArgumentValues;
Handler = handler;
}
Expand Down

0 comments on commit b3de91c

Please sign in to comment.