package ecs

// Code generated by go generate; DO NOT EDIT.

import 

type cursor struct {
	archetype int32
	table     int32
	index     uintptr
	maxIndex  int64
}

// Query0 is a query for 0 components.
// Use a [Filter0] to create one.
//
// Queries are one-time use iterators and must be re-created each time before iterating.
//
// See [Query2] for a usage example.
type Query0 struct {
	world       *World
	filter      *filter
	table       *table
	cache       *cacheEntry
	relations   []relationID
	tables      []tableID
	components  []*componentStorage
	cursor      cursor
	lock        uint8
	rareComp    uint8
	hasRareComp bool
}

// Count counts the entities matching this query.
//
// Has some overhead of iterating through archetypes.
// However, this is still much faster than manual counting via iteration.
//
// Does not iterate or close the query.
//
// See [Query2.Count] for an example.
func ( *Query0) () int {
	if .cache == nil {
		if .hasRareComp {
			return countQuery(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp])
		}
		return countQuery(&.world.storage, .filter, .relations, .world.storage.allArchetypes)
	}
	return countQueryCache(&.world.storage, .cache, .relations)
}

// EntityAt returns the entity at a given index.
//
// The method is particularly useful for random sampling of entities from a query.
// However, performance depends on the number of archetypes in the world and in the query.
// In worlds with many archetypes, it is recommended to use a registered/cached filter.
//
// Do not use this to iterate a query! Use [Query0.Next] instead.
//
// Panics if the index is out of range, as indicated by [Query0.Count].
//
// See [Query2.EntityAt] for an example.
func ( *Query0) ( int) Entity {
	if .cache == nil {
		if .hasRareComp {
			return entityAt(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp], uint32())
		}
		return entityAt(&.world.storage, .filter, .relations, .world.storage.allArchetypes, uint32())
	}
	return entityAtCache(&.world.storage, .cache, .relations, uint32())
}

// Close closes the Query and unlocks the world.
//
// Automatically called when iteration completes.
// Needs to be called only if breaking out of the query iteration or not iterating at all.
func ( *Query0) () {
	if .cursor.table < -1 {
		return
	}
	.cursor.archetype = -2
	.cursor.table = -2
	.tables = nil
	.table = nil
	.cache = nil
	.world.unlockSafe(.lock)
}

func ( *Query0) () bool {
	if .cache != nil {
		return .nextTable(.cache.tables.tables)
	}
	if .cursor.archetype >= 0 && .nextTable(.tables) {
		return true
	}
	return .nextArchetype()
}

func ( *Query0) () bool {
	.tables = nil
	var  []archetypeID
	if .hasRareComp {
		 = .world.storage.componentIndex[.rareComp]
	} else {
		 = .world.storage.allArchetypes
	}
	 := int32(len() - 1)
	for .cursor.archetype <  {
		.cursor.archetype++
		 := &.world.storage.archetypes[[.cursor.archetype]]

		if !.filter.matches(&.mask) {
			continue
		}

		if !.HasRelations() {
			 := &.world.storage.tables[.tables.tables[0]]
			if .len > 0 {
				.setTable(0, )
				return true
			}
			continue
		}

		.tables = .GetTables(.relations)
		.cursor.table = -1
		if .nextTable(.tables) {
			return true
		}
	}
	.Close()
	return false
}

func ( *Query0) ( []tableID) bool {
	 := int32(len() - 1)
	for .cursor.table <  {
		.cursor.table++
		 := &.world.storage.tables[[.cursor.table]]
		if .len == 0 || !.Matches(.relations) {
			continue
		}
		.setTable(.cursor.table, )
		return true
	}
	if .cache != nil {
		.Close()
	}
	return false
}

func ( *Query0) ( int32,  *table) {
	.cursor.table = 
	.table = 
	.cursor.index = 0
	.cursor.maxIndex = int64(.table.len - 1)
}

// Query1 is a query for 1 components.
// Use a [Filter1] to create one.
//
// Queries are one-time use iterators and must be re-created each time before iterating.
//
// See [Query2] for a usage example.
type Query1[ any] struct {
	world      *World
	filter     *filter
	table      *table
	cache      *cacheEntry
	columnA    *column
	columnPtrA unsafe.Pointer
	itemSizeA  uintptr
	relations  []relationID
	tables     []tableID
	components []*componentStorage
	cursor     cursor
	lock       uint8
	rareComp   uint8
}

// GetRelation returns the entity relation target of the component at the given index.
//
// Can be used for the current entity in entity-based iteration,
// as well as for the entire current table in table-based iteration.
func ( *Query1[]) ( int) Entity {
	return .components[].columns[.table.id].target
}

// Count counts the entities matching this query.
//
// Has some overhead of iterating through archetypes.
// However, this is still much faster than manual counting via iteration.
//
// Does not iterate or close the query.
//
// See [Query2.Count] for an example.
func ( *Query1[]) () int {
	if .cache == nil {
		return countQuery(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp])
	}
	return countQueryCache(&.world.storage, .cache, .relations)
}

// EntityAt returns the entity at a given index.
//
// The method is particularly useful for random sampling of entities from a query.
// However, performance depends on the number of archetypes in the world and in the query.
// In worlds with many archetypes, it is recommended to use a registered/cached filter.
//
// Do not use this to iterate a query! Use [Query1.Next] instead.
//
// Panics if the index is out of range, as indicated by [Query1.Count].
//
// See [Query2.EntityAt] for an example.
func ( *Query1[]) ( int) Entity {
	if .cache == nil {
		return entityAt(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp], uint32())
	}
	return entityAtCache(&.world.storage, .cache, .relations, uint32())
}

