package ecs
type UnsafeQuery struct {
world *World
table *table
relations []relationID
tables []tableID
filter filter
cursor cursor
lock uint8
}
func (q *UnsafeQuery ) Has (comp ID ) bool {
return q .table .Has (comp )
}
func (q *UnsafeQuery ) GetRelation (comp ID ) Entity {
return q .table .GetRelation (comp )
}
func (q *UnsafeQuery ) Count () int {
return countQuery (&q .world .storage , &q .filter , q .relations , q .world .storage .allArchetypes )
}
func (q *UnsafeQuery ) EntityAt (index int ) Entity {
return entityAt (&q .world .storage , &q .filter , q .relations , q .world .storage .allArchetypes , uint32 (index ))
}
func (q *UnsafeQuery ) IDs () IDs {
return newIDs (q .table .ids )
}
func (q *UnsafeQuery ) Close () {
if q .cursor .table < -1 {
return
}
q .cursor .archetype = -2
q .cursor .table = -2
q .tables = nil
q .table = nil
q .world .unlockSafe (q .lock )
}
func (q *UnsafeQuery ) nextTableOrArchetype () bool {
if q .cursor .archetype >= 0 && q .nextTable () {
return true
}
return q .nextArchetype ()
}
func (q *UnsafeQuery ) nextArchetype () bool {
q .tables = nil
maxArchIndex := int32 (len (q .world .storage .archetypes ) - 1 )
for q .cursor .archetype < maxArchIndex {
q .cursor .archetype ++
archetype := &q .world .storage .archetypes [q .cursor .archetype ]
if !q .filter .matches (&archetype .mask ) {
continue
}
if !archetype .HasRelations () {
table := &q .world .storage .tables [archetype .tables .tables [0 ]]
if table .len > 0 {
q .setTable (0 , table )
return true
}
continue
}
q .tables = archetype .GetTables (q .relations )
q .cursor .table = -1
if q .nextTable () {
return true
}
}
q .Close ()
return false
}
func (q *UnsafeQuery ) nextTable () bool {
maxTableIndex := int32 (len (q .tables ) - 1 )
for q .cursor .table < maxTableIndex {
q .cursor .table ++
table := &q .world .storage .tables [q .tables [q .cursor .table ]]
if table .len == 0 || !table .Matches (q .relations ) {
continue
}
q .setTable (q .cursor .table , table )
return true
}
return false
}
func (q *UnsafeQuery ) setTable (index int32 , table *table ) {
q .cursor .table = index
q .table = table
q .cursor .index = 0
q .cursor .maxIndex = int64 (q .table .len - 1 )
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .