diff --git a/ephysics/collision/TriangleVertexArray.cpp b/ephysics/collision/TriangleVertexArray.cpp index b6a3972..32ea667 100644 --- a/ephysics/collision/TriangleVertexArray.cpp +++ b/ephysics/collision/TriangleVertexArray.cpp @@ -8,7 +8,7 @@ #include -ephysics::TriangleVertexArray::TriangleVertexArray(const etk::Vector& _vertices, etk::Vector _triangles): +ephysics::TriangleVertexArray::TriangleVertexArray(const etk::Vector& _vertices, const etk::Vector& _triangles): m_vertices(_vertices), m_triangles(_triangles) { @@ -26,11 +26,11 @@ const etk::Vector& ephysics::TriangleVertexArray::getVertices() const { return m_vertices; } -const etk::Vector& ephysics::TriangleVertexArray::getIndices() const{ +const etk::Vector& ephysics::TriangleVertexArray::getIndices() const{ return m_triangles; } -ephysics::Triangle ephysics::TriangleVertexArray::getTriangle(size_t _id) const { +ephysics::Triangle ephysics::TriangleVertexArray::getTriangle(uint32_t _id) const { ephysics::Triangle out; out[0] = m_vertices[m_triangles[_id*3]]; out[1] = m_vertices[m_triangles[_id*3+1]]; diff --git a/ephysics/collision/TriangleVertexArray.hpp b/ephysics/collision/TriangleVertexArray.hpp index 7eb1b0f..9568dd0 100644 --- a/ephysics/collision/TriangleVertexArray.hpp +++ b/ephysics/collision/TriangleVertexArray.hpp @@ -28,7 +28,7 @@ namespace ephysics { class TriangleVertexArray { protected: etk::Vector m_vertices; //!< Vertice list - etk::Vector m_triangles; //!< List of triangle (3 pos for each triangle) + etk::Vector m_triangles; //!< List of triangle (3 pos for each triangle) public: /** * @brief Constructor @@ -36,7 +36,7 @@ namespace ephysics { * @param[in] _triangles List of all linked points */ TriangleVertexArray(const etk::Vector& _vertices, - etk::Vector _triangles); + const etk::Vector& _triangles); /** * @brief Get the number of vertices * @return Number of vertices @@ -56,12 +56,12 @@ namespace ephysics { * @brief Get The table of the triangle indice * @return reference on the triangle indice */ - const etk::Vector& getIndices() const; + const etk::Vector& getIndices() const; /** * @brief Get a triangle at the specific ID * @return Buffer of 3 points */ - ephysics::Triangle getTriangle(size_t _id) const; + ephysics::Triangle getTriangle(uint32_t _id) const; }; diff --git a/ephysics/engine/CollisionWorld.cpp b/ephysics/engine/CollisionWorld.cpp index d479f73..7a72ff9 100644 --- a/ephysics/engine/CollisionWorld.cpp +++ b/ephysics/engine/CollisionWorld.cpp @@ -6,6 +6,7 @@ // Libraries #include +#include // Namespaces using namespace ephysics; @@ -14,7 +15,7 @@ using namespace std; // Constructor CollisionWorld::CollisionWorld() : m_collisionDetection(this, m_memoryAllocator), m_currentBodyID(0), - m_eventListener(nullptrptr) { + m_eventListener(nullptr) { } @@ -43,16 +44,16 @@ CollisionBody* CollisionWorld::createCollisionBody(const etk::Transform3D& trans bodyindex bodyID = computeNextAvailableBodyID(); // Largest index cannot be used (it is used for invalid index) - EPHYSIC_ASSERT(bodyID < std::numeric_limits::max(), "index too big"); + EPHY_ASSERT(bodyID < std::numeric_limits::max(), "index too big"); // Create the collision body CollisionBody* collisionBody = new (m_memoryAllocator.allocate(sizeof(CollisionBody))) CollisionBody(transform, *this, bodyID); - EPHYSIC_ASSERT(collisionBody != nullptr, "empty Body collision"); + EPHY_ASSERT(collisionBody != nullptr, "empty Body collision"); // Add the collision body to the world - m_bodies.insert(collisionBody); + m_bodies.add(collisionBody); // Return the pointer to the rigid body return collisionBody; @@ -74,7 +75,7 @@ void CollisionWorld::destroyCollisionBody(CollisionBody* collisionBody) { collisionBody->~CollisionBody(); // Remove the collision body from the list of bodies - m_bodies.erase(collisionBody); + m_bodies.erase(m_bodies.find(collisionBody)); // Free the object from the memory allocator m_memoryAllocator.release(collisionBody, sizeof(CollisionBody)); @@ -142,7 +143,7 @@ void CollisionWorld::testCollision(const ProxyShape* shape, // Create the sets of shapes etk::Set shapes; - shapes.insert(shape->m_broadPhaseID); + shapes.add(shape->m_broadPhaseID); etk::Set emptySet; // Perform the collision detection and report contacts @@ -164,9 +165,9 @@ void CollisionWorld::testCollision(const ProxyShape* shape1, // Create the sets of shapes etk::Set shapes1; - shapes1.insert(shape1->m_broadPhaseID); + shapes1.add(shape1->m_broadPhaseID); etk::Set shapes2; - shapes2.insert(shape2->m_broadPhaseID); + shapes2.add(shape2->m_broadPhaseID); // Perform the collision detection and report contacts m_collisionDetection.testCollisionBetweenShapes(callback, shapes1, shapes2); @@ -190,7 +191,7 @@ void CollisionWorld::testCollision(const CollisionBody* body, // For each shape of the body for (const ProxyShape* shape=body->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { - shapes1.insert(shape->m_broadPhaseID); + shapes1.add(shape->m_broadPhaseID); } etk::Set emptySet; @@ -216,13 +217,13 @@ void CollisionWorld::testCollision(const CollisionBody* body1, etk::Set shapes1; for (const ProxyShape* shape=body1->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { - shapes1.insert(shape->m_broadPhaseID); + shapes1.add(shape->m_broadPhaseID); } etk::Set shapes2; for (const ProxyShape* shape=body2->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { - shapes2.insert(shape->m_broadPhaseID); + shapes2.add(shape->m_broadPhaseID); } // Perform the collision detection and report contacts diff --git a/ephysics/engine/DynamicsWorld.cpp b/ephysics/engine/DynamicsWorld.cpp index f887cfc..7f95a05 100644 --- a/ephysics/engine/DynamicsWorld.cpp +++ b/ephysics/engine/DynamicsWorld.cpp @@ -268,7 +268,7 @@ void DynamicsWorld::initVelocityArrays() { for (it = m_rigidBodies.begin(); it != m_rigidBodies.end(); ++it) { // Add the body int32_to the map - m_mapBodyToConstrainedVelocityIndex.insert(etk::makePair(*it, indexBody)); + m_mapBodyToConstrainedVelocityIndex.add(*it, indexBody); indexBody++; } } @@ -441,8 +441,8 @@ RigidBody* DynamicsWorld::createRigidBody(const etk::Transform3D& transform) { assert(rigidBody != nullptr); // Add the rigid body to the physics world - m_bodies.insert(rigidBody); - m_rigidBodies.insert(rigidBody); + m_bodies.add(rigidBody); + m_rigidBodies.add(rigidBody); // Return the pointer to the rigid body return rigidBody; @@ -473,8 +473,8 @@ void DynamicsWorld::destroyRigidBody(RigidBody* rigidBody) { rigidBody->~RigidBody(); // Remove the rigid body from the list of rigid bodies - m_bodies.erase(rigidBody); - m_rigidBodies.erase(rigidBody); + m_bodies.erase(m_bodies.find(rigidBody)); + m_rigidBodies.erase(m_rigidBodies.find(rigidBody)); // Free the object from the memory allocator m_memoryAllocator.release(rigidBody, sizeof(RigidBody)); @@ -544,7 +544,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) { } // Add the joint int32_to the world - m_joints.insert(newJoint); + m_joints.add(newJoint); // Add the joint int32_to the joint list of the bodies involved in the joint addJointToBody(newJoint); @@ -573,7 +573,7 @@ void DynamicsWorld::destroyJoint(Joint* joint) { joint->getBody2()->setIsSleeping(false); // Remove the joint from the world - m_joints.erase(joint); + m_joints.erase(m_joints.find(joint)); // Remove the joint from the joint list of the bodies involved in the joint joint->m_body1->removeJointFrom_jointsList(m_memoryAllocator, joint); @@ -862,7 +862,7 @@ void DynamicsWorld::testCollision(const ProxyShape* shape, // Create the sets of shapes etk::Set shapes; - shapes.insert(shape->m_broadPhaseID); + shapes.add(shape->m_broadPhaseID); etk::Set emptySet; // Perform the collision detection and report contacts @@ -883,9 +883,9 @@ void DynamicsWorld::testCollision(const ProxyShape* shape1, // Create the sets of shapes etk::Set shapes1; - shapes1.insert(shape1->m_broadPhaseID); + shapes1.add(shape1->m_broadPhaseID); etk::Set shapes2; - shapes2.insert(shape2->m_broadPhaseID); + shapes2.add(shape2->m_broadPhaseID); // Perform the collision detection and report contacts m_collisionDetection.reportCollisionBetweenShapes(callback, shapes1, shapes2); @@ -908,7 +908,7 @@ void DynamicsWorld::testCollision(const CollisionBody* body, // For each shape of the body for (const ProxyShape* shape=body->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { - shapes1.insert(shape->m_broadPhaseID); + shapes1.add(shape->m_broadPhaseID); } etk::Set emptySet; @@ -933,13 +933,13 @@ void DynamicsWorld::testCollision(const CollisionBody* body1, etk::Set shapes1; for (const ProxyShape* shape=body1->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { - shapes1.insert(shape->m_broadPhaseID); + shapes1.add(shape->m_broadPhaseID); } etk::Set shapes2; for (const ProxyShape* shape=body2->getProxyShapesList(); shape != nullptr; shape = shape->getNext()) { - shapes2.insert(shape->m_broadPhaseID); + shapes2.add(shape->m_broadPhaseID); } // Perform the collision detection and report contacts diff --git a/ephysics/engine/Timer.cpp b/ephysics/engine/Timer.cpp index 26e8eea..5acb77e 100644 --- a/ephysics/engine/Timer.cpp +++ b/ephysics/engine/Timer.cpp @@ -6,62 +6,39 @@ // Libraries #include +#include -// We want to use the ReactPhysics3D namespace -using namespace ephysics; -// Constructor -Timer::Timer(double timeStep) : m_timeStep(timeStep), m_isRunning(false) { +ephysics::Timer::Timer(double timeStep) : m_timeStep(timeStep), m_isRunning(false) { assert(timeStep > 0.0); } -// Destructor -Timer::~Timer() { - +ephysics::Timer::~Timer() { + } -// Return the current time of the system in seconds -long double Timer::getCurrentSystemTime() { - - #if defined(__TARGET_OS__Windows) - LARGE_INTEGER ticksPerSecond; - LARGE_INTEGER ticks; - QueryPerformanceFrequency(&ticksPerSecond); - QueryPerformanceCounter(&ticks); - return (long double(ticks.QuadPart) / long double(ticksPerSecond.QuadPart)); - #else - // Initialize the lastUpdateTime with the current time in seconds - timeval timeValue; - gettimeofday(&timeValue, NULL); - return (timeValue.tv_sec + (timeValue.tv_usec / 1000000.0)); - #endif +long double ephysics::Timer::getCurrentSystemTime() { + return (long double)(echrono::Clock::now().get()) / 1000000000.0; } - - -// Return the timestep of the physics engine -double Timer::getTimeStep() const { +double ephysics::Timer::getTimeStep() const { return m_timeStep; } -// Set the timestep of the physics engine -void Timer::setTimeStep(double timeStep) { +void ephysics::Timer::setTimeStep(double timeStep) { assert(timeStep > 0.0f); m_timeStep = timeStep; } -// Return the current time -long double Timer::getPhysicsTime() const { +long double ephysics::Timer::getPhysicsTime() const { return m_lastUpdateTime; } -// Return if the timer is running -bool Timer::getIsRunning() const { +bool ephysics::Timer::getIsRunning() const { return m_isRunning; } -// Start the timer -void Timer::start() { +void ephysics::Timer::start() { if (!m_isRunning) { // Get the current system time m_lastUpdateTime = getCurrentSystemTime(); @@ -70,40 +47,28 @@ void Timer::start() { } } -// Stop the timer -void Timer::stop() { +void ephysics::Timer::stop() { m_isRunning = false; } -// True if it's possible to take a new step -bool Timer::isPossibleToTakeStep() const { +bool ephysics::Timer::isPossibleToTakeStep() const { return (m_accumulator >= m_timeStep); } -// Take a new step => update the timer by adding the timeStep value to the current time -void Timer::nextStep() { +void ephysics::Timer::nextStep() { assert(m_isRunning); - // Update the accumulator value m_accumulator -= m_timeStep; } -// Compute the int32_terpolation factor -float Timer::computeInterpolationFactor() { +float ephysics::Timer::computeInterpolationFactor() { return (float(m_accumulator / m_timeStep)); } -// Compute the time since the last update() call and add it to the accumulator -void Timer::update() { +void ephysics::Timer::update() { long double currentTime = getCurrentSystemTime(); m_deltaTime = currentTime - m_lastUpdateTime; m_lastUpdateTime = currentTime; m_accumulator += m_deltaTime; } - - - - - - diff --git a/ephysics/engine/Timer.hpp b/ephysics/engine/Timer.hpp index 8a3b70d..aac182f 100644 --- a/ephysics/engine/Timer.hpp +++ b/ephysics/engine/Timer.hpp @@ -7,8 +7,7 @@ // Libraries #include -#include - +#include namespace ephysics { /** diff --git a/lutin_ephysics.py b/lutin_ephysics.py index ce618d4..f5c5a59 100644 --- a/lutin_ephysics.py +++ b/lutin_ephysics.py @@ -156,7 +156,8 @@ def configure(target, my_module): 'm', 'elog', 'etk', - 'ememory' + 'ememory', + 'echrono' ]) # TODO: Remove this ... #my_module.add_flag('c++', "-Wno-overloaded-virtual", export=True)