// Close closes the Query and unlocks the world.
//
// Automatically called when iteration completes.
// Needs to be called only if breaking out of the query iteration or not iterating at all.
func ( *Query1[]) () {
	if .cursor.table < -1 {
		return
	}
	.cursor.archetype = -2
	.cursor.table = -2
	.tables = nil
	.table = nil
	.cache = nil
	.columnA = nil
	.columnPtrA = unsafe.Pointer(nilDummy)
	.itemSizeA = 0
	.world.unlockSafe(.lock)
}

func ( *Query1[]) () bool {
	if .cache != nil {
		return .nextTable(.cache.tables.tables)
	}
	if .cursor.archetype >= 0 && .nextTable(.tables) {
		return true
	}
	return .nextArchetype()
}

func ( *Query1[]) () bool {
	.tables = nil
	 := .world.storage.componentIndex[.rareComp]
	 := int32(len() - 1)
	for .cursor.archetype <  {
		.cursor.archetype++
		 := &.world.storage.archetypes[[.cursor.archetype]]

		if !.filter.matches(&.mask) {
			continue
		}

		if !.HasRelations() {
			 := &.world.storage.tables[.tables.tables[0]]
			if .len > 0 {
				.setTable(0, )
				return true
			}
			continue
		}

		.tables = .GetTables(.relations)
		.cursor.table = -1
		if .nextTable(.tables) {
			return true
		}
	}
	.Close()
	return false
}

func ( *Query1[]) ( []tableID) bool {
	 := int32(len() - 1)
	for .cursor.table <  {
		.cursor.table++
		 := &.world.storage.tables[[.cursor.table]]
		if .len == 0 || !.Matches(.relations) {
			continue
		}
		.setTable(.cursor.table, )
		return true
	}
	if .cache != nil {
		.Close()
	}
	return false
}

func ( *Query1[]) ( int32,  *table) {
	.cursor.table = 
	.table = 
	.columnA = .components[0].columns[.table.id]
	.columnPtrA = .columnA.pointer
	.itemSizeA = .columnA.itemSize
	.cursor.index = 0
	.cursor.maxIndex = int64(.table.len - 1)
}

// Query2 is a query for 2 components.
// Use a [Filter2] to create one.
//
// Queries are one-time use iterators and must be re-created each time before iterating.
type Query2[ any,  any] struct {
	world      *World
	filter     *filter
	table      *table
	cache      *cacheEntry
	columnA    *column
	columnPtrA unsafe.Pointer
	itemSizeA  uintptr
	columnB    *column
	columnPtrB unsafe.Pointer
	itemSizeB  uintptr
	relations  []relationID
	tables     []tableID
	components []*componentStorage
	cursor     cursor
	lock       uint8
	rareComp   uint8
}

// GetRelation returns the entity relation target of the component at the given index.
//
// Can be used for the current entity in entity-based iteration,
// as well as for the entire current table in table-based iteration.
func ( *Query2[, ]) ( int) Entity {
	return .components[].columns[.table.id].target
}

// Count counts the entities matching this query.
//
// Has some overhead of iterating through archetypes.
// However, this is still much faster than manual counting via iteration.
//
// Does not iterate or close the query.
func ( *Query2[, ]) () int {
	if .cache == nil {
		return countQuery(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp])
	}
	return countQueryCache(&.world.storage, .cache, .relations)
}

// EntityAt returns the entity at a given index.
//
// The method is particularly useful for random sampling of entities from a query.
// However, performance depends on the number of archetypes in the world and in the query.
// In worlds with many archetypes, it is recommended to use a registered/cached filter.
//
// Do not use this to iterate a query! Use [Query2.Next] instead.
//
// Panics if the index is out of range, as indicated by [Query2.Count].
func ( *Query2[, ]) ( int) Entity {
	if .cache == nil {
		return entityAt(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp], uint32())
	}
	return entityAtCache(&.world.storage, .cache, .relations, uint32())
}

// Close closes the Query and unlocks the world.
//
// Automatically called when iteration completes.
// Needs to be called only if breaking out of the query iteration or not iterating at all.
func ( *Query2[, ]) () {
	if .cursor.table < -1 {
		return
	}
	.cursor.archetype = -2
	.cursor.table = -2
	.tables = nil
	.table = nil
	.cache = nil
	.columnA = nil
	.columnPtrA = unsafe.Pointer(nilDummy)
	.itemSizeA = 0
	.columnB = nil
	.columnPtrB = unsafe.Pointer(nilDummy)
	.itemSizeB = 0
	.world.unlockSafe(.lock)
}

func ( *Query2[, ]) () bool {
	if .cache != nil {
		return .nextTable(.cache.tables.tables)
	}
	if .cursor.archetype >= 0 && .nextTable(.tables) {
		return true
	}
	return .nextArchetype()
}

func ( *Query2[, ]) () bool {
	.tables = nil
	 := .world.storage.componentIndex[.rareComp]
	 := int32(len() - 1)
	for .cursor.archetype <  {
		.cursor.archetype++
		 := &.world.storage.archetypes[[.cursor.archetype]]

		if !.filter.matches(&.mask) {
			continue
		}

		if !.HasRelations() {
			 := &.world.storage.tables[.tables.tables[0]]
			if .len > 0 {
				.setTable(0, )
				return true
			}
			continue
		}

		.tables = .GetTables(.relations)
		.cursor.table = -1
		if .nextTable(.tables) {
			return true
		}
	}
	.Close()
	return false
}

func ( *Query2[, ]) ( []tableID) bool {
	 := int32(len() - 1)
	for .cursor.table <  {
		.cursor.table++
		 := &.world.storage.tables[[.cursor.table]]
		if .len == 0 || !.Matches(.relations) {
			continue
		}
		.setTable(.cursor.table, )
		return true
	}
	if .cache != nil {
		.Close()
	}
	return false
}

