refactor: Dependency Injection to PhysicsEngine2Ds
This commit is contained in:
parent
8619778d52
commit
de336d0ee5
|
@ -12,8 +12,9 @@ public class PhysicsEngine2D : IPhysicsEngine2D
|
|||
private readonly List<ICollider2D> colliders = new(64);
|
||||
|
||||
private int _iterationCount = 1;
|
||||
private ICollisionDetector2D collisionDetector = new CollisionDetector2D();
|
||||
private ICollisionResolver2D collisionResolver = new CollisionResolver2D();
|
||||
|
||||
private readonly ICollisionDetector2D collisionDetector = null!;
|
||||
private readonly ICollisionResolver2D collisionResolver = null!;
|
||||
|
||||
public int IterationCount { get => _iterationCount; set => _iterationCount = value < 1 ? 1 : value; }
|
||||
|
||||
|
@ -122,4 +123,16 @@ public class PhysicsEngine2D : IPhysicsEngine2D
|
|||
|
||||
colliders.Remove(collider2D);
|
||||
}
|
||||
|
||||
public PhysicsEngine2D()
|
||||
{
|
||||
collisionDetector = new CollisionDetector2D();
|
||||
collisionResolver = new CollisionResolver2D();
|
||||
}
|
||||
|
||||
public PhysicsEngine2D(ICollisionDetector2D collisionDetector, ICollisionResolver2D collisionResolver)
|
||||
{
|
||||
this.collisionDetector = collisionDetector;
|
||||
this.collisionResolver = collisionResolver;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,9 @@ public class PhysicsEngine2DCacher : IPhysicsEngine2D, IAssignableGameManager
|
|||
|
||||
private int _iterationCount = 1;
|
||||
|
||||
protected ICollisionDetector2D collisionDetector = new CollisionDetector2D(); // TODO Dependency Injection or Reversion
|
||||
protected ICollisionResolver2D collisionResolver = new CollisionResolver2D(); // TODO Dependency Injection or Reversion
|
||||
protected readonly ICollisionDetector2D collisionDetector = null!;
|
||||
protected readonly ICollisionResolver2D collisionResolver = null!;
|
||||
|
||||
protected BehaviourCacher<IRigidBody2D> rigidBodyCacher = new();
|
||||
protected BehaviourCacher<ICollider2D> colliderCacher = new();
|
||||
|
||||
|
@ -121,6 +122,29 @@ public class PhysicsEngine2DCacher : IPhysicsEngine2D, IAssignableGameManager
|
|||
return true;
|
||||
}
|
||||
|
||||
public PhysicsEngine2DCacher() { }
|
||||
public PhysicsEngine2DCacher(IGameManager gameManager) => Assign(gameManager);
|
||||
public PhysicsEngine2DCacher()
|
||||
{
|
||||
collisionDetector = new CollisionDetector2D();
|
||||
collisionResolver = new CollisionResolver2D();
|
||||
}
|
||||
|
||||
public PhysicsEngine2DCacher(IGameManager gameManager)
|
||||
{
|
||||
Assign(gameManager);
|
||||
collisionDetector = new CollisionDetector2D();
|
||||
collisionResolver = new CollisionResolver2D();
|
||||
}
|
||||
|
||||
public PhysicsEngine2DCacher(IGameManager gameManager, ICollisionDetector2D collisionDetector, ICollisionResolver2D collisionResolver)
|
||||
{
|
||||
Assign(gameManager);
|
||||
this.collisionDetector = collisionDetector;
|
||||
this.collisionResolver = collisionResolver;
|
||||
}
|
||||
|
||||
public PhysicsEngine2DCacher(ICollisionDetector2D collisionDetector, ICollisionResolver2D collisionResolver)
|
||||
{
|
||||
this.collisionDetector = collisionDetector;
|
||||
this.collisionResolver = collisionResolver;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue