tirbofish/dropbear · commit
e6110fc6ffed9403bc908173ce760ee624a38cd4
wip: got doc build working
Signature present but could not be verified.
Unverified
@@ -161,7 +161,7 @@ impl PhysicsState { let mut builder = match &collider_component.shape { ColliderShape::Box { half_extents } => { - ColliderBuilder::cuboid(half_extents[0], half_extents[1], half_extents[2]) + ColliderBuilder::cuboid(half_extents.x as f32, half_extents.y as f32, half_extents.z as f32) } ColliderShape::Sphere { radius } => { ColliderBuilder::ball(*radius) @@ -457,7 +457,7 @@ fn shape_cast( let cast_shape = { match shape { crate::physics::collider::ColliderShape::Box { half_extents } => { - rapier3d::geometry::SharedShape::cuboid(half_extents[0], half_extents[1], half_extents[2]) + rapier3d::geometry::SharedShape::cuboid(half_extents.x as f32, half_extents.y as f32, half_extents.z as f32) } crate::physics::collider::ColliderShape::Sphere { radius } => rapier3d::geometry::SharedShape::ball(*radius), crate::physics::collider::ColliderShape::Capsule { half_height, radius } => { @@ -135,9 +135,9 @@ impl From<&ColliderShape> for ColliderShapeKey { match *shape { ColliderShape::Box { half_extents } => Self::Box { half_extents_bits: [ - half_extents[0].to_bits(), - half_extents[1].to_bits(), - half_extents[2].to_bits(), + half_extents.x.to_bits() as u32, + half_extents.y.to_bits() as u32, + half_extents.z.to_bits() as u32, ], }, ColliderShape::Sphere { radius } => Self::Sphere { @@ -164,7 +164,7 @@ impl From<&ColliderShape> for ColliderShapeKey { #[dropbear_macro::repr_c_enum] pub enum ColliderShape { /// Box shape with half-extents (half-width, half-height, half-depth). - Box { half_extents: [f32; 3] }, + Box { half_extents: NVector3 }, /// Sphere shape with radius. Sphere { radius: f32 }, @@ -182,7 +182,7 @@ pub enum ColliderShape { impl Default for ColliderShape { fn default() -> Self { ColliderShape::Box { - half_extents: [0.5, 0.5, 0.5] + half_extents: NVector3::from([0.5, 0.5, 0.5]) } } } @@ -201,9 +201,9 @@ impl ToJObject for ColliderShape { &vec_cls, "(DDD)V", &[ - JValue::Double(half_extents[0] as f64), - JValue::Double(half_extents[1] as f64), - JValue::Double(half_extents[2] as f64) + JValue::Double(half_extents.x), + JValue::Double(half_extents.y), + JValue::Double(half_extents.z) ] ).map_err(|_| DropbearNativeError::JNIFailedToCreateObject)?; @@ -299,7 +299,7 @@ impl FromJObject for ColliderShape { .map_err(|_| DropbearNativeError::JNIFailedToGetField)?.d().unwrap_or(0.0); return Ok(ColliderShape::Box { - half_extents: [x as f32, y as f32, z as f32] + half_extents: NVector3::from([x as f32, y as f32, z as f32]) }); } @@ -362,7 +362,7 @@ impl Collider { /// Create a box collider pub fn box_collider(half_extents: [f32; 3]) -> Self { Self { - shape: ColliderShape::Box { half_extents }, + shape: ColliderShape::Box { half_extents: NVector3::from(half_extents) }, ..Self::new() } } @@ -430,7 +430,7 @@ impl Collider { pub fn to_rapier(&self) -> rapier3d::prelude::Collider { let shape: ColliderBuilder = match &self.shape { ColliderShape::Box { half_extents } => { - ColliderBuilder::cuboid(half_extents[0], half_extents[1], half_extents[2]) + ColliderBuilder::cuboid(half_extents.x as f32, half_extents.y as f32, half_extents.z as f32) } ColliderShape::Sphere { radius } => { ColliderBuilder::ball(*radius) @@ -675,7 +675,7 @@ fn get_collider_shape( TypedShape::Cuboid(c) => { let he = c.half_extents; ColliderShape::Box { - half_extents: [he.x, he.y, he.z], + half_extents: NVector3::from([he.x, he.y, he.z]), } } TypedShape::Ball(b) => ColliderShape::Sphere { radius: b.radius }, @@ -715,7 +715,7 @@ fn set_collider_shape( let new_shape = match shape { ColliderShape::Box { half_extents } => { - SharedShape::cuboid(half_extents[0], half_extents[1], half_extents[2]) + SharedShape::cuboid(half_extents.x as f32, half_extents.y as f32, half_extents.z as f32) } ColliderShape::Sphere { radius } => SharedShape::ball(*radius), ColliderShape::Capsule { half_height, radius } => { @@ -192,7 +192,7 @@ pub fn create_wireframe_geometry( ) -> WireframeGeometry { match shape { ColliderShape::Box { half_extents } => { - WireframeGeometry::box_wireframe(graphics, *half_extents) + WireframeGeometry::box_wireframe(graphics, half_extents.to_float_array()) } ColliderShape::Sphere { radius } => { WireframeGeometry::sphere_wireframe(graphics, *radius, 16, 16) @@ -66,7 +66,7 @@ impl From<(f64, f64)> for NVector2 { } #[repr(C)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize, PartialEq)] pub struct NVector3 { pub x: f64, pub y: f64, @@ -572,9 +572,7 @@ fn emit_repr_c_enum( for var in &enm.variants { for field in &var.fields { - if is_array_type(&field.ty) { - emit_array_struct(&field.ty, structs, emitted, out); - } + emit_field_type_deps(&field.ty, structs, emitted, out); } } @@ -739,13 +737,7 @@ fn emit_structs_recursive( if let Some(def) = structs.get(name) { for field in &def.fields { - if is_array_type(&field.ty) { - emit_array_struct(&field.ty, structs, emitted, out); - continue; - } - if is_custom_type(&field.ty) { - emit_structs_recursive(&field.ty, structs, emitted, out); - } + emit_field_type_deps(&field.ty, structs, emitted, out); } if !def.is_repr_c { @@ -766,6 +758,29 @@ fn emit_structs_recursive( } } +fn emit_field_type_deps( + field_ty: &str, + structs: &std::collections::HashMap<String, StructDef>, + emitted: &mut std::collections::HashSet<String>, + out: &mut String, +) { + if is_array_type(field_ty) { + emit_array_struct(field_ty, structs, emitted, out); + return; + } + + if let Some(base) = base_type_name(field_ty) { + if is_custom_type(&base) || is_opaque_ptr_name(&base) || is_array_type(&base) { + emit_structs_recursive(&base, structs, emitted, out); + } + return; + } + + if is_custom_type(field_ty) || is_opaque_ptr_name(field_ty) { + emit_structs_recursive(field_ty, structs, emitted, out); + } +} + fn is_array_type(ty: &str) -> bool { ty.ends_with("Array") } @@ -0,0 +1,8 @@ +note to anyone using this header: + +it is not always updated to the latest build. to build one for yourself, just compile +`eucalyptus-core` to generate the header. + + +The header must stay here so the documentation builder dokka is able to create +the package. @@ -16,6 +16,12 @@ typedef enum AssetKind { AssetKind_Model = 1, } AssetKind; +typedef struct NVector3 { + double x; + double y; + double z; +} NVector3; + typedef enum ColliderShapeTag { ColliderShapeTag_Box = 0, ColliderShapeTag_Sphere = 1, @@ -25,7 +31,7 @@ typedef enum ColliderShapeTag { } ColliderShapeTag; typedef struct ColliderShapeBox { - void half_extents; + NVector3 half_extents; } ColliderShapeBox; typedef struct ColliderShapeSphere { @@ -123,12 +129,6 @@ typedef struct NAnimationInterpolationFfi { typedef NAnimationInterpolationFfi NAnimationInterpolation; -typedef struct NVector3 { - double x; - double y; - double z; -} NVector3; - typedef struct NVector3Array { NVector3* values; size_t length; @@ -179,32 +179,84 @@ typedef struct NChannelValuesFfi { typedef NChannelValuesFfi NChannelValues; -typedef struct IndexNative { - uint32_t index; - uint32_t generation; -} IndexNative; +typedef struct f64Array { + double* values; + size_t length; + size_t capacity; +} f64Array; -typedef struct NCollider { - IndexNative index; - uint64_t entity_id; - uint32_t id; -} NCollider; +typedef struct NAnimationChannel { + int32_t target_node; + f64Array times; + NChannelValues values; + NAnimationInterpolation interpolation; +} NAnimationChannel; -typedef struct NShapeCastHit { - NCollider collider; - double distance; - NVector3 witness1; - NVector3 witness2; - NVector3 normal1; - NVector3 normal2; - NShapeCastStatus status; -} NShapeCastHit; +typedef struct NAnimationChannelArray { + NAnimationChannel* values; + size_t length; + size_t capacity; +} NAnimationChannelArray; -typedef struct Progress { - size_t current; - size_t total; - const char* message; -} Progress; +typedef struct NAnimation { + const char* name; + NAnimationChannelArray channels; + float duration; +} NAnimation; + +typedef struct NAnimationArray { + NAnimation* values; + size_t length; + size_t capacity; +} NAnimationArray; + +typedef struct u64Array { + uint64_t* values; + size_t length; + size_t capacity; +} u64Array; + +typedef struct ConnectedGamepadIds { + u64Array ids; +} ConnectedGamepadIds; + +typedef void* InputStatePtr; + +typedef struct NVector4 { + double x; + double y; + double z; + double w; +} NVector4; + +typedef struct NVector2 { + double x; + double y; +} NVector2; + +typedef struct NMaterial { + const char* name; + uint64_t diffuse_texture; + uint64_t normal_texture; + NVector4 tint; + NVector3 emissive_factor; + float metallic_factor; + float roughness_factor; + const float* alpha_cutoff; + bool double_sided; + float occlusion_strength; + float normal_scale; + NVector2 uv_tiling; + const uint64_t* emissive_texture; + const uint64_t* metallic_roughness_texture; + const uint64_t* occlusion_texture; +} NMaterial; + +typedef struct NMaterialArray { + NMaterial* values; + size_t length; + size_t capacity; +} NMaterialArray; typedef struct i32Array { int32_t* values; @@ -231,32 +283,23 @@ typedef struct NSkinArray { size_t capacity; } NSkinArray; -typedef struct NColliderArray { - NCollider* values; +typedef void* GraphicsContextPtr; + +typedef struct IndexNative { + uint32_t index; + uint32_t generation; +} IndexNative; + +typedef struct IndexNativeArray { + IndexNative* values; size_t length; size_t capacity; -} NColliderArray; +} IndexNativeArray; -typedef struct RigidBodyContext { - IndexNative index; +typedef struct CharacterCollisionArray { uint64_t entity_id; -} RigidBodyContext; - -typedef void* InputStatePtr; - -typedef void* AssetRegistryPtr; - -typedef struct NTransform { - NVector3 position; - NQuaternion rotation; - NVector3 scale; -} NTransform; - -typedef struct NAttenuation { - float constant; - float linear; - float quadratic; -} NAttenuation; + IndexNativeArray collisions; +} CharacterCollisionArray; typedef struct NNodeTransform { NVector3 translation; @@ -277,17 +320,60 @@ typedef struct NNodeArray { size_t capacity; } NNodeArray; -typedef struct NVector4 { - double x; - double y; - double z; - double w; -} NVector4; +typedef struct NCollider { + IndexNative index; + uint64_t entity_id; + uint32_t id; +} NCollider; -typedef struct NVector2 { - double x; - double y; -} NVector2; +typedef struct AxisLock { + bool x; + bool y; + bool z; +} AxisLock; + +typedef void* PhysicsStatePtr; + +typedef void* SceneLoaderPtr; + +typedef struct NTransform { + NVector3 position; + NQuaternion rotation; + NVector3 scale; +} NTransform; + +typedef struct NAttenuation { + float constant; + float linear; + float quadratic; +} NAttenuation; + +typedef struct NColliderArray { + NCollider* values; + size_t length; + size_t capacity; +} NColliderArray; + +typedef struct NColour { + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; +} NColour; + +typedef struct NShapeCastHit { + NCollider collider; + double distance; + NVector3 witness1; + NVector3 witness2; + NVector3 normal1; + NVector3 normal2; + NShapeCastStatus status; +} NShapeCastHit; + +typedef void* WorldPtr; + +typedef void* CommandBufferPtr; typedef struct NModelVertex { NVector3 position; @@ -319,114 +405,28 @@ typedef struct NMeshArray { size_t capacity; } NMeshArray; -typedef struct f64Array { - double* values; - size_t length; - size_t capacity; -} f64Array; - -typedef struct NAnimationChannel { - int32_t target_node; - f64Array times; - NChannelValues values; - NAnimationInterpolation interpolation; -} NAnimationChannel; - -typedef struct NAnimationChannelArray { - NAnimationChannel* values; - size_t length; - size_t capacity; -} NAnimationChannelArray; - -typedef struct NAnimation { - const char* name; - NAnimationChannelArray channels; - float duration; -} NAnimation; - -typedef struct NAnimationArray { - NAnimation* values; - size_t length; - size_t capacity; -} NAnimationArray; - -typedef struct IndexNativeArray { - IndexNative* values; - size_t length; - size_t capacity; -} IndexNativeArray; - -typedef struct CharacterCollisionArray { - uint64_t entity_id; - IndexNativeArray collisions; -} CharacterCollisionArray; - -typedef struct u64Array { - uint64_t* values; - size_t length; - size_t capacity; -} u64Array; - -typedef struct ConnectedGamepadIds { - u64Array ids; -} ConnectedGamepadIds; - typedef struct RayHit { NCollider collider; double distance; } RayHit; -typedef void* GraphicsContextPtr; - -typedef void* CommandBufferPtr; - typedef struct NRange { float start; float end; } NRange; -typedef struct AxisLock { - bool x; - bool y; - bool z; -} AxisLock; - -typedef void* SceneLoaderPtr; - -typedef void* WorldPtr; - -typedef struct NColour { - uint8_t r; - uint8_t g; - uint8_t b; - uint8_t a; -} NColour; - -typedef struct NMaterial { - const char* name; - uint64_t diffuse_texture; - uint64_t normal_texture; - NVector4 tint; - NVector3 emissive_factor; - float metallic_factor; - float roughness_factor; - const float* alpha_cutoff; - bool double_sided; - float occlusion_strength; - float normal_scale; - NVector2 uv_tiling; - const uint64_t* emissive_texture; - const uint64_t* metallic_roughness_texture; - const uint64_t* occlusion_texture; -} NMaterial; +typedef struct Progress { + size_t current; + size_t total; + const char* message; +} Progress; -typedef struct NMaterialArray { - NMaterial* values; - size_t length; - size_t capacity; -} NMaterialArray; +typedef void* AssetRegistryPtr; -typedef void* PhysicsStatePtr; +typedef struct RigidBodyContext { + IndexNative index; + uint64_t entity_id; +} RigidBodyContext; int32_t dropbear_gamepad_is_button_pressed(InputStatePtr input, uint64_t gamepad_id, int32_t button_ordinal, bool* out0); int32_t dropbear_gamepad_get_left_stick_position(InputStatePtr input, uint64_t gamepad_id, NVector2* out0); @@ -3,11 +3,11 @@ package com.dropbear.input /** * Buttons that can be pressed on a mouse */ -sealed class MouseButton { - object Left : MouseButton() - object Right : MouseButton() - object Middle : MouseButton() - object Back : MouseButton() - object Forward : MouseButton() - data class Other(val value: Int) : MouseButton() +sealed class MouseButton(val ordinal: Int) { + object Left : MouseButton(0) + object Right : MouseButton(1) + object Middle : MouseButton(2) + object Back : MouseButton(3) + object Forward : MouseButton(4) + data class Other(val value: Int) : MouseButton(value) } @@ -28,7 +28,7 @@ internal actual fun KinematicCharacterController.setRotationNative(rotation: com } internal actual fun KinematicCharacterController.getHitsNative(): List<CharacterCollision> { - return KinematicCharacterControllerNative.getHitNative( + return KinematicCharacterControllerNative.getHit( DropbearEngine.native.worldHandle, entity.raw, ).toList() @@ -3,29 +3,29 @@ package com.dropbear.scene import com.dropbear.DropbearEngine internal actual fun SceneManager.loadSceneAsyncNative(sceneName: String): SceneLoadHandle? { - val result = SceneManagerNative.loadSceneAsyncNative( + val result = SceneManagerNative.loadSceneAsync( DropbearEngine.native.commandBufferHandle, DropbearEngine.native.sceneLoaderHandle, sceneName ) - return if (result != null) SceneLoadHandle(result) else null + return SceneLoadHandle(result) } internal actual fun SceneManager.loadSceneAsyncNative( sceneName: String, loadingScene: String ): SceneLoadHandle? { - val result = SceneManagerNative.loadSceneAsyncNative( + val result = SceneManagerNative.loadSceneAsyncWithLoading( DropbearEngine.native.commandBufferHandle, DropbearEngine.native.sceneLoaderHandle, sceneName, loadingScene ) - return if (result != null) SceneLoadHandle(result) else null + return SceneLoadHandle(result) } internal actual fun SceneManager.switchToSceneImmediateNative(sceneName: String) { - SceneManagerNative.switchToSceneImmediateNative( + SceneManagerNative.switchToSceneImmediate( DropbearEngine.native.commandBufferHandle, sceneName ) @@ -12,6 +12,7 @@ internal actual fun getAsset(eucaURI: String): Long? { } internal actual fun quit() { + } internal actual fun renderUI(instructions: List<UIInstruction>) {