refactor: behaviour collector Count and indexer accessors added
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
/// <summary>
|
||||
@@ -19,6 +17,16 @@ public interface IBehaviourCollector<T> : IHasUniverse where T : class
|
||||
/// </summary>
|
||||
event RemovedEventHandler? OnRemoved;
|
||||
|
||||
/// <summary>
|
||||
/// Amount of <typeparamref name="T"/> collected.
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get a <typeparamref name="T"/> collected by it's index.
|
||||
/// </summary>
|
||||
T this[System.Index index] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for handling the <see cref="OnCollected"/> event.
|
||||
/// </summary>
|
||||
|
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -16,7 +15,6 @@ public class ActiveBehaviourCollector<T> : IBehaviourCollector<T> where T : clas
|
||||
protected readonly List<T> activeBehaviours = new(32);
|
||||
protected readonly Dictionary<IActive, T> monitoringActiveToBehaviour = new(32);
|
||||
|
||||
public IReadOnlyList<T> Behaviours => activeBehaviours;
|
||||
public IUniverse Universe { get; private set; } = null!;
|
||||
|
||||
public ActiveBehaviourCollector() { }
|
||||
@@ -117,4 +115,7 @@ public class ActiveBehaviourCollector<T> : IBehaviourCollector<T> where T : clas
|
||||
OnUnassigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int Count => activeBehaviours.Count;
|
||||
public T this[System.Index index] => activeBehaviours[index];
|
||||
}
|
||||
|
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -14,7 +13,6 @@ public class BehaviourCollector<T> : IBehaviourCollector<T> where T : class
|
||||
|
||||
protected readonly List<T> behaviours = new(32);
|
||||
|
||||
public IReadOnlyList<T> Behaviours => behaviours;
|
||||
public IUniverse Universe { get; private set; } = null!;
|
||||
|
||||
public BehaviourCollector() { }
|
||||
@@ -96,4 +94,7 @@ public class BehaviourCollector<T> : IBehaviourCollector<T> where T : class
|
||||
OnUnassigned?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int Count => behaviours.Count;
|
||||
public T this[System.Index index] => behaviours[index];
|
||||
}
|
||||
|
@@ -11,20 +11,20 @@ public class DrawManager : UniverseObject
|
||||
|
||||
private void OnPreDraw(IUniverse sender)
|
||||
{
|
||||
for (int i = preDrawEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
preDrawEntities.Behaviours[i].PreDraw();
|
||||
for (int i = preDrawEntities.Count - 1; i >= 0; i--)
|
||||
preDrawEntities[i].PreDraw();
|
||||
}
|
||||
|
||||
private void OnDraw(IUniverse sender)
|
||||
{
|
||||
for (int i = drawEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
drawEntities.Behaviours[i].Draw();
|
||||
for (int i = drawEntities.Count - 1; i >= 0; i--)
|
||||
drawEntities[i].Draw();
|
||||
}
|
||||
|
||||
private void OnPostDraw(IUniverse sender)
|
||||
{
|
||||
for (int i = postDrawEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
postDrawEntities.Behaviours[i].PostDraw();
|
||||
for (int i = postDrawEntities.Count - 1; i >= 0; i--)
|
||||
postDrawEntities[i].PostDraw();
|
||||
}
|
||||
|
||||
protected override void OnEnteringUniverse(IUniverse universe)
|
||||
|
@@ -46,20 +46,20 @@ public class UpdateManager : UniverseObject
|
||||
toCallFirstFrameUpdates.RemoveAt(i);
|
||||
}
|
||||
|
||||
for (int i = preUpdateEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
preUpdateEntities.Behaviours[i].PreUpdate();
|
||||
for (int i = preUpdateEntities.Count - 1; i >= 0; i--)
|
||||
preUpdateEntities[i].PreUpdate();
|
||||
}
|
||||
|
||||
private void OnUpdate(IUniverse sender, UniverseTime engineTime)
|
||||
{
|
||||
for (int i = updateEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
updateEntities.Behaviours[i].Update();
|
||||
for (int i = updateEntities.Count - 1; i >= 0; i--)
|
||||
updateEntities[i].Update();
|
||||
}
|
||||
|
||||
private void OnPostUpdate(IUniverse sender, UniverseTime engineTime)
|
||||
{
|
||||
for (int i = postUpdateEntities.Behaviours.Count - 1; i >= 0; i--)
|
||||
postUpdateEntities.Behaviours[i].PostUpdate();
|
||||
for (int i = postUpdateEntities.Count - 1; i >= 0; i--)
|
||||
postUpdateEntities[i].PostUpdate();
|
||||
}
|
||||
|
||||
private void OnFirstFrameCollected(IBehaviourCollector<IFirstFrameUpdate> sender, IFirstFrameUpdate behaviourCollected)
|
||||
|
Reference in New Issue
Block a user