func ( *Query2[, ]) ( int32,  *table) {
	.cursor.table = 
	.table = 
	.columnA = .components[0].columns[.table.id]
	.columnPtrA = .columnA.pointer
	.itemSizeA = .columnA.itemSize
	.columnB = .components[1].columns[.table.id]
	.columnPtrB = .columnB.pointer
	.itemSizeB = .columnB.itemSize
	.cursor.index = 0
	.cursor.maxIndex = int64(.table.len - 1)
}

// Query3 is a query for 3 components.
// Use a [Filter3] to create one.
//
// Queries are one-time use iterators and must be re-created each time before iterating.
//
// See [Query2] for a usage example.
type Query3[ any,  any,  any] struct {
	world      *World
	filter     *filter
	table      *table
	cache      *cacheEntry
	columnA    *column
	columnPtrA unsafe.Pointer
	itemSizeA  uintptr
	columnB    *column
	columnPtrB unsafe.Pointer
	itemSizeB  uintptr
	columnC    *column
	columnPtrC unsafe.Pointer
	itemSizeC  uintptr
	relations  []relationID
	tables     []tableID
	components []*componentStorage
	cursor     cursor
	lock       uint8
	rareComp   uint8
}

// GetRelation returns the entity relation target of the component at the given index.
//
// Can be used for the current entity in entity-based iteration,
// as well as for the entire current table in table-based iteration.
func ( *Query3[, , ]) ( int) Entity {
	return .components[].columns[.table.id].target
}

// Count counts the entities matching this query.
//
// Has some overhead of iterating through archetypes.
// However, this is still much faster than manual counting via iteration.
//
// Does not iterate or close the query.
//
// See [Query2.Count] for an example.
func ( *Query3[, , ]) () int {
	if .cache == nil {
		return countQuery(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp])
	}
	return countQueryCache(&.world.storage, .cache, .relations)
}

// EntityAt returns the entity at a given index.
//
// The method is particularly useful for random sampling of entities from a query.
// However, performance depends on the number of archetypes in the world and in the query.
// In worlds with many archetypes, it is recommended to use a registered/cached filter.
//
// Do not use this to iterate a query! Use [Query3.Next] instead.
//
// Panics if the index is out of range, as indicated by [Query3.Count].
//
// See [Query2.EntityAt] for an example.
func ( *Query3[, , ]) ( int) Entity {
	if .cache == nil {
		return entityAt(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp], uint32())
	}
	return entityAtCache(&.world.storage, .cache, .relations, uint32())
}

// Close closes the Query and unlocks the world.
//
// Automatically called when iteration completes.
// Needs to be called only if breaking out of the query iteration or not iterating at all.
func ( *Query3[, , ]) () {
	if .cursor.table < -1 {
		return
	}
	.cursor.archetype = -2
	.cursor.table = -2
	.tables = nil
	.table = nil
	.cache = nil
	.columnA = nil
	.columnPtrA = unsafe.Pointer(nilDummy)
	.itemSizeA = 0
	.columnB = nil
	.columnPtrB = unsafe.Pointer(nilDummy)
	.itemSizeB = 0
	.columnC = nil
	.columnPtrC = unsafe.Pointer(nilDummy)
	.itemSizeC = 0
	.world.unlockSafe(.lock)
}

func ( *Query3[, , ]) () bool {
	if .cache != nil {
		return .nextTable(.cache.tables.tables)
	}
	if .cursor.archetype >= 0 && .nextTable(.tables) {
		return true
	}
	return .nextArchetype()
}

func ( *Query3[, , ]) () bool {
	.tables = nil
	 := .world.storage.componentIndex[.rareComp]
	 := int32(len() - 1)
	for .cursor.archetype <  {
		.cursor.archetype++
		 := &.world.storage.archetypes[[.cursor.archetype]]

		if !.filter.matches(&.mask) {
			continue
		}

		if !.HasRelations() {
			 := &.world.storage.tables[.tables.tables[0]]
			if .len > 0 {
				.setTable(0, )
				return true
			}
			continue
		}

		.tables = .GetTables(.relations)
		.cursor.table = -1
		if .nextTable(.tables) {
			return true
		}
	}
	.Close()
	return false
}

func ( *Query3[, , ]) ( []tableID) bool {
	 := int32(len() - 1)
	for .cursor.table <  {
		.cursor.table++
		 := &.world.storage.tables[[.cursor.table]]
		if .len == 0 || !.Matches(.relations) {
			continue
		}
		.setTable(.cursor.table, )
		return true
	}
	if .cache != nil {
		.Close()
	}
	return false
}

func ( *Query3[, , ]) ( int32,  *table) {
	.cursor.table = 
	.table = 
	.columnA = .components[0].columns[.table.id]
	.columnPtrA = .columnA.pointer
	.itemSizeA = .columnA.itemSize
	.columnB = .components[1].columns[.table.id]
	.columnPtrB = .columnB.pointer
	.itemSizeB = .columnB.itemSize
	.columnC = .components[2].columns[.table.id]
	.columnPtrC = .columnC.pointer
	.itemSizeC = .columnC.itemSize
	.cursor.index = 0
	.cursor.maxIndex = int64(.table.len - 1)
}

// Query4 is a query for 4 components.
// Use a [Filter4] to create one.
//
// Queries are one-time use iterators and must be re-created each time before iterating.
//
// See [Query2] for a usage example.
type Query4[ any,  any,  any,  any] struct {
	world      *World
	filter     *filter
	table      *table
	cache      *cacheEntry
	columnA    *column
	columnPtrA unsafe.Pointer
	itemSizeA  uintptr
	columnB    *column
	columnPtrB unsafe.Pointer
	itemSizeB  uintptr
	columnC    *column
	columnPtrC unsafe.Pointer
	itemSizeC  uintptr
	columnD    *column
	columnPtrD unsafe.Pointer
	itemSizeD  uintptr
	relations  []relationID
	tables     []tableID
	components []*componentStorage
	cursor     cursor
	lock       uint8
	rareComp   uint8
}

