From 59cdc6b8f8f2f1b5ba8683a18cf927466ea301aa Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Thu, 10 Oct 2019 07:53:25 +0200 Subject: [PATCH] Take care of TODOs --- CHANGELOG.md | 3 + src/body/CollisionBody.cpp | 8 +-- src/body/RigidBody.cpp | 21 +----- src/body/RigidBody.h | 11 ---- src/collision/ProxyShape.cpp | 2 - src/collision/broadphase/DynamicAABBTree.cpp | 68 ++++++++++---------- src/collision/broadphase/DynamicAABBTree.h | 58 ++++++++--------- src/components/ProxyShapeComponents.cpp | 12 ++-- src/components/ProxyShapeComponents.h | 15 ++--- src/engine/CollisionWorld.cpp | 7 +- src/engine/DynamicsWorld.cpp | 10 +-- src/engine/EventListener.h | 14 ---- src/systems/BroadPhaseSystem.cpp | 4 +- src/systems/BroadPhaseSystem.h | 2 +- src/systems/ConstraintSolverSystem.cpp | 4 +- src/systems/ConstraintSolverSystem.h | 12 ---- src/systems/ContactSolverSystem.cpp | 2 - src/systems/DynamicsSystem.cpp | 2 - 18 files changed, 89 insertions(+), 166 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db4b85ba..2d9628d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ - DynamicsWorld::getContactsList(). You need to use the EventListener class to retrieve contacts now. - The DynamicsWorld::getNbJoints() method has been removed. - The DynamicsWorld::getNbRigidBodies() method has been removed. + - The EventListener::beginInternalTick() method has been removed (because internal ticks do not exist anymore). + - The EventListener::endInternalTick() method has been removed (because internal ticks do not exist anymore). + - The RigidBody::getJointsList() method has been removed. ## Release Candidate diff --git a/src/body/CollisionBody.cpp b/src/body/CollisionBody.cpp index b47ecca5..a0c3c068 100644 --- a/src/body/CollisionBody.cpp +++ b/src/body/CollisionBody.cpp @@ -86,7 +86,7 @@ ProxyShape* CollisionBody::addCollisionShape(CollisionShape* collisionShape, con Vector3 localBoundsMax; // TODO : Maybe this method can directly returns an AABB collisionShape->getLocalBounds(localBoundsMin, localBoundsMax); - ProxyShapeComponents::ProxyShapeComponent proxyShapeComponent(mEntity, proxyShape, -1, + ProxyShapeComponents::ProxyShapeComponent proxyShapeComponent(mEntity, proxyShape, AABB(localBoundsMin, localBoundsMax), transform, collisionShape, decimal(1), 0x0001, 0xFFFF); bool isActive = mWorld.mCollisionBodyComponents.getIsActive(mEntity); @@ -208,8 +208,6 @@ void CollisionBody::removeAllCollisionShapes() { */ const Transform& CollisionBody::getTransform() const { - // TODO : Make sure we do not call this method from the internal physics engine - return mWorld.mTransformComponents.getTransform(mEntity); } @@ -354,8 +352,6 @@ AABB CollisionBody::getAABB() const { const List& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity); if (proxyShapesEntities.size() == 0) return bodyAABB; - // TODO : Make sure we compute this in a system - const Transform& transform = mWorld.mTransformComponents.getTransform(mEntity); ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[0]); @@ -384,8 +380,6 @@ AABB CollisionBody::getAABB() const { */ void CollisionBody::setTransform(const Transform& transform) { - // TODO : Make sure this method is never called from the internal physics engine - // Update the transform of the body mWorld.mTransformComponents.setTransform(mEntity, transform); diff --git a/src/body/RigidBody.cpp b/src/body/RigidBody.cpp index 93979cbc..592a57d5 100644 --- a/src/body/RigidBody.cpp +++ b/src/body/RigidBody.cpp @@ -260,8 +260,6 @@ void RigidBody::setInverseInertiaTensorLocal(const Matrix3x3& inverseInertiaTens */ void RigidBody::setCenterOfMassLocal(const Vector3& centerOfMassLocal) { - // TODO : Check if we need to update the postion of the body here at the end (transform of the body) - if (mWorld.mRigidBodyComponents.getBodyType(mEntity) != BodyType::DYNAMIC) return; mIsCenterOfMassSetByUser = true; @@ -270,8 +268,7 @@ void RigidBody::setCenterOfMassLocal(const Vector3& centerOfMassLocal) { mWorld.mRigidBodyComponents.setCenterOfMassLocal(mEntity, centerOfMassLocal); // Compute the center of mass in world-space coordinates - const Vector3& updatedCenterOfMassLocal = mWorld.mRigidBodyComponents.getCenterOfMassLocal(mEntity); - mWorld.mRigidBodyComponents.setCenterOfMassWorld(mEntity, mWorld.mTransformComponents.getTransform(mEntity) * updatedCenterOfMassLocal); + mWorld.mRigidBodyComponents.setCenterOfMassWorld(mEntity, mWorld.mTransformComponents.getTransform(mEntity) * centerOfMassLocal); // Update the linear velocity of the center of mass Vector3 linearVelocity = mWorld.mRigidBodyComponents.getAngularVelocity(mEntity); @@ -340,7 +337,7 @@ ProxyShape* RigidBody::addCollisionShape(CollisionShape* collisionShape, // TODO : Maybe this method can directly returns an AABB collisionShape->getLocalBounds(localBoundsMin, localBoundsMax); - ProxyShapeComponents::ProxyShapeComponent proxyShapeComponent(mEntity, proxyShape, -1, + ProxyShapeComponents::ProxyShapeComponent proxyShapeComponent(mEntity, proxyShape, AABB(localBoundsMin, localBoundsMax), transform, collisionShape, mass, 0x0001, 0xFFFF); bool isSleeping = mWorld.mRigidBodyComponents.getIsSleeping(mEntity); @@ -438,18 +435,6 @@ void RigidBody::setAngularDamping(decimal angularDamping) { "Body " + std::to_string(mEntity.id) + ": Set angularDamping=" + std::to_string(angularDamping)); } -/// Update the transform of the body after a change of the center of mass -void RigidBody::updateTransformWithCenterOfMass() { - - // TODO : Make sure we compute this in a system - - // Translate the body according to the translation of the center of mass position - Transform& transform = mWorld.mTransformComponents.getTransform(mEntity); - const Vector3& centerOfMassWorld = mWorld.mRigidBodyComponents.getCenterOfMassWorld(mEntity); - const Vector3& centerOfMassLocal = mWorld.mRigidBodyComponents.getCenterOfMassLocal(mEntity); - transform.setPosition(centerOfMassWorld - transform.getOrientation() * centerOfMassLocal); -} - // Set a new material for this rigid body /** * @param material The material you want to set to the body @@ -488,8 +473,6 @@ void RigidBody::setLinearVelocity(const Vector3& linearVelocity) { */ void RigidBody::setAngularVelocity(const Vector3& angularVelocity) { - // TODO : Make sure this method is not called from the internal physics engine - // If it is a static body, we do nothing if (mWorld.mRigidBodyComponents.getBodyType(mEntity) == BodyType::STATIC) return; diff --git a/src/body/RigidBody.h b/src/body/RigidBody.h index a9be0847..0a83d5af 100644 --- a/src/body/RigidBody.h +++ b/src/body/RigidBody.h @@ -70,9 +70,6 @@ class RigidBody : public CollisionBody { // -------------------- Methods -------------------- // - /// Update the transform of the body after a change of the center of mass - void updateTransformWithCenterOfMass(); - /// Set the variable to know whether or not the body is sleeping void setIsSleeping(bool isSleeping); @@ -161,14 +158,6 @@ class RigidBody : public CollisionBody { /// Set the angular damping factor void setAngularDamping(decimal angularDamping); - /// Return the first element of the linked list of joints involving this body - // TODO : Remove this - const JointListElement* getJointsList() const; - - /// Return the first element of the linked list of joints involving this body - // TODO : Remove this - JointListElement* getJointsList(); - /// Apply an external force to the body at its center of mass. void applyForceToCenterOfMass(const Vector3& force); diff --git a/src/collision/ProxyShape.cpp b/src/collision/ProxyShape.cpp index e46ec63a..cc81f8c8 100644 --- a/src/collision/ProxyShape.cpp +++ b/src/collision/ProxyShape.cpp @@ -113,8 +113,6 @@ void ProxyShape::setCollideWithMaskBits(unsigned short collideWithMaskBits) { // Set the local to parent body transform void ProxyShape::setLocalToBodyTransform(const Transform& transform) { - // TODO : Make sure this method is never called by the internal physics engine - mBody->mWorld.mProxyShapesComponents.setLocalToBodyTransform(mEntity, transform); RigidBody* rigidBody = static_cast(mBody); diff --git a/src/collision/broadphase/DynamicAABBTree.cpp b/src/collision/broadphase/DynamicAABBTree.cpp index 82dc16e9..c27262ee 100644 --- a/src/collision/broadphase/DynamicAABBTree.cpp +++ b/src/collision/broadphase/DynamicAABBTree.cpp @@ -32,7 +32,7 @@ using namespace reactphysics3d; // Initialization of static variables -const int TreeNode::NULL_TREE_NODE = -1; +const int32 TreeNode::NULL_TREE_NODE = -1; // Constructor DynamicAABBTree::DynamicAABBTree(MemoryAllocator& allocator, decimal extraAABBGap) @@ -45,7 +45,7 @@ DynamicAABBTree::DynamicAABBTree(MemoryAllocator& allocator, decimal extraAABBGa DynamicAABBTree::~DynamicAABBTree() { // Free the allocated memory for the nodes - mAllocator.release(mNodes, mNbAllocatedNodes * sizeof(TreeNode)); + mAllocator.release(mNodes, static_cast(mNbAllocatedNodes) * sizeof(TreeNode)); } // Initialize the tree @@ -56,12 +56,12 @@ void DynamicAABBTree::init() { mNbAllocatedNodes = 8; // Allocate memory for the nodes of the tree - mNodes = static_cast(mAllocator.allocate(mNbAllocatedNodes * sizeof(TreeNode))); + mNodes = static_cast(mAllocator.allocate(static_cast(mNbAllocatedNodes) * sizeof(TreeNode))); assert(mNodes); - std::memset(mNodes, 0, mNbAllocatedNodes * sizeof(TreeNode)); + std::memset(mNodes, 0, static_cast(mNbAllocatedNodes) * sizeof(TreeNode)); // Initialize the allocated nodes - for (int i=0; i(mNbAllocatedNodes) * sizeof(TreeNode)); // Initialize the tree init(); } // Allocate and return a new node in the tree -int DynamicAABBTree::allocateNode() { +int32 DynamicAABBTree::allocateNode() { // If there is no more allocated node to use if (mFreeNodeID == TreeNode::NULL_TREE_NODE) { @@ -89,16 +89,16 @@ int DynamicAABBTree::allocateNode() { assert(mNbNodes == mNbAllocatedNodes); // Allocate more nodes in the tree - uint oldNbAllocatedNodes = mNbAllocatedNodes; + int32 oldNbAllocatedNodes = mNbAllocatedNodes; mNbAllocatedNodes *= 2; TreeNode* oldNodes = mNodes; - mNodes = static_cast(mAllocator.allocate(mNbAllocatedNodes * sizeof(TreeNode))); + mNodes = static_cast(mAllocator.allocate(static_cast(mNbAllocatedNodes) * sizeof(TreeNode))); assert(mNodes); - memcpy(mNodes, oldNodes, mNbNodes * sizeof(TreeNode)); - mAllocator.release(oldNodes, oldNbAllocatedNodes * sizeof(TreeNode)); + memcpy(mNodes, oldNodes, static_cast(mNbNodes) * sizeof(TreeNode)); + mAllocator.release(oldNodes, static_cast(oldNbAllocatedNodes) * sizeof(TreeNode)); // Initialize the allocated nodes - for (int i=mNbNodes; i= 0 && nodeID < mNbAllocatedNodes); assert(mNodes[nodeID].isLeaf()); @@ -170,7 +170,7 @@ void DynamicAABBTree::removeObject(int nodeID) { /// The method returns true if the object has been reinserted into the tree. The "displacement" /// argument is the linear velocity of the AABB multiplied by the elapsed time between two /// frames. -bool DynamicAABBTree::updateObject(int nodeID, const AABB& newAABB, const Vector3& displacement) { +bool DynamicAABBTree::updateObject(int32 nodeID, const AABB& newAABB, const Vector3& displacement) { RP3D_PROFILE("DynamicAABBTree::updateObject()", mProfiler); @@ -424,7 +424,7 @@ void DynamicAABBTree::removeLeafNode(int nodeID) { // Balance the sub-tree of a given node using left or right rotations. /// The rotation schemes are described in the book "Introduction to Game Physics /// with Box2D" by Ian Parberry. This method returns the new root node ID. -int DynamicAABBTree::balanceSubTreeAtNode(int nodeID) { +int32 DynamicAABBTree::balanceSubTreeAtNode(int32 nodeID) { assert(nodeID != TreeNode::NULL_TREE_NODE); @@ -593,11 +593,11 @@ int DynamicAABBTree::balanceSubTreeAtNode(int nodeID) { } /// Take a list of shapes to be tested for broad-phase overlap and return a list of pair of overlapping shapes -void DynamicAABBTree::reportAllShapesOverlappingWithShapes(const List& nodesToTest, size_t startIndex, - size_t endIndex, List>& outOverlappingNodes) const { +void DynamicAABBTree::reportAllShapesOverlappingWithShapes(const List& nodesToTest, size_t startIndex, + size_t endIndex, List>& outOverlappingNodes) const { // Create a stack with the nodes to visit - Stack stack(mAllocator, 64); + Stack stack(mAllocator, 64); // For each shape to be tested for overlap for (uint i=startIndex; i < endIndex; i++) { @@ -612,7 +612,7 @@ void DynamicAABBTree::reportAllShapesOverlappingWithShapes(const List& node while(stack.size() > 0) { // Get the next node ID to visit - const int nodeIDToVisit = stack.pop(); + const int32 nodeIDToVisit = stack.pop(); // Skip it if it is a null node if (nodeIDToVisit == TreeNode::NULL_TREE_NODE) continue; @@ -627,7 +627,7 @@ void DynamicAABBTree::reportAllShapesOverlappingWithShapes(const List& node if (nodeToVisit->isLeaf()) { // Add the node in the list of overlapping nodes - outOverlappingNodes.add(Pair(nodesToTest[i], nodeIDToVisit)); + outOverlappingNodes.add(Pair(nodesToTest[i], nodeIDToVisit)); } else { // If the node is not a leaf @@ -643,17 +643,17 @@ void DynamicAABBTree::reportAllShapesOverlappingWithShapes(const List& node } // Report all shapes overlapping with the AABB given in parameter. -void DynamicAABBTree::reportAllShapesOverlappingWithAABB(const AABB& aabb, List& overlappingNodes) const { +void DynamicAABBTree::reportAllShapesOverlappingWithAABB(const AABB& aabb, List& overlappingNodes) const { // Create a stack with the nodes to visit - Stack stack(mAllocator, 64); + Stack stack(mAllocator, 64); stack.push(mRootNodeID); // While there are still nodes to visit while(stack.size() > 0) { // Get the next node ID to visit - const int nodeIDToVisit = stack.pop(); + const int32 nodeIDToVisit = stack.pop(); // Skip it if it is a null node if (nodeIDToVisit == TreeNode::NULL_TREE_NODE) continue; @@ -687,7 +687,7 @@ void DynamicAABBTree::raycast(const Ray& ray, DynamicAABBTreeRaycastCallback& ca decimal maxFraction = ray.maxFraction; - Stack stack(mAllocator, 128); + Stack stack(mAllocator, 128); stack.push(mRootNodeID); // Walk through the tree from the root looking for proxy shapes @@ -695,7 +695,7 @@ void DynamicAABBTree::raycast(const Ray& ray, DynamicAABBTreeRaycastCallback& ca while (stack.size() > 0) { // Get the next node in the stack - int nodeID = stack.pop(); + int32 nodeID = stack.pop(); // If it is a null node, skip it if (nodeID == TreeNode::NULL_TREE_NODE) continue; @@ -750,8 +750,8 @@ void DynamicAABBTree::check() const { // Recursively check each node checkNode(mRootNodeID); - int nbFreeNodes = 0; - int freeNodeID = mFreeNodeID; + int32 nbFreeNodes = 0; + int32 freeNodeID = mFreeNodeID; // Check the free nodes while(freeNodeID != TreeNode::NULL_TREE_NODE) { @@ -764,7 +764,7 @@ void DynamicAABBTree::check() const { } // Check if the node structure is valid (for debugging purpose) -void DynamicAABBTree::checkNode(int nodeID) const { +void DynamicAABBTree::checkNode(int32 nodeID) const { if (nodeID == TreeNode::NULL_TREE_NODE) return; @@ -776,8 +776,8 @@ void DynamicAABBTree::checkNode(int nodeID) const { // Get the children nodes TreeNode* pNode = mNodes + nodeID; assert(!pNode->isLeaf()); - int leftChild = pNode->children[0]; - int rightChild = pNode->children[1]; + int32 leftChild = pNode->children[0]; + int32 rightChild = pNode->children[1]; assert(pNode->height >= 0); assert(pNode->aabb.getVolume() > 0); @@ -822,7 +822,7 @@ int DynamicAABBTree::computeHeight() { } // Compute the height of a given node in the tree -int DynamicAABBTree::computeHeight(int nodeID) { +int DynamicAABBTree::computeHeight(int32 nodeID) { assert(nodeID >= 0 && nodeID < mNbAllocatedNodes); TreeNode* node = mNodes + nodeID; diff --git a/src/collision/broadphase/DynamicAABBTree.h b/src/collision/broadphase/DynamicAABBTree.h index 0bc16e8e..3cbf2daa 100644 --- a/src/collision/broadphase/DynamicAABBTree.h +++ b/src/collision/broadphase/DynamicAABBTree.h @@ -54,7 +54,7 @@ struct TreeNode { // -------------------- Constants -------------------- // /// Null tree node constant - const static int NULL_TREE_NODE; + const static int32 NULL_TREE_NODE; // -------------------- Attributes -------------------- // @@ -148,16 +148,16 @@ class DynamicAABBTree { TreeNode* mNodes; /// ID of the root node of the tree - int mRootNodeID; + int32 mRootNodeID; /// ID of the first node of the list of free (allocated) nodes in the tree that we can use - int mFreeNodeID; + int32 mFreeNodeID; /// Number of allocated nodes in the tree - int mNbAllocatedNodes; + int32 mNbAllocatedNodes; /// Number of nodes in the tree - int mNbNodes; + int32 mNbNodes; /// Extra AABB Gap used to allow the collision shape to move a little bit /// without triggering a large modification of the tree which can be costly @@ -173,25 +173,25 @@ class DynamicAABBTree { // -------------------- Methods -------------------- // /// Allocate and return a node to use in the tree - int allocateNode(); + int32 allocateNode(); /// Release a node - void releaseNode(int nodeID); + void releaseNode(int32 nodeID); /// Insert a leaf node in the tree - void insertLeafNode(int nodeID); + void insertLeafNode(int32 nodeID); /// Remove a leaf node from the tree - void removeLeafNode(int nodeID); + void removeLeafNode(int32 nodeID); /// Balance the sub-tree of a given node using left or right rotations. - int balanceSubTreeAtNode(int nodeID); + int32 balanceSubTreeAtNode(int32 nodeID); /// Compute the height of a given node in the tree - int computeHeight(int nodeID); + int computeHeight(int32 nodeID); /// Internally add an object into the tree - int addObjectInternal(const AABB& aabb); + int32 addObjectInternal(const AABB& aabb); /// Initialize the tree void init(); @@ -202,7 +202,7 @@ class DynamicAABBTree { void check() const; /// Check if the node structure is valid (for debugging purpose) - void checkNode(int nodeID) const; + void checkNode(int32 nodeID) const; #endif @@ -217,29 +217,29 @@ class DynamicAABBTree { ~DynamicAABBTree(); /// Add an object into the tree (where node data are two integers) - int addObject(const AABB& aabb, int32 data1, int32 data2); + int32 addObject(const AABB& aabb, int32 data1, int32 data2); /// Add an object into the tree (where node data is a pointer) - int addObject(const AABB& aabb, void* data); + int32 addObject(const AABB& aabb, void* data); /// Remove an object from the tree - void removeObject(int nodeID); + void removeObject(int32 nodeID); /// Update the dynamic tree after an object has moved. - bool updateObject(int nodeID, const AABB& newAABB, const Vector3& displacement); + bool updateObject(int32 nodeID, const AABB& newAABB, const Vector3& displacement); /// Return the fat AABB corresponding to a given node ID - const AABB& getFatAABB(int nodeID) const; + const AABB& getFatAABB(int32 nodeID) const; /// Return the pointer to the data array of a given leaf node of the tree - int32* getNodeDataInt(int nodeID) const; + int32* getNodeDataInt(int32 nodeID) const; /// Return the data pointer of a given leaf node of the tree - void* getNodeDataPointer(int nodeID) const; + void* getNodeDataPointer(int32 nodeID) const; /// Report all shapes overlapping with all the shapes in the map in parameter - void reportAllShapesOverlappingWithShapes(const List& nodesToTest, size_t startIndex, - size_t endIndex, List>& outOverlappingNodes) const; + void reportAllShapesOverlappingWithShapes(const List& nodesToTest, size_t startIndex, + size_t endIndex, List>& outOverlappingNodes) const; /// Report all shapes overlapping with the AABB given in parameter. void reportAllShapesOverlappingWithAABB(const AABB& aabb, List& overlappingNodes) const; @@ -271,20 +271,20 @@ inline bool TreeNode::isLeaf() const { } // Return the fat AABB corresponding to a given node ID -inline const AABB& DynamicAABBTree::getFatAABB(int nodeID) const { +inline const AABB& DynamicAABBTree::getFatAABB(int32 nodeID) const { assert(nodeID >= 0 && nodeID < mNbAllocatedNodes); return mNodes[nodeID].aabb; } // Return the pointer to the data array of a given leaf node of the tree -inline int32* DynamicAABBTree::getNodeDataInt(int nodeID) const { +inline int32* DynamicAABBTree::getNodeDataInt(int32 nodeID) const { assert(nodeID >= 0 && nodeID < mNbAllocatedNodes); assert(mNodes[nodeID].isLeaf()); return mNodes[nodeID].dataInt; } // Return the pointer to the data pointer of a given leaf node of the tree -inline void* DynamicAABBTree::getNodeDataPointer(int nodeID) const { +inline void* DynamicAABBTree::getNodeDataPointer(int32 nodeID) const { assert(nodeID >= 0 && nodeID < mNbAllocatedNodes); assert(mNodes[nodeID].isLeaf()); return mNodes[nodeID].dataPointer; @@ -297,9 +297,9 @@ inline AABB DynamicAABBTree::getRootAABB() const { // Add an object into the tree. This method creates a new leaf node in the tree and // returns the ID of the corresponding node. -inline int DynamicAABBTree::addObject(const AABB& aabb, int32 data1, int32 data2) { +inline int32 DynamicAABBTree::addObject(const AABB& aabb, int32 data1, int32 data2) { - int nodeId = addObjectInternal(aabb); + int32 nodeId = addObjectInternal(aabb); mNodes[nodeId].dataInt[0] = data1; mNodes[nodeId].dataInt[1] = data2; @@ -309,9 +309,9 @@ inline int DynamicAABBTree::addObject(const AABB& aabb, int32 data1, int32 data2 // Add an object into the tree. This method creates a new leaf node in the tree and // returns the ID of the corresponding node. -inline int DynamicAABBTree::addObject(const AABB& aabb, void* data) { +inline int32 DynamicAABBTree::addObject(const AABB& aabb, void* data) { - int nodeId = addObjectInternal(aabb); + int32 nodeId = addObjectInternal(aabb); mNodes[nodeId].dataPointer = data; diff --git a/src/components/ProxyShapeComponents.cpp b/src/components/ProxyShapeComponents.cpp index 198b80da..4f06aebb 100644 --- a/src/components/ProxyShapeComponents.cpp +++ b/src/components/ProxyShapeComponents.cpp @@ -59,7 +59,7 @@ void ProxyShapeComponents::allocate(uint32 nbComponentsToAllocate) { Entity* newProxyShapesEntities = static_cast(newBuffer); Entity* newBodiesEntities = reinterpret_cast(newProxyShapesEntities + nbComponentsToAllocate); ProxyShape** newProxyShapes = reinterpret_cast(newBodiesEntities + nbComponentsToAllocate); - int* newBroadPhaseIds = reinterpret_cast(newProxyShapes + nbComponentsToAllocate); + int32* newBroadPhaseIds = reinterpret_cast(newProxyShapes + nbComponentsToAllocate); Transform* newLocalToBodyTransforms = reinterpret_cast(newBroadPhaseIds + nbComponentsToAllocate); CollisionShape** newCollisionShapes = reinterpret_cast(newLocalToBodyTransforms + nbComponentsToAllocate); decimal* newMasses = reinterpret_cast(newCollisionShapes + nbComponentsToAllocate); @@ -73,7 +73,7 @@ void ProxyShapeComponents::allocate(uint32 nbComponentsToAllocate) { memcpy(newProxyShapesEntities, mProxyShapesEntities, mNbComponents * sizeof(Entity)); memcpy(newBodiesEntities, mBodiesEntities, mNbComponents * sizeof(Entity)); memcpy(newProxyShapes, mProxyShapes, mNbComponents * sizeof(ProxyShape*)); - memcpy(newBroadPhaseIds, mBroadPhaseIds, mNbComponents * sizeof(int)); + memcpy(newBroadPhaseIds, mBroadPhaseIds, mNbComponents * sizeof(int32)); memcpy(newLocalToBodyTransforms, mLocalToBodyTransforms, mNbComponents * sizeof(Transform)); memcpy(newCollisionShapes, mCollisionShapes, mNbComponents * sizeof(CollisionShape*)); memcpy(newMasses, mMasses, mNbComponents * sizeof(decimal)); @@ -109,7 +109,7 @@ void ProxyShapeComponents::addComponent(Entity proxyShapeEntity, bool isSleeping new (mProxyShapesEntities + index) Entity(proxyShapeEntity); new (mBodiesEntities + index) Entity(component.bodyEntity); mProxyShapes[index] = component.proxyShape; - new (mBroadPhaseIds + index) int(component.broadPhaseId); + new (mBroadPhaseIds + index) int32(-1); new (mLocalToBodyTransforms + index) Transform(component.localToBodyTransform); mCollisionShapes[index] = component.collisionShape; new (mMasses + index) decimal(component.mass); @@ -134,7 +134,7 @@ void ProxyShapeComponents::moveComponentToIndex(uint32 srcIndex, uint32 destInde new (mProxyShapesEntities + destIndex) Entity(mProxyShapesEntities[srcIndex]); new (mBodiesEntities + destIndex) Entity(mBodiesEntities[srcIndex]); mProxyShapes[destIndex] = mProxyShapes[srcIndex]; - new (mBroadPhaseIds + destIndex) int(mBroadPhaseIds[srcIndex]); + new (mBroadPhaseIds + destIndex) int32(mBroadPhaseIds[srcIndex]); new (mLocalToBodyTransforms + destIndex) Transform(mLocalToBodyTransforms[srcIndex]); mCollisionShapes[destIndex] = mCollisionShapes[srcIndex]; new (mMasses + destIndex) decimal(mMasses[srcIndex]); @@ -159,7 +159,7 @@ void ProxyShapeComponents::swapComponents(uint32 index1, uint32 index2) { Entity proxyShapeEntity1(mProxyShapesEntities[index1]); Entity bodyEntity1(mBodiesEntities[index1]); ProxyShape* proxyShape1 = mProxyShapes[index1]; - int broadPhaseId1 = mBroadPhaseIds[index1]; + int32 broadPhaseId1 = mBroadPhaseIds[index1]; Transform localToBodyTransform1 = mLocalToBodyTransforms[index1]; CollisionShape* collisionShape1 = mCollisionShapes[index1]; decimal mass1 = mMasses[index1]; @@ -175,7 +175,7 @@ void ProxyShapeComponents::swapComponents(uint32 index1, uint32 index2) { new (mProxyShapesEntities + index2) Entity(proxyShapeEntity1); new (mBodiesEntities + index2) Entity(bodyEntity1); mProxyShapes[index2] = proxyShape1; - new (mBroadPhaseIds + index2) int(broadPhaseId1); + new (mBroadPhaseIds + index2) int32(broadPhaseId1); new (mLocalToBodyTransforms + index2) Transform(localToBodyTransform1); mCollisionShapes[index2] = collisionShape1; new (mMasses + index2) decimal(mass1); diff --git a/src/components/ProxyShapeComponents.h b/src/components/ProxyShapeComponents.h index 7c9c8364..c5d9cf25 100644 --- a/src/components/ProxyShapeComponents.h +++ b/src/components/ProxyShapeComponents.h @@ -66,7 +66,7 @@ class ProxyShapeComponents : public Components { /// Ids of the proxy-shapes for the broad-phase algorithm // TODO : Try to change type to uint32 - int* mBroadPhaseIds; + int32* mBroadPhaseIds; /// Transform from local-space of the proxy-shape to the body-space of its body Transform* mLocalToBodyTransforms; @@ -111,7 +111,6 @@ class ProxyShapeComponents : public Components { Entity bodyEntity; ProxyShape* proxyShape; - int broadPhaseId; AABB localBounds; Transform localToBodyTransform; CollisionShape* collisionShape; @@ -120,10 +119,10 @@ class ProxyShapeComponents : public Components { unsigned short collideWithMaskBits; /// Constructor - ProxyShapeComponent(Entity bodyEntity, ProxyShape* proxyShape, int broadPhaseId, AABB localBounds, Transform localToBodyTransform, + ProxyShapeComponent(Entity bodyEntity, ProxyShape* proxyShape, AABB localBounds, Transform localToBodyTransform, CollisionShape* collisionShape, decimal mass, unsigned short collisionCategoryBits, unsigned short collideWithMaskBits) - :bodyEntity(bodyEntity), proxyShape(proxyShape), broadPhaseId(broadPhaseId), localBounds(localBounds), localToBodyTransform(localToBodyTransform), + :bodyEntity(bodyEntity), proxyShape(proxyShape), localBounds(localBounds), localToBodyTransform(localToBodyTransform), collisionShape(collisionShape), mass(mass), collisionCategoryBits(collisionCategoryBits), collideWithMaskBits(collideWithMaskBits) { } @@ -159,10 +158,10 @@ class ProxyShapeComponents : public Components { CollisionShape* getCollisionShape(Entity proxyShapeEntity) const; /// Return the broad-phase id of a given proxy shape - int getBroadPhaseId(Entity proxyShapeEntity) const; + int32 getBroadPhaseId(Entity proxyShapeEntity) const; /// Set the broad-phase id of a given proxy shape - void setBroadPhaseId(Entity proxyShapeEntity, int broadPhaseId); + void setBroadPhaseId(Entity proxyShapeEntity, int32 broadPhaseId); /// Return the collision category bits of a given proxy-shape unsigned short getCollisionCategoryBits(Entity proxyShapeEntity) const; @@ -230,7 +229,7 @@ inline CollisionShape* ProxyShapeComponents::getCollisionShape(Entity proxyShape } // Return the broad-phase id of a given proxy shape -inline int ProxyShapeComponents::getBroadPhaseId(Entity proxyShapeEntity) const { +inline int32 ProxyShapeComponents::getBroadPhaseId(Entity proxyShapeEntity) const { assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity)); @@ -238,7 +237,7 @@ inline int ProxyShapeComponents::getBroadPhaseId(Entity proxyShapeEntity) const } // Set the broad-phase id of a given proxy shape -inline void ProxyShapeComponents::setBroadPhaseId(Entity proxyShapeEntity, int broadPhaseId) { +inline void ProxyShapeComponents::setBroadPhaseId(Entity proxyShapeEntity, int32 broadPhaseId) { assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity)); diff --git a/src/engine/CollisionWorld.cpp b/src/engine/CollisionWorld.cpp index c4a9351f..902e8fa9 100644 --- a/src/engine/CollisionWorld.cpp +++ b/src/engine/CollisionWorld.cpp @@ -214,8 +214,6 @@ void CollisionWorld::setBodyDisabled(Entity bodyEntity, bool isDisabled) { if (isDisabled == mCollisionBodyComponents.getIsEntityDisabled(bodyEntity)) return; - // TODO : Make sure we notify all the components here ... - // Notify all the components mCollisionBodyComponents.setIsEntityDisabled(bodyEntity, isDisabled); mTransformComponents.setIsEntityDisabled(bodyEntity, isDisabled); @@ -238,8 +236,8 @@ void CollisionWorld::setBodyDisabled(Entity bodyEntity, bool isDisabled) { const List& joints = mRigidBodyComponents.getJoints(bodyEntity); for(uint32 i=0; i < joints.size(); i++) { - Entity body1Entity = mJointsComponents.getBody1Entity(joints[i]); - Entity body2Entity = mJointsComponents.getBody2Entity(joints[i]); + const Entity body1Entity = mJointsComponents.getBody1Entity(joints[i]); + const Entity body2Entity = mJointsComponents.getBody2Entity(joints[i]); // If both bodies of the joint are disabled if (mRigidBodyComponents.getIsEntityDisabled(body1Entity) && @@ -262,7 +260,6 @@ void CollisionWorld::setJointDisabled(Entity jointEntity, bool isDisabled) { if (isDisabled == mJointsComponents.getIsEntityDisabled(jointEntity)) return; - // TODO : Make sure we notify all the components here ... mJointsComponents.setIsEntityDisabled(jointEntity, isDisabled); if (mBallAndSocketJointsComponents.hasComponent(jointEntity)) { mBallAndSocketJointsComponents.setIsEntityDisabled(jointEntity, isDisabled); diff --git a/src/engine/DynamicsWorld.cpp b/src/engine/DynamicsWorld.cpp index f09b37bb..164d3fa8 100644 --- a/src/engine/DynamicsWorld.cpp +++ b/src/engine/DynamicsWorld.cpp @@ -115,9 +115,6 @@ void DynamicsWorld::update(decimal timeStep) { RP3D_PROFILE("DynamicsWorld::update()", mProfiler); - // Notify the event listener about the beginning of an internal tick - if (mEventListener != nullptr) mEventListener->beginInternalTick(); - // Compute the collision detection mCollisionDetection.computeCollisionDetection(); @@ -153,9 +150,6 @@ void DynamicsWorld::update(decimal timeStep) { if (mIsSleepingEnabled) updateSleepingBodies(timeStep); - // Notify the event listener about the end of an internal tick - if (mEventListener != nullptr) mEventListener->endInternalTick(); - // Reset the external force and torque applied to the bodies mDynamicsSystem.resetBodiesForceAndTorque(); @@ -463,10 +457,7 @@ void DynamicsWorld::destroyJoint(Joint* joint) { Entity jointEntity = joint->getEntity(); // Destroy the corresponding entity and its components - // TODO : Make sure we remove all its components here mJointsComponents.removeComponent(jointEntity); - mEntityManager.destroyEntity(jointEntity); - if (mBallAndSocketJointsComponents.hasComponent(jointEntity)) { mBallAndSocketJointsComponents.removeComponent(jointEntity); } @@ -479,6 +470,7 @@ void DynamicsWorld::destroyJoint(Joint* joint) { if (mSliderJointsComponents.hasComponent(jointEntity)) { mSliderJointsComponents.removeComponent(jointEntity); } + mEntityManager.destroyEntity(jointEntity); // Call the destructor of the joint joint->~Joint(); diff --git a/src/engine/EventListener.h b/src/engine/EventListener.h index e0ee9e80..44da1c44 100644 --- a/src/engine/EventListener.h +++ b/src/engine/EventListener.h @@ -54,20 +54,6 @@ class EventListener : public CollisionCallback { * @param collisionInfo Information about the contacts */ virtual void onContact(const CollisionCallback::CallbackData& callbackData) override {} - - // TODO : Remove this method (no internal steps anymore) - /// Called at the beginning of an internal tick of the simulation step. - /// Each time the DynamicsWorld::update() method is called, the physics - /// engine will do several internal simulation steps. This method is - /// called at the beginning of each internal simulation step. - virtual void beginInternalTick() {} - - // TODO : Remove this method (no internal steps anymore) - /// Called at the end of an internal tick of the simulation step. - /// Each time the DynamicsWorld::update() metho is called, the physics - /// engine will do several internal simulation steps. This method is - /// called at the end of each internal simulation step. - virtual void endInternalTick() {} }; } diff --git a/src/systems/BroadPhaseSystem.cpp b/src/systems/BroadPhaseSystem.cpp index 52e48375..08aea7f8 100644 --- a/src/systems/BroadPhaseSystem.cpp +++ b/src/systems/BroadPhaseSystem.cpp @@ -128,7 +128,7 @@ void BroadPhaseSystem::updateProxyShapes(decimal timeStep) { } // Notify the broad-phase that a collision shape has moved and need to be updated -void BroadPhaseSystem::updateProxyShapeInternal(int broadPhaseId, const AABB& aabb, const Vector3& displacement) { +void BroadPhaseSystem::updateProxyShapeInternal(int32 broadPhaseId, const AABB& aabb, const Vector3& displacement) { assert(broadPhaseId >= 0); @@ -161,7 +161,7 @@ void BroadPhaseSystem::updateProxyShapesComponents(uint32 startIndex, uint32 nbI // For each proxy-shape component to update for (uint32 i = startIndex; i < startIndex + nbItems; i++) { - const int broadPhaseId = mProxyShapesComponents.mBroadPhaseIds[i]; + const int32 broadPhaseId = mProxyShapesComponents.mBroadPhaseIds[i]; if (broadPhaseId != -1) { const Entity& bodyEntity = mProxyShapesComponents.mBodiesEntities[i]; diff --git a/src/systems/BroadPhaseSystem.h b/src/systems/BroadPhaseSystem.h index 934ea9b6..a6ae9815 100644 --- a/src/systems/BroadPhaseSystem.h +++ b/src/systems/BroadPhaseSystem.h @@ -140,7 +140,7 @@ class BroadPhaseSystem { // -------------------- Methods -------------------- // /// Notify the Dynamic AABB tree that a proxy-shape needs to be updated - void updateProxyShapeInternal(int broadPhaseId, const AABB& aabb, const Vector3& displacement); + void updateProxyShapeInternal(int32 broadPhaseId, const AABB& aabb, const Vector3& displacement); /// Update the broad-phase state of some proxy-shapes components void updateProxyShapesComponents(uint32 startIndex, uint32 nbItems, decimal timeStep); diff --git a/src/systems/ConstraintSolverSystem.cpp b/src/systems/ConstraintSolverSystem.cpp index ae487375..53dd41c8 100644 --- a/src/systems/ConstraintSolverSystem.cpp +++ b/src/systems/ConstraintSolverSystem.cpp @@ -45,9 +45,7 @@ ConstraintSolverSystem::ConstraintSolverSystem(DynamicsWorld& world, Islands& is mSolveBallAndSocketJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, ballAndSocketJointComponents), mSolveFixedJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, fixedJointComponents), mSolveHingeJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, hingeJointComponents), - mSolveSliderJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, sliderJointComponents), - mJointComponents(jointComponents), mBallAndSocketJointComponents(ballAndSocketJointComponents), - mFixedJointComponents(fixedJointComponents), mHingeJointComponents(hingeJointComponents) { + mSolveSliderJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, sliderJointComponents) { #ifdef IS_PROFILING_ACTIVE diff --git a/src/systems/ConstraintSolverSystem.h b/src/systems/ConstraintSolverSystem.h index 710d8a87..c3a419bf 100644 --- a/src/systems/ConstraintSolverSystem.h +++ b/src/systems/ConstraintSolverSystem.h @@ -173,18 +173,6 @@ class ConstraintSolverSystem { /// Solver for the SliderJoint constraints SolveSliderJointSystem mSolveSliderJointSystem; - // TODO : Delete this - JointComponents& mJointComponents; - - // TODO : Delete this - BallAndSocketJointComponents& mBallAndSocketJointComponents; - - // TODO : Delete this - FixedJointComponents& mFixedJointComponents; - - // TODO : Delete this - HingeJointComponents& mHingeJointComponents; - #ifdef IS_PROFILING_ACTIVE /// Pointer to the profiler diff --git a/src/systems/ContactSolverSystem.cpp b/src/systems/ContactSolverSystem.cpp index e95603a7..ac54f36f 100644 --- a/src/systems/ContactSolverSystem.cpp +++ b/src/systems/ContactSolverSystem.cpp @@ -68,7 +68,6 @@ void ContactSolverSystem::init(List* contactManifolds, Listsize(); uint nbContactPoints = mAllContactPoints->size(); @@ -80,7 +79,6 @@ void ContactSolverSystem::init(List* contactManifolds, List(mMemoryManager.allocate(MemoryManager::AllocationType::Frame, sizeof(ContactPointSolver) * nbContactPoints)); assert(mContactPoints != nullptr); diff --git a/src/systems/DynamicsSystem.cpp b/src/systems/DynamicsSystem.cpp index 68a12299..4dcee2ac 100644 --- a/src/systems/DynamicsSystem.cpp +++ b/src/systems/DynamicsSystem.cpp @@ -73,8 +73,6 @@ void DynamicsSystem::updateBodiesState() { RP3D_PROFILE("DynamicsSystem::updateBodiesState()", mProfiler); - // TODO : Make sure we compute this in a system - for (uint32 i=0; i < mRigidBodyComponents.getNbEnabledComponents(); i++) { // Update the linear and angular velocity of the body