summaryrefslogtreecommitdiff
path: root/servers/physics
diff options
context:
space:
mode:
Diffstat (limited to 'servers/physics')
-rw-r--r--servers/physics/area_pair_sw.cpp10
-rw-r--r--servers/physics/body_pair_sw.cpp2
-rw-r--r--servers/physics/collision_object_sw.cpp1
-rw-r--r--servers/physics/collision_object_sw.h8
-rw-r--r--servers/physics/joints/hinge_joint_sw.cpp1
-rw-r--r--servers/physics/physics_server_sw.cpp77
-rw-r--r--servers/physics/physics_server_sw.h6
-rw-r--r--servers/physics/space_sw.cpp4
-rw-r--r--servers/physics/space_sw.h16
-rw-r--r--servers/physics/step_sw.cpp38
10 files changed, 160 insertions, 3 deletions
diff --git a/servers/physics/area_pair_sw.cpp b/servers/physics/area_pair_sw.cpp
index c6bf6114a0..24f3b75ca5 100644
--- a/servers/physics/area_pair_sw.cpp
+++ b/servers/physics/area_pair_sw.cpp
@@ -32,6 +32,11 @@
bool AreaPairSW::setup(float p_step) {
+ if (!area->test_collision_mask(body)) {
+ colliding = false;
+ return false;
+ }
+
bool result = CollisionSolverSW::solve_static(body->get_shape(body_shape),body->get_transform() * body->get_shape_transform(body_shape),area->get_shape(area_shape),area->get_transform() * area->get_shape_transform(area_shape),NULL,this);
if (result!=colliding) {
@@ -100,6 +105,11 @@ AreaPairSW::~AreaPairSW() {
bool Area2PairSW::setup(float p_step) {
+ if (!area_a->test_collision_mask(area_b)) {
+ colliding = false;
+ return false;
+ }
+
// bool result = area_a->test_collision_mask(area_b) && CollisionSolverSW::solve(area_a->get_shape(shape_a),area_a->get_transform() * area_a->get_shape_transform(shape_a),Vector2(),area_b->get_shape(shape_b),area_b->get_transform() * area_b->get_shape_transform(shape_b),Vector2(),NULL,this);
bool result = CollisionSolverSW::solve_static(area_a->get_shape(shape_a),area_a->get_transform() * area_a->get_shape_transform(shape_a),area_b->get_shape(shape_b),area_b->get_transform() * area_b->get_shape_transform(shape_b),NULL,this);
diff --git a/servers/physics/body_pair_sw.cpp b/servers/physics/body_pair_sw.cpp
index a971cdaad8..40e906c36c 100644
--- a/servers/physics/body_pair_sw.cpp
+++ b/servers/physics/body_pair_sw.cpp
@@ -221,7 +221,7 @@ bool BodyPairSW::_test_ccd(float p_step,BodySW *p_A, int p_shape_A,const Transfo
bool BodyPairSW::setup(float p_step) {
//cannot collide
- if ((A->get_layer_mask()&B->get_layer_mask())==0 || A->has_exception(B->get_self()) || B->has_exception(A->get_self()) || (A->get_mode()<=PhysicsServer::BODY_MODE_KINEMATIC && B->get_mode()<=PhysicsServer::BODY_MODE_KINEMATIC && A->get_max_contacts_reported()==0 && B->get_max_contacts_reported()==0)) {
+ if (!A->test_collision_mask(B) || A->has_exception(B->get_self()) || B->has_exception(A->get_self()) || (A->get_mode()<=PhysicsServer::BODY_MODE_KINEMATIC && B->get_mode()<=PhysicsServer::BODY_MODE_KINEMATIC && A->get_max_contacts_reported()==0 && B->get_max_contacts_reported()==0)) {
collided=false;
return false;
}
diff --git a/servers/physics/collision_object_sw.cpp b/servers/physics/collision_object_sw.cpp
index 55c8c1b955..f2864ee95e 100644
--- a/servers/physics/collision_object_sw.cpp
+++ b/servers/physics/collision_object_sw.cpp
@@ -217,5 +217,6 @@ CollisionObjectSW::CollisionObjectSW(Type p_type) {
space=NULL;
instance_id=0;
layer_mask=1;
+ collision_mask=1;
ray_pickable=true;
}
diff --git a/servers/physics/collision_object_sw.h b/servers/physics/collision_object_sw.h
index 592c84e667..bc71c2709b 100644
--- a/servers/physics/collision_object_sw.h
+++ b/servers/physics/collision_object_sw.h
@@ -53,6 +53,7 @@ private:
RID self;
ObjectID instance_id;
uint32_t layer_mask;
+ uint32_t collision_mask;
struct Shape {
@@ -136,6 +137,13 @@ public:
_FORCE_INLINE_ void set_layer_mask(uint32_t p_mask) { layer_mask=p_mask; }
_FORCE_INLINE_ uint32_t get_layer_mask() const { return layer_mask; }
+ _FORCE_INLINE_ void set_collision_mask(uint32_t p_mask) { collision_mask=p_mask; }
+ _FORCE_INLINE_ uint32_t get_collision_mask() const { return collision_mask; }
+
+ _FORCE_INLINE_ bool test_collision_mask(CollisionObjectSW* p_other) const {
+ return layer_mask&p_other->collision_mask || p_other->layer_mask&collision_mask;
+ }
+
void remove_shape(ShapeSW *p_shape);
void remove_shape(int p_index);
diff --git a/servers/physics/joints/hinge_joint_sw.cpp b/servers/physics/joints/hinge_joint_sw.cpp
index feaf00290d..37b73f64c7 100644
--- a/servers/physics/joints/hinge_joint_sw.cpp
+++ b/servers/physics/joints/hinge_joint_sw.cpp
@@ -420,7 +420,6 @@ float HingeJointSW::get_param(PhysicsServer::HingeJointParam p_param) const{
void HingeJointSW::set_flag(PhysicsServer::HingeJointFlag p_flag, bool p_value){
- print_line(p_flag+": "+itos(p_value));
switch (p_flag) {
case PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT: m_useLimit=p_value; break;
case PhysicsServer::HINGE_JOINT_FLAG_ENABLE_MOTOR: m_enableAngularMotor=p_value; break;
diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp
index 5eb14d80dc..6c098a6df2 100644
--- a/servers/physics/physics_server_sw.cpp
+++ b/servers/physics/physics_server_sw.cpp
@@ -34,7 +34,8 @@
#include "joints/slider_joint_sw.h"
#include "joints/cone_twist_joint_sw.h"
#include "joints/generic_6dof_joint_sw.h"
-
+#include "script_language.h"
+#include "os/os.h"
RID PhysicsServerSW::shape_create(ShapeType p_shape) {
@@ -418,6 +419,22 @@ Transform PhysicsServerSW::area_get_transform(RID p_area) const {
return area->get_transform();
};
+void PhysicsServerSW::area_set_layer_mask(RID p_area,uint32_t p_mask) {
+
+ AreaSW *area = area_owner.get(p_area);
+ ERR_FAIL_COND(!area);
+
+ area->set_layer_mask(p_mask);
+}
+
+void PhysicsServerSW::area_set_collision_mask(RID p_area,uint32_t p_mask) {
+
+ AreaSW *area = area_owner.get(p_area);
+ ERR_FAIL_COND(!area);
+
+ area->set_collision_mask(p_mask);
+}
+
void PhysicsServerSW::area_set_monitorable(RID p_area,bool p_monitorable) {
AreaSW *area = area_owner.get(p_area);
@@ -657,6 +674,25 @@ uint32_t PhysicsServerSW::body_get_layer_mask(RID p_body, uint32_t p_mask) const
}
+void PhysicsServerSW::body_set_collision_mask(RID p_body, uint32_t p_mask) {
+
+ BodySW *body = body_owner.get(p_body);
+ ERR_FAIL_COND(!body);
+
+ body->set_collision_mask(p_mask);
+ body->wakeup();
+
+}
+
+uint32_t PhysicsServerSW::body_get_collision_mask(RID p_body, uint32_t p_mask) const{
+
+ const BodySW *body = body_owner.get(p_body);
+ ERR_FAIL_COND_V(!body,0);
+
+ return body->get_collision_mask();
+
+}
+
void PhysicsServerSW::body_attach_object_instance_ID(RID p_body,uint32_t p_ID) {
@@ -1474,12 +1510,51 @@ void PhysicsServerSW::flush_queries() {
return;
doing_sync=true;
+
+ uint64_t time_beg = OS::get_singleton()->get_ticks_usec();
+
for( Set<const SpaceSW*>::Element *E=active_spaces.front();E;E=E->next()) {
SpaceSW *space=(SpaceSW *)E->get();
space->call_queries();
}
+
+ if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) {
+
+ uint64_t total_time[SpaceSW::ELAPSED_TIME_MAX];
+ static const char* time_name[SpaceSW::ELAPSED_TIME_MAX]={
+ "integrate_forces",
+ "generate_islands",
+ "setup_constraints",
+ "solve_constraints",
+ "integrate_velocities"
+ };
+
+ for(int i=0;i<SpaceSW::ELAPSED_TIME_MAX;i++) {
+ total_time[i]=0;
+ }
+
+ for( Set<const SpaceSW*>::Element *E=active_spaces.front();E;E=E->next()) {
+
+ for(int i=0;i<SpaceSW::ELAPSED_TIME_MAX;i++) {
+ total_time[i]+=E->get()->get_elapsed_time(SpaceSW::ElapsedTime(i));
+ }
+
+ }
+
+ Array values;
+ values.resize(SpaceSW::ELAPSED_TIME_MAX*2);
+ for(int i=0;i<SpaceSW::ELAPSED_TIME_MAX;i++) {
+ values[i*2+0]=time_name[i];
+ values[i*2+1]=USEC_TO_SEC(total_time[i]);
+ }
+ values.push_back("flush_queries");
+ values.push_back(USEC_TO_SEC(OS::get_singleton()->get_ticks_usec()-time_beg));
+
+ ScriptDebugger::get_singleton()->add_profiling_frame_data("physics",values);
+
+ }
};
diff --git a/servers/physics/physics_server_sw.h b/servers/physics/physics_server_sw.h
index 2aadac2216..59eeeb42a7 100644
--- a/servers/physics/physics_server_sw.h
+++ b/servers/physics/physics_server_sw.h
@@ -131,6 +131,9 @@ public:
virtual void area_set_ray_pickable(RID p_area,bool p_enable);
virtual bool area_is_ray_pickable(RID p_area) const;
+ virtual void area_set_collision_mask(RID p_area,uint32_t p_mask);
+ virtual void area_set_layer_mask(RID p_area,uint32_t p_mask);
+
virtual void area_set_monitorable(RID p_area,bool p_monitorable);
virtual void area_set_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method);
@@ -171,6 +174,9 @@ public:
virtual void body_set_layer_mask(RID p_body, uint32_t p_mask);
virtual uint32_t body_get_layer_mask(RID p_body, uint32_t p_mask) const;
+ virtual void body_set_collision_mask(RID p_body, uint32_t p_mask);
+ virtual uint32_t body_get_collision_mask(RID p_body, uint32_t p_mask) const;
+
virtual void body_set_user_flags(RID p_body, uint32_t p_flags);
virtual uint32_t body_get_user_flags(RID p_body, uint32_t p_flags) const;
diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp
index 4cf7729b09..1e6f42aa02 100644
--- a/servers/physics/space_sw.cpp
+++ b/servers/physics/space_sw.cpp
@@ -736,6 +736,10 @@ SpaceSW::SpaceSW() {
direct_access = memnew( PhysicsDirectSpaceStateSW );
direct_access->space=this;
+
+ for(int i=0;i<ELAPSED_TIME_MAX;i++)
+ elapsed_time[i]=0;
+
}
SpaceSW::~SpaceSW() {
diff --git a/servers/physics/space_sw.h b/servers/physics/space_sw.h
index 6300c206d8..3fdef7e62b 100644
--- a/servers/physics/space_sw.h
+++ b/servers/physics/space_sw.h
@@ -59,6 +59,20 @@ public:
class SpaceSW {
+public:
+
+ enum ElapsedTime {
+ ELAPSED_TIME_INTEGRATE_FORCES,
+ ELAPSED_TIME_GENERATE_ISLANDS,
+ ELAPSED_TIME_SETUP_CONSTRAINTS,
+ ELAPSED_TIME_SOLVE_CONSTRAINTS,
+ ELAPSED_TIME_INTEGRATE_VELOCITIES,
+ ELAPSED_TIME_MAX
+
+ };
+private:
+
+ uint64_t elapsed_time[ELAPSED_TIME_MAX];
PhysicsDirectSpaceStateSW *direct_access;
RID self;
@@ -178,6 +192,8 @@ public:
void set_static_global_body(RID p_body) { static_global_body=p_body; }
RID get_static_global_body() { return static_global_body; }
+ void set_elapsed_time(ElapsedTime p_time,uint64_t p_msec) { elapsed_time[p_time]=p_msec; }
+ uint64_t get_elapsed_time(ElapsedTime p_time) const { return elapsed_time[p_time]; }
SpaceSW();
~SpaceSW();
diff --git a/servers/physics/step_sw.cpp b/servers/physics/step_sw.cpp
index f10dadf81a..5b7ebce817 100644
--- a/servers/physics/step_sw.cpp
+++ b/servers/physics/step_sw.cpp
@@ -29,6 +29,8 @@
#include "step_sw.h"
#include "joints_sw.h"
+#include "os/os.h"
+
void StepSW::_populate_island(BodySW* p_body,BodySW** p_island,ConstraintSW **p_constraint_island) {
p_body->set_island_step(_step);
@@ -152,6 +154,10 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) {
const SelfList<BodySW>::List * body_list = &p_space->get_active_body_list();
/* INTEGRATE FORCES */
+
+ uint64_t profile_begtime = OS::get_singleton()->get_ticks_usec();
+ uint64_t profile_endtime=0;
+
int active_count=0;
const SelfList<BodySW>*b = body_list->first();
@@ -165,6 +171,12 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) {
p_space->set_active_objects(active_count);
+ { //profile
+ profile_endtime=OS::get_singleton()->get_ticks_usec();
+ p_space->set_elapsed_time(SpaceSW::ELAPSED_TIME_INTEGRATE_FORCES,profile_endtime-profile_begtime);
+ profile_begtime=profile_endtime;
+ }
+
/* GENERATE CONSTRAINT ISLANDS */
BodySW *island_list=NULL;
@@ -214,6 +226,13 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) {
p_space->area_remove_from_moved_list((SelfList<AreaSW>*)aml.first()); //faster to remove here
}
+ { //profile
+ profile_endtime=OS::get_singleton()->get_ticks_usec();
+ p_space->set_elapsed_time(SpaceSW::ELAPSED_TIME_GENERATE_ISLANDS,profile_endtime-profile_begtime);
+ profile_begtime=profile_endtime;
+ }
+
+
// print_line("island count: "+itos(island_count)+" active count: "+itos(active_count));
/* SETUP CONSTRAINT ISLANDS */
@@ -226,6 +245,12 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) {
}
}
+ { //profile
+ profile_endtime=OS::get_singleton()->get_ticks_usec();
+ p_space->set_elapsed_time(SpaceSW::ELAPSED_TIME_SETUP_CONSTRAINTS,profile_endtime-profile_begtime);
+ profile_begtime=profile_endtime;
+ }
+
/* SOLVE CONSTRAINT ISLANDS */
{
@@ -237,6 +262,13 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) {
}
}
+
+ { //profile
+ profile_endtime=OS::get_singleton()->get_ticks_usec();
+ p_space->set_elapsed_time(SpaceSW::ELAPSED_TIME_SOLVE_CONSTRAINTS,profile_endtime-profile_begtime);
+ profile_begtime=profile_endtime;
+ }
+
/* INTEGRATE VELOCITIES */
b = body_list->first();
@@ -257,6 +289,12 @@ void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) {
}
}
+ { //profile
+ profile_endtime=OS::get_singleton()->get_ticks_usec();
+ p_space->set_elapsed_time(SpaceSW::ELAPSED_TIME_INTEGRATE_VELOCITIES,profile_endtime-profile_begtime);
+ profile_begtime=profile_endtime;
+ }
+
p_space->update();
p_space->unlock();
_step++;