// GetRelation returns the entity relation target of the component at the given index.
//
// Can be used for the current entity in entity-based iteration,
// as well as for the entire current table in table-based iteration.
func ( *Query4[, , , ]) ( int) Entity {
	return .components[].columns[.table.id].target
}

// Count counts the entities matching this query.
//
// Has some overhead of iterating through archetypes.
// However, this is still much faster than manual counting via iteration.
//
// Does not iterate or close the query.
//
// See [Query2.Count] for an example.
func ( *Query4[, , , ]) () int {
	if .cache == nil {
		return countQuery(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp])
	}
	return countQueryCache(&.world.storage, .cache, .relations)
}

// EntityAt returns the entity at a given index.
//
// The method is particularly useful for random sampling of entities from a query.
// However, performance depends on the number of archetypes in the world and in the query.
// In worlds with many archetypes, it is recommended to use a registered/cached filter.
//
// Do not use this to iterate a query! Use [Query4.Next] instead.
//
// Panics if the index is out of range, as indicated by [Query4.Count].
//
// See [Query2.EntityAt] for an example.
func ( *Query4[, , , ]) ( int) Entity {
	if .cache == nil {
		return entityAt(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp], uint32())
	}
	return entityAtCache(&.world.storage, .cache, .relations, uint32())
}

// Close closes the Query and unlocks the world.
//
// Automatically called when iteration completes.
// Needs to be called only if breaking out of the query iteration or not iterating at all.
func ( *Query4[, , , ]) () {
	if .cursor.table < -1 {
		return
	}
	.cursor.archetype = -2
	.cursor.table = -2
	.tables = nil
	.table = nil
	.cache = nil
	.columnA = nil
	.columnPtrA = unsafe.Pointer(nilDummy)
	.itemSizeA = 0
	.columnB = nil
	.columnPtrB = unsafe.Pointer(nilDummy)
	.itemSizeB = 0
	.columnC = nil
	.columnPtrC = unsafe.Pointer(nilDummy)
	.itemSizeC = 0
	.columnD = nil
	.columnPtrD = unsafe.Pointer(nilDummy)
	.itemSizeD = 0
	.world.unlockSafe(.lock)
}

func ( *Query4[, , , ]) () bool {
	if .cache != nil {
		return .nextTable(.cache.tables.tables)
	}
	if .cursor.archetype >= 0 && .nextTable(.tables) {
		return true
	}
	return .nextArchetype()
}

func ( *Query4[, , , ]) () bool {
	.tables = nil
	 := .world.storage.componentIndex[.rareComp]
	 := int32(len() - 1)
	for .cursor.archetype <  {
		.cursor.archetype++
		 := &.world.storage.archetypes[[.cursor.archetype]]

		if !.filter.matches(&.mask) {
			continue
		}

		if !.HasRelations() {
			 := &.world.storage.tables[.tables.tables[0]]
			if .len > 0 {
				.setTable(0, )
				return true
			}
			continue
		}

		.tables = .GetTables(.relations)
		.cursor.table = -1
		if .nextTable(.tables) {
			return true
		}
	}
	.Close()
	return false
}

func ( *Query4[, , , ]) ( []tableID) bool {
	 := int32(len() - 1)
	for .cursor.table <  {
		.cursor.table++
		 := &.world.storage.tables[[.cursor.table]]
		if .len == 0 || !.Matches(.relations) {
			continue
		}
		.setTable(.cursor.table, )
		return true
	}
	if .cache != nil {
		.Close()
	}
	return false
}

func ( *Query4[, , , ]) ( int32,  *table) {
	.cursor.table = 
	.table = 
	.columnA = .components[0].columns[.table.id]
	.columnPtrA = .columnA.pointer
	.itemSizeA = .columnA.itemSize
	.columnB = .components[1].columns[.table.id]
	.columnPtrB = .columnB.pointer
	.itemSizeB = .columnB.itemSize
	.columnC = .components[2].columns[.table.id]
	.columnPtrC = .columnC.pointer
	.itemSizeC = .columnC.itemSize
	.columnD = .components[3].columns[.table.id]
	.columnPtrD = .columnD.pointer
	.itemSizeD = .columnD.itemSize
	.cursor.index = 0
	.cursor.maxIndex = int64(.table.len - 1)
}

// Query5 is a query for 5 components.
// Use a [Filter5] to create one.
//
// Queries are one-time use iterators and must be re-created each time before iterating.
//
// See [Query2] for a usage example.
type Query5[ any,  any,  any,  any,  any] struct {
	world      *World
	filter     *filter
	table      *table
	cache      *cacheEntry
	columnA    *column
	columnPtrA unsafe.Pointer
	itemSizeA  uintptr
	columnB    *column
	columnPtrB unsafe.Pointer
	itemSizeB  uintptr
	columnC    *column
	columnPtrC unsafe.Pointer
	itemSizeC  uintptr
	columnD    *column
	columnPtrD unsafe.Pointer
	itemSizeD  uintptr
	columnE    *column
	columnPtrE unsafe.Pointer
	itemSizeE  uintptr
	relations  []relationID
	tables     []tableID
	components []*componentStorage
	cursor     cursor
	lock       uint8
	rareComp   uint8
}

// GetRelation returns the entity relation target of the component at the given index.
//
// Can be used for the current entity in entity-based iteration,
// as well as for the entire current table in table-based iteration.
func ( *Query5[, , , , ]) ( int) Entity {
	return .components[].columns[.table.id].target
}

