[DEV] work with new ETK but no clean from STD

This commit is contained in:
Edouard DUPIN 2017-09-29 09:24:44 +02:00
parent d7470ad277
commit fc1a41f768
7 changed files with 51 additions and 85 deletions

View File

@ -8,7 +8,7 @@
#include <ephysics/collision/TriangleVertexArray.hpp> #include <ephysics/collision/TriangleVertexArray.hpp>
ephysics::TriangleVertexArray::TriangleVertexArray(const etk::Vector<vec3>& _vertices, etk::Vector<size_t> _triangles): ephysics::TriangleVertexArray::TriangleVertexArray(const etk::Vector<vec3>& _vertices, const etk::Vector<uint32_t>& _triangles):
m_vertices(_vertices), m_vertices(_vertices),
m_triangles(_triangles) { m_triangles(_triangles) {
@ -26,11 +26,11 @@ const etk::Vector<vec3>& ephysics::TriangleVertexArray::getVertices() const {
return m_vertices; return m_vertices;
} }
const etk::Vector<size_t>& ephysics::TriangleVertexArray::getIndices() const{ const etk::Vector<uint32_t>& ephysics::TriangleVertexArray::getIndices() const{
return m_triangles; return m_triangles;
} }
ephysics::Triangle ephysics::TriangleVertexArray::getTriangle(size_t _id) const { ephysics::Triangle ephysics::TriangleVertexArray::getTriangle(uint32_t _id) const {
ephysics::Triangle out; ephysics::Triangle out;
out[0] = m_vertices[m_triangles[_id*3]]; out[0] = m_vertices[m_triangles[_id*3]];
out[1] = m_vertices[m_triangles[_id*3+1]]; out[1] = m_vertices[m_triangles[_id*3+1]];

View File

@ -28,7 +28,7 @@ namespace ephysics {
class TriangleVertexArray { class TriangleVertexArray {
protected: protected:
etk::Vector<vec3> m_vertices; //!< Vertice list etk::Vector<vec3> m_vertices; //!< Vertice list
etk::Vector<size_t> m_triangles; //!< List of triangle (3 pos for each triangle) etk::Vector<uint32_t> m_triangles; //!< List of triangle (3 pos for each triangle)
public: public:
/** /**
* @brief Constructor * @brief Constructor
@ -36,7 +36,7 @@ namespace ephysics {
* @param[in] _triangles List of all linked points * @param[in] _triangles List of all linked points
*/ */
TriangleVertexArray(const etk::Vector<vec3>& _vertices, TriangleVertexArray(const etk::Vector<vec3>& _vertices,
etk::Vector<size_t> _triangles); const etk::Vector<uint32_t>& _triangles);
/** /**
* @brief Get the number of vertices * @brief Get the number of vertices
* @return Number of vertices * @return Number of vertices
@ -56,12 +56,12 @@ namespace ephysics {
* @brief Get The table of the triangle indice * @brief Get The table of the triangle indice
* @return reference on the triangle indice * @return reference on the triangle indice
*/ */
const etk::Vector<size_t>& getIndices() const; const etk::Vector<uint32_t>& getIndices() const;
/** /**
* @brief Get a triangle at the specific ID * @brief Get a triangle at the specific ID
* @return Buffer of 3 points * @return Buffer of 3 points
*/ */
ephysics::Triangle getTriangle(size_t _id) const; ephysics::Triangle getTriangle(uint32_t _id) const;
}; };

View File

@ -6,6 +6,7 @@
// Libraries // Libraries
#include <ephysics/engine/CollisionWorld.hpp> #include <ephysics/engine/CollisionWorld.hpp>
#include <ephysics/debug.hpp>
// Namespaces // Namespaces
using namespace ephysics; using namespace ephysics;
@ -14,7 +15,7 @@ using namespace std;
// Constructor // Constructor
CollisionWorld::CollisionWorld() CollisionWorld::CollisionWorld()
: m_collisionDetection(this, m_memoryAllocator), m_currentBodyID(0), : 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(); bodyindex bodyID = computeNextAvailableBodyID();
// Largest index cannot be used (it is used for invalid index) // Largest index cannot be used (it is used for invalid index)
EPHYSIC_ASSERT(bodyID < std::numeric_limits<ephysics::bodyindex>::max(), "index too big"); EPHY_ASSERT(bodyID < std::numeric_limits<ephysics::bodyindex>::max(), "index too big");
// Create the collision body // Create the collision body
CollisionBody* collisionBody = new (m_memoryAllocator.allocate(sizeof(CollisionBody))) CollisionBody* collisionBody = new (m_memoryAllocator.allocate(sizeof(CollisionBody)))
CollisionBody(transform, *this, bodyID); 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 // Add the collision body to the world
m_bodies.insert(collisionBody); m_bodies.add(collisionBody);
// Return the pointer to the rigid body // Return the pointer to the rigid body
return collisionBody; return collisionBody;
@ -74,7 +75,7 @@ void CollisionWorld::destroyCollisionBody(CollisionBody* collisionBody) {
collisionBody->~CollisionBody(); collisionBody->~CollisionBody();
// Remove the collision body from the list of bodies // 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 // Free the object from the memory allocator
m_memoryAllocator.release(collisionBody, sizeof(CollisionBody)); m_memoryAllocator.release(collisionBody, sizeof(CollisionBody));
@ -142,7 +143,7 @@ void CollisionWorld::testCollision(const ProxyShape* shape,
// Create the sets of shapes // Create the sets of shapes
etk::Set<uint32_t> shapes; etk::Set<uint32_t> shapes;
shapes.insert(shape->m_broadPhaseID); shapes.add(shape->m_broadPhaseID);
etk::Set<uint32_t> emptySet; etk::Set<uint32_t> emptySet;
// Perform the collision detection and report contacts // Perform the collision detection and report contacts
@ -164,9 +165,9 @@ void CollisionWorld::testCollision(const ProxyShape* shape1,
// Create the sets of shapes // Create the sets of shapes
etk::Set<uint32_t> shapes1; etk::Set<uint32_t> shapes1;
shapes1.insert(shape1->m_broadPhaseID); shapes1.add(shape1->m_broadPhaseID);
etk::Set<uint32_t> shapes2; etk::Set<uint32_t> shapes2;
shapes2.insert(shape2->m_broadPhaseID); shapes2.add(shape2->m_broadPhaseID);
// Perform the collision detection and report contacts // Perform the collision detection and report contacts
m_collisionDetection.testCollisionBetweenShapes(callback, shapes1, shapes2); m_collisionDetection.testCollisionBetweenShapes(callback, shapes1, shapes2);
@ -190,7 +191,7 @@ void CollisionWorld::testCollision(const CollisionBody* body,
// For each shape of the body // For each shape of the body
for (const ProxyShape* shape=body->getProxyShapesList(); shape != nullptr; for (const ProxyShape* shape=body->getProxyShapesList(); shape != nullptr;
shape = shape->getNext()) { shape = shape->getNext()) {
shapes1.insert(shape->m_broadPhaseID); shapes1.add(shape->m_broadPhaseID);
} }
etk::Set<uint32_t> emptySet; etk::Set<uint32_t> emptySet;
@ -216,13 +217,13 @@ void CollisionWorld::testCollision(const CollisionBody* body1,
etk::Set<uint32_t> shapes1; etk::Set<uint32_t> shapes1;
for (const ProxyShape* shape=body1->getProxyShapesList(); shape != nullptr; for (const ProxyShape* shape=body1->getProxyShapesList(); shape != nullptr;
shape = shape->getNext()) { shape = shape->getNext()) {
shapes1.insert(shape->m_broadPhaseID); shapes1.add(shape->m_broadPhaseID);
} }
etk::Set<uint32_t> shapes2; etk::Set<uint32_t> shapes2;
for (const ProxyShape* shape=body2->getProxyShapesList(); shape != nullptr; for (const ProxyShape* shape=body2->getProxyShapesList(); shape != nullptr;
shape = shape->getNext()) { shape = shape->getNext()) {
shapes2.insert(shape->m_broadPhaseID); shapes2.add(shape->m_broadPhaseID);
} }
// Perform the collision detection and report contacts // Perform the collision detection and report contacts

View File

@ -268,7 +268,7 @@ void DynamicsWorld::initVelocityArrays() {
for (it = m_rigidBodies.begin(); it != m_rigidBodies.end(); ++it) { for (it = m_rigidBodies.begin(); it != m_rigidBodies.end(); ++it) {
// Add the body int32_to the map // Add the body int32_to the map
m_mapBodyToConstrainedVelocityIndex.insert(etk::makePair(*it, indexBody)); m_mapBodyToConstrainedVelocityIndex.add(*it, indexBody);
indexBody++; indexBody++;
} }
} }
@ -441,8 +441,8 @@ RigidBody* DynamicsWorld::createRigidBody(const etk::Transform3D& transform) {
assert(rigidBody != nullptr); assert(rigidBody != nullptr);
// Add the rigid body to the physics world // Add the rigid body to the physics world
m_bodies.insert(rigidBody); m_bodies.add(rigidBody);
m_rigidBodies.insert(rigidBody); m_rigidBodies.add(rigidBody);
// Return the pointer to the rigid body // Return the pointer to the rigid body
return rigidBody; return rigidBody;
@ -473,8 +473,8 @@ void DynamicsWorld::destroyRigidBody(RigidBody* rigidBody) {
rigidBody->~RigidBody(); rigidBody->~RigidBody();
// Remove the rigid body from the list of rigid bodies // Remove the rigid body from the list of rigid bodies
m_bodies.erase(rigidBody); m_bodies.erase(m_bodies.find(rigidBody));
m_rigidBodies.erase(rigidBody); m_rigidBodies.erase(m_rigidBodies.find(rigidBody));
// Free the object from the memory allocator // Free the object from the memory allocator
m_memoryAllocator.release(rigidBody, sizeof(RigidBody)); m_memoryAllocator.release(rigidBody, sizeof(RigidBody));
@ -544,7 +544,7 @@ Joint* DynamicsWorld::createJoint(const JointInfo& jointInfo) {
} }
// Add the joint int32_to the world // 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 // Add the joint int32_to the joint list of the bodies involved in the joint
addJointToBody(newJoint); addJointToBody(newJoint);
@ -573,7 +573,7 @@ void DynamicsWorld::destroyJoint(Joint* joint) {
joint->getBody2()->setIsSleeping(false); joint->getBody2()->setIsSleeping(false);
// Remove the joint from the world // 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 // Remove the joint from the joint list of the bodies involved in the joint
joint->m_body1->removeJointFrom_jointsList(m_memoryAllocator, joint); joint->m_body1->removeJointFrom_jointsList(m_memoryAllocator, joint);
@ -862,7 +862,7 @@ void DynamicsWorld::testCollision(const ProxyShape* shape,
// Create the sets of shapes // Create the sets of shapes
etk::Set<uint32_t> shapes; etk::Set<uint32_t> shapes;
shapes.insert(shape->m_broadPhaseID); shapes.add(shape->m_broadPhaseID);
etk::Set<uint32_t> emptySet; etk::Set<uint32_t> emptySet;
// Perform the collision detection and report contacts // Perform the collision detection and report contacts
@ -883,9 +883,9 @@ void DynamicsWorld::testCollision(const ProxyShape* shape1,
// Create the sets of shapes // Create the sets of shapes
etk::Set<uint32_t> shapes1; etk::Set<uint32_t> shapes1;
shapes1.insert(shape1->m_broadPhaseID); shapes1.add(shape1->m_broadPhaseID);
etk::Set<uint32_t> shapes2; etk::Set<uint32_t> shapes2;
shapes2.insert(shape2->m_broadPhaseID); shapes2.add(shape2->m_broadPhaseID);
// Perform the collision detection and report contacts // Perform the collision detection and report contacts
m_collisionDetection.reportCollisionBetweenShapes(callback, shapes1, shapes2); m_collisionDetection.reportCollisionBetweenShapes(callback, shapes1, shapes2);
@ -908,7 +908,7 @@ void DynamicsWorld::testCollision(const CollisionBody* body,
// For each shape of the body // For each shape of the body
for (const ProxyShape* shape=body->getProxyShapesList(); shape != nullptr; for (const ProxyShape* shape=body->getProxyShapesList(); shape != nullptr;
shape = shape->getNext()) { shape = shape->getNext()) {
shapes1.insert(shape->m_broadPhaseID); shapes1.add(shape->m_broadPhaseID);
} }
etk::Set<uint32_t> emptySet; etk::Set<uint32_t> emptySet;
@ -933,13 +933,13 @@ void DynamicsWorld::testCollision(const CollisionBody* body1,
etk::Set<uint32_t> shapes1; etk::Set<uint32_t> shapes1;
for (const ProxyShape* shape=body1->getProxyShapesList(); shape != nullptr; for (const ProxyShape* shape=body1->getProxyShapesList(); shape != nullptr;
shape = shape->getNext()) { shape = shape->getNext()) {
shapes1.insert(shape->m_broadPhaseID); shapes1.add(shape->m_broadPhaseID);
} }
etk::Set<uint32_t> shapes2; etk::Set<uint32_t> shapes2;
for (const ProxyShape* shape=body2->getProxyShapesList(); shape != nullptr; for (const ProxyShape* shape=body2->getProxyShapesList(); shape != nullptr;
shape = shape->getNext()) { shape = shape->getNext()) {
shapes2.insert(shape->m_broadPhaseID); shapes2.add(shape->m_broadPhaseID);
} }
// Perform the collision detection and report contacts // Perform the collision detection and report contacts

View File

@ -6,62 +6,39 @@
// Libraries // Libraries
#include <ephysics/engine/Timer.hpp> #include <ephysics/engine/Timer.hpp>
#include <echrono/Clock.hpp>
// We want to use the ReactPhysics3D namespace
using namespace ephysics;
// Constructor ephysics::Timer::Timer(double timeStep) : m_timeStep(timeStep), m_isRunning(false) {
Timer::Timer(double timeStep) : m_timeStep(timeStep), m_isRunning(false) {
assert(timeStep > 0.0); assert(timeStep > 0.0);
} }
// Destructor ephysics::Timer::~Timer() {
Timer::~Timer() {
} }
// Return the current time of the system in seconds long double ephysics::Timer::getCurrentSystemTime() {
long double Timer::getCurrentSystemTime() { return (long double)(echrono::Clock::now().get()) / 1000000000.0;
#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
} }
double ephysics::Timer::getTimeStep() const {
// Return the timestep of the physics engine
double Timer::getTimeStep() const {
return m_timeStep; return m_timeStep;
} }
// Set the timestep of the physics engine void ephysics::Timer::setTimeStep(double timeStep) {
void Timer::setTimeStep(double timeStep) {
assert(timeStep > 0.0f); assert(timeStep > 0.0f);
m_timeStep = timeStep; m_timeStep = timeStep;
} }
// Return the current time long double ephysics::Timer::getPhysicsTime() const {
long double Timer::getPhysicsTime() const {
return m_lastUpdateTime; return m_lastUpdateTime;
} }
// Return if the timer is running bool ephysics::Timer::getIsRunning() const {
bool Timer::getIsRunning() const {
return m_isRunning; return m_isRunning;
} }
// Start the timer void ephysics::Timer::start() {
void Timer::start() {
if (!m_isRunning) { if (!m_isRunning) {
// Get the current system time // Get the current system time
m_lastUpdateTime = getCurrentSystemTime(); m_lastUpdateTime = getCurrentSystemTime();
@ -70,40 +47,28 @@ void Timer::start() {
} }
} }
// Stop the timer void ephysics::Timer::stop() {
void Timer::stop() {
m_isRunning = false; m_isRunning = false;
} }
// True if it's possible to take a new step bool ephysics::Timer::isPossibleToTakeStep() const {
bool Timer::isPossibleToTakeStep() const {
return (m_accumulator >= m_timeStep); return (m_accumulator >= m_timeStep);
} }
// Take a new step => update the timer by adding the timeStep value to the current time void ephysics::Timer::nextStep() {
void Timer::nextStep() {
assert(m_isRunning); assert(m_isRunning);
// Update the accumulator value // Update the accumulator value
m_accumulator -= m_timeStep; m_accumulator -= m_timeStep;
} }
// Compute the int32_terpolation factor float ephysics::Timer::computeInterpolationFactor() {
float Timer::computeInterpolationFactor() {
return (float(m_accumulator / m_timeStep)); return (float(m_accumulator / m_timeStep));
} }
// Compute the time since the last update() call and add it to the accumulator void ephysics::Timer::update() {
void Timer::update() {
long double currentTime = getCurrentSystemTime(); long double currentTime = getCurrentSystemTime();
m_deltaTime = currentTime - m_lastUpdateTime; m_deltaTime = currentTime - m_lastUpdateTime;
m_lastUpdateTime = currentTime; m_lastUpdateTime = currentTime;
m_accumulator += m_deltaTime; m_accumulator += m_deltaTime;
} }

View File

@ -7,8 +7,7 @@
// Libraries // Libraries
#include <ephysics/configuration.hpp> #include <ephysics/configuration.hpp>
#include <eechrono/echrono.hpp> #include <echrono/echrono.hpp>
namespace ephysics { namespace ephysics {
/** /**

View File

@ -156,7 +156,8 @@ def configure(target, my_module):
'm', 'm',
'elog', 'elog',
'etk', 'etk',
'ememory' 'ememory',
'echrono'
]) ])
# TODO: Remove this ... # TODO: Remove this ...
#my_module.add_flag('c++', "-Wno-overloaded-virtual", export=True) #my_module.add_flag('c++', "-Wno-overloaded-virtual", export=True)