using Svelto.Common; using Svelto.DataStructures; namespace Svelto.ECS { /// /// UnsortedEnginesGroup is a practical way to group engines that can be ticked together. As the name suggest /// there is no way to defines an order, although the engines will run in the same order they are added. /// It is abstract and it requires a user defined interface to push the user to use recognisable names meaningful /// to the context where they are used. /// /// user defined interface that implements IStepEngine public abstract class UnsortedEnginesGroup : IStepGroupEngine where Interface : IStepEngine { protected UnsortedEnginesGroup() { _name = "UnsortedEnginesGroup - "+this.GetType().Name; _instancedSequence = new FasterList(); } protected UnsortedEnginesGroup(FasterList engines) { _name = "UnsortedEnginesGroup - "+this.GetType().Name; _instancedSequence = engines; } public void Step() { var sequenceItems = _instancedSequence; using (var profiler = new PlatformProfiler(_name)) { for (var index = 0; index < sequenceItems.count; index++) { var engine = sequenceItems[index]; using (profiler.Sample(engine.name)) engine.Step(); } } } public void Add(Interface engine) { _instancedSequence.Add(engine); } public string name => _name; readonly string _name; readonly FasterList _instancedSequence; } /// /// Similar to UnsortedEnginesGroup except for the fact that an optional parameter can be passed to the engines /// /// /// Specialised Parameter that can be passed to all the engines in the group public abstract class UnsortedEnginesGroup : IStepGroupEngine where Interface : IStepEngine { protected UnsortedEnginesGroup() { _name = "UnsortedEnginesGroup - "+this.GetType().Name; _instancedSequence = new FasterList(); } protected UnsortedEnginesGroup(FasterList engines) { _name = "UnsortedEnginesGroup - "+this.GetType().Name; _instancedSequence = engines; } public void Step(in Parameter param) { var sequenceItems = _instancedSequence; using (var profiler = new PlatformProfiler(_name)) { for (var index = 0; index < sequenceItems.count; index++) { var engine = sequenceItems[index]; using (profiler.Sample(engine.name)) engine.Step(param); } } } public void Add(Interface engine) { _instancedSequence.Add(engine); } public string name => _name; readonly string _name; readonly FasterList _instancedSequence; } }