package ecs

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

// Exchange1 allows to exchange components of entities.
// It adds the given components. Use [Exchange1.Removes]
// to set components to be removed.
//
// Instances should be created during initialization and stored, e.g. in systems.
//
// See [Exchange2] for a usage example.
type Exchange1[ any] struct {
	world     *World
	ids       []ID
	remove    []ID
	relations []relationID
	mask      bitMask
}

// New creates a new [Exchange1]. It is safe to call on `nil` instance.
// It is a helper method, intended to avoid repeated listing of type parameters.
//
// See [Exchange2.New] for an example.
func (*Exchange1[]) ( *World) *Exchange1[] {
	return NewExchange1[]()
}

// NewExchange1 creates an [Exchange1].
//
// See also [Exchange1.New] for a shortcut when constructing an already defined instance.
func [ any]( *World) *Exchange1[] {
	 := []ID{
		ComponentID[](),
	}
	return &Exchange1[]{
		world: ,
		ids:   ,
		mask:  newMask(...),
	}
}

// Removes sets the components that this [Exchange1] removes.
// Can be called multiple times in chains, or once with multiple arguments.
func ( *Exchange1[]) ( ...Comp) *Exchange1[] {
	for ,  := range  {
		.remove = append(.remove, .world.componentID(.tp))
	}
	return 
}

// Add the mapped components to the given entity.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange1[]) ( Entity,  *,  ...Relation) {
	.AddFn(, func( *) {
		* = *
	}, ...)
}

// AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange1[]) ( Entity,  func(*),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.add(, .ids, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// Remove the components previously specified with [Exchange1.Removes] from the given entity.
func ( *Exchange1[]) ( Entity) {
	.world.remove(, .remove)
}

// Exchange performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange1.Removes].
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange1[]) ( Entity,  *,  ...Relation) {
	.ExchangeFn(, func( *) {
		* = *
	}, ...)

}

// ExchangeFn performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange1.Removes].
// It runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange1[]) ( Entity,  func(*),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.exchange(, .ids, .remove, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// AddBatch adds the mapped components to all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange1[]) ( Batch,  *,  ...Relation) {
	.AddBatchFn(, func( Entity,  *) {
		* = *
	}, ...)
}

// AddBatchFn adds the mapped components to all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange1[]) ( Batch,  func(Entity, *),  ...Relation) {
	.exchangeBatchFn(&, , false, ...)
}

// RemoveBatch removes the components previously specified with [Exchange1.Removes]
// from all entities matching the given batch filter,
// running the given function on each. The function can be nil.
func ( *Exchange1[]) ( Batch,  func( Entity)) {
	removeBatch(.world, &, .remove, )
}

// ExchangeBatch performs the exchange on all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange1[]) ( Batch,  *,  ...Relation) {
	.ExchangeBatchFn(, func( Entity,  *) {
		* = *
	}, ...)
}

// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange1[]) ( Batch,  func(Entity, *),  ...Relation) {
	.exchangeBatchFn(&, , true, ...)
}

func ( *Exchange1[]) ( *Batch,  func(Entity, *),  bool,  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)

	var  func( tableID, ,  uint32)
	if  != nil {
		 = func( tableID, ,  uint32) {
			 := &.world.storage.tables[]
			 := .Column(.ids[0])

			for  := range  {
				 := uintptr( + )
				(
					.GetEntity(),
					(*)(.Get()),
				)
			}
		}
	}
	if  {
		.world.exchangeBatch(, .ids, .remove, .relations, )
	} else {
		.world.exchangeBatch(, .ids, nil, .relations, )
	}
}

func ( *Exchange1[]) ( Entity,  func( *)) {
	 := &.world.storage.entities[.id]
	 := &.world.storage.tables[.table]
	 := uintptr(.row)
	(
		(*)(.Column(.ids[0]).Get()),
	)
}

// Exchange2 allows to exchange components of entities.
// It adds the given components. Use [Exchange2.Removes]
// to set components to be removed.
//
// Instances should be created during initialization and stored, e.g. in systems.
type Exchange2[ any,  any] struct {
	world     *World
	ids       []ID
	remove    []ID
	relations []relationID
	mask      bitMask
}

// New creates a new [Exchange2]. It is safe to call on `nil` instance.
// It is a helper method, intended to avoid repeated listing of type parameters.
func (*Exchange2[, ]) ( *World) *Exchange2[, ] {
	return NewExchange2[, ]()
}

