Added/Changed filters for bevy queries#39
Merged
andreakarasho merged 16 commits intomainfrom May 1, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces updated filtering and query behavior to mimic Bevy’s approach while improving performance when no entities match a query. Key changes include:
- Updates to the query builder and generated filter code with new type constraints and unconditional builder calls.
- Integration of tick tracking in World and Archetype to mark component changes and additions.
- Adjustments to scheduler system interfaces and query parameters across the codebase and sample projects.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tools/TinyEcs.Generator/Program.cs | Modified filter generation code and type constraints in query builders. |
| tests/FilterMatch.cs | Test file refactored (now commented out) to match new filtering APIs. |
| src/World.cs | Added tick tracking and integrated tick updates when modifying components. |
| src/Term.cs, src/Query.cs, src/Ptr.cs, src/Match.cs, src/Archetype.cs | Updated API signatures and internal behaviors to use new types and tick logic. |
| samples/TinyEcsGame/Program.cs, samples/MyBattleground/Program.cs | Updated sample code to reflect scheduler system and query API changes. |
Comments suppressed due to low confidence (6)
samples/MyBattleground/Program.cs:15
- [nitpick] Consider removing unused commented-out code blocks to enhance code readability.
// scheduler.OnUpdate((Query<Data<Position>, Changed<Position>> query) => {
tools/TinyEcs.Generator/Program.cs:82
- Ensure that the unconditional call to 'builder.With<T{j}>();' is intentional, as its removal of the previous conditional check may affect filter inclusion logic.
var queryBuilderCalls = GenerateSequence(i + 1, "\n", j => $"builder.With<T{j}>();");
tools/TinyEcs.Generator/Program.cs:214
- [nitpick] Review the new type constraint 'allows ref struct' to ensure it meets the design requirements for all IFilter implementations.
var genericsArgsWhere = GenerateSequence(i + 1, "\n", j => $"where T{j} : struct, IFilter<T{j}>, allows ref struct");
src/Query.cs:216
- [nitpick] Verify that switching to 'Value.Value' for the data reference assignment preserves the intended pointer arithmetic semantics.
data.Value.Value = ref Unsafe.Add(ref reference, _startSafe);
src/Ptr.cs:50
- [nitpick] Double-check that advancing the pointer using AddByteOffset and assigning to Value.Value maintains the desired behavior.
Value.Value = ref Unsafe.AddByteOffset(ref Value.Ref, Size);
src/Archetype.cs:123
- Confirm that using 'row & Archetype.CHUNK_THRESHOLD' correctly computes the index for marking changes within the chunk layout.
Columns![column].MarkChanged(row & Archetype.CHUNK_THRESHOLD, ticks);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Finally I got it working.
Surprisingly there is not performance loss, it's actually faster once the query returns no entities.
The behaviour is quite close to Bevy. Each system stores a
SystemTickswhich gets updated at the begin/end of a system run.Each
SystemParamget updated throught theLock/Unlockapi.Entity's component changed/added ticks get updated once you do something like:
entity.Set(new Position())for the moment.I'll evaluate an alternative method.
Solves #18