Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed _queryCache to an ordered list #119

Closed
wants to merge 1 commit into from

Conversation

TheyCallMeRyan
Copy link

Proposed changes

The compatibleArchetypes list can become out of order for QueryResults. This makes it skip over entirely valid archetype strings. Changing it from a set to a list can resolve this. Because it already uses the set _entityArchetypeCache to add new archetypes to queryCaches, there's no overhead trying to see if a new archetype has already been added to a queryCache or not.

Related issues

https://discord.com/channels/1234249974959702056/1283058858536992811
(Sorry this isn't a Github Issue, I was expecting to be committing an error myself).

Additional comments

I initially coded this in the current release, which until this worked without issue in my game.

The working version uses a different nextItem() function that in general seems to be erroring for my game, even prior to any changes. I also can't replicate the bug in the new release (but I think this could be due in part to the random erroring); however, the new version of nextItem() still relies on next(compatibleArchetypes) as a set, and it is my intention to resolve this bug and not the other things happening with queryResult.

A potential related issue with the new implementation of nextItem() would be around the removal of optimizeQueries / storage levels:
I may just be misreading the way the storage system is now working, but looking at the new implementation, this would likely happen on the entity level instead of the archetype level as entity archetypes change. E.g. an unordered list of entities {[1] = ..., [8] = ..., [95] = ..., [88] = ...} is not guaranteed to be in order.
This can be seen in use in nextItem() because it uses entityId, entityData = next(storage[currentCompatibleArchetype]). If this data is being modified, I would expect an entity to be removed from the currentCompatibleArchetype and moved to another archetype, causing the ordering next returns to sometimes change randomly.
But this is speculation, and I haven't thoroughly looked into the new storage implementation.

@TheyCallMeRyan
Copy link
Author

Another comment related to the way the new nextItem is implemented - the new version removes the previous hasSeen set to determine if the next value can be returned, so if a query changes the archetype of an entity, a new archetype could be added at the end of compatibleArchetypes, and the same entity could then be queried again. Again, I don't know if the storage[1] has some additional things going on the background I'm unaware of, but if it's just the active world's storage in general, I would expect this.

@memorycode
Copy link
Contributor

Continued in #137.

Thanks for bringing this up!

@memorycode memorycode closed this Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants