From 2c69f3d0d217a42489308f465712a656c4678307 Mon Sep 17 00:00:00 2001 From: AndreaCatania Date: Sun, 5 Nov 2017 18:50:39 +0100 Subject: Bullet - Added support to multiple spaces --- modules/bullet/bullet_physics_server.cpp | 39 +++++++++++++++++--------------- modules/bullet/bullet_physics_server.h | 3 ++- 2 files changed, 23 insertions(+), 19 deletions(-) (limited to 'modules/bullet') diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index 2656074296..96875924a5 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -81,7 +81,7 @@ void BulletPhysicsServer::_bind_methods() { BulletPhysicsServer::BulletPhysicsServer() : PhysicsServer(), active(true), - activeSpace(NULL) {} + active_spaces_count(0) {} BulletPhysicsServer::~BulletPhysicsServer() {} @@ -162,27 +162,28 @@ RID BulletPhysicsServer::space_create() { } void BulletPhysicsServer::space_set_active(RID p_space, bool p_active) { + + SpaceBullet *space = space_owner.get(p_space); + ERR_FAIL_COND(!space); + + if (space_is_active(p_space) == p_active) { + return; + } + if (p_active) { - if (activeSpace) { - // There is another space and this cannot be activated - ERR_PRINT("There is another space, before activate new one deactivate the current space."); - } else { - SpaceBullet *space = space_owner.get(p_space); - if (space) { - activeSpace = space; - } else { - ERR_PRINT("The passed RID is not a valid space. Please provide a RID with SpaceBullet type."); - } - } + ++active_spaces_count; + active_spaces.push_back(space); } else { - if (!space_is_active(p_space)) { - activeSpace = NULL; - } + --active_spaces_count; + active_spaces.erase(space); } } bool BulletPhysicsServer::space_is_active(RID p_space) const { - return NULL != activeSpace && activeSpace == p_space.get_data(); + SpaceBullet *space = space_owner.get(p_space); + ERR_FAIL_COND_V(!space, false); + + return -1 != active_spaces.find(space); } void BulletPhysicsServer::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) { @@ -1296,8 +1297,10 @@ void BulletPhysicsServer::step(float p_deltaTime) { return; BulletPhysicsDirectBodyState::singleton_setDeltaTime(p_deltaTime); - if (activeSpace) { - activeSpace->step(p_deltaTime); + + for (int i = 0; i < active_spaces_count; ++i) { + + active_spaces[i]->step(p_deltaTime); } } diff --git a/modules/bullet/bullet_physics_server.h b/modules/bullet/bullet_physics_server.h index e66e8a5ac1..04d9d89594 100644 --- a/modules/bullet/bullet_physics_server.h +++ b/modules/bullet/bullet_physics_server.h @@ -47,7 +47,8 @@ class BulletPhysicsServer : public PhysicsServer { friend class BulletPhysicsDirectSpaceState; bool active; - SpaceBullet *activeSpace; + char active_spaces_count; + Vector active_spaces; mutable RID_Owner space_owner; mutable RID_Owner shape_owner; -- cgit v1.2.3