// NewExchange2 creates an [Exchange2].
//
// See also [Exchange2.New] for a shortcut when constructing an already defined instance.
func [ any,  any]( *World) *Exchange2[, ] {
	 := []ID{
		ComponentID[](),
		ComponentID[](),
	}
	return &Exchange2[, ]{
		world: ,
		ids:   ,
		mask:  newMask(...),
	}
}

// Removes sets the components that this [Exchange2] removes.
// Can be called multiple times in chains, or once with multiple arguments.
func ( *Exchange2[, ]) ( ...Comp) *Exchange2[, ] {
	for ,  := range  {
		.remove = append(.remove, .world.componentID(.tp))
	}
	return 
}

// Add the mapped components to the given entity.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange2[, ]) ( Entity,  *,  *,  ...Relation) {
	.AddFn(, func( *,  *) {
		* = *
		* = *
	}, ...)
}

// AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange2[, ]) ( Entity,  func(*, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.add(, .ids, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// Remove the components previously specified with [Exchange2.Removes] from the given entity.
func ( *Exchange2[, ]) ( Entity) {
	.world.remove(, .remove)
}

// Exchange performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange2.Removes].
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange2[, ]) ( Entity,  *,  *,  ...Relation) {
	.ExchangeFn(, func( *,  *) {
		* = *
		* = *
	}, ...)

}

// ExchangeFn performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange2.Removes].
// It runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange2[, ]) ( Entity,  func(*, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.exchange(, .ids, .remove, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// AddBatch adds the mapped components to all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange2[, ]) ( Batch,  *,  *,  ...Relation) {
	.AddBatchFn(, func( Entity,  *,  *) {
		* = *
		* = *
	}, ...)
}

// AddBatchFn adds the mapped components to all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange2[, ]) ( Batch,  func(Entity, *, *),  ...Relation) {
	.exchangeBatchFn(&, , false, ...)
}

// RemoveBatch removes the components previously specified with [Exchange2.Removes]
// from all entities matching the given batch filter,
// running the given function on each. The function can be nil.
func ( *Exchange2[, ]) ( Batch,  func( Entity)) {
	removeBatch(.world, &, .remove, )
}

// ExchangeBatch performs the exchange on all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange2[, ]) ( Batch,  *,  *,  ...Relation) {
	.ExchangeBatchFn(, func( Entity,  *,  *) {
		* = *
		* = *
	}, ...)
}

// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange2[, ]) ( Batch,  func(Entity, *, *),  ...Relation) {
	.exchangeBatchFn(&, , true, ...)
}

func ( *Exchange2[, ]) ( *Batch,  func(Entity, *, *),  bool,  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)

	var  func( tableID, ,  uint32)
	if  != nil {
		 = func( tableID, ,  uint32) {
			 := &.world.storage.tables[]
			 := .Column(.ids[0])
			 := .Column(.ids[1])

			for  := range  {
				 := uintptr( + )
				(
					.GetEntity(),
					(*)(.Get()),
					(*)(.Get()),
				)
			}
		}
	}
	if  {
		.world.exchangeBatch(, .ids, .remove, .relations, )
	} else {
		.world.exchangeBatch(, .ids, nil, .relations, )
	}
}

func ( *Exchange2[, ]) ( Entity,  func( *,  *)) {
	 := &.world.storage.entities[.id]
	 := &.world.storage.tables[.table]
	 := uintptr(.row)
	(
		(*)(.Column(.ids[0]).Get()),
		(*)(.Column(.ids[1]).Get()),
	)
}

// Exchange3 allows to exchange components of entities.
// It adds the given components. Use [Exchange3.Removes]
// to set components to be removed.
//
// Instances should be created during initialization and stored, e.g. in systems.
//
// See [Exchange2] for a usage example.
type Exchange3[ any,  any,  any] struct {
	world     *World
	ids       []ID
	remove    []ID
	relations []relationID
	mask      bitMask
}

// New creates a new [Exchange3]. It is safe to call on `nil` instance.
// It is a helper method, intended to avoid repeated listing of type parameters.
//
// See [Exchange2.New] for an example.
func (*Exchange3[, , ]) ( *World) *Exchange3[, , ] {
	return NewExchange3[, , ]()
}

// NewExchange3 creates an [Exchange3].
//
// See also [Exchange3.New] for a shortcut when constructing an already defined instance.
func [ any,  any,  any]( *World) *Exchange3[, , ] {
	 := []ID{
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
	}
	return &Exchange3[, , ]{
		world: ,
		ids:   ,
		mask:  newMask(...),
	}
}

