summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/main.cpp59
-rw-r--r--main/main.h1
-rw-r--r--main/main_timer_sync.cpp16
-rw-r--r--main/main_timer_sync.h6
4 files changed, 51 insertions, 31 deletions
diff --git a/main/main.cpp b/main/main.cpp
index d91cc5c9bf..9076d110bd 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -571,8 +571,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
List<String>::Element *I = args.front();
- I = args.front();
-
while (I) {
I->get() = unescape_cmdline(I->get().strip_edges());
I = I->next();
@@ -1340,9 +1338,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
{
window_vsync_mode = DisplayServer::VSyncMode(int(GLOBAL_DEF("display/window/vsync/vsync_mode", DisplayServer::VSyncMode::VSYNC_ENABLED)));
}
- Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF_BASIC("physics/common/physics_fps", 60));
- ProjectSettings::get_singleton()->set_custom_property_info("physics/common/physics_fps",
- PropertyInfo(Variant::INT, "physics/common/physics_fps",
+ Engine::get_singleton()->set_physics_ticks_per_second(GLOBAL_DEF_BASIC("physics/common/physics_ticks_per_second", 60));
+ ProjectSettings::get_singleton()->set_custom_property_info("physics/common/physics_ticks_per_second",
+ PropertyInfo(Variant::INT, "physics/common/physics_ticks_per_second",
PROPERTY_HINT_RANGE, "1,1000,1"));
Engine::get_singleton()->set_physics_jitter_fix(GLOBAL_DEF("physics/common/physics_jitter_fix", 0.5));
Engine::get_singleton()->set_target_fps(GLOBAL_DEF("debug/settings/fps/force_fps", 0));
@@ -1352,6 +1350,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
PROPERTY_HINT_RANGE, "0,1000,1"));
GLOBAL_DEF("debug/settings/stdout/print_fps", false);
+ GLOBAL_DEF("debug/settings/stdout/print_gpu_profile", false);
GLOBAL_DEF("debug/settings/stdout/verbose_stdout", false);
if (!OS::get_singleton()->_verbose_stdout) { // Not manually overridden.
@@ -1591,7 +1590,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
rendering_server->init();
rendering_server->set_render_loop_enabled(!disable_render_loop);
- if (profile_gpu) {
+ if (profile_gpu || (!editor && bool(GLOBAL_GET("debug/settings/stdout/print_gpu_profile")))) {
rendering_server->set_print_gpu_profile(true);
}
@@ -1734,6 +1733,8 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
Input *id = Input::get_singleton();
if (id) {
+ agile_input_event_flushing = GLOBAL_DEF("input_devices/buffering/agile_event_flushing", false);
+
if (bool(GLOBAL_DEF("input_devices/pointing/emulate_touch_from_mouse", false)) &&
!(editor || project_manager)) {
bool found_touchscreen = false;
@@ -1966,7 +1967,7 @@ bool Main::start() {
for (int i = 0; i < _doc_data_class_path_count; i++) {
// Custom modules are always located by absolute path.
String path = _doc_data_class_paths[i].path;
- if (path.is_rel_path()) {
+ if (path.is_relative_path()) {
path = doc_tool_path.plus_file(path);
}
String name = _doc_data_class_paths[i].name;
@@ -2124,11 +2125,11 @@ bool Main::start() {
if (!project_manager && !editor) { // game
if (game_path != "" || script != "") {
//autoload
- Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
+ OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
//first pass, add the constants so they exist before any script is loaded
- for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
- const ProjectSettings::AutoloadInfo &info = E->get();
+ for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
+ const ProjectSettings::AutoloadInfo &info = E.get();
if (info.is_singleton) {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
@@ -2139,8 +2140,8 @@ bool Main::start() {
//second pass, load into global constants
List<Node *> to_add;
- for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
- const ProjectSettings::AutoloadInfo &info = E->get();
+ for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
+ const ProjectSettings::AutoloadInfo &info = E.get();
RES res = ResourceLoader::load(info.path);
ERR_CONTINUE_MSG(res.is_null(), "Can't autoload: " + info.path);
@@ -2200,7 +2201,7 @@ bool Main::start() {
//standard helpers that can be changed from main config
String stretch_mode = GLOBAL_DEF_BASIC("display/window/stretch/mode", "disabled");
- String stretch_aspect = GLOBAL_DEF_BASIC("display/window/stretch/aspect", "ignore");
+ String stretch_aspect = GLOBAL_DEF_BASIC("display/window/stretch/aspect", "keep");
Size2i stretch_size = Size2i(GLOBAL_DEF_BASIC("display/window/size/width", 0),
GLOBAL_DEF_BASIC("display/window/size/height", 0));
@@ -2239,6 +2240,10 @@ bool Main::start() {
DisplayServer::get_singleton()->window_set_title(appname);
#endif
+ // Define a very small minimum window size to prevent bugs such as GH-37242.
+ // It can still be overridden by the user in a script.
+ DisplayServer::get_singleton()->window_set_min_size(Size2i(64, 64));
+
bool snap_controls = GLOBAL_DEF("gui/common/snap_controls_to_pixels", true);
sml->get_root()->set_snap_controls_to_pixels(snap_controls);
@@ -2259,7 +2264,7 @@ bool Main::start() {
"display/window/stretch/mode",
PROPERTY_HINT_ENUM,
"disabled,canvas_items,viewport"));
- GLOBAL_DEF_BASIC("display/window/stretch/aspect", "ignore");
+ GLOBAL_DEF_BASIC("display/window/stretch/aspect", "keep");
ProjectSettings::get_singleton()->set_custom_property_info("display/window/stretch/aspect",
PropertyInfo(Variant::STRING,
"display/window/stretch/aspect",
@@ -2441,6 +2446,7 @@ uint32_t Main::frames = 0;
uint32_t Main::frame = 0;
bool Main::force_redraw_requested = false;
int Main::iterating = 0;
+bool Main::agile_input_event_flushing = false;
bool Main::is_iterating() {
return iterating > 0;
@@ -2463,12 +2469,12 @@ bool Main::iteration() {
uint64_t ticks_elapsed = ticks - last_ticks;
- int physics_fps = Engine::get_singleton()->get_iterations_per_second();
- float physics_step = 1.0 / physics_fps;
+ int physics_ticks_per_second = Engine::get_singleton()->get_physics_ticks_per_second();
+ float physics_step = 1.0 / physics_ticks_per_second;
float time_scale = Engine::get_singleton()->get_time_scale();
- MainFrameTime advance = main_timer_sync.advance(physics_step, physics_fps);
+ MainFrameTime advance = main_timer_sync.advance(physics_step, physics_ticks_per_second);
double process_step = advance.process_step;
double scaled_step = process_step * time_scale;
@@ -2490,9 +2496,13 @@ bool Main::iteration() {
bool exit = false;
- Engine::get_singleton()->_in_physics = true;
-
for (int iters = 0; iters < advance.physics_steps; ++iters) {
+ if (Input::get_singleton()->is_using_input_buffering() && agile_input_event_flushing) {
+ Input::get_singleton()->flush_buffered_events();
+ }
+
+ Engine::get_singleton()->_in_physics = true;
+
uint64_t physics_begin = OS::get_singleton()->get_ticks_usec();
PhysicsServer3D::get_singleton()->sync();
@@ -2521,9 +2531,13 @@ bool Main::iteration() {
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;
}
- Engine::get_singleton()->_in_physics = false;
+ if (Input::get_singleton()->is_using_input_buffering() && agile_input_event_flushing) {
+ Input::get_singleton()->flush_buffered_events();
+ }
uint64_t process_begin = OS::get_singleton()->get_ticks_usec();
@@ -2586,6 +2600,11 @@ bool Main::iteration() {
iterating--;
+ // Needed for OSs using input buffering regardless accumulation (like Android)
+ if (Input::get_singleton()->is_using_input_buffering() && !agile_input_event_flushing) {
+ Input::get_singleton()->flush_buffered_events();
+ }
+
if (fixed_fps != -1) {
return exit;
}
diff --git a/main/main.h b/main/main.h
index 84077137ba..4911ff42b4 100644
--- a/main/main.h
+++ b/main/main.h
@@ -42,6 +42,7 @@ class Main {
static uint32_t frame;
static bool force_redraw_requested;
static int iterating;
+ static bool agile_input_event_flushing;
public:
static bool is_project_manager();
diff --git a/main/main_timer_sync.cpp b/main/main_timer_sync.cpp
index 94e62bea97..0d172be65e 100644
--- a/main/main_timer_sync.cpp
+++ b/main/main_timer_sync.cpp
@@ -73,14 +73,14 @@ int MainTimerSync::get_average_physics_steps(double &p_min, double &p_max) {
}
// advance physics clock by p_process_step, return appropriate number of steps to simulate
-MainFrameTime MainTimerSync::advance_core(double p_physics_step, int p_physics_fps, double p_process_step) {
+MainFrameTime MainTimerSync::advance_core(double p_physics_step, int p_physics_ticks_per_second, double p_process_step) {
MainFrameTime ret;
ret.process_step = p_process_step;
// simple determination of number of physics iteration
time_accum += ret.process_step;
- ret.physics_steps = floor(time_accum * p_physics_fps);
+ ret.physics_steps = floor(time_accum * p_physics_ticks_per_second);
int min_typical_steps = typical_physics_steps[0];
int max_typical_steps = min_typical_steps + 1;
@@ -107,7 +107,7 @@ MainFrameTime MainTimerSync::advance_core(double p_physics_step, int p_physics_f
// try to keep it consistent with previous iterations
if (ret.physics_steps < min_typical_steps) {
- const int max_possible_steps = floor((time_accum)*p_physics_fps + get_physics_jitter_fix());
+ const int max_possible_steps = floor((time_accum)*p_physics_ticks_per_second + 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(double p_physics_step, int p_physics_f
ret.physics_steps = min_typical_steps;
}
} else if (ret.physics_steps > max_typical_steps) {
- const int min_possible_steps = floor((time_accum)*p_physics_fps - get_physics_jitter_fix());
+ const int min_possible_steps = floor((time_accum)*p_physics_ticks_per_second - get_physics_jitter_fix());
if (min_possible_steps > max_typical_steps) {
ret.physics_steps = min_possible_steps;
update_typical = true;
@@ -146,7 +146,7 @@ MainFrameTime MainTimerSync::advance_core(double p_physics_step, int p_physics_f
}
// 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(double p_physics_step, int p_physics_fps, double p_process_step) {
+MainFrameTime MainTimerSync::advance_checked(double p_physics_step, int p_physics_ticks_per_second, double p_process_step) {
if (fixed_fps != -1) {
p_process_step = 1.0 / fixed_fps;
}
@@ -154,7 +154,7 @@ MainFrameTime MainTimerSync::advance_checked(double p_physics_step, int p_physic
// compensate for last deficit
p_process_step += time_deficit;
- MainFrameTime ret = advance_core(p_physics_step, p_physics_fps, p_process_step);
+ MainFrameTime ret = advance_core(p_physics_step, p_physics_ticks_per_second, p_process_step);
// 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
@@ -220,8 +220,8 @@ void MainTimerSync::set_fixed_fps(int p_fixed_fps) {
}
// advance one physics frame, return timesteps to take
-MainFrameTime MainTimerSync::advance(double p_physics_step, int p_physics_fps) {
+MainFrameTime MainTimerSync::advance(double p_physics_step, int p_physics_ticks_per_second) {
double cpu_process_step = get_cpu_process_step();
- return advance_checked(p_physics_step, p_physics_fps, cpu_process_step);
+ return advance_checked(p_physics_step, p_physics_ticks_per_second, cpu_process_step);
}
diff --git a/main/main_timer_sync.h b/main/main_timer_sync.h
index abdec18f6d..d0ebcb8f96 100644
--- a/main/main_timer_sync.h
+++ b/main/main_timer_sync.h
@@ -77,10 +77,10 @@ protected:
int get_average_physics_steps(double &p_min, double &p_max);
// advance physics clock by p_process_step, return appropriate number of steps to simulate
- MainFrameTime advance_core(double p_physics_step, int p_physics_fps, double p_process_step);
+ MainFrameTime advance_core(double p_physics_step, int p_physics_ticks_per_second, double 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(double p_physics_step, int p_physics_fps, double p_process_step);
+ MainFrameTime advance_checked(double p_physics_step, int p_physics_ticks_per_second, double p_process_step);
// determine wall clock step since last iteration
double get_cpu_process_step();
@@ -96,7 +96,7 @@ public:
void set_fixed_fps(int p_fixed_fps);
// advance one frame, return timesteps to take
- MainFrameTime advance(double p_physics_step, int p_physics_fps);
+ MainFrameTime advance(double p_physics_step, int p_physics_ticks_per_second);
};
#endif // MAIN_TIMER_SYNC_H