diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/main.cpp | 228 | ||||
-rw-r--r-- | main/main.h | 6 | ||||
-rw-r--r-- | main/main_timer_sync.cpp | 76 | ||||
-rw-r--r-- | main/main_timer_sync.h | 24 | ||||
-rw-r--r-- | main/performance.cpp | 8 | ||||
-rw-r--r-- | main/performance.h | 9 |
6 files changed, 203 insertions, 148 deletions
diff --git a/main/main.cpp b/main/main.cpp index f2d057665a..f454829100 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -30,6 +30,7 @@ #include "main.h" +#include "core/config/project_settings.h" #include "core/core_string_names.h" #include "core/crypto/crypto.h" #include "core/debugger/engine_debugger.h" @@ -41,12 +42,11 @@ #include "core/io/image_loader.h" #include "core/io/ip.h" #include "core/io/resource_loader.h" -#include "core/message_queue.h" +#include "core/object/message_queue.h" #include "core/os/dir_access.h" #include "core/os/os.h" -#include "core/project_settings.h" #include "core/register_core_types.h" -#include "core/translation.h" +#include "core/string/translation.h" #include "core/version.h" #include "core/version_hash.gen.h" #include "drivers/register_driver_types.h" @@ -70,8 +70,9 @@ #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_default.h" #include "servers/rendering/rendering_server_wrap_mt.h" +#include "servers/text_server.h" #include "servers/xr_server.h" #ifdef TESTS_ENABLED @@ -80,8 +81,8 @@ #ifdef TOOLS_ENABLED -#include "editor/doc_data.h" #include "editor/doc_data_class_path.gen.h" +#include "editor/doc_tools.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" #include "editor/progress_dialog.h" @@ -113,6 +114,7 @@ static DisplayServer *display_server = nullptr; static RenderingServer *rendering_server = nullptr; static CameraServer *camera_server = nullptr; static XRServer *xr_server = nullptr; +static TextServerManager *tsman = nullptr; static PhysicsServer3D *physics_server = nullptr; static PhysicsServer2D *physics_2d_server = nullptr; static NavigationServer3D *navigation_server = nullptr; @@ -122,6 +124,8 @@ static bool _start_success = false; // Drivers +String text_driver = ""; +static int text_driver_idx = -1; static int display_driver_idx = -1; static int audio_driver_idx = -1; @@ -167,6 +171,8 @@ static bool disable_render_loop = false; static int fixed_fps = -1; static bool print_fps = false; +bool profile_gpu = false; + /* Helper methods */ // Used by Mono module, should likely be registered in Engine singleton instead @@ -252,8 +258,8 @@ void finalize_navigation_server() { 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"); - OS::get_singleton()->print("(c) 2014-2020 Godot Engine contributors.\n"); + OS::get_singleton()->print("(c) 2007-2021 Juan Linietsky, Ariel Manzur.\n"); + OS::get_singleton()->print("(c) 2014-2021 Godot Engine contributors.\n"); OS::get_singleton()->print("\n"); OS::get_singleton()->print("Usage: %s [options] [path to scene or 'project.godot' file]\n", p_binary); OS::get_singleton()->print("\n"); @@ -304,7 +310,11 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(")"); } OS::get_singleton()->print("].\n"); + OS::get_singleton()->print(" --rendering-driver <driver> Rendering driver (depends on display driver).\n"); + + OS::get_singleton()->print(" --text-driver <driver> Text driver (Fonts, BiDi, shaping)\n"); + OS::get_singleton()->print("\n"); #ifndef SERVER_ENABLED @@ -334,8 +344,8 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(" -d, --debug Debug (local stdout debugger).\n"); 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"); -#if DEBUG_ENABLED OS::get_singleton()->print(" --vk-layers Enable Vulkan Validation layers for debugging.\n"); +#if DEBUG_ENABLED OS::get_singleton()->print(" --gpu-abort Abort on GPU errors (usually validation layer errors), may help see the problem if your system freezes.\n"); #endif OS::get_singleton()->print(" --remote-debug <uri> Remote debug (<protocol>://<host/IP>[:<port>], e.g. tcp://127.0.0.1:6007).\n"); @@ -349,6 +359,7 @@ void Main::print_help(const char *p_binary) { OS::get_singleton()->print(" --disable-crash-handler Disable crash handler when supported by the platform code.\n"); OS::get_singleton()->print(" --fixed-fps <fps> Force a fixed number of frames per second. This setting disables real-time synchronization.\n"); OS::get_singleton()->print(" --print-fps Print the frames per second to the stdout.\n"); + OS::get_singleton()->print(" --profile-gpu Show a simple profile of the tasks that took more time during frame rendering.\n"); OS::get_singleton()->print("\n"); OS::get_singleton()->print("Standalone tools:\n"); @@ -380,8 +391,6 @@ Error Main::test_setup() { engine = memnew(Engine); - ClassDB::init(); - register_core_types(); register_core_driver_types(); @@ -499,8 +508,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph engine = memnew(Engine); - ClassDB::init(); - MAIN_PRINT("Main: Initialize CORE"); register_core_types(); @@ -520,6 +527,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph ClassDB::register_class<Performance>(); engine->add_singleton(Engine::Singleton("Performance", performance)); + // Only flush stdout in debug builds by default, as spamming `print()` will + // decrease performance if this is enabled. + GLOBAL_DEF("application/run/flush_stdout_on_print", false); + GLOBAL_DEF("application/run/flush_stdout_on_print.debug", true); + GLOBAL_DEF("debug/settings/crash_handler/message", String("Please include this when reporting the bug on https://github.com/godotengine/godot/issues")); @@ -649,6 +661,14 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->print("Missing audio driver argument, aborting.\n"); goto error; } + } else if (I->get() == "--text-driver") { + if (I->next()) { + text_driver = I->next()->get(); + N = I->next()->next(); + } else { + OS::get_singleton()->print("Missing text driver argument, aborting.\n"); + goto error; + } } else if (I->get() == "--display-driver") { // force video driver @@ -698,9 +718,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "-w" || I->get() == "--windowed") { // force windowed window init_windowed = true; -#ifdef DEBUG_ENABLED } else if (I->get() == "--vk-layers") { Engine::singleton->use_validation_layers = true; +#ifdef DEBUG_ENABLED } else if (I->get() == "--gpu-abort") { Engine::singleton->abort_on_gpu_errors = true; #endif @@ -989,6 +1009,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } } else if (I->get() == "--print-fps") { print_fps = true; + } else if (I->get() == "--profile-gpu") { + profile_gpu = true; } else if (I->get() == "--disable-crash-handler") { OS::get_singleton()->disable_crash_handler(); } else if (I->get() == "--skip-breakpoints") { @@ -1143,7 +1165,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph use_custom_res = false; input_map->load_default(); //keys for editor } else { - input_map->load_from_globals(); //keys for game + input_map->load_from_project_settings(); //keys for game } if (bool(ProjectSettings::get_singleton()->get("application/run/disable_stdout"))) { @@ -1228,6 +1250,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } } + GLOBAL_DEF("display/window/force_right_to_left_layout_direction", false); + if (!force_lowdpi) { OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", false); } @@ -1388,6 +1412,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph error: + text_driver = ""; display_driver = ""; audio_driver = ""; tablet_driver = ""; @@ -1449,6 +1474,65 @@ Error Main::setup2(Thread::ID p_main_tid_override) { Thread::_main_thread_id = p_main_tid_override; } + /* Determine text driver */ + + GLOBAL_DEF("display/window/text_name", ""); + if (text_driver == "") { + text_driver = GLOBAL_GET("display/window/text_name"); + } + + if (text_driver != "") { + /* Load user selected text server. */ + for (int i = 0; i < TextServerManager::get_interface_count(); i++) { + if (text_driver == TextServerManager::get_interface_name(i)) { + text_driver_idx = i; + break; + } + } + } + + if (text_driver_idx < 0) { + /* If not selected, use one with the most features available. */ + int max_features = 0; + for (int i = 0; i < TextServerManager::get_interface_count(); i++) { + uint32_t ftrs = TextServerManager::get_interface_features(i); + int features = 0; + while (ftrs) { + features += ftrs & 1; + ftrs >>= 1; + } + if (features >= max_features) { + max_features = features; + text_driver_idx = i; + } + } + } + printf("Using %s text server...\n", TextServerManager::get_interface_name(text_driver_idx).utf8().get_data()); + + /* Initialize Text Server */ + + { + tsman = memnew(TextServerManager); + Error err; + TextServer *text_server = TextServerManager::initialize(text_driver_idx, err); + if (err != OK || text_server == nullptr) { + for (int i = 0; i < TextServerManager::get_interface_count(); i++) { + if (i == text_driver_idx) { + continue; //don't try the same twice + } + text_server = TextServerManager::initialize(i, err); + if (err == OK && text_server != nullptr) { + break; + } + } + } + + if (err != OK || text_server == nullptr) { + ERR_PRINT("Unable to create TextServer, all text drivers failed."); + return err; + } + } + /* Initialize Input */ input = memnew(Input); @@ -1459,23 +1543,21 @@ Error Main::setup2(Thread::ID p_main_tid_override) { 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) { + display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_flags, window_size, err); + if (err != OK || display_server == nullptr) { //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) { + display_server = DisplayServer::create(i, rendering_driver, window_mode, window_flags, window_size, err); + if (err == OK && display_server != nullptr) { break; } } } - if (!display_server || err != OK) { + if (err != OK || display_server == nullptr) { ERR_PRINT("Unable to create DisplayServer, all display drivers failed."); return err; } @@ -1487,7 +1569,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { /* Initialize Visual Server */ - rendering_server = memnew(RenderingServerRaster); + rendering_server = memnew(RenderingServerDefault); 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() == @@ -1497,6 +1579,10 @@ Error Main::setup2(Thread::ID p_main_tid_override) { rendering_server->init(); rendering_server->set_render_loop_enabled(!disable_render_loop); + if (profile_gpu) { + rendering_server->set_print_gpu_profile(true); + } + OS::get_singleton()->initialize_joypads(); /* Initialize Audio Driver */ @@ -1608,7 +1694,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { GLOBAL_DEF("application/config/icon", String()); ProjectSettings::get_singleton()->set_custom_property_info("application/config/icon", PropertyInfo(Variant::STRING, "application/config/icon", - PROPERTY_HINT_FILE, "*.png,*.webp")); + PROPERTY_HINT_FILE, "*.png,*.webp,*.svg,*.svgz")); GLOBAL_DEF("application/config/macos_native_icon", String()); ProjectSettings::get_singleton()->set_custom_property_info("application/config/macos_native_icon", @@ -1838,10 +1924,10 @@ bool Main::start() { GLOBAL_DEF("mono/project/auto_update_project", true); #endif - DocData doc; + DocTools doc; doc.generate(doc_base); - DocData docsrc; + DocTools docsrc; Map<String, String> doc_data_classes; Set<String> checked_paths; print_line("Loading docs..."); @@ -1881,7 +1967,7 @@ bool Main::start() { doc.merge_from(docsrc); for (Set<String>::Element *E = checked_paths.front(); E; E = E->next()) { print_line("Erasing old docs at: " + E->get()); - DocData::erase_classes(E->get()); + DocTools::erase_classes(E->get()); } print_line("Generating new docs..."); @@ -1890,14 +1976,6 @@ bool Main::start() { return false; } - if (_export_preset != "") { - if (positional_arg == "") { - String err = "Command line includes export parameter option, but no destination path was given.\n"; - err += "Please specify the binary's file path to export to. Aborting export."; - ERR_PRINT(err); - return false; - } - } #endif if (script == "" && game_path == "" && String(GLOBAL_DEF("application/run/main_scene", "")) != "") { @@ -1934,7 +2012,7 @@ bool Main::start() { script)); } - script_loop->set_init_script(script_res); + script_loop->set_initialize_script(script_res); main_loop = script_loop; } else { return false; @@ -1953,7 +2031,7 @@ bool Main::start() { DisplayServer::get_singleton()->alert("Error: Invalid MainLoop script base type: " + script_base); ERR_FAIL_V_MSG(false, vformat("The global class %s does not inherit from SceneTree or MainLoop.", main_loop_type)); } - script_loop->set_init_script(script_res); + script_loop->set_initialize_script(script_res); main_loop = script_loop; } } @@ -2073,11 +2151,6 @@ bool Main::start() { } #endif - { - int directional_atlas_size = GLOBAL_GET("rendering/quality/directional_shadow/size"); - RenderingServer::get_singleton()->directional_shadow_atlas_set_size(directional_atlas_size); - } - if (!editor && !project_manager) { //standard helpers that can be changed from main config @@ -2121,22 +2194,6 @@ bool Main::start() { 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"); - int shadow_atlas_q1_subdiv = GLOBAL_GET("rendering/quality/shadow_atlas/quadrant_1_subdiv"); - int shadow_atlas_q2_subdiv = GLOBAL_GET("rendering/quality/shadow_atlas/quadrant_2_subdiv"); - int shadow_atlas_q3_subdiv = GLOBAL_GET("rendering/quality/shadow_atlas/quadrant_3_subdiv"); - - sml->get_root()->set_shadow_atlas_size(shadow_atlas_size); - sml->get_root()->set_shadow_atlas_quadrant_subdiv(0, Viewport::ShadowAtlasQuadrantSubdiv( - shadow_atlas_q0_subdiv)); - sml->get_root()->set_shadow_atlas_quadrant_subdiv(1, Viewport::ShadowAtlasQuadrantSubdiv( - shadow_atlas_q1_subdiv)); - sml->get_root()->set_shadow_atlas_quadrant_subdiv(2, Viewport::ShadowAtlasQuadrantSubdiv( - shadow_atlas_q2_subdiv)); - sml->get_root()->set_shadow_atlas_quadrant_subdiv(3, Viewport::ShadowAtlasQuadrantSubdiv( - shadow_atlas_q3_subdiv)); - bool snap_controls = GLOBAL_DEF("gui/common/snap_controls_to_pixels", true); sml->get_root()->set_snap_controls_to_pixels(snap_controls); @@ -2232,7 +2289,7 @@ bool Main::start() { #ifdef TOOLS_ENABLED if (editor) { - if (game_path != GLOBAL_GET("application/run/main_scene") || !editor_node->has_scenes_in_session()) { + if (game_path != String(GLOBAL_GET("application/run/main_scene")) || !editor_node->has_scenes_in_session()) { Error serr = editor_node->load_scene(local_game_path); if (serr != OK) { ERR_PRINT("Failed to load scene"); @@ -2349,7 +2406,7 @@ bool Main::is_iterating() { // For performance metrics. static uint64_t physics_process_max = 0; -static uint64_t idle_process_max = 0; +static uint64_t process_max = 0; bool Main::iteration() { //for now do not error on this @@ -2365,19 +2422,19 @@ bool Main::iteration() { uint64_t ticks_elapsed = ticks - last_ticks; int physics_fps = Engine::get_singleton()->get_iterations_per_second(); - float frame_slice = 1.0 / physics_fps; + float physics_step = 1.0 / physics_fps; float time_scale = Engine::get_singleton()->get_time_scale(); - MainFrameTime advance = main_timer_sync.advance(frame_slice, physics_fps); - double step = advance.idle_step; - double scaled_step = step * time_scale; + MainFrameTime advance = main_timer_sync.advance(physics_step, physics_fps); + double process_step = advance.process_step; + double scaled_step = process_step * time_scale; - Engine::get_singleton()->_frame_step = step; + Engine::get_singleton()->_process_step = process_step; Engine::get_singleton()->_physics_interpolation_fraction = advance.interpolation_fraction; uint64_t physics_process_ticks = 0; - uint64_t idle_process_ticks = 0; + uint64_t process_ticks = 0; frame += ticks_elapsed; @@ -2385,7 +2442,7 @@ bool Main::iteration() { static const int max_physics_steps = 8; if (fixed_fps == -1 && advance.physics_steps > max_physics_steps) { - step -= (advance.physics_steps - max_physics_steps) * frame_slice; + process_step -= (advance.physics_steps - max_physics_steps) * physics_step; advance.physics_steps = max_physics_steps; } @@ -2396,39 +2453,37 @@ bool Main::iteration() { for (int iters = 0; iters < advance.physics_steps; ++iters) { uint64_t physics_begin = OS::get_singleton()->get_ticks_usec(); - PhysicsServer3D::get_singleton()->sync(); PhysicsServer3D::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)) { + if (OS::get_singleton()->get_main_loop()->physics_process(physics_step * time_scale)) { exit = true; break; } - NavigationServer3D::get_singleton_mut()->process(frame_slice * time_scale); + NavigationServer3D::get_singleton_mut()->process(physics_step * time_scale); message_queue->flush(); - PhysicsServer3D::get_singleton()->step(frame_slice * time_scale); + PhysicsServer3D::get_singleton()->step(physics_step * time_scale); PhysicsServer2D::get_singleton()->end_sync(); - PhysicsServer2D::get_singleton()->step(frame_slice * time_scale); + PhysicsServer2D::get_singleton()->step(physics_step * time_scale); message_queue->flush(); - physics_process_ticks = MAX(physics_process_ticks, OS::get_singleton()->get_ticks_usec() - - physics_begin); // keep the largest one for reference + physics_process_ticks = MAX(physics_process_ticks, OS::get_singleton()->get_ticks_usec() - physics_begin); // keep the largest one for reference physics_process_max = MAX(OS::get_singleton()->get_ticks_usec() - physics_begin, physics_process_max); Engine::get_singleton()->_physics_frames++; } Engine::get_singleton()->_in_physics = false; - uint64_t idle_begin = OS::get_singleton()->get_ticks_usec(); + uint64_t process_begin = OS::get_singleton()->get_ticks_usec(); - if (OS::get_singleton()->get_main_loop()->idle(step * time_scale)) { + if (OS::get_singleton()->get_main_loop()->process(process_step * time_scale)) { exit = true; } message_queue->flush(); @@ -2449,8 +2504,8 @@ bool Main::iteration() { } } - idle_process_ticks = OS::get_singleton()->get_ticks_usec() - idle_begin; - idle_process_max = MAX(idle_process_ticks, idle_process_max); + process_ticks = OS::get_singleton()->get_ticks_usec() - process_begin; + process_max = MAX(process_ticks, process_max); uint64_t frame_time = OS::get_singleton()->get_ticks_usec() - ticks; for (int i = 0; i < ScriptServer::get_language_count(); i++) { @@ -2460,11 +2515,11 @@ bool Main::iteration() { AudioServer::get_singleton()->update(); if (EngineDebugger::is_active()) { - EngineDebugger::get_singleton()->iteration(frame_time, idle_process_ticks, physics_process_ticks, frame_slice); + EngineDebugger::get_singleton()->iteration(frame_time, process_ticks, physics_process_ticks, physics_step); } frames++; - Engine::get_singleton()->_idle_frames++; + Engine::get_singleton()->_process_frames++; if (frame > 1000000) { if (editor || project_manager) { @@ -2476,9 +2531,9 @@ bool Main::iteration() { } Engine::get_singleton()->_fps = frames; - performance->set_process_time(USEC_TO_SEC(idle_process_max)); + performance->set_process_time(USEC_TO_SEC(process_max)); performance->set_physics_process_time(USEC_TO_SEC(physics_process_max)); - idle_process_max = 0; + process_max = 0; physics_process_max = 0; frame %= 1000000; @@ -2581,6 +2636,10 @@ void Main::cleanup() { finalize_navigation_server(); finalize_display(); + if (tsman) { + memdelete(tsman); + } + if (input) { memdelete(input); } @@ -2611,8 +2670,7 @@ void Main::cleanup() { //attempt to restart with arguments String exec = OS::get_singleton()->get_executable_path(); List<String> args = OS::get_singleton()->get_restart_on_exit_arguments(); - OS::ProcessID pid = 0; - OS::get_singleton()->execute(exec, args, false, &pid); + OS::get_singleton()->create_process(exec, args); OS::get_singleton()->set_restart_on_exit(false, List<String>()); //clear list (uses memory) } diff --git a/main/main.h b/main/main.h index 75a1c0d8cd..9e606c188d 100644 --- a/main/main.h +++ b/main/main.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -31,7 +31,7 @@ #ifndef MAIN_H #define MAIN_H -#include "core/error_list.h" +#include "core/error/error_list.h" #include "core/os/thread.h" #include "core/typedefs.h" diff --git a/main/main_timer_sync.cpp b/main/main_timer_sync.cpp index 5252ea005b..93448d0904 100644 --- a/main/main_timer_sync.cpp +++ b/main/main_timer_sync.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -30,17 +30,17 @@ #include "main_timer_sync.h" -void MainFrameTime::clamp_idle(float min_idle_step, float max_idle_step) { - if (idle_step < min_idle_step) { - idle_step = min_idle_step; - } else if (idle_step > max_idle_step) { - idle_step = max_idle_step; +void MainFrameTime::clamp_process_step(float min_process_step, float max_process_step) { + if (process_step < min_process_step) { + process_step = min_process_step; + } else if (process_step > max_process_step) { + process_step = max_process_step; } } ///////////////////////////////// -// returns the fraction of p_frame_slice required for the timer to overshoot +// returns the fraction of p_physics_step required for the timer to overshoot // before advance_core considers changing the physics_steps return from // the typical values as defined by typical_physics_steps float MainTimerSync::get_physics_jitter_fix() { @@ -72,15 +72,15 @@ int MainTimerSync::get_average_physics_steps(float &p_min, float &p_max) { return CONTROL_STEPS; } -// advance physics clock by p_idle_step, return appropriate number of steps to simulate -MainFrameTime MainTimerSync::advance_core(float p_frame_slice, int p_iterations_per_second, float p_idle_step) { +// advance physics clock by p_process_step, return appropriate number of steps to simulate +MainFrameTime MainTimerSync::advance_core(float p_physics_step, int p_physics_fps, float p_process_step) { MainFrameTime ret; - ret.idle_step = p_idle_step; + ret.process_step = p_process_step; // simple determination of number of physics iteration - time_accum += ret.idle_step; - ret.physics_steps = floor(time_accum * p_iterations_per_second); + time_accum += ret.process_step; + ret.physics_steps = floor(time_accum * p_physics_fps); int min_typical_steps = typical_physics_steps[0]; int max_typical_steps = min_typical_steps + 1; @@ -107,7 +107,7 @@ MainFrameTime MainTimerSync::advance_core(float p_frame_slice, int p_iterations_ // try to keep it consistent with previous iterations if (ret.physics_steps < min_typical_steps) { - const int max_possible_steps = floor((time_accum)*p_iterations_per_second + get_physics_jitter_fix()); + const int max_possible_steps = floor((time_accum)*p_physics_fps + get_physics_jitter_fix()); if (max_possible_steps < min_typical_steps) { ret.physics_steps = max_possible_steps; update_typical = true; @@ -115,7 +115,7 @@ MainFrameTime MainTimerSync::advance_core(float p_frame_slice, int p_iterations_ ret.physics_steps = min_typical_steps; } } else if (ret.physics_steps > max_typical_steps) { - const int min_possible_steps = floor((time_accum)*p_iterations_per_second - get_physics_jitter_fix()); + const int min_possible_steps = floor((time_accum)*p_physics_fps - get_physics_jitter_fix()); if (min_possible_steps > max_typical_steps) { ret.physics_steps = min_possible_steps; update_typical = true; @@ -124,7 +124,7 @@ MainFrameTime MainTimerSync::advance_core(float p_frame_slice, int p_iterations_ } } - time_accum -= ret.physics_steps * p_frame_slice; + time_accum -= ret.physics_steps * p_physics_step; // keep track of accumulated step counts for (int i = CONTROL_STEPS - 2; i >= 0; --i) { @@ -146,52 +146,52 @@ MainFrameTime MainTimerSync::advance_core(float p_frame_slice, int p_iterations_ } // calls advance_core, keeps track of deficit it adds to animaption_step, make sure the deficit sum stays close to zero -MainFrameTime MainTimerSync::advance_checked(float p_frame_slice, int p_iterations_per_second, float p_idle_step) { +MainFrameTime MainTimerSync::advance_checked(float p_physics_step, int p_physics_fps, float p_process_step) { if (fixed_fps != -1) { - p_idle_step = 1.0 / fixed_fps; + p_process_step = 1.0 / fixed_fps; } // compensate for last deficit - p_idle_step += time_deficit; + p_process_step += time_deficit; - MainFrameTime ret = advance_core(p_frame_slice, p_iterations_per_second, p_idle_step); + MainFrameTime ret = advance_core(p_physics_step, p_physics_fps, p_process_step); - // we will do some clamping on ret.idle_step and need to sync those changes to time_accum, + // we will do some clamping on ret.process_step and need to sync those changes to time_accum, // that's easiest if we just remember their fixed difference now - const double idle_minus_accum = ret.idle_step - time_accum; + const double process_minus_accum = ret.process_step - time_accum; - // first, least important clamping: keep ret.idle_step consistent with typical_physics_steps. - // this smoothes out the idle steps and culls small but quick variations. + // first, least important clamping: keep ret.process_step consistent with typical_physics_steps. + // this smoothes out the process steps and culls small but quick variations. { float min_average_physics_steps, max_average_physics_steps; int consistent_steps = get_average_physics_steps(min_average_physics_steps, max_average_physics_steps); if (consistent_steps > 3) { - ret.clamp_idle(min_average_physics_steps * p_frame_slice, max_average_physics_steps * p_frame_slice); + ret.clamp_process_step(min_average_physics_steps * p_physics_step, max_average_physics_steps * p_physics_step); } } // second clamping: keep abs(time_deficit) < jitter_fix * frame_slise - float max_clock_deviation = get_physics_jitter_fix() * p_frame_slice; - ret.clamp_idle(p_idle_step - max_clock_deviation, p_idle_step + max_clock_deviation); + float max_clock_deviation = get_physics_jitter_fix() * p_physics_step; + ret.clamp_process_step(p_process_step - max_clock_deviation, p_process_step + max_clock_deviation); - // last clamping: make sure time_accum is between 0 and p_frame_slice for consistency between physics and idle - ret.clamp_idle(idle_minus_accum, idle_minus_accum + p_frame_slice); + // last clamping: make sure time_accum is between 0 and p_physics_step for consistency between physics and process + ret.clamp_process_step(process_minus_accum, process_minus_accum + p_physics_step); // restore time_accum - time_accum = ret.idle_step - idle_minus_accum; + time_accum = ret.process_step - process_minus_accum; // track deficit - time_deficit = p_idle_step - ret.idle_step; + time_deficit = p_process_step - ret.process_step; - // p_frame_slice is 1.0 / iterations_per_sec + // p_physics_step is 1.0 / iterations_per_sec // i.e. the time in seconds taken by a physics tick - ret.interpolation_fraction = time_accum / p_frame_slice; + ret.interpolation_fraction = time_accum / p_physics_step; return ret; } // determine wall clock step since last iteration -float MainTimerSync::get_cpu_idle_step() { +float MainTimerSync::get_cpu_process_step() { uint64_t cpu_ticks_elapsed = current_cpu_ticks_usec - last_cpu_ticks_usec; last_cpu_ticks_usec = current_cpu_ticks_usec; @@ -219,9 +219,9 @@ void MainTimerSync::set_fixed_fps(int p_fixed_fps) { fixed_fps = p_fixed_fps; } -// advance one frame, return timesteps to take -MainFrameTime MainTimerSync::advance(float p_frame_slice, int p_iterations_per_second) { - float cpu_idle_step = get_cpu_idle_step(); +// advance one physics frame, return timesteps to take +MainFrameTime MainTimerSync::advance(float p_physics_step, int p_physics_fps) { + float cpu_process_step = get_cpu_process_step(); - return advance_checked(p_frame_slice, p_iterations_per_second, cpu_idle_step); + return advance_checked(p_physics_step, p_physics_fps, cpu_process_step); } diff --git a/main/main_timer_sync.h b/main/main_timer_sync.h index 2126381c7c..884978bf96 100644 --- a/main/main_timer_sync.h +++ b/main/main_timer_sync.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -31,14 +31,14 @@ #ifndef MAIN_TIMER_SYNC_H #define MAIN_TIMER_SYNC_H -#include "core/engine.h" +#include "core/config/engine.h" struct MainFrameTime { - float idle_step; // time to advance idles for (argument to process()) + float process_step; // delta time to advance during process() int physics_steps; // number of times to iterate the physics engine float interpolation_fraction; // fraction through the current physics tick - void clamp_idle(float min_idle_step, float max_idle_step); + void clamp_process_step(float min_process_step, float max_process_step); }; class MainTimerSync { @@ -49,7 +49,7 @@ class MainTimerSync { // logical game time since last physics timestep float time_accum = 0; - // current difference between wall clock time and reported sum of idle_steps + // current difference between wall clock time and reported sum of process_steps float time_deficit = 0; // number of frames back for keeping accumulated physics steps roughly constant. @@ -67,7 +67,7 @@ class MainTimerSync { int fixed_fps = 0; protected: - // returns the fraction of p_frame_slice required for the timer to overshoot + // returns the fraction of p_physics_step required for the timer to overshoot // before advance_core considers changing the physics_steps return from // the typical values as defined by typical_physics_steps float get_physics_jitter_fix(); @@ -76,14 +76,14 @@ protected: // return value: number of frames back this data is consistent int get_average_physics_steps(float &p_min, float &p_max); - // advance physics clock by p_idle_step, return appropriate number of steps to simulate - MainFrameTime advance_core(float p_frame_slice, int p_iterations_per_second, float p_idle_step); + // advance physics clock by p_process_step, return appropriate number of steps to simulate + MainFrameTime advance_core(float p_physics_step, int p_physics_fps, float p_process_step); // calls advance_core, keeps track of deficit it adds to animaption_step, make sure the deficit sum stays close to zero - MainFrameTime advance_checked(float p_frame_slice, int p_iterations_per_second, float p_idle_step); + MainFrameTime advance_checked(float p_physics_step, int p_physics_fps, float p_process_step); // determine wall clock step since last iteration - float get_cpu_idle_step(); + float get_cpu_process_step(); public: MainTimerSync(); @@ -96,7 +96,7 @@ public: void set_fixed_fps(int p_fixed_fps); // advance one frame, return timesteps to take - MainFrameTime advance(float p_frame_slice, int p_iterations_per_second); + MainFrameTime advance(float p_physics_step, int p_physics_fps); }; #endif // MAIN_TIMER_SYNC_H diff --git a/main/performance.cpp b/main/performance.cpp index 7234511aeb..1a422dc499 100644 --- a/main/performance.cpp +++ b/main/performance.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -30,7 +30,7 @@ #include "performance.h" -#include "core/message_queue.h" +#include "core/object/message_queue.h" #include "core/os/os.h" #include "scene/main/node.h" #include "scene/main/scene_tree.h" @@ -93,7 +93,6 @@ float Performance::_get_node_count() const { String Performance::get_monitor_name(Monitor p_monitor) const { ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, String()); static const char *names[MONITOR_MAX] = { - "time/fps", "time/process", "time/physics_process", @@ -195,7 +194,6 @@ Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, MONITOR_TYPE_QUANTITY); // ugly static const MonitorType types[MONITOR_MAX] = { - MONITOR_TYPE_QUANTITY, MONITOR_TYPE_TIME, MONITOR_TYPE_TIME, diff --git a/main/performance.h b/main/performance.h index f406433cf2..122e5a4f9a 100644 --- a/main/performance.h +++ b/main/performance.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -31,8 +31,8 @@ #ifndef PERFORMANCE_H #define PERFORMANCE_H -#include "core/class_db.h" -#include "core/ordered_hash_map.h" +#include "core/object/class_db.h" +#include "core/templates/ordered_hash_map.h" #define PERF_WARN_OFFLINE_FUNCTION #define PERF_WARN_PROCESS_SYNC @@ -63,7 +63,6 @@ class Performance : public Object { public: enum Monitor { - TIME_FPS, TIME_PROCESS, TIME_PHYSICS_PROCESS, |