package wasvy_ecs_app
import (
witRuntime "go.bytecodealliance.org/pkg/wit/runtime"
witTypes "go.bytecodealliance.org/pkg/wit/types"
"runtime"
"unsafe"
)
func resourceDropApp(handle int32)
type App struct {
handle *witRuntime.Handle
}
func (self *App) TakeHandle() int32 {
return self.handle.Take()
}
func (self *App) SetHandle(handle int32) {
self.handle.Set(handle)
}
func (self *App) Handle() int32 {
return self.handle.Use()
}
func (self *App) Drop() {
handle := self.handle.TakeOrNil()
if handle != 0 {
resourceDropApp(handle)
}
}
func AppFromOwnHandle(handleValue int32) *App {
handle := witRuntime.MakeHandle(handleValue)
value := &App{handle}
runtime.AddCleanup(value, func(_ int) {
handleValue := handle.TakeOrNil()
if handleValue != 0 {
resourceDropApp(handleValue)
}
}, 0)
return value
}
func AppFromBorrowHandle(handleValue int32) *App {
handle := witRuntime.MakeHandle(handleValue)
return &App{handle}
}
func resourceDropSystem(handle int32)
type System struct {
handle *witRuntime.Handle
}
func (self *System) TakeHandle() int32 {
return self.handle.Take()
}
func (self *System) SetHandle(handle int32) {
self.handle.Set(handle)
}
func (self *System) Handle() int32 {
return self.handle.Use()
}
func (self *System) Drop() {
handle := self.handle.TakeOrNil()
if handle != 0 {
resourceDropSystem(handle)
}
}
func SystemFromOwnHandle(handleValue int32) *System {
handle := witRuntime.MakeHandle(handleValue)
value := &System{handle}
runtime.AddCleanup(value, func(_ int) {
handleValue := handle.TakeOrNil()
if handleValue != 0 {
resourceDropSystem(handleValue)
}
}, 0)
return value
}
func SystemFromBorrowHandle(handleValue int32) *System {
handle := witRuntime.MakeHandle(handleValue)
return &System{handle}
}
func resourceDropCommands(handle int32)
type Commands struct {
handle *witRuntime.Handle
}
func (self *Commands) TakeHandle() int32 {
return self.handle.Take()
}
func (self *Commands) SetHandle(handle int32) {
self.handle.Set(handle)
}
func (self *Commands) Handle() int32 {
return self.handle.Use()
}
func (self *Commands) Drop() {
handle := self.handle.TakeOrNil()
if handle != 0 {
resourceDropCommands(handle)
}
}
func CommandsFromOwnHandle(handleValue int32) *Commands {
handle := witRuntime.MakeHandle(handleValue)
value := &Commands{handle}
runtime.AddCleanup(value, func(_ int) {
handleValue := handle.TakeOrNil()
if handleValue != 0 {
resourceDropCommands(handleValue)
}
}, 0)
return value
}
func CommandsFromBorrowHandle(handleValue int32) *Commands {
handle := witRuntime.MakeHandle(handleValue)
return &Commands{handle}
}
func resourceDropEntityCommands(handle int32)
type EntityCommands struct {
handle *witRuntime.Handle
}
func (self *EntityCommands) TakeHandle() int32 {
return self.handle.Take()
}
func (self *EntityCommands) SetHandle(handle int32) {
self.handle.Set(handle)
}
func (self *EntityCommands) Handle() int32 {
return self.handle.Use()
}
func (self *EntityCommands) Drop() {
handle := self.handle.TakeOrNil()
if handle != 0 {
resourceDropEntityCommands(handle)
}
}
func EntityCommandsFromOwnHandle(handleValue int32) *EntityCommands {
handle := witRuntime.MakeHandle(handleValue)
value := &EntityCommands{handle}
runtime.AddCleanup(value, func(_ int) {
handleValue := handle.TakeOrNil()
if handleValue != 0 {
resourceDropEntityCommands(handleValue)
}
}, 0)
return value
}
func EntityCommandsFromBorrowHandle(handleValue int32) *EntityCommands {
handle := witRuntime.MakeHandle(handleValue)
return &EntityCommands{handle}
}
func resourceDropEntity(handle int32)
type Entity struct {
handle *witRuntime.Handle
}
func (self *Entity) TakeHandle() int32 {
return self.handle.Take()
}
func (self *Entity) SetHandle(handle int32) {
self.handle.Set(handle)
}
func (self *Entity) Handle() int32 {
return self.handle.Use()
}
func (self *Entity) Drop() {
handle := self.handle.TakeOrNil()
if handle != 0 {
resourceDropEntity(handle)
}
}
func EntityFromOwnHandle(handleValue int32) *Entity {
handle := witRuntime.MakeHandle(handleValue)
value := &Entity{handle}
runtime.AddCleanup(value, func(_ int) {
handleValue := handle.TakeOrNil()
if handleValue != 0 {
resourceDropEntity(handleValue)
}
}, 0)
return value
}
func EntityFromBorrowHandle(handleValue int32) *Entity {
handle := witRuntime.MakeHandle(handleValue)
return &Entity{handle}
}
func resourceDropQuery(handle int32)
type Query struct {
handle *witRuntime.Handle
}
func (self *Query) TakeHandle() int32 {
return self.handle.Take()
}
func (self *Query) SetHandle(handle int32) {
self.handle.Set(handle)
}
func (self *Query) Handle() int32 {
return self.handle.Use()
}
func (self *Query) Drop() {
handle := self.handle.TakeOrNil()
if handle != 0 {
resourceDropQuery(handle)
}
}
func QueryFromOwnHandle(handleValue int32) *Query {
handle := witRuntime.MakeHandle(handleValue)
value := &Query{handle}
runtime.AddCleanup(value, func(_ int) {
handleValue := handle.TakeOrNil()
if handleValue != 0 {
resourceDropQuery(handleValue)
}
}, 0)
return value
}
func QueryFromBorrowHandle(handleValue int32) *Query {
handle := witRuntime.MakeHandle(handleValue)
return &Query{handle}
}
func resourceDropQueryResult(handle int32)
type QueryResult struct {
handle *witRuntime.Handle
}
func (self *QueryResult) TakeHandle() int32 {
return self.handle.Take()
}
func (self *QueryResult) SetHandle(handle int32) {
self.handle.Set(handle)
}
func (self *QueryResult) Handle() int32 {
return self.handle.Use()
}
func (self *QueryResult) Drop() {
handle := self.handle.TakeOrNil()
if handle != 0 {
resourceDropQueryResult(handle)
}
}
func QueryResultFromOwnHandle(handleValue int32) *QueryResult {
handle := witRuntime.MakeHandle(handleValue)
value := &QueryResult{handle}
runtime.AddCleanup(value, func(_ int) {
handleValue := handle.TakeOrNil()
if handleValue != 0 {
resourceDropQueryResult(handleValue)
}
}, 0)
return value
}
func QueryResultFromBorrowHandle(handleValue int32) *QueryResult {
handle := witRuntime.MakeHandle(handleValue)
return &QueryResult{handle}
}
func resourceDropComponent(handle int32)
type Component struct {
handle *witRuntime.Handle
}
func (self *Component) TakeHandle() int32 {
return self.handle.Take()
}
func (self *Component) SetHandle(handle int32) {
self.handle.Set(handle)
}
func (self *Component) Handle() int32 {
return self.handle.Use()
}
func (self *Component) Drop() {
handle := self.handle.TakeOrNil()
if handle != 0 {
resourceDropComponent(handle)
}
}
func ComponentFromOwnHandle(handleValue int32) *Component {
handle := witRuntime.MakeHandle(handleValue)
value := &Component{handle}
runtime.AddCleanup(value, func(_ int) {
handleValue := handle.TakeOrNil()
if handleValue != 0 {
resourceDropComponent(handleValue)
}
}, 0)
return value
}
func ComponentFromBorrowHandle(handleValue int32) *Component {
handle := witRuntime.MakeHandle(handleValue)
return &Component{handle}
}
type TypePath = string
type SerializedComponent = string
type Bundle = []witTypes.Tuple2[string, string]
type BundleTypes = []string
type ComponentIndex = uint8
const (
ScheduleModStartup uint8 = 0
SchedulePreUpdate uint8 = 1
ScheduleUpdate uint8 = 2
SchedulePostUpdate uint8 = 3
ScheduleFixedPreUpdate uint8 = 4
ScheduleFixedUpdate uint8 = 5
ScheduleFixedPostUpdate uint8 = 6
ScheduleCustom uint8 = 7
)
type Schedule struct {
tag uint8
value any
}
func (self Schedule) Tag() uint8 {
return self.tag
}
func (self Schedule) Custom() string {
if self.tag != ScheduleCustom {
panic("tag mismatch")
}
return self.value.(string)
}
func MakeScheduleModStartup() Schedule {
return Schedule{ScheduleModStartup, nil}
}
func MakeSchedulePreUpdate() Schedule {
return Schedule{SchedulePreUpdate, nil}
}
func MakeScheduleUpdate() Schedule {
return Schedule{ScheduleUpdate, nil}
}
func MakeSchedulePostUpdate() Schedule {
return Schedule{SchedulePostUpdate, nil}
}
func MakeScheduleFixedPreUpdate() Schedule {
return Schedule{ScheduleFixedPreUpdate, nil}
}
func MakeScheduleFixedUpdate() Schedule {
return Schedule{ScheduleFixedUpdate, nil}
}
func MakeScheduleFixedPostUpdate() Schedule {
return Schedule{ScheduleFixedPostUpdate, nil}
}
func MakeScheduleCustom(value string) Schedule {
return Schedule{ScheduleCustom, value}
}
const (
QueryForRef uint8 = 0
QueryForMut uint8 = 1
QueryForWith uint8 = 2
QueryForWithout uint8 = 3
)
type QueryFor struct {
tag uint8
value any
}
func (self QueryFor) Tag() uint8 {
return self.tag
}
func (self QueryFor) Ref() string {
if self.tag != QueryForRef {
panic("tag mismatch")
}
return self.value.(string)
}
func (self QueryFor) Mut() string {
if self.tag != QueryForMut {
panic("tag mismatch")
}
return self.value.(string)
}
func (self QueryFor) With() string {
if self.tag != QueryForWith {
panic("tag mismatch")
}
return self.value.(string)
}
func (self QueryFor) Without() string {
if self.tag != QueryForWithout {
panic("tag mismatch")
}
return self.value.(string)
}
func MakeQueryForRef(value string) QueryFor {
return QueryFor{QueryForRef, value}
}
func MakeQueryForMut(value string) QueryFor {
return QueryFor{QueryForMut, value}
}
func MakeQueryForWith(value string) QueryFor {
return QueryFor{QueryForWith, value}
}
func MakeQueryForWithout(value string) QueryFor {
return QueryFor{QueryForWithout, value}
}
func wasm_import_method_app_add_systems(arg0 int32, arg1 int32, arg2 uintptr, arg3 uint32, arg4 uintptr, arg5 uint32)
func (self *App) AddSystems(schedule Schedule, systems []*System) {
pinner := &runtime.Pinner{}
defer pinner.Unpin()
var variant int32
var variant0 uintptr
var variant1 uint32
switch schedule.Tag() {
case ScheduleModStartup:
variant = int32(0)
variant0 = 0
variant1 = 0
case SchedulePreUpdate:
variant = int32(1)
variant0 = 0
variant1 = 0
case ScheduleUpdate:
variant = int32(2)
variant0 = 0
variant1 = 0
case SchedulePostUpdate:
variant = int32(3)
variant0 = 0
variant1 = 0
case ScheduleFixedPreUpdate:
variant = int32(4)
variant0 = 0
variant1 = 0
case ScheduleFixedUpdate:
variant = int32(5)
variant0 = 0
variant1 = 0
case ScheduleFixedPostUpdate:
variant = int32(6)
variant0 = 0
variant1 = 0
case ScheduleCustom:
payload := schedule.Custom()
utf8 := unsafe.Pointer(unsafe.StringData(payload))
pinner.Pin(utf8)
variant = int32(7)
variant0 = uintptr(utf8)
variant1 = uint32(len(payload))
default:
panic("unreachable")
}
slice := systems
length := uint32(len(slice))
result := witRuntime.Allocate(pinner, uintptr(length*4), 4)
for index, element := range slice {
base := unsafe.Add(result, index*4)
*(*int32)(unsafe.Add(unsafe.Pointer(base), 0)) = (element).Handle()
}
wasm_import_method_app_add_systems((self).Handle(), variant, variant0, variant1, uintptr(result), length)
}
func wasm_import_constructor_system(arg0 uintptr, arg1 uint32) int32
func MakeSystem(name string) *System {
pinner := &runtime.Pinner{}
defer pinner.Unpin()
utf8 := unsafe.Pointer(unsafe.StringData(name))
pinner.Pin(utf8)
result := wasm_import_constructor_system(uintptr(utf8), uint32(len(name)))
return SystemFromOwnHandle(int32(uintptr(result)))
}
func wasm_import_method_system_add_commands(arg0 int32)
func (self *System) AddCommands() {
wasm_import_method_system_add_commands((self).Handle())
}
func wasm_import_method_system_add_query(arg0 int32, arg1 uintptr, arg2 uint32)
func (self *System) AddQuery(query []QueryFor) {
pinner := &runtime.Pinner{}
defer pinner.Unpin()
slice := query
length := uint32(len(slice))
result := witRuntime.Allocate(pinner, uintptr(length*(3*4)), 4)
for index, element := range slice {
base := unsafe.Add(result, index*(3*4))
switch element.Tag() {
case QueryForRef:
payload := element.Ref()
*(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(0))
utf8 := unsafe.Pointer(unsafe.StringData(payload))
pinner.Pin(utf8)
*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uint32(len(payload)))
*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uintptr(uintptr(utf8)))
case QueryForMut:
payload := element.Mut()
*(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(1))
utf80 := unsafe.Pointer(unsafe.StringData(payload))
pinner.Pin(utf80)
*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uint32(len(payload)))
*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uintptr(uintptr(utf80)))
case QueryForWith:
payload := element.With()
*(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(2))
utf81 := unsafe.Pointer(unsafe.StringData(payload))
pinner.Pin(utf81)
*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uint32(len(payload)))
*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uintptr(uintptr(utf81)))
case QueryForWithout:
payload := element.Without()
*(*int8)(unsafe.Add(unsafe.Pointer(base), 0)) = int8(int32(3))
utf82 := unsafe.Pointer(unsafe.StringData(payload))
pinner.Pin(utf82)
*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uint32(len(payload)))
*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uintptr(uintptr(utf82)))
default:
panic("unreachable")
}
}
wasm_import_method_system_add_query((self).Handle(), uintptr(result), length)
}
func wasm_import_method_system_after(arg0 int32, arg1 int32)
func (self *System) After(other *System) {
wasm_import_method_system_after((self).Handle(), (other).Handle())
}
func wasm_import_method_system_before(arg0 int32, arg1 int32)
func (self *System) Before(other *System) {
wasm_import_method_system_before((self).Handle(), (other).Handle())
}
func wasm_import_method_commands_spawn_empty(arg0 int32) int32
func (self *Commands) SpawnEmpty() *EntityCommands {
result := wasm_import_method_commands_spawn_empty((self).Handle())
return EntityCommandsFromOwnHandle(int32(uintptr(result)))
}
func wasm_import_method_commands_spawn(arg0 int32, arg1 uintptr, arg2 uint32) int32
func (self *Commands) Spawn(bundle []witTypes.Tuple2[string, string]) *EntityCommands {
pinner := &runtime.Pinner{}
defer pinner.Unpin()
slice := bundle
length := uint32(len(slice))
result := witRuntime.Allocate(pinner, uintptr(length*(4*4)), 4)
for index, element := range slice {
base := unsafe.Add(result, index*(4*4))
utf8 := unsafe.Pointer(unsafe.StringData((element).F0))
pinner.Pin(utf8)
*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len((element).F0)))
*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf8)))
utf80 := unsafe.Pointer(unsafe.StringData((element).F1))
pinner.Pin(utf80)
*(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))) = uint32(uint32(len((element).F1)))
*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uintptr(uintptr(utf80)))
}
result1 := wasm_import_method_commands_spawn((self).Handle(), uintptr(result), length)
return EntityCommandsFromOwnHandle(int32(uintptr(result1)))
}
func wasm_import_method_commands_entity(arg0 int32, arg1 int32) int32
func (self *Commands) Entity(entity *Entity) *EntityCommands {
result := wasm_import_method_commands_entity((self).Handle(), (entity).Handle())
return EntityCommandsFromOwnHandle(int32(uintptr(result)))
}
func wasm_import_method_entity_commands_id(arg0 int32) int32
func (self *EntityCommands) Id() *Entity {
result := wasm_import_method_entity_commands_id((self).Handle())
return EntityFromOwnHandle(int32(uintptr(result)))
}
func wasm_import_method_entity_commands_insert(arg0 int32, arg1 uintptr, arg2 uint32)
func (self *EntityCommands) Insert(bundle []witTypes.Tuple2[string, string]) {
pinner := &runtime.Pinner{}
defer pinner.Unpin()
slice := bundle
length := uint32(len(slice))
result := witRuntime.Allocate(pinner, uintptr(length*(4*4)), 4)
for index, element := range slice {
base := unsafe.Add(result, index*(4*4))
utf8 := unsafe.Pointer(unsafe.StringData((element).F0))
pinner.Pin(utf8)
*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len((element).F0)))
*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf8)))
utf80 := unsafe.Pointer(unsafe.StringData((element).F1))
pinner.Pin(utf80)
*(*uint32)(unsafe.Add(unsafe.Pointer(base), (3 * 4))) = uint32(uint32(len((element).F1)))
*(*uint32)(unsafe.Add(unsafe.Pointer(base), (2 * 4))) = uint32(uintptr(uintptr(utf80)))
}
wasm_import_method_entity_commands_insert((self).Handle(), uintptr(result), length)
}
func wasm_import_method_entity_commands_remove(arg0 int32, arg1 uintptr, arg2 uint32)
func (self *EntityCommands) Remove(bundle []string) {
pinner := &runtime.Pinner{}
defer pinner.Unpin()
slice := bundle
length := uint32(len(slice))
result := witRuntime.Allocate(pinner, uintptr(length*(2*4)), 4)
for index, element := range slice {
base := unsafe.Add(result, index*(2*4))
utf8 := unsafe.Pointer(unsafe.StringData(element))
pinner.Pin(utf8)
*(*uint32)(unsafe.Add(unsafe.Pointer(base), 4)) = uint32(uint32(len(element)))
*(*uint32)(unsafe.Add(unsafe.Pointer(base), 0)) = uint32(uintptr(uintptr(utf8)))
}
wasm_import_method_entity_commands_remove((self).Handle(), uintptr(result), length)
}
func wasm_import_method_entity_commands_despawn(arg0 int32)
func (self *EntityCommands) Despawn() {
wasm_import_method_entity_commands_despawn((self).Handle())
}
func wasm_import_method_entity_commands_try_despawn(arg0 int32)
func (self *EntityCommands) TryDespawn() {
wasm_import_method_entity_commands_try_despawn((self).Handle())
}
func wasm_import_method_query_iter(arg0 int32, arg1 uintptr)
func (self *Query) Iter() witTypes.Option[*QueryResult] {
pinner := &runtime.Pinner{}
defer pinner.Unpin()
returnArea := uintptr(witRuntime.Allocate(pinner, 8, 4))
wasm_import_method_query_iter((self).Handle(), returnArea)
var option witTypes.Option[*QueryResult]
switch uint8(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))) {
case 0:
option = witTypes.None[*QueryResult]()
case 1:
option = witTypes.Some[*QueryResult](QueryResultFromOwnHandle(int32(uintptr(*(*int32)(unsafe.Add(unsafe.Pointer(returnArea), 4))))))
default:
panic("unreachable")
}
result := option
return result
}
func wasm_import_method_query_result_entity(arg0 int32) int32
func (self *QueryResult) Entity() *Entity {
result := wasm_import_method_query_result_entity((self).Handle())
return EntityFromOwnHandle(int32(uintptr(result)))
}
func wasm_import_method_query_result_component(arg0 int32, arg1 int32) int32
func (self *QueryResult) Component(index uint8) *Component {
result := wasm_import_method_query_result_component((self).Handle(), int32(index))
return ComponentFromOwnHandle(int32(uintptr(result)))
}
func wasm_import_method_component_get(arg0 int32, arg1 uintptr)
func (self *Component) Get() string {
pinner := &runtime.Pinner{}
defer pinner.Unpin()
returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
wasm_import_method_component_get((self).Handle(), returnArea)
value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
result := value
return result
}
func wasm_import_method_component_set(arg0 int32, arg1 uintptr, arg2 uint32)
func (self *Component) Set(value string) {
pinner := &runtime.Pinner{}
defer pinner.Unpin()
utf8 := unsafe.Pointer(unsafe.StringData(value))
pinner.Pin(utf8)
wasm_import_method_component_set((self).Handle(), uintptr(utf8), uint32(len(value)))
}
func wasm_import_method_component_invoke(arg0 int32, arg1 uintptr, arg2 uint32, arg3 uintptr, arg4 uint32, arg5 uintptr)
func (self *Component) Invoke(method string, params string) string {
pinner := &runtime.Pinner{}
defer pinner.Unpin()
returnArea := uintptr(witRuntime.Allocate(pinner, (2 * 4), 4))
utf8 := unsafe.Pointer(unsafe.StringData(method))
pinner.Pin(utf8)
utf80 := unsafe.Pointer(unsafe.StringData(params))
pinner.Pin(utf80)
wasm_import_method_component_invoke((self).Handle(), uintptr(utf8), uint32(len(method)), uintptr(utf80), uint32(len(params)), returnArea)
value := unsafe.String((*uint8)(unsafe.Pointer(uintptr(*(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 0))))), *(*uint32)(unsafe.Add(unsafe.Pointer(returnArea), 4)))
result := value
return result
}