perf!: improved sorted behaviour collector by using binary insertion to reduce performance impact

This commit is contained in:
2025-05-31 12:00:32 +03:00
parent 61e2761580
commit 1acc8bdb8f
7 changed files with 103 additions and 19 deletions

View File

@@ -41,13 +41,14 @@ public class BehaviourCollector<T> : IBehaviourCollector<T> where T : class
OnBehaviourRemoved(universeObject.BehaviourController, new(universeObject.BehaviourController[i]));
}
protected virtual void AddBehaviour(T behaviour) => behaviours.Add(behaviour);
protected virtual void OnBehaviourAdd(IBehaviour behaviour) { }
private void OnBehaviourAdded(IBehaviourController controller, IBehaviourController.BehaviourAddedArguments args)
{
if (args.BehaviourAdded is not T tBehaviour)
return;
behaviours.Add(tBehaviour);
AddBehaviour(tBehaviour);
OnBehaviourAdd(args.BehaviourAdded);
OnCollected?.Invoke(this, new(tBehaviour));
}