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, } record component-info { host-name: option, /// 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, component-infos: list); /// 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>>; } /// 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), } 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, component-infos: list) -> 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, component-infos: list); /// 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) -> 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) -> option>; get-resource: func(type-id: wasm-type-id) -> world-resource-result; //with_system: func(stage: string, component-infos: list, system: func(components: list)); } }