Target .NET 6

- Cleaned up code with Global and Implicit Usings
- Nullable is now enabled
- New .NET workflow
This commit is contained in:
Tony Bark 2023-01-02 16:26:29 -05:00
parent c042b47b4a
commit 4210e21c65
26 changed files with 776 additions and 794 deletions

View file

@ -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 }}

26
.github/workflows/dotnet.yml vendored Normal file
View file

@ -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

1
src/GlobalUsing.cs Normal file
View file

@ -0,0 +1 @@


View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
@ -11,12 +11,14 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> <PrivateAssets>all</PrivateAssets>
<PackageReference Include="coverlet.collector" Version="1.2.1"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference>
<PrivateAssets>all</PrivateAssets> <PackageReference Include="coverlet.collector" Version="1.2.1">
</PackageReference> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -1,10 +1,9 @@
using System; using System;
using System.Diagnostics;
using Xunit; using Xunit;
namespace SimAI.Tests namespace SimAI.Tests;
{
public class UnitTest1 public class UnitTest1
{ {
[Fact] [Fact]
public void Test1() public void Test1()
@ -15,4 +14,3 @@ namespace SimAI.Tests
Console.WriteLine(clock.Ticks); Console.WriteLine(clock.Ticks);
} }
} }
}

View file

@ -1,12 +1,11 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
namespace SimAI.Tests namespace SimAI.Tests;
{
public class VMTest public class VMTest
{ {
public VMTest() public VMTest()
{ {
} }
} }
}

View file

@ -1,9 +1,13 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio Version 17
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimAI", "SimAI\SimAI.csproj", "{6B758449-9D5A-456A-A733-31B7841E538A}" 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 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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.ActiveCfg = Release|Any CPU
{4B7461A4-982A-4D89-92E3-E4D4A3EC85FB}.Release|Any CPU.Build.0 = Release|Any CPU {4B7461A4-982A-4D89-92E3-E4D4A3EC85FB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0CAB232D-BCC7-412F-9D4F-715753F4DFF5}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0 Policies = $0
$0.StandardHeader = $1 $0.StandardHeader = $1

View file

@ -1,11 +1,10 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
namespace SimAI;
namespace SimAI public enum Direction
{ {
public enum Direction
{
NORTH, NORTH,
NORTHEAST, NORTHEAST,
EAST, EAST,
@ -14,5 +13,4 @@ namespace SimAI
SOUTHWEST, SOUTHWEST,
WEST, WEST,
NORTHWEST NORTHWEST
}
} }

View file

@ -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<short> MyList = new();
// public List<VMSoundEntry> SoundThreads;
// public VMRuntimeHeadline Headline;
/// <summary>
/// IS NOT serialized, but rather regenerated on deserialize.
/// </summary>
// 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;
/// <summary>
/// set when the entity is removed, threads owned by this object or with this object as callee will be cancelled/have their stack emptied
/// </summary>
public bool Dead;
/** Relationship variables **/
public Dictionary<ushort, List<short>>? MeToObject;
public Dictionary<uint, List<short>>? 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<ushort> 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<uint> 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<string, VMTreeByNameTableEntry> 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<CTSS>(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; }
}

View file

@ -1,12 +1,11 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
namespace SimAI.Engine namespace SimAI.Engine;
public class VMMemory
{ {
public class VMMemory
{
public VMMemory() public VMMemory()
{ {
} }
}
} }

View file

@ -1,16 +1,15 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
using System.Collections.Generic; using SimAntics.Engine.Entities;
using SimAI.Engine.Entities;
namespace SimAI.Engine namespace SimAI.Engine;
public class VMScheduler
{ {
public class VMScheduler
{
VM VM { get; set; } VM VM { get; set; }
Dictionary<uint, List<VMEntity>> _tickScheduler = new Dictionary<uint, List<VMEntity>>(); Dictionary<uint, List<VMEntity>> _tickScheduler = new();
List<VMEntity> _tickThisFrame; List<VMEntity> _tickThisFrame;
public HashSet<VMEntity> PendingDeletion { get; set; } = new HashSet<VMEntity>(); public HashSet<VMEntity> PendingDeletion { get; set; } = new HashSet<VMEntity>();
@ -28,5 +27,4 @@ namespace SimAI.Engine
{ {
} }
}
} }

View file

@ -2,15 +2,14 @@
// If a copy of the MPL was not distributed with this file, You can obtain one at // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
using SimAI.Engine.Entities; using SimAntics.Engine.Entities;
using SimAI.Marshals;
namespace SimAI.Engine namespace SimAI.Engine;
{
/// <summary> /// <summary>
/// Holds information about the execution of a routine /// Holds information about the execution of a routine
/// </summary> /// </summary>
public class VMStackFrame public class VMStackFrame
{ {
public VMStackFrame() { } public VMStackFrame() { }
@ -176,4 +175,3 @@ namespace SimAI.Engine
} }
#endregion #endregion
} }
}

