2024-07-27 19:24:14 +00:00
|
|
|
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.
|
2024-09-03 00:59:29 +00:00
|
|
|
next: func() -> option<tuple<entity, list<u8>>>;
|
2024-07-27 19:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-09-03 00:59:29 +00:00
|
|
|
/// 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>);
|
|
|
|
|
2024-07-27 19:24:14 +00:00
|
|
|
/// Query for a list of entities and their components.
|
|
|
|
///
|
|
|
|
/// Parameters:
|
2024-09-03 00:59:29 +00:00
|
|
|
/// * `component-infos`: The `component-info`'s of the components that you are querying.
|
2024-07-27 19:24:14 +00:00
|
|
|
///
|
|
|
|
/// Returns: an iterator that returns the byte buffers of each row.
|
|
|
|
view: func(component-infos: list<component-info>) -> ecs-dynamic-view;
|
|
|
|
|
2024-09-03 00:59:29 +00:00
|
|
|
/// 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>>;
|
|
|
|
|
2024-07-27 19:24:14 +00:00
|
|
|
//with_system: func(stage: string, component-infos: list<component-info>, system: func(components: list<u8>));
|
|
|
|
}
|
|
|
|
}
|