chore: bumped dotnet version to 10
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user