// Count counts the entities matching this query.
//
// Has some overhead of iterating through archetypes.
// However, this is still much faster than manual counting via iteration.
//
// Does not iterate or close the query.
//
// See [Query2.Count] for an example.
func ( *Query5[, , , , ]) () int {
	if .cache == nil {
		return countQuery(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp])
	}
	return countQueryCache(&.world.storage, .cache, .relations)
}

// EntityAt returns the entity at a given index.
//
// The method is particularly useful for random sampling of entities from a query.
// However, performance depends on the number of archetypes in the world and in the query.
// In worlds with many archetypes, it is recommended to use a registered/cached filter.
//
// Do not use this to iterate a query! Use [Query5.Next] instead.
//
// Panics if the index is out of range, as indicated by [Query5.Count].
//
// See [Query2.EntityAt] for an example.
func ( *Query5[, , , , ]) ( int) Entity {
	if .cache == nil {
		return entityAt(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp], uint32())
	}
	return entityAtCache(&.world.storage, .cache, .relations, uint32())
}

// Close closes the Query and unlocks the world.
//
// Automatically called when iteration completes.
// Needs to be called only if breaking out of the query iteration or not iterating at all.
func ( *Query5[, , , , ]) () {
	if .cursor.table < -1 {
		return
	}
	.cursor.archetype = -2
	.cursor.table = -2
	.tables = nil
	.table = nil
	.cache = nil
	.columnA = nil
	.columnPtrA = unsafe.Pointer(nilDummy)
	.itemSizeA = 0
	.columnB = nil
	.columnPtrB = unsafe.Pointer(nilDummy)
	.itemSizeB = 0
	.columnC = nil
	.columnPtrC = unsafe.Pointer(nilDummy)
	.itemSizeC = 0
	.columnD = nil
	.columnPtrD = unsafe.Pointer(nilDummy)
	.itemSizeD = 0
	.columnE = nil
	.columnPtrE = unsafe.Pointer(nilDummy)
	.itemSizeE = 0
	.world.unlockSafe(.lock)
}

func ( *Query5[, , , , ]) () bool {
	if .cache != nil {
		return .nextTable(.cache.tables.tables)
	}
	if .cursor.archetype >= 0 && .nextTable(.tables) {
		return true
	}
	return .nextArchetype()
}

func ( *Query5[, , , , ]) () bool {
	.tables = nil
	 := .world.storage.componentIndex[.rareComp]
	 := int32(len() - 1)
	for .cursor.archetype <  {
		.cursor.archetype++
		 := &.world.storage.archetypes[[.cursor.archetype]]

		if !.filter.matches(&.mask) {
			continue
		}

		if !.HasRelations() {
			 := &.world.storage.tables[.tables.tables[0]]
			if .len > 0 {
				.setTable(0, )
				return true
			}
			continue
		}

		.tables = .GetTables(.relations)
		.cursor.table = -1
		if .nextTable(.tables) {
			return true
		}
	}
	.Close()
	return false
}

func ( *Query5[, , , , ]) ( []tableID) bool {
	 := int32(len() - 1)
	for .cursor.table <  {
		.cursor.table++
		 := &.world.storage.tables[[.cursor.table]]
		if .len == 0 || !.Matches(.relations) {
			continue
		}
		.setTable(.cursor.table, )
		return true
	}
	if .cache != nil {
		.Close()
	}
	return false
}

func ( *Query5[, , , , ]) ( int32,  *table) {
	.cursor.table = 
	.table = 
	.columnA = .components[0].columns[.table.id]
	.columnPtrA = .columnA.pointer
	.itemSizeA = .columnA.itemSize
	.columnB = .components[1].columns[.table.id]
	.columnPtrB = .columnB.pointer
	.itemSizeB = .columnB.itemSize
	.columnC = .components[2].columns[.table.id]
	.columnPtrC = .columnC.pointer
	.itemSizeC = .columnC.itemSize
	.columnD = .components[3].columns[.table.id]
	.columnPtrD = .columnD.pointer
	.itemSizeD = .columnD.itemSize
	.columnE = .components[4].columns[.table.id]
	.columnPtrE = .columnE.pointer
	.itemSizeE = .columnE.itemSize
	.cursor.index = 0
	.cursor.maxIndex = int64(.table.len - 1)
}

// Query6 is a query for 6 components.
// Use a [Filter6] to create one.
//
// Queries are one-time use iterators and must be re-created each time before iterating.
//
// See [Query2] for a usage example.
type Query6[ any,  any,  any,  any,  any,  any] struct {
	world      *World
	filter     *filter
	table      *table
	cache      *cacheEntry
	columnA    *column
	columnPtrA unsafe.Pointer
	itemSizeA  uintptr
	columnB    *column
	columnPtrB unsafe.Pointer
	itemSizeB  uintptr
	columnC    *column
	columnPtrC unsafe.Pointer
	itemSizeC  uintptr
	columnD    *column
	columnPtrD unsafe.Pointer
	itemSizeD  uintptr
	columnE    *column
	columnPtrE unsafe.Pointer
	itemSizeE  uintptr
	columnF    *column
	columnPtrF unsafe.Pointer
	itemSizeF  uintptr
	relations  []relationID
	tables     []tableID
	components []*componentStorage
	cursor     cursor
	lock       uint8
	rareComp   uint8
}

// GetRelation returns the entity relation target of the component at the given index.
//
// Can be used for the current entity in entity-based iteration,
// as well as for the entire current table in table-based iteration.
func ( *Query6[, , , , , ]) ( int) Entity {
	return .components[].columns[.table.id].target
}

// Count counts the entities matching this query.
//
// Has some overhead of iterating through archetypes.
// However, this is still much faster than manual counting via iteration.
//
// Does not iterate or close the query.
//
// See [Query2.Count] for an example.
func ( *Query6[, , , , , ]) () int {
	if .cache == nil {
		return countQuery(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp])
	}
	return countQueryCache(&.world.storage, .cache, .relations)
}

