summaryrefslogtreecommitdiff
path: root/main/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main/main.cpp')
-rw-r--r--main/main.cpp119
1 files changed, 84 insertions, 35 deletions
diff --git a/main/main.cpp b/main/main.cpp
index d67761db55..9e3b5c9ba2 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -34,8 +34,10 @@
#include "core/core_string_names.h"
#include "core/crypto/crypto.h"
#include "core/debugger/engine_debugger.h"
+#include "core/extension/extension_api_dump.h"
#include "core/input/input.h"
#include "core/input/input_map.h"
+#include "core/io/dir_access.h"
#include "core/io/file_access_network.h"
#include "core/io/file_access_pack.h"
#include "core/io/file_access_zip.h"
@@ -43,8 +45,8 @@
#include "core/io/ip.h"
#include "core/io/resource_loader.h"
#include "core/object/message_queue.h"
-#include "core/os/dir_access.h"
#include "core/os/os.h"
+#include "core/os/time.h"
#include "core/register_core_types.h"
#include "core/string/translation.h"
#include "core/version.h"
@@ -101,6 +103,7 @@ static InputMap *input_map = nullptr;
static TranslationServer *translation_server = nullptr;
static Performance *performance = nullptr;
static PackedData *packed_data = nullptr;
+static Time *time_singleton = nullptr;
#ifdef MINIZIP_ENABLED
static ZipArchive *zip_packed_data = nullptr;
#endif
@@ -135,6 +138,7 @@ static int audio_driver_idx = -1;
static bool single_window = false;
static bool editor = false;
static bool project_manager = false;
+static bool cmdline_tool = false;
static String locale;
static bool show_help = false;
static bool auto_quit = false;
@@ -171,7 +175,9 @@ static int frame_delay = 0;
static bool disable_render_loop = false;
static int fixed_fps = -1;
static bool print_fps = false;
-
+#ifdef TOOLS_ENABLED
+static bool dump_extension_api = false;
+#endif
bool profile_gpu = false;
/* Helper methods */
@@ -183,6 +189,10 @@ bool Main::is_project_manager() {
return project_manager;
}
+bool Main::is_cmdline_tool() {
+ return cmdline_tool;
+}
+
static String unescape_cmdline(const String &p_str) {
return p_str.replace("%20", " ");
}
@@ -399,6 +409,8 @@ Error Main::test_setup() {
translation_server = memnew(TranslationServer);
+ register_core_extensions();
+
// From `Main::setup2()`.
preregister_module_types();
preregister_server_types();
@@ -532,6 +544,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
MAIN_PRINT("Main: Initialize Globals");
input_map = memnew(InputMap);
+ time_singleton = memnew(Time);
globals = memnew(ProjectSettings);
register_core_settings(); //here globals are present
@@ -878,18 +891,31 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
auto_build_solutions = true;
editor = true;
-#ifdef DEBUG_METHODS_ENABLED
+ cmdline_tool = true;
+
} else if (I->get() == "--gdnative-generate-json-api" || I->get() == "--gdnative-generate-json-builtin-api") {
// Register as an editor instance to use low-end fallback if relevant.
editor = true;
+ cmdline_tool = true;
// We still pass it to the main arguments since the argument handling itself is not done in this function
main_args.push_back(I->get());
-#endif
+ } else if (I->get() == "--dump-extension-api") {
+ // Register as an editor instance to use low-end fallback if relevant.
+ editor = true;
+ cmdline_tool = true;
+ dump_extension_api = true;
+ print_line("dump extension?");
+ main_args.push_back(I->get());
} else if (I->get() == "--export" || I->get() == "--export-debug" ||
I->get() == "--export-pack") { // Export project
-
+ // Actually handling is done in start().
editor = true;
+ cmdline_tool = true;
+ main_args.push_back(I->get());
+ } else if (I->get() == "--doctool") {
+ // Actually handling is done in start().
+ cmdline_tool = true;
main_args.push_back(I->get());
#endif
} else if (I->get() == "--path") { // set path of project to start or edit
@@ -1122,8 +1148,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
}
if (!project_manager && !editor) {
- // Determine if the project manager should be requested
- project_manager = main_args.size() == 0 && !found_project;
+ // If we didn't find a project, we fall back to the project manager.
+ project_manager = !found_project && !cmdline_tool;
}
#endif
@@ -1183,6 +1209,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->set_cmdline(execpath, main_args);
+ register_core_extensions(); //before display
+
GLOBAL_DEF("rendering/driver/driver_name", "Vulkan");
ProjectSettings::get_singleton()->set_custom_property_info("rendering/driver/driver_name",
PropertyInfo(Variant::STRING,
@@ -1333,13 +1361,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF_BASIC("physics/common/physics_fps", 60));
ProjectSettings::get_singleton()->set_custom_property_info("physics/common/physics_fps",
PropertyInfo(Variant::INT, "physics/common/physics_fps",
- PROPERTY_HINT_RANGE, "1,120,1,or_greater"));
+ PROPERTY_HINT_RANGE, "1,1000,1"));
Engine::get_singleton()->set_physics_jitter_fix(GLOBAL_DEF("physics/common/physics_jitter_fix", 0.5));
Engine::get_singleton()->set_target_fps(GLOBAL_DEF("debug/settings/fps/force_fps", 0));
ProjectSettings::get_singleton()->set_custom_property_info("debug/settings/fps/force_fps",
PropertyInfo(Variant::INT,
"debug/settings/fps/force_fps",
- PROPERTY_HINT_RANGE, "0,120,1,or_greater"));
+ PROPERTY_HINT_RANGE, "0,1000,1"));
GLOBAL_DEF("debug/settings/stdout/print_fps", false);
GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false);
@@ -1402,6 +1430,9 @@ error:
if (input_map) {
memdelete(input_map);
}
+ if (time_singleton) {
+ memdelete(time_singleton);
+ }
if (translation_server) {
memdelete(translation_server);
}
@@ -1446,8 +1477,8 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
#endif
#ifdef TOOLS_ENABLED
- if (editor || project_manager) {
- EditorNode::register_editor_paths(project_manager);
+ if (editor || project_manager || cmdline_tool) {
+ EditorPaths::create();
}
#endif
@@ -1571,7 +1602,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
print_verbose("Using \"" + tablet_driver + "\" pen tablet driver...");
- /* Initialize Visual Server */
+ /* Initialize Rendering Server */
rendering_server = memnew(RenderingServerDefault(OS::get_singleton()->get_render_thread_mode() == OS::RENDER_SEPARATE_THREAD));
@@ -1651,7 +1682,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
boot_logo_path = boot_logo_path.strip_edges();
if (boot_logo_path != String()) {
- boot_logo.instance();
+ boot_logo.instantiate();
Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo);
if (load_err) {
ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash.");
@@ -1822,13 +1853,13 @@ bool Main::start() {
ERR_FAIL_COND_V(!_start_success, false);
bool hasicon = false;
- String doc_tool_path;
String positional_arg;
String game_path;
String script;
bool check_only = false;
#ifdef TOOLS_ENABLED
+ String doc_tool_path;
bool doc_base = true;
String _export_preset;
bool export_debug = false;
@@ -1838,8 +1869,9 @@ bool Main::start() {
main_timer_sync.init(OS::get_singleton()->get_ticks_usec());
List<String> args = OS::get_singleton()->get_cmdline_args();
- // parameters that do not have an argument to the right
for (int i = 0; i < args.size(); i++) {
+ // First check parameters that do not have an argument to the right.
+
// Doctest Unit Testing Handler
// Designed to override and pass arguments to the unit test handler.
if (args[i] == "--check-only") {
@@ -1869,7 +1901,7 @@ bool Main::start() {
game_path = args[i];
}
}
- //parameters that have an argument to the right
+ // Then parameters that have an argument to the right.
else if (i < (args.size() - 1)) {
bool parsed_pair = true;
if (args[i] == "-s" || args[i] == "--script") {
@@ -1901,16 +1933,19 @@ bool Main::start() {
if (parsed_pair) {
i++;
}
- } else if (args[i] == "--doctool") {
- // Handle case where no path is given to --doctool.
+ }
+#ifdef TOOLS_ENABLED
+ // Handle case where no path is given to --doctool.
+ else if (args[i] == "--doctool") {
doc_tool_path = ".";
}
+#endif
}
#ifdef TOOLS_ENABLED
if (doc_tool_path != "") {
- Engine::get_singleton()->set_editor_hint(
- true); // Needed to instance editor-only classes for their default values
+ // Needed to instance editor-only classes for their default values
+ Engine::get_singleton()->set_editor_hint(true);
{
DirAccessRef da = DirAccess::open(doc_tool_path);
@@ -1983,16 +2018,30 @@ bool Main::start() {
return false;
}
+ if (dump_extension_api) {
+ NativeExtensionAPIDump::generate_extension_json_file("extension_api.json");
+ return false;
+ }
#endif
if (script == "" && game_path == "" && String(GLOBAL_GET("application/run/main_scene")) != "") {
game_path = GLOBAL_GET("application/run/main_scene");
}
+#ifdef TOOLS_ENABLED
+ if (!editor && !project_manager && !cmdline_tool && script == "" && game_path == "") {
+ // If we end up here, it means we didn't manage to detect what we want to run.
+ // Let's throw an error gently. The code leading to this is pretty brittle so
+ // this might end up triggered by valid usage, in which case we'll have to
+ // fine-tune further.
+ ERR_FAIL_V_MSG(false, "Couldn't detect whether to run the editor, the project manager or a specific project. Aborting.");
+ }
+#endif
+
MainLoop *main_loop = nullptr;
if (editor) {
main_loop = memnew(SceneTree);
- };
+ }
String main_loop_type = GLOBAL_DEF("application/run/main_loop_type", "SceneTree");
if (script != "") {
@@ -2006,9 +2055,9 @@ bool Main::start() {
return false;
}
- if (script_res->can_instance()) {
+ if (script_res->can_instantiate()) {
StringName instance_type = script_res->get_instance_base_type();
- Object *obj = ClassDB::instance(instance_type);
+ Object *obj = ClassDB::instantiate(instance_type);
MainLoop *script_loop = Object::cast_to<MainLoop>(obj);
if (!script_loop) {
if (obj) {
@@ -2029,7 +2078,7 @@ bool Main::start() {
String script_path = ScriptServer::get_global_class_path(main_loop_type);
Ref<Script> script_res = ResourceLoader::load(script_path);
StringName script_base = ScriptServer::get_global_class_native_base(main_loop_type);
- Object *obj = ClassDB::instance(script_base);
+ Object *obj = ClassDB::instantiate(script_base);
MainLoop *script_loop = Object::cast_to<MainLoop>(obj);
if (!script_loop) {
if (obj) {
@@ -2052,7 +2101,7 @@ bool Main::start() {
DisplayServer::get_singleton()->alert("Error: MainLoop type doesn't exist: " + main_loop_type);
return false;
} else {
- Object *ml = ClassDB::instance(main_loop_type);
+ Object *ml = ClassDB::instantiate(main_loop_type);
ERR_FAIL_COND_V_MSG(!ml, false, "Can't instance MainLoop type.");
main_loop = Object::cast_to<MainLoop>(ml);
@@ -2109,14 +2158,14 @@ bool Main::start() {
Node *n = nullptr;
if (res->is_class("PackedScene")) {
Ref<PackedScene> ps = res;
- n = ps->instance();
+ n = ps->instantiate();
} else if (res->is_class("Script")) {
Ref<Script> script_res = res;
StringName ibt = script_res->get_instance_base_type();
bool valid_type = ClassDB::is_parent_class(ibt, "Node");
ERR_CONTINUE_MSG(!valid_type, "Script does not inherit a Node: " + info.path);
- Object *obj = ClassDB::instance(ibt);
+ Object *obj = ClassDB::instantiate(ibt);
ERR_CONTINUE_MSG(obj == nullptr,
"Cannot instance script for autoload, expected 'Node' inheritance, got: " +
@@ -2319,7 +2368,7 @@ bool Main::start() {
Node *scene = nullptr;
Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path);
if (scenedata.is_valid()) {
- scene = scenedata->instance();
+ scene = scenedata->instantiate();
}
ERR_FAIL_COND_V_MSG(!scene, false, "Failed loading scene: " + local_game_path);
@@ -2344,7 +2393,7 @@ bool Main::start() {
String iconpath = GLOBAL_DEF("application/config/icon", "Variant()");
if ((iconpath != "") && (!hasicon)) {
Ref<Image> icon;
- icon.instance();
+ icon.instantiate();
if (ImageLoader::load_image(iconpath, icon) == OK) {
DisplayServer::get_singleton()->set_icon(icon);
hasicon = true;
@@ -2354,14 +2403,13 @@ bool Main::start() {
}
#ifdef TOOLS_ENABLED
- if (project_manager || (script == "" && game_path == "" && !editor)) {
+ if (project_manager) {
Engine::get_singleton()->set_editor_hint(true);
ProjectManager *pmanager = memnew(ProjectManager);
ProgressDialog *progress_dialog = memnew(ProgressDialog);
pmanager->add_child(progress_dialog);
sml->get_root()->add_child(pmanager);
DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_PROJECTMAN);
- project_manager = true;
}
if (project_manager || editor) {
@@ -2373,10 +2421,8 @@ bool Main::start() {
}
// Load SSL Certificates from Editor Settings (or builtin)
- Crypto::load_default_certificates(EditorSettings::get_singleton()->get_setting(
- "network/ssl/editor_ssl_certificates")
- .
- operator String());
+ Crypto::load_default_certificates(
+ EditorSettings::get_singleton()->get_setting("network/ssl/editor_ssl_certificates").operator String());
}
#endif
}
@@ -2667,6 +2713,9 @@ void Main::cleanup(bool p_force) {
if (input_map) {
memdelete(input_map);
}
+ if (time_singleton) {
+ memdelete(time_singleton);
+ }
if (translation_server) {
memdelete(translation_server);
}