-
I'm in the process of working on a core set of entities to our game, where we expect to have enough processing to do to require time slicing, async processing and general scheduling work. One of the approaches I'm investigating (which may or may not be optimal) is having a scheduling processor assign a priority component to these entities, and then sorting using that priority component. Then, in theory, I should be able to time slice work by just processing entities in that priority order and stopping once the time slice has lapsed. But while there's a decent amount of documentation on how to sort components, entities or groups, there's not much in the way of accessing based on that order. One thing I've found is that if I just use the priority component as one component of my view, even if it's the "first" in the declaration, it won't be guaranteed to be in that order:
This makes sense, because the multi-component view doesn't necessarily care or respect order. I believe this could be addressed by making a group including Priority, DataIn and DataOut, but DataIn/DataOut likely will end up with different group requirements as scheduling, so I don't want to lock them into a group at this time. Instead, it seems like my best bet is to access priority using a single component view, and then fetch the data components independently:
I'm aware that ordering being different on Priority and Data means that the order in which Data is accessed might not be the most optimal, but Data here is large enough that I'm more concerned about accessing DataIn and DataOut coherently (i.e.: potentially put them in a group, without Priority) rather than pay the cost of sorting DataIn/DataOut. I'm just looking for a sanity check here, this seems like the "correct" way to go about this? edit: One reason I'm not super fond of this approach is that I have multiple read/write phases over Data that are run in different processors, and I need to filter them based on "tag" components:
Maintaining order in the single-component iteration requires explicitly testing for the tag:
While I'm fairly certain this is essentially what happens behind the scenes anyway in a multiple component view, it just feels... clumsy spelling it out this way vs. having it be an implicit part of the view. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I think what you're looking for is the auto priority_view = Registry.view<const Priority, const DataIn, DataOut>().use<priority>(); // use<T> returns a new view
for (auto [E, P, In, Out] : priority_view.each()) { ... } In this case, entities and components are returned with the order of the |
Beta Was this translation helpful? Give feedback.
I think what you're looking for is the
use<T>
function of the view class:In this case, entities and components are returned with the order of the
Priority
component.