From a9dff78445dd77bcc63a92a4e4dbfc8e020dade9 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Sat, 12 Oct 2024 03:13:33 -0700 Subject: [PATCH] Add custom iterator for Godex. --- SConstruct | 9 +++++++++ core/config/engine.h | 5 +++++ main/main.cpp | 8 ++++++++ main/main.h | 3 +++ 4 files changed, 25 insertions(+) diff --git a/SConstruct b/SConstruct index 63cff4fe1672..5864da1413a5 100644 --- a/SConstruct +++ b/SConstruct @@ -970,6 +970,15 @@ for name, path in modules_detected.items(): env.module_icons_paths.append(path + "/" + "icons") modules_enabled[name] = path + if getattr(config, "has_custom_iterator", False) and config.has_custom_iterator(): + env.AppendUnique(CPPDEFINES=["CUSTOM_ITERATOR"]) + + if getattr(config, "has_custom_physics_iterator", False) and config.has_custom_physics_iterator(): + env.AppendUnique(CPPDEFINES=["CUSTOM_PHYSICS_ITERATOR"]) + + if getattr(config, "has_custom_audio_iterator", False) and config.has_custom_audio_iterator(): + env.AppendUnique(CPPDEFINES=["CUSTOM_AUDIO_ITERATOR"]) + sys.path.remove(path) sys.modules.pop("config") diff --git a/core/config/engine.h b/core/config/engine.h index a0b1ffa98123..b956bb0e51d4 100644 --- a/core/config/engine.h +++ b/core/config/engine.h @@ -118,7 +118,12 @@ class Engine { uint64_t get_frames_drawn(); + void set_physics_frames(uint32_t p_physics_frames) { _physics_frames = p_physics_frames; } + uint64_t get_physics_frames() const { return _physics_frames; } + + void set_in_physics_frame(bool p_in_physics) { _in_physics = p_in_physics; } + uint64_t get_process_frames() const { return _process_frames; } bool is_in_physics_frame() const { return _in_physics; } uint64_t get_frame_ticks() const { return _frame_ticks; } diff --git a/main/main.cpp b/main/main.cpp index 5206e9b84c57..b16f41c13ec3 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -4328,11 +4328,16 @@ bool Main::iteration() { NavigationServer2D::get_singleton()->sync(); NavigationServer3D::get_singleton()->sync(); +#ifdef CUSTOM_ITERATOR + exit = custom_iteration(process_step, physics_step, &advance, time_scale); +#endif + for (int iters = 0; iters < advance.physics_steps; ++iters) { if (Input::get_singleton()->is_agile_input_event_flushing()) { Input::get_singleton()->flush_buffered_events(); } +#ifndef CUSTOM_PHYSICS_ITERATOR Engine::get_singleton()->_in_physics = true; Engine::get_singleton()->_physics_frames++; @@ -4387,6 +4392,7 @@ bool Main::iteration() { physics_process_max = MAX(OS::get_singleton()->get_ticks_usec() - physics_begin, physics_process_max); Engine::get_singleton()->_in_physics = false; +#ifndef CUSTOM_PHYSICS_ITERATOR } if (Input::get_singleton()->is_agile_input_event_flushing()) { @@ -4424,7 +4430,9 @@ bool Main::iteration() { ScriptServer::get_language(i)->frame(); } +#ifndef CUSTOM_AUDIO_ITERATOR AudioServer::get_singleton()->update(); +#endif if (EngineDebugger::is_active()) { EngineDebugger::get_singleton()->iteration(frame_time, process_ticks, physics_process_ticks, physics_step); diff --git a/main/main.h b/main/main.h index 6dd2ff7d7a81..1a5d2bc05c7c 100644 --- a/main/main.h +++ b/main/main.h @@ -80,6 +80,9 @@ class Main { #endif static int start(); +#ifdef CUSTOM_ITERATOR + static bool custom_iteration(float p_process_delta, float p_physics_delta, struct MainFrameTime *p_frame_time, float p_time_scale); +#endif static bool iteration(); static void force_redraw();