mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 19:33:01 +02:00
expose physics simulation stats to Test JS API
This commit is contained in:
parent
4540e9e483
commit
2538204b1e
7 changed files with 43 additions and 5 deletions
|
@ -3222,8 +3222,6 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Application::keyReleaseEvent(QKeyEvent* event) {
|
void Application::keyReleaseEvent(QKeyEvent* event) {
|
||||||
_keysPressed.remove(event->key());
|
_keysPressed.remove(event->key());
|
||||||
|
|
||||||
|
@ -7506,4 +7504,9 @@ void Application::setAvatarOverrideUrl(const QUrl& url, bool save) {
|
||||||
_avatarOverrideUrl = url;
|
_avatarOverrideUrl = url;
|
||||||
_saveAvatarOverrideUrl = save;
|
_saveAvatarOverrideUrl = save;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::saveNextPhysicsStats(QString filename) {
|
||||||
|
_physicsEngine->saveNextPhysicsStats(filename);
|
||||||
|
}
|
||||||
|
|
||||||
#include "Application.moc"
|
#include "Application.moc"
|
||||||
|
|
|
@ -280,6 +280,7 @@ public:
|
||||||
void clearAvatarOverrideUrl() { _avatarOverrideUrl = QUrl(); _saveAvatarOverrideUrl = false; }
|
void clearAvatarOverrideUrl() { _avatarOverrideUrl = QUrl(); _saveAvatarOverrideUrl = false; }
|
||||||
QUrl getAvatarOverrideUrl() { return _avatarOverrideUrl; }
|
QUrl getAvatarOverrideUrl() { return _avatarOverrideUrl; }
|
||||||
bool getSaveAvatarOverrideUrl() { return _saveAvatarOverrideUrl; }
|
bool getSaveAvatarOverrideUrl() { return _saveAvatarOverrideUrl; }
|
||||||
|
void saveNextPhysicsStats(QString filename);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void svoImportRequested(const QString& url);
|
void svoImportRequested(const QString& url);
|
||||||
|
@ -432,6 +433,7 @@ private slots:
|
||||||
|
|
||||||
void handleSandboxStatus(QNetworkReply* reply);
|
void handleSandboxStatus(QNetworkReply* reply);
|
||||||
void switchDisplayMode();
|
void switchDisplayMode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void initDisplay();
|
static void initDisplay();
|
||||||
void init();
|
void init();
|
||||||
|
|
|
@ -141,6 +141,10 @@ void TestScriptingInterface::endTraceEvent(QString name) {
|
||||||
tracing::traceEvent(trace_test(), name, tracing::DurationEnd);
|
tracing::traceEvent(trace_test(), name, tracing::DurationEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestScriptingInterface::savePhysicsSimulationStats(QString filename) {
|
||||||
|
qApp->saveNextPhysicsStats(filename);
|
||||||
|
}
|
||||||
|
|
||||||
void TestScriptingInterface::profileRange(const QString& name, QScriptValue fn) {
|
void TestScriptingInterface::profileRange(const QString& name, QScriptValue fn) {
|
||||||
PROFILE_RANGE(script, name);
|
PROFILE_RANGE(script, name);
|
||||||
fn.call();
|
fn.call();
|
||||||
|
|
|
@ -71,6 +71,11 @@ public slots:
|
||||||
|
|
||||||
void endTraceEvent(QString name);
|
void endTraceEvent(QString name);
|
||||||
|
|
||||||
|
/**jsdoc
|
||||||
|
* Write detailed timing stats of next physics stepSimulation() to filename
|
||||||
|
*/
|
||||||
|
void savePhysicsSimulationStats(QString filename);
|
||||||
|
|
||||||
Q_INVOKABLE void profileRange(const QString& name, QScriptValue function);
|
Q_INVOKABLE void profileRange(const QString& name, QScriptValue function);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
|
#include <Profile.h>
|
||||||
|
|
||||||
#include "CharacterController.h"
|
#include "CharacterController.h"
|
||||||
#include "ObjectMotionState.h"
|
#include "ObjectMotionState.h"
|
||||||
|
@ -294,6 +295,7 @@ void PhysicsEngine::stepSimulation() {
|
||||||
float timeStep = btMin(dt, MAX_TIMESTEP);
|
float timeStep = btMin(dt, MAX_TIMESTEP);
|
||||||
|
|
||||||
if (_myAvatarController) {
|
if (_myAvatarController) {
|
||||||
|
DETAILED_PROFILE_RANGE(simulation_physics, "avatarController");
|
||||||
BT_PROFILE("avatarController");
|
BT_PROFILE("avatarController");
|
||||||
// TODO: move this stuff outside and in front of stepSimulation, because
|
// TODO: move this stuff outside and in front of stepSimulation, because
|
||||||
// the updateShapeIfNecessary() call needs info from MyAvatar and should
|
// the updateShapeIfNecessary() call needs info from MyAvatar and should
|
||||||
|
@ -465,6 +467,7 @@ void PhysicsEngine::doOwnershipInfection(const btCollisionObject* objectA, const
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsEngine::updateContactMap() {
|
void PhysicsEngine::updateContactMap() {
|
||||||
|
DETAILED_PROFILE_RANGE(simulation_physics, "updateContactMap");
|
||||||
BT_PROFILE("updateContactMap");
|
BT_PROFILE("updateContactMap");
|
||||||
++_numContactFrames;
|
++_numContactFrames;
|
||||||
|
|
||||||
|
@ -582,10 +585,20 @@ void PhysicsEngine::dumpStatsIfNecessary() {
|
||||||
if (_dumpNextStats) {
|
if (_dumpNextStats) {
|
||||||
_dumpNextStats = false;
|
_dumpNextStats = false;
|
||||||
CProfileManager::Increment_Frame_Counter();
|
CProfileManager::Increment_Frame_Counter();
|
||||||
|
if (_saveNextStats) {
|
||||||
|
_saveNextStats = false;
|
||||||
|
printPerformanceStatsToFile(_statsFilename);
|
||||||
|
}
|
||||||
CProfileManager::dumpAll();
|
CProfileManager::dumpAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicsEngine::saveNextPhysicsStats(QString filename) {
|
||||||
|
_saveNextStats = true;
|
||||||
|
_dumpNextStats = true;
|
||||||
|
_statsFilename = filename;
|
||||||
|
}
|
||||||
|
|
||||||
// Bullet collision flags are as follows:
|
// Bullet collision flags are as follows:
|
||||||
// CF_STATIC_OBJECT= 1,
|
// CF_STATIC_OBJECT= 1,
|
||||||
// CF_KINEMATIC_OBJECT= 2,
|
// CF_KINEMATIC_OBJECT= 2,
|
||||||
|
|
|
@ -77,6 +77,9 @@ public:
|
||||||
/// \brief prints timings for last frame if stats have been requested.
|
/// \brief prints timings for last frame if stats have been requested.
|
||||||
void dumpStatsIfNecessary();
|
void dumpStatsIfNecessary();
|
||||||
|
|
||||||
|
/// \brief saves timings for last frame in filename
|
||||||
|
void saveNextPhysicsStats(QString filename);
|
||||||
|
|
||||||
/// \param offset position of simulation origin in domain-frame
|
/// \param offset position of simulation origin in domain-frame
|
||||||
void setOriginOffset(const glm::vec3& offset) { _originOffset = offset; }
|
void setOriginOffset(const glm::vec3& offset) { _originOffset = offset; }
|
||||||
|
|
||||||
|
@ -116,6 +119,7 @@ private:
|
||||||
QHash<QUuid, EntityDynamicPointer> _objectDynamics;
|
QHash<QUuid, EntityDynamicPointer> _objectDynamics;
|
||||||
QHash<btRigidBody*, QSet<QUuid>> _objectDynamicsByBody;
|
QHash<btRigidBody*, QSet<QUuid>> _objectDynamicsByBody;
|
||||||
std::set<btRigidBody*> _activeStaticBodies;
|
std::set<btRigidBody*> _activeStaticBodies;
|
||||||
|
QString _statsFilename;
|
||||||
|
|
||||||
glm::vec3 _originOffset;
|
glm::vec3 _originOffset;
|
||||||
|
|
||||||
|
@ -124,8 +128,9 @@ private:
|
||||||
uint32_t _numContactFrames = 0;
|
uint32_t _numContactFrames = 0;
|
||||||
uint32_t _numSubsteps;
|
uint32_t _numSubsteps;
|
||||||
|
|
||||||
bool _dumpNextStats = false;
|
bool _dumpNextStats { false };
|
||||||
bool _hasOutgoingChanges = false;
|
bool _saveNextStats { false };
|
||||||
|
bool _hasOutgoingChanges { false };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <LinearMath/btQuickprof.h>
|
#include <LinearMath/btQuickprof.h>
|
||||||
|
|
||||||
#include "ThreadSafeDynamicsWorld.h"
|
#include "ThreadSafeDynamicsWorld.h"
|
||||||
|
#include "Profile.h"
|
||||||
|
|
||||||
ThreadSafeDynamicsWorld::ThreadSafeDynamicsWorld(
|
ThreadSafeDynamicsWorld::ThreadSafeDynamicsWorld(
|
||||||
btDispatcher* dispatcher,
|
btDispatcher* dispatcher,
|
||||||
|
@ -29,6 +30,7 @@ ThreadSafeDynamicsWorld::ThreadSafeDynamicsWorld(
|
||||||
|
|
||||||
int ThreadSafeDynamicsWorld::stepSimulationWithSubstepCallback(btScalar timeStep, int maxSubSteps,
|
int ThreadSafeDynamicsWorld::stepSimulationWithSubstepCallback(btScalar timeStep, int maxSubSteps,
|
||||||
btScalar fixedTimeStep, SubStepCallback onSubStep) {
|
btScalar fixedTimeStep, SubStepCallback onSubStep) {
|
||||||
|
DETAILED_PROFILE_RANGE(simulation_physics, "stepWithCB");
|
||||||
BT_PROFILE("stepSimulationWithSubstepCallback");
|
BT_PROFILE("stepSimulationWithSubstepCallback");
|
||||||
int subSteps = 0;
|
int subSteps = 0;
|
||||||
if (maxSubSteps) {
|
if (maxSubSteps) {
|
||||||
|
@ -68,11 +70,13 @@ int ThreadSafeDynamicsWorld::stepSimulationWithSubstepCallback(btScalar timeStep
|
||||||
saveKinematicState(fixedTimeStep*clampedSimulationSteps);
|
saveKinematicState(fixedTimeStep*clampedSimulationSteps);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
DETAILED_PROFILE_RANGE(simulation_physics, "applyGravity");
|
||||||
BT_PROFILE("applyGravity");
|
BT_PROFILE("applyGravity");
|
||||||
applyGravity();
|
applyGravity();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0;i<clampedSimulationSteps;i++) {
|
for (int i=0;i<clampedSimulationSteps;i++) {
|
||||||
|
DETAILED_PROFILE_RANGE(simulation_physics, "substep");
|
||||||
internalSingleStepSimulation(fixedTimeStep);
|
internalSingleStepSimulation(fixedTimeStep);
|
||||||
onSubStep();
|
onSubStep();
|
||||||
}
|
}
|
||||||
|
@ -118,7 +122,8 @@ void ThreadSafeDynamicsWorld::synchronizeMotionState(btRigidBody* body) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadSafeDynamicsWorld::synchronizeMotionStates() {
|
void ThreadSafeDynamicsWorld::synchronizeMotionStates() {
|
||||||
BT_PROFILE("synchronizeMotionStates");
|
DETAILED_PROFILE_RANGE(simulation_physics, "syncMotionStates");
|
||||||
|
BT_PROFILE("syncMotionStates");
|
||||||
_changedMotionStates.clear();
|
_changedMotionStates.clear();
|
||||||
|
|
||||||
// NOTE: m_synchronizeAllMotionStates is 'false' by default for optimization.
|
// NOTE: m_synchronizeAllMotionStates is 'false' by default for optimization.
|
||||||
|
@ -161,6 +166,7 @@ void ThreadSafeDynamicsWorld::saveKinematicState(btScalar timeStep) {
|
||||||
///would like to iterate over m_nonStaticRigidBodies, but unfortunately old API allows
|
///would like to iterate over m_nonStaticRigidBodies, but unfortunately old API allows
|
||||||
///to switch status _after_ adding kinematic objects to the world
|
///to switch status _after_ adding kinematic objects to the world
|
||||||
///fix it for Bullet 3.x release
|
///fix it for Bullet 3.x release
|
||||||
|
DETAILED_PROFILE_RANGE(simulation_physics, "saveKinematicState");
|
||||||
BT_PROFILE("saveKinematicState");
|
BT_PROFILE("saveKinematicState");
|
||||||
for (int i=0;i<m_collisionObjects.size();i++)
|
for (int i=0;i<m_collisionObjects.size();i++)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue