kitgit

tirbofish/dropbear · commit

82a4473659641fa9cfa843031a5e07fae670b46c

attempting hybrid solution: jvm for dev build, native for prod build.

Unverified

tk <4tkbytes@pm.me> · 2025-10-02 11:57

view full diff

diff --git a/.run/eucalyptus-editor.run.xml b/.run/eucalyptus-editor.run.xml
new file mode 100644
index 0000000..6cec2ad
--- /dev/null
+++ b/.run/eucalyptus-editor.run.xml
@@ -0,0 +1,20 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="eucalyptus-editor" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
+    <option name="buildProfileId" value="dev" />
+    <option name="command" value="run" />
+    <option name="workingDirectory" value="file://$PROJECT_DIR$" />
+    <envs />
+    <option name="emulateTerminal" value="true" />
+    <option name="channel" value="DEFAULT" />
+    <option name="requiredFeatures" value="true" />
+    <option name="allFeatures" value="false" />
+    <option name="withSudo" value="false" />
+    <option name="buildTarget" value="REMOTE" />
+    <option name="backtrace" value="SHORT" />
+    <option name="isRedirectInput" value="false" />
+    <option name="redirectInputPath" value="" />
+    <method v="2">
+      <option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
+    </method>
+  </configuration>
+</component>
\ No newline at end of file
diff --git a/.run/generateJniHeaders.run.xml b/.run/generateJniHeaders.run.xml
deleted file mode 100644
index acc9512..0000000
--- a/.run/generateJniHeaders.run.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<component name="ProjectRunConfigurationManager">
-  <configuration default="false" name="generateJniHeaders" type="GradleRunConfiguration" factoryName="Gradle">
-    <ExternalSystemSettings>
-      <option name="executionName" />
-      <option name="externalProjectPath" value="$PROJECT_DIR$" />
-      <option name="externalSystemIdString" value="GRADLE" />
-      <option name="scriptParameters" value="" />
-      <option name="taskDescriptions">
-        <list />
-      </option>
-      <option name="taskNames">
-        <list>
-          <option value="generateJniHeaders" />
-        </list>
-      </option>
-      <option name="vmOptions" />
-    </ExternalSystemSettings>
-    <ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
-    <ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
-    <DebugAllEnabled>false</DebugAllEnabled>
-    <RunAsTest>false</RunAsTest>
-    <method v="2" />
-  </configuration>
-</component>
\ No newline at end of file
diff --git a/eucalyptus-core/Cargo.toml b/eucalyptus-core/Cargo.toml
index c2122bd..202141c 100644
--- a/eucalyptus-core/Cargo.toml
+++ b/eucalyptus-core/Cargo.toml
@@ -27,6 +27,7 @@ tokio.workspace = true
 rayon.workspace = true
 jni.workspace = true
 lazy_static = "1.5.0"
+crossbeam-channel = "0.5.15"
 
 [features]
 editor = []
diff --git a/eucalyptus-core/src/scripting.rs b/eucalyptus-core/src/scripting.rs
index d3907e5..0475600 100644
--- a/eucalyptus-core/src/scripting.rs
+++ b/eucalyptus-core/src/scripting.rs
@@ -8,7 +8,7 @@ use std::path::PathBuf;
 use std::{collections::HashMap, fs};
 use crate::scripting::java::JavaContext;
 
-pub const TEMPLATE_SCRIPT: &str = include_str!("../../resources/scripting/swift/sample.swift");
+pub const TEMPLATE_SCRIPT: &str = include_str!("../../resources/scripting/kotlin/Template.kt");
 
 #[derive(Clone)]
 pub struct DropbearScriptingAPIContext {
@@ -81,9 +81,21 @@ impl DropbearScriptingAPIContext {
     }
 }
 
+/// A message from Kotlin that gets sent to Rust
+pub enum KotlinMessage {
+
+}
+
+/// A message from Rust that gets sent to Kotlin
+pub enum RustMessage {
+
+}
+
 pub struct ScriptManager {
     script_context: DropbearScriptingAPIContext,
     java: JavaContext,
+    from_kotlin: crossbeam_channel::Receiver<KotlinMessage>,
+    to_kotlin: crossbeam_channel::Sender<RustMessage>,
 }
 
 impl ScriptManager {
diff --git a/eucalyptus-core/src/scripting/java.rs b/eucalyptus-core/src/scripting/java.rs
index 0b18927..62b3c3c 100644
--- a/eucalyptus-core/src/scripting/java.rs
+++ b/eucalyptus-core/src/scripting/java.rs
@@ -1,4 +1,5 @@
-use jni::{InitArgsBuilder, JNIVersion, JavaVM};
+use jni::{InitArgsBuilder, JNIEnv, JNIVersion, JavaVM};
+use jni::objects::{JObject, JString};
 
 /// A dropbear wrapper for Java Virtual Machine (JVM) based functions
 pub(crate) struct JavaContext {
@@ -6,6 +7,7 @@ pub(crate) struct JavaContext {
 }
 
 impl JavaContext {
+    /// Creates a new [`JavaContext`]
     pub fn new() -> anyhow::Result<Self> {
         let jvm_args = InitArgsBuilder::new()
             .version(JNIVersion::V8)
@@ -17,4 +19,25 @@ impl JavaContext {
             jvm
         })
     }
+}
+
+// JNIEXPORT jstring JNICALL Java_com_dropbear_ffi_NativeEngine_Ping
+//    (JNIEnv *, jobject, jstring);
+#[unsafe(no_mangle)]
+#[allow(non_snake_case)]
+pub extern "system" fn Java_com_dropbear_ffi_NativeEngine_Ping<'local>(
+    mut env: JNIEnv<'local>,
+    _this: JObject<'local>,
+    input: JString<'local>,
+) -> JString<'local> {
+    let message: String = env.get_string(&input)
+        .expect("Failed to get input string")
+        .into();
+
+    let response = format!("Pong! You sent: {}", message);
+
+    let output = env.new_string(response)
+        .expect("Failed to create output string");
+
+    output.into()
 }
