summaryrefslogtreecommitdiff
path: root/main/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main/main.cpp')
-rw-r--r--main/main.cpp890
1 files changed, 511 insertions, 379 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 9fbef718fa..79c8fe532d 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -31,7 +31,9 @@
#include "main.h"
#include "core/crypto/crypto.h"
-#include "core/input_map.h"
+#include "core/debugger/engine_debugger.h"
+#include "core/input/input.h"
+#include "core/input/input_map.h"
#include "core/io/file_access_network.h"
#include "core/io/file_access_pack.h"
#include "core/io/file_access_zip.h"
@@ -43,38 +45,38 @@
#include "core/os/os.h"
#include "core/project_settings.h"
#include "core/register_core_types.h"
-#include "core/script_debugger_local.h"
-#include "core/script_debugger_remote.h"
-#include "core/script_language.h"
#include "core/translation.h"
#include "core/version.h"
#include "core/version_hash.gen.h"
#include "drivers/register_driver_types.h"
#include "main/app_icon.gen.h"
-#include "main/input_default.h"
#include "main/main_timer_sync.h"
#include "main/performance.h"
#include "main/splash.gen.h"
#include "main/splash_editor.gen.h"
#include "main/tests/test_main.h"
+#include "modules/modules_enabled.gen.h"
#include "modules/register_module_types.h"
#include "platform/register_platform_apis.h"
#include "scene/main/scene_tree.h"
-#include "scene/main/viewport.h"
+#include "scene/main/window.h"
#include "scene/register_scene_types.h"
#include "scene/resources/packed_scene.h"
-#include "servers/arvr_server.h"
#include "servers/audio_server.h"
#include "servers/camera_server.h"
-#include "servers/navigation_2d_server.h"
-#include "servers/navigation_server.h"
-#include "servers/physics_2d_server.h"
-#include "servers/physics_server.h"
+#include "servers/display_server.h"
+#include "servers/navigation_server_2d.h"
+#include "servers/navigation_server_3d.h"
+#include "servers/physics_server_2d.h"
+#include "servers/physics_server_3d.h"
#include "servers/register_server_types.h"
+#include "servers/rendering/rendering_server_raster.h"
+#include "servers/rendering/rendering_server_wrap_mt.h"
+#include "servers/xr_server.h"
#ifdef TOOLS_ENABLED
-#include "editor/doc/doc_data.h"
-#include "editor/doc/doc_data_class_path.gen.h"
+#include "editor/doc_data.h"
+#include "editor/doc_data_class_path.gen.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/progress_dialog.h"
@@ -86,37 +88,40 @@
// Singletons
// Initialized in setup()
-static Engine *engine = NULL;
-static ProjectSettings *globals = NULL;
-static InputMap *input_map = NULL;
-static TranslationServer *translation_server = NULL;
-static Performance *performance = NULL;
-static PackedData *packed_data = NULL;
+static Engine *engine = nullptr;
+static ProjectSettings *globals = nullptr;
+static Input *input = nullptr;
+static InputMap *input_map = nullptr;
+static TranslationServer *translation_server = nullptr;
+static Performance *performance = nullptr;
+static PackedData *packed_data = nullptr;
#ifdef MINIZIP_ENABLED
-static ZipArchive *zip_packed_data = NULL;
+static ZipArchive *zip_packed_data = nullptr;
#endif
-static FileAccessNetworkClient *file_access_network_client = NULL;
-static ScriptDebugger *script_debugger = NULL;
-static MessageQueue *message_queue = NULL;
+static FileAccessNetworkClient *file_access_network_client = nullptr;
+static MessageQueue *message_queue = nullptr;
// Initialized in setup2()
-static AudioServer *audio_server = NULL;
-static CameraServer *camera_server = NULL;
-static ARVRServer *arvr_server = NULL;
-static PhysicsServer *physics_server = NULL;
-static Physics2DServer *physics_2d_server = NULL;
-static NavigationServer *navigation_server = NULL;
-static Navigation2DServer *navigation_2d_server = NULL;
+static AudioServer *audio_server = nullptr;
+static DisplayServer *display_server = nullptr;
+static RenderingServer *rendering_server = nullptr;
+static CameraServer *camera_server = nullptr;
+static XRServer *xr_server = nullptr;
+static PhysicsServer3D *physics_server = nullptr;
+static PhysicsServer2D *physics_2d_server = nullptr;
+static NavigationServer3D *navigation_server = nullptr;
+static NavigationServer2D *navigation_2d_server = nullptr;
// We error out if setup2() doesn't turn this true
static bool _start_success = false;
// Drivers
-static int video_driver_idx = -1;
+static int display_driver_idx = -1;
static int audio_driver_idx = -1;
// Engine config/tools
+static bool single_window = false;
static bool editor = false;
static bool project_manager = false;
static String locale;
@@ -129,7 +134,12 @@ static bool auto_build_solutions = false;
// Display
-static OS::VideoMode video_mode;
+static DisplayServer::WindowMode window_mode = DisplayServer::WINDOW_MODE_WINDOWED;
+static DisplayServer::ScreenOrientation window_orientation = DisplayServer::SCREEN_LANDSCAPE;
+static uint32_t window_flags = 0;
+static Size2i window_size = Size2i(1024, 600);
+static bool window_vsync_via_compositor = false;
+
static int init_screen = -1;
static bool init_fullscreen = false;
static bool init_maximized = false;
@@ -166,28 +176,29 @@ static String unescape_cmdline(const String &p_str) {
static String get_full_version_string() {
String hash = String(VERSION_HASH);
- if (hash.length() != 0)
+ if (hash.length() != 0) {
hash = "." + hash.left(9);
+ }
return String(VERSION_FULL_BUILD) + hash;
}
-// FIXME: Could maybe be moved to PhysicsServerManager and Physics2DServerManager directly
+// FIXME: Could maybe be moved to PhysicsServer3DManager and PhysicsServer2DManager directly
// to have less code in main.cpp.
void initialize_physics() {
/// 3D Physics Server
- physics_server = PhysicsServerManager::new_server(ProjectSettings::get_singleton()->get(PhysicsServerManager::setting_property_name));
+ physics_server = PhysicsServer3DManager::new_server(ProjectSettings::get_singleton()->get(PhysicsServer3DManager::setting_property_name));
if (!physics_server) {
// Physics server not found, Use the default physics
- physics_server = PhysicsServerManager::new_default_server();
+ physics_server = PhysicsServer3DManager::new_default_server();
}
ERR_FAIL_COND(!physics_server);
physics_server->init();
/// 2D Physics server
- physics_2d_server = Physics2DServerManager::new_server(ProjectSettings::get_singleton()->get(Physics2DServerManager::setting_property_name));
+ physics_2d_server = PhysicsServer2DManager::new_server(ProjectSettings::get_singleton()->get(PhysicsServer2DManager::setting_property_name));
if (!physics_2d_server) {
// Physics server not found, Use the default physics
- physics_2d_server = Physics2DServerManager::new_default_server();
+ physics_2d_server = PhysicsServer2DManager::new_default_server();
}
ERR_FAIL_COND(!physics_2d_server);
physics_2d_server->init();
@@ -201,19 +212,26 @@ void finalize_physics() {
memdelete(physics_2d_server);
}
+void finalize_display() {
+ rendering_server->finish();
+ memdelete(rendering_server);
+
+ memdelete(display_server);
+}
+
void initialize_navigation_server() {
- ERR_FAIL_COND(navigation_server != NULL);
+ ERR_FAIL_COND(navigation_server != nullptr);
- navigation_server = NavigationServerManager::new_default_server();
- navigation_2d_server = memnew(Navigation2DServer);
+ navigation_server = NavigationServer3DManager::new_default_server();
+ navigation_2d_server = memnew(NavigationServer2D);
}
void finalize_navigation_server() {
memdelete(navigation_server);
- navigation_server = NULL;
+ navigation_server = nullptr;
memdelete(navigation_2d_server);
- navigation_2d_server = NULL;
+ navigation_2d_server = nullptr;
}
//#define DEBUG_INIT
@@ -224,7 +242,6 @@ void finalize_navigation_server() {
#endif
void Main::print_help(const char *p_binary) {
-
print_line(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE));
OS::get_singleton()->print("Free and open source software under the terms of the MIT license.\n");
OS::get_singleton()->print("(c) 2007-2020 Juan Linietsky, Ariel Manzur.\n");
@@ -253,20 +270,33 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" --render-thread <mode> Render thread mode ('unsafe', 'safe', 'separate').\n");
OS::get_singleton()->print(" --remote-fs <address> Remote filesystem (<host/IP>[:<port>] address).\n");
OS::get_singleton()->print(" --remote-fs-password <password> Password for remote filesystem.\n");
- OS::get_singleton()->print(" --audio-driver <driver> Audio driver (");
- for (int i = 0; i < OS::get_singleton()->get_audio_driver_count(); i++) {
- if (i != 0)
+
+ OS::get_singleton()->print(" --audio-driver <driver> Audio driver [");
+ for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
+ if (i > 0) {
OS::get_singleton()->print(", ");
- OS::get_singleton()->print("'%s'", OS::get_singleton()->get_audio_driver_name(i));
+ }
+ OS::get_singleton()->print("'%s'", AudioDriverManager::get_driver(i)->get_name());
}
- OS::get_singleton()->print(").\n");
- OS::get_singleton()->print(" --video-driver <driver> Video driver (");
- for (int i = 0; i < OS::get_singleton()->get_video_driver_count(); i++) {
- if (i != 0)
+ OS::get_singleton()->print("].\n");
+
+ OS::get_singleton()->print(" --display-driver <driver> Display driver (and rendering driver) [");
+ for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
+ if (i > 0) {
OS::get_singleton()->print(", ");
- OS::get_singleton()->print("'%s'", OS::get_singleton()->get_video_driver_name(i));
+ }
+ OS::get_singleton()->print("'%s' (", DisplayServer::get_create_function_name(i));
+ Vector<String> rd = DisplayServer::get_create_function_rendering_drivers(i);
+ for (int j = 0; j < rd.size(); j++) {
+ if (j > 0) {
+ OS::get_singleton()->print(", ");
+ }
+ OS::get_singleton()->print("'%s'", rd[j].utf8().get_data());
+ }
+ OS::get_singleton()->print(")");
}
- OS::get_singleton()->print(").\n");
+ OS::get_singleton()->print("].\n");
+ OS::get_singleton()->print(" --rendering-driver <driver> Rendering driver (depends on display driver).\n");
OS::get_singleton()->print("\n");
#ifndef SERVER_ENABLED
@@ -281,6 +311,14 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" --no-window Disable window creation (Windows only). Useful together with --script.\n");
OS::get_singleton()->print(" --enable-vsync-via-compositor When vsync is enabled, vsync via the OS' window compositor (Windows only).\n");
OS::get_singleton()->print(" --disable-vsync-via-compositor Disable vsync via the OS' window compositor (Windows only).\n");
+ OS::get_singleton()->print(" --single-window Use a single window (no separate subwindows).\n");
+ OS::get_singleton()->print(" --tablet-driver Tablet input driver (");
+ for (int i = 0; i < OS::get_singleton()->get_tablet_driver_count(); i++) {
+ if (i != 0)
+ OS::get_singleton()->print(", ");
+ OS::get_singleton()->print("'%s'", OS::get_singleton()->get_tablet_driver_name(i).utf8().get_data());
+ }
+ OS::get_singleton()->print(") (Windows only).\n");
OS::get_singleton()->print("\n");
#endif
@@ -289,7 +327,7 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" -b, --breakpoints Breakpoint list as source::line comma-separated pairs, no spaces (use %%20 instead).\n");
OS::get_singleton()->print(" --profiling Enable profiling in the script debugger.\n");
OS::get_singleton()->print(" --gpu-abort Abort on GPU errors (usually validation layer errors), may help see the problem if your system freezes.\n");
- OS::get_singleton()->print(" --remote-debug <address> Remote debug (<host/IP>:<port> address).\n");
+ OS::get_singleton()->print(" --remote-debug <uri> Remote debug (<protocol>://<host/IP>[:<port>], e.g. tcp://127.0.0.1:6007).\n");
#if defined(DEBUG_ENABLED) && !defined(SERVER_ENABLED)
OS::get_singleton()->print(" --debug-collisions Show collision shapes when running the scene.\n");
OS::get_singleton()->print(" --debug-navigation Show navigation polygons when running the scene.\n");
@@ -316,7 +354,7 @@ void Main::print_help(const char *p_binary) {
#ifdef DEBUG_METHODS_ENABLED
OS::get_singleton()->print(" --gdnative-generate-json-api Generate JSON dump of the Godot API for GDNative bindings.\n");
#endif
- OS::get_singleton()->print(" --test <test> Run a unit test (");
+ OS::get_singleton()->print(" --test <test> Run a unit test [");
const char **test_names = tests_get_names();
const char *comma = "";
while (*test_names) {
@@ -324,7 +362,7 @@ void Main::print_help(const char *p_binary) {
test_names++;
comma = ", ";
}
- OS::get_singleton()->print(").\n");
+ OS::get_singleton()->print("].\n");
#endif
}
@@ -355,8 +393,7 @@ void Main::print_help(const char *p_binary) {
*/
Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_phase) {
-
- OS::get_singleton()->initialize_core();
+ OS::get_singleton()->initialize();
engine = memnew(Engine);
@@ -390,7 +427,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
List<String> main_args;
for (int i = 0; i < argc; i++) {
-
args.push_back(String::utf8(argv[i]));
}
@@ -399,19 +435,18 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
I = args.front();
while (I) {
-
I->get() = unescape_cmdline(I->get().strip_edges());
I = I->next();
}
I = args.front();
- String video_driver = "";
+ String display_driver = "";
String audio_driver = "";
+ String tablet_driver = "";
String project_path = ".";
bool upwards = false;
- String debug_mode;
- String debug_host;
+ String debug_uri = "";
bool skip_breakpoints = false;
String main_pack;
bool quiet_stdout = false;
@@ -427,10 +462,12 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
#ifdef TOOLS_ENABLED
bool found_project = false;
#endif
+ bool use_vsync = false;
packed_data = PackedData::get_singleton();
- if (!packed_data)
+ if (!packed_data) {
packed_data = memnew(PackedData);
+ }
#ifdef MINIZIP_ENABLED
@@ -446,6 +483,14 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
I = args.front();
while (I) {
+#ifdef OSX_ENABLED
+ // Ignore the process serial number argument passed by macOS Gatekeeper.
+ // Otherwise, Godot would try to open a non-existent project on the first start and abort.
+ if (I->get().begins_with("-psn_")) {
+ I = I->next();
+ continue;
+ }
+#endif
List<String>::Element *N = I->next();
@@ -455,7 +500,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
goto error;
} else if (I->get() == "--version") {
-
print_line(get_full_version_string());
goto error;
@@ -469,12 +513,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--audio-driver") { // audio driver
if (I->next()) {
-
audio_driver = I->next()->get();
bool found = false;
- for (int i = 0; i < OS::get_singleton()->get_audio_driver_count(); i++) {
- if (audio_driver == OS::get_singleton()->get_audio_driver_name(i)) {
+ for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
+ if (audio_driver == AudioDriverManager::get_driver(i)->get_name()) {
found = true;
}
}
@@ -482,14 +525,14 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
if (!found) {
OS::get_singleton()->print("Unknown audio driver '%s', aborting.\nValid options are ", audio_driver.utf8().get_data());
- for (int i = 0; i < OS::get_singleton()->get_audio_driver_count(); i++) {
- if (i == OS::get_singleton()->get_audio_driver_count() - 1) {
+ for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
+ if (i == AudioDriverManager::get_driver_count() - 1) {
OS::get_singleton()->print(" and ");
} else if (i != 0) {
OS::get_singleton()->print(", ");
}
- OS::get_singleton()->print("'%s'", OS::get_singleton()->get_audio_driver_name(i));
+ OS::get_singleton()->print("'%s'", AudioDriverManager::get_driver(i)->get_name());
}
OS::get_singleton()->print(".\n");
@@ -503,30 +546,29 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
goto error;
}
- } else if (I->get() == "--video-driver") { // force video driver
+ } else if (I->get() == "--display-driver") { // force video driver
if (I->next()) {
-
- video_driver = I->next()->get();
+ display_driver = I->next()->get();
bool found = false;
- for (int i = 0; i < OS::get_singleton()->get_video_driver_count(); i++) {
- if (video_driver == OS::get_singleton()->get_video_driver_name(i)) {
+ for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
+ if (display_driver == DisplayServer::get_create_function_name(i)) {
found = true;
}
}
if (!found) {
- OS::get_singleton()->print("Unknown video driver '%s', aborting.\nValid options are ", video_driver.utf8().get_data());
+ OS::get_singleton()->print("Unknown display driver '%s', aborting.\nValid options are ", display_driver.utf8().get_data());
- for (int i = 0; i < OS::get_singleton()->get_video_driver_count(); i++) {
- if (i == OS::get_singleton()->get_video_driver_count() - 1) {
+ for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
+ if (i == DisplayServer::get_create_function_count() - 1) {
OS::get_singleton()->print(" and ");
} else if (i != 0) {
OS::get_singleton()->print(", ");
}
- OS::get_singleton()->print("'%s'", OS::get_singleton()->get_video_driver_name(i));
+ OS::get_singleton()->print("'%s'", DisplayServer::get_create_function_name(i));
}
OS::get_singleton()->print(".\n");
@@ -546,7 +588,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "-m" || I->get() == "--maximized") { // force maximized window
init_maximized = true;
- video_mode.maximized = true;
+ window_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
} else if (I->get() == "-w" || I->get() == "--windowed") { // force windowed window
@@ -554,13 +596,35 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--gpu-abort") { // force windowed window
Engine::singleton->abort_on_gpu_errors = true;
+ } else if (I->get() == "--tablet-driver") {
+ if (I->next()) {
+ tablet_driver = I->next()->get();
+ bool found = false;
+ for (int i = 0; i < OS::get_singleton()->get_tablet_driver_count(); i++) {
+ if (tablet_driver == OS::get_singleton()->get_tablet_driver_name(i)) {
+ found = true;
+ }
+ }
+
+ if (!found) {
+ OS::get_singleton()->print("Unknown tablet driver '%s', aborting.\n", tablet_driver.utf8().get_data());
+ goto error;
+ }
+
+ N = I->next()->next();
+ } else {
+ OS::get_singleton()->print("Missing tablet driver argument, aborting.\n");
+ goto error;
+ }
+ } else if (I->get() == "--single-window") { // force single window
+
+ single_window = true;
} else if (I->get() == "-t" || I->get() == "--always-on-top") { // force always-on-top window
init_always_on_top = true;
} else if (I->get() == "--resolution") { // force resolution
if (I->next()) {
-
String vm = I->next()->get();
if (vm.find("x") == -1) { // invalid parameter format
@@ -573,13 +637,12 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
int h = vm.get_slice("x", 1).to_int();
if (w <= 0 || h <= 0) {
-
OS::get_singleton()->print("Invalid resolution '%s', width and height must be above 0.\n", vm.utf8().get_data());
goto error;
}
- video_mode.width = w;
- video_mode.height = h;
+ window_size.width = w;
+ window_size.height = h;
force_res = true;
N = I->next()->next();
@@ -591,7 +654,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--position") { // set window position
if (I->next()) {
-
String vm = I->next()->get();
if (vm.find(",") == -1) { // invalid parameter format
@@ -619,12 +681,10 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->set_no_window_mode(true);
} else if (I->get() == "--enable-vsync-via-compositor") {
-
- video_mode.vsync_via_compositor = true;
+ window_vsync_via_compositor = true;
saw_vsync_via_compositor_override = true;
} else if (I->get() == "--disable-vsync-via-compositor") {
-
- video_mode.vsync_via_compositor = false;
+ window_vsync_via_compositor = false;
saw_vsync_via_compositor_override = true;
#endif
} else if (I->get() == "--profiling") { // enable profiling
@@ -634,7 +694,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "-l" || I->get() == "--language") { // language
if (I->next()) {
-
locale = I->next()->get();
N = I->next()->next();
} else {
@@ -645,7 +704,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--remote-fs") { // remote filesystem
if (I->next()) {
-
remotefs = I->next()->get();
N = I->next()->next();
} else {
@@ -655,7 +713,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--remote-fs-password") { // remote filesystem password
if (I->next()) {
-
remotefs_pass = I->next()->get();
N = I->next()->next();
} else {
@@ -665,13 +722,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--render-thread") { // render thread mode
if (I->next()) {
-
- if (I->next()->get() == "safe")
+ if (I->next()->get() == "safe") {
rtm = OS::RENDER_THREAD_SAFE;
- else if (I->next()->get() == "unsafe")
+ } else if (I->next()->get() == "unsafe") {
rtm = OS::RENDER_THREAD_UNSAFE;
- else if (I->next()->get() == "separate")
+ } else if (I->next()->get() == "separate") {
rtm = OS::RENDER_SEPARATE_THREAD;
+ }
N = I->next()->next();
} else {
@@ -705,7 +762,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--path") { // set path of project to start or edit
if (I->next()) {
-
String p = I->next()->get();
if (OS::get_singleton()->set_cwd(p) == OK) {
//nothing
@@ -725,9 +781,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
String path;
String file = I->get();
int sep = MAX(file.find_last("/"), file.find_last("\\"));
- if (sep == -1)
+ if (sep == -1) {
path = ".";
- else {
+ } else {
path = file.substr(0, sep);
}
if (OS::get_singleton()->set_cwd(path) == OK) {
@@ -741,7 +797,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "-b" || I->get() == "--breakpoints") { // add breakpoints
if (I->next()) {
-
String bplist = I->next()->get();
breakpoints = bplist.split(",");
N = I->next()->next();
@@ -753,7 +808,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--frame-delay") { // force frame delay
if (I->next()) {
-
frame_delay = I->next()->get().to_int();
N = I->next()->next();
} else {
@@ -764,7 +818,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--time-scale") { // force time scale
if (I->next()) {
-
Engine::get_singleton()->set_time_scale(I->next()->get().to_double());
N = I->next()->next();
} else {
@@ -773,9 +826,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
}
} else if (I->get() == "--main-pack") {
-
if (I->next()) {
-
main_pack = I->next()->get();
N = I->next()->next();
} else {
@@ -784,7 +835,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
};
} else if (I->get() == "-d" || I->get() == "--debug") {
- debug_mode = "local";
+ debug_uri = "local://";
#if defined(DEBUG_ENABLED) && !defined(SERVER_ENABLED)
} else if (I->get() == "--debug-collisions") {
debug_collisions = true;
@@ -793,11 +844,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
#endif
} else if (I->get() == "--remote-debug") {
if (I->next()) {
-
- debug_mode = "remote";
- debug_host = I->next()->get();
- if (debug_host.find(":") == -1) { // wrong address
- OS::get_singleton()->print("Invalid debug host address, it should be of the form <host/IP>:<port>.\n");
+ debug_uri = I->next()->get();
+ if (debug_uri.find("://") == -1) { // wrong address
+ OS::get_singleton()->print("Invalid debug host address, it should be of the form <protocol>://<host/IP>:<port>.\n");
goto error;
}
N = I->next()->next();
@@ -807,7 +856,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
}
} else if (I->get() == "--allow_focus_steal_pid") { // not exposed to user
if (I->next()) {
-
allow_focus_steal_pid = I->next()->get().to_int64();
N = I->next()->next();
} else {
@@ -848,7 +896,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
// 'project.godot' file which will only be available through the network if this is enabled
FileAccessNetwork::configure();
if (remotefs != "") {
-
file_access_network_client = memnew(FileAccessNetworkClient);
int port;
if (remotefs.find(":") != -1) {
@@ -872,71 +919,38 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
found_project = true;
#endif
} else {
-
#ifdef TOOLS_ENABLED
editor = false;
#else
const String error_msg = "Error: Couldn't load project data at path \"" + project_path + "\". Is the .pck file missing?\nIf you've renamed the executable, the associated .pck file should also be renamed to match the executable's name (without the extension).\n";
OS::get_singleton()->print("%s", error_msg.ascii().get_data());
- OS::get_singleton()->alert(error_msg);
+ DisplayServer::get_singleton()->alert(error_msg);
goto error;
#endif
}
+ // Initialize user data dir.
+ OS::get_singleton()->ensure_user_data_dir();
+
GLOBAL_DEF("memory/limits/multithreaded_server/rid_pool_prealloc", 60);
ProjectSettings::get_singleton()->set_custom_property_info("memory/limits/multithreaded_server/rid_pool_prealloc", PropertyInfo(Variant::INT, "memory/limits/multithreaded_server/rid_pool_prealloc", PROPERTY_HINT_RANGE, "0,500,1")); // No negative and limit to 500 due to crashes
- GLOBAL_DEF("network/limits/debugger_stdout/max_chars_per_second", 2048);
- ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_chars_per_second", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_chars_per_second", PROPERTY_HINT_RANGE, "0, 4096, 1, or_greater"));
- GLOBAL_DEF("network/limits/debugger_stdout/max_messages_per_frame", 10);
- ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_messages_per_frame", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_messages_per_frame", PROPERTY_HINT_RANGE, "0, 20, 1, or_greater"));
- GLOBAL_DEF("network/limits/debugger_stdout/max_errors_per_second", 100);
- ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_errors_per_second", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_errors_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater"));
- GLOBAL_DEF("network/limits/debugger_stdout/max_warnings_per_second", 100);
- ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_warnings_per_second", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_warnings_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater"));
-
- if (debug_mode == "remote") {
-
- ScriptDebuggerRemote *sdr = memnew(ScriptDebuggerRemote);
- uint16_t debug_port = 6007;
- if (debug_host.find(":") != -1) {
- int sep_pos = debug_host.find_last(":");
- debug_port = debug_host.substr(sep_pos + 1, debug_host.length()).to_int();
- debug_host = debug_host.substr(0, sep_pos);
- }
- Error derr = sdr->connect_to_host(debug_host, debug_port);
+ GLOBAL_DEF("network/limits/debugger/max_chars_per_second", 32768);
+ ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger/max_chars_per_second", PropertyInfo(Variant::INT, "network/limits/debugger/max_chars_per_second", PROPERTY_HINT_RANGE, "0, 4096, 1, or_greater"));
+ GLOBAL_DEF("network/limits/debugger/max_queued_messages", 2048);
+ ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger/max_queued_messages", PropertyInfo(Variant::INT, "network/limits/debugger/max_queued_messages", PROPERTY_HINT_RANGE, "0, 8192, 1, or_greater"));
+ GLOBAL_DEF("network/limits/debugger/max_errors_per_second", 400);
+ ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger/max_errors_per_second", PropertyInfo(Variant::INT, "network/limits/debugger/max_errors_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater"));
+ GLOBAL_DEF("network/limits/debugger/max_warnings_per_second", 400);
+ ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger/max_warnings_per_second", PropertyInfo(Variant::INT, "network/limits/debugger/max_warnings_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater"));
- sdr->set_skip_breakpoints(skip_breakpoints);
-
- if (derr != OK) {
- memdelete(sdr);
- } else {
- script_debugger = sdr;
- }
- } else if (debug_mode == "local") {
-
- script_debugger = memnew(ScriptDebuggerLocal);
- OS::get_singleton()->initialize_debugging();
- }
- if (script_debugger) {
- //there is a debugger, parse breakpoints
-
- for (int i = 0; i < breakpoints.size(); i++) {
-
- String bp = breakpoints[i];
- int sp = bp.find_last(":");
- ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format.");
-
- script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp));
- }
- }
+ EngineDebugger::initialize(debug_uri, skip_breakpoints, breakpoints);
#ifdef TOOLS_ENABLED
if (editor) {
packed_data->set_disabled(true);
globals->set_disable_feature_overrides(true);
}
-
#endif
GLOBAL_DEF("logging/file_logging/enable_file_logging", false);
@@ -955,7 +969,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
main_args.push_back("--editor");
if (!init_windowed) {
init_maximized = true;
- video_mode.maximized = true;
+ window_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
}
}
@@ -991,15 +1005,16 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
_print_error_enabled = false;
};
- if (quiet_stdout)
+ if (quiet_stdout) {
_print_line_enabled = false;
+ }
OS::get_singleton()->set_cmdline(execpath, main_args);
GLOBAL_DEF("rendering/quality/driver/driver_name", "Vulkan");
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/driver/driver_name", PropertyInfo(Variant::STRING, "rendering/quality/driver/driver_name", PROPERTY_HINT_ENUM, "Vulkan,GLES2"));
- if (video_driver == "") {
- video_driver = GLOBAL_GET("rendering/quality/driver/driver_name");
+ if (display_driver == "") {
+ display_driver = GLOBAL_GET("rendering/quality/driver/driver_name");
}
// Assigning here even though it's GLES2-specific, to be sure that it appears in docs
@@ -1019,50 +1034,73 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_height", PropertyInfo(Variant::INT, "display/window/size/test_height", PROPERTY_HINT_RANGE, "0,4320,or_greater")); // 8K resolution
if (use_custom_res) {
-
if (!force_res) {
- video_mode.width = GLOBAL_GET("display/window/size/width");
- video_mode.height = GLOBAL_GET("display/window/size/height");
+ window_size.width = GLOBAL_GET("display/window/size/width");
+ window_size.height = GLOBAL_GET("display/window/size/height");
if (globals->has_setting("display/window/size/test_width") && globals->has_setting("display/window/size/test_height")) {
-
int tw = globals->get("display/window/size/test_width");
if (tw > 0) {
- video_mode.width = tw;
+ window_size.width = tw;
}
int th = globals->get("display/window/size/test_height");
if (th > 0) {
- video_mode.height = th;
+ window_size.height = th;
}
}
}
- video_mode.resizable = GLOBAL_GET("display/window/size/resizable");
- video_mode.borderless_window = GLOBAL_GET("display/window/size/borderless");
- video_mode.fullscreen = GLOBAL_GET("display/window/size/fullscreen");
- video_mode.always_on_top = GLOBAL_GET("display/window/size/always_on_top");
+ if (!bool(GLOBAL_GET("display/window/size/resizable"))) {
+ window_flags |= DisplayServer::WINDOW_FLAG_RESIZE_DISABLED_BIT;
+ }
+ if (bool(GLOBAL_GET("display/window/size/borderless"))) {
+ window_flags |= DisplayServer::WINDOW_FLAG_BORDERLESS_BIT;
+ }
+ if (bool(GLOBAL_GET("display/window/size/fullscreen"))) {
+ window_mode = DisplayServer::WINDOW_MODE_FULLSCREEN;
+ }
+
+ if (bool(GLOBAL_GET("display/window/size/always_on_top"))) {
+ window_flags |= DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP;
+ }
}
if (!force_lowdpi) {
OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", false);
}
- video_mode.use_vsync = GLOBAL_DEF_RST("display/window/vsync/use_vsync", true);
- OS::get_singleton()->_use_vsync = video_mode.use_vsync;
+ use_vsync = GLOBAL_DEF_RST("display/window/vsync/use_vsync", true);
+ OS::get_singleton()->_use_vsync = use_vsync;
if (!saw_vsync_via_compositor_override) {
// If one of the command line options to enable/disable vsync via the
// window compositor ("--enable-vsync-via-compositor" or
// "--disable-vsync-via-compositor") was present then it overrides the
// project setting.
- video_mode.vsync_via_compositor = GLOBAL_DEF("display/window/vsync/vsync_via_compositor", false);
+ window_vsync_via_compositor = GLOBAL_DEF("display/window/vsync/vsync_via_compositor", false);
+ }
+
+ OS::get_singleton()->_vsync_via_compositor = window_vsync_via_compositor;
+
+ if (tablet_driver == "") { // specified in project.godot
+ tablet_driver = GLOBAL_DEF_RST("display/window/tablet_driver", OS::get_singleton()->get_tablet_driver_name(0));
+ }
+
+ for (int i = 0; i < OS::get_singleton()->get_tablet_driver_count(); i++) {
+ if (tablet_driver == OS::get_singleton()->get_tablet_driver_name(i)) {
+ OS::get_singleton()->set_current_tablet_driver(OS::get_singleton()->get_tablet_driver_name(i));
+ break;
+ }
}
- OS::get_singleton()->_vsync_via_compositor = video_mode.vsync_via_compositor;
+ if (tablet_driver == "") {
+ OS::get_singleton()->set_current_tablet_driver(OS::get_singleton()->get_tablet_driver_name(0));
+ }
+ /* todo restore
OS::get_singleton()->_allow_layered = GLOBAL_DEF("display/window/per_pixel_transparency/allowed", false);
video_mode.layered = GLOBAL_DEF("display/window/per_pixel_transparency/enabled", false);
-
+*/
GLOBAL_DEF("rendering/quality/intended_usage/framebuffer_allocation", 2);
GLOBAL_DEF("rendering/quality/intended_usage/framebuffer_allocation.mobile", 3);
@@ -1087,27 +1125,23 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
/* Determine audio and video drivers */
- for (int i = 0; i < OS::get_singleton()->get_video_driver_count(); i++) {
-
- if (video_driver == OS::get_singleton()->get_video_driver_name(i)) {
-
- video_driver_idx = i;
+ for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
+ if (display_driver == DisplayServer::get_create_function_name(i)) {
+ display_driver_idx = i;
break;
}
}
- if (video_driver_idx < 0) {
- video_driver_idx = 0;
+ if (display_driver_idx < 0) {
+ display_driver_idx = 0;
}
if (audio_driver == "") { // specified in project.godot
- audio_driver = GLOBAL_DEF_RST("audio/driver", OS::get_singleton()->get_audio_driver_name(0));
+ audio_driver = GLOBAL_DEF_RST("audio/driver", AudioDriverManager::get_driver(0)->get_name());
}
- for (int i = 0; i < OS::get_singleton()->get_audio_driver_count(); i++) {
-
- if (audio_driver == OS::get_singleton()->get_audio_driver_name(i)) {
-
+ for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
+ if (audio_driver == AudioDriverManager::get_driver(i)->get_name()) {
audio_driver_idx = i;
break;
}
@@ -1120,20 +1154,21 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
{
String orientation = GLOBAL_DEF("display/window/handheld/orientation", "landscape");
- if (orientation == "portrait")
- OS::get_singleton()->set_screen_orientation(OS::SCREEN_PORTRAIT);
- else if (orientation == "reverse_landscape")
- OS::get_singleton()->set_screen_orientation(OS::SCREEN_REVERSE_LANDSCAPE);
- else if (orientation == "reverse_portrait")
- OS::get_singleton()->set_screen_orientation(OS::SCREEN_REVERSE_PORTRAIT);
- else if (orientation == "sensor_landscape")
- OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR_LANDSCAPE);
- else if (orientation == "sensor_portrait")
- OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR_PORTRAIT);
- else if (orientation == "sensor")
- OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR);
- else
- OS::get_singleton()->set_screen_orientation(OS::SCREEN_LANDSCAPE);
+ if (orientation == "portrait") {
+ window_orientation = DisplayServer::SCREEN_PORTRAIT;
+ } else if (orientation == "reverse_landscape") {
+ window_orientation = DisplayServer::SCREEN_REVERSE_LANDSCAPE;
+ } else if (orientation == "reverse_portrait") {
+ window_orientation = DisplayServer::SCREEN_REVERSE_PORTRAIT;
+ } else if (orientation == "sensor_landscape") {
+ window_orientation = DisplayServer::SCREEN_SENSOR_LANDSCAPE;
+ } else if (orientation == "sensor_portrait") {
+ window_orientation = DisplayServer::SCREEN_SENSOR_PORTRAIT;
+ } else if (orientation == "sensor") {
+ window_orientation = DisplayServer::SCREEN_SENSOR;
+ } else {
+ window_orientation = DisplayServer::SCREEN_LANDSCAPE;
+ }
}
Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/common/physics_fps", 60));
@@ -1143,9 +1178,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
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"));
GLOBAL_DEF("debug/settings/stdout/print_fps", false);
+ GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false);
- if (!OS::get_singleton()->_verbose_stdout) //overridden
- OS::get_singleton()->_verbose_stdout = GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false);
+ if (!OS::get_singleton()->_verbose_stdout) { // Not manually overridden.
+ OS::get_singleton()->_verbose_stdout = GLOBAL_GET("debug/settings/stdout/verbose_stdout");
+ }
if (frame_delay == 0) {
frame_delay = GLOBAL_DEF("application/run/frame_delay_msec", 0);
@@ -1162,47 +1199,58 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
message_queue = memnew(MessageQueue);
- if (p_second_phase)
+ if (p_second_phase) {
return setup2();
+ }
return OK;
error:
- video_driver = "";
+ display_driver = "";
audio_driver = "";
+ tablet_driver = "";
project_path = "";
args.clear();
main_args.clear();
- if (show_help)
+ if (show_help) {
print_help(execpath);
+ }
- if (performance)
+ EngineDebugger::deinitialize();
+
+ if (performance) {
memdelete(performance);
- if (input_map)
+ }
+ if (input_map) {
memdelete(input_map);
- if (translation_server)
+ }
+ if (translation_server) {
memdelete(translation_server);
- if (globals)
+ }
+ if (globals) {
memdelete(globals);
- if (engine)
+ }
+ if (engine) {
memdelete(engine);
- if (script_debugger)
- memdelete(script_debugger);
- if (packed_data)
+ }
+ if (packed_data) {
memdelete(packed_data);
- if (file_access_network_client)
+ }
+ if (file_access_network_client) {
memdelete(file_access_network_client);
+ }
unregister_core_driver_types();
unregister_core_types();
OS::get_singleton()->_cmdline.clear();
- if (message_queue)
+ if (message_queue) {
memdelete(message_queue);
+ }
OS::get_singleton()->finalize_core();
locale = String();
@@ -1210,7 +1258,6 @@ error:
}
Error Main::setup2(Thread::ID p_main_tid_override) {
-
preregister_module_types();
preregister_server_types();
@@ -1221,15 +1268,60 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
Thread::_main_thread_id = p_main_tid_override;
}
- Error err = OS::get_singleton()->initialize(video_mode, video_driver_idx, audio_driver_idx);
- if (err != OK) {
- return err;
+ /* Initialize Input */
+
+ input = memnew(Input);
+
+ /* Iniitalize Display Server */
+
+ {
+ String rendering_driver; // temp broken
+
+ Error err;
+ display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_flags, window_size, err);
+ if (err != OK) {
+ //ok i guess we can't use this display server, try other ones
+ for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
+ if (i == display_driver_idx) {
+ continue; //don't try the same twice
+ }
+ display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_flags, window_size, err);
+ if (err == OK) {
+ break;
+ }
+ }
+ }
+
+ if (!display_server) {
+ ERR_PRINT("Unable to create DisplayServer, all display drivers failed.");
+ return err;
+ }
}
+ if (display_server->has_feature(DisplayServer::FEATURE_ORIENTATION)) {
+ display_server->screen_set_orientation(window_orientation);
+ }
+
+ /* Initialize Visual Server */
+
+ rendering_server = memnew(RenderingServerRaster);
+ if (OS::get_singleton()->get_render_thread_mode() != OS::RENDER_THREAD_UNSAFE) {
+ rendering_server = memnew(RenderingServerWrapMT(rendering_server, OS::get_singleton()->get_render_thread_mode() == OS::RENDER_SEPARATE_THREAD));
+ }
+
+ rendering_server->init();
+ rendering_server->set_render_loop_enabled(!disable_render_loop);
+
+ OS::get_singleton()->initialize_joypads();
+
+ /* Initialize Audio Driver */
+
+ AudioDriverManager::initialize(audio_driver_idx);
+
print_line(" "); //add a blank line for readability
if (init_use_custom_pos) {
- OS::get_singleton()->set_window_position(init_custom_pos);
+ display_server->window_set_position(init_custom_pos);
}
// right moment to create and initialize the audio server
@@ -1237,8 +1329,8 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
audio_server = memnew(AudioServer);
audio_server->init();
- // also init our arvr_server from here
- arvr_server = memnew(ARVRServer);
+ // also init our xr_server from here
+ xr_server = memnew(XRServer);
register_core_singletons();
@@ -1251,21 +1343,21 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
#endif
if (init_screen != -1) {
- OS::get_singleton()->set_current_screen(init_screen);
+ DisplayServer::get_singleton()->window_set_current_screen(init_screen);
}
if (init_windowed) {
//do none..
} else if (init_maximized) {
- OS::get_singleton()->set_window_maximized(true);
+ DisplayServer::get_singleton()->window_set_mode(DisplayServer::WINDOW_MODE_MAXIMIZED);
} else if (init_fullscreen) {
- OS::get_singleton()->set_window_fullscreen(true);
+ DisplayServer::get_singleton()->window_set_mode(DisplayServer::WINDOW_MODE_FULLSCREEN);
}
if (init_always_on_top) {
- OS::get_singleton()->set_window_always_on_top(true);
+ DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP, true);
}
if (allow_focus_steal_pid) {
- OS::get_singleton()->enable_for_stealing_focus(allow_focus_steal_pid);
+ DisplayServer::get_singleton()->enable_for_stealing_focus(allow_focus_steal_pid);
}
register_server_types();
@@ -1273,7 +1365,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
MAIN_PRINT("Main: Load Remaps");
Color clear = GLOBAL_DEF("rendering/environment/default_clear_color", Color(0.3, 0.3, 0.3));
- VisualServer::get_singleton()->set_default_clear_color(clear);
+ RenderingServer::get_singleton()->set_default_clear_color(clear);
if (show_logo) { //boot logo!
String boot_logo_path = GLOBAL_DEF("application/boot_splash/image", String());
@@ -1288,14 +1380,15 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
if (boot_logo_path != String()) {
boot_logo.instance();
Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo);
- if (load_err)
+ if (load_err) {
ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash.");
+ }
}
Color boot_bg_color = GLOBAL_DEF("application/boot_splash/bg_color", boot_splash_bg_color);
if (boot_logo.is_valid()) {
OS::get_singleton()->_msec_splash = OS::get_singleton()->get_ticks_msec();
- VisualServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, boot_logo_filter);
+ RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, boot_logo_filter);
} else {
#ifndef NO_DEFAULT_BOOT_LOGO
@@ -1307,20 +1400,20 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
#endif
MAIN_PRINT("Main: ClearColor");
- VisualServer::get_singleton()->set_default_clear_color(boot_bg_color);
+ RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color);
MAIN_PRINT("Main: Image");
- VisualServer::get_singleton()->set_boot_image(splash, boot_bg_color, false);
+ RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false);
#endif
}
#ifdef TOOLS_ENABLED
Ref<Image> icon = memnew(Image(app_icon_png));
- OS::get_singleton()->set_icon(icon);
+ DisplayServer::get_singleton()->set_icon(icon);
#endif
}
MAIN_PRINT("Main: DCC");
- VisualServer::get_singleton()->set_default_clear_color(GLOBAL_DEF("rendering/environment/default_clear_color", Color(0.3, 0.3, 0.3)));
+ RenderingServer::get_singleton()->set_default_clear_color(GLOBAL_DEF("rendering/environment/default_clear_color", Color(0.3, 0.3, 0.3)));
MAIN_PRINT("Main: END");
GLOBAL_DEF("application/config/icon", String());
@@ -1332,10 +1425,16 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
GLOBAL_DEF("application/config/windows_native_icon", String());
ProjectSettings::get_singleton()->set_custom_property_info("application/config/windows_native_icon", PropertyInfo(Variant::STRING, "application/config/windows_native_icon", PROPERTY_HINT_FILE, "*.ico"));
- InputDefault *id = Object::cast_to<InputDefault>(Input::get_singleton());
+ Input *id = Input::get_singleton();
if (id) {
if (bool(GLOBAL_DEF("input_devices/pointing/emulate_touch_from_mouse", false)) && !(editor || project_manager)) {
- if (!OS::get_singleton()->has_touchscreen_ui_hint()) {
+ bool found_touchscreen = false;
+ for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
+ if (DisplayServer::get_singleton()->screen_is_touchscreen(i)) {
+ found_touchscreen = true;
+ }
+ }
+ if (!found_touchscreen) {
//only if no touchscreen ui hint, set emulation
id->set_emulate_touch_from_mouse(true);
}
@@ -1356,7 +1455,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
ProjectSettings::get_singleton()->set_custom_property_info("display/mouse_cursor/custom_image", PropertyInfo(Variant::STRING, "display/mouse_cursor/custom_image", PROPERTY_HINT_FILE, "*.png,*.webp"));
if (String(ProjectSettings::get_singleton()->get("display/mouse_cursor/custom_image")) != String()) {
-
Ref<Texture2D> cursor = ResourceLoader::load(ProjectSettings::get_singleton()->get("display/mouse_cursor/custom_image"));
if (cursor.is_valid()) {
Vector2 hotspot = ProjectSettings::get_singleton()->get("display/mouse_cursor/custom_image_hotspot");
@@ -1391,7 +1489,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
translation_server->setup(); //register translations, load them, etc.
if (locale != "") {
-
translation_server->set_locale(locale);
}
translation_server->load_translations();
@@ -1401,9 +1498,20 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
audio_server->load_default_bus_layout();
- if (use_debug_profiler && script_debugger) {
- script_debugger->profiling_start();
+ if (use_debug_profiler && EngineDebugger::is_active()) {
+ // Start the "scripts" profiler, used in local debugging.
+ // We could add more, and make the CLI arg require a comma-separated list of profilers.
+ EngineDebugger::get_singleton()->profiler_enable("scripts", true);
+ }
+
+ if (!project_manager) {
+ // If not running the project manager, and now that the engine is
+ // able to load resources, load the global shader variables.
+ // If running on editor, dont load the textures because the editor
+ // may want to import them first. Editor will reload those later.
+ rendering_server->global_variables_load_settings(!editor);
}
+
_start_success = true;
locale = String();
@@ -1420,7 +1528,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
static MainTimerSync main_timer_sync;
bool Main::start() {
-
ERR_FAIL_COND_V(!_start_success, false);
bool hasicon = false;
@@ -1457,7 +1564,11 @@ bool Main::start() {
} else if (args[i].length() && args[i][0] != '-' && positional_arg == "") {
positional_arg = args[i];
- if (args[i].ends_with(".scn") || args[i].ends_with(".tscn") || args[i].ends_with(".escn")) {
+ if (args[i].ends_with(".scn") ||
+ args[i].ends_with(".tscn") ||
+ args[i].ends_with(".escn") ||
+ args[i].ends_with(".res") ||
+ args[i].ends_with(".tres")) {
// Only consider the positional argument to be a scene path if it ends with
// a file extension associated with Godot scenes. This makes it possible
// for projects to parse command-line arguments for custom CLI arguments
@@ -1477,8 +1588,9 @@ bool Main::start() {
#ifdef TOOLS_ENABLED
} else if (args[i] == "--doctool") {
doc_tool = args[i + 1];
- for (int j = i + 2; j < args.size(); j++)
+ for (int j = i + 2; j < args.size(); j++) {
removal_docs.push_back(args[j]);
+ }
} else if (args[i] == "--export") {
editor = true; //needs editor
_export_preset = args[i + 1];
@@ -1504,13 +1616,27 @@ bool Main::start() {
String main_loop_type;
#ifdef TOOLS_ENABLED
if (doc_tool != "") {
-
Engine::get_singleton()->set_editor_hint(true); // Needed to instance editor-only classes for their default values
{
DirAccessRef da = DirAccess::open(doc_tool);
ERR_FAIL_COND_V_MSG(!da, false, "Argument supplied to --doctool must be a valid directory path.");
}
+
+#ifndef MODULE_MONO_ENABLED
+ // Hack to define Mono-specific project settings even on non-Mono builds,
+ // so that we don't lose their descriptions and default values in DocData.
+ // Default values should be synced with mono_gd/gd_mono.cpp.
+ GLOBAL_DEF("mono/debugger_agent/port", 23685);
+ GLOBAL_DEF("mono/debugger_agent/wait_for_debugger", false);
+ GLOBAL_DEF("mono/debugger_agent/wait_timeout", 3000);
+ GLOBAL_DEF("mono/profiler/args", "log:calls,alloc,sample,output=output.mlpd");
+ GLOBAL_DEF("mono/profiler/enabled", false);
+ GLOBAL_DEF("mono/unhandled_exception_policy", 0);
+ // From editor/csharp_project.cpp.
+ GLOBAL_DEF("mono/project/auto_update_project", true);
+#endif
+
DocData doc;
doc.generate(doc_base);
@@ -1520,7 +1646,11 @@ bool Main::start() {
print_line("Loading docs...");
for (int i = 0; i < _doc_data_class_path_count; i++) {
- String path = doc_tool.plus_file(_doc_data_class_paths[i].path);
+ // Custom modules are always located by absolute path.
+ String path = _doc_data_class_paths[i].path;
+ if (path.is_rel_path()) {
+ path = doc_tool.plus_file(path);
+ }
String name = _doc_data_class_paths[i].name;
doc_data_classes[name] = path;
if (!checked_paths.has(path)) {
@@ -1573,7 +1703,7 @@ bool Main::start() {
game_path = GLOBAL_DEF("application/run/main_scene", "");
}
- MainLoop *main_loop = NULL;
+ MainLoop *main_loop = nullptr;
if (editor) {
main_loop = memnew(SceneTree);
};
@@ -1582,12 +1712,12 @@ bool Main::start() {
#ifdef TOOLS_ENABLED
main_loop = test_main(test, args);
- if (!main_loop)
+ if (!main_loop) {
return false;
+ }
#endif
} else if (script != "") {
-
Ref<Script> script_res = ResourceLoader::load(script);
ERR_FAIL_COND_V_MSG(script_res.is_null(), false, "Can't load script: " + script);
@@ -1598,21 +1728,20 @@ bool Main::start() {
return false;
}
- if (script_res->can_instance() /*&& script_res->inherits_from("SceneTreeScripted")*/) {
-
+ if (script_res->can_instance()) {
StringName instance_type = script_res->get_instance_base_type();
Object *obj = ClassDB::instance(instance_type);
MainLoop *script_loop = Object::cast_to<MainLoop>(obj);
if (!script_loop) {
- if (obj)
+ if (obj) {
memdelete(obj);
- ERR_FAIL_V_MSG(false, "Can't load script '" + script + "', it does not inherit from a MainLoop type.");
+ }
+ ERR_FAIL_V_MSG(false, vformat("Can't load the script \"%s\" as it doesn't inherit from SceneTree or MainLoop.", script));
}
script_loop->set_init_script(script_res);
main_loop = script_loop;
} else {
-
return false;
}
@@ -1620,21 +1749,20 @@ bool Main::start() {
main_loop_type = GLOBAL_DEF("application/run/main_loop_type", "");
}
- if (!main_loop && main_loop_type == "")
+ if (!main_loop && main_loop_type == "") {
main_loop_type = "SceneTree";
+ }
if (!main_loop) {
if (!ClassDB::class_exists(main_loop_type)) {
- OS::get_singleton()->alert("Error: MainLoop type doesn't exist: " + main_loop_type);
+ DisplayServer::get_singleton()->alert("Error: MainLoop type doesn't exist: " + main_loop_type);
return false;
} else {
-
Object *ml = ClassDB::instance(main_loop_type);
ERR_FAIL_COND_V_MSG(!ml, false, "Can't instance MainLoop type.");
main_loop = Object::cast_to<MainLoop>(ml);
if (!main_loop) {
-
memdelete(ml);
ERR_FAIL_V_MSG(false, "Invalid MainLoop type.");
}
@@ -1642,7 +1770,6 @@ bool Main::start() {
}
if (main_loop->is_class("SceneTree")) {
-
SceneTree *sml = Object::cast_to<SceneTree>(main_loop);
#ifdef DEBUG_ENABLED
@@ -1654,6 +1781,11 @@ bool Main::start() {
}
#endif
+ bool embed_subwindows = GLOBAL_DEF("display/window/subwindows/embed_subwindows", false);
+
+ if (single_window || (!project_manager && !editor && embed_subwindows)) {
+ sml->get_root()->set_embed_subwindows_hint(true);
+ }
ResourceLoader::add_custom_loaders();
ResourceSaver::add_custom_savers();
@@ -1665,10 +1797,10 @@ bool Main::start() {
//first pass, add the constants so they exist before any script is loaded
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
-
String s = E->get().name;
- if (!s.begins_with("autoload/"))
+ if (!s.begins_with("autoload/")) {
continue;
+ }
String name = s.get_slicec('/', 1);
String path = ProjectSettings::get_singleton()->get(s);
bool global_var = false;
@@ -1686,10 +1818,10 @@ bool Main::start() {
//second pass, load into global constants
List<Node *> to_add;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
-
String s = E->get().name;
- if (!s.begins_with("autoload/"))
+ if (!s.begins_with("autoload/")) {
continue;
+ }
String name = s.get_slicec('/', 1);
String path = ProjectSettings::get_singleton()->get(s);
bool global_var = false;
@@ -1700,7 +1832,7 @@ bool Main::start() {
RES res = ResourceLoader::load(path);
ERR_CONTINUE_MSG(res.is_null(), "Can't autoload: " + path);
- Node *n = NULL;
+ Node *n = nullptr;
if (res->is_class("PackedScene")) {
Ref<PackedScene> ps = res;
n = ps->instance();
@@ -1712,7 +1844,7 @@ bool Main::start() {
Object *obj = ClassDB::instance(ibt);
- ERR_CONTINUE_MSG(obj == NULL, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt));
+ ERR_CONTINUE_MSG(obj == nullptr, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt));
n = Object::cast_to<Node>(obj);
n->set_script(script_res);
@@ -1732,14 +1864,13 @@ bool Main::start() {
}
for (List<Node *>::Element *E = to_add.front(); E; E = E->next()) {
-
sml->get_root()->add_child(E->get());
}
}
}
#ifdef TOOLS_ENABLED
- EditorNode *editor_node = NULL;
+ EditorNode *editor_node = nullptr;
if (editor) {
editor_node = memnew(EditorNode);
sml->get_root()->add_child(editor_node);
@@ -1752,9 +1883,8 @@ bool Main::start() {
#endif
{
-
int directional_atlas_size = GLOBAL_GET("rendering/quality/directional_shadow/size");
- VisualServer::get_singleton()->directional_shadow_atlas_set_size(directional_atlas_size);
+ RenderingServer::get_singleton()->directional_shadow_atlas_set_size(directional_atlas_size);
}
if (!editor && !project_manager) {
@@ -1763,31 +1893,41 @@ bool Main::start() {
String stretch_mode = GLOBAL_DEF("display/window/stretch/mode", "disabled");
String stretch_aspect = GLOBAL_DEF("display/window/stretch/aspect", "ignore");
Size2i stretch_size = Size2(GLOBAL_DEF("display/window/size/width", 0), GLOBAL_DEF("display/window/size/height", 0));
- real_t stretch_shrink = GLOBAL_DEF("display/window/stretch/shrink", 1.0);
-
- SceneTree::StretchMode sml_sm = SceneTree::STRETCH_MODE_DISABLED;
- if (stretch_mode == "2d")
- sml_sm = SceneTree::STRETCH_MODE_2D;
- else if (stretch_mode == "viewport")
- sml_sm = SceneTree::STRETCH_MODE_VIEWPORT;
-
- SceneTree::StretchAspect sml_aspect = SceneTree::STRETCH_ASPECT_IGNORE;
- if (stretch_aspect == "keep")
- sml_aspect = SceneTree::STRETCH_ASPECT_KEEP;
- else if (stretch_aspect == "keep_width")
- sml_aspect = SceneTree::STRETCH_ASPECT_KEEP_WIDTH;
- else if (stretch_aspect == "keep_height")
- sml_aspect = SceneTree::STRETCH_ASPECT_KEEP_HEIGHT;
- else if (stretch_aspect == "expand")
- sml_aspect = SceneTree::STRETCH_ASPECT_EXPAND;
-
- sml->set_screen_stretch(sml_sm, sml_aspect, stretch_size, stretch_shrink);
+
+ Window::ContentScaleMode cs_sm = Window::CONTENT_SCALE_MODE_DISABLED;
+ if (stretch_mode == "objects") {
+ cs_sm = Window::CONTENT_SCALE_MODE_OBJECTS;
+ } else if (stretch_mode == "pixels") {
+ cs_sm = Window::CONTENT_SCALE_MODE_PIXELS;
+ }
+
+ Window::ContentScaleAspect cs_aspect = Window::CONTENT_SCALE_ASPECT_IGNORE;
+ if (stretch_aspect == "keep") {
+ cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP;
+ } else if (stretch_aspect == "keep_width") {
+ cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP_WIDTH;
+ } else if (stretch_aspect == "keep_height") {
+ cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP_HEIGHT;
+ } else if (stretch_aspect == "expand") {
+ cs_aspect = Window::CONTENT_SCALE_ASPECT_EXPAND;
+ }
+
+ sml->get_root()->set_content_scale_mode(cs_sm);
+ sml->get_root()->set_content_scale_aspect(cs_aspect);
+ sml->get_root()->set_content_scale_size(stretch_size);
sml->set_auto_accept_quit(GLOBAL_DEF("application/config/auto_accept_quit", true));
sml->set_quit_on_go_back(GLOBAL_DEF("application/config/quit_on_go_back", true));
String appname = ProjectSettings::get_singleton()->get("application/config/name");
appname = TranslationServer::get_singleton()->translate(appname);
- OS::get_singleton()->set_window_title(appname);
+#ifdef DEBUG_ENABLED
+ // Append a suffix to the window title to denote that the project is running
+ // from a debug build (including the editor). Since this results in lower performance,
+ // this should be clearly presented to the user.
+ DisplayServer::get_singleton()->window_set_title(vformat("%s (DEBUG)", appname));
+#else
+ DisplayServer::get_singleton()->window_set_title(appname);
+#endif
int shadow_atlas_size = GLOBAL_GET("rendering/quality/shadow_atlas/size");
int shadow_atlas_q0_subdiv = GLOBAL_GET("rendering/quality/shadow_atlas/quadrant_0_subdiv");
@@ -1805,7 +1945,7 @@ bool Main::start() {
sml->get_root()->set_snap_controls_to_pixels(snap_controls);
bool font_oversampling = GLOBAL_DEF("rendering/quality/dynamic_fonts/use_oversampling", true);
- sml->set_use_font_oversampling(font_oversampling);
+ sml->get_root()->set_use_font_oversampling(font_oversampling);
int texture_filter = GLOBAL_DEF("rendering/canvas_textures/default_texture_filter", 1);
int texture_repeat = GLOBAL_DEF("rendering/canvas_textures/default_texture_repeat", 0);
@@ -1813,7 +1953,6 @@ bool Main::start() {
sml->get_root()->set_default_canvas_item_texture_repeat(Viewport::DefaultCanvasItemTextureRepeat(texture_repeat));
} else {
-
GLOBAL_DEF("display/window/stretch/mode", "disabled");
ProjectSettings::get_singleton()->set_custom_property_info("display/window/stretch/mode", PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,2d,viewport"));
GLOBAL_DEF("display/window/stretch/aspect", "ignore");
@@ -1831,18 +1970,25 @@ bool Main::start() {
ProjectSettings::get_singleton()->set_custom_property_info("rendering/canvas_textures/default_texture_repeat", PropertyInfo(Variant::INT, "rendering/canvas_textures/default_texture_repeat", PROPERTY_HINT_ENUM, "Disable,Enable,Mirror"));
}
+#ifdef TOOLS_ENABLED
+ if (editor) {
+ bool editor_embed_subwindows = EditorSettings::get_singleton()->get_setting("interface/editor/single_window_mode");
+
+ if (editor_embed_subwindows) {
+ sml->get_root()->set_embed_subwindows_hint(true);
+ }
+ }
+#endif
+
String local_game_path;
if (game_path != "" && !project_manager) {
-
local_game_path = game_path.replace("\\", "/");
if (!local_game_path.begins_with("res://")) {
bool absolute = (local_game_path.size() > 1) && (local_game_path[0] == '/' || local_game_path[1] == ':');
if (!absolute) {
-
if (ProjectSettings::get_singleton()->is_using_datapack()) {
-
local_game_path = "res://" + local_game_path;
} else {
@@ -1853,7 +1999,6 @@ bool Main::start() {
local_game_path = da->get_current_dir().plus_file(local_game_path);
memdelete(da);
} else {
-
DirAccess *da = DirAccess::open(local_game_path.substr(0, sep));
if (da) {
local_game_path = da->get_current_dir().plus_file(local_game_path.substr(sep + 1, local_game_path.length()));
@@ -1868,30 +2013,31 @@ bool Main::start() {
#ifdef TOOLS_ENABLED
if (editor) {
-
if (game_path != GLOBAL_GET("application/run/main_scene") || !editor_node->has_scenes_in_session()) {
Error serr = editor_node->load_scene(local_game_path);
- if (serr != OK)
+ if (serr != OK) {
ERR_PRINT("Failed to load scene");
+ }
}
- OS::get_singleton()->set_context(OS::CONTEXT_EDITOR);
+ DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_EDITOR);
}
#endif
if (!editor) {
- OS::get_singleton()->set_context(OS::CONTEXT_ENGINE);
+ DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_ENGINE);
}
}
if (!project_manager && !editor) { // game
// Load SSL Certificates from Project Settings (or builtin).
- Crypto::load_default_certificates(GLOBAL_DEF("network/ssl/certificates", ""));
+ Crypto::load_default_certificates(GLOBAL_DEF("network/ssl/certificate_bundle_override", ""));
if (game_path != "") {
- Node *scene = NULL;
+ Node *scene = nullptr;
Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path);
- if (scenedata.is_valid())
+ if (scenedata.is_valid()) {
scene = scenedata->instance();
+ }
ERR_FAIL_COND_V_MSG(!scene, false, "Failed loading scene: " + local_game_path);
sml->add_current_scene(scene);
@@ -1899,7 +2045,7 @@ bool Main::start() {
#ifdef OSX_ENABLED
String mac_iconpath = GLOBAL_DEF("application/config/macos_native_icon", "Variant()");
if (mac_iconpath != "") {
- OS::get_singleton()->set_native_icon(mac_iconpath);
+ DisplayServer::get_singleton()->set_native_icon(mac_iconpath);
hasicon = true;
}
#endif
@@ -1907,7 +2053,7 @@ bool Main::start() {
#ifdef WINDOWS_ENABLED
String win_iconpath = GLOBAL_DEF("application/config/windows_native_icon", "Variant()");
if (win_iconpath != "") {
- OS::get_singleton()->set_native_icon(win_iconpath);
+ DisplayServer::get_singleton()->set_native_icon(win_iconpath);
hasicon = true;
}
#endif
@@ -1917,7 +2063,7 @@ bool Main::start() {
Ref<Image> icon;
icon.instance();
if (ImageLoader::load_image(iconpath, icon) == OK) {
- OS::get_singleton()->set_icon(icon);
+ DisplayServer::get_singleton()->set_icon(icon);
hasicon = true;
}
}
@@ -1926,20 +2072,21 @@ bool Main::start() {
#ifdef TOOLS_ENABLED
if (project_manager || (script == "" && test == "" && game_path == "" && !editor)) {
-
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);
- OS::get_singleton()->set_context(OS::CONTEXT_PROJECTMAN);
+ DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_PROJECTMAN);
project_manager = true;
}
if (project_manager || editor) {
- // Hide console window if requested (Windows-only).
- bool hide_console = EditorSettings::get_singleton()->get_setting("interface/editor/hide_console_window");
- OS::get_singleton()->set_console_visible(!hide_console);
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CONSOLE_WINDOW)) {
+ // Hide console window if requested (Windows-only).
+ bool hide_console = EditorSettings::get_singleton()->get_setting("interface/editor/hide_console_window");
+ DisplayServer::get_singleton()->console_set_visible(!hide_console);
+ }
// Load SSL Certificates from Editor Settings (or builtin)
Crypto::load_default_certificates(EditorSettings::get_singleton()->get_setting("network/ssl/editor_ssl_certificates").operator String());
@@ -1949,7 +2096,7 @@ bool Main::start() {
if (!hasicon) {
Ref<Image> icon = memnew(Image(app_icon_png));
- OS::get_singleton()->set_icon(icon);
+ DisplayServer::get_singleton()->set_icon(icon);
}
OS::get_singleton()->set_main_loop(main_loop);
@@ -1968,7 +2115,6 @@ bool Main::start() {
*/
uint64_t Main::last_ticks = 0;
-uint64_t Main::target_ticks = 0;
uint32_t Main::frames = 0;
uint32_t Main::frame = 0;
bool Main::force_redraw_requested = false;
@@ -1982,7 +2128,6 @@ static uint64_t physics_process_max = 0;
static uint64_t idle_process_max = 0;
bool Main::iteration() {
-
//for now do not error on this
//ERR_FAIL_COND_V(iterating, false);
@@ -2025,28 +2170,27 @@ bool Main::iteration() {
Engine::get_singleton()->_in_physics = true;
for (int iters = 0; iters < advance.physics_steps; ++iters) {
-
uint64_t physics_begin = OS::get_singleton()->get_ticks_usec();
- PhysicsServer::get_singleton()->sync();
- PhysicsServer::get_singleton()->flush_queries();
+ PhysicsServer3D::get_singleton()->sync();
+ PhysicsServer3D::get_singleton()->flush_queries();
- Physics2DServer::get_singleton()->sync();
- Physics2DServer::get_singleton()->flush_queries();
+ PhysicsServer2D::get_singleton()->sync();
+ PhysicsServer2D::get_singleton()->flush_queries();
if (OS::get_singleton()->get_main_loop()->iteration(frame_slice * time_scale)) {
exit = true;
break;
}
- NavigationServer::get_singleton_mut()->process(frame_slice * time_scale);
+ NavigationServer3D::get_singleton_mut()->process(frame_slice * time_scale);
message_queue->flush();
- PhysicsServer::get_singleton()->step(frame_slice * time_scale);
+ PhysicsServer3D::get_singleton()->step(frame_slice * time_scale);
- Physics2DServer::get_singleton()->end_sync();
- Physics2DServer::get_singleton()->step(frame_slice * time_scale);
+ PhysicsServer2D::get_singleton()->end_sync();
+ PhysicsServer2D::get_singleton()->step(frame_slice * time_scale);
message_queue->flush();
@@ -2064,17 +2208,16 @@ bool Main::iteration() {
}
message_queue->flush();
- VisualServer::get_singleton()->sync(); //sync if still drawing from previous frames.
-
- if (OS::get_singleton()->can_draw() && !disable_render_loop) {
+ RenderingServer::get_singleton()->sync(); //sync if still drawing from previous frames.
+ if (DisplayServer::get_singleton()->can_any_window_draw() && RenderingServer::get_singleton()->is_render_loop_enabled()) {
if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) {
- if (VisualServer::get_singleton()->has_changed()) {
- VisualServer::get_singleton()->draw(true, scaled_step); // flush visual commands
+ if (RenderingServer::get_singleton()->has_changed()) {
+ RenderingServer::get_singleton()->draw(true, scaled_step); // flush visual commands
Engine::get_singleton()->frames_drawn++;
}
} else {
- VisualServer::get_singleton()->draw(true, scaled_step); // flush visual commands
+ RenderingServer::get_singleton()->draw(true, scaled_step); // flush visual commands
Engine::get_singleton()->frames_drawn++;
force_redraw_requested = false;
}
@@ -2090,18 +2233,14 @@ bool Main::iteration() {
AudioServer::get_singleton()->update();
- if (script_debugger) {
- if (script_debugger->is_profiling()) {
- script_debugger->profiling_set_frame_times(USEC_TO_SEC(frame_time), USEC_TO_SEC(idle_process_ticks), USEC_TO_SEC(physics_process_ticks), frame_slice);
- }
- script_debugger->idle_poll();
+ if (EngineDebugger::is_active()) {
+ EngineDebugger::get_singleton()->iteration(frame_time, idle_process_ticks, physics_process_ticks, frame_slice);
}
frames++;
Engine::get_singleton()->_idle_frames++;
if (frame > 1000000) {
-
if (editor || project_manager) {
if (print_fps) {
print_line("Editor FPS: " + itos(frames));
@@ -2122,26 +2261,11 @@ bool Main::iteration() {
iterating--;
- if (fixed_fps != -1)
+ if (fixed_fps != -1) {
return exit;
-
- if (OS::get_singleton()->is_in_low_processor_usage_mode() || !OS::get_singleton()->can_draw())
- OS::get_singleton()->delay_usec(OS::get_singleton()->get_low_processor_usage_mode_sleep_usec()); //apply some delay to force idle time
- else {
- uint32_t frame_delay = Engine::get_singleton()->get_frame_delay();
- if (frame_delay)
- OS::get_singleton()->delay_usec(Engine::get_singleton()->get_frame_delay() * 1000);
}
- int target_fps = Engine::get_singleton()->get_target_fps();
- if (target_fps > 0 && !Engine::get_singleton()->is_editor_hint()) {
- uint64_t time_step = 1000000L / target_fps;
- target_ticks += time_step;
- uint64_t current_ticks = OS::get_singleton()->get_ticks_usec();
- if (current_ticks < target_ticks) OS::get_singleton()->delay_usec(target_ticks - current_ticks);
- current_ticks = OS::get_singleton()->get_ticks_usec();
- target_ticks = MIN(MAX(target_ticks, current_ticks - time_step), current_ticks + time_step);
- }
+ OS::get_singleton()->add_frame_delay(DisplayServer::get_singleton()->window_can_draw());
#ifdef TOOLS_ENABLED
if (auto_build_solutions) {
@@ -2170,27 +2294,15 @@ void Main::force_redraw() {
* The order matters as some of those steps are linked with each other.
*/
void Main::cleanup() {
-
ERR_FAIL_COND(!_start_success);
- if (script_debugger) {
- // Flush any remaining messages
- script_debugger->idle_poll();
- }
+ EngineDebugger::deinitialize();
ResourceLoader::remove_custom_loaders();
ResourceSaver::remove_custom_savers();
+ // Flush before uninitializing the scene, but delete the MessageQueue as late as possible.
message_queue->flush();
- memdelete(message_queue);
-
- if (script_debugger) {
- if (use_debug_profiler) {
- script_debugger->profiling_end();
- }
-
- memdelete(script_debugger);
- }
OS::get_singleton()->delete_main_loop();
@@ -2204,15 +2316,18 @@ void Main::cleanup() {
ScriptServer::finish_languages();
// Sync pending commands that may have been queued from a different thread during ScriptServer finalization
- VisualServer::get_singleton()->sync();
+ RenderingServer::get_singleton()->sync();
+
+ //clear global shader variables before scene and other graphics stuff is deinitialized.
+ rendering_server->global_variables_clear();
#ifdef TOOLS_ENABLED
EditorNode::unregister_editor_types();
#endif
- if (arvr_server) {
+ if (xr_server) {
// cleanup now before we pull the rug from underneath...
- memdelete(arvr_server);
+ memdelete(xr_server);
}
ImageLoader::cleanup();
@@ -2233,23 +2348,36 @@ void Main::cleanup() {
}
OS::get_singleton()->finalize();
+
finalize_physics();
finalize_navigation_server();
+ finalize_display();
+
+ if (input) {
+ memdelete(input);
+ }
- if (packed_data)
+ if (packed_data) {
memdelete(packed_data);
- if (file_access_network_client)
+ }
+ if (file_access_network_client) {
memdelete(file_access_network_client);
- if (performance)
+ }
+ if (performance) {
memdelete(performance);
- if (input_map)
+ }
+ if (input_map) {
memdelete(input_map);
- if (translation_server)
+ }
+ if (translation_server) {
memdelete(translation_server);
- if (globals)
+ }
+ if (globals) {
memdelete(globals);
- if (engine)
+ }
+ if (engine) {
memdelete(engine);
+ }
if (OS::get_singleton()->is_restart_on_exit_set()) {
//attempt to restart with arguments
@@ -2260,6 +2388,10 @@ void Main::cleanup() {
OS::get_singleton()->set_restart_on_exit(false, List<String>()); //clear list (uses memory)
}
+ // Now should be safe to delete MessageQueue (famous last words).
+ message_queue->flush();
+ memdelete(message_queue);
+
unregister_core_driver_types();
unregister_core_types();