// Removes sets the components that this [Exchange3] removes.
// Can be called multiple times in chains, or once with multiple arguments.
func ( *Exchange3[, , ]) ( ...Comp) *Exchange3[, , ] {
	for ,  := range  {
		.remove = append(.remove, .world.componentID(.tp))
	}
	return 
}

// Add the mapped components to the given entity.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange3[, , ]) ( Entity,  *,  *,  *,  ...Relation) {
	.AddFn(, func( *,  *,  *) {
		* = *
		* = *
		* = *
	}, ...)
}

// AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange3[, , ]) ( Entity,  func(*, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.add(, .ids, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// Remove the components previously specified with [Exchange3.Removes] from the given entity.
func ( *Exchange3[, , ]) ( Entity) {
	.world.remove(, .remove)
}

// Exchange performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange3.Removes].
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange3[, , ]) ( Entity,  *,  *,  *,  ...Relation) {
	.ExchangeFn(, func( *,  *,  *) {
		* = *
		* = *
		* = *
	}, ...)

}

// ExchangeFn performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange3.Removes].
// It runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange3[, , ]) ( Entity,  func(*, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.exchange(, .ids, .remove, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// AddBatch adds the mapped components to all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange3[, , ]) ( Batch,  *,  *,  *,  ...Relation) {
	.AddBatchFn(, func( Entity,  *,  *,  *) {
		* = *
		* = *
		* = *
	}, ...)
}

// AddBatchFn adds the mapped components to all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange3[, , ]) ( Batch,  func(Entity, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , false, ...)
}

// RemoveBatch removes the components previously specified with [Exchange3.Removes]
// from all entities matching the given batch filter,
// running the given function on each. The function can be nil.
func ( *Exchange3[, , ]) ( Batch,  func( Entity)) {
	removeBatch(.world, &, .remove, )
}

// ExchangeBatch performs the exchange on all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange3[, , ]) ( Batch,  *,  *,  *,  ...Relation) {
	.ExchangeBatchFn(, func( Entity,  *,  *,  *) {
		* = *
		* = *
		* = *
	}, ...)
}

// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange3[, , ]) ( Batch,  func(Entity, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , true, ...)
}

func ( *Exchange3[, , ]) ( *Batch,  func(Entity, *, *, *),  bool,  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)

	var  func( tableID, ,  uint32)
	if  != nil {
		 = func( tableID, ,  uint32) {
			 := &.world.storage.tables[]
			 := .Column(.ids[0])
			 := .Column(.ids[1])
			 := .Column(.ids[2])

			for  := range  {
				 := uintptr( + )
				(
					.GetEntity(),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
				)
			}
		}
	}
	if  {
		.world.exchangeBatch(, .ids, .remove, .relations, )
	} else {
		.world.exchangeBatch(, .ids, nil, .relations, )
	}
}

func ( *Exchange3[, , ]) ( Entity,  func( *,  *,  *)) {
	 := &.world.storage.entities[.id]
	 := &.world.storage.tables[.table]
	 := uintptr(.row)
	(
		(*)(.Column(.ids[0]).Get()),
		(*)(.Column(.ids[1]).Get()),
		(*)(.Column(.ids[2]).Get()),
	)
}

// Exchange4 allows to exchange components of entities.
// It adds the given components. Use [Exchange4.Removes]
// to set components to be removed.
//
// Instances should be created during initialization and stored, e.g. in systems.
//
// See [Exchange2] for a usage example.
type Exchange4[ any,  any,  any,  any] struct {
	world     *World
	ids       []ID
	remove    []ID
	relations []relationID
	mask      bitMask
}

// New creates a new [Exchange4]. It is safe to call on `nil` instance.
// It is a helper method, intended to avoid repeated listing of type parameters.
//
// See [Exchange2.New] for an example.
func (*Exchange4[, , , ]) ( *World) *Exchange4[, , , ] {
	return NewExchange4[, , , ]()
}

// NewExchange4 creates an [Exchange4].
//
// See also [Exchange4.New] for a shortcut when constructing an already defined instance.
func [ any,  any,  any,  any]( *World) *Exchange4[, , , ] {
	 := []ID{
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
	}
	return &Exchange4[, , , ]{
		world: ,
		ids:   ,
		mask:  newMask(...),
	}
}

