mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01: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) {
|
||||
_keysPressed.remove(event->key());
|
||||
|
||||
|
@ -7506,4 +7504,9 @@ void Application::setAvatarOverrideUrl(const QUrl& url, bool save) {
|
|||
_avatarOverrideUrl = url;
|
||||
_saveAvatarOverrideUrl = save;
|
||||
}
|
||||
|
||||
void Application::saveNextPhysicsStats(QString filename) {
|
||||
_physicsEngine->saveNextPhysicsStats(filename);
|
||||
}
|
||||
|
||||
#include "Application.moc"
|
||||
|
|
|
@ -280,6 +280,7 @@ public:
|
|||
void clearAvatarOverrideUrl() { _avatarOverrideUrl = QUrl(); _saveAvatarOverrideUrl = false; }
|
||||
QUrl getAvatarOverrideUrl() { return _avatarOverrideUrl; }
|
||||
bool getSaveAvatarOverrideUrl() { return _saveAvatarOverrideUrl; }
|
||||
void saveNextPhysicsStats(QString filename);
|
||||
|
||||
signals:
|
||||
void svoImportRequested(const QString& url);
|
||||
|
@ -432,6 +433,7 @@ private slots:
|
|||
|
||||
void handleSandboxStatus(QNetworkReply* reply);
|
||||
void switchDisplayMode();
|
||||
|
||||
private:
|
||||
static void initDisplay();
|
||||
void init();
|
||||
|
|
|
@ -141,6 +141,10 @@ void TestScriptingInterface::endTraceEvent(QString name) {
|
|||
tracing::traceEvent(trace_test(), name, tracing::DurationEnd);
|
||||
}
|
||||
|
||||
void TestScriptingInterface::savePhysicsSimulationStats(QString filename) {
|
||||
qApp->saveNextPhysicsStats(filename);
|
||||
}
|
||||
|
||||
void TestScriptingInterface::profileRange(const QString& name, QScriptValue fn) {
|
||||
PROFILE_RANGE(script, name);
|
||||
fn.call();
|
||||
|
|
|
@ -71,6 +71,11 @@ public slots:
|
|||
|
||||
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);
|
||||
|
||||
private:
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <QFile>
|
||||
|
||||
#include <PerfStat.h>
|
||||
#include <Profile.h>
|
||||
|
||||
#include "CharacterController.h"
|
||||
#include "ObjectMotionState.h"
|
||||
|
@ -294,6 +295,7 @@ void PhysicsEngine::stepSimulation() {
|
|||
float timeStep = btMin(dt, MAX_TIMESTEP);
|
||||
|
||||
if (_myAvatarController) {
|
||||
DETAILED_PROFILE_RANGE(simulation_physics, "avatarController");
|
||||
BT_PROFILE("avatarController");
|
||||
// TODO: move this stuff outside and in front of stepSimulation, because
|
||||
// the updateShapeIfNecessary() call needs info from MyAvatar and should
|
||||
|
@ -465,6 +467,7 @@ void PhysicsEngine::doOwnershipInfection(const btCollisionObject* objectA, const
|
|||
}
|
||||
|
||||
void PhysicsEngine::updateContactMap() {
|
||||
DETAILED_PROFILE_RANGE(simulation_physics, "updateContactMap");
|
||||
BT_PROFILE("updateContactMap");
|
||||
++_numContactFrames;
|
||||
|
||||
|
@ -582,10 +585,20 @@ void PhysicsEngine::dumpStatsIfNecessary() {
|
|||
if (_dumpNextStats) {
|
||||
_dumpNextStats = false;
|
||||
CProfileManager::Increment_Frame_Counter();
|
||||
if (_saveNextStats) {
|
||||
_saveNextStats = false;
|
||||
printPerformanceStatsToFile(_statsFilename);
|
||||
}
|
||||
CProfileManager::dumpAll();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsEngine::saveNextPhysicsStats(QString filename) {
|
||||
_saveNextStats = true;
|
||||
_dumpNextStats = true;
|
||||
_statsFilename = filename;
|
||||
}
|
||||
|
||||
// Bullet collision flags are as follows:
|
||||
// CF_STATIC_OBJECT= 1,
|
||||
// CF_KINEMATIC_OBJECT= 2,
|
||||
|
|
|
@ -77,6 +77,9 @@ public:
|
|||
/// \brief prints timings for last frame if stats have been requested.
|
||||
void dumpStatsIfNecessary();
|
||||
|
||||
/// \brief saves timings for last frame in filename
|
||||
void saveNextPhysicsStats(QString filename);
|
||||
|
||||
/// \param offset position of simulation origin in domain-frame
|
||||
void setOriginOffset(const glm::vec3& offset) { _originOffset = offset; }
|
||||
|
||||
|
@ -116,6 +119,7 @@ private:
|
|||
QHash<QUuid, EntityDynamicPointer> _objectDynamics;
|
||||
QHash<btRigidBody*, QSet<QUuid>> _objectDynamicsByBody;
|
||||
std::set<btRigidBody*> _activeStaticBodies;
|
||||
QString _statsFilename;
|
||||
|
||||
glm::vec3 _originOffset;
|
||||
|
||||
|
@ -124,8 +128,9 @@ private:
|
|||
uint32_t _numContactFrames = 0;
|
||||
uint32_t _numSubsteps;
|
||||
|
||||
bool _dumpNextStats = false;
|
||||
bool _hasOutgoingChanges = false;
|
||||
bool _dumpNextStats { false };
|
||||
bool _saveNextStats { false };
|
||||
bool _hasOutgoingChanges { false };
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <LinearMath/btQuickprof.h>
|
||||
|
||||
#include "ThreadSafeDynamicsWorld.h"
|
||||
#include "Profile.h"
|
||||
|
||||
ThreadSafeDynamicsWorld::ThreadSafeDynamicsWorld(
|
||||
btDispatcher* dispatcher,
|
||||
|
@ -29,6 +30,7 @@ ThreadSafeDynamicsWorld::ThreadSafeDynamicsWorld(
|
|||
|
||||
int ThreadSafeDynamicsWorld::stepSimulationWithSubstepCallback(btScalar timeStep, int maxSubSteps,
|
||||
btScalar fixedTimeStep, SubStepCallback onSubStep) {
|
||||
DETAILED_PROFILE_RANGE(simulation_physics, "stepWithCB");
|
||||
BT_PROFILE("stepSimulationWithSubstepCallback");
|
||||
int subSteps = 0;
|
||||
if (maxSubSteps) {
|
||||
|
@ -68,11 +70,13 @@ int ThreadSafeDynamicsWorld::stepSimulationWithSubstepCallback(btScalar timeStep
|
|||
saveKinematicState(fixedTimeStep*clampedSimulationSteps);
|
||||
|
||||
{
|
||||
DETAILED_PROFILE_RANGE(simulation_physics, "applyGravity");
|
||||
BT_PROFILE("applyGravity");
|
||||
applyGravity();
|
||||
}
|
||||
|
||||
for (int i=0;i<clampedSimulationSteps;i++) {
|
||||
DETAILED_PROFILE_RANGE(simulation_physics, "substep");
|
||||
internalSingleStepSimulation(fixedTimeStep);
|
||||
onSubStep();
|
||||
}
|
||||
|
@ -118,7 +122,8 @@ void ThreadSafeDynamicsWorld::synchronizeMotionState(btRigidBody* body) {
|
|||
}
|
||||
|
||||
void ThreadSafeDynamicsWorld::synchronizeMotionStates() {
|
||||
BT_PROFILE("synchronizeMotionStates");
|
||||
DETAILED_PROFILE_RANGE(simulation_physics, "syncMotionStates");
|
||||
BT_PROFILE("syncMotionStates");
|
||||
_changedMotionStates.clear();
|
||||
|
||||
// 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
|
||||
///to switch status _after_ adding kinematic objects to the world
|
||||
///fix it for Bullet 3.x release
|
||||
DETAILED_PROFILE_RANGE(simulation_physics, "saveKinematicState");
|
||||
BT_PROFILE("saveKinematicState");
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue