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<IAssignable> OnUnassigned { get; } = new();
private IStateEnable _stateEnable = null!;
private bool _initialized = false;
private string _id = string.Empty;
public virtual IStateEnable StateEnable => _stateEnable;
public virtual IStateEnable StateEnable { get; private set; } = null!;
public string Id
{
get => _id;
get;
set
{
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;
string previousId = _id;
string previousId = field;
_id = value;
field = value;
OnIdChanged?.Invoke(this, new(previousId));
}
}
} = string.Empty;
public bool IsInitialized
{
get => _initialized;
get;
private set
{
if (value == _initialized)
if (value == field)
return;
_initialized = value;
field = value;
if (value)
OnInitialized?.Invoke(this);
else
OnFinalized?.Invoke(this);
}
}
} = false;
protected virtual void OnAssign(IStateEnable stateEnable) { }
public bool Assign(IStateEnable stateEnable)
@@ -57,8 +52,8 @@ public abstract class BaseEntity : IEntity
if (IsInitialized)
return false;
_stateEnable = stateEnable;
_stateEnable.Assign(this);
StateEnable = stateEnable;
StateEnable.Assign(this);
OnAssign(stateEnable);
OnStateEnableAssigned?.Invoke(this);
return true;
@@ -72,8 +67,8 @@ public abstract class BaseEntity : IEntity
UnassignInternal();
_stateEnable = null!;
_stateEnable.Unassign();
StateEnable = null!;
StateEnable.Unassign();
OnUnassigned?.Invoke(this);
return true;
}
@@ -84,7 +79,7 @@ public abstract class BaseEntity : IEntity
if (IsInitialized)
return false;
_stateEnable ??= Factory.StateEnableFactory.Instantiate(this);
StateEnable ??= Factory.StateEnableFactory.Instantiate(this);
InitializeInternal();
@@ -104,6 +99,6 @@ public abstract class BaseEntity : IEntity
return true;
}
protected BaseEntity() => _id = Guid.NewGuid().ToString("D");
protected BaseEntity(string id) => _id = id;
protected BaseEntity() => Id = Guid.NewGuid().ToString("D");
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 IUniverseObject UniverseObject => BehaviourController.UniverseObject;
private IBehaviourController _behaviourController = null!;
public IBehaviourController BehaviourController => _behaviourController;
public IBehaviourController BehaviourController { get; private set; } = null!;
private int _priority = 0;
public int Priority
{
get => _priority;
get;
set
{
if (value == _priority)
if (value == field)
return;
int previousPriority = _priority;
_priority = value;
int previousPriority = field;
field = value;
OnPriorityChanged?.Invoke(this, new(previousPriority));
}
}
} = 0;
private bool _isActive = false;
public bool IsActive => _isActive;
public bool IsActive { get; private set; } = false;
protected virtual void OnAssign(IBehaviourController behaviourController) { }
public bool Assign(IBehaviourController behaviourController)
@@ -41,7 +38,7 @@ public abstract class Behaviour : BaseEntity, IBehaviour
if (IsInitialized)
return false;
_behaviourController = behaviourController;
BehaviourController = behaviourController;
OnAssign(behaviourController);
behaviourController.OnUniverseObjectAssigned.AddListener(delegateOnUniverseObjectAssigned);
behaviourController.StateEnable.OnEnabledChanged.AddListener(delegateOnStateEnabledChanged);
@@ -71,7 +68,7 @@ public abstract class Behaviour : BaseEntity, IBehaviour
BehaviourController.OnUniverseObjectAssigned.RemoveListener(delegateOnUniverseObjectAssigned);
BehaviourController.StateEnable.OnEnabledChanged.RemoveListener(delegateOnStateEnabledChanged);
base.UnassignInternal();
_behaviourController = null!;
BehaviourController = null!;
}
protected override void InitializeInternal()
@@ -88,7 +85,7 @@ public abstract class Behaviour : BaseEntity, IBehaviour
private void UpdateActive()
{
bool previousActive = IsActive;
_isActive = StateEnable.Enabled && _behaviourController.StateEnable.Enabled && _behaviourController.UniverseObject.IsActive;
IsActive = StateEnable.Enabled && BehaviourController.StateEnable.Enabled && BehaviourController.UniverseObject.IsActive;
if (previousActive != IsActive)
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 IUniverseObject _universeObject = null!;
public IUniverseObject UniverseObject { get; private set; } = null!;
public IUniverseObject UniverseObject => _universeObject;
public int Count => behaviours.Count;
public IBehaviour this[Index index] => behaviours[index];
@@ -103,7 +102,7 @@ public class BehaviourController : BaseEntity, IBehaviourController
if (UniverseObject is not null && UniverseObject.IsInitialized)
return false;
_universeObject = universeObject;
UniverseObject = universeObject;
OnAssign(universeObject);
OnUniverseObjectAssigned?.Invoke(this);
return true;

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>false</ImplicitUsings>
<Nullable>enable</Nullable>
<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
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 => _logger; set => _logger = value ?? ILogger.Shared; }
public ILogger Logger { get; set => field = value ?? ILogger.Shared; } = ILogger.Shared;
private readonly List<ListenerData> listeners = 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
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 => _logger; set => _logger = value ?? ILogger.Shared; }
public ILogger Logger { get; set => field = value ?? ILogger.Shared; } = ILogger.Shared;
private readonly List<ListenerData> listeners = 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
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 => _logger; set => _logger = value ?? ILogger.Shared; }
public ILogger Logger { get; set => field = value ?? ILogger.Shared; } = ILogger.Shared;
private readonly List<ListenerData> listeners = 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();
private List<Vector2D> _vertices = vertices;
private readonly List<Vector2D> _vertices = vertices;
/// <summary>
/// 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<IAssignable>? OnUnassigned { get; } = new();
private bool _enabled = true;
private IEntity _entity = null!;
public IEntity Entity => _entity;
public IEntity Entity { get; private set; } = null!;
public bool Enabled
{
get => _enabled;
get;
set
{
if (value == _enabled)
if (value == field)
return;
bool previousState = _enabled;
_enabled = value;
bool previousState = field;
field = value;
OnEnabledChanged?.Invoke(this, new(previousState));
}
}
} = true;
protected virtual void OnAssign(IEntity entity) { }
public bool Assign(IEntity entity)
{
if (_entity is not null && _entity.IsInitialized)
if (Entity is not null && Entity.IsInitialized)
return false;
_entity = entity;
Entity = entity;
OnAssign(entity);
OnEntityAssigned?.Invoke(this);
return true;
@@ -39,10 +36,10 @@ public class StateEnable : IStateEnable
public bool Unassign()
{
if (_entity is null)
if (Entity is null)
return false;
_entity = null!;
Entity = null!;
OnUnassigned?.Invoke(this);
return true;
}

View File

@@ -23,7 +23,6 @@ public class Universe : BaseEntity, IUniverse
private readonly Event<IUniverseObject, IUniverseObject.ExitedUniverseArguments>.EventHandler delegateOnUniverseObjectExitedUniverse = null!;
private readonly FastList<IUniverseObject> _universeObjects = new(Constants.UNIVERSE_OBJECTS_SIZE_INITIAL);
private float _timeScale = 1f;
public Universe()
{
@@ -37,18 +36,18 @@ public class Universe : BaseEntity, IUniverse
public UniverseTime UnscaledTime { get; private set; } = new();
public float TimeScale
{
get => _timeScale;
get;
set
{
value = value.Max(0f);
if (value == _timeScale)
if (value == field)
return;
float previousTimeScale = _timeScale;
_timeScale = value;
float previousTimeScale = field;
field = value;
OnTimeScaleChanged?.Invoke(this, new(previousTimeScale));
}
}
} = 1f;
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<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 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 IBehaviourController BehaviourController => _behaviourController;
public IUniverse Universe => _universe;
public bool IsInUniverse => _universe is not null;
public bool IsActive => _isActive;
public bool IsInUniverse => Universe is not null;
public string Name
{
get => _name;
get;
set
{
if (value == _name) return;
if (value == field) return;
string previousName = _name;
_name = value;
string previousName = field;
field = value;
OnNameChanged?.Invoke(this, new(previousName));
}
}
} = nameof(UniverseObject);
public IUniverseObject? Parent
{
get => _parent;
get;
set
{
if (value == this)
throw new Exceptions.AssignFailedException($"{Name} can not parent itself");
if (_parent == value)
if (field == value)
return;
IUniverseObject? previousParent = Parent;
@@ -59,7 +55,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
previousParent.OnActiveChanged.RemoveListener(OnParentActiveChanged);
}
_parent = value;
field = value;
if (value is not null)
{
@@ -73,7 +69,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
UpdateActive();
OnParentChanged?.Invoke(this, new(previousParent, value));
}
}
} = null;
protected virtual void OnEnteringUniverse(IUniverse universe) { }
bool IUniverseObject.EnterUniverse(IUniverse universe)
@@ -81,7 +77,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
if (IsInUniverse)
return false;
_universe = universe;
Universe = universe;
UpdateActive();
OnEnteringUniverse(universe);
OnEnteredUniverse?.Invoke(this, new(universe));
@@ -91,11 +87,11 @@ public class UniverseObject : BaseEntity, IUniverseObject
protected virtual void OnExitingUniverse(IUniverse universe) { }
bool IUniverseObject.ExitUniverse()
{
if (!IsInUniverse || _universe is not IUniverse universe)
if (!IsInUniverse || Universe is not IUniverse universe)
return false;
OnExitingUniverse(universe);
_universe = null!;
Universe = null!;
OnExitedUniverse?.Invoke(this, new(universe));
return true;
}
@@ -125,7 +121,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
if (IsInitialized)
return false;
_behaviourController = behaviourController;
BehaviourController = behaviourController;
OnAssign(behaviourController);
OnBehaviourControllerAssigned?.Invoke(this);
return true;
@@ -145,7 +141,7 @@ public class UniverseObject : BaseEntity, IUniverseObject
private void UpdateActive()
{
bool previousActive = IsActive;
_isActive = StateEnable.Enabled && (Parent?.IsActive ?? true);
IsActive = StateEnable.Enabled && (Parent?.IsActive ?? true);
if (previousActive != IsActive)
OnActiveChanged?.Invoke(this, new(previousActive));
@@ -160,12 +156,12 @@ public class UniverseObject : BaseEntity, IUniverseObject
protected override void InitializeInternal()
{
base.InitializeInternal();
_behaviourController ??= Factory.BehaviourControllerFactory.Instantiate(this);
_behaviourController.Initialize();
BehaviourController ??= Factory.BehaviourControllerFactory.Instantiate(this);
BehaviourController.Initialize();
}
public UniverseObject()
{
_name = GetType().Name;
Name = GetType().Name;
}
}

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<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> OnZoomChanged { get; } = new();
private Matrix _matrixTransform = Matrix.Identity;
private Viewport _viewport = default;
private float _zoom = 1f;
public GraphicsDeviceManager Graphics { get; private set; } = null!;
public ITransform2D Transform { get; private set; } = null!;
public Matrix MatrixTransform
{
get => _matrixTransform;
get;
set
{
if (_matrixTransform == value)
if (field == value)
return;
_matrixTransform = value;
field = value;
OnMatrixTransformChanged.Invoke(this);
}
}
} = Matrix.Identity;
public Vector2D Position
{
@@ -40,31 +35,31 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr
public Viewport Viewport
{
get => _viewport;
get;
set
{
if (_viewport.Equals(value))
if (field.Equals(value))
return;
_viewport = value;
field = value;
OnViewportChanged.Invoke(this);
}
}
} = default;
public float Zoom
{
get => _zoom;
get;
set
{
float newValue = Math.Max(0.1f, value);
if (_zoom == newValue)
if (field == newValue)
return;
_zoom = newValue;
field = newValue;
OnZoomChanged.Invoke(this);
}
}
} = 1f;
public float Rotation
{
@@ -99,6 +94,6 @@ public class MonoGameCamera2D : Behaviour, ICamera2D, IFirstFrameUpdate, ILastFr
Matrix.CreateRotationZ(Rotation * Math.DegreeToRadian) *
Matrix.CreateScale(Transform.Scale.X.Max(Transform.Scale.Y)) *
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.FieldOfViewChangedArguments> OnFieldOfViewChanged { get; } = new();
private Matrix _view = Matrix.Identity;
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 float fieldOfView = Math.DegreeToRadian * 70f;
private bool isRecalculationNeeded = true;
public GraphicsDeviceManager Graphics { get; private set; } = null!;
@@ -28,41 +23,42 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
public Matrix View
{
get => _view;
get;
set
{
if (_view == value)
if (field == value)
return;
Matrix previousView = _view;
_view = value;
Matrix previousView = field;
field = value;
OnViewChanged.Invoke(this, new(previousView));
}
}
} = Matrix.Identity;
public Matrix Projection
{
get => _projection;
get;
set
{
if (_projection == value)
if (field == value)
return;
Matrix previousProjection = _projection;
_projection = value;
Matrix previousProjection = field;
field = value;
OnProjectionChanged.Invoke(this, new(previousProjection));
}
}
} = Matrix.Identity;
public Viewport Viewport
{
get => _viewport;
get;
set
{
if (_viewport.Equals(value))
if (field.Equals(value))
return;
Viewport previousViewport = _viewport;
_viewport = value;
Viewport previousViewport = field;
field = value;
SetForRecalculation();
OnViewportChanged.Invoke(this, new(previousViewport));
}
@@ -70,40 +66,40 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
public float NearPlane
{
get => _nearPlane;
get;
set
{
float previousNearPlane = _nearPlane;
_nearPlane = value.Max(0.0001f);
float previousNearPlane = field;
field = value.Max(0.0001f);
SetForRecalculation();
OnNearPlaneChanged.Invoke(this, new(previousNearPlane));
}
}
} = 0.01f;
public float FarPlane
{
get => _farPlane;
get;
set
{
float previousFarPlane = _farPlane;
_farPlane = value.Max(NearPlane);
float previousFarPlane = field;
field = value.Max(NearPlane);
SetForRecalculation();
OnFarPlaneChanged.Invoke(this, new(previousFarPlane));
}
}
} = 100f;
public float FieldOfView
{
get => _fieldOfView * Math.RadianToDegree;
get => fieldOfView * Math.RadianToDegree;
set
{
value = value.Max(0.1f) * Math.DegreeToRadian;
if (_fieldOfView == value)
if (fieldOfView == value)
return;
float previousFieldOfView = _fieldOfView;
_fieldOfView = value;
float previousFieldOfView = fieldOfView;
fieldOfView = value;
SetForRecalculation();
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 farPoint = new(screenPosition.X, screenPosition.Y, 1f);
Vector3 worldNear = Viewport.Unproject(nearPoint, _projection, _view, Matrix.Identity);
Vector3 worldFar = Viewport.Unproject(farPoint, _projection, _view, Matrix.Identity);
Vector3 worldNear = Viewport.Unproject(nearPoint, Projection, View, Matrix.Identity);
Vector3 worldFar = Viewport.Unproject(farPoint, Projection, View, Matrix.Identity);
Vector3 direction = Vector3.Normalize(worldFar - worldNear);
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 FirstActiveFrame()
@@ -167,14 +163,14 @@ public class MonoGameCamera3D : Behaviour, ICamera3D, IFirstFrameUpdate, ILastFr
private void CalculateProjection()
{
float yScale = 1f / (float)Math.Tan(_fieldOfView / 2f);
float yScale = 1f / (float)Math.Tan(fieldOfView / 2f);
float xScale = yScale / Viewport.AspectRatio;
Projection = new Matrix(
xScale, 0, 0, 0,
0, yScale, 0, 0,
0, 0, _farPlane / (_farPlane - _nearPlane), 1,
0, 0, -_nearPlane * _farPlane / (_farPlane - _nearPlane), 0
0, 0, FarPlane / (FarPlane - NearPlane), 1,
0, 0, -NearPlane * FarPlane / (FarPlane - NearPlane), 0
);
}

View File

@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<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 Engine.Core;

View File

@@ -8,12 +8,14 @@ namespace Engine.Integration.MonoGame;
public class TriangleBatch : ITriangleBatch
{
private readonly GraphicsDevice graphicsDevice;
private VertexBuffer vertexBuffer = default!;
private readonly VertexBuffer vertexBuffer = default!;
private readonly VertexPositionColor[] vertices = new VertexPositionColor[1024];
private int verticesIndex = 0;
private Matrix _view;
private Matrix _projection;
private readonly BasicEffect basicEffect;
private Matrix view = Matrix.Identity;
private Matrix projection = Matrix.Identity;
private readonly BasicEffect basicEffect = null!;
private readonly RasterizerState rasterizerState = new() { CullMode = CullMode.None };
public TriangleBatch(GraphicsDevice graphicsDevice)
@@ -42,16 +44,16 @@ public class TriangleBatch : ITriangleBatch
public void Begin(Matrix? view = null, Matrix? projection = null)
{
if (view != null)
_view = view.Value;
this.view = view.Value;
else
_view = Matrix.Identity;
this.view = Matrix.Identity;
if (projection != null)
_projection = projection.Value;
this.projection = projection.Value;
else
{
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;
graphicsDevice.RasterizerState = rasterizerState;
basicEffect.Projection = _projection;
basicEffect.View = _view;
basicEffect.Projection = projection;
basicEffect.View = view;
vertexBuffer.SetData(vertices);
graphicsDevice.SetVertexBuffer(vertexBuffer);

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<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!;
protected bool NeedsRecalculation { get; set; } = true;
protected IRigidBody2D? _rigidBody2D = null;
protected Collider2DBase()
{
delegateOnBehaviourAddedToController = OnBehaviourAddedToController;
delegateOnBehaviourRemovedFromController = OnBehaviourRemovedFromController;
delegateSetNeedsRecalculationFromPosition = SetNeedsRecalculationFromPosition;
delegateSetNeedsRecalculationFromRotation = SetNeedsRecalculationFromRotation;
delegateSetNeedsRecalculationFromScale = SetNeedsRecalculationFromScale;
delegateUpdateRigidBody2D = UpdateRigidBody2D;
}
public IRigidBody2D? RigidBody2D => _rigidBody2D;
public IRigidBody2D? RigidBody2D { get; protected set; } = null;
public bool IsTrigger { get; set; } = false;
public void Recalculate()
@@ -46,7 +35,8 @@ public abstract class Collider2DBase : Behaviour2D, ICollider2D
{
base.OnInitialize();
BehaviourController.TryGetBehaviourInParent(out _rigidBody2D);
BehaviourController.TryGetBehaviourInParent(out IRigidBody2D? foundRigidBody2D);
RigidBody2D = foundRigidBody2D;
BehaviourController.OnBehaviourAdded.AddListener(delegateOnBehaviourAddedToController);
BehaviourController.OnBehaviourRemoved.AddListener(delegateOnBehaviourRemovedFromController);
@@ -59,19 +49,20 @@ public abstract class Collider2DBase : Behaviour2D, ICollider2D
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)
{
if (args.BehaviourAdded is IRigidBody2D rigidBody)
_rigidBody2D = rigidBody;
RigidBody2D = rigidBody;
}
private void OnBehaviourRemovedFromController(IBehaviourController sender, IBehaviourController.BehaviourRemovedArguments args)
{
if (args.BehaviourRemoved is IRigidBody2D)
_rigidBody2D = null;
RigidBody2D = null;
}
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 Resolve(CollisionDetectionInformation collisionDetectionInformation) => OnCollisionResolved?.Invoke(this, collisionDetectionInformation);
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
{
private Circle _circleLocal = Circle.UnitCircle;
public Circle CircleWorld { get; protected set; } = Circle.UnitCircle;
public Circle CircleLocal
{
get => _circleLocal;
get;
set
{
_circleLocal = value;
field = value;
NeedsRecalculation = true;
}
}
} = Circle.UnitCircle;
public override void CalculateCollider() => CircleWorld = Transform.Transform(_circleLocal);
public override void CalculateCollider() => CircleWorld = Transform.Transform(CircleLocal);
public Collider2DCircle() { }
public Collider2DCircle(Circle circle) => CircleLocal = circle;

View File

@@ -4,25 +4,19 @@ namespace Engine.Physics2D;
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
{
get => _shapeLocal;
get;
set
{
_shapeLocal = value;
field = value;
NeedsRecalculation = true;
}
}
} = Shape2D.Square;
private Shape2D _shapeWorld = Shape2D.Square;
private Shape2D _shapeLocal = Shape2D.Square;
public override void CalculateCollider() => ShapeLocal.Transform(Transform, _shapeWorld);
public override void CalculateCollider() => ShapeLocal.Transform(Transform, ShapeWorld);
public Collider2DShape() { }
public Collider2DShape(Shape2D shape)
{
ShapeLocal = shape;
}
public Collider2DShape(Shape2D shape) { ShapeLocal = shape; }
}

View File

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

View File

@@ -10,8 +10,6 @@ public class PhysicsEngine2D : Behaviour, IEnterUniverse, IExitUniverse, IPreUpd
public Event<IPhysicsEngine2D, float> OnPhysicsStep { get; } = new();
private float physicsTicker = 0f;
private int _iterationPerStep = 1;
private float _iterationPeriod = 1f / 60f;
protected readonly ICollisionDetector2D collisionDetector = 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<IPostPhysicsUpdate> postPhysicsUpdatePool = new();
public int IterationPerStep { get => _iterationPerStep; set => _iterationPerStep = value < 1 ? 1 : value; }
public float IterationPeriod { get => _iterationPeriod; set => _iterationPeriod = value.Max(0.0001f); }
public int IterationPerStep { get; set => field = value < 1 ? 1 : value; } = 1;
public float IterationPeriod { get; set => field = value.Max(0.0001f); } = 1f / 60f;
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<ICollider2D> colliders = new(64);
private int _iterationCount = 1;
private readonly ICollisionDetector2D collisionDetector = null!;
private readonly ICollisionResolver2D collisionResolver = null!;
private readonly IRaycastResolver2D raycastResolver = null!;
@@ -27,7 +24,7 @@ public class PhysicsEngine2DStandalone : IPhysicsEngine2D
private readonly ListPool<IPhysicsIteration> physicsIterationPool = 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)
{

View File

@@ -5,7 +5,6 @@ namespace Engine.Physics2D;
public class RigidBody2D : Behaviour2D, IRigidBody2D
{
private const float LOWEST_ALLOWED_MASS = 0.00001f;
private float _mass = 1f;
public IPhysicsMaterial2D Material { get; set; } = new PhysicsMaterial2DDefault();
@@ -13,5 +12,5 @@ public class RigidBody2D : Behaviour2D, IRigidBody2D
public float AngularVelocity { get; set; } = 0f;
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">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Engine.Systems</RootNamespace>

View File

@@ -29,22 +29,21 @@ public class NetworkManager : Behaviour, IEnterUniverse, IExitUniverse, INetwork
private readonly BehaviourCollector<INetworkEntity> _networkEntityCollector = new();
public IBehaviourCollector<INetworkEntity> NetworkEntityCollector => _networkEntityCollector;
private INetworkCommunicator _networkCommunicator = null!;
public INetworkCommunicator NetworkCommunicator
{
get => _networkCommunicator;
get;
set
{
if (_networkCommunicator == value)
if (field == value)
return;
INetworkCommunicator? previousCommunicator = _networkCommunicator;
_networkCommunicator = value;
INetworkCommunicator? previousCommunicator = field;
field = value;
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
private void SubscribeCommunicatorMethods(INetworkCommunicator networkCommunicator)

View File

@@ -2,15 +2,14 @@ namespace Engine.Systems.Network;
public static class TypeHasher<T>
{
private static long _fnv1a = 0;
public static long FNV1a
{
get
{
if (_fnv1a == 0)
_fnv1a = Hasher.FNV1a(typeof(T).FullName ?? typeof(T).Name);
if (field == 0)
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 Dictionary<string, StateTransition> possibleTransitions = [];
private string _name = "Default State Name";
public IReadOnlyList<StateTransition> Transitions => transitions;
public IReadOnlyDictionary<string, StateTransition> PossibleTransitions => possibleTransitions;
public string Name
{
get => _name;
get;
set
{
if (_name.CompareTo(value) == 0)
if (field.CompareTo(value) == 0)
return;
string previousName = _name;
_name = value;
string previousName = field;
field = value;
OnNameChanged?.Invoke(this, new(previousName));
}
}
} = "Default State 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<INameable, INameable.NameChangedArguments> OnNameChanged { get; } = new();
private string _name = string.Empty;
public string Name
{
get => _name;
get;
set
{
if (_name.CompareTo(value) == 0)
if (field.CompareTo(value) == 0)
return;
string previousName = _name;
_name = value;
string previousName = field;
field = value;
OnNameChanged?.Invoke(this, new(previousName));
}
}
} = string.Empty;
protected virtual void OnUpdateState() { }
public void Update()

View File

@@ -9,33 +9,26 @@ public class StateMachine : Behaviour, IUpdate
private readonly Event<IState, IState.StateTransitionReadyArguments>.EventHandler delegateOnStateTransitionReady = null!;
private IState _state = new State();
public StateMachine()
{
delegateOnStateTransitionReady = OnStateTransitionReady;
}
[Serialize]
public IState State
{
get => _state;
get;
set
{
if (_state == value)
if (field == value)
return;
IState previousState = _state;
IState previousState = field;
previousState.OnStateTransitionReady.RemoveListener(delegateOnStateTransitionReady);
_state = value;
field = value;
previousState.TransitionFrom(value);
value.TransitionTo(_state);
value.TransitionTo(field);
OnStateChanged?.Invoke(this, new(value, previousState));
value.OnStateTransitionReady.AddListener(delegateOnStateTransitionReady);
}
}
} = new State();
private void OnStateTransitionReady(IState sender, IState.StateTransitionReadyArguments args)
{
@@ -55,5 +48,10 @@ public class StateMachine : Behaviour, IUpdate
State.Update();
}
public StateMachine()
{
delegateOnStateTransitionReady = OnStateTransitionReady;
}
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 float Percentage => (float)(1f - (Remaining / StartTime));
private double _remaining = 0f;
public double Remaining
{
get => _remaining;
get;
protected set
{
if (value < .0f)
value = .0f;
_remaining = value;
field = value;
}
}
} = 0f;
private bool shouldBeTicking = false;
private bool hasStartedTickingBefore = false;

View File

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

View File

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