Prepare NavigationServer for process() and physics_process() split

Prepares the NavigationServer API for a split of its functionality between frame process() and stepped physics_process().
This commit is contained in:
smix8
2025-03-31 22:32:59 +02:00
parent c7ea8614d7
commit 16fd7b6ae1
15 changed files with 131 additions and 103 deletions

View File

@@ -1138,8 +1138,6 @@ Vector<Vector2> GodotNavigationServer2D::obstacle_get_vertices(RID p_obstacle) c
}
void GodotNavigationServer2D::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);
@@ -1259,7 +1257,21 @@ void GodotNavigationServer2D::internal_free_obstacle(RID p_object) {
}
}
void GodotNavigationServer2D::process(real_t p_delta_time) {
void GodotNavigationServer2D::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 GodotNavigationServer2D::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

@@ -320,7 +320,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

@@ -532,10 +532,8 @@ void NavMap2D::compute_single_avoidance_step(uint32_t p_index, NavAgent2D **p_ag
(*(p_agent + p_index))->update();
}
void NavMap2D::step(real_t p_deltatime) {
deltatime = p_deltatime;
rvo_simulation.setTimeStep(float(deltatime));
void NavMap2D::step(double p_delta_time) {
rvo_simulation.setTimeStep(float(p_delta_time));
if (active_avoidance_agents.size() > 0) {
if (use_threads && avoidance_use_multiple_threads) {

View File

@@ -91,9 +91,6 @@ class NavMap2D : public NavRid2D {
/// 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;
@@ -203,7 +200,7 @@ public:
Vector2 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