tirbofish/dropbear · diff
attempting hybrid solution: jvm for dev build, native for prod build.
Signature present but could not be verified.
Unverified
@@ -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> @@ -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> @@ -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 = [] @@ -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 { @@ -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() } @@ -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) @@ -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") + } +} @@ -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" - ] - ), - ] -) @@ -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?") - } -} @@ -1,4 +1,4 @@ plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" } -rootProject.name = "com.dropbear" +rootProject.name = "dropbear" @@ -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(); }