From 8911351c8f3af47a577b2a59117787f48a6dd57e Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Tue, 26 Mar 2019 22:55:32 +0100 Subject: [PATCH] Fix issue in DynamicsComponents --- CMakeLists.txt | 1 - src/collision/broadphase/BroadPhasePair.cpp | 31 ------ src/collision/broadphase/BroadPhasePair.h | 104 -------------------- src/components/DynamicsComponents.cpp | 14 ++- 4 files changed, 9 insertions(+), 141 deletions(-) delete mode 100644 src/collision/broadphase/BroadPhasePair.cpp delete mode 100644 src/collision/broadphase/BroadPhasePair.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 445b8a70..63cc8a17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,6 @@ SET (REACTPHYSICS3D_HEADERS "src/body/RigidBody.h" "src/collision/ContactPointInfo.h" "src/collision/broadphase/DynamicAABBTree.h" - "src/collision/broadphase/BroadPhasePair.h" "src/collision/narrowphase/CollisionDispatch.h" "src/collision/narrowphase/GJK/VoronoiSimplex.h" "src/collision/narrowphase/GJK/GJKAlgorithm.h" diff --git a/src/collision/broadphase/BroadPhasePair.cpp b/src/collision/broadphase/BroadPhasePair.cpp deleted file mode 100644 index ba590031..00000000 --- a/src/collision/broadphase/BroadPhasePair.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************** -* ReactPhysics3D physics library, http://www.reactphysics3d.com * -* Copyright (c) 2010-2018 Daniel Chappuis * -********************************************************************************* -* * -* This software is provided 'as-is', without any express or implied warranty. * -* In no event will the authors be held liable for any damages arising from the * -* use of this software. * -* * -* Permission is granted to anyone to use this software for any purpose, * -* including commercial applications, and to alter it and redistribute it * -* freely, subject to the following restrictions: * -* * -* 1. The origin of this software must not be misrepresented; you must not claim * -* that you wrote the original software. If you use this software in a * -* product, an acknowledgment in the product documentation would be * -* appreciated but is not required. * -* * -* 2. Altered source versions must be plainly marked as such, and must not be * -* misrepresented as being the original software. * -* * -* 3. This notice may not be removed or altered from any source distribution. * -* * -********************************************************************************/ - -// Libraries -#include "BroadPhasePair.h" - -// We want to use the ReactPhysics3D namespace -using namespace reactphysics3d; - diff --git a/src/collision/broadphase/BroadPhasePair.h b/src/collision/broadphase/BroadPhasePair.h deleted file mode 100644 index 7379365f..00000000 --- a/src/collision/broadphase/BroadPhasePair.h +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************** -* ReactPhysics3D physics library, http://www.reactphysics3d.com * -* Copyright (c) 2010-2018 Daniel Chappuis * -********************************************************************************* -* * -* This software is provided 'as-is', without any express or implied warranty. * -* In no event will the authors be held liable for any damages arising from the * -* use of this software. * -* * -* Permission is granted to anyone to use this software for any purpose, * -* including commercial applications, and to alter it and redistribute it * -* freely, subject to the following restrictions: * -* * -* 1. The origin of this software must not be misrepresented; you must not claim * -* that you wrote the original software. If you use this software in a * -* product, an acknowledgment in the product documentation would be * -* appreciated but is not required. * -* * -* 2. Altered source versions must be plainly marked as such, and must not be * -* misrepresented as being the original software. * -* * -* 3. This notice may not be removed or altered from any source distribution. * -* * -********************************************************************************/ - -#ifndef REACTPHYSICS3D_BROAD_PHASE_PAIR_H -#define REACTPHYSICS3D_BROAD_PHASE_PAIR_H - -// Libraries -#include -#include -#include"containers/Pair.h" - - -/// Namespace ReactPhysics3D -namespace reactphysics3d { - -// Structure BroadPhasePair -/** - * This structure represent a potential overlapping pair during the - * broad-phase collision detection. - */ -struct BroadPhasePair { - - public: - - // -------------------- Attributes -------------------- // - - // Broad-phase id of the first collision shape - int shape1BroadPhaseId; - - // Broad-phase id of the second collision shape - int shape2BroadPhaseId; - - // -------------------- Methods -------------------- // - - /// Constructor - BroadPhasePair(int shapeId1, int shapeId2) - : shape1BroadPhaseId(std::min(shapeId1, shapeId2)), - shape2BroadPhaseId(std::max(shapeId1, shapeId2)) { - - assert(shape1BroadPhaseId != -1); - assert(shape2BroadPhaseId != -1); - } - - /// Equality operator - bool operator==(const BroadPhasePair& pair) const; - - /// Inequality operator - bool operator!=(const BroadPhasePair& pair) const; -}; - -// Equality operator -inline bool BroadPhasePair::operator==(const BroadPhasePair& pair) const { - - return shape1BroadPhaseId == pair.shape1BroadPhaseId && shape2BroadPhaseId == pair.shape2BroadPhaseId; -} - -// Inequality operator -inline bool BroadPhasePair::operator!=(const BroadPhasePair& pair) const { - return shape1BroadPhaseId != pair.shape1BroadPhaseId || shape2BroadPhaseId != pair.shape2BroadPhaseId; -} - -} - -// Hash function for a reactphysics3d BroadPhasePair -namespace std { - - template <> struct hash { - - size_t operator()(const reactphysics3d::BroadPhasePair& pair) const { - - assert(pair.shape1BroadPhaseId <= pair.shape2BroadPhaseId); - - std::size_t seed = 0; - reactphysics3d::hash_combine(seed, pair.shape1BroadPhaseId); - reactphysics3d::hash_combine(seed, pair.shape2BroadPhaseId); - - return seed; - } - }; -} - -#endif diff --git a/src/components/DynamicsComponents.cpp b/src/components/DynamicsComponents.cpp index effe55d6..e23b3cfb 100644 --- a/src/components/DynamicsComponents.cpp +++ b/src/components/DynamicsComponents.cpp @@ -54,23 +54,24 @@ void DynamicsComponents::allocate(uint32 nbComponentsToAllocate) { assert(newBuffer != nullptr); // New pointers to components data - Entity* newEntities = static_cast(newBuffer); - Vector3* newLinearVelocities = reinterpret_cast(newEntities + nbComponentsToAllocate); + Entity* newBodies = static_cast(newBuffer); + Vector3* newLinearVelocities = reinterpret_cast(newBodies + nbComponentsToAllocate); Vector3* newAngularVelocities = reinterpret_cast(newLinearVelocities + nbComponentsToAllocate); // If there was already components before if (mNbComponents > 0) { // Copy component data from the previous buffer to the new one - memcpy(newLinearVelocities, mLinearVelocities, mNbComponents * sizeof(Transform)); - memcpy(newAngularVelocities, mAngularVelocities, mNbComponents * sizeof(Entity)); + memcpy(newBodies, mBodies, mNbComponents * sizeof(Entity)); + memcpy(newLinearVelocities, mLinearVelocities, mNbComponents * sizeof(Vector3)); + memcpy(newAngularVelocities, mAngularVelocities, mNbComponents * sizeof(Vector3)); // Deallocate previous memory mMemoryAllocator.release(mBuffer, mNbAllocatedComponents * mComponentDataSize); } mBuffer = newBuffer; - mBodies = newEntities; + mBodies = newBodies; mLinearVelocities = newLinearVelocities; mAngularVelocities = newAngularVelocities; mNbAllocatedComponents = nbComponentsToAllocate; @@ -121,6 +122,9 @@ void DynamicsComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex) // Swap two components in the array void DynamicsComponents::swapComponents(uint32 index1, uint32 index2) { + assert(mMapEntityToComponentIndex[mBodies[index1]] == index1); + assert(mMapEntityToComponentIndex[mBodies[index2]] == index2); + // Copy component 1 data Entity entity1(mBodies[index1]); Vector3 linearVelocity1(mLinearVelocities[index1]);