ark-api-ffi 0.17.0-pre.15

Ark low-level Wasm FFI API
Documentation
define_api_id!(0x1df7_daa6_26c6_0ecc, "world-v1");

pub use crate::world_v0::ComponentType;
pub use crate::world_v0::EntityHandle;
pub use crate::world_v0::ValueType;
use bytemuck::CheckedBitPattern;
use bytemuck::NoUninit;
use bytemuck::Pod;
use bytemuck::Zeroable;

pub type DataHandle = u64;

/// Describes what a component parameter is or what it is used for.
///
/// Useful for doing ui or serialization of data.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[repr(u32)]
#[non_exhaustive]
pub enum ParameterSemantic {
    Unspecified = 0,
    EntityHandle = 1,
    // Deprecated 2021-11-08 in favor of DataHandle
    //MeshHandle = 2,
    Position = 3,
    Scale = 4,
    Rotation = 5,
    Color = 6,
    MeshStyleFlags = 7,
    DynamicLockFlags = 8,
    // 9 used to be CharacterCollisionFlags
    JointType = 10,
    JointLimitType = 11,
    NormalizedDirection = 12,
    Direction = 13,
    Bitmask = 15,
    CameraProjectionMode = 16,
    AngleDegrees = 17,
    DataHandle = 18,
    Count = 19,
}

/// Struct describing a specific parameter of a component.
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct ParameterMetaDataEntry {
    pub parameter_id: u32,
    pub name: DataHandle, // Points to string
    pub value_type: ValueType,

    pub semantic: ParameterSemantic,
    // Add this here for any future per semantic / type info, such as ranges / enum names. Will usually be invalid.
    pub size_semantic_data_entry: u32,
    pub semantic_data: DataHandle,
}

/// Struct describing a specific component.
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct ComponentMetaDataEntry {
    pub component_type: ComponentType,
    pub name: DataHandle,          // Points to string
    pub size_parameter_entry: u32, // Used for sanity checking "version" and calculate num elements
    pub parameters: DataHandle,
}

/// Struct describing all components
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct ComponentsMetaDataEntry {
    pub size_component_entry: u32, // Used for sanity checking "version" and calculate num elements
    pub components: DataHandle,
}

/// Type describing what entities a `WorldEntityQuery` should start with.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, NoUninit, CheckedBitPattern)]
#[repr(u32)]
#[non_exhaustive]
pub enum WorldEntityQueryType {
    AllEntities = 0,
    TransformChildren = 1,
    TransformDescendants = 2,
    AllEntitiesNoLayerFilter = 3,
    TransformChildrenNoLayerFilter = 4,
    TransformDescendantsNoLayerFilter = 5,
}

/// Struct describing a query for entities in the world.
///
/// A query with `layer_mask` = !0u64, `num_include_tags` = 0, `num_exclude_tags` = 0,
/// will mean all the entities in the world.
/// Retrieving output of the data will get all the entities the query results in.
#[derive(Debug, Copy, Clone, NoUninit, CheckedBitPattern)]
#[repr(C)]
pub struct WorldEntityQuery {
    /// What layers to include
    pub layer_mask: u64,

    /// Number of tags to include
    pub num_include_tags: u8,

    /// Number of tags to exclude
    pub num_exclude_tags: u8,

    pub _pad0: [u8; 6],

    // Storage for the tags to include
    pub include_tags: [u64; 16],

    // Storage for the tags to exclude
    pub exclude_tags: [u64; 16],

    pub query_type: WorldEntityQueryType,

    pub _pad1: u32,

    pub root_entity: EntityHandle,
}

#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct PhysicsShapeBox {
    pub center: [f32; 3],
    pub half_size: [f32; 3],
    pub rotation: [f32; 4],
}

#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct PhysicsShapeSphere {
    pub center: [f32; 3],
    pub radius: f32,
}

#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct PhysicsShapeCapsule {
    pub pos0: [f32; 3],
    pub pos1: [f32; 3],
    pub radius: f32,
}

#[derive(Debug, Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct CompoundPhysicsShape {
    pub num_boxes: u32,
    pub boxes_ptr: u32,
    pub num_spheres: u32,
    pub spheres_ptr: u32,
    pub num_capsules: u32,
    pub capsules_ptr: u32,
}