瀏覽代碼

oops, previous commit was not working

it is working now
Juan Linietsky 10 年之前
父節點
當前提交
b1b7826ea7

+ 0 - 1
demos/2d/platformer/engine.cfg

@@ -28,7 +28,6 @@ spawn=[key(F1), jbutton(0, 11)]
 [physics_2d]
 
 default_gravity=700
-thread_model=1
 
 [rasterizer]
 

+ 9 - 1
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;
 }
 
 

+ 5 - 3
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<RID> 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);
 	}
 

+ 1 - 1
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;
 }