// EntityAt returns the entity at a given index.
//
// The method is particularly useful for random sampling of entities from a query.
// However, performance depends on the number of archetypes in the world and in the query.
// In worlds with many archetypes, it is recommended to use a registered/cached filter.
//
// Do not use this to iterate a query! Use [Query6.Next] instead.
//
// Panics if the index is out of range, as indicated by [Query6.Count].
//
// See [Query2.EntityAt] for an example.
func ( *Query6[, , , , , ]) ( int) Entity {
	if .cache == nil {
		return entityAt(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp], uint32())
	}
	return entityAtCache(&.world.storage, .cache, .relations, uint32())
}

// Close closes the Query and unlocks the world.
//
// Automatically called when iteration completes.
// Needs to be called only if breaking out of the query iteration or not iterating at all.
func ( *Query6[, , , , , ]) () {
	if .cursor.table < -1 {
		return
	}
	.cursor.archetype = -2
	.cursor.table = -2
	.tables = nil
	.table = nil
	.cache = nil
	.columnA = nil
	.columnPtrA = unsafe.Pointer(nilDummy)
	.itemSizeA = 0
	.columnB = nil
	.columnPtrB = unsafe.Pointer(nilDummy)
	.itemSizeB = 0
	.columnC = nil
	.columnPtrC = unsafe.Pointer(nilDummy)
	.itemSizeC = 0
	.columnD = nil
	.columnPtrD = unsafe.Pointer(nilDummy)
	.itemSizeD = 0
	.columnE = nil
	.columnPtrE = unsafe.Pointer(nilDummy)
	.itemSizeE = 0
	.columnF = nil
	.columnPtrF = unsafe.Pointer(nilDummy)
	.itemSizeF = 0
	.world.unlockSafe(.lock)
}

func ( *Query6[, , , , , ]) () bool {
	if .cache != nil {
		return .nextTable(.cache.tables.tables)
	}
	if .cursor.archetype >= 0 && .nextTable(.tables) {
		return true
	}
	return .nextArchetype()
}

func ( *Query6[, , , , , ]) () bool {
	.tables = nil
	 := .world.storage.componentIndex[.rareComp]
	 := int32(len() - 1)
	for .cursor.archetype <  {
		.cursor.archetype++
		 := &.world.storage.archetypes[[.cursor.archetype]]

		if !.filter.matches(&.mask) {
			continue
		}

		if !.HasRelations() {
			 := &.world.storage.tables[.tables.tables[0]]
			if .len > 0 {
				.setTable(0, )
				return true
			}
			continue
		}

		.tables = .GetTables(.relations)
		.cursor.table = -1
		if .nextTable(.tables) {
			return true
		}
	}
	.Close()
	return false
}

func ( *Query6[, , , , , ]) ( []tableID) bool {
	 := int32(len() - 1)
	for .cursor.table <  {
		.cursor.table++
		 := &.world.storage.tables[[.cursor.table]]
		if .len == 0 || !.Matches(.relations) {
			continue
		}
		.setTable(.cursor.table, )
		return true
	}
	if .cache != nil {
		.Close()
	}
	return false
}

func ( *Query6[, , , , , ]) ( int32,  *table) {
	.cursor.table = 
	.table = 
	.columnA = .components[0].columns[.table.id]
	.columnPtrA = .columnA.pointer
	.itemSizeA = .columnA.itemSize
	.columnB = .components[1].columns[.table.id]
	.columnPtrB = .columnB.pointer
	.itemSizeB = .columnB.itemSize
	.columnC = .components[2].columns[.table.id]
	.columnPtrC = .columnC.pointer
	.itemSizeC = .columnC.itemSize
	.columnD = .components[3].columns[.table.id]
	.columnPtrD = .columnD.pointer
	.itemSizeD = .columnD.itemSize
	.columnE = .components[4].columns[.table.id]
	.columnPtrE = .columnE.pointer
	.itemSizeE = .columnE.itemSize
	.columnF = .components[5].columns[.table.id]
	.columnPtrF = .columnF.pointer
	.itemSizeF = .columnF.itemSize
	.cursor.index = 0
	.cursor.maxIndex = int64(.table.len - 1)
}

// Query7 is a query for 7 components.
// Use a [Filter7] to create one.
//
// Queries are one-time use iterators and must be re-created each time before iterating.
//
// See [Query2] for a usage example.
type Query7[ any,  any,  any,  any,  any,  any,  any] struct {
	world      *World
	filter     *filter
	table      *table
	cache      *cacheEntry
	columnA    *column
	columnPtrA unsafe.Pointer
	itemSizeA  uintptr
	columnB    *column
	columnPtrB unsafe.Pointer
	itemSizeB  uintptr
	columnC    *column
	columnPtrC unsafe.Pointer
	itemSizeC  uintptr
	columnD    *column
	columnPtrD unsafe.Pointer
	itemSizeD  uintptr
	columnE    *column
	columnPtrE unsafe.Pointer
	itemSizeE  uintptr
	columnF    *column
	columnPtrF unsafe.Pointer
	itemSizeF  uintptr
	columnG    *column
	columnPtrG unsafe.Pointer
	itemSizeG  uintptr
	relations  []relationID
	tables     []tableID
	components []*componentStorage
	cursor     cursor
	lock       uint8
	rareComp   uint8
}

// GetRelation returns the entity relation target of the component at the given index.
//
// Can be used for the current entity in entity-based iteration,
// as well as for the entire current table in table-based iteration.
func ( *Query7[, , , , , , ]) ( int) Entity {
	return .components[].columns[.table.id].target
}

