Lets say I am making an RTS with 20 thousand+ units active at any time.
I have figured that I can create entities that act as unit groups; they store shared data between units of that group. The player will interact with these groups instead of individual units, and then the units will do some very basic systems to remain coherent and in formation, etc.
Almost all logic/work needing to be done on these entities (except for player input and translation movement/animation) , including AI does not need to be done every frame. Ideally all of this work can be done withing every second, or within every 60 frames
What if I structures my code by having a seperate component tag for every group, something like:
public struct UnitGroup1: Icompdata
public struct UnitGroup2: Icompdata
Etc…
And then have a JobComponentSystem, with a differentJob struct for each one. During update, based on some int counter, I choose which one to schedule and run.
Performance-wise I see two major benefits.
#1 By having the work done on the units for each group in seperate systems, it makes the work highly multi-threadable.
#2 It allows me to divide up the pathfinding and logic between frames, because in each JobSystem I can just have some int counter and set it so that each job will run one frame after the other. Because I can just filter out all the entities by their tag.
I know for a fact that new groups and units will never be added during a game, because they will be set.
Lets say I have 60 groups per team with 300 units each. This means using my system instead of working on 30 * 300 units every frame, I can work on 1 group each frame meaning within 60 frames I will hit every unit , cutting my work down by 60 times.
This will lead to copy and paste of components and systems (60 times for every new system I want to implement), but I’m willing to do it, if there’s no other way to do this.