kitgit

tirbofish/dropbear · commit

481ea184b272ab0d614c99b38e45308c441674eb

fix: scripting, runtime/play mode works now :)

Unverified

Thribhu K <4tkbytes@pm.me> · 2026-02-18 08:01

view full diff

diff --git a/crates/eucalyptus-core/src/ptr.rs b/crates/eucalyptus-core/src/ptr.rs
index 1bf3a60..87a9860 100644
--- a/crates/eucalyptus-core/src/ptr.rs
+++ b/crates/eucalyptus-core/src/ptr.rs
@@ -1,6 +1,7 @@
 //! Helper pointers and typedef definitions.
 
 use std::sync::Arc;
+use std::ffi::c_void;
 use crate::input::InputState;
 use crate::command::CommandBuffer;
 use crossbeam_channel::Sender;
@@ -52,4 +53,9 @@ pub type SceneLoaderUnwrapped = Mutex<SceneLoader>;
 /// A mutable pointer to a [`PhysicsState`].
 ///
 /// Defined in `dropbear_common.h` as `PhysicsEngine`
-pub type PhysicsStatePtr = *mut PhysicsState;
\ No newline at end of file
+pub type PhysicsStatePtr = *mut PhysicsState;
+
+/// A mutable pointer to the UI command buffer/state.
+///
+/// This is treated as an opaque pointer by scripting layers.
+pub type UiBufferPtr = *mut c_void;
\ No newline at end of file
diff --git a/crates/eucalyptus-core/src/scripting.rs b/crates/eucalyptus-core/src/scripting.rs
index 5c9590f..d48bcac 100644
--- a/crates/eucalyptus-core/src/scripting.rs
+++ b/crates/eucalyptus-core/src/scripting.rs
@@ -12,7 +12,7 @@ pub static JVM_ARGS: OnceLock<String> = OnceLock::new();
 pub static AWAIT_JDB: OnceLock<bool> = OnceLock::new();
 
 use std::sync::OnceLock;
-use crate::ptr::{AssetRegistryPtr, CommandBufferPtr, GraphicsContextPtr, InputStatePtr, PhysicsStatePtr, SceneLoaderPtr, WorldPtr};
+use crate::ptr::{AssetRegistryPtr, CommandBufferPtr, GraphicsContextPtr, InputStatePtr, PhysicsStatePtr, SceneLoaderPtr, UiBufferPtr, WorldPtr};
 use crate::scripting::jni::JavaContext;
 use crate::scripting::native::NativeLibrary;
 use crate::states::{Script};
