Merge pull request #104862 from smix8/navserver_process

Prepare NavigationServer for `process()` and `physics_process()` split
This commit is contained in:
Thaddeus Crews 2025-04-02 07:37:32 -05:00
commit c9c8556a47
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
15 changed files with 131 additions and 103 deletions

View file

@ -1306,8 +1306,6 @@ void GodotNavigationServer3D::set_active(bool p_active) {
}
void GodotNavigationServer3D::flush_queries() {
// In c++ we can't be sure that this is performed in the main thread
// even with mutable functions.
MutexLock lock(commands_mutex);
MutexLock lock2(operations_mutex);
@ -1340,7 +1338,21 @@ void GodotNavigationServer3D::sync() {
}
}
void GodotNavigationServer3D::process(real_t p_delta_time) {
void GodotNavigationServer3D::process(double p_delta_time) {
// Called for each main loop iteration AFTER node and user script process() and BEFORE RenderingServer sync.
// Will run reliably every rendered frame independent of the physics tick rate.
// Use for things that (only) need to update once per main loop iteration and rendered frame or is visible to the user.
// E.g. (final) sync of objects for this main loop iteration, updating rendered debug visuals, updating debug statistics, ...
}
void GodotNavigationServer3D::physics_process(double p_delta_time) {
// Called for each physics process step AFTER node and user script physics_process() and BEFORE PhysicsServer sync.
// Will NOT run reliably every rendered frame. If there is no physics step this function will not run.
// Use for physics or step depending calculations and updates where the result affects the next step calculation.
// E.g. anything physics sync related, avoidance simulations, physics space state queries, ...
// If physics process needs to play catchup this function will be called multiple times per frame so it should not hold
// costly updates that are not important outside the stepped calculations to avoid causing a physics performance death spiral.
flush_queries();
if (!active) {

View file

@ -280,7 +280,9 @@ public:
virtual void set_active(bool p_active) override;
void flush_queries();
virtual void process(real_t p_delta_time) override;
virtual void process(double p_delta_time) override;
virtual void physics_process(double p_delta_time) override;
virtual void init() override;
virtual void sync() override;
virtual void finish() override;

View file

@ -614,11 +614,9 @@ void NavMap3D::compute_single_avoidance_step_3d(uint32_t index, NavAgent3D **age
(*(agent + index))->update();
}
void NavMap3D::step(real_t p_deltatime) {
deltatime = p_deltatime;
rvo_simulation_2d.setTimeStep(float(deltatime));
rvo_simulation_3d.setTimeStep(float(deltatime));
void NavMap3D::step(double p_delta_time) {
rvo_simulation_2d.setTimeStep(float(p_delta_time));
rvo_simulation_3d.setTimeStep(float(p_delta_time));
if (active_2d_avoidance_agents.size() > 0) {
if (use_threads && avoidance_use_multiple_threads) {

View file

@ -99,9 +99,6 @@ class NavMap3D : public NavRid3D {
/// Are rvo obstacles modified?
bool obstacles_dirty = true;
/// Physics delta time
real_t deltatime = 0.0;
/// Change the id each time the map is updated.
uint32_t iteration_id = 0;
@ -221,7 +218,7 @@ public:
Vector3 get_random_point(uint32_t p_navigation_layers, bool p_uniformly) const;
void sync();
void step(real_t p_deltatime);
void step(double p_delta_time);
void dispatch_callbacks();
// Performance Monitor