// Removes sets the components that this [Exchange4] removes.
// Can be called multiple times in chains, or once with multiple arguments.
func ( *Exchange4[, , , ]) ( ...Comp) *Exchange4[, , , ] {
	for ,  := range  {
		.remove = append(.remove, .world.componentID(.tp))
	}
	return 
}

// Add the mapped components to the given entity.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange4[, , , ]) ( Entity,  *,  *,  *,  *,  ...Relation) {
	.AddFn(, func( *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange4[, , , ]) ( Entity,  func(*, *, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.add(, .ids, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// Remove the components previously specified with [Exchange4.Removes] from the given entity.
func ( *Exchange4[, , , ]) ( Entity) {
	.world.remove(, .remove)
}

// Exchange performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange4.Removes].
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange4[, , , ]) ( Entity,  *,  *,  *,  *,  ...Relation) {
	.ExchangeFn(, func( *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
	}, ...)

}

// ExchangeFn performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange4.Removes].
// It runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange4[, , , ]) ( Entity,  func(*, *, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.exchange(, .ids, .remove, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// AddBatch adds the mapped components to all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange4[, , , ]) ( Batch,  *,  *,  *,  *,  ...Relation) {
	.AddBatchFn(, func( Entity,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// AddBatchFn adds the mapped components to all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange4[, , , ]) ( Batch,  func(Entity, *, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , false, ...)
}

// RemoveBatch removes the components previously specified with [Exchange4.Removes]
// from all entities matching the given batch filter,
// running the given function on each. The function can be nil.
func ( *Exchange4[, , , ]) ( Batch,  func( Entity)) {
	removeBatch(.world, &, .remove, )
}

// ExchangeBatch performs the exchange on all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange4[, , , ]) ( Batch,  *,  *,  *,  *,  ...Relation) {
	.ExchangeBatchFn(, func( Entity,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange4[, , , ]) ( Batch,  func(Entity, *, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , true, ...)
}

func ( *Exchange4[, , , ]) ( *Batch,  func(Entity, *, *, *, *),  bool,  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)

	var  func( tableID, ,  uint32)
	if  != nil {
		 = func( tableID, ,  uint32) {
			 := &.world.storage.tables[]
			 := .Column(.ids[0])
			 := .Column(.ids[1])
			 := .Column(.ids[2])
			 := .Column(.ids[3])

			for  := range  {
				 := uintptr( + )
				(
					.GetEntity(),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
				)
			}
		}
	}
	if  {
		.world.exchangeBatch(, .ids, .remove, .relations, )
	} else {
		.world.exchangeBatch(, .ids, nil, .relations, )
	}
}

func ( *Exchange4[, , , ]) ( Entity,  func( *,  *,  *,  *)) {
	 := &.world.storage.entities[.id]
	 := &.world.storage.tables[.table]
	 := uintptr(.row)
	(
		(*)(.Column(.ids[0]).Get()),
		(*)(.Column(.ids[1]).Get()),
		(*)(.Column(.ids[2]).Get()),
		(*)(.Column(.ids[3]).Get()),
	)
}

// Exchange5 allows to exchange components of entities.
// It adds the given components. Use [Exchange5.Removes]
// to set components to be removed.
//
// Instances should be created during initialization and stored, e.g. in systems.
//
// See [Exchange2] for a usage example.
type Exchange5[ any,  any,  any,  any,  any] struct {
	world     *World
	ids       []ID
	remove    []ID
	relations []relationID
	mask      bitMask
}

// New creates a new [Exchange5]. It is safe to call on `nil` instance.
// It is a helper method, intended to avoid repeated listing of type parameters.
//
// See [Exchange2.New] for an example.
func (*Exchange5[, , , , ]) ( *World) *Exchange5[, , , , ] {
	return NewExchange5[, , , , ]()
}

// NewExchange5 creates an [Exchange5].
//
// See also [Exchange5.New] for a shortcut when constructing an already defined instance.
func [ any,  any,  any,  any,  any]( *World) *Exchange5[, , , , ] {
	 := []ID{
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
	}
	return &Exchange5[, , , , ]{
		world: ,
		ids:   ,
		mask:  newMask(...),
	}
}

// Removes sets the components that this [Exchange5] removes.
// Can be called multiple times in chains, or once with multiple arguments.
func ( *Exchange5[, , , , ]) ( ...Comp) *Exchange5[, , , , ] {
	for ,  := range  {
		.remove = append(.remove, .world.componentID(.tp))
	}
	return 
}

// Add the mapped components to the given entity.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange5[, , , , ]) ( Entity,  *,  *,  *,  *,  *,  ...Relation) {
	.AddFn(, func( *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange5[, , , , ]) ( Entity,  func(*, *, *, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.add(, .ids, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// Remove the components previously specified with [Exchange5.Removes] from the given entity.
func ( *Exchange5[, , , , ]) ( Entity) {
	.world.remove(, .remove)
}

// Exchange performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange5.Removes].
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange5[, , , , ]) ( Entity,  *,  *,  *,  *,  *,  ...Relation) {
	.ExchangeFn(, func( *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)

}

// ExchangeFn performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange5.Removes].
// It runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange5[, , , , ]) ( Entity,  func(*, *, *, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.exchange(, .ids, .remove, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// AddBatch adds the mapped components to all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange5[, , , , ]) ( Batch,  *,  *,  *,  *,  *,  ...Relation) {
	.AddBatchFn(, func( Entity,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// AddBatchFn adds the mapped components to all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange5[, , , , ]) ( Batch,  func(Entity, *, *, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , false, ...)
}

// RemoveBatch removes the components previously specified with [Exchange5.Removes]
// from all entities matching the given batch filter,
// running the given function on each. The function can be nil.
func ( *Exchange5[, , , , ]) ( Batch,  func( Entity)) {
	removeBatch(.world, &, .remove, )
}

// ExchangeBatch performs the exchange on all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange5[, , , , ]) ( Batch,  *,  *,  *,  *,  *,  ...Relation) {
	.ExchangeBatchFn(, func( Entity,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange5[, , , , ]) ( Batch,  func(Entity, *, *, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , true, ...)
}

func ( *Exchange5[, , , , ]) ( *Batch,  func(Entity, *, *, *, *, *),  bool,  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)

	var  func( tableID, ,  uint32)
	if  != nil {
		 = func( tableID, ,  uint32) {
			 := &.world.storage.tables[]
			 := .Column(.ids[0])
			 := .Column(.ids[1])
			 := .Column(.ids[2])
			 := .Column(.ids[3])
			 := .Column(.ids[4])

			for  := range  {
				 := uintptr( + )
				(
					.GetEntity(),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
				)
			}
		}
	}
	if  {
		.world.exchangeBatch(, .ids, .remove, .relations, )
	} else {
		.world.exchangeBatch(, .ids, nil, .relations, )
	}
}

func ( *Exchange5[, , , , ]) ( Entity,  func( *,  *,  *,  *,  *)) {
	 := &.world.storage.entities[.id]
	 := &.world.storage.tables[.table]
	 := uintptr(.row)
	(
		(*)(.Column(.ids[0]).Get()),
		(*)(.Column(.ids[1]).Get()),
		(*)(.Column(.ids[2]).Get()),
		(*)(.Column(.ids[3]).Get()),
		(*)(.Column(.ids[4]).Get()),
	)
}

// Exchange6 allows to exchange components of entities.
// It adds the given components. Use [Exchange6.Removes]
// to set components to be removed.
//
// Instances should be created during initialization and stored, e.g. in systems.
//
// See [Exchange2] for a usage example.
type Exchange6[ any,  any,  any,  any,  any,  any] struct {
	world     *World
	ids       []ID
	remove    []ID
	relations []relationID
	mask      bitMask
}

// New creates a new [Exchange6]. It is safe to call on `nil` instance.
// It is a helper method, intended to avoid repeated listing of type parameters.
//
// See [Exchange2.New] for an example.
func (*Exchange6[, , , , , ]) ( *World) *Exchange6[, , , , , ] {
	return NewExchange6[, , , , , ]()
}

// NewExchange6 creates an [Exchange6].
//
// See also [Exchange6.New] for a shortcut when constructing an already defined instance.
func [ any,  any,  any,  any,  any,  any]( *World) *Exchange6[, , , , , ] {
	 := []ID{
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
	}
	return &Exchange6[, , , , , ]{
		world: ,
		ids:   ,
		mask:  newMask(...),
	}
}

// Removes sets the components that this [Exchange6] removes.
// Can be called multiple times in chains, or once with multiple arguments.
func ( *Exchange6[, , , , , ]) ( ...Comp) *Exchange6[, , , , , ] {
	for ,  := range  {
		.remove = append(.remove, .world.componentID(.tp))
	}
	return 
}

// Add the mapped components to the given entity.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange6[, , , , , ]) ( Entity,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.AddFn(, func( *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange6[, , , , , ]) ( Entity,  func(*, *, *, *, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.add(, .ids, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// Remove the components previously specified with [Exchange6.Removes] from the given entity.
func ( *Exchange6[, , , , , ]) ( Entity) {
	.world.remove(, .remove)
}

// Exchange performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange6.Removes].
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange6[, , , , , ]) ( Entity,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.ExchangeFn(, func( *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)

}

// ExchangeFn performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange6.Removes].
// It runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange6[, , , , , ]) ( Entity,  func(*, *, *, *, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.exchange(, .ids, .remove, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// AddBatch adds the mapped components to all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange6[, , , , , ]) ( Batch,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.AddBatchFn(, func( Entity,  *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// AddBatchFn adds the mapped components to all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange6[, , , , , ]) ( Batch,  func(Entity, *, *, *, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , false, ...)
}

// RemoveBatch removes the components previously specified with [Exchange6.Removes]
// from all entities matching the given batch filter,
// running the given function on each. The function can be nil.
func ( *Exchange6[, , , , , ]) ( Batch,  func( Entity)) {
	removeBatch(.world, &, .remove, )
}

// ExchangeBatch performs the exchange on all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange6[, , , , , ]) ( Batch,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.ExchangeBatchFn(, func( Entity,  *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange6[, , , , , ]) ( Batch,  func(Entity, *, *, *, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , true, ...)
}

func ( *Exchange6[, , , , , ]) ( *Batch,  func(Entity, *, *, *, *, *, *),  bool,  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)

	var  func( tableID, ,  uint32)
	if  != nil {
		 = func( tableID, ,  uint32) {
			 := &.world.storage.tables[]
			 := .Column(.ids[0])
			 := .Column(.ids[1])
			 := .Column(.ids[2])
			 := .Column(.ids[3])
			 := .Column(.ids[4])
			 := .Column(.ids[5])

			for  := range  {
				 := uintptr( + )
				(
					.GetEntity(),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
				)
			}
		}
	}
	if  {
		.world.exchangeBatch(, .ids, .remove, .relations, )
	} else {
		.world.exchangeBatch(, .ids, nil, .relations, )
	}
}

func ( *Exchange6[, , , , , ]) ( Entity,  func( *,  *,  *,  *,  *,  *)) {
	 := &.world.storage.entities[.id]
	 := &.world.storage.tables[.table]
	 := uintptr(.row)
	(
		(*)(.Column(.ids[0]).Get()),
		(*)(.Column(.ids[1]).Get()),
		(*)(.Column(.ids[2]).Get()),
		(*)(.Column(.ids[3]).Get()),
		(*)(.Column(.ids[4]).Get()),
		(*)(.Column(.ids[5]).Get()),
	)
}

// Exchange7 allows to exchange components of entities.
// It adds the given components. Use [Exchange7.Removes]
// to set components to be removed.
//
// Instances should be created during initialization and stored, e.g. in systems.
//
// See [Exchange2] for a usage example.
type Exchange7[ any,  any,  any,  any,  any,  any,  any] struct {
	world     *World
	ids       []ID
	remove    []ID
	relations []relationID
	mask      bitMask
}

// New creates a new [Exchange7]. It is safe to call on `nil` instance.
// It is a helper method, intended to avoid repeated listing of type parameters.
//
// See [Exchange2.New] for an example.
func (*Exchange7[, , , , , , ]) ( *World) *Exchange7[, , , , , , ] {
	return NewExchange7[, , , , , , ]()
}

// NewExchange7 creates an [Exchange7].
//
// See also [Exchange7.New] for a shortcut when constructing an already defined instance.
func [ any,  any,  any,  any,  any,  any,  any]( *World) *Exchange7[, , , , , , ] {
	 := []ID{
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
	}
	return &Exchange7[, , , , , , ]{
		world: ,
		ids:   ,
		mask:  newMask(...),
	}
}

// Removes sets the components that this [Exchange7] removes.
// Can be called multiple times in chains, or once with multiple arguments.
func ( *Exchange7[, , , , , , ]) ( ...Comp) *Exchange7[, , , , , , ] {
	for ,  := range  {
		.remove = append(.remove, .world.componentID(.tp))
	}
	return 
}

// Add the mapped components to the given entity.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange7[, , , , , , ]) ( Entity,  *,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.AddFn(, func( *,  *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange7[, , , , , , ]) ( Entity,  func(*, *, *, *, *, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.add(, .ids, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// Remove the components previously specified with [Exchange7.Removes] from the given entity.
func ( *Exchange7[, , , , , , ]) ( Entity) {
	.world.remove(, .remove)
}

// Exchange performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange7.Removes].
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange7[, , , , , , ]) ( Entity,  *,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.ExchangeFn(, func( *,  *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)

}

// ExchangeFn performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange7.Removes].
// It runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange7[, , , , , , ]) ( Entity,  func(*, *, *, *, *, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.exchange(, .ids, .remove, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// AddBatch adds the mapped components to all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange7[, , , , , , ]) ( Batch,  *,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.AddBatchFn(, func( Entity,  *,  *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// AddBatchFn adds the mapped components to all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange7[, , , , , , ]) ( Batch,  func(Entity, *, *, *, *, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , false, ...)
}

// RemoveBatch removes the components previously specified with [Exchange7.Removes]
// from all entities matching the given batch filter,
// running the given function on each. The function can be nil.
func ( *Exchange7[, , , , , , ]) ( Batch,  func( Entity)) {
	removeBatch(.world, &, .remove, )
}

// ExchangeBatch performs the exchange on all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange7[, , , , , , ]) ( Batch,  *,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.ExchangeBatchFn(, func( Entity,  *,  *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange7[, , , , , , ]) ( Batch,  func(Entity, *, *, *, *, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , true, ...)
}

func ( *Exchange7[, , , , , , ]) ( *Batch,  func(Entity, *, *, *, *, *, *, *),  bool,  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)

	var  func( tableID, ,  uint32)
	if  != nil {
		 = func( tableID, ,  uint32) {
			 := &.world.storage.tables[]
			 := .Column(.ids[0])
			 := .Column(.ids[1])
			 := .Column(.ids[2])
			 := .Column(.ids[3])
			 := .Column(.ids[4])
			 := .Column(.ids[5])
			 := .Column(.ids[6])

			for  := range  {
				 := uintptr( + )
				(
					.GetEntity(),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
				)
			}
		}
	}
	if  {
		.world.exchangeBatch(, .ids, .remove, .relations, )
	} else {
		.world.exchangeBatch(, .ids, nil, .relations, )
	}
}

func ( *Exchange7[, , , , , , ]) ( Entity,  func( *,  *,  *,  *,  *,  *,  *)) {
	 := &.world.storage.entities[.id]
	 := &.world.storage.tables[.table]
	 := uintptr(.row)
	(
		(*)(.Column(.ids[0]).Get()),
		(*)(.Column(.ids[1]).Get()),
		(*)(.Column(.ids[2]).Get()),
		(*)(.Column(.ids[3]).Get()),
		(*)(.Column(.ids[4]).Get()),
		(*)(.Column(.ids[5]).Get()),
		(*)(.Column(.ids[6]).Get()),
	)
}

// Exchange8 allows to exchange components of entities.
// It adds the given components. Use [Exchange8.Removes]
// to set components to be removed.
//
// Instances should be created during initialization and stored, e.g. in systems.
//
// See [Exchange2] for a usage example.
type Exchange8[ any,  any,  any,  any,  any,  any,  any,  any] struct {
	world     *World
	ids       []ID
	remove    []ID
	relations []relationID
	mask      bitMask
}

// New creates a new [Exchange8]. It is safe to call on `nil` instance.
// It is a helper method, intended to avoid repeated listing of type parameters.
//
// See [Exchange2.New] for an example.
func (*Exchange8[, , , , , , , ]) ( *World) *Exchange8[, , , , , , , ] {
	return NewExchange8[, , , , , , , ]()
}

// NewExchange8 creates an [Exchange8].
//
// See also [Exchange8.New] for a shortcut when constructing an already defined instance.
func [ any,  any,  any,  any,  any,  any,  any,  any]( *World) *Exchange8[, , , , , , , ] {
	 := []ID{
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
		ComponentID[](),
	}
	return &Exchange8[, , , , , , , ]{
		world: ,
		ids:   ,
		mask:  newMask(...),
	}
}

// Removes sets the components that this [Exchange8] removes.
// Can be called multiple times in chains, or once with multiple arguments.
func ( *Exchange8[, , , , , , , ]) ( ...Comp) *Exchange8[, , , , , , , ] {
	for ,  := range  {
		.remove = append(.remove, .world.componentID(.tp))
	}
	return 
}

// Add the mapped components to the given entity.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange8[, , , , , , , ]) ( Entity,  *,  *,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.AddFn(, func( *,  *,  *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// AddFn adds the mapped components to the given entity and runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange8[, , , , , , , ]) ( Entity,  func(*, *, *, *, *, *, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.add(, .ids, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// Remove the components previously specified with [Exchange8.Removes] from the given entity.
func ( *Exchange8[, , , , , , , ]) ( Entity) {
	.world.remove(, .remove)
}

// Exchange performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange8.Removes].
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange8[, , , , , , , ]) ( Entity,  *,  *,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.ExchangeFn(, func( *,  *,  *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)

}

// ExchangeFn performs the exchange on the given entity, adding the provided components
// and removing those previously specified with [Exchange8.Removes].
// It runs a callback instead of using components for initialization.
// The callback can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange8[, , , , , , , ]) ( Entity,  func(*, *, *, *, *, *, *, *),  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)
	,  := .world.exchange(, .ids, .remove, .relations)
	if  != nil {
		.runCallback(, )
	}
	.world.storage.observers.FireAddIfHas(OnAddComponents, , , )
	if len() > 0 {
		.world.storage.observers.FireAddIfHas(OnAddRelations, , , )
	}
}

// AddBatch adds the mapped components to all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange8[, , , , , , , ]) ( Batch,  *,  *,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.AddBatchFn(, func( Entity,  *,  *,  *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// AddBatchFn adds the mapped components to all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange8[, , , , , , , ]) ( Batch,  func(Entity, *, *, *, *, *, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , false, ...)
}

// RemoveBatch removes the components previously specified with [Exchange8.Removes]
// from all entities matching the given batch filter,
// running the given function on each. The function can be nil.
func ( *Exchange8[, , , , , , , ]) ( Batch,  func( Entity)) {
	removeBatch(.world, &, .remove, )
}

// ExchangeBatch performs the exchange on all entities matching the given batch filter.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
func ( *Exchange8[, , , , , , , ]) ( Batch,  *,  *,  *,  *,  *,  *,  *,  *,  ...Relation) {
	.ExchangeBatchFn(, func( Entity,  *,  *,  *,  *,  *,  *,  *,  *) {
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
		* = *
	}, ...)
}

// ExchangeBatchFn performs the exchange on all entities matching the given batch filter,
// running the given function on each. The function can be nil.
//
// For each mapped component that is a relationships (see [RelationMarker]),
// a relation target entity must be provided via the variadic arguments.
//
// ⚠️ Do not store the obtained pointers outside of the current context!
func ( *Exchange8[, , , , , , , ]) ( Batch,  func(Entity, *, *, *, *, *, *, *, *),  ...Relation) {
	.exchangeBatchFn(&, , true, ...)
}

func ( *Exchange8[, , , , , , , ]) ( *Batch,  func(Entity, *, *, *, *, *, *, *, *),  bool,  ...Relation) {
	.relations = relationSlice().ToRelations(.world, &.mask, .ids, .relations[:0], false)

	var  func( tableID, ,  uint32)
	if  != nil {
		 = func( tableID, ,  uint32) {
			 := &.world.storage.tables[]
			 := .Column(.ids[0])
			 := .Column(.ids[1])
			 := .Column(.ids[2])
			 := .Column(.ids[3])
			 := .Column(.ids[4])
			 := .Column(.ids[5])
			 := .Column(.ids[6])
			 := .Column(.ids[7])

			for  := range  {
				 := uintptr( + )
				(
					.GetEntity(),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
					(*)(.Get()),
				)
			}
		}
	}
	if  {
		.world.exchangeBatch(, .ids, .remove, .relations, )
	} else {
		.world.exchangeBatch(, .ids, nil, .relations, )
	}
}

func ( *Exchange8[, , , , , , , ]) ( Entity,  func( *,  *,  *,  *,  *,  *,  *,  *)) {
	 := &.world.storage.entities[.id]
	 := &.world.storage.tables[.table]
	 := uintptr(.row)
	(
		(*)(.Column(.ids[0]).Get()),
		(*)(.Column(.ids[1]).Get()),
		(*)(.Column(.ids[2]).Get()),
		(*)(.Column(.ids[3]).Get()),
		(*)(.Column(.ids[4]).Get()),
		(*)(.Column(.ids[5]).Get()),
		(*)(.Column(.ids[6]).Get()),
		(*)(.Column(.ids[7]).Get()),
	)
}