From 3bd825196efdcdefb6114a24cd5454f944740306 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Thu, 4 Apr 2019 12:55:24 -0500 Subject: [PATCH] Get the magicleap immersive mode demo to take a filename argument --- demo/magicleap/src/lib.rs | 8 ++++-- demo/magicleap/src/main.cpp | 50 ++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/demo/magicleap/src/lib.rs b/demo/magicleap/src/lib.rs index b5680569..546ed394 100644 --- a/demo/magicleap/src/lib.rs +++ b/demo/magicleap/src/lib.rs @@ -56,7 +56,7 @@ mod magicleap; mod mocked_c_api; #[no_mangle] -pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context: EGLContext) { +pub unsafe extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context: EGLContext, file_name: *const c_char) { unsafe { c_api::MLLoggingLog(c_api::MLLogLevel::Info, &b"Pathfinder Demo\0"[0], &b"Initializing\0"[0]) }; let tag = CString::new("Pathfinder Demo").unwrap(); @@ -75,7 +75,11 @@ pub extern "C" fn magicleap_pathfinder_demo(egl_display: EGLDisplay, egl_context options.mode = Mode::VR; options.jobs = Some(3); options.pipeline = 0; - + if let Some(file_name) = file_name.as_ref() { + let file_name = CStr::from_ptr(file_name).to_string_lossy().into_owned(); + options.input_path = SVGPath::Resource(file_name); + } + let mut app = DemoApp::new(window, window_size, options); debug!("Initialized app"); diff --git a/demo/magicleap/src/main.cpp b/demo/magicleap/src/main.cpp index 6de3d895..d526e414 100644 --- a/demo/magicleap/src/main.cpp +++ b/demo/magicleap/src/main.cpp @@ -24,12 +24,13 @@ #include #include #include +#include #include #include #include // Entry point to the Rust code -extern "C" MLResult magicleap_pathfinder_demo(EGLDisplay egl_display, EGLContext egl_context); +extern "C" MLResult magicleap_pathfinder_demo(EGLDisplay egl_display, EGLContext egl_context, const char* file_name); // Initialization of the scene thread extern "C" void init_scene_thread(uint64_t id) { @@ -181,13 +182,56 @@ int main() { return -1; } + // Get the file argument if there is one + MLLifecycleInitArgList* arg_list = nullptr; + const MLLifecycleInitArg* arg = nullptr; + const MLFileInfo* file_info = nullptr; + const char* file_name = nullptr; + int64_t arg_list_len = 0; + int64_t file_list_len = 0; + + if (MLResult_Ok != MLLifecycleGetInitArgList(&arg_list)) { + ML_LOG(Error, "%s: Failed to get init args.", application_name); + return -1; + } + + if (MLResult_Ok != MLLifecycleGetInitArgListLength(arg_list, &arg_list_len)) { + ML_LOG(Error, "%s: Failed to get init arg length.", application_name); + return -1; + } + + if (arg_list_len) { + if (MLResult_Ok != MLLifecycleGetInitArgByIndex(arg_list, 0, &arg)) { + ML_LOG(Error, "%s: Failed to get init arg.", application_name); + return -1; + } + + if (MLResult_Ok != MLLifecycleGetFileInfoListLength(arg, &file_list_len)) { + ML_LOG(Error, "%s: Failed to get file list length.", application_name); + return -1; + } + } + + if (file_list_len) { + if (MLResult_Ok != MLLifecycleGetFileInfoByIndex(arg, 0, &file_info)) { + ML_LOG(Error, "%s: Failed to get file info.", application_name); + return -1; + } + + if (MLResult_Ok != MLFileInfoGetFileName(file_info, &file_name)) { + ML_LOG(Error, "%s: Failed to get file name.", application_name); + return -1; + } + } + // Run the demo! - ML_LOG(Info, "%s: Begin demo.", application_name); - MLResult status = magicleap_pathfinder_demo(graphics_context.egl_display, graphics_context.egl_context); + ML_LOG(Info, "%s: Begin demo (%s).", application_name, file_name); + MLResult status = magicleap_pathfinder_demo(graphics_context.egl_display, graphics_context.egl_context, file_name); ML_LOG(Info, "%s: End demo (%d).", application_name, status); // Shut down MLPerceptionShutdown(); + MLLifecycleFreeInitArgList(&arg_list); return 0; }