chore: bumped dotnet version to 10

This commit is contained in:
2026-01-23 12:16:07 +03:00
parent 097f1897c2
commit 90e59802c6
32 changed files with 210 additions and 257 deletions

View File

@@ -10,46 +10,41 @@ public abstract class BaseEntity : IEntity
public Event<IHasStateEnable> OnStateEnableAssigned { get; } = new(); public Event<IHasStateEnable> OnStateEnableAssigned { get; } = new();
public Event<IAssignable> OnUnassigned { get; } = new(); public Event<IAssignable> OnUnassigned { get; } = new();
private IStateEnable _stateEnable = null!; public virtual IStateEnable StateEnable { get; private set; } = null!;
private bool _initialized = false;
private string _id = string.Empty;
public virtual IStateEnable StateEnable => _stateEnable;
public string Id public string Id
{ {
get => _id; get;
set set
{ {
if (IsInitialized) if (IsInitialized)
throw new($"Can't change {nameof(Id)} of {_id} because it's initialized"); throw new($"Can't change {nameof(Id)} of {field} because it's initialized");
if (value == _id) if (value == field)
return; return;
string previousId = _id; string previousId = field;
_id = value; field = value;
OnIdChanged?.Invoke(this, new(previousId)); OnIdChanged?.Invoke(this, new(previousId));
} }
} } = string.Empty;
public bool IsInitialized public bool IsInitialized
{ {
get => _initialized; get;
private set private set
{ {
if (value == _initialized) if (value == field)
return; return;
_initialized = value; field = value;
if (value) if (value)
OnInitialized?.Invoke(this); OnInitialized?.Invoke(this);
else else
OnFinalized?.Invoke(this); OnFinalized?.Invoke(this);
} }
} } = false;
protected virtual void OnAssign(IStateEnable stateEnable) { } protected virtual void OnAssign(IStateEnable stateEnable) { }
public bool Assign(IStateEnable stateEnable) public bool Assign(IStateEnable stateEnable)
@@ -57,8 +52,8 @@ public abstract class BaseEntity : IEntity
if (IsInitialized) if (IsInitialized)
return false; return false;
_stateEnable = stateEnable; StateEnable = stateEnable;
_stateEnable.Assign(this); StateEnable.Assign(this);
OnAssign(stateEnable); OnAssign(stateEnable);
OnStateEnableAssigned?.Invoke(this); OnStateEnableAssigned?.Invoke(this);
return true; return true;
@@ -72,8 +67,8 @@ public abstract class BaseEntity : IEntity
UnassignInternal(); UnassignInternal();
_stateEnable = null!; StateEnable = null!;
_stateEnable.Unassign(); StateEnable.Unassign();
OnUnassigned?.Invoke(this); OnUnassigned?.Invoke(this);
return true; return true;
} }
@@ -84,7 +79,7 @@ public abstract class BaseEntity : IEntity
if (IsInitialized) if (IsInitialized)
return false; return false;
_stateEnable ??= Factory.StateEnableFactory.Instantiate(this); StateEnable ??= Factory.StateEnableFactory.Instantiate(this);
InitializeInternal(); InitializeInternal();
@@ -104,6 +99,6 @@ public abstract class BaseEntity : IEntity
return true; return true;
} }
protected BaseEntity() => _id = Guid.NewGuid().ToString("D"); protected BaseEntity() => Id = Guid.NewGuid().ToString("D");
protected BaseEntity(string id) => _id = id; protected BaseEntity(string id) => Id = id;
} }

View File

