diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
deleted file mode 100644
index 2fc272c..0000000
--- a/.github/workflows/build.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-name: build
-
-on: [push, pull_request]
-
-jobs:
- build:
-
- runs-on: ${{ matrix.os }}
- strategy:
- matrix:
- dotnet: [ '3.1.200', '3.1.201' ]
- build_mode: [ 'Release', 'Debug' ]
- os: [ubuntu-latest, windows-latest, macOS-latest]
- steps:
- - uses: actions/checkout@v1
- - name: Setup .NET Core
- uses: actions/setup-dotnet@v1
- with:
- dotnet-version: ${{ matrix.dotnet }}
- - name: Build
- run: dotnet build src -c ${{ matrix.build_mode }}
- - name: Run tests
- run: dotnet test src -c ${{ matrix.build_mode }}
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
new file mode 100644
index 0000000..1e24bc2
--- /dev/null
+++ b/.github/workflows/dotnet.yml
@@ -0,0 +1,26 @@
+name: .NET
+
+on:
+ push:
+ branches: [main, master, "releases/**"]
+ pull_request:
+ branches: [main, master, "releases/**"]
+jobs:
+ build:
+ timeout-minutes: 15
+ continue-on-error: true
+ runs-on: ${{ matrix.platforms }}
+ strategy:
+ matrix:
+ dotnet: ["6.0.x"]
+ platforms: ["ubuntu-latest", "windows-latest", "macos-latest"]
+ steps:
+ - uses: actions/checkout@v2
+ - name: Setup .NET
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: ${{ matrix.dotnet }}
+ - name: Install dependencies
+ run: dotnet restore
+ - name: Build
+ run: dotnet build --configuration Release --no-restore
diff --git a/src/GlobalUsing.cs b/src/GlobalUsing.cs
new file mode 100644
index 0000000..5f28270
--- /dev/null
+++ b/src/GlobalUsing.cs
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/SimAI.Tests/SimAI.Tests.csproj b/src/SimAI.Tests/SimAI.Tests.csproj
index 7311189..a67e001 100644
--- a/src/SimAI.Tests/SimAI.Tests.csproj
+++ b/src/SimAI.Tests/SimAI.Tests.csproj
@@ -1,26 +1,28 @@
-
- netcoreapp3.1
+
+ net6.0
- false
+ false
- SimAntics.Tests
-
+ SimAntics.Tests
+
-
-
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
-all
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
-all
-
-
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
-
-
-
+
+
+
diff --git a/src/SimAI.Tests/UnitTest1.cs b/src/SimAI.Tests/UnitTest1.cs
index 504b666..638cbae 100644
--- a/src/SimAI.Tests/UnitTest1.cs
+++ b/src/SimAI.Tests/UnitTest1.cs
@@ -1,18 +1,16 @@
using System;
-using System.Diagnostics;
using Xunit;
-namespace SimAI.Tests
-{
- public class UnitTest1
- {
- [Fact]
- public void Test1()
- {
- var clock = new VMClock();
- Console.WriteLine(clock.Ticks);
- clock.Tick();
- Console.WriteLine(clock.Ticks);
- }
- }
-}
\ No newline at end of file
+namespace SimAI.Tests;
+
+public class UnitTest1
+ {
+ [Fact]
+ public void Test1()
+ {
+ var clock = new VMClock();
+ Console.WriteLine(clock.Ticks);
+ clock.Tick();
+ Console.WriteLine(clock.Ticks);
+ }
+ }
\ No newline at end of file
diff --git a/src/SimAI.Tests/VMTest.cs b/src/SimAI.Tests/VMTest.cs
index ce304ca..58b8b32 100644
--- a/src/SimAI.Tests/VMTest.cs
+++ b/src/SimAI.Tests/VMTest.cs
@@ -1,12 +1,11 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-namespace SimAI.Tests
-{
- public class VMTest
- {
- public VMTest()
- {
- }
- }
-}
+namespace SimAI.Tests;
+
+ public class VMTest
+ {
+ public VMTest()
+ {
+ }
+ }
diff --git a/src/SimAI.sln b/src/SimAI.sln
index 61f1e58..a02d3b3 100644
--- a/src/SimAI.sln
+++ b/src/SimAI.sln
@@ -1,9 +1,13 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimAI", "SimAI\SimAI.csproj", "{6B758449-9D5A-456A-A733-31B7841E538A}"
+# Visual Studio Version 17
+VisualStudioVersion = 17.4.33205.214
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimAI", "SimAI\SimAI.csproj", "{6B758449-9D5A-456A-A733-31B7841E538A}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimAI.Tests", "SimAI.Tests\SimAI.Tests.csproj", "{4B7461A4-982A-4D89-92E3-E4D4A3EC85FB}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimAI.Tests", "SimAI.Tests\SimAI.Tests.csproj", "{4B7461A4-982A-4D89-92E3-E4D4A3EC85FB}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4FF3BCA6-25C6-4E59-9036-2B416C836B7D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -20,6 +24,12 @@ Global
{4B7461A4-982A-4D89-92E3-E4D4A3EC85FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B7461A4-982A-4D89-92E3-E4D4A3EC85FB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {0CAB232D-BCC7-412F-9D4F-715753F4DFF5}
+ EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
$0.StandardHeader = $1
diff --git a/src/SimAI/Direction.cs b/src/SimAI/Direction.cs
index 4a459c8..a77fdcd 100644
--- a/src/SimAI/Direction.cs
+++ b/src/SimAI/Direction.cs
@@ -1,18 +1,16 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
+namespace SimAI;
-namespace SimAI
+public enum Direction
{
- public enum Direction
- {
- NORTH,
- NORTHEAST,
- EAST,
- SOUTHEAST,
- SOUTH,
- SOUTHWEST,
- WEST,
- NORTHWEST
- }
+ NORTH,
+ NORTHEAST,
+ EAST,
+ SOUTHEAST,
+ SOUTH,
+ SOUTHWEST,
+ WEST,
+ NORTHWEST
}
diff --git a/src/SimAI/Engine/Entities/VMEntity.cs b/src/SimAI/Engine/Entities/VMEntity.cs
new file mode 100644
index 0000000..6098628
--- /dev/null
+++ b/src/SimAI/Engine/Entities/VMEntity.cs
@@ -0,0 +1,157 @@
+// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+// If a copy of the MPL was not distributed with this file, You can obtain one at
+// http://mozilla.org/MPL/2.0/.
+using SimAI;
+
+namespace SimAntics.Engine.Entities;
+
+public class VMEntityRTTI
+{
+ public string[]? AttributeLabels;
+}
+
+public abstract class VMEntity
+{
+ public static bool UseWorld = true;
+ public VMEntityRTTI? RTTI;
+ public bool GhostImage;
+
+ public short ObjectID;
+ public uint PersistID;
+
+ public short[]? ObjectData;
+ public LinkedList MyList = new();
+ // public List SoundThreads;
+
+ // public VMRuntimeHeadline Headline;
+ ///
+ /// IS NOT serialized, but rather regenerated on deserialize.
+ ///
+ // public VMHeadlineRenderer HeadlineRenderer;
+
+ // public GameObject Object;
+ public VMThread? Thread;
+ // public VMMultitileGroup MultitileGroup;
+
+ public short MainParam; //parameters passed to main on creation.
+ public short MainStackOBJ;
+
+ public VMEntity[] Contained = new VMEntity[0];
+ public VMEntity? Container;
+ public short ContainerSlot;
+ ///
+ /// set when the entity is removed, threads owned by this object or with this object as callee will be cancelled/have their stack emptied
+ ///
+ public bool Dead;
+
+ /** Relationship variables **/
+ public Dictionary>? MeToObject;
+ public Dictionary>? MeToPersist;
+ //a runtime cache for objects that have relationships to us. Used to get a quick reference to objects
+ //that may need to delete a relationship to us.
+ //note this can point to false positives, but the worst case is a slow deletion if somehow every object is added.
+ public HashSet MayHaveRelToMe = new();
+
+ //signals which relationships have changed since the last time this was reset
+ //used to partial update relationships when doing an avatar save to db
+ public HashSet ChangedRels = new();
+
+ public ulong DynamicSpriteFlags; /** Used to show/hide dynamic sprites **/
+ public ulong DynamicSpriteFlags2;
+ //public VMObstacle Footprint;
+
+ //LotTilePos _Position = new LotTilePos(LotTilePos.OUT_OF_WORLD);
+ //public EntityComponent WorldUI;
+
+ public uint TimestampLockoutCount = 0;
+ //public Color LightColor = Color.White;
+
+ //inferred properties (from object resource)
+ //public GameGlobalResource SemiGlobal;
+ //public TTAB TreeTable;
+ //public TTAs TreeTableStrings;
+ //public Dictionary TreeByName;
+ //public SLOT Slots;
+ //public OBJD MasterDefinition; //if this object is multitile, its master definition will be stored here.
+ //public OBJfFunctionEntry[] EntryPoints; /** Entry points for specific events, eg. init, main, clean... **/
+ //public virtual bool MovesOften
+ //{
+ // get
+ // {
+ // if (Container != null) return true;
+ // if (Slots == null) return false;
+ // if (!Slots.Slots.ContainsKey(3)) return false;
+ // var slots = Slots.Slots[3];
+ // return (slots.Count > 7);
+ // }
+ //}
+
+ //public string Name
+ //{
+ // get
+ // {
+ // if (MultitileGroup.Name != "") return MultitileGroup.Name;
+ // else return this.ToString();
+ // }
+ // set
+ // {
+ // MultitileGroup.Name = value;
+ // }
+ //}
+
+ //bool DynamicMultitile
+ //{
+ // get
+ // {
+ // return EntryPoints[8].ActionFunction >= 256;
+ // }
+ //}
+
+ //public override string ToString()
+ //{
+ // if (MultitileGroup.Name != "") return MultitileGroup.Name;
+ // var strings = Object.Resource.Get(Object.OBJ.CatalogStringsID);
+ // if (strings != null)
+ // {
+ // return strings.GetString(0);
+ // }
+ // var label = Object.OBJ.ChunkLabel;
+ // if (label != null && label.Length > 0)
+ // {
+ // return label;
+ // }
+ // return Object.OBJ.GUID.ToString("X");
+ //}
+
+ //positioning properties
+
+ protected static Direction[] DirectionNotches = new Direction[]
+ {
+ Direction.NORTH,
+ Direction.NORTHEAST,
+ Direction.EAST,
+ Direction.SOUTHEAST,
+ Direction.SOUTH,
+ Direction.SOUTHWEST,
+ Direction.WEST,
+ Direction.NORTHWEST
+ };
+
+ //public LotTilePos Position
+ //{
+ // get { return _Position; }
+ // set
+ // {
+ // _Position = value;
+ // if (UseWorld) WorldUI.Level = Position.Level;
+ // if (this is VMAvatar) ((VMAvatar)this).VisualPositionStart = null;
+ // VisualPosition = new Vector3(_Position.x / 16.0f, _Position.y / 16.0f, (_Position.Level - 1) * 2.95f);
+ // }
+ // }
+
+ // public abstract Vector3 VisualPosition { get; set; }
+ public abstract Direction Direction { get; set; }
+ public abstract float RadianDirection { get; set; }
+
+
+}
diff --git a/src/SimAI/Engine/VMMemory.cs b/src/SimAI/Engine/VMMemory.cs
index 3d4b85c..bc27363 100644
--- a/src/SimAI/Engine/VMMemory.cs
+++ b/src/SimAI/Engine/VMMemory.cs
@@ -1,12 +1,11 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-namespace SimAI.Engine
+namespace SimAI.Engine;
+
+public class VMMemory
{
- public class VMMemory
- {
- public VMMemory()
- {
- }
- }
+ public VMMemory()
+ {
+ }
}
diff --git a/src/SimAI/Engine/VMScheduler.cs b/src/SimAI/Engine/VMScheduler.cs
index 87f489a..89d78c9 100644
--- a/src/SimAI/Engine/VMScheduler.cs
+++ b/src/SimAI/Engine/VMScheduler.cs
@@ -1,32 +1,30 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-using System.Collections.Generic;
-using SimAI.Engine.Entities;
+using SimAntics.Engine.Entities;
-namespace SimAI.Engine
+namespace SimAI.Engine;
+
+public class VMScheduler
{
- public class VMScheduler
- {
- VM VM { get; set; }
+ VM VM { get; set; }
- Dictionary> _tickScheduler = new Dictionary>();
- List _tickThisFrame;
+ Dictionary> _tickScheduler = new();
+ List _tickThisFrame;
- public HashSet PendingDeletion { get; set; } = new HashSet();
- public uint CurrentTickID { get; set; }
- public short CurrentObjectID { get; set; }
- public bool RunningNow { get; set; }
+ public HashSet PendingDeletion { get; set; } = new HashSet();
+ public uint CurrentTickID { get; set; }
+ public short CurrentObjectID { get; set; }
+ public bool RunningNow { get; set; }
- public VMScheduler(VM vm)
- {
- VM = vm;
- }
+ public VMScheduler(VM vm)
+ {
+ VM = vm;
+ }
- public void ScheduleTickIn(VMEntity _ent, uint delay)
- {
+ public void ScheduleTickIn(VMEntity _ent, uint delay)
+ {
- }
- }
+ }
}
diff --git a/src/SimAI/Engine/VMStackFrame.cs b/src/SimAI/Engine/VMStackFrame.cs
index fd5a424..2728a07 100644
--- a/src/SimAI/Engine/VMStackFrame.cs
+++ b/src/SimAI/Engine/VMStackFrame.cs
@@ -2,178 +2,176 @@
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-using SimAI.Engine.Entities;
-using SimAI.Marshals;
+using SimAntics.Engine.Entities;
-namespace SimAI.Engine
-{
- ///
- /// Holds information about the execution of a routine
- ///
- public class VMStackFrame
- {
- public VMStackFrame() { }
+namespace SimAI.Engine;
- /** Thread executing this routine **/
- public VMThread Thread;
+///
+/// Holds information about the execution of a routine
+///
+public class VMStackFrame
+ {
+ public VMStackFrame() { }
- /** Routine that this context relates to **/
- // public VMRoutine Routine;
+ /** Thread executing this routine **/
+ public VMThread Thread;
- /** Current instruction **/
- public ushort InstructionPointer;
+ /** Routine that this context relates to **/
+ // public VMRoutine Routine;
- /** The object who executed this behavior **/
- public VMEntity Caller;
+ /** Current instruction **/
+ public ushort InstructionPointer;
- /** The object the code is running on **/
- public VMEntity Callee;
+ /** The object who executed this behavior **/
+ public VMEntity Caller;
- /** An object selected by the code to perform operations on. **/
- public VMEntity StackObject
- {
- get { return _StackObject; }
- set
- {
- _StackObject = value;
- _StackObjectID = value?.ObjectID ?? 0;
- }
- }
- public short StackObjectID
- {
- get { return _StackObjectID; }
- set
- {
- _StackObjectID = value;
- _StackObject = VM.GetObjectById(value);
- }
- }
+ /** The object the code is running on **/
+ public VMEntity Callee;
- VMEntity _StackObject;
- public short _StackObjectID;
+ /** An object selected by the code to perform operations on. **/
+ public VMEntity StackObject
+ {
+ get { return _StackObject; }
+ set
+ {
+ _StackObject = value;
+ _StackObjectID = value?.ObjectID ?? 0;
+ }
+ }
+ public short StackObjectID
+ {
+ get { return _StackObjectID; }
+ set
+ {
+ _StackObjectID = value;
+ _StackObject = VM.GetObjectById(value);
+ }
+ }
- /** If true, this stack frame is not a subroutine. Return with a continue. **/
- public bool DiscardResult;
+ VMEntity _StackObject;
+ public short _StackObjectID;
- /** Indicates that the current stack frame is part of an action tree.
- ** Set by "idle for input, allow push", when an interaction is selected.
- ** Used to stop recursive interactions, is only false when within "main".
- **/
- public bool ActionTree;
+ /** If true, this stack frame is not a subroutine. Return with a continue. **/
+ public bool DiscardResult;
- /** Used to get strings and other resources (for primitives) from the code owner, as it may not be the callee but instead a semiglobal or global. **/
- //public GameIffResource ScopeResource
- //{
- // get
- // {
- // return CodeOwner.Resource;
- // }
- //}
+ /** Indicates that the current stack frame is part of an action tree.
+ ** Set by "idle for input, allow push", when an interaction is selected.
+ ** Used to stop recursive interactions, is only false when within "main".
+ **/
+ public bool ActionTree;
- //public GameObject CodeOwner;
- /**
- * Routine locals
- */
- public short[] Locals;
+ /** Used to get strings and other resources (for primitives) from the code owner, as it may not be the callee but instead a semiglobal or global. **/
+ //public GameIffResource ScopeResource
+ //{
+ // get
+ // {
+ // return CodeOwner.Resource;
+ // }
+ //}
- /**
- * Arguments
- */
- public short[] Args;
+ //public GameObject CodeOwner;
+ /**
+ * Routine locals
+ */
+ public short[] Locals;
- //public GameObjectResource CallerPrivate
- //{
- // get
- // {
- // return Caller.Object.Resource;
- // }
- //}
+ /**
+ * Arguments
+ */
+ public short[] Args;
- //public GameObjectResource CalleePrivate
- //{
- // get
- // {
- // return Callee.Object.Resource;
- // }
- //}
+ //public GameObjectResource CallerPrivate
+ //{
+ // get
+ // {
+ // return Caller.Object.Resource;
+ // }
+ //}
- //public GameObjectResource StackObjPrivate
- //{
- // get
- // {
- // return StackObject.Object.Resource;
- // }
- //}
+ //public GameObjectResource CalleePrivate
+ //{
+ // get
+ // {
+ // return Callee.Object.Resource;
+ // }
+ //}
- //public GameGlobal Global
- //{
- // get
- // {
- // return Thread.Context.Globals;
- // }
- //}
+ //public GameObjectResource StackObjPrivate
+ //{
+ // get
+ // {
+ // return StackObject.Object.Resource;
+ // }
+ //}
- public VM VM
- {
- get
- {
- return Thread.Context.VM;
- }
- }
+ //public GameGlobal Global
+ //{
+ // get
+ // {
+ // return Thread.Context.Globals;
+ // }
+ //}
- /** Utilities **/
- //public VMInstruction GetCurrentInstruction()
- //{
- // return Routine.Instructions[InstructionPointer];
- //}
+ public VM VM
+ {
+ get
+ {
+ return Thread.Context.VM;
+ }
+ }
- //public T GetCurrentOperand()
- //{
- // return (T)GetCurrentInstruction().Operand;
- //}
+ /** Utilities **/
+ //public VMInstruction GetCurrentInstruction()
+ //{
+ // return Routine.Instructions[InstructionPointer];
+ //}
- #region VM Marshalling Functions
- //public virtual VMStackFrameMarshal Save()
- //{
- // return new VMStackFrameMarshal
- // {
- // RoutineID = Routine?.ID ?? 0,
- // InstructionPointer = InstructionPointer,
- // Caller = (Caller == null) ? (short)0 : Caller.ObjectID,
- // Callee = (Callee == null) ? (short)0 : Callee.ObjectID,
- // StackObject = StackObjectID,
- // CodeOwnerGUID = CodeOwner.OBJ.GUID,
- // Locals = (short[])Locals?.Clone(),
- // Args = (short[])Args?.Clone(),
- // DiscardResult = DiscardResult,
- // ActionTree = ActionTree,
- // };
- //}
+ //public T GetCurrentOperand()
+ //{
+ // return (T)GetCurrentInstruction().Operand;
+ //}
- public virtual void Load(VMStackFrameMarshal input, VMContext context)
- {
- // CodeOwner = GameContent.Get.WorldObjects.Get(input.CodeOwnerGUID);
+ #region VM Marshalling Functions
+ //public virtual VMStackFrameMarshal Save()
+ //{
+ // return new VMStackFrameMarshal
+ // {
+ // RoutineID = Routine?.ID ?? 0,
+ // InstructionPointer = InstructionPointer,
+ // Caller = (Caller == null) ? (short)0 : Caller.ObjectID,
+ // Callee = (Callee == null) ? (short)0 : Callee.ObjectID,
+ // StackObject = StackObjectID,
+ // CodeOwnerGUID = CodeOwner.OBJ.GUID,
+ // Locals = (short[])Locals?.Clone(),
+ // Args = (short[])Args?.Clone(),
+ // DiscardResult = DiscardResult,
+ // ActionTree = ActionTree,
+ // };
+ //}
- // Routine = null;
- //if (input.RoutineID >= 8192) Routine = (VMRoutine)ScopeResource.SemiGlobal.GetRoutine(input.RoutineID);
- //else if (input.RoutineID >= 4096) Routine = (VMRoutine)ScopeResource.GetRoutine(input.RoutineID);
- //else Routine = (VMRoutine)Global.Resource.GetRoutine(input.RoutineID);
+ public virtual void Load(VMStackFrameMarshal input, VMContext context)
+ {
+ // CodeOwner = GameContent.Get.WorldObjects.Get(input.CodeOwnerGUID);
- InstructionPointer = input.InstructionPointer;
- Caller = context.VM.GetObjectById(input.Caller);
- Callee = context.VM.GetObjectById(input.Callee);
- StackObjectID = input.StackObject;
- Locals = input.Locals;
- Args = input.Args;
- DiscardResult = input.DiscardResult;
- ActionTree = input.ActionTree;
- }
+ // Routine = null;
+ //if (input.RoutineID >= 8192) Routine = (VMRoutine)ScopeResource.SemiGlobal.GetRoutine(input.RoutineID);
+ //else if (input.RoutineID >= 4096) Routine = (VMRoutine)ScopeResource.GetRoutine(input.RoutineID);
+ //else Routine = (VMRoutine)Global.Resource.GetRoutine(input.RoutineID);
- public VMStackFrame(VMStackFrameMarshal input, VMContext context, VMThread thread)
- {
- Thread = thread;
- // Load(input, context);
- }
- #endregion
- }
-}
+ InstructionPointer = input.InstructionPointer;
+ Caller = context.VM.GetObjectById(input.Caller);
+ Callee = context.VM.GetObjectById(input.Callee);
+ StackObjectID = input.StackObject;
+ Locals = input.Locals;
+ Args = input.Args;
+ DiscardResult = input.DiscardResult;
+ ActionTree = input.ActionTree;
+ }
+
+ public VMStackFrame(VMStackFrameMarshal input, VMContext context, VMThread thread)
+ {
+ Thread = thread;
+ // Load(input, context);
+ }
+ #endregion
+ }
diff --git a/src/SimAI/Engine/VMThread.cs b/src/SimAI/Engine/VMThread.cs
index 0f4e24b..1928109 100644
--- a/src/SimAI/Engine/VMThread.cs
+++ b/src/SimAI/Engine/VMThread.cs
@@ -5,52 +5,50 @@
#define IDE_COMPAT
#endif
-using System.Collections.Generic;
-using SimAI.Engine.Entities;
+using SimAntics.Engine.Entities;
-namespace SimAI.Engine
+namespace SimAI.Engine;
+
+///
+/// Compatibility class
+///
+public class VMThread : VMInstruction { }
+
+///
+/// Handles instruction sets
+///
+public class VMInstruction
{
- ///
- /// Compatibility class
- ///
- public class VMThread : VMInstruction { }
-
- ///
- /// Handles instruction sets
- ///
- public class VMInstruction
- {
- public static int MAX_USER_ACTIONS = 20;
+ public static int MAX_USER_ACTIONS = 20;
- public VMContext Context;
+ public VMContext? Context;
- //check tree only vars
- public bool IsCheck;
+ //check tree only vars
+ public bool IsCheck;
- VMEntity Entity;
+ VMEntity? Entity;
- public List Stack;
- bool ContinueExecution;
+ public List? Stack;
+ bool ContinueExecution;
- public string ThreadBreakString;
- public int BreakFrame; //frame the last breakpoint was performed on
- public bool RoutineDirty;
+ public string? ThreadBreakString;
+ public int BreakFrame; //frame the last breakpoint was performed on
+ public bool RoutineDirty;
- public bool Interrupt;
+ public bool Interrupt;
- ushort ActionUID;
+ ushort ActionUID;
- // Exception handling variables
- // Don't need to be serialized.
- public int DialogCooldown = 0;
- // the number of ticks that have executed so far this frame. If this exceeds the allowed max,
- // the thread resets, and a SimAI Error pops up.
- public int TicksThisFrame = 0;
- // the maximum number of primitives a thread can execute in one frame. Tweak appropriately.
+ // Exception handling variables
+ // Don't need to be serialized.
+ public int DialogCooldown = 0;
+ // the number of ticks that have executed so far this frame. If this exceeds the allowed max,
+ // the thread resets, and a SimAI Error pops up.
+ public int TicksThisFrame = 0;
+ // the maximum number of primitives a thread can execute in one frame. Tweak appropriately.
- // variables for internal scheduler
- public uint ScheduleIdleStart; // keep track of tick when we started idling for an object. must be synced!
- public uint ScheduleIdleEnd;
+ // variables for internal scheduler
+ public uint ScheduleIdleStart; // keep track of tick when we started idling for an object. must be synced!
+ public uint ScheduleIdleEnd;
- }
}
\ No newline at end of file
diff --git a/src/SimAI/Entities/VMEntity.cs b/src/SimAI/Entities/VMEntity.cs
deleted file mode 100644
index 0856b81..0000000
--- a/src/SimAI/Entities/VMEntity.cs
+++ /dev/null
@@ -1,158 +0,0 @@
-// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
-// If a copy of the MPL was not distributed with this file, You can obtain one at
-// http://mozilla.org/MPL/2.0/.
-using System.Collections.Generic;
-
-namespace SimAI.Engine.Entities
-{
- public class VMEntityRTTI
- {
- public string[] AttributeLabels;
- }
-
- public abstract class VMEntity
- {
- public static bool UseWorld = true;
- public VMEntityRTTI RTTI;
- public bool GhostImage;
-
- public short ObjectID;
- public uint PersistID;
-
- public short[] ObjectData;
- public LinkedList MyList = new LinkedList();
- // public List SoundThreads;
-
- // public VMRuntimeHeadline Headline;
- ///
- /// IS NOT serialized, but rather regenerated on deserialize.
- ///
- // public VMHeadlineRenderer HeadlineRenderer;
-
- // public GameObject Object;
- public VMThread Thread;
- // public VMMultitileGroup MultitileGroup;
-
- public short MainParam; //parameters passed to main on creation.
- public short MainStackOBJ;
-
- public VMEntity[] Contained = new VMEntity[0];
- public VMEntity Container;
- public short ContainerSlot;
- ///
- /// set when the entity is removed, threads owned by this object or with this object as callee will be cancelled/have their stack emptied
- ///
- public bool Dead;
-
- /** Relationship variables **/
- public Dictionary> MeToObject;
- public Dictionary> MeToPersist;
- //a runtime cache for objects that have relationships to us. Used to get a quick reference to objects
- //that may need to delete a relationship to us.
- //note this can point to false positives, but the worst case is a slow deletion if somehow every object is added.
- public HashSet MayHaveRelToMe = new HashSet();
-
- //signals which relationships have changed since the last time this was reset
- //used to partial update relationships when doing an avatar save to db
- public HashSet ChangedRels = new HashSet();
-
- public ulong DynamicSpriteFlags; /** Used to show/hide dynamic sprites **/
- public ulong DynamicSpriteFlags2;
- //public VMObstacle Footprint;
-
- //LotTilePos _Position = new LotTilePos(LotTilePos.OUT_OF_WORLD);
- //public EntityComponent WorldUI;
-
- public uint TimestampLockoutCount = 0;
- //public Color LightColor = Color.White;
-
- //inferred properties (from object resource)
- //public GameGlobalResource SemiGlobal;
- //public TTAB TreeTable;
- //public TTAs TreeTableStrings;
- //public Dictionary TreeByName;
- //public SLOT Slots;
- //public OBJD MasterDefinition; //if this object is multitile, its master definition will be stored here.
- //public OBJfFunctionEntry[] EntryPoints; /** Entry points for specific events, eg. init, main, clean... **/
- //public virtual bool MovesOften
- //{
- // get
- // {
- // if (Container != null) return true;
- // if (Slots == null) return false;
- // if (!Slots.Slots.ContainsKey(3)) return false;
- // var slots = Slots.Slots[3];
- // return (slots.Count > 7);
- // }
- //}
-
- //public string Name
- //{
- // get
- // {
- // if (MultitileGroup.Name != "") return MultitileGroup.Name;
- // else return this.ToString();
- // }
- // set
- // {
- // MultitileGroup.Name = value;
- // }
- //}
-
- //bool DynamicMultitile
- //{
- // get
- // {
- // return EntryPoints[8].ActionFunction >= 256;
- // }
- //}
-
- //public override string ToString()
- //{
- // if (MultitileGroup.Name != "") return MultitileGroup.Name;
- // var strings = Object.Resource.Get(Object.OBJ.CatalogStringsID);
- // if (strings != null)
- // {
- // return strings.GetString(0);
- // }
- // var label = Object.OBJ.ChunkLabel;
- // if (label != null && label.Length > 0)
- // {
- // return label;
- // }
- // return Object.OBJ.GUID.ToString("X");
- //}
-
- //positioning properties
-
- protected static Direction[] DirectionNotches = new Direction[]
- {
- Direction.NORTH,
- Direction.NORTHEAST,
- Direction.EAST,
- Direction.SOUTHEAST,
- Direction.SOUTH,
- Direction.SOUTHWEST,
- Direction.WEST,
- Direction.NORTHWEST
- };
-
- //public LotTilePos Position
- //{
- // get { return _Position; }
- // set
- // {
- // _Position = value;
- // if (UseWorld) WorldUI.Level = Position.Level;
- // if (this is VMAvatar) ((VMAvatar)this).VisualPositionStart = null;
- // VisualPosition = new Vector3(_Position.x / 16.0f, _Position.y / 16.0f, (_Position.Level - 1) * 2.95f);
- // }
- // }
-
- // public abstract Vector3 VisualPosition { get; set; }
- public abstract Direction Direction { get; set; }
- public abstract float RadianDirection { get; set; }
-
-
- }
-}
diff --git a/src/SimAI/GlobalUsing.cs b/src/SimAI/GlobalUsing.cs
new file mode 100644
index 0000000..6908a59
--- /dev/null
+++ b/src/SimAI/GlobalUsing.cs
@@ -0,0 +1,2 @@
+global using SimAI.Engine;
+global using SimAI.Marshals;
\ No newline at end of file
diff --git a/src/SimAI/IVM.cs b/src/SimAI/IVM.cs
index 8589488..c2a90eb 100644
--- a/src/SimAI/IVM.cs
+++ b/src/SimAI/IVM.cs
@@ -1,15 +1,13 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
+namespace SimAI;
-namespace SimAI
+public interface IVM
{
- public interface IVM
- {
- void Init();
- void Reset();
- void Update();
- void Tick();
- void InternalTick(uint tickId);
- }
+ void Init();
+ void Reset();
+ void Update();
+ void Tick();
+ void InternalTick(uint tickId);
}
diff --git a/src/SimAI/Interfaces/VMIMotiveDecay.cs b/src/SimAI/Interfaces/VMIMotiveDecay.cs
index bef333a..ee61456 100644
--- a/src/SimAI/Interfaces/VMIMotiveDecay.cs
+++ b/src/SimAI/Interfaces/VMIMotiveDecay.cs
@@ -1,10 +1,9 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-namespace SimAI.Interfaces
+namespace SimAI.Interfaces;
+
+public interface VMIMotiveDecay : VMSerializable
{
- public interface VMIMotiveDecay : VMSerializable
- {
- // void Tick(VMAvatar avatar, VMContext context);
- }
+ // void Tick(VMAvatar avatar, VMContext context);
}
diff --git a/src/SimAI/Interfaces/VMSerializable.cs b/src/SimAI/Interfaces/VMSerializable.cs
index 9c19dea..e2a6100 100644
--- a/src/SimAI/Interfaces/VMSerializable.cs
+++ b/src/SimAI/Interfaces/VMSerializable.cs
@@ -1,9 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-namespace SimAI.Interfaces
+namespace SimAI.Interfaces;
+
+public interface VMSerializable
{
- public interface VMSerializable
- {
- }
}
\ No newline at end of file
diff --git a/src/SimAI/Marshals/VMMarshal.cs b/src/SimAI/Marshals/VMMarshal.cs
index af9ce13..da90a89 100644
--- a/src/SimAI/Marshals/VMMarshal.cs
+++ b/src/SimAI/Marshals/VMMarshal.cs
@@ -1,13 +1,11 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-using System;
-namespace SimAI.Marshals
+namespace SimAI.Marshals;
+
+public class VMMarshal
{
- public class VMMarshal
- {
- public VMMarshal()
- {
- }
- }
+ public VMMarshal()
+ {
+ }
}
diff --git a/src/SimAI/Marshals/VMStackFrameMarshal.cs b/src/SimAI/Marshals/VMStackFrameMarshal.cs
index 4ce62c7..294b500 100644
--- a/src/SimAI/Marshals/VMStackFrameMarshal.cs
+++ b/src/SimAI/Marshals/VMStackFrameMarshal.cs
@@ -1,70 +1,66 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-using System;
-using System.IO;
+namespace SimAI.Marshals;
-namespace SimAI.Marshals
+public class VMStackFrameMarshal
{
- public class VMStackFrameMarshal
- {
- public ushort RoutineID { get; set; }
- public ushort InstructionPointer { get; set; }
- public short Caller { get; set; }
- public short Callee { get; set; }
- public short StackObject { get; set; }
- public uint CodeOwnerGUID { get; set; }
- public short[] Locals { get; set; }
- public short[] Args { get; set; }
- public bool DiscardResult { get; set; }
- public bool ActionTree { get; set; }
+ public ushort RoutineID { get; set; }
+ public ushort InstructionPointer { get; set; }
+ public short Caller { get; set; }
+ public short Callee { get; set; }
+ public short StackObject { get; set; }
+ public uint CodeOwnerGUID { get; set; }
+ public short[] Locals { get; set; }
+ public short[] Args { get; set; }
+ public bool DiscardResult { get; set; }
+ public bool ActionTree { get; set; }
- public int Version { get; set; }
+ public int Version { get; set; }
- public VMStackFrameMarshal() { }
- public VMStackFrameMarshal(int version) { Version = version; }
+ public VMStackFrameMarshal() { }
+ public VMStackFrameMarshal(int version) { Version = version; }
- public virtual void Deserialize(BinaryReader reader)
- {
- RoutineID = reader.ReadUInt16();
- InstructionPointer = reader.ReadUInt16();
- Caller = reader.ReadInt16();
- Callee = reader.ReadInt16();
- StackObject = reader.ReadInt16();
- CodeOwnerGUID = reader.ReadUInt32();
+ public virtual void Deserialize(BinaryReader reader)
+ {
+ RoutineID = reader.ReadUInt16();
+ InstructionPointer = reader.ReadUInt16();
+ Caller = reader.ReadInt16();
+ Callee = reader.ReadInt16();
+ StackObject = reader.ReadInt16();
+ CodeOwnerGUID = reader.ReadUInt32();
- var localN = reader.ReadInt32();
- if (localN > -1)
- {
- Locals = new short[localN];
- for (var i = 0; i < localN; i++) Locals[i] = reader.ReadInt16();
- }
+ var localN = reader.ReadInt32();
+ if (localN > -1)
+ {
+ Locals = new short[localN];
+ for (var i = 0; i < localN; i++) Locals[i] = reader.ReadInt16();
+ }
- var argsN = reader.ReadInt32();
- if (argsN > -1)
- {
- Args = new short[argsN];
- for (var i = 0; i < argsN; i++) Args[i] = reader.ReadInt16();
- }
+ var argsN = reader.ReadInt32();
+ if (argsN > -1)
+ {
+ Args = new short[argsN];
+ for (var i = 0; i < argsN; i++) Args[i] = reader.ReadInt16();
+ }
- if (Version > 3) DiscardResult = reader.ReadBoolean();
- ActionTree = reader.ReadBoolean();
- }
+ if (Version > 3) DiscardResult = reader.ReadBoolean();
+ ActionTree = reader.ReadBoolean();
+ }
- public virtual void SerializeInto(BinaryWriter writer)
- {
- writer.Write(RoutineID);
- writer.Write(InstructionPointer);
- writer.Write(Caller);
- writer.Write(Callee);
- writer.Write(StackObject);
- writer.Write(CodeOwnerGUID);
- writer.Write((Locals == null) ? -1 : Locals.Length);
- //if (Locals != null) writer.Write(VMSerializableUtils.ToByteArray(Locals));
- //writer.Write((Args == null) ? -1 : Args.Length);
- //if (Args != null) writer.Write(VMSerializableUtils.ToByteArray(Args));
- writer.Write(DiscardResult);
- writer.Write(ActionTree);
- }
- }
+ public virtual void SerializeInto(BinaryWriter writer)
+ {
+ writer.Write(RoutineID);
+ writer.Write(InstructionPointer);
+ writer.Write(Caller);
+ writer.Write(Callee);
+ writer.Write(StackObject);
+ writer.Write(CodeOwnerGUID);
+ writer.Write((Locals == null) ? -1 : Locals.Length);
+ //if (Locals != null) writer.Write(VMSerializableUtils.ToByteArray(Locals));
+ //writer.Write((Args == null) ? -1 : Args.Length);
+ //if (Args != null) writer.Write(VMSerializableUtils.ToByteArray(Args));
+ writer.Write(DiscardResult);
+ writer.Write(ActionTree);
+ }
}
diff --git a/src/SimAI/SimAI.csproj b/src/SimAI/SimAI.csproj
index c7b2018..742a955 100644
--- a/src/SimAI/SimAI.csproj
+++ b/src/SimAI/SimAI.csproj
@@ -1,13 +1,16 @@
-
- netstandard2.0
- SimAntics
-
+
+ net6.0
+ SimAntics
+ enable
+ enable
+ Tony Bark
+
-
-
-
-
-
+
+
+
+
+
diff --git a/src/SimAI/VM.cs b/src/SimAI/VM.cs
index b4fd88e..0f8dd2c 100644
--- a/src/SimAI/VM.cs
+++ b/src/SimAI/VM.cs
@@ -1,144 +1,140 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-using System;
-using System.Collections.Generic;
-using SimAI.Engine;
-using SimAI.Engine.Entities;
+using SimAntics.Engine.Entities;
-namespace SimAI
+namespace SimAI;
+
+///
+/// VM is an abstract class that contains the
+///
+public abstract class VM : IVM
{
- ///
- /// VM is an abstract class that contains the
- ///
- public abstract class VM : IVM
- {
- public bool IsTS1 { get; set; }
- public bool Ready { get; set; }
- public bool BHAVDirty { get; set; }
- public VMContext Context { get; internal set; }
- public VMScheduler Scheduler { set; get; }
+ public bool IsTS1 { get; set; }
+ public bool Ready { get; set; }
+ public bool BHAVDirty { get; set; }
+ public VMContext Context { get; internal set; }
+ public VMScheduler Scheduler { set; get; }
- public delegate void VMRefreshHandler();
- public delegate void VMLotSwitchHandler(uint lotId);
+ public delegate void VMRefreshHandler();
+ public delegate void VMLotSwitchHandler(uint lotId);
- Dictionary ObjectsById = new Dictionary();
- short ObjectId = 1;
+ Dictionary ObjectsById = new();
+ short ObjectId = 1;
- public List Entities = new List();
- public HashSet SoundEntities = new HashSet();
- public short[] GlobalState;
-
- int GameTickRate = 60;
- int GameTickNum = 0;
- public int SpeedMultiplier = 1;
- public int LastSpeedMultiplier;
- int LastFrameSpeed = 1;
- float Fraction;
- public VMEntity GlobalBlockingDialog;
+ public List Entities = new();
+ public HashSet SoundEntities = new();
+ public short[] GlobalState;
- ///
- /// Gets an entity from this VM.
- ///
- /// The entity's ID.
- /// A VMEntity instance associated with the ID.
- public VMEntity GetObjectById(short id)
- {
- return ObjectsById.ContainsKey(id) ? ObjectsById[id] : null;
- }
+ int GameTickRate = 60;
+ int GameTickNum = 0;
+ public int SpeedMultiplier = 1;
+ public int LastSpeedMultiplier;
+ int LastFrameSpeed = 1;
+ float Fraction;
+ public VMEntity GlobalBlockingDialog;
- ///
- /// Constructs a new Virtual Machine instance.
- ///
- /// The VMContext instance to use.
- public VM(VMContext context)
- {
- context.VM = this;
- Context = context;
- Scheduler = new VMScheduler(this);
- }
+ ///
+ /// Gets an entity from this VM.
+ ///
+ /// The entity's ID.
+ /// A VMEntity instance associated with the ID.
+ public VMEntity? GetObjectById(short id)
+ {
+ return ObjectsById.ContainsKey(id) ? ObjectsById[id] : null;
+ }
- public VMEntity GetObjectByPersist(uint id)
- {
- // return Entities.FirstOrDefault(x => x.PersistID == id);
- throw new VMSimanticsException();
- }
+ ///
+ /// Constructs a new Virtual Machine instance.
+ ///
+ /// The VMContext instance to use.
+ public VM(VMContext context)
+ {
+ context.VM = this;
+ Context = context;
+ Scheduler = new VMScheduler(this);
+ }
- public virtual void Init()
- {
- // PlatformState = (TS1)?(VMAbstractLotState)new VMTS1LotState():new VMTSOLotState();
- GlobalState = new short[38];
- GlobalState[20] = 255; //Game Edition. Basically, what "expansion packs" are running. Let's just say all of them.
- GlobalState[25] = 4; //as seen in EA-Land edith's simulator globals, this needs to be set for people to do their idle interactions.
- GlobalState[17] = 4; //Runtime Code Version, is this in EA-Land.
- // if (Driver is VMServerDriver) EODHost = new VMEODHost();
- }
+ public VMEntity GetObjectByPersist(uint id)
+ {
+ // return Entities.FirstOrDefault(x => x.PersistID == id);
+ throw new VMSimanticsException();
+ }
- public virtual void Reset()
- {
- throw new NotImplementedException();
- }
- public virtual void Update()
- {
- throw new NotImplementedException();
- }
+ public virtual void Init()
+ {
+ // PlatformState = (TS1)?(VMAbstractLotState)new VMTS1LotState():new VMTSOLotState();
+ GlobalState = new short[38];
+ GlobalState[20] = 255; //Game Edition. Basically, what "expansion packs" are running. Let's just say all of them.
+ GlobalState[25] = 4; //as seen in EA-Land edith's simulator globals, this needs to be set for people to do their idle interactions.
+ GlobalState[17] = 4; //Runtime Code Version, is this in EA-Land.
+ // if (Driver is VMServerDriver) EODHost = new VMEODHost();
+ }
- public virtual void Tick()
- {
- throw new NotImplementedException();
- }
+ public virtual void Reset()
+ {
+ throw new NotImplementedException();
+ }
+ public virtual void Update()
+ {
+ throw new NotImplementedException();
+ }
- public virtual void InternalTick(uint tickId)
- {
- throw new NotImplementedException();
- }
-
- ///
- /// Adds an entity to this Virtual Machine.
- ///
- /// The entity to add.
- public void AddEntity(VMEntity entity)
- {
- entity.ObjectID = ObjectId;
- ObjectsById.Add(entity.ObjectID, entity);
- // AddToObjList(this.Entities, entity);
- // if (!entity.GhostImage) Context.ObjectQueries.NewObject(entity);
- // ObjectId = NextObjID();
- }
-
- public static void AddToObjList(List list, VMEntity entity)
- {
- if (list.Count == 0) { list.Add(entity); return; }
- int id = entity.ObjectID;
- var max = list.Count;
- var min = 0;
- while (max>min)
- {
- var mid = (max+min) / 2;
- int nid = list[mid].ObjectID;
- if (id < nid) max = mid;
- else if (id == nid) return; //do not add dupes
- else min = mid+1;
- }
- list.Insert(min, entity);
- // list.Insert((list[min].ObjectID>id)?min:((list[max].ObjectID > id)?max:max+1), entity);
- }
+ public virtual void Tick()
+ {
+ throw new NotImplementedException();
+ }
- ///
- /// Removes an entity from this Virtual Machine.
- ///
- /// The entity to remove.
- public void RemoveEntity(VMEntity entity)
- {
- if (Entities.Contains(entity))
- {
- // Context.ObjectQueries.RemoveObject(entity);
- this.Entities.Remove(entity);
- ObjectsById.Remove(entity.ObjectID);
- // Scheduler.DescheduleTick(entity);
- if (entity.ObjectID < ObjectId) ObjectId = entity.ObjectID; //this id is now the smallest free object id.
- }
- entity.Dead = true;
- }
- }
+ public virtual void InternalTick(uint tickId)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// Adds an entity to this Virtual Machine.
+ ///
+ /// The entity to add.
+ public void AddEntity(VMEntity entity)
+ {
+ entity.ObjectID = ObjectId;
+ ObjectsById.Add(entity.ObjectID, entity);
+ // AddToObjList(this.Entities, entity);
+ // if (!entity.GhostImage) Context.ObjectQueries.NewObject(entity);
+ // ObjectId = NextObjID();
+ }
+
+ public static void AddToObjList(List list, VMEntity entity)
+ {
+ if (list.Count == 0) { list.Add(entity); return; }
+ int id = entity.ObjectID;
+ var max = list.Count;
+ var min = 0;
+ while (max > min)
+ {
+ var mid = (max + min) / 2;
+ int nid = list[mid].ObjectID;
+ if (id < nid) max = mid;
+ else if (id == nid) return; //do not add dupes
+ else min = mid + 1;
+ }
+ list.Insert(min, entity);
+ // list.Insert((list[min].ObjectID>id)?min:((list[max].ObjectID > id)?max:max+1), entity);
+ }
+
+ ///
+ /// Removes an entity from this Virtual Machine.
+ ///
+ /// The entity to remove.
+ public void RemoveEntity(VMEntity entity)
+ {
+ if (Entities.Contains(entity))
+ {
+ // Context.ObjectQueries.RemoveObject(entity);
+ this.Entities.Remove(entity);
+ ObjectsById.Remove(entity.ObjectID);
+ // Scheduler.DescheduleTick(entity);
+ if (entity.ObjectID < ObjectId) ObjectId = entity.ObjectID; //this id is now the smallest free object id.
+ }
+ entity.Dead = true;
+ }
}
\ No newline at end of file
diff --git a/src/SimAI/VMClock.cs b/src/SimAI/VMClock.cs
index ab4bddf..d96bb0f 100644
--- a/src/SimAI/VMClock.cs
+++ b/src/SimAI/VMClock.cs
@@ -1,46 +1,44 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-using System;
-namespace SimAI
+namespace SimAI;
+
+public class VMClock
{
- public class VMClock
- {
- public long Ticks { get; set; }
- public int MinuteFractions { get; set; }
- public int TicksPerMinute { get; set; }
- public int Minutes { get; set; }
- public int Hours { get; set; }
+ public long Ticks { get; set; }
+ public int MinuteFractions { get; set; }
+ public int TicksPerMinute { get; set; }
+ public int Minutes { get; set; }
+ public int Hours { get; set; }
- public int DayOfMonth = 1;
- public int Month = 6;
- public int Year = 1997;
+ public int DayOfMonth = 1;
+ public int Month = 6;
+ public int Year = 1997;
- public int FirePercent { get; set; }
- public long UTCStart = DateTime.UtcNow.Ticks;
+ public int FirePercent { get; set; }
+ public long UTCStart = DateTime.UtcNow.Ticks;
- public int TimeOfDay => (Hours >= 6 && Hours < 18) ? 0 : 1;
- public int Seconds => MinuteFractions * 60 / TicksPerMinute;
+ public int TimeOfDay => (Hours >= 6 && Hours < 18) ? 0 : 1;
+ public int Seconds => MinuteFractions * 60 / TicksPerMinute;
- public DateTime UTCNow => new DateTime(UTCStart).AddSeconds(Ticks / 30.0);
-
- public VMClock() {}
+ public DateTime UTCNow => new DateTime(UTCStart).AddSeconds(Ticks / 30.0);
- public void Tick()
- {
- if (FirePercent < 2000) FirePercent++;
- if (++MinuteFractions < TicksPerMinute) return;
- MinuteFractions = 0;
- if (++Minutes < 60) return;
- Minutes = 0;
- if (++DayOfMonth <= 30) return;
- DayOfMonth = 1;
- if (++Month <= 12) return;
- Month = 1;
- Year++;
+ public VMClock() { }
- Ticks++;
- }
- }
+ public void Tick()
+ {
+ if (FirePercent < 2000) FirePercent++;
+ if (++MinuteFractions < TicksPerMinute) return;
+ MinuteFractions = 0;
+ if (++Minutes < 60) return;
+ Minutes = 0;
+ if (++DayOfMonth <= 30) return;
+ DayOfMonth = 1;
+ if (++Month <= 12) return;
+ Month = 1;
+ Year++;
+
+ Ticks++;
+ }
}
\ No newline at end of file
diff --git a/src/SimAI/VMContext.cs b/src/SimAI/VMContext.cs
index 6ce9333..43e224e 100644
--- a/src/SimAI/VMContext.cs
+++ b/src/SimAI/VMContext.cs
@@ -1,11 +1,10 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-namespace SimAI
+namespace SimAI;
+
+public class VMContext
{
- public class VMContext
- {
- public static bool useWorld = true;
- public VM VM { get; set; }
- }
+ public static bool useWorld = true;
+ public VM? VM { get; set; }
}
\ No newline at end of file
diff --git a/src/SimAI/VMSimanticsException.cs b/src/SimAI/VMSimanticsException.cs
index ab1ea0b..33fd731 100644
--- a/src/SimAI/VMSimanticsException.cs
+++ b/src/SimAI/VMSimanticsException.cs
@@ -1,98 +1,94 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
-using System;
-using System.Collections.Generic;
using System.Text;
-using SimAI.Engine;
-namespace SimAI
+namespace SimAI;
+
+public class VMSimanticsException : Exception
{
- public class VMSimanticsException : Exception
- {
- readonly string _message;
- VMStackFrame _context;
+ readonly string _message;
+ VMStackFrame _context;
- public VMSimanticsException() { }
+ public VMSimanticsException() { }
- public VMSimanticsException(string message, VMStackFrame context) : base(message)
- {
- _context = context;
- _message = message;
- }
+ public VMSimanticsException(string message, VMStackFrame context) : base(message)
+ {
+ _context = context;
+ _message = message;
+ }
- public override string ToString()
- {
- var output = new StringBuilder();
- output.Append(_message);
- output.AppendLine();
- output.AppendLine();
- output.Append(GetStackTrace());
- return output.ToString();
- }
+ public override string ToString()
+ {
+ var output = new StringBuilder();
+ output.Append(_message);
+ output.AppendLine();
+ output.AppendLine();
+ output.Append(GetStackTrace());
+ return output.ToString();
+ }
- public string GetStackTrace()
- {
- if (_context == null) return "No Stack Info.";
+ public string GetStackTrace()
+ {
+ if (_context == null) return "No Stack Info.";
- var stack = _context.Thread.Stack;
- return GetStackTrace(stack);
- }
+ var stack = _context.Thread.Stack;
+ return GetStackTrace(stack);
+ }
- public static string GetStackTrace(List stack)
- {
- var output = new StringBuilder();
- var prevEE = "";
- var prevER = "";
+ public static string GetStackTrace(List stack)
+ {
+ var output = new StringBuilder();
+ var prevEE = "";
+ var prevER = "";
- for (var i = stack.Count - 1; i >= 0; i--)
- {
- if (i == 9 && i <= stack.Count - 8)
- {
- output.Append("...");
- output.AppendLine();
- }
- if (i > 8 && i <= stack.Count - 8) continue;
- var frame = stack[i];
- //run in tree:76
+ for (var i = stack.Count - 1; i >= 0; i--)
+ {
+ if (i == 9 && i <= stack.Count - 8)
+ {
+ output.Append("...");
+ output.AppendLine();
+ }
+ if (i > 8 && i <= stack.Count - 8) continue;
+ var frame = stack[i];
+ //run in tree:76
- var callerStr = frame.Caller.ToString();
- var calleeStr = frame.Callee?.ToString();
+ var callerStr = frame.Caller.ToString();
+ var calleeStr = frame.Callee?.ToString();
- if (callerStr != prevER || calleeStr != prevEE)
- {
- output.Append('(');
- output.Append(callerStr);
- output.Append(':');
- output.Append(calleeStr);
- output.Append(") ");
- output.AppendLine();
- prevEE = calleeStr;
- prevER = callerStr;
- }
+ if (callerStr != prevER || calleeStr != prevEE)
+ {
+ output.Append('(');
+ output.Append(callerStr);
+ output.Append(':');
+ output.Append(calleeStr);
+ output.Append(") ");
+ output.AppendLine();
+ prevEE = calleeStr;
+ prevER = callerStr;
+ }
- output.Append(" > ");
+ output.Append(" > ");
- /*if (frame is VMRoutingFrame)
- {
- output.Append("VMRoutingFrame with state: ");
- output.Append(((VMRoutingFrame)frame).State.ToString());
- }
- else
- {
- output.Append(frame.Routine.Rti.Name.TrimEnd('\0'));
- output.Append(':');
- output.Append(frame.InstructionPointer);
- output.Append(" (");
- var opcode = frame.GetCurrentInstruction().Opcode;
- var primitive = (opcode > 255) ? null : VMContext.Primitives[opcode];
- output.Append((primitive == null) ? opcode.ToString() : primitive.Name);
- output.Append(")");
- }*/
- output.AppendLine();
- }
+ /*if (frame is VMRoutingFrame)
+ {
+ output.Append("VMRoutingFrame with state: ");
+ output.Append(((VMRoutingFrame)frame).State.ToString());
+ }
+ else
+ {
+ output.Append(frame.Routine.Rti.Name.TrimEnd('\0'));
+ output.Append(':');
+ output.Append(frame.InstructionPointer);
+ output.Append(" (");
+ var opcode = frame.GetCurrentInstruction().Opcode;
+ var primitive = (opcode > 255) ? null : VMContext.Primitives[opcode];
+ output.Append((primitive == null) ? opcode.ToString() : primitive.Name);
+ output.Append(")");
+ }*/
+ output.AppendLine();
+ }
- return output.ToString();
- }
- }
+ return output.ToString();
+ }
}
diff --git a/src/global.json b/src/global.json
deleted file mode 100644
index 70a59a3..0000000
--- a/src/global.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "sdk": {
- "version": "3.1.201"
- }
-}
\ No newline at end of file