1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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,
    CharacterCollisionFlags = 9,
    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,
}