View file

@ -5,34 +5,33 @@
#define IDE_COMPAT #define IDE_COMPAT
#endif #endif
using System.Collections.Generic; using SimAntics.Engine.Entities;
using SimAI.Engine.Entities;
namespace SimAI.Engine namespace SimAI.Engine;
/// <summary>
/// Compatibility class
/// </summary>
public class VMThread : VMInstruction { }
/// <summary>
/// Handles instruction sets
/// </summary>
public class VMInstruction
{ {
/// <summary>
/// Compatibility class
/// </summary>
public class VMThread : VMInstruction { }
/// <summary>
/// Handles instruction sets
/// </summary>
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 //check tree only vars
public bool IsCheck; public bool IsCheck;
VMEntity Entity; VMEntity? Entity;
public List<VMStackFrame> Stack; public List<VMStackFrame>? Stack;
bool ContinueExecution; bool ContinueExecution;
public string ThreadBreakString; public string? ThreadBreakString;
public int BreakFrame; //frame the last breakpoint was performed on public int BreakFrame; //frame the last breakpoint was performed on
public bool RoutineDirty; public bool RoutineDirty;
@ -52,5 +51,4 @@ namespace SimAI.Engine
public uint ScheduleIdleStart; // keep track of tick when we started idling for an object. must be synced! public uint ScheduleIdleStart; // keep track of tick when we started idling for an object. must be synced!
public uint ScheduleIdleEnd; public uint ScheduleIdleEnd;
}
} }

View file

@ -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<short> MyList = new LinkedList<short>();
// public List<VMSoundEntry> SoundThreads;
// public VMRuntimeHeadline Headline;
/// <summary>
/// IS NOT serialized, but rather regenerated on deserialize.
/// </summary>
// 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;
/// <summary>
/// set when the entity is removed, threads owned by this object or with this object as callee will be cancelled/have their stack emptied
/// </summary>
public bool Dead;
/** Relationship variables **/
public Dictionary<ushort, List<short>> MeToObject;
public Dictionary<uint, List<short>> 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<ushort> MayHaveRelToMe = new HashSet<ushort>();
//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<uint> ChangedRels = new HashSet<uint>();
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<string, VMTreeByNameTableEntry> 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<CTSS>(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; }
}
}

2
src/SimAI/GlobalUsing.cs Normal file
View file

@ -0,0 +1,2 @@
global using SimAI.Engine;
global using SimAI.Marshals;

View file

@ -1,15 +1,13 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
namespace SimAI;
namespace SimAI public interface IVM
{ {
public interface IVM
{
void Init(); void Init();
void Reset(); void Reset();
void Update(); void Update();
void Tick(); void Tick();
void InternalTick(uint tickId); void InternalTick(uint tickId);
}
} }

View file

@ -1,10 +1,9 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // 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);
}
} }

View file

@ -1,9 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
namespace SimAI.Interfaces namespace SimAI.Interfaces;
public interface VMSerializable
{ {
public interface VMSerializable
{
}
} }

View file

@ -1,13 +1,11 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
using System; namespace SimAI.Marshals;
namespace SimAI.Marshals
public class VMMarshal
{ {
public class VMMarshal
{
public VMMarshal() public VMMarshal()
{ {
} }
}
} }

View file

@ -1,13 +1,10 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
using System; namespace SimAI.Marshals;
using System.IO;
namespace SimAI.Marshals public class VMStackFrameMarshal
{ {
public class VMStackFrameMarshal
{
public ushort RoutineID { get; set; } public ushort RoutineID { get; set; }
public ushort InstructionPointer { get; set; } public ushort InstructionPointer { get; set; }
public short Caller { get; set; } public short Caller { get; set; }
@ -66,5 +63,4 @@ namespace SimAI.Marshals
writer.Write(DiscardResult); writer.Write(DiscardResult);
writer.Write(ActionTree); writer.Write(ActionTree);
} }
}
} }

View file

@ -1,12 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<RootNamespace>SimAntics</RootNamespace> <RootNamespace>SimAntics</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Authors>Tony Bark</Authors>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Entities\" /> <Folder Include="Engine\Entities\" />
<Folder Include="Interfaces\" /> <Folder Include="Interfaces\" />
<Folder Include="Marshals\" /> <Folder Include="Marshals\" />
</ItemGroup> </ItemGroup>

View file