\ No newline at end of file
diff --git a/eucalyptus-editor/src/menu.rs b/eucalyptus-editor/src/menu.rs
index 4891811..02938ee 100644
--- a/eucalyptus-editor/src/menu.rs
+++ b/eucalyptus-editor/src/menu.rs
@@ -79,7 +79,7 @@ impl MainMenu {
             let folders = [
                 ("git", 0.1, "Initialising git repository..."),
                 ("src", 0.2, "Creating src folder..."),
-                ("swift", 0.25, "Initialising Swift project"),
+                // ("swift", 0.25, "Initialising Swift project"),
                 ("resources/models", 0.3, "Creating models folder..."),
                 ("resources/shaders", 0.4, "Creating shaders folder..."),
                 ("resources/textures", 0.5, "Creating textures folder..."),
@@ -116,14 +116,14 @@ impl MainMenu {
                             *global = config;
                             Ok(())
                         }
-                        "swift" => {
-                            let package_template = include_str!("../../resources/scripting/swift/Build.swift");
-                            let package_template = package_template.replace("skibidi_toilet_goon_maxx", &project_name);
-                            // do not ask my why i chose skibidi_toilet_goon_maxx, it was just the first word i came up with. 
-                            std::fs::write(path.join("Package.swift"), package_template)?;
-
-                            Ok(())
-                        }
+                        // "swift" => {
+                        //     let package_template = include_str!("../../resources/scripting/swift/Build.swift");
+                        //     let package_template = package_template.replace("skibidi_toilet_goon_maxx", &project_name);
+                        //     // do not ask my why i chose skibidi_toilet_goon_maxx, it was just the first word i came up with. 
+                        //     std::fs::write(path.join("Package.swift"), package_template)?;
+                        // 
+                        //     Ok(())
+                        // }
                         _ => {
                             if !full_path.exists() {
                                 fs::create_dir_all(&full_path)
diff --git a/resources/scripting/kotlin/Template.kt b/resources/scripting/kotlin/Template.kt
new file mode 100644
index 0000000..97e2201
--- /dev/null
+++ b/resources/scripting/kotlin/Template.kt
@@ -0,0 +1,11 @@
+import com.dropbear
+
+class Example(override var engine: DropbearEngine) : RunnableScript {
+    override fun load() {
+        TODO("Not yet implemented")
+    }
+
+    override fun update() {
+        TODO("Not yet implemented")
+    }
+}
\ No newline at end of file
diff --git a/resources/scripting/swift/Build.swift b/resources/scripting/swift/Build.swift
deleted file mode 100644
index 1ea84fa..0000000
--- a/resources/scripting/swift/Build.swift
+++ /dev/null
@@ -1,30 +0,0 @@
-// swift-tools-version: 6.2
-
-// Build system file for the dropbear-engine scripting API
-
-import PackageDescription
-
-let package = Package(
-    name: "skibidi_toilet_goon_maxx",
-    products: [
-        .library(
-            name: "skibidi_toilet_goon_maxx",
-            type: .dynamic, // required as it will be linked to the final executable
-            targets: ["skibidi_toilet_goon_maxx"]
-        ),
-    ],
-    dependencies: [
-        // add your own dependencies here!
-        // .package(url: "https://github.com/4tkbytes/dropbear", from: "0.0.0")
-    ],
-    targets: [
-        .target(
-            name: "skibidi_toilet_goon_maxx",
-            path: "src",
-            exclude: [
-                // exclude other items here
-                "source.eucc"
-            ]
-        ),
-    ]
-)
diff --git a/resources/scripting/swift/sample.swift b/resources/scripting/swift/sample.swift
deleted file mode 100644
index 7c22d79..0000000
--- a/resources/scripting/swift/sample.swift
+++ /dev/null
@@ -1,14 +0,0 @@
-// dropbear engine script example, make the necessary changes
-
-import dropbear
-
-@ScriptEntry
-class ChangeMyName: BaseScript {
-    override func onLoad() {
-        print("It's alive! It's alive! It's alive, it's alive, IT'S ALIVE!")
-    }
-
-    override func onUpdate(dt: Float) {
-        print("And it's running at: \(1/dt) FPS?")
-    }
-}
\ No newline at end of file
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 2f9554a..5354fc0 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -1,4 +1,4 @@
 plugins {
     id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
 }
-rootProject.name = "com.dropbear"
\ No newline at end of file
+rootProject.name = "dropbear"
\ No newline at end of file
diff --git a/src/main/kotlin/com/dropbear/ffi/NativeEngine.java b/src/main/kotlin/com/dropbear/ffi/NativeEngine.java
index fbb19da..bbedb38 100644
--- a/src/main/kotlin/com/dropbear/ffi/NativeEngine.java
+++ b/src/main/kotlin/com/dropbear/ffi/NativeEngine.java
@@ -13,5 +13,10 @@ public class NativeEngine {
      * @return The {@link Transform} component if the entity exists, null if not.
      */
     public native Transform getTransformOfEntity(String label);
+
+    /**
+     * Fetches the label of the entity this script is currently attached to.
+     * @return The label of the attached entity or null if its not attached
+     */
     public native String getLabelOfAttachedEntity();
 }