Skip to content

Commit

Permalink
Add custom iterator for Godex.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Oct 12, 2024
1 parent 2a9cd7e commit a9dff78
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
5 changes: 5 additions & 0 deletions core/config/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
8 changes: 8 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions main/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit a9dff78

Please sign in to comment.