@@ -14,26 +14,23 @@ public abstract class Behaviour : BaseEntity, IBehaviour
public IUniverse Universe => BehaviourController.UniverseObject.Universe; public IUniverse Universe => BehaviourController.UniverseObject.Universe;
public IUniverseObject UniverseObject => BehaviourController.UniverseObject; public IUniverseObject UniverseObject => BehaviourController.UniverseObject;
private IBehaviourController _behaviourController = null!; public IBehaviourController BehaviourController { get; private set; } = null!;
public IBehaviourController BehaviourController => _behaviourController;
private int _priority = 0;
public int Priority public int Priority
{ {
get => _priority; get;
set set
{ {
if (value == _priority) if (value == field)
return; return;
int previousPriority = _priority; int previousPriority = field;
_priority = value; field = value;
OnPriorityChanged?.Invoke(this, new(previousPriority)); OnPriorityChanged?.Invoke(this, new(previousPriority));
} }
} } = 0;
private bool _isActive = false; public bool IsActive { get; private set; } = false;
public bool IsActive => _isActive;
protected virtual void OnAssign(IBehaviourController behaviourController) { } protected virtual void OnAssign(IBehaviourController behaviourController) { }
public bool Assign(IBehaviourController behaviourController) public bool Assign(IBehaviourController behaviourController)
@@ -41,7 +38,7 @@ public abstract class Behaviour : BaseEntity, IBehaviour
if (IsInitialized) if (IsInitialized)
return false; return false;
_behaviourController = behaviourController; BehaviourController = behaviourController;
OnAssign(behaviourController); OnAssign(behaviourController);
behaviourController.OnUniverseObjectAssigned.AddListener(delegateOnUniverseObjectAssigned); behaviourController.OnUniverseObjectAssigned.AddListener(delegateOnUniverseObjectAssigned);
behaviourController.StateEnable.OnEnabledChanged.AddListener(delegateOnStateEnabledChanged); behaviourController.StateEnable.OnEnabledChanged.AddListener(delegateOnStateEnabledChanged);
@@ -71,7 +68,7 @@ public abstract class Behaviour : BaseEntity, IBehaviour
BehaviourController.OnUniverseObjectAssigned.RemoveListener(delegateOnUniverseObjectAssigned); BehaviourController.OnUniverseObjectAssigned.RemoveListener(delegateOnUniverseObjectAssigned);
BehaviourController.StateEnable.OnEnabledChanged.RemoveListener(delegateOnStateEnabledChanged); BehaviourController.StateEnable.OnEnabledChanged.RemoveListener(delegateOnStateEnabledChanged);
base.UnassignInternal(); base.UnassignInternal();
_behaviourController = null!; BehaviourController = null!;
} }
protected override void InitializeInternal() protected override void InitializeInternal()
@@ -88,7 +85,7 @@ public abstract class Behaviour : BaseEntity, IBehaviour
private void UpdateActive() private void UpdateActive()
{ {
bool previousActive = IsActive; bool previousActive = IsActive;
_isActive = StateEnable.Enabled && _behaviourController.StateEnable.Enabled && _behaviourController.UniverseObject.IsActive; IsActive = StateEnable.Enabled && BehaviourController.StateEnable.Enabled && BehaviourController.UniverseObject.IsActive;
if (previousActive != IsActive) if (previousActive != IsActive)
OnActiveChanged?.Invoke(this, new(previousActive)); OnActiveChanged?.Invoke(this, new(previousActive));

View File

@@ -12,9 +12,8 @@ public class BehaviourController : BaseEntity, IBehaviourController
private readonly FastList<IBehaviour> behaviours = new(Constants.BEHAVIOURS_SIZE_INITIAL); private readonly FastList<IBehaviour> behaviours = new(Constants.BEHAVIOURS_SIZE_INITIAL);
private IUniverseObject _universeObject = null!; public IUniverseObject UniverseObject { get; private set; } = null!;
public IUniverseObject UniverseObject => _universeObject;
public int Count => behaviours.Count; public int Count => behaviours.Count;
public IBehaviour this[Index index] => behaviours[index]; public IBehaviour this[Index index] => behaviours[index];
@@ -103,7 +102,7 @@ public class BehaviourController : BaseEntity, IBehaviourController
if (UniverseObject is not null && UniverseObject.IsInitialized) if (UniverseObject is not null && UniverseObject.IsInitialized)
return false; return false;
_universeObject = universeObject; UniverseObject = universeObject;
OnAssign(universeObject); OnAssign(universeObject);
OnUniverseObjectAssigned?.Invoke(this); OnUniverseObjectAssigned?.Invoke(this);
return true; return true;

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>false</ImplicitUsings> <ImplicitUsings>false</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>Engine.Core</RootNamespace> <RootNamespace>Engine.Core</RootNamespace>

View File

@@ -56,8 +56,7 @@ public class Event
// We use Ascending order because draw calls are running from last to first // We use Ascending order because draw calls are running from last to first
private static readonly Comparer<ListenerData> SortByAscendingPriority = Comparer<ListenerData>.Create((x, y) => x.Priority.CompareTo(y.Priority)); private static readonly Comparer<ListenerData> SortByAscendingPriority = Comparer<ListenerData>.Create((x, y) => x.Priority.CompareTo(y.Priority));
private ILogger _logger = ILogger.Shared; public ILogger Logger { get; set => field = value ?? ILogger.Shared; } = ILogger.Shared;
public ILogger Logger { get => _logger; set => _logger = value ?? ILogger.Shared; }
private readonly List<ListenerData> listeners = null!; private readonly List<ListenerData> listeners = null!;
private readonly List<ListenerData> onceListeners = null!; private readonly List<ListenerData> onceListeners = null!;
@@ -215,8 +214,7 @@ public class Event<TSender> where TSender : class
// We use Ascending order because draw calls are running from last to first // We use Ascending order because draw calls are running from last to first
private static readonly Comparer<ListenerData> SortByAscendingPriority = Comparer<ListenerData>.Create((x, y) => x.Priority.CompareTo(y.Priority)); private static readonly Comparer<ListenerData> SortByAscendingPriority = Comparer<ListenerData>.Create((x, y) => x.Priority.CompareTo(y.Priority));
private ILogger _logger = ILogger.Shared; public ILogger Logger { get; set => field = value ?? ILogger.Shared; } = ILogger.Shared;
public ILogger Logger { get => _logger; set => _logger = value ?? ILogger.Shared; }
private readonly List<ListenerData> listeners = null!; private readonly List<ListenerData> listeners = null!;
private readonly List<ListenerData> onceListeners = null!; private readonly List<ListenerData> onceListeners = null!;
@@ -382,8 +380,7 @@ public class Event<TSender, TArguments> where TSender : class
// We use Ascending order because draw calls are running from last to first // We use Ascending order because draw calls are running from last to first
private static readonly Comparer<ListenerData> SortByAscendingPriority = Comparer<ListenerData>.Create((x, y) => x.Priority.CompareTo(y.Priority)); private static readonly Comparer<ListenerData> SortByAscendingPriority = Comparer<ListenerData>.Create((x, y) => x.Priority.CompareTo(y.Priority));
private ILogger _logger = ILogger.Shared; public ILogger Logger { get; set => field = value ?? ILogger.Shared; } = ILogger.Shared;
public ILogger Logger { get => _logger; set => _logger = value ?? ILogger.Shared; }
private readonly List<ListenerData> listeners = null!; private readonly List<ListenerData> listeners = null!;
private readonly List<ListenerData> onceListeners = null!; private readonly List<ListenerData> onceListeners = null!;

View File

@@ -20,7 +20,7 @@ public class Shape2D(List<Vector2D> vertices) : IEnumerable<Vector2D>
public Event<Shape2D> OnShapeUpdated { get; } = new(); public Event<Shape2D> OnShapeUpdated { get; } = new();
private List<Vector2D> _vertices = vertices; private readonly List<Vector2D> _vertices = vertices;
/// <summary> /// <summary>
/// Gets the vertices of the <see cref="Shape2D"/>. /// Gets the vertices of the <see cref="Shape2D"/>.

View File

@@ -6,32 +6,29 @@ public class StateEnable : IStateEnable
public Event<IHasEntity> OnEntityAssigned { get; } = new(); public Event<IHasEntity> OnEntityAssigned { get; } = new();
public Event<IAssignable>? OnUnassigned { get; } = new(); public Event<IAssignable>? OnUnassigned { get; } = new();
private bool _enabled = true; public IEntity Entity { get; private set; } = null!;
private IEntity _entity = null!;
public IEntity Entity => _entity;
public bool Enabled public bool Enabled
{ {
get => _enabled; get;
set set
{ {
if (value == _enabled) if (value == field)
return; return;
bool previousState = _enabled; bool previousState = field;
_enabled = value; field = value;
OnEnabledChanged?.Invoke(this, new(previousState)); OnEnabledChanged?.Invoke(this, new(previousState));
} }
} } = true;
protected virtual void OnAssign(IEntity entity) { } protected virtual void OnAssign(IEntity entity) { }
public bool Assign(IEntity entity) public bool Assign(IEntity entity)
{ {
if (_entity is not null && _entity.IsInitialized) if (Entity is not null && Entity.IsInitialized)
return false; return false;
_entity = entity; Entity = entity;
OnAssign(entity); OnAssign(entity);
OnEntityAssigned?.Invoke(this); OnEntityAssigned?.Invoke(this);
return true; return true;
@@ -39,10 +36,10 @@ public class StateEnable : IStateEnable
public bool Unassign() public bool Unassign()
{ {
if (_entity is null) if (Entity is null)
return false; return false;
_entity = null!; Entity = null!;
OnUnassigned?.Invoke(this); OnUnassigned?.Invoke(this);
return true; return true;
} }

View File

@@ -23,7 +23,6 @@ public class Universe : BaseEntity, IUniverse
private readonly Event<IUniverseObject, IUniverseObject.ExitedUniverseArguments>.EventHandler delegateOnUniverseObjectExitedUniverse = null!; private readonly Event<IUniverseObject, IUniverseObject.ExitedUniverseArguments>.EventHandler delegateOnUniverseObjectExitedUniverse = null!;
private readonly FastList<IUniverseObject> _universeObjects = new(Constants.UNIVERSE_OBJECTS_SIZE_INITIAL); private readonly FastList<IUniverseObject> _universeObjects = new(Constants.UNIVERSE_OBJECTS_SIZE_INITIAL);
private float _timeScale = 1f;
public Universe() public Universe()
{ {
@@ -37,18 +36,18 @@ public class Universe : BaseEntity, IUniverse
public UniverseTime UnscaledTime { get; private set; } = new(); public UniverseTime UnscaledTime { get; private set; } = new();
public float TimeScale public float TimeScale
{ {
get => _timeScale; get;
set set
{ {
value = value.Max(0f); value = value.Max(0f);
if (value == _timeScale) if (value == field)
return; return;
float previousTimeScale = _timeScale; float previousTimeScale = field;
_timeScale = value; field = value;
OnTimeScaleChanged?.Invoke(this, new(previousTimeScale)); OnTimeScaleChanged?.Invoke(this, new(previousTimeScale));
} }
} } = 1f;
public void Register(IUniverseObject universeObject) public void Register(IUniverseObject universeObject)
{ {

View File

@@ -15,41 +15,37 @@ public class UniverseObject : BaseEntity, IUniverseObject
public Event<INameable, INameable.NameChangedArguments> OnNameChanged { get; } = new(); public Event<INameable, INameable.NameChangedArguments> OnNameChanged { get; } = new();
public Event<IHasBehaviourController> OnBehaviourControllerAssigned { get; } = new(); public Event<IHasBehaviourController> OnBehaviourControllerAssigned { get; } = new();
private string _name = nameof(UniverseObject);
private IUniverse _universe = null!;
private IBehaviourController _behaviourController = null!;
private bool _isActive = false;
private readonly FastList<IUniverseObject> _children = []; private readonly FastList<IUniverseObject> _children = [];
private IUniverseObject? _parent = null;
public IBehaviourController BehaviourController { get; private set; } = null!;
public IUniverse Universe { get; private set; } = null!;
public bool IsActive { get; private set; } = false;
public IReadOnlyList<IUniverseObject> Children => _children; public IReadOnlyList<IUniverseObject> Children => _children;
public IBehaviourController BehaviourController => _behaviourController; public bool IsInUniverse => Universe is not null;
public IUniverse Universe => _universe;
public bool IsInUniverse => _universe is not null;
public bool IsActive => _isActive;
public string Name public string Name
{ {
get => _name; get;
set set
{ {
if (value == _name) return; if (value == field) return;
string previousName = _name; string previousName = field;
_name = value; field = value;
OnNameChanged?.Invoke(this, new(previousName)); OnNameChanged?.Invoke(this, new(previousName));
} }
} } = nameof(UniverseObject);
public IUniverseObject? Parent public IUniverseObject? Parent
{ {
get => _parent; get;
set set
{ {
if (value == this) if (value == this)
throw new Exceptions.AssignFailedException($"{Name} can not parent itself"); throw new Exceptions.AssignFailedException($"{Name} can not parent itself");
if (_parent == value) if (field == value)
return; return;
IUniverseObject? previousParent = Parent; IUniverseObject? previousParent = Parent;
@@ -59,7 +55,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
previousParent.OnActiveChanged.RemoveListener(OnParentActiveChanged); previousParent.OnActiveChanged.RemoveListener(OnParentActiveChanged);
} }
_parent = value; field = value;
if (value is not null) if (value is not null)
{ {
@@ -73,7 +69,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
UpdateActive(); UpdateActive();
OnParentChanged?.Invoke(this, new(previousParent, value)); OnParentChanged?.Invoke(this, new(previousParent, value));
} }
} } = null;
protected virtual void OnEnteringUniverse(IUniverse universe) { } protected virtual void OnEnteringUniverse(IUniverse universe) { }
bool IUniverseObject.EnterUniverse(IUniverse universe) bool IUniverseObject.EnterUniverse(IUniverse universe)
@@ -81,7 +77,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
if (IsInUniverse) if (IsInUniverse)
return false; return false;
_universe = universe; Universe = universe;
UpdateActive(); UpdateActive();
OnEnteringUniverse(universe); OnEnteringUniverse(universe);
OnEnteredUniverse?.Invoke(this, new(universe)); OnEnteredUniverse?.Invoke(this, new(universe));
@@ -91,11 +87,11 @@ public class UniverseObject : BaseEntity, IUniverseObject
protected virtual void OnExitingUniverse(IUniverse universe) { } protected virtual void OnExitingUniverse(IUniverse universe) { }
bool IUniverseObject.ExitUniverse() bool IUniverseObject.ExitUniverse()
{ {
if (!IsInUniverse || _universe is not IUniverse universe) if (!IsInUniverse || Universe is not IUniverse universe)
return false; return false;
OnExitingUniverse(universe); OnExitingUniverse(universe);
_universe = null!; Universe = null!;
OnExitedUniverse?.Invoke(this, new(universe)); OnExitedUniverse?.Invoke(this, new(universe));
return true; return true;
} }
@@ -125,7 +121,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
if (IsInitialized) if (IsInitialized)
return false; return false;
_behaviourController = behaviourController; BehaviourController = behaviourController;
OnAssign(behaviourController); OnAssign(behaviourController);
OnBehaviourControllerAssigned?.Invoke(this); OnBehaviourControllerAssigned?.Invoke(this);
return true; return true;
@@ -145,7 +141,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
private void UpdateActive() private void UpdateActive()
{ {
bool previousActive = IsActive; bool previousActive = IsActive;
_isActive = StateEnable.Enabled && (Parent?.IsActive ?? true); IsActive = StateEnable.Enabled && (Parent?.IsActive ?? true);
if (previousActive != IsActive) if (previousActive != IsActive)
OnActiveChanged?.Invoke(this, new(previousActive)); OnActiveChanged?.Invoke(this, new(previousActive));
@@ -160,12 +156,12 @@ public class UniverseObject : BaseEntity, IUniverseObject
protected override void InitializeInternal() protected override void InitializeInternal()
{ {
base.InitializeInternal(); base.InitializeInternal();
_behaviourController ??= Factory.BehaviourControllerFactory.Instantiate(this); BehaviourController ??= Factory.BehaviourControllerFactory.Instantiate(this);
_behaviourController.Initialize(); BehaviourController.Initialize();
} }
public UniverseObject() public UniverseObject()
{ {
_name = GetType().Name; Name = GetType().Name;
} }
} }

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>Engine.Systems.Network</RootNamespace> <RootNamespace>Engine.Systems.Network</RootNamespace>

View File

@@ -11,26 +11,21 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr
public Event<MonoGameCamera2D> OnViewportChanged { get; } = new(); public Event<MonoGameCamera2D> OnViewportChanged { get; } = new();
public Event<MonoGameCamera2D> OnZoomChanged { get; } = new(); public Event<MonoGameCamera2D> OnZoomChanged { get; } = new();
private Matrix _matrixTransform = Matrix.Identity;
private Viewport _viewport = default;
private float _zoom = 1f;
public GraphicsDeviceManager Graphics { get; private set; } = null!; public GraphicsDeviceManager Graphics { get; private set; } = null!;
public ITransform2D Transform { get; private set; } = null!; public ITransform2D Transform { get; private set; } = null!;
public Matrix MatrixTransform public Matrix MatrixTransform
{ {
get => _matrixTransform; get;
set set
{ {
if (_matrixTransform == value) if (field == value)
return; return;
_matrixTransform = value; field = value;
OnMatrixTransformChanged.Invoke(this); OnMatrixTransformChanged.Invoke(this);
} }
} } = Matrix.Identity;
public Vector2D Position public Vector2D Position
{ {
@@ -40,31 +35,31 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr
public Viewport Viewport public Viewport Viewport
{ {
get => _viewport; get;
set set
{ {
if (_viewport.Equals(value)) if (field.Equals(value))
return; return;
_viewport = value; field = value;
OnViewportChanged.Invoke(this); OnViewportChanged.Invoke(this);
} }
} } = default;
public float Zoom public float Zoom
{ {
get => _zoom; get;
set set
{ {
float newValue = Math.Max(0.1f, value); float newValue = Math.Max(0.1f, value);
if (_zoom == newValue) if (field == newValue)
return; return;
_zoom = newValue; field = newValue;
OnZoomChanged.Invoke(this); OnZoomChanged.Invoke(this);
} }
} } = 1f;
public float Rotation public float Rotation
{ {
@@ -99,6 +94,6 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr
Matrix.CreateRotationZ(Rotation * Math.DegreeToRadian) * Matrix.CreateRotationZ(Rotation * Math.DegreeToRadian) *
Matrix.CreateScale(Transform.Scale.X.Max(Transform.Scale.Y)) * Matrix.CreateScale(Transform.Scale.X.Max(Transform.Scale.Y)) *
Matrix.CreateScale(Zoom) * Matrix.CreateScale(Zoom) *
Matrix.CreateTranslation(new Vector3(_viewport.Width * .5f, _viewport.Height * .5f, 0f)); Matrix.CreateTranslation(new Vector3(Viewport.Width * .5f, Viewport.Height * .5f, 0f));
} }
} }

View File

@@ -15,12 +15,7 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
public Event<ICamera3D, ICamera3D.FarPlaneChangedArguments> OnFarPlaneChanged { get; } = new(); public Event<ICamera3D, ICamera3D.FarPlaneChangedArguments> OnFarPlaneChanged { get; } = new();
public Event<ICamera3D, ICamera3D.FieldOfViewChangedArguments> OnFieldOfViewChanged { get; } = new(); public Event<ICamera3D, ICamera3D.FieldOfViewChangedArguments> OnFieldOfViewChanged { get; } = new();
private Matrix _view = Matrix.Identity; private float fieldOfView = Math.DegreeToRadian * 70f;
private Matrix _projection = Matrix.Identity;
private Viewport _viewport = default;
private float _nearPlane = 0.01f;
private float _farPlane = 100f;
private float _fieldOfView = Math.DegreeToRadian * 70f;
private bool isRecalculationNeeded = true; private bool isRecalculationNeeded = true;
public GraphicsDeviceManager Graphics { get; private set; } = null!; public GraphicsDeviceManager Graphics { get; private set; } = null!;
@@ -28,41 +23,42 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
public Matrix View public Matrix View
{ {
get => _view; get;
set set
{ {
if (_view == value) if (field == value)
return; return;
Matrix previousView = _view; Matrix previousView = field;
_view = value; field = value;
OnViewChanged.Invoke(this, new(previousView)); OnViewChanged.Invoke(this, new(previousView));
} }
} } = Matrix.Identity;
public Matrix Projection public Matrix Projection
{ {
get => _projection; get;
set set
{ {
if (_projection == value) if (field == value)
return; return;
Matrix previousProjection = _projection; Matrix previousProjection = field;
_projection = value; field = value;
OnProjectionChanged.Invoke(this, new(previousProjection)); OnProjectionChanged.Invoke(this, new(previousProjection));
} }
} } = Matrix.Identity;
public Viewport Viewport public Viewport Viewport
{ {
get => _viewport; get;
set set
{ {
if (_viewport.Equals(value)) if (field.Equals(value))
return; return;
Viewport previousViewport = _viewport; Viewport previousViewport = field;
_viewport = value; field = value;
SetForRecalculation(); SetForRecalculation();
OnViewportChanged.Invoke(this, new(previousViewport)); OnViewportChanged.Invoke(this, new(previousViewport));
} }
@@ -70,40 +66,40 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
public float NearPlane public float NearPlane
{ {
get => _nearPlane; get;
set set
{ {
float previousNearPlane = _nearPlane; float previousNearPlane = field;
_nearPlane = value.Max(0.0001f); field = value.Max(0.0001f);
SetForRecalculation(); SetForRecalculation();
OnNearPlaneChanged.Invoke(this, new(previousNearPlane)); OnNearPlaneChanged.Invoke(this, new(previousNearPlane));
} }
} } = 0.01f;
public float FarPlane public float FarPlane
{ {
get => _farPlane; get;
set set
{ {
float previousFarPlane = _farPlane; float previousFarPlane = field;
_farPlane = value.Max(NearPlane); field = value.Max(NearPlane);
SetForRecalculation(); SetForRecalculation();
OnFarPlaneChanged.Invoke(this, new(previousFarPlane)); OnFarPlaneChanged.Invoke(this, new(previousFarPlane));
} }
} } = 100f;
public float FieldOfView public float FieldOfView
{ {
get => _fieldOfView * Math.RadianToDegree; get => fieldOfView * Math.RadianToDegree;
set set
{ {
value = value.Max(0.1f) * Math.DegreeToRadian; value = value.Max(0.1f) * Math.DegreeToRadian;
if (_fieldOfView == value) if (fieldOfView == value)
return; return;
float previousFieldOfView = _fieldOfView; float previousFieldOfView = fieldOfView;
_fieldOfView = value; fieldOfView = value;
SetForRecalculation(); SetForRecalculation();
OnFieldOfViewChanged.Invoke(this, new(previousFieldOfView)); OnFieldOfViewChanged.Invoke(this, new(previousFieldOfView));
} }
@@ -115,14 +111,14 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
Vector3 nearPoint = new(screenPosition.X, screenPosition.Y, 0f); Vector3 nearPoint = new(screenPosition.X, screenPosition.Y, 0f);
Vector3 farPoint = new(screenPosition.X, screenPosition.Y, 1f); Vector3 farPoint = new(screenPosition.X, screenPosition.Y, 1f);
Vector3 worldNear = Viewport.Unproject(nearPoint, _projection, _view, Matrix.Identity); Vector3 worldNear = Viewport.Unproject(nearPoint, Projection, View, Matrix.Identity);
Vector3 worldFar = Viewport.Unproject(farPoint, _projection, _view, Matrix.Identity); Vector3 worldFar = Viewport.Unproject(farPoint, Projection, View, Matrix.Identity);
Vector3 direction = Vector3.Normalize(worldFar - worldNear); Vector3 direction = Vector3.Normalize(worldFar - worldNear);
return new(worldNear.ToVector3D(), direction.ToVector3D()); return new(worldNear.ToVector3D(), direction.ToVector3D());
} }
public Vector2D WorldToScreenPosition(Vector3D worldPosition) => Viewport.Project(worldPosition.ToVector3(), _projection, _view, Matrix.Identity).ToVector3D(); public Vector2D WorldToScreenPosition(Vector3D worldPosition) => Viewport.Project(worldPosition.ToVector3(), Projection, View, Matrix.Identity).ToVector3D();
public void LastActiveFrame() => Transform.OnTransformUpdated.RemoveListener(SetDirtyOnTransformUpdate); public void LastActiveFrame() => Transform.OnTransformUpdated.RemoveListener(SetDirtyOnTransformUpdate);
public void FirstActiveFrame() public void FirstActiveFrame()
@@ -167,14 +163,14 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
private void CalculateProjection() private void CalculateProjection()
{ {
float yScale = 1f / (float)Math.Tan(_fieldOfView / 2f); float yScale = 1f / (float)Math.Tan(fieldOfView / 2f);
float xScale = yScale / Viewport.AspectRatio; float xScale = yScale / Viewport.AspectRatio;
Projection = new Matrix( Projection = new Matrix(
xScale, 0, 0, 0, xScale, 0, 0, 0,
0, yScale, 0, 0, 0, yScale, 0, 0,
0, 0, _farPlane / (_farPlane - _nearPlane), 1, 0, 0, FarPlane / (FarPlane - NearPlane), 1,
0, 0, -_nearPlane * _farPlane / (_farPlane - _nearPlane), 0 0, 0, -NearPlane * FarPlane / (FarPlane - NearPlane), 0
); );
} }

View File

@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>Engine.Integration.MonoGame</RootNamespace> <RootNamespace>Engine.Integration.MonoGame</RootNamespace>

View File

@@ -1,4 +1,4 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Engine.Core; using Engine.Core;

View File

@@ -8,12 +8,14 @@ namespace Engine.Integration.MonoGame;
public class TriangleBatch : ITriangleBatch public class TriangleBatch : ITriangleBatch
{ {
private readonly GraphicsDevice graphicsDevice; private readonly GraphicsDevice graphicsDevice;
private VertexBuffer vertexBuffer = default!; private readonly VertexBuffer vertexBuffer = default!;
private readonly VertexPositionColor[] vertices = new VertexPositionColor[1024]; private readonly VertexPositionColor[] vertices = new VertexPositionColor[1024];
private int verticesIndex = 0; private int verticesIndex = 0;
private Matrix _view; private Matrix view = Matrix.Identity;
private Matrix _projection; private Matrix projection = Matrix.Identity;
private readonly BasicEffect basicEffect;
private readonly BasicEffect basicEffect = null!;
private readonly RasterizerState rasterizerState = new() { CullMode = CullMode.None }; private readonly RasterizerState rasterizerState = new() { CullMode = CullMode.None };
public TriangleBatch(GraphicsDevice graphicsDevice) public TriangleBatch(GraphicsDevice graphicsDevice)
@@ -42,16 +44,16 @@ public class TriangleBatch : ITriangleBatch
public void Begin(Matrix? view = null, Matrix? projection = null) public void Begin(Matrix? view = null, Matrix? projection = null)
{ {
if (view != null) if (view != null)
_view = view.Value; this.view = view.Value;
else else
_view = Matrix.Identity; this.view = Matrix.Identity;
if (projection != null) if (projection != null)
_projection = projection.Value; this.projection = projection.Value;
else else
{ {
Viewport viewport = graphicsDevice.Viewport; Viewport viewport = graphicsDevice.Viewport;
_projection = Matrix.CreateOrthographicOffCenter(viewport.X, viewport.Width, viewport.Height, viewport.Y, 0, 1); this.projection = Matrix.CreateOrthographicOffCenter(viewport.X, viewport.Width, viewport.Height, viewport.Y, 0, 1);
} }
} }
@@ -63,8 +65,8 @@ public class TriangleBatch : ITriangleBatch
return; return;
graphicsDevice.RasterizerState = rasterizerState; graphicsDevice.RasterizerState = rasterizerState;
basicEffect.Projection = _projection; basicEffect.Projection = projection;
basicEffect.View = _view; basicEffect.View = view;
vertexBuffer.SetData(vertices); vertexBuffer.SetData(vertices);
graphicsDevice.SetVertexBuffer(vertexBuffer); graphicsDevice.SetVertexBuffer(vertexBuffer);

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>Engine.Integration.Yaml</RootNamespace> <RootNamespace>Engine.Integration.Yaml</RootNamespace>

View File

@@ -16,19 +16,8 @@ public abstract class Collider2DBase : Behaviour2D, ICollider2D
private readonly Event<IUniverseObject, IUniverseObject.ParentChangedArguments>.EventHandler delegateUpdateRigidBody2D = null!; private readonly Event<IUniverseObject, IUniverseObject.ParentChangedArguments>.EventHandler delegateUpdateRigidBody2D = null!;
protected bool NeedsRecalculation { get; set; } = true; protected bool NeedsRecalculation { get; set; } = true;
protected IRigidBody2D? _rigidBody2D = null;
protected Collider2DBase() public IRigidBody2D? RigidBody2D { get; protected set; } = null;
{
delegateOnBehaviourAddedToController = OnBehaviourAddedToController;
delegateOnBehaviourRemovedFromController = OnBehaviourRemovedFromController;
delegateSetNeedsRecalculationFromPosition = SetNeedsRecalculationFromPosition;
delegateSetNeedsRecalculationFromRotation = SetNeedsRecalculationFromRotation;
delegateSetNeedsRecalculationFromScale = SetNeedsRecalculationFromScale;
delegateUpdateRigidBody2D = UpdateRigidBody2D;
}
public IRigidBody2D? RigidBody2D => _rigidBody2D;
public bool IsTrigger { get; set; } = false; public bool IsTrigger { get; set; } = false;
public void Recalculate() public void Recalculate()
@@ -46,7 +35,8 @@ public abstract class Collider2DBase : Behaviour2D, ICollider2D
{ {
base.OnInitialize(); base.OnInitialize();
BehaviourController.TryGetBehaviourInParent(out _rigidBody2D); BehaviourController.TryGetBehaviourInParent(out IRigidBody2D? foundRigidBody2D);
RigidBody2D = foundRigidBody2D;
BehaviourController.OnBehaviourAdded.AddListener(delegateOnBehaviourAddedToController); BehaviourController.OnBehaviourAdded.AddListener(delegateOnBehaviourAddedToController);
BehaviourController.OnBehaviourRemoved.AddListener(delegateOnBehaviourRemovedFromController); BehaviourController.OnBehaviourRemoved.AddListener(delegateOnBehaviourRemovedFromController);
@@ -59,19 +49,20 @@ public abstract class Collider2DBase : Behaviour2D, ICollider2D
private void UpdateRigidBody2D(IUniverseObject sender, IUniverseObject.ParentChangedArguments args) private void UpdateRigidBody2D(IUniverseObject sender, IUniverseObject.ParentChangedArguments args)
{ {
BehaviourController.TryGetBehaviourInParent(out _rigidBody2D); BehaviourController.TryGetBehaviourInParent(out IRigidBody2D? foundRigidBody2D);
RigidBody2D = foundRigidBody2D;
} }
private void OnBehaviourAddedToController(IBehaviourController sender, IBehaviourController.BehaviourAddedArguments args) private void OnBehaviourAddedToController(IBehaviourController sender, IBehaviourController.BehaviourAddedArguments args)
{ {
if (args.BehaviourAdded is IRigidBody2D rigidBody) if (args.BehaviourAdded is IRigidBody2D rigidBody)
_rigidBody2D = rigidBody; RigidBody2D = rigidBody;
} }
private void OnBehaviourRemovedFromController(IBehaviourController sender, IBehaviourController.BehaviourRemovedArguments args) private void OnBehaviourRemovedFromController(IBehaviourController sender, IBehaviourController.BehaviourRemovedArguments args)
{ {
if (args.BehaviourRemoved is IRigidBody2D) if (args.BehaviourRemoved is IRigidBody2D)
_rigidBody2D = null; RigidBody2D = null;
} }
private void SetNeedsRecalculationFromPosition(ITransform2D sender, ITransform2D.PositionChangedArguments args) => NeedsRecalculation = true; private void SetNeedsRecalculationFromPosition(ITransform2D sender, ITransform2D.PositionChangedArguments args) => NeedsRecalculation = true;
@@ -93,4 +84,14 @@ public abstract class Collider2DBase : Behaviour2D, ICollider2D
public void Detect(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionDetected?.Invoke(this, collisionDetectionInformation); public void Detect(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionDetected?.Invoke(this, collisionDetectionInformation);
public void Resolve(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionResolved?.Invoke(this, collisionDetectionInformation); public void Resolve(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionResolved?.Invoke(this, collisionDetectionInformation);
public void Trigger(ICollider2D initiator) => OnTriggered?.Invoke(this, initiator); public void Trigger(ICollider2D initiator) => OnTriggered?.Invoke(this, initiator);
protected Collider2DBase()
{
delegateOnBehaviourAddedToController = OnBehaviourAddedToController;
delegateOnBehaviourRemovedFromController = OnBehaviourRemovedFromController;
delegateSetNeedsRecalculationFromPosition = SetNeedsRecalculationFromPosition;
delegateSetNeedsRecalculationFromRotation = SetNeedsRecalculationFromRotation;
delegateSetNeedsRecalculationFromScale = SetNeedsRecalculationFromScale;
delegateUpdateRigidBody2D = UpdateRigidBody2D;
}
} }

View File

@@ -4,20 +4,18 @@ namespace Engine.Physics2D;
public class Collider2DCircle : Collider2DBase, ICircleCollider2D public class Collider2DCircle : Collider2DBase, ICircleCollider2D
{ {
private Circle _circleLocal = Circle.UnitCircle;
public Circle CircleWorld { get; protected set; } = Circle.UnitCircle; public Circle CircleWorld { get; protected set; } = Circle.UnitCircle;
public Circle CircleLocal public Circle CircleLocal
{ {
get => _circleLocal; get;
set set
{ {
_circleLocal = value; field = value;
NeedsRecalculation = true; NeedsRecalculation = true;
} }
} } = Circle.UnitCircle;
public override void CalculateCollider() => CircleWorld = Transform.Transform(_circleLocal); public override void CalculateCollider() => CircleWorld = Transform.Transform(CircleLocal);
public Collider2DCircle() { } public Collider2DCircle() { }
public Collider2DCircle(Circle circle) => CircleLocal = circle; public Collider2DCircle(Circle circle) => CircleLocal = circle;

View File

@@ -4,25 +4,19 @@ namespace Engine.Physics2D;
public class Collider2DShape : Collider2DBase, IShapeCollider2D public class Collider2DShape : Collider2DBase, IShapeCollider2D
{ {
public Shape2D ShapeWorld { get => _shapeWorld; protected set => _shapeWorld = value; } public Shape2D ShapeWorld { get; protected set; } = Shape2D.Square;
public Shape2D ShapeLocal public Shape2D ShapeLocal
{ {
get => _shapeLocal; get;
set set
{ {
_shapeLocal = value; field = value;
NeedsRecalculation = true; NeedsRecalculation = true;
} }
} } = Shape2D.Square;
private Shape2D _shapeWorld = Shape2D.Square; public override void CalculateCollider() => ShapeLocal.Transform(Transform, ShapeWorld);
private Shape2D _shapeLocal = Shape2D.Square;
public override void CalculateCollider() => ShapeLocal.Transform(Transform, _shapeWorld);
public Collider2DShape() { } public Collider2DShape() { }
public Collider2DShape(Shape2D shape) public Collider2DShape(Shape2D shape) { ShapeLocal = shape; }
{
ShapeLocal = shape;
}
} }

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>Engine.Physics2D</RootNamespace> <RootNamespace>Engine.Physics2D</RootNamespace>

View File

@@ -10,8 +10,6 @@ public class PhysicsEngine2D : Behaviour, IEnterUniverse, IExitUniverse, IPreUpd
public Event<IPhysicsEngine2D, float> OnPhysicsStep { get; } = new(); public Event<IPhysicsEngine2D, float> OnPhysicsStep { get; } = new();
private float physicsTicker = 0f; private float physicsTicker = 0f;
private int _iterationPerStep = 1;
private float _iterationPeriod = 1f / 60f;
protected readonly ICollisionDetector2D collisionDetector = null!; protected readonly ICollisionDetector2D collisionDetector = null!;
protected readonly ICollisionResolver2D collisionResolver = null!; protected readonly ICollisionResolver2D collisionResolver = null!;
@@ -32,8 +30,8 @@ public class PhysicsEngine2D : Behaviour, IEnterUniverse, IExitUniverse, IPreUpd
private readonly ListPool<IPhysicsIteration> physicsIterationPool = new(); private readonly ListPool<IPhysicsIteration> physicsIterationPool = new();
private readonly ListPool<IPostPhysicsUpdate> postPhysicsUpdatePool = new(); private readonly ListPool<IPostPhysicsUpdate> postPhysicsUpdatePool = new();
public int IterationPerStep { get => _iterationPerStep; set => _iterationPerStep = value < 1 ? 1 : value; } public int IterationPerStep { get; set => field = value < 1 ? 1 : value; } = 1;
public float IterationPeriod { get => _iterationPeriod; set => _iterationPeriod = value.Max(0.0001f); } public float IterationPeriod { get; set => field = value.Max(0.0001f); } = 1f / 60f;
public RaycastResult? Raycast(Ray2D ray, float length = float.MaxValue) public RaycastResult? Raycast(Ray2D ray, float length = float.MaxValue)
{ {

View File

@@ -14,9 +14,6 @@ public class PhysicsEngine2DStandalone : IPhysicsEngine2D
private readonly List<IRigidBody2D> rigidBodies = new(32); private readonly List<IRigidBody2D> rigidBodies = new(32);
private readonly List<ICollider2D> colliders = new(64); private readonly List<ICollider2D> colliders = new(64);
private int _iterationCount = 1;
private readonly ICollisionDetector2D collisionDetector = null!; private readonly ICollisionDetector2D collisionDetector = null!;
private readonly ICollisionResolver2D collisionResolver = null!; private readonly ICollisionResolver2D collisionResolver = null!;
private readonly IRaycastResolver2D raycastResolver = null!; private readonly IRaycastResolver2D raycastResolver = null!;
@@ -27,7 +24,7 @@ public class PhysicsEngine2DStandalone : IPhysicsEngine2D
private readonly ListPool<IPhysicsIteration> physicsIterationPool = new(); private readonly ListPool<IPhysicsIteration> physicsIterationPool = new();
private readonly ListPool<IPostPhysicsUpdate> postPhysicsUpdatePool = new(); private readonly ListPool<IPostPhysicsUpdate> postPhysicsUpdatePool = new();
public int IterationPerStep { get => _iterationCount; set => _iterationCount = value < 1 ? 1 : value; } public int IterationPerStep { get; set => field = value.Max(1); } = 1;
public void AddRigidBody(IRigidBody2D rigidBody) public void AddRigidBody(IRigidBody2D rigidBody)
{ {

View File

@@ -5,7 +5,6 @@ namespace Engine.Physics2D;
public class RigidBody2D : Behaviour2D, IRigidBody2D public class RigidBody2D : Behaviour2D, IRigidBody2D
{ {
private const float LOWEST_ALLOWED_MASS = 0.00001f; private const float LOWEST_ALLOWED_MASS = 0.00001f;
private float _mass = 1f;
public IPhysicsMaterial2D Material { get; set; } = new PhysicsMaterial2DDefault(); public IPhysicsMaterial2D Material { get; set; } = new PhysicsMaterial2DDefault();
@@ -13,5 +12,5 @@ public class RigidBody2D : Behaviour2D, IRigidBody2D
public float AngularVelocity { get; set; } = 0f; public float AngularVelocity { get; set; } = 0f;
public bool IsStatic { get; set; } = false; public bool IsStatic { get; set; } = false;
public float Mass { get => _mass; set => _mass = Core.Math.Max(value, LOWEST_ALLOWED_MASS); } public float Mass { get; set => field = Math.Max(value, LOWEST_ALLOWED_MASS); } = 1f;
} }

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>Engine.Systems</RootNamespace> <RootNamespace>Engine.Systems</RootNamespace>

View File

@@ -29,22 +29,21 @@ public class NetworkManager : Behaviour, IEnterUniverse, IExitUniverse, INetwork
private readonly BehaviourCollector<INetworkEntity> _networkEntityCollector = new(); private readonly BehaviourCollector<INetworkEntity> _networkEntityCollector = new();
public IBehaviourCollector<INetworkEntity> NetworkEntityCollector => _networkEntityCollector; public IBehaviourCollector<INetworkEntity> NetworkEntityCollector => _networkEntityCollector;
private INetworkCommunicator _networkCommunicator = null!;
public INetworkCommunicator NetworkCommunicator public INetworkCommunicator NetworkCommunicator
{ {
get => _networkCommunicator; get;
set set
{ {
if (_networkCommunicator == value) if (field == value)
return; return;
INetworkCommunicator? previousCommunicator = _networkCommunicator; INetworkCommunicator? previousCommunicator = field;
_networkCommunicator = value; field = value;
if (previousCommunicator is not null) UnsubscribeCommunicatorMethods(previousCommunicator); if (previousCommunicator is not null) UnsubscribeCommunicatorMethods(previousCommunicator);
if (_networkCommunicator is not null) SubscribeCommunicatorMethods(_networkCommunicator); if (field is not null) SubscribeCommunicatorMethods(field);
} }
} } = null!;
#region Communicator Subscriptions #region Communicator Subscriptions
private void SubscribeCommunicatorMethods(INetworkCommunicator networkCommunicator) private void SubscribeCommunicatorMethods(INetworkCommunicator networkCommunicator)

View File

@@ -2,15 +2,14 @@ namespace Engine.Systems.Network;
public static class TypeHasher<T> public static class TypeHasher<T>
{ {
private static long _fnv1a = 0;
public static long FNV1a public static long FNV1a
{ {
get get
{ {
if (_fnv1a == 0) if (field == 0)
_fnv1a = Hasher.FNV1a(typeof(T).FullName ?? typeof(T).Name); field = Hasher.FNV1a(typeof(T).FullName ?? typeof(T).Name);
return _fnv1a; return field;
} }
} } = 0;
} }

View File

@@ -14,23 +14,22 @@ public class State : BaseEntity, IState
private readonly List<StateTransition> transitions = []; private readonly List<StateTransition> transitions = [];
private readonly Dictionary<string, StateTransition> possibleTransitions = []; private readonly Dictionary<string, StateTransition> possibleTransitions = [];
private string _name = "Default State Name";
public IReadOnlyList<StateTransition> Transitions => transitions; public IReadOnlyList<StateTransition> Transitions => transitions;
public IReadOnlyDictionary<string, StateTransition> PossibleTransitions => possibleTransitions; public IReadOnlyDictionary<string, StateTransition> PossibleTransitions => possibleTransitions;
public string Name public string Name
{ {
get => _name; get;
set set
{ {
if (_name.CompareTo(value) == 0) if (field.CompareTo(value) == 0)
return; return;
string previousName = _name; string previousName = field;
_name = value; field = value;
OnNameChanged?.Invoke(this, new(previousName)); OnNameChanged?.Invoke(this, new(previousName));
} }
} } = "Default State Name";
public void RemoveTransition(string name) public void RemoveTransition(string name)
{ {

View File

@@ -10,20 +10,19 @@ public abstract class StateBehaviourBase : Behaviour, IState
public Event<IState, IState.StateTransitionReadyArguments> OnStateTransitionReady { get; } = new(); public Event<IState, IState.StateTransitionReadyArguments> OnStateTransitionReady { get; } = new();
public Event<INameable, INameable.NameChangedArguments> OnNameChanged { get; } = new(); public Event<INameable, INameable.NameChangedArguments> OnNameChanged { get; } = new();
private string _name = string.Empty;
public string Name public string Name
{ {
get => _name; get;
set set
{ {
if (_name.CompareTo(value) == 0) if (field.CompareTo(value) == 0)
return; return;
string previousName = _name; string previousName = field;
_name = value; field = value;
OnNameChanged?.Invoke(this, new(previousName)); OnNameChanged?.Invoke(this, new(previousName));
} }
} } = string.Empty;
protected virtual void OnUpdateState() { } protected virtual void OnUpdateState() { }
public void Update() public void Update()

View File

@@ -9,33 +9,26 @@ public class StateMachine : Behaviour, IUpdate
private readonly Event<IState, IState.StateTransitionReadyArguments>.EventHandler delegateOnStateTransitionReady = null!; private readonly Event<IState, IState.StateTransitionReadyArguments>.EventHandler delegateOnStateTransitionReady = null!;
private IState _state = new State();
public StateMachine()
{
delegateOnStateTransitionReady = OnStateTransitionReady;
}
[Serialize] [Serialize]
public IState State public IState State
{ {
get => _state; get;
set set
{ {
if (_state == value) if (field == value)
return; return;
IState previousState = _state; IState previousState = field;
previousState.OnStateTransitionReady.RemoveListener(delegateOnStateTransitionReady); previousState.OnStateTransitionReady.RemoveListener(delegateOnStateTransitionReady);
_state = value; field = value;
previousState.TransitionFrom(value); previousState.TransitionFrom(value);
value.TransitionTo(_state); value.TransitionTo(field);
OnStateChanged?.Invoke(this, new(value, previousState)); OnStateChanged?.Invoke(this, new(value, previousState));
value.OnStateTransitionReady.AddListener(delegateOnStateTransitionReady); value.OnStateTransitionReady.AddListener(delegateOnStateTransitionReady);
} }
} } = new State();
private void OnStateTransitionReady(IState sender, IState.StateTransitionReadyArguments args) private void OnStateTransitionReady(IState sender, IState.StateTransitionReadyArguments args)
{ {
@@ -55,5 +48,10 @@ public class StateMachine : Behaviour, IUpdate
State.Update(); State.Update();
} }
public StateMachine()
{
delegateOnStateTransitionReady = OnStateTransitionReady;
}
public readonly record struct StateChangedArguments(IState CurrentState, IState PreviousState); public readonly record struct StateChangedArguments(IState CurrentState, IState PreviousState);
} }

View File

@@ -14,18 +14,17 @@ public class Timer : Behaviour, IUpdate, IEnterUniverse, IExitUniverse, ITimer
public double StartTime { get; protected set; } = 0f; public double StartTime { get; protected set; } = 0f;
public float Percentage => (float)(1f - (Remaining / StartTime)); public float Percentage => (float)(1f - (Remaining / StartTime));
private double _remaining = 0f;
public double Remaining public double Remaining
{ {
get => _remaining; get;
protected set protected set
{ {
if (value < .0f) if (value < .0f)
value = .0f; value = .0f;
_remaining = value; field = value;
} }
} } = 0f;
private bool shouldBeTicking = false; private bool shouldBeTicking = false;
private bool hasStartedTickingBefore = false; private bool hasStartedTickingBefore = false;

View File

@@ -13,17 +13,18 @@ internal class Tween : ITween
public Event<ITween> OnUpdated { get; } = new(); public Event<ITween> OnUpdated { get; } = new();
public Event<ITween, ITween.TweenDeltaArguments> OnDeltaUpdated { get; } = new(); public Event<ITween, ITween.TweenDeltaArguments> OnDeltaUpdated { get; } = new();
private TweenState _state = TweenState.Idle; private float _counter = 0f;
public TweenState State public TweenState State
{ {
get => _state; get;
set set
{ {
if (value == _state) if (value == field)
return; return;
TweenState previousState = _state; TweenState previousState = field;
_state = value; field = value;
switch (value) switch (value)
{ {
case TweenState.Completed: OnCompleted?.Invoke(this); OnEnded?.Invoke(this); break; case TweenState.Completed: OnCompleted?.Invoke(this); OnEnded?.Invoke(this); break;
@@ -37,11 +38,10 @@ internal class Tween : ITween
break; break;
} }
} }
} } = TweenState.Idle;
public float Duration { get; internal set; } = 1f; public float Duration { get; internal set; } = 1f;
public float Progress { get; internal set; } = 0f; public float Progress { get; internal set; } = 0f;
private float _counter = 0f;
public IEasing Easing { get; set; } = EaseLinear.Instance; public IEasing Easing { get; set; } = EaseLinear.Instance;
public float Value => Easing.Evaluate(Progress); public float Value => Easing.Evaluate(Progress);

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>Engine</RootNamespace> <RootNamespace>Engine</RootNamespace>