refactor: Renamed BehaviourCacher to BehaviourCollector

This commit is contained in:
Syntriax 2024-02-09 09:43:15 +03:00
parent be06575f91
commit 2cf6135063
2 changed files with 24 additions and 24 deletions

View File

@ -6,13 +6,13 @@ using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Core;
public class BehaviourCacher<T> : IAssignableGameManager, IEnumerable<T>
public class BehaviourCollector<T> : IAssignableGameManager, IEnumerable<T>
{
public Action<IAssignable>? OnUnassigned { get; set; } = null;
public Action<IAssignableGameManager>? OnGameManagerAssigned { get; set; } = null;
public Action<BehaviourCacher<T>, T>? OnCached { get; set; } = null;
public Action<BehaviourCacher<T>, T>? OnUncached { get; set; } = null;
public Action<BehaviourCollector<T>, T>? OnCollected { get; set; } = null;
public Action<BehaviourCollector<T>, T>? OnRemoved { get; set; } = null;
private readonly List<T> _behaviours = new(32);
@ -21,8 +21,8 @@ public class BehaviourCacher<T> : IAssignableGameManager, IEnumerable<T>
public T this[Index index] => _behaviours[index];
public BehaviourCacher() { }
public BehaviourCacher(IGameManager gameManager) => Assign(gameManager);
public BehaviourCollector() { }
public BehaviourCollector(IGameManager gameManager) => Assign(gameManager);
private void OnGameObjectRegistered(IGameManager manager, IGameObject gameObject)
{
@ -42,7 +42,7 @@ public class BehaviourCacher<T> : IAssignableGameManager, IEnumerable<T>
return;
_behaviours.Add(tBehaviour);
OnCached?.Invoke(this, tBehaviour);
OnCollected?.Invoke(this, tBehaviour);
}
private void OnBehaviourRemoved(IBehaviourController controller, IBehaviour behaviour)
@ -53,7 +53,7 @@ public class BehaviourCacher<T> : IAssignableGameManager, IEnumerable<T>
if (!_behaviours.Remove(tBehaviour))
return;
OnUncached?.Invoke(this, tBehaviour);
OnRemoved?.Invoke(this, tBehaviour);
}
public bool Assign(IGameManager gameManager)

View File

@ -6,7 +6,7 @@ using Syntriax.Engine.Physics2D.Abstract;
namespace Syntriax.Engine.Physics2D;
public class PhysicsEngine2DCacher : IPhysicsEngine2D, IAssignableGameManager
public class PhysicsEngine2DCollector : IPhysicsEngine2D, IAssignableGameManager
{
public Action<IAssignable>? OnUnassigned { get; set; } = null;
public Action<IAssignableGameManager>? OnGameManagerAssigned { get; set; } = null;
@ -17,8 +17,8 @@ public class PhysicsEngine2DCacher : IPhysicsEngine2D, IAssignableGameManager
protected readonly ICollisionDetector2D collisionDetector = null!;
protected readonly ICollisionResolver2D collisionResolver = null!;
protected BehaviourCacher<IRigidBody2D> rigidBodyCacher = new();
protected BehaviourCacher<ICollider2D> colliderCacher = new();
protected BehaviourCollector<IRigidBody2D> rigidBodyCollector = new();
protected BehaviourCollector<ICollider2D> colliderCollector = new();
public int IterationPerStep { get => _iterationPerStep; set => _iterationPerStep = value < 1 ? 1 : value; }
@ -31,23 +31,23 @@ public class PhysicsEngine2DCacher : IPhysicsEngine2D, IAssignableGameManager
for (int iterationIndex = 0; iterationIndex < IterationPerStep; iterationIndex++)
{
// Can Parallel
foreach (var rigidBody in rigidBodyCacher)
foreach (var rigidBody in rigidBodyCollector)
StepRigidBody(rigidBody, intervalDeltaTime);
// Can Parallel
foreach (var collider in colliderCacher)
foreach (var collider in colliderCollector)
collider.Recalculate();
// Can Parallel
for (int x = 0; x < colliderCacher.Behaviours.Count; x++)
for (int x = 0; x < colliderCollector.Behaviours.Count; x++)
{
ICollider2D? colliderX = colliderCacher.Behaviours[x];
ICollider2D? colliderX = colliderCollector.Behaviours[x];
if (!colliderX.IsActive)
return;
for (int y = x + 1; y < colliderCacher.Behaviours.Count; y++)
for (int y = x + 1; y < colliderCollector.Behaviours.Count; y++)
{
ICollider2D? colliderY = colliderCacher.Behaviours[y];
ICollider2D? colliderY = colliderCollector.Behaviours[y];
if (!colliderY.IsActive)
return;
@ -100,8 +100,8 @@ public class PhysicsEngine2DCacher : IPhysicsEngine2D, IAssignableGameManager
if (GameManager is not null)
return false;
colliderCacher.Assign(gameManager);
rigidBodyCacher.Assign(gameManager);
colliderCollector.Assign(gameManager);
rigidBodyCollector.Assign(gameManager);
GameManager = gameManager;
OnGameManagerAssigned?.Invoke(this);
@ -114,35 +114,35 @@ public class PhysicsEngine2DCacher : IPhysicsEngine2D, IAssignableGameManager
if (GameManager is null)
return false;
colliderCacher.Unassign();
rigidBodyCacher.Unassign();
colliderCollector.Unassign();
rigidBodyCollector.Unassign();
GameManager = null!;
OnUnassigned?.Invoke(this);
return true;
}
public PhysicsEngine2DCacher()
public PhysicsEngine2DCollector()
{
collisionDetector = new CollisionDetector2D();
collisionResolver = new CollisionResolver2D();
}
public PhysicsEngine2DCacher(IGameManager gameManager)
public PhysicsEngine2DCollector(IGameManager gameManager)
{
Assign(gameManager);
collisionDetector = new CollisionDetector2D();
collisionResolver = new CollisionResolver2D();
}
public PhysicsEngine2DCacher(IGameManager gameManager, ICollisionDetector2D collisionDetector, ICollisionResolver2D collisionResolver)
public PhysicsEngine2DCollector(IGameManager gameManager, ICollisionDetector2D collisionDetector, ICollisionResolver2D collisionResolver)
{
Assign(gameManager);
this.collisionDetector = collisionDetector;
this.collisionResolver = collisionResolver;
}
public PhysicsEngine2DCacher(ICollisionDetector2D collisionDetector, ICollisionResolver2D collisionResolver)
public PhysicsEngine2DCollector(ICollisionDetector2D collisionDetector, ICollisionResolver2D collisionResolver)
{
this.collisionDetector = collisionDetector;
this.collisionResolver = collisionResolver;