Skip to content

Commit ab8e529

Browse files
committed
IsClosed
1 parent fac626c commit ab8e529

File tree

2 files changed

+121
-1
lines changed

2 files changed

+121
-1
lines changed

ecs/internal/generate/query.go.template

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ func (q *Query{{.}}{{$genericsShort}}) Close() {
129129
q.world.unlockSafe(q.lock)
130130
}
131131

132+
// IsClosed reports whether the query was closed.
133+
//
134+
// A query is considered closed after iteration finishes or Close()
135+
// is called manually. Internally, this is represented by the cursor's
136+
// table index being set to a value less than -1.
137+
//
138+
// Closed queries cannot be iterated and should not be reused.
139+
// Create a new query instead.
140+
func (q *Query{{.}}{{$genericsShort}}) IsClosed() bool {
141+
return q.cursor.table < -1
142+
}
143+
132144
func (q *Query{{.}}{{$genericsShort}}) nextTableOrArchetype() bool {
133145
if q.cache != nil {
134146
return q.nextTable(q.cache.tables.tables)
@@ -155,7 +167,7 @@ func (q *Query{{.}}{{$genericsShort}}) nextArchetype() bool {
155167
for q.cursor.archetype < maxArchIndex {
156168
q.cursor.archetype++
157169
archetype := &q.world.storage.archetypes[archetypes[q.cursor.archetype]]
158-
170+
159171
if !q.filter.matches(&archetype.mask) {
160172
continue
161173
}

ecs/query_gen.go

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)