// Count counts the entities matching this query.
//
// Has some overhead of iterating through archetypes.
// However, this is still much faster than manual counting via iteration.
//
// Does not iterate or close the query.
//
// See [Query2.Count] for an example.
func ( *Query7[, , , , , , ]) () int {
	if .cache == nil {
		return countQuery(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp])
	}
	return countQueryCache(&.world.storage, .cache, .relations)
}

// EntityAt returns the entity at a given index.
//
// The method is particularly useful for random sampling of entities from a query.
// However, performance depends on the number of archetypes in the world and in the query.
// In worlds with many archetypes, it is recommended to use a registered/cached filter.
//
// Do not use this to iterate a query! Use [Query7.Next] instead.
//
// Panics if the index is out of range, as indicated by [Query7.Count].
//
// See [Query2.EntityAt] for an example.
func ( *Query7[, , , , , , ]) ( int) Entity {
	if .cache == nil {
		return entityAt(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp], uint32())
	}
	return entityAtCache(&.world.storage, .cache, .relations, uint32())
}

// Close closes the Query and unlocks the world.
//
// Automatically called when iteration completes.
// Needs to be called only if breaking out of the query iteration or not iterating at all.
func ( *Query7[, , , , , , ]) () {
	if .cursor.table < -1 {
		return
	}
	.cursor.archetype = -2
	.cursor.table = -2
	.tables = nil
	.table = nil
	.cache = nil
	.columnA = nil
	.columnPtrA = unsafe.Pointer(nilDummy)
	.itemSizeA = 0
	.columnB = nil
	.columnPtrB = unsafe.Pointer(nilDummy)
	.itemSizeB = 0
	.columnC = nil
	.columnPtrC = unsafe.Pointer(nilDummy)
	.itemSizeC = 0
	.columnD = nil
	.columnPtrD = unsafe.Pointer(nilDummy)
	.itemSizeD = 0
	.columnE = nil
	.columnPtrE = unsafe.Pointer(nilDummy)
	.itemSizeE = 0
	.columnF = nil
	.columnPtrF = unsafe.Pointer(nilDummy)
	.itemSizeF = 0
	.columnG = nil
	.columnPtrG = unsafe.Pointer(nilDummy)
	.itemSizeG = 0
	.world.unlockSafe(.lock)
}

func ( *Query7[, , , , , , ]) () bool {
	if .cache != nil {
		return .nextTable(.cache.tables.tables)
	}
	if .cursor.archetype >= 0 && .nextTable(.tables) {
		return true
	}
	return .nextArchetype()
}

func ( *Query7[, , , , , , ]) () bool {
	.tables = nil
	 := .world.storage.componentIndex[.rareComp]
	 := int32(len() - 1)
	for .cursor.archetype <  {
		.cursor.archetype++
		 := &.world.storage.archetypes[[.cursor.archetype]]

		if !.filter.matches(&.mask) {
			continue
		}

		if !.HasRelations() {
			 := &.world.storage.tables[.tables.tables[0]]
			if .len > 0 {
				.setTable(0, )
				return true
			}
			continue
		}

		.tables = .GetTables(.relations)
		.cursor.table = -1
		if .nextTable(.tables) {
			return true
		}
	}
	.Close()
	return false
}

func ( *Query7[, , , , , , ]) ( []tableID) bool {
	 := int32(len() - 1)
	for .cursor.table <  {
		.cursor.table++
		 := &.world.storage.tables[[.cursor.table]]
		if .len == 0 || !.Matches(.relations) {
			continue
		}
		.setTable(.cursor.table, )
		return true
	}
	if .cache != nil {
		.Close()
	}
	return false
}

func ( *Query7[, , , , , , ]) ( int32,  *table) {
	.cursor.table = 
	.table = 
	.columnA = .components[0].columns[.table.id]
	.columnPtrA = .columnA.pointer
	.itemSizeA = .columnA.itemSize
	.columnB = .components[1].columns[.table.id]
	.columnPtrB = .columnB.pointer
	.itemSizeB = .columnB.itemSize
	.columnC = .components[2].columns[.table.id]
	.columnPtrC = .columnC.pointer
	.itemSizeC = .columnC.itemSize
	.columnD = .components[3].columns[.table.id]
	.columnPtrD = .columnD.pointer
	.itemSizeD = .columnD.itemSize
	.columnE = .components[4].columns[.table.id]
	.columnPtrE = .columnE.pointer
	.itemSizeE = .columnE.itemSize
	.columnF = .components[5].columns[.table.id]
	.columnPtrF = .columnF.pointer
	.itemSizeF = .columnF.itemSize
	.columnG = .components[6].columns[.table.id]
	.columnPtrG = .columnG.pointer
	.itemSizeG = .columnG.itemSize
	.cursor.index = 0
	.cursor.maxIndex = int64(.table.len - 1)
}

// Query8 is a query for 8 components.
// Use a [Filter8] to create one.
//
// Queries are one-time use iterators and must be re-created each time before iterating.
//
// See [Query2] for a usage example.
type Query8[ any,  any,  any,  any,  any,  any,  any,  any] struct {
	world      *World
	filter     *filter
	table      *table
	cache      *cacheEntry
	columnA    *column
	columnPtrA unsafe.Pointer
	itemSizeA  uintptr
	columnB    *column
	columnPtrB unsafe.Pointer
	itemSizeB  uintptr
	columnC    *column
	columnPtrC unsafe.Pointer
	itemSizeC  uintptr
	columnD    *column
	columnPtrD unsafe.Pointer
	itemSizeD  uintptr
	columnE    *column
	columnPtrE unsafe.Pointer
	itemSizeE  uintptr
	columnF    *column
	columnPtrF unsafe.Pointer
	itemSizeF  uintptr
	columnG    *column
	columnPtrG unsafe.Pointer
	itemSizeG  uintptr
	columnH    *column
	columnPtrH unsafe.Pointer
	itemSizeH  uintptr
	relations  []relationID
	tables     []tableID
	components []*componentStorage
	cursor     cursor
	lock       uint8
	rareComp   uint8
}

