lyra-wasm-scripting-test/guests/csharp/dotnet-guest-test/wit/deps/lyraapi/ecs.wit

96 lines
3.4 KiB
Plaintext

package lyra:api;
interface ecs {
record entity-id {
id: u64,
}
record entity {
id: entity-id,
generation: u64,
}
record wasm-type-id {
// represents a u128, can be converted into that with mem::transmute
inner: tuple<u64, u64>,
}
record component-info {
host-name: option<string>,
/// The size of the component in memory.
size: u64,
/// The alignment of the component in memory.
alignment: u64,
/// The type id of the component.
///
/// This must be unique between component types since its used to identify the components
/// in spawning and querying.
type-id: wasm-type-id,
}
resource ecs-dynamic-view {
constructor(wrld: borrow<ecs-world>, component-infos: list<component-info>);
/// Get the bytes of the next row in the view.
///
/// A row contains multiple component serialized as bytes. The buffer is tighly packed.
next: func() -> option<tuple<entity, list<u8>>>;
}
/// An resource that can be "downcasted" to a specific type.
///
/// You can use `T.from-ecs-resource` to "downcast" the type
resource ecs-resource {
}
variant world-resource-result {
none,
wasm-resource(ecs-resource),
bytes(list<u8>),
}
resource ecs-world {
constructor();
/// Spawn an entity.
///
/// Parameters:
/// * `components`: A tightly packed byte buffer containing the components to spawn
/// with the entity. This expects the components in the same order of `component-infos`.
/// * `component-infos`: A list of `component-infos` uses to identify the components
/// and specify the layouts of them.
spawn: func(components: list<u8>, component-infos: list<component-info>) -> entity;
/// Insert components into an existing entity.
///
/// Parameters:
/// * `en`: The entity to insert into.
/// * `components`: A tightly packed byte buffer containing the components to spawn
/// with the entity. This expects the components in the same order of `component-infos`.
/// * `component-infos`: A list of `component-infos` uses to identify the components
/// and specify the layouts of them.
insert: func(en: entity, components: list<u8>, component-infos: list<component-info>);
/// Query for a list of entities and their components.
///
/// Parameters:
/// * `component-infos`: The `component-info`'s of the components that you are querying.
///
/// Returns: an iterator that returns the byte buffers of each row.
view: func(component-infos: list<component-info>) -> ecs-dynamic-view;
/// Query for components from a single entity.
///
/// Parameters:
/// * `en`: The entity to query components from.
/// * `component-infos`: The `component-info`'s of the components that you are querying.
///
/// Returns: A row of components serialized as bytes. The buffer is tighly packed.
view-one: func(en: entity, component-infos: list<component-info>) -> option<list<u8>>;
get-resource: func(type-id: wasm-type-id) -> world-resource-result;
//with_system: func(stage: string, component-infos: list<component-info>, system: func(components: list<u8>));
}
}