Make physics interpolation compatible with separate-thread rendering

This commit is contained in:
Pedro J. Estébanez
2025-12-15 21:36:52 +01:00
parent 42b054a401
commit 49700eb84b
6 changed files with 43 additions and 2 deletions

View File

@@ -133,9 +133,16 @@ void VisualServerRaster::draw(bool p_swap_buffers, double frame_step) {
}
VS::get_singleton()->emit_signal("frame_post_draw");
}
void VisualServerRaster::sync() {
}
void VisualServerRaster::sync_and_halt() {
}
void VisualServerRaster::thaw() {
}
void VisualServerRaster::set_physics_interpolation_enabled(bool p_enabled) {
VSG::scene->set_physics_interpolation_enabled(p_enabled);
VSG::canvas->set_physics_interpolation_enabled(p_enabled);

View File

@@ -803,6 +803,8 @@ public:
virtual void pre_draw(bool p_will_draw);
virtual void draw(bool p_swap_buffers, double frame_step);
virtual void sync();
virtual void sync_and_halt();
virtual void thaw();
virtual bool has_changed(ChangedPriority p_priority = CHANGED_PRIORITY_ANY) const;
virtual void init();
virtual void finish();

View File

@@ -43,6 +43,10 @@ void VisualServerWrapMT::thread_draw(bool p_swap_buffers, double frame_step) {
void VisualServerWrapMT::thread_flush() {
}
void VisualServerWrapMT::thread_halt() {
thread_halt_semaphore.wait();
}
void VisualServerWrapMT::_thread_callback(void *_instance) {
VisualServerWrapMT *vsmt = reinterpret_cast<VisualServerWrapMT *>(_instance);
@@ -102,6 +106,19 @@ void VisualServerWrapMT::sync() {
}
}
void VisualServerWrapMT::sync_and_halt() {
if (create_thread) {
command_queue.push_and_sync(this, &VisualServerWrapMT::thread_flush);
command_queue.push(this, &VisualServerWrapMT::thread_halt);
}
}
void VisualServerWrapMT::thaw() {
if (create_thread) {
thread_halt_semaphore.post();
}
}
void VisualServerWrapMT::draw(bool p_swap_buffers, double frame_step) {
if (create_thread) {
command_queue.push(this, &VisualServerWrapMT::thread_draw, p_swap_buffers, frame_step);

View File

@@ -54,6 +54,9 @@ class VisualServerWrapMT : public VisualServer {
void thread_draw(bool p_swap_buffers, double frame_step);
void thread_flush();
Semaphore thread_halt_semaphore;
void thread_halt();
void thread_exit();
Mutex alloc_mutex;
@@ -709,6 +712,8 @@ public:
virtual void pre_draw(bool p_will_draw);
virtual void draw(bool p_swap_buffers, double frame_step);
virtual void sync();
virtual void sync_and_halt();
virtual void thaw();
FUNC1RC(bool, has_changed, ChangedPriority)
virtual void set_physics_interpolation_enabled(bool p_enabled);