// GetRelation returns the entity relation target of the component at the given index.
//
// Can be used for the current entity in entity-based iteration,
// as well as for the entire current table in table-based iteration.
func ( *Query8[, , , , , , , ]) ( int) Entity {
	return .components[].columns[.table.id].target
}

// Count counts the entities matching this query.
//
// Has some overhead of iterating through archetypes.
// However, this is still much faster than manual counting via iteration.
//
// Does not iterate or close the query.
//
// See [Query2.Count] for an example.
func ( *Query8[, , , , , , , ]) () int {
	if .cache == nil {
		return countQuery(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp])
	}
	return countQueryCache(&.world.storage, .cache, .relations)
}

// EntityAt returns the entity at a given index.
//
// The method is particularly useful for random sampling of entities from a query.
// However, performance depends on the number of archetypes in the world and in the query.
// In worlds with many archetypes, it is recommended to use a registered/cached filter.
//
// Do not use this to iterate a query! Use [Query8.Next] instead.
//
// Panics if the index is out of range, as indicated by [Query8.Count].
//
// See [Query2.EntityAt] for an example.
func ( *Query8[, , , , , , , ]) ( int) Entity {
	if .cache == nil {
		return entityAt(&.world.storage, .filter, .relations, .world.storage.componentIndex[.rareComp], uint32())
	}
	return entityAtCache(&.world.storage, .cache, .relations, uint32())
}

// Close closes the Query and unlocks the world.
//
// Automatically called when iteration completes.
// Needs to be called only if breaking out of the query iteration or not iterating at all.
func ( *Query8[, , , , , , , ]) () {
	if .cursor.table < -1 {
		return
	}
	.cursor.archetype = -2
	.cursor.table = -2
	.tables = nil
	.table = nil
	.cache = nil
	.columnA = nil
	.columnPtrA = unsafe.Pointer(nilDummy)
	.itemSizeA = 0
	.columnB = nil
	.columnPtrB = unsafe.Pointer(nilDummy)
	.itemSizeB = 0
	.columnC = nil
	.columnPtrC = unsafe.Pointer(nilDummy)
	.itemSizeC = 0
	.columnD = nil
	.columnPtrD = unsafe.Pointer(nilDummy)
	.itemSizeD = 0
	.columnE = nil
	.columnPtrE = unsafe.Pointer(nilDummy)
	.itemSizeE = 0
	.columnF = nil
	.columnPtrF = unsafe.Pointer(nilDummy)
	.itemSizeF = 0
	.columnG = nil
	.columnPtrG = unsafe.Pointer(nilDummy)
	.itemSizeG = 0
	.columnH = nil
	.columnPtrH = unsafe.Pointer(nilDummy)
	.itemSizeH = 0
	.world.unlockSafe(.lock)
}

func ( *Query8[, , , , , , , ]) () bool {
	if .cache != nil {
		return .nextTable(.cache.tables.tables)
	}
	if .cursor.archetype >= 0 && .nextTable(.tables) {
		return true
	}
	return .nextArchetype()
}

func ( *Query8[, , , , , , , ]) () bool {
	.tables = nil
	 := .world.storage.componentIndex[.rareComp]
	 := int32(len() - 1)
	for .cursor.archetype <  {
		.cursor.archetype++
		 := &.world.storage.archetypes[[.cursor.archetype]]

		if !.filter.matches(&.mask) {
			continue
		}

		if !.HasRelations() {
			 := &.world.storage.tables[.tables.tables[0]]
			if .len > 0 {
				.setTable(0, )
				return true
			}
			continue
		}

		.tables = .GetTables(.relations)
		.cursor.table = -1
		if .nextTable(.tables) {
			return true
		}
	}
	.Close()
	return false
}

func ( *Query8[, , , , , , , ]) ( []tableID) bool {
	 := int32(len() - 1)
	for .cursor.table <  {
		.cursor.table++
		 := &.world.storage.tables[[.cursor.table]]
		if .len == 0 || !.Matches(.relations) {
			continue
		}
		.setTable(.cursor.table, )
		return true
	}
	if .cache != nil {
		.Close()
	}
	return false
}

func ( *Query8[, , , , , , , ]) ( int32,  *table) {
	.cursor.table = 
	.table = 
	.columnA = .components[0].columns[.table.id]
	.columnPtrA = .columnA.pointer
	.itemSizeA = .columnA.itemSize
	.columnB = .components[1].columns[.table.id]
	.columnPtrB = .columnB.pointer
	.itemSizeB = .columnB.itemSize
	.columnC = .components[2].columns[.table.id]
	.columnPtrC = .columnC.pointer
	.itemSizeC = .columnC.itemSize
	.columnD = .components[3].columns[.table.id]
	.columnPtrD = .columnD.pointer
	.itemSizeD = .columnD.itemSize
	.columnE = .components[4].columns[.table.id]
	.columnPtrE = .columnE.pointer
	.itemSizeE = .columnE.itemSize
	.columnF = .components[5].columns[.table.id]
	.columnPtrF = .columnF.pointer
	.itemSizeF = .columnF.itemSize
	.columnG = .components[6].columns[.table.id]
	.columnPtrG = .columnG.pointer
	.itemSizeG = .columnG.itemSize
	.columnH = .components[7].columns[.table.id]
	.columnPtrH = .columnH.pointer
	.itemSizeH = .columnH.itemSize
	.cursor.index = 0
	.cursor.maxIndex = int64(.table.len - 1)
}