Debian Codegraph @

platform/android/editor/editor_utils_jni.cpp

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