Rename BodyComponents class to CollisionBodyComponents

This commit is contained in:
Daniel Chappuis 2019-07-15 17:44:45 +02:00
parent 569964e365
commit b93ba5c476
8 changed files with 37 additions and 37 deletions

View File

@ -141,7 +141,7 @@ SET (REACTPHYSICS3D_HEADERS
"src/engine/Timer.h" "src/engine/Timer.h"
"src/systems/BroadPhaseSystem.h" "src/systems/BroadPhaseSystem.h"
"src/components/Components.h" "src/components/Components.h"
"src/components/BodyComponents.h" "src/components/CollisionBodyComponents.h"
"src/components/TransformComponents.h" "src/components/TransformComponents.h"
"src/components/ProxyShapeComponents.h" "src/components/ProxyShapeComponents.h"
"src/components/DynamicsComponents.h" "src/components/DynamicsComponents.h"
@ -232,7 +232,7 @@ SET (REACTPHYSICS3D_SOURCES
"src/engine/EntityManager.cpp" "src/engine/EntityManager.cpp"
"src/systems/BroadPhaseSystem.cpp" "src/systems/BroadPhaseSystem.cpp"
"src/components/Components.cpp" "src/components/Components.cpp"
"src/components/BodyComponents.cpp" "src/components/CollisionBodyComponents.cpp"
"src/components/TransformComponents.cpp" "src/components/TransformComponents.cpp"
"src/components/ProxyShapeComponents.cpp" "src/components/ProxyShapeComponents.cpp"
"src/components/DynamicsComponents.cpp" "src/components/DynamicsComponents.cpp"

View File

@ -24,7 +24,7 @@
********************************************************************************/ ********************************************************************************/
// Libraries // Libraries
#include "BodyComponents.h" #include "CollisionBodyComponents.h"
#include "engine/EntityManager.h" #include "engine/EntityManager.h"
#include <cassert> #include <cassert>
#include <random> #include <random>
@ -33,7 +33,7 @@
using namespace reactphysics3d; using namespace reactphysics3d;
// Constructor // Constructor
BodyComponents::BodyComponents(MemoryAllocator& allocator) CollisionBodyComponents::CollisionBodyComponents(MemoryAllocator& allocator)
:Components(allocator, sizeof(Entity) + sizeof(CollisionBody*) + sizeof(List<Entity>) + :Components(allocator, sizeof(Entity) + sizeof(CollisionBody*) + sizeof(List<Entity>) +
sizeof(bool) + sizeof(bool) + sizeof(bool) + sizeof(decimal) + sizeof(bool) + sizeof(bool) + sizeof(bool) + sizeof(decimal) +
sizeof(void*)) { sizeof(void*)) {
@ -43,7 +43,7 @@ BodyComponents::BodyComponents(MemoryAllocator& allocator)
} }
// Allocate memory for a given number of components // Allocate memory for a given number of components
void BodyComponents::allocate(uint32 nbComponentsToAllocate) { void CollisionBodyComponents::allocate(uint32 nbComponentsToAllocate) {
assert(nbComponentsToAllocate > mNbAllocatedComponents); assert(nbComponentsToAllocate > mNbAllocatedComponents);
@ -94,7 +94,7 @@ void BodyComponents::allocate(uint32 nbComponentsToAllocate) {
} }
// Add a component // Add a component
void BodyComponents::addComponent(Entity bodyEntity, bool isSleeping, const BodyComponent& component) { void CollisionBodyComponents::addComponent(Entity bodyEntity, bool isSleeping, const BodyComponent& component) {
// Prepare to add new component (allocate memory if necessary and compute insertion index) // Prepare to add new component (allocate memory if necessary and compute insertion index)
uint32 index = prepareAddComponent(isSleeping); uint32 index = prepareAddComponent(isSleeping);
@ -120,7 +120,7 @@ void BodyComponents::addComponent(Entity bodyEntity, bool isSleeping, const Body
// Move a component from a source to a destination index in the components array // Move a component from a source to a destination index in the components array
// The destination location must contain a constructed object // The destination location must contain a constructed object
void BodyComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex) { void CollisionBodyComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex) {
const Entity entity = mBodiesEntities[srcIndex]; const Entity entity = mBodiesEntities[srcIndex];
@ -146,7 +146,7 @@ void BodyComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex) {
} }
// Swap two components in the array // Swap two components in the array
void BodyComponents::swapComponents(uint32 index1, uint32 index2) { void CollisionBodyComponents::swapComponents(uint32 index1, uint32 index2) {
// Copy component 1 data // Copy component 1 data
Entity entity1(mBodiesEntities[index1]); Entity entity1(mBodiesEntities[index1]);
@ -181,7 +181,7 @@ void BodyComponents::swapComponents(uint32 index1, uint32 index2) {
} }
// Destroy a component at a given index // Destroy a component at a given index
void BodyComponents::destroyComponent(uint32 index) { void CollisionBodyComponents::destroyComponent(uint32 index) {
Components::destroyComponent(index); Components::destroyComponent(index);

View File

@ -40,12 +40,12 @@ class MemoryAllocator;
class EntityManager; class EntityManager;
class CollisionBody; class CollisionBody;
// Class BodyComponents // Class CollisionBodyComponents
/** /**
* This class represent the component of the ECS that contains data about a physics body. * This class represent the component of the ECS that contains data about a collision body.
* The components of the sleeping entities (bodies) are always stored at the end of the array. * The components of the sleeping entities (bodies) are always stored at the end of the array.
*/ */
class BodyComponents : public Components { class CollisionBodyComponents : public Components {
private: private:
@ -105,10 +105,10 @@ class BodyComponents : public Components {
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //
/// Constructor /// Constructor
BodyComponents(MemoryAllocator& allocator); CollisionBodyComponents(MemoryAllocator& allocator);
/// Destructor /// Destructor
virtual ~BodyComponents() override = default; virtual ~CollisionBodyComponents() override = default;
/// Add a component /// Add a component
void addComponent(Entity bodyEntity, bool isSleeping, const BodyComponent& component); void addComponent(Entity bodyEntity, bool isSleeping, const BodyComponent& component);
@ -157,7 +157,7 @@ class BodyComponents : public Components {
}; };
// Add a proxy-shape to a body component // Add a proxy-shape to a body component
inline void BodyComponents::addProxyShapeToBody(Entity bodyEntity, Entity proxyShapeEntity) { inline void CollisionBodyComponents::addProxyShapeToBody(Entity bodyEntity, Entity proxyShapeEntity) {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -165,7 +165,7 @@ inline void BodyComponents::addProxyShapeToBody(Entity bodyEntity, Entity proxyS
} }
// Set the transform of an entity // Set the transform of an entity
inline void BodyComponents::removeProxyShapeFromBody(Entity bodyEntity, Entity proxyShapeEntity) { inline void CollisionBodyComponents::removeProxyShapeFromBody(Entity bodyEntity, Entity proxyShapeEntity) {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -173,7 +173,7 @@ inline void BodyComponents::removeProxyShapeFromBody(Entity bodyEntity, Entity p
} }
// Return a pointer to a body // Return a pointer to a body
inline CollisionBody *BodyComponents::getBody(Entity bodyEntity) { inline CollisionBody *CollisionBodyComponents::getBody(Entity bodyEntity) {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -181,7 +181,7 @@ inline CollisionBody *BodyComponents::getBody(Entity bodyEntity) {
} }
// Return the list of proxy-shapes of a body // Return the list of proxy-shapes of a body
inline const List<Entity>& BodyComponents::getProxyShapes(Entity bodyEntity) const { inline const List<Entity>& CollisionBodyComponents::getProxyShapes(Entity bodyEntity) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -189,7 +189,7 @@ inline const List<Entity>& BodyComponents::getProxyShapes(Entity bodyEntity) con
} }
// Return true if the body is allowed to sleep // Return true if the body is allowed to sleep
inline bool BodyComponents::getIsAllowedToSleep(Entity bodyEntity) const { inline bool CollisionBodyComponents::getIsAllowedToSleep(Entity bodyEntity) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -197,7 +197,7 @@ inline bool BodyComponents::getIsAllowedToSleep(Entity bodyEntity) const {
} }
// Set the value to know if the body is allowed to sleep // Set the value to know if the body is allowed to sleep
inline void BodyComponents::setIsAllowedToSleep(Entity bodyEntity, bool isAllowedToSleep) const { inline void CollisionBodyComponents::setIsAllowedToSleep(Entity bodyEntity, bool isAllowedToSleep) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -205,7 +205,7 @@ inline void BodyComponents::setIsAllowedToSleep(Entity bodyEntity, bool isAllowe
} }
// Return true if the body is active // Return true if the body is active
inline bool BodyComponents::getIsActive(Entity bodyEntity) const { inline bool CollisionBodyComponents::getIsActive(Entity bodyEntity) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -213,7 +213,7 @@ inline bool BodyComponents::getIsActive(Entity bodyEntity) const {
} }
// Set the value to know if the body is active // Set the value to know if the body is active
inline void BodyComponents::setIsActive(Entity bodyEntity, bool isActive) const { inline void CollisionBodyComponents::setIsActive(Entity bodyEntity, bool isActive) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -221,7 +221,7 @@ inline void BodyComponents::setIsActive(Entity bodyEntity, bool isActive) const
} }
// Return true if the body is sleeping // Return true if the body is sleeping
inline bool BodyComponents::getIsSleeping(Entity bodyEntity) const { inline bool CollisionBodyComponents::getIsSleeping(Entity bodyEntity) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -229,7 +229,7 @@ inline bool BodyComponents::getIsSleeping(Entity bodyEntity) const {
} }
// Set the value to know if the body is sleeping // Set the value to know if the body is sleeping
inline void BodyComponents::setIsSleeping(Entity bodyEntity, bool isSleeping) const { inline void CollisionBodyComponents::setIsSleeping(Entity bodyEntity, bool isSleeping) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -237,7 +237,7 @@ inline void BodyComponents::setIsSleeping(Entity bodyEntity, bool isSleeping) co
} }
// Return the sleep time // Return the sleep time
inline decimal BodyComponents::getSleepTime(Entity bodyEntity) const { inline decimal CollisionBodyComponents::getSleepTime(Entity bodyEntity) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -245,7 +245,7 @@ inline decimal BodyComponents::getSleepTime(Entity bodyEntity) const {
} }
// Set the sleep time // Set the sleep time
inline void BodyComponents::setSleepTime(Entity bodyEntity, decimal sleepTime) const { inline void CollisionBodyComponents::setSleepTime(Entity bodyEntity, decimal sleepTime) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -253,7 +253,7 @@ inline void BodyComponents::setSleepTime(Entity bodyEntity, decimal sleepTime) c
} }
// Return the user data associated with the body // Return the user data associated with the body
inline void* BodyComponents::getUserData(Entity bodyEntity) const { inline void* CollisionBodyComponents::getUserData(Entity bodyEntity) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
@ -261,7 +261,7 @@ inline void* BodyComponents::getUserData(Entity bodyEntity) const {
} }
// Set the user data associated with the body // Set the user data associated with the body
inline void BodyComponents::setUserData(Entity bodyEntity, void* userData) const { inline void CollisionBodyComponents::setUserData(Entity bodyEntity, void* userData) const {
assert(mMapEntityToComponentIndex.containsKey(bodyEntity)); assert(mMapEntityToComponentIndex.containsKey(bodyEntity));

View File

@ -157,7 +157,7 @@ CollisionBody* CollisionWorld::createCollisionBody(const Transform& transform) {
assert(collisionBody != nullptr); assert(collisionBody != nullptr);
// Add the components // Add the components
BodyComponents::BodyComponent bodyComponent(collisionBody); CollisionBodyComponents::BodyComponent bodyComponent(collisionBody);
mBodyComponents.addComponent(entity, false, bodyComponent); mBodyComponents.addComponent(entity, false, bodyComponent);
// Add the collision body to the world // Add the collision body to the world

View File

@ -33,7 +33,7 @@
#include "constraint/Joint.h" #include "constraint/Joint.h"
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "engine/EntityManager.h" #include "engine/EntityManager.h"
#include "components/BodyComponents.h" #include "components/CollisionBodyComponents.h"
#include "components/TransformComponents.h" #include "components/TransformComponents.h"
#include "components/ProxyShapeComponents.h" #include "components/ProxyShapeComponents.h"
#include "components/DynamicsComponents.h" #include "components/DynamicsComponents.h"
@ -77,7 +77,7 @@ class CollisionWorld {
EntityManager mEntityManager; EntityManager mEntityManager;
/// Body Components /// Body Components
BodyComponents mBodyComponents; CollisionBodyComponents mBodyComponents;
/// Transform Components /// Transform Components
TransformComponents mTransformComponents; TransformComponents mTransformComponents;

View File

@ -30,7 +30,7 @@
#include "constraint/ContactPoint.h" #include "constraint/ContactPoint.h"
#include "utils/Profiler.h" #include "utils/Profiler.h"
#include "engine/Island.h" #include "engine/Island.h"
#include "components/BodyComponents.h" #include "components/CollisionBodyComponents.h"
#include "components/DynamicsComponents.h" #include "components/DynamicsComponents.h"
#include "components/ProxyShapeComponents.h" #include "components/ProxyShapeComponents.h"
#include "collision/ContactManifold.h" #include "collision/ContactManifold.h"
@ -44,7 +44,7 @@ const decimal ContactSolver::BETA_SPLIT_IMPULSE = decimal(0.2);
const decimal ContactSolver::SLOP = decimal(0.01); const decimal ContactSolver::SLOP = decimal(0.01);
// Constructor // Constructor
ContactSolver::ContactSolver(MemoryManager& memoryManager, Islands& islands, BodyComponents& bodyComponents, DynamicsComponents& dynamicsComponents, ContactSolver::ContactSolver(MemoryManager& memoryManager, Islands& islands, CollisionBodyComponents& bodyComponents, DynamicsComponents& dynamicsComponents,
ProxyShapeComponents& proxyShapeComponents, const WorldSettings& worldSettings) ProxyShapeComponents& proxyShapeComponents, const WorldSettings& worldSettings)
:mMemoryManager(memoryManager), mContactConstraints(nullptr), mContactPoints(nullptr), :mMemoryManager(memoryManager), mContactConstraints(nullptr), mContactPoints(nullptr),
mIslands(islands), mAllContactManifolds(nullptr), mAllContactPoints(nullptr), mBodyComponents(bodyComponents), mIslands(islands), mAllContactManifolds(nullptr), mAllContactPoints(nullptr), mBodyComponents(bodyComponents),

View File

@ -43,7 +43,7 @@ class MemoryManager;
class Profiler; class Profiler;
class Island; class Island;
class RigidBody; class RigidBody;
class BodyComponents; class CollisionBodyComponents;
class DynamicsComponents; class DynamicsComponents;
class ProxyShapeComponents; class ProxyShapeComponents;
@ -310,7 +310,7 @@ class ContactSolver {
List<ContactPoint>* mAllContactPoints; List<ContactPoint>* mAllContactPoints;
/// Reference to the body components /// Reference to the body components
BodyComponents& mBodyComponents; CollisionBodyComponents& mBodyComponents;
/// Reference to the dynamics components /// Reference to the dynamics components
DynamicsComponents& mDynamicsComponents; DynamicsComponents& mDynamicsComponents;
@ -359,7 +359,7 @@ class ContactSolver {
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //
/// Constructor /// Constructor
ContactSolver(MemoryManager& memoryManager, Islands& islands, BodyComponents& bodyComponents, ContactSolver(MemoryManager& memoryManager, Islands& islands, CollisionBodyComponents& bodyComponents,
DynamicsComponents& dynamicsComponents, ProxyShapeComponents& proxyShapeComponents, DynamicsComponents& dynamicsComponents, ProxyShapeComponents& proxyShapeComponents,
const WorldSettings& worldSettings); const WorldSettings& worldSettings);

View File

@ -384,7 +384,7 @@ RigidBody* DynamicsWorld::createRigidBody(const Transform& transform) {
sizeof(RigidBody))) RigidBody(transform, *this, entity); sizeof(RigidBody))) RigidBody(transform, *this, entity);
assert(rigidBody != nullptr); assert(rigidBody != nullptr);
BodyComponents::BodyComponent bodyComponent(rigidBody); CollisionBodyComponents::BodyComponent bodyComponent(rigidBody);
mBodyComponents.addComponent(entity, false, bodyComponent); mBodyComponents.addComponent(entity, false, bodyComponent);
// Add the rigid body to the physics world // Add the rigid body to the physics world