@ -1,18 +1,15 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
using System; using SimAntics.Engine.Entities;
using System.Collections.Generic;
using SimAI.Engine;
using SimAI.Engine.Entities;
namespace SimAI namespace SimAI;
/// <summary>
/// VM is an abstract class that contains the
/// </summary>
public abstract class VM : IVM
{ {
/// <summary>
/// VM is an abstract class that contains the
/// </summary>
public abstract class VM : IVM
{
public bool IsTS1 { get; set; } public bool IsTS1 { get; set; }
public bool Ready { get; set; } public bool Ready { get; set; }
public bool BHAVDirty { get; set; } public bool BHAVDirty { get; set; }
@ -22,11 +19,11 @@ namespace SimAI
public delegate void VMRefreshHandler(); public delegate void VMRefreshHandler();
public delegate void VMLotSwitchHandler(uint lotId); public delegate void VMLotSwitchHandler(uint lotId);
Dictionary<short, VMEntity> ObjectsById = new Dictionary<short, VMEntity>(); Dictionary<short, VMEntity> ObjectsById = new();
short ObjectId = 1; short ObjectId = 1;
public List<VMEntity> Entities = new List<VMEntity>(); public List<VMEntity> Entities = new();
public HashSet<VMEntity> SoundEntities = new HashSet<VMEntity>(); public HashSet<VMEntity> SoundEntities = new();
public short[] GlobalState; public short[] GlobalState;
int GameTickRate = 60; int GameTickRate = 60;
@ -42,7 +39,7 @@ namespace SimAI
/// </summary> /// </summary>
/// <param name="id">The entity's ID.</param> /// <param name="id">The entity's ID.</param>
/// <returns>A VMEntity instance associated with the ID.</returns> /// <returns>A VMEntity instance associated with the ID.</returns>
public VMEntity GetObjectById(short id) public VMEntity? GetObjectById(short id)
{ {
return ObjectsById.ContainsKey(id) ? ObjectsById[id] : null; return ObjectsById.ContainsKey(id) ? ObjectsById[id] : null;
} }
@ -112,13 +109,13 @@ namespace SimAI
int id = entity.ObjectID; int id = entity.ObjectID;
var max = list.Count; var max = list.Count;
var min = 0; var min = 0;
while (max>min) while (max > min)
{ {
var mid = (max+min) / 2; var mid = (max + min) / 2;
int nid = list[mid].ObjectID; int nid = list[mid].ObjectID;
if (id < nid) max = mid; if (id < nid) max = mid;
else if (id == nid) return; //do not add dupes else if (id == nid) return; //do not add dupes
else min = mid+1; else min = mid + 1;
} }
list.Insert(min, entity); list.Insert(min, entity);
// list.Insert((list[min].ObjectID>id)?min:((list[max].ObjectID > id)?max:max+1), entity); // list.Insert((list[min].ObjectID>id)?min:((list[max].ObjectID > id)?max:max+1), entity);
@ -140,5 +137,4 @@ namespace SimAI
} }
entity.Dead = true; entity.Dead = true;
} }
}
} }

View file

@ -1,12 +1,11 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
using System;
namespace SimAI namespace SimAI;
public class VMClock
{ {
public class VMClock
{
public long Ticks { get; set; } public long Ticks { get; set; }
public int MinuteFractions { get; set; } public int MinuteFractions { get; set; }
public int TicksPerMinute { get; set; } public int TicksPerMinute { get; set; }
@ -25,7 +24,7 @@ namespace SimAI
public DateTime UTCNow => new DateTime(UTCStart).AddSeconds(Ticks / 30.0); public DateTime UTCNow => new DateTime(UTCStart).AddSeconds(Ticks / 30.0);
public VMClock() {} public VMClock() { }
public void Tick() public void Tick()
{ {
@ -42,5 +41,4 @@ namespace SimAI
Ticks++; Ticks++;
} }
}
} }

View file

@ -1,11 +1,10 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
namespace SimAI namespace SimAI;
public class VMContext
{ {
public class VMContext
{
public static bool useWorld = true; public static bool useWorld = true;
public VM VM { get; set; } public VM? VM { get; set; }
}
} }

View file

@ -1,15 +1,12 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.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 // If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/. // http://mozilla.org/MPL/2.0/.
using System;
using System.Collections.Generic;
using System.Text; using System.Text;
using SimAI.Engine;
namespace SimAI namespace SimAI;
public class VMSimanticsException : Exception
{ {
public class VMSimanticsException : Exception
{
readonly string _message; readonly string _message;
VMStackFrame _context; VMStackFrame _context;
@ -94,5 +91,4 @@ namespace SimAI
return output.ToString(); return output.ToString();
} }
}
} }

View file

@ -1,5 +0,0 @@
{
"sdk": {
"version": "3.1.201"
}
}