Path: blob/master/platform/android/editor/editor_utils_jni.cpp
10278 views
/**************************************************************************/1/* editor_utils_jni.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "editor_utils_jni.h"3132#include "jni_utils.h"3334#ifdef TOOLS_ENABLED35#include "editor/debugger/editor_debugger_node.h"36#include "editor/debugger/script_editor_debugger.h"37#include "editor/run/editor_run_bar.h"38#include "main/main.h"39#endif4041extern "C" {42JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_EditorUtils_runScene(JNIEnv *p_env, jclass, jstring p_scene, jobjectArray p_scene_args) {43#ifdef TOOLS_ENABLED44Vector<String> scene_args;45jint length = p_env->GetArrayLength(p_scene_args);46for (jint i = 0; i < length; ++i) {47jstring j_arg = (jstring)p_env->GetObjectArrayElement(p_scene_args, i);48String arg = jstring_to_string(j_arg, p_env);49scene_args.push_back(arg);50p_env->DeleteLocalRef(j_arg);51}5253String scene = jstring_to_string(p_scene, p_env);5455EditorRunBar *editor_run_bar = EditorRunBar::get_singleton();56if (editor_run_bar != nullptr) {57editor_run_bar->stop_playing();58// Ensure that all ScriptEditorDebugger instances are explicitly stopped.59// If not, a closing instance from the previous run session will trigger `_stop_and_notify()`, in turn causing60// the closure of the ScriptEditorDebugger instances of the run session we're about to launch.61EditorDebuggerNode *dbg_node = EditorDebuggerNode::get_singleton();62if (dbg_node != nullptr) {63for (int i = 0; ScriptEditorDebugger *dbg = dbg_node->get_debugger(i); i++) {64dbg->stop();65}66}6768if (scene.is_empty()) {69editor_run_bar->play_main_scene(false);70} else {71editor_run_bar->play_custom_scene(scene, scene_args);72}73} else {74List<String> args;7576for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_PROJECT)) {77args.push_back(a);78}7980for (const String &arg : scene_args) {81args.push_back(arg);82}8384if (!scene.is_empty()) {85args.push_back("--scene");86args.push_back(scene);87}8889Error err = OS::get_singleton()->create_instance(args);90ERR_FAIL_COND(err);91}92#endif93}94}959697