mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 13:53:30 +02:00
add ThreadSafeDynamicsWorld pure virtual interface
This commit is contained in:
parent
66857b823f
commit
0117233ed4
2 changed files with 127 additions and 0 deletions
libraries/physics/src
83
libraries/physics/src/ThreadSafeDynamicsWorld.cpp
Normal file
83
libraries/physics/src/ThreadSafeDynamicsWorld.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Bullet Continuous Collision Detection and Physics Library
|
||||
* Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Copied and modified from btDiscreteDynamicsWorld.cpp by AndrewMeadows on 2014.11.12.
|
||||
* */
|
||||
|
||||
#include "ThreadSafeDynamicsWorld.h"
|
||||
|
||||
ThreadSafeDynamicsWorld::ThreadSafeDynamicsWorld(
|
||||
btDispatcher* dispatcher,
|
||||
btBroadphaseInterface* pairCache,
|
||||
btConstraintSolver* constraintSolver,
|
||||
btCollisionConfiguration* collisionConfiguration)
|
||||
: btDiscreteDynamicsWorld(dispatcher, pairCache, constraintSolver, collisionConfiguration) {
|
||||
}
|
||||
|
||||
void ThreadSafeDynamicsWorld::synchronizeMotionStates() {
|
||||
if (tryLock()) {
|
||||
btDiscreteDynamicsWorld::synchronizeMotionStates();
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
int ThreadSafeDynamicsWorld::stepSimulation( btScalar timeStep, int maxSubSteps, btScalar fixedTimeStep) {
|
||||
int subSteps = 0;
|
||||
if (maxSubSteps) {
|
||||
//fixed timestep with interpolation
|
||||
m_fixedTimeStep = fixedTimeStep;
|
||||
m_localTime += timeStep;
|
||||
if (m_localTime >= fixedTimeStep)
|
||||
{
|
||||
subSteps = int( m_localTime / fixedTimeStep);
|
||||
m_localTime -= subSteps * fixedTimeStep;
|
||||
}
|
||||
} else {
|
||||
//variable timestep
|
||||
fixedTimeStep = timeStep;
|
||||
m_localTime = m_latencyMotionStateInterpolation ? 0 : timeStep;
|
||||
m_fixedTimeStep = 0;
|
||||
if (btFuzzyZero(timeStep))
|
||||
{
|
||||
subSteps = 0;
|
||||
maxSubSteps = 0;
|
||||
} else
|
||||
{
|
||||
subSteps = 1;
|
||||
maxSubSteps = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*//process some debugging flags
|
||||
if (getDebugDrawer()) {
|
||||
btIDebugDraw* debugDrawer = getDebugDrawer ();
|
||||
gDisableDeactivation = (debugDrawer->getDebugMode() & btIDebugDraw::DBG_NoDeactivation) != 0;
|
||||
}*/
|
||||
if (subSteps) {
|
||||
//clamp the number of substeps, to prevent simulation grinding spiralling down to a halt
|
||||
int clampedSimulationSteps = (subSteps > maxSubSteps)? maxSubSteps : subSteps;
|
||||
|
||||
saveKinematicState(fixedTimeStep*clampedSimulationSteps);
|
||||
|
||||
applyGravity();
|
||||
|
||||
for (int i=0;i<clampedSimulationSteps;i++) {
|
||||
internalSingleStepSimulation(fixedTimeStep);
|
||||
}
|
||||
}
|
||||
|
||||
synchronizeMotionStates();
|
||||
clearForces();
|
||||
return subSteps;
|
||||
}
|
44
libraries/physics/src/ThreadSafeDynamicsWorld.h
Normal file
44
libraries/physics/src/ThreadSafeDynamicsWorld.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Bullet Continuous Collision Detection and Physics Library
|
||||
* Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Copied and modified from btDiscreteDynamicsWorld.h by AndrewMeadows on 2014.11.12.
|
||||
* */
|
||||
|
||||
#ifndef hifi_ThreadSafeDynamicsWorld_h
|
||||
#define hifi_ThreadSafeDynamicsWorld_h
|
||||
|
||||
#include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
|
||||
|
||||
ATTRIBUTE_ALIGNED16(class) ThreadSafeDynamicsWorld : public btDiscreteDynamicsWorld
|
||||
{
|
||||
public:
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
||||
ThreadSafeDynamicsWorld(
|
||||
btDispatcher* dispatcher,
|
||||
btBroadphaseInterface* pairCache,
|
||||
btConstraintSolver* constraintSolver,
|
||||
btCollisionConfiguration* collisionConfiguration);
|
||||
|
||||
// virtual overrides of btDiscreteDynamicsWorld
|
||||
int stepSimulation( btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
|
||||
void synchronizeMotionStates();
|
||||
|
||||
/// \return true if lock succeeds
|
||||
virtual bool tryLock() = 0;
|
||||
|
||||
virtual void unlock() = 0;
|
||||
};
|
||||
|
||||
#endif // hifi_ThreadSafeDynamicsWorld_h
|
Loading…
Reference in a new issue