mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 07:17:42 -05:00
Pause physics command queue during physics processing
This commit is contained in:
@@ -42,10 +42,17 @@ void PhysicsServer2DWrapMT::_thread_exit() {
|
||||
void PhysicsServer2DWrapMT::_thread_loop() {
|
||||
while (!exit) {
|
||||
WorkerThreadPool::get_singleton()->yield();
|
||||
command_queue.flush_all();
|
||||
|
||||
if (!doing_sync.is_set()) {
|
||||
command_queue.flush_all();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsServer2DWrapMT::_thread_sync() {
|
||||
doing_sync.set();
|
||||
}
|
||||
|
||||
/* EVENT QUEUING */
|
||||
|
||||
void PhysicsServer2DWrapMT::step(real_t p_step) {
|
||||
@@ -58,7 +65,7 @@ void PhysicsServer2DWrapMT::step(real_t p_step) {
|
||||
|
||||
void PhysicsServer2DWrapMT::sync() {
|
||||
if (create_thread) {
|
||||
command_queue.sync();
|
||||
command_queue.push_and_sync(this, &PhysicsServer2DWrapMT::_thread_sync);
|
||||
} else {
|
||||
command_queue.flush_all(); // Flush all pending from other threads.
|
||||
}
|
||||
@@ -71,6 +78,10 @@ void PhysicsServer2DWrapMT::flush_queries() {
|
||||
|
||||
void PhysicsServer2DWrapMT::end_sync() {
|
||||
physics_server_2d->end_sync();
|
||||
|
||||
if (create_thread) {
|
||||
doing_sync.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsServer2DWrapMT::init() {
|
||||
|
||||
Reference in New Issue
Block a user