60 lines
1.9 KiB
Plaintext
60 lines
1.9 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<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;
|
|
|
|
/// 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;
|
|
}
|
|
} |