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">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
@ -11,10 +11,12 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<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">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.2.1"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="coverlet.collector" Version="1.2.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

View file

@ -1,9 +1,8 @@
using System;
using System.Diagnostics;
using Xunit;
namespace SimAI.Tests
{
namespace SimAI.Tests;
public class UnitTest1
{
[Fact]
@ -15,4 +14,3 @@ namespace SimAI.Tests
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.
// 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
{
namespace SimAI.Tests;
public class VMTest
{
public VMTest()
{
}
}
}

View file

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

View file

@ -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;
namespace SimAI
{
public enum Direction
{
NORTH,
@ -15,4 +14,3 @@ namespace SimAI
WEST,
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.
// 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 VMMemory()
{
}
}
}

View file

@ -1,16 +1,15 @@
// 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
{
VM VM { get; set; }
Dictionary<uint, List<VMEntity>> _tickScheduler = new Dictionary<uint, List<VMEntity>>();
Dictionary<uint, List<VMEntity>> _tickScheduler = new();
List<VMEntity> _tickThisFrame;
public HashSet<VMEntity> PendingDeletion { get; set; } = new HashSet<VMEntity>();
@ -29,4 +28,3 @@ namespace SimAI.Engine
}
}
}

View file

@ -2,11 +2,10 @@
// 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;
namespace SimAI.Engine
{
/// <summary>
/// Holds information about the execution of a routine
/// </summary>
@ -176,4 +175,3 @@ namespace SimAI.Engine
}
#endregion
}
}

View file

@ -5,11 +5,10 @@
#define IDE_COMPAT
#endif
using System.Collections.Generic;
using SimAI.Engine.Entities;
using SimAntics.Engine.Entities;
namespace SimAI.Engine;
namespace SimAI.Engine
{
/// <summary>
/// Compatibility class
/// </summary>
@ -22,17 +21,17 @@ namespace SimAI.Engine
{
public static int MAX_USER_ACTIONS = 20;
public VMContext Context;
public VMContext? Context;
//check tree only vars
public bool IsCheck;
VMEntity Entity;
VMEntity? Entity;
public List<VMStackFrame> Stack;
public List<VMStackFrame>? Stack;
bool ContinueExecution;
public string ThreadBreakString;
public string? ThreadBreakString;
public int BreakFrame; //frame the last breakpoint was performed on
public bool RoutineDirty;
@ -53,4 +52,3 @@ namespace SimAI.Engine
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,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;
namespace SimAI
{
public interface IVM
{
void Init();
@ -12,4 +11,3 @@ namespace SimAI
void Tick();
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.
// 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
{
// 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.
// 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
{
}
}

View file

@ -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 VMMarshal()
{
}
}
}

View file

@ -1,11 +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/.
using System;
using System.IO;
namespace SimAI.Marshals;
namespace SimAI.Marshals
{
public class VMStackFrameMarshal
{
public ushort RoutineID { get; set; }
@ -67,4 +64,3 @@ namespace SimAI.Marshals
writer.Write(ActionTree);
}
}
}

View file

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

View file

@ -1,13 +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/.
using System;
using System.Collections.Generic;
using SimAI.Engine;
using SimAI.Engine.Entities;
using SimAntics.Engine.Entities;
namespace SimAI;
namespace SimAI
{
/// <summary>
/// VM is an abstract class that contains the
/// </summary>
@ -22,11 +19,11 @@ namespace SimAI
public delegate void VMRefreshHandler();
public delegate void VMLotSwitchHandler(uint lotId);
Dictionary<short, VMEntity> ObjectsById = new Dictionary<short, VMEntity>();
Dictionary<short, VMEntity> ObjectsById = new();
short ObjectId = 1;
public List<VMEntity> Entities = new List<VMEntity>();
public HashSet<VMEntity> SoundEntities = new HashSet<VMEntity>();
public List<VMEntity> Entities = new();
public HashSet<VMEntity> SoundEntities = new();
public short[] GlobalState;
int GameTickRate = 60;
@ -42,7 +39,7 @@ namespace SimAI
/// </summary>
/// <param name="id">The entity's ID.</param>
/// <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;
}
@ -141,4 +138,3 @@ namespace SimAI
entity.Dead = true;
}
}
}

View file

@ -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/.
using System;
namespace SimAI
{
namespace SimAI;
public class VMClock
{
public long Ticks { get; set; }
@ -43,4 +42,3 @@ namespace SimAI
Ticks++;
}
}
}

View file

@ -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 static bool useWorld = true;
public VM VM { get; set; }
}
public VM? VM { get; set; }
}

View file

@ -1,13 +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/.
using System;
using System.Collections.Generic;
using System.Text;
using SimAI.Engine;
namespace SimAI
{
namespace SimAI;
public class VMSimanticsException : Exception
{
readonly string _message;
@ -95,4 +92,3 @@ namespace SimAI
return output.ToString();
}
}
}

View file

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