@@ -221,6 +221,7 @@ impl ScriptManager {
         graphics: CommandBufferPtr,
         graphics_context: GraphicsContextPtr,
         physics_state: PhysicsStatePtr,
+        ui_buffer: UiBufferPtr,
     ) -> anyhow::Result<()> {
         let assets = &raw const *ASSET_REGISTRY;
         let scene_loader = &raw const *SCENE_LOADER;
@@ -233,6 +234,7 @@ impl ScriptManager {
             assets,
             scene_loader,
             physics_state,
+            ui_buffer,
         };
 
         if world.is_null() { log::error!("World pointer is null"); }
@@ -242,6 +244,7 @@ impl ScriptManager {
         if assets.is_null() { log::error!("AssetRegistry pointer is null"); }
         if scene_loader.is_null() { log::error!("SceneLoader pointer is null"); }
         if physics_state.is_null() { log::error!("PhysicsState pointer is null"); }
+        if ui_buffer.is_null() { log::error!("UiBuffer pointer is null"); }
 
         match &self.script_target {
             ScriptTarget::JVM { .. } => {
@@ -968,4 +971,5 @@ pub struct DropbearContext {
     pub assets: AssetRegistryPtr,
     pub scene_loader: SceneLoaderPtr,
     pub physics_state: PhysicsStatePtr,
+    pub ui_buffer: UiBufferPtr,
 }
\ No newline at end of file
diff --git a/crates/eucalyptus-core/src/scripting/jni.rs b/crates/eucalyptus-core/src/scripting/jni.rs
index 319aea5..970875a 100644
--- a/crates/eucalyptus-core/src/scripting/jni.rs
+++ b/crates/eucalyptus-core/src/scripting/jni.rs
@@ -287,6 +287,7 @@ impl JavaContext {
             let asset_handle = context.assets as jlong;
             let scene_loader_handle = context.scene_loader as jlong;
             let physics_handle = context.physics_state as jlong;
+            let ui_handle = context.ui_buffer as jlong;
 
             let args = [
                 JValue::Long(world_handle),
@@ -296,6 +297,7 @@ impl JavaContext {
                 JValue::Long(asset_handle),
                 JValue::Long(scene_loader_handle),
                 JValue::Long(physics_handle),
+                JValue::Long(ui_handle),
             ];
 
             let mut sig = String::from("(");
diff --git a/crates/redback-runtime/src/lib.rs b/crates/redback-runtime/src/lib.rs
index 7f3623a..5d128eb 100644
--- a/crates/redback-runtime/src/lib.rs
+++ b/crates/redback-runtime/src/lib.rs
@@ -20,7 +20,7 @@ use eucalyptus_core::input::InputState;
 use eucalyptus_core::scripting::{ScriptManager, ScriptTarget};
 use eucalyptus_core::states::{WorldLoadingStatus, SCENES, Script};
 use eucalyptus_core::scene::loading::{SceneLoadResult, SCENE_LOADER};
-use eucalyptus_core::ptr::{CommandBufferPtr, GraphicsContextPtr, InputStatePtr, PhysicsStatePtr, WorldPtr};
+use eucalyptus_core::ptr::{CommandBufferPtr, GraphicsContextPtr, InputStatePtr, PhysicsStatePtr, UiBufferPtr, WorldPtr};
 use eucalyptus_core::command::COMMAND_BUFFER;
 use eucalyptus_core::scene::loading::IsSceneLoaded;
 use std::collections::HashMap;
@@ -285,10 +285,22 @@ impl PlayMode {
         let graphics_ptr = COMMAND_BUFFER.0.as_ref() as CommandBufferPtr;
         let graphics_context_ptr = Arc::as_ptr(&graphics) as GraphicsContextPtr;
         let physics_ptr = self.physics_state.as_mut() as PhysicsStatePtr;
+        let ui_ptr = self
+            .kino
+            .as_mut()
+            .map(|kino| kino as *mut KinoState as UiBufferPtr)
+            .unwrap_or(std::ptr::null_mut());
         
         if let Err(e) = self
             .script_manager
-            .load_script(world_ptr, input_ptr, graphics_ptr, graphics_context_ptr, physics_ptr)
+            .load_script(
+                world_ptr,
+                input_ptr,
+                graphics_ptr,
+                graphics_context_ptr,
+                physics_ptr,
+                ui_ptr,
+            )
         {
             panic!("Failed to load scripts: {}", e);
         } else {
diff --git a/include/dropbear.h b/include/dropbear.h
index 267f432..d0051ff 100644
--- a/include/dropbear.h
+++ b/include/dropbear.h
@@ -179,7 +179,37 @@ typedef struct NShapeCastStatusFfi {
 
 typedef NShapeCastStatusFfi NShapeCastStatus;
 
-typedef void* AssetRegistryPtr;
+typedef void* PhysicsStatePtr;
+
+typedef struct NVector2 {
+    double x;
+    double y;
+} NVector2;
+
+typedef struct i32Array {
+    int32_t* values;
+    size_t length;
+    size_t capacity;
+} i32Array;
+
+typedef struct NNodeTransform {
+    NVector3 translation;
+    NQuaternion rotation;
+    NVector3 scale;
+} NNodeTransform;
+
+typedef struct NNode {
+    const char* name;
+    const int32_t* parent;
+    i32Array children;
+    NNodeTransform transform;
+} NNode;
+
+typedef struct NNodeArray {
+    NNode* values;
+    size_t length;
+    size_t capacity;
+} NNodeArray;
 
 typedef struct IndexNative {
     uint32_t index;
@@ -191,6 +221,50 @@ typedef struct RigidBodyContext {
     uint64_t entity_id;
 } RigidBodyContext;
 
+typedef struct f64ArrayArray {
+    double* values;
+    size_t length;
+    size_t capacity;
+} f64ArrayArray;
+
+typedef struct NSkin {
+    const char* name;
+    i32Array joints;
+    f64ArrayArray inverse_bind_matrices;
+    const int32_t* skeleton_root;
+} NSkin;
+
+typedef struct NSkinArray {
+    NSkin* values;
+    size_t length;
+    size_t capacity;
+} NSkinArray;
+
+typedef struct NTransform {
+    NVector3 position;
+    NQuaternion rotation;
+    NVector3 scale;
+} NTransform;
+
+typedef struct u64Array {
+    uint64_t* values;
+    size_t length;
+    size_t capacity;
+} u64Array;
+
+typedef struct NCollider {
+    IndexNative index;
+    uint64_t entity_id;
+    uint32_t id;
+} NCollider;
+
+typedef struct RayHit {
+    NCollider collider;
+    double distance;
+} RayHit;
+
+typedef void* GraphicsContextPtr;
+
 typedef struct IndexNativeArray {
     IndexNative* values;
     size_t length;
@@ -202,42 +276,33 @@ typedef struct CharacterCollisionArray {
     IndexNativeArray collisions;
 } CharacterCollisionArray;
 
-typedef struct f64Array {
-    double* values;
-    size_t length;
-    size_t capacity;
-} f64Array;
+typedef struct Progress {
+    size_t current;
+    size_t total;
+    const char* message;
+} Progress;
 
-typedef struct NAnimationChannel {
-    int32_t target_node;
-    f64Array times;
-    NChannelValues values;
-    NAnimationInterpolation interpolation;
-} NAnimationChannel;
+typedef struct NAttenuation {
+    float constant;
+    float linear;
+    float quadratic;
+} NAttenuation;
 
-typedef struct NAnimationChannelArray {
-    NAnimationChannel* values;
+typedef struct NColliderArray {
+    NCollider* values;
     size_t length;
     size_t capacity;
-} NAnimationChannelArray;
+} NColliderArray;
 
-typedef struct NAnimation {
-    const char* name;
-    NAnimationChannelArray channels;
-    float duration;
-} NAnimation;
+typedef void* WorldPtr;
 
-typedef struct NAnimationArray {
-    NAnimation* values;
-    size_t length;
-    size_t capacity;
-} NAnimationArray;
+typedef void* CommandBufferPtr;
 
-typedef struct NCollider {
-    IndexNative index;
-    uint64_t entity_id;
-    uint32_t id;
-} NCollider;
+typedef struct ConnectedGamepadIds {
+    u64Array ids;
+} ConnectedGamepadIds;
+
+typedef void* InputStatePtr;
 
 typedef struct NShapeCastHit {
     NCollider collider;
@@ -249,15 +314,12 @@ typedef struct NShapeCastHit {
     NShapeCastStatus status;
 } NShapeCastHit;
 
-typedef struct u64Array {
-    uint64_t* values;
-    size_t length;
-    size_t capacity;
-} u64Array;
-
-typedef struct ConnectedGamepadIds {
-    u64Array ids;
-} ConnectedGamepadIds;
+typedef struct NColour {
+    uint8_t r;
+    uint8_t g;
+    uint8_t b;
+    uint8_t a;
+} NColour;
 
 typedef struct NVector4 {
     double x;
@@ -266,16 +328,34 @@ typedef struct NVector4 {
     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 i32Array {
-    int32_t* values;
+typedef struct NMaterialArray {
+    NMaterial* values;
     size_t length;
     size_t capacity;
-} i32Array;
+} NMaterialArray;
+
+typedef struct NRange {
+    float start;
+    float end;
+} NRange;
 
 typedef struct NModelVertex {
     NVector3 position;
@@ -307,77 +387,40 @@ typedef struct NMeshArray {
     size_t capacity;
 } NMeshArray;
 
-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 NNodeTransform {
-    NVector3 translation;
-    NQuaternion rotation;
-    NVector3 scale;
-} NNodeTransform;
-
-typedef struct NNode {
-    const char* name;
-    const int32_t* parent;
-    i32Array children;
-    NNodeTransform transform;
-} NNode;
-
-typedef struct NNodeArray {
-    NNode* values;
+typedef struct f64Array {
+    double* values;
     size_t length;
     size_t capacity;
-} NNodeArray;
-
-typedef void* SceneLoaderPtr;
+} f64Array;
 
-typedef void* CommandBufferPtr;
+typedef struct NAnimationChannel {
+    int32_t target_node;
+    f64Array times;
+    NChannelValues values;
+    NAnimationInterpolation interpolation;
+} NAnimationChannel;
 
-typedef struct f64ArrayArray {
-    double* values;
+typedef struct NAnimationChannelArray {
+    NAnimationChannel* values;
     size_t length;
     size_t capacity;
-} f64ArrayArray;
+} NAnimationChannelArray;
 
-typedef struct NSkin {
+typedef struct NAnimation {
     const char* name;
-    i32Array joints;
-    f64ArrayArray inverse_bind_matrices;
-    const int32_t* skeleton_root;
-} NSkin;
+    NAnimationChannelArray channels;
+    float duration;
+} NAnimation;
 
-typedef struct NSkinArray {
-    NSkin* values;
+typedef struct NAnimationArray {
+    NAnimation* values;
     size_t length;
     size_t capacity;
-} NSkinArray;
+} NAnimationArray;
 
-typedef struct NAttenuation {
-    float constant;
-    float linear;
-    float quadratic;
-} NAttenuation;
+typedef void* AssetRegistryPtr;
+
+typedef void* SceneLoaderPtr;
 
 typedef struct AxisLock {
     bool x;
@@ -385,49 +428,6 @@ typedef struct AxisLock {
     bool z;
 } AxisLock;
 
-typedef struct Progress {
-    size_t current;
-    size_t total;
-    const char* message;
-} Progress;
-
-typedef void* WorldPtr;
-
-typedef struct NRange {
-    float start;
-    float end;
-} NRange;
-
-typedef void* PhysicsStatePtr;
-
-typedef struct NTransform {
-    NVector3 position;
-    NQuaternion rotation;
-    NVector3 scale;
-} NTransform;
-
-typedef void* GraphicsContextPtr;
-
-typedef struct NColour {
-    uint8_t r;
-    uint8_t g;
-    uint8_t b;
-    uint8_t a;
-} NColour;
-
-typedef void* InputStatePtr;
-
-typedef struct NColliderArray {
-    NCollider* values;
-    size_t length;
-    size_t capacity;
-} NColliderArray;
-
-typedef struct RayHit {
-    NCollider collider;
-    double distance;
-} RayHit;
-
 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);
 int32_t dropbear_gamepad_get_right_stick_position(InputStatePtr input, uint64_t gamepad_id, NVector2* out0);