From b1b7826ea7e04a3eb4d9b3d011e9a2a8dff5db03 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 26 May 2015 01:30:36 -0300 Subject: [PATCH] oops, previous commit was not working it is working now --- demos/2d/platformer/engine.cfg | 1 - servers/physics_2d/physics_2d_server_wrap_mt.cpp | 10 +++++++++- servers/physics_2d/physics_2d_server_wrap_mt.h | 8 +++++--- servers/physics_2d_server.cpp | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/demos/2d/platformer/engine.cfg b/demos/2d/platformer/engine.cfg index 5461cbddcbc..50b6b862e97 100644 --- a/demos/2d/platformer/engine.cfg +++ b/demos/2d/platformer/engine.cfg @@ -28,7 +28,6 @@ spawn=[key(F1), jbutton(0, 11)] [physics_2d] default_gravity=700 -thread_model=1 [rasterizer] diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.cpp b/servers/physics_2d/physics_2d_server_wrap_mt.cpp index 0ee78afbaa0..c5f023f162a 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.cpp +++ b/servers/physics_2d/physics_2d_server_wrap_mt.cpp @@ -61,7 +61,12 @@ void Physics2DServerWrapMT::step(float p_step) { void Physics2DServerWrapMT::sync() { - step_sem->wait(); + if (step_sem) { + if (first_frame) + first_frame=false; + else + step_sem->wait(); //must not wait if a step was not issued + } physics_2d_server->sync();; } @@ -147,6 +152,9 @@ Physics2DServerWrapMT::Physics2DServerWrapMT(Physics2DServer* p_contained,bool p } else { server_thread=0; } + + main_thread = Thread::get_caller_ID(); + first_frame=true; } diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h index 4c18464e396..48382498efd 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.h +++ b/servers/physics_2d/physics_2d_server_wrap_mt.h @@ -24,6 +24,7 @@ class Physics2DServerWrapMT : public Physics2DServer { void thread_loop(); Thread::ID server_thread; + Thread::ID main_thread; volatile bool exit; Thread *thread; volatile bool step_thread_up; @@ -37,6 +38,7 @@ class Physics2DServerWrapMT : public Physics2DServer { void thread_exit(); Mutex*alloc_mutex; + bool first_frame; int shape_pool_max_size; List shape_id_pool; @@ -72,7 +74,7 @@ public: //these work well, but should be used from the main thread only bool shape_collide(RID p_shape_A, const Matrix32& p_xform_A,const Vector2& p_motion_A,RID p_shape_B, const Matrix32& p_xform_B, const Vector2& p_motion_B,Vector2 *r_results,int p_result_max,int &r_result_count) { - ERR_FAIL_COND_V(server_thread!=Thread::get_caller_ID(),false); + ERR_FAIL_COND_V(main_thread!=Thread::get_caller_ID(),false); return physics_2d_server->shape_collide(p_shape_A,p_xform_A,p_motion_A,p_shape_B,p_xform_B,p_motion_B,r_results,p_result_max,r_result_count); } @@ -88,7 +90,7 @@ public: // this function only works on fixed process, errors and returns null otherwise Physics2DDirectSpaceState* space_get_direct_state(RID p_space) { - ERR_FAIL_COND_V(server_thread!=Thread::get_caller_ID(),NULL); + ERR_FAIL_COND_V(main_thread!=Thread::get_caller_ID(),NULL); return physics_2d_server->space_get_direct_state(p_space); } @@ -221,7 +223,7 @@ public: bool body_test_motion(RID p_body,const Vector2& p_motion,float p_margin=0.001,MotionResult *r_result=NULL) { - ERR_FAIL_COND_V(server_thread!=Thread::get_caller_ID(),false); + ERR_FAIL_COND_V(main_thread!=Thread::get_caller_ID(),false); return body_test_motion(p_body,p_motion,p_margin,r_result); } diff --git a/servers/physics_2d_server.cpp b/servers/physics_2d_server.cpp index 279ad0d7421..c2ad7b2165b 100644 --- a/servers/physics_2d_server.cpp +++ b/servers/physics_2d_server.cpp @@ -713,7 +713,7 @@ void Physics2DServer::_bind_methods() { Physics2DServer::Physics2DServer() { - ERR_FAIL_COND( singleton!=NULL ); + //ERR_FAIL_COND( singleton!=NULL ); singleton=this; }