refactor: updated systems to use the update interfaces
This commit is contained in:
@@ -4,13 +4,11 @@ using Syntriax.Engine.Core;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D;
|
||||
|
||||
public class PhysicsEngine2D : Behaviour, IPhysicsEngine2D
|
||||
public class PhysicsEngine2D : Behaviour, IPreUpdate, IPhysicsEngine2D
|
||||
{
|
||||
public Event<IPhysicsEngine2D, float> OnPhysicsIteration { get; } = new();
|
||||
public Event<IPhysicsEngine2D, float> OnPhysicsStep { get; } = new();
|
||||
|
||||
private readonly Event<IUniverse, IUniverse.UpdateArguments>.EventHandler delegateOnPreUpdate = null!;
|
||||
|
||||
private float physicsTicker = 0f;
|
||||
private int _iterationPerStep = 1;
|
||||
private float _iterationPeriod = 1f / 60f;
|
||||
@@ -191,8 +189,6 @@ public class PhysicsEngine2D : Behaviour, IPhysicsEngine2D
|
||||
physicsPostUpdateCollector.Assign(universe);
|
||||
colliderCollector.Assign(universe);
|
||||
rigidBodyCollector.Assign(universe);
|
||||
|
||||
universe.OnPreUpdate.AddListener(OnEnginePreUpdate);
|
||||
}
|
||||
|
||||
protected override void OnExitedUniverse(IUniverse universe)
|
||||
@@ -203,13 +199,11 @@ public class PhysicsEngine2D : Behaviour, IPhysicsEngine2D
|
||||
physicsPostUpdateCollector.Unassign();
|
||||
colliderCollector.Unassign();
|
||||
rigidBodyCollector.Unassign();
|
||||
|
||||
universe.OnPreUpdate.RemoveListener(OnEnginePreUpdate);
|
||||
}
|
||||
|
||||
private void OnEnginePreUpdate(IUniverse sender, IUniverse.UpdateArguments args)
|
||||
void IPreUpdate.PreUpdate()
|
||||
{
|
||||
physicsTicker += args.EngineTime.DeltaTime;
|
||||
physicsTicker += Universe.Time.DeltaTime;
|
||||
|
||||
while (physicsTicker >= IterationPeriod)
|
||||
{
|
||||
@@ -222,15 +216,13 @@ public class PhysicsEngine2D : Behaviour, IPhysicsEngine2D
|
||||
{
|
||||
collisionDetector = new CollisionDetector2D();
|
||||
collisionResolver = new CollisionResolver2D();
|
||||
|
||||
delegateOnPreUpdate = OnEnginePreUpdate;
|
||||
Priority = int.MaxValue;
|
||||
}
|
||||
|
||||
public PhysicsEngine2D(ICollisionDetector2D collisionDetector, ICollisionResolver2D collisionResolver)
|
||||
{
|
||||
this.collisionDetector = collisionDetector;
|
||||
this.collisionResolver = collisionResolver;
|
||||
|
||||
delegateOnPreUpdate = OnEnginePreUpdate;
|
||||
Priority = int.MaxValue;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user