time budget

This commit is contained in:
luiscuenca 2019-02-13 08:16:22 -07:00
parent bebbbc643b
commit 05d50f32ba
2 changed files with 18 additions and 16 deletions

View file

@ -593,9 +593,6 @@ void Flow::calculateConstraints() {
}
}
_initialized = _jointThreads.size() > 0;
if (_initialized) {
_mtimer.restart();
}
}
void Flow::cleanUp() {
@ -620,25 +617,29 @@ void Flow::setTransform(float scale, const glm::vec3& position, const glm::quat&
void Flow::update(float deltaTime) {
if (_initialized && _active) {
QElapsedTimer timer;
timer.start();
QElapsedTimer _timer;
_timer.start();
updateJoints();
int count = 0;
for (auto &thread : _jointThreads) {
for (size_t i = 0; i < _jointThreads.size(); i++) {
size_t index = _invertThreadLoop ? _jointThreads.size() - 1 - i : i;
auto &thread = _jointThreads[index];
thread.update(deltaTime);
thread.solve(USE_COLLISIONS, _collisionSystem);
if (!updateRootFramePositions(count++)) {
if (!updateRootFramePositions(index)) {
return;
}
thread.apply();
if (_timer.elapsed() > MAX_UPDATE_FLOW_TIME_BUDGET) {
break;
qWarning(animation) << "Flow Bones ran out of time updating threads";
}
}
setJoints();
_deltaTime += timer.nsecsElapsed();
_invertThreadLoop = !_invertThreadLoop;
_deltaTime += _timer.nsecsElapsed();
_updates++;
if (_deltaTime > _deltaTimeLimit) {
qint64 currentTime = _mtimer.elapsed();
qDebug() << "Flow C++ update " << _deltaTime / _updates << " nanoSeconds " << (currentTime - _lastTime) / _updates << " miliseconds since last update";
_lastTime = currentTime;
qDebug() << "Flow C++ update " << _deltaTime / _updates << " nanoSeconds ";
_deltaTime = 0;
_updates = 0;
}
@ -656,7 +657,7 @@ bool Flow::worldToJointPoint(const glm::vec3& position, const int jointIndex, gl
return false;
}
bool Flow::updateRootFramePositions(int threadIndex) {
bool Flow::updateRootFramePositions(size_t threadIndex) {
auto &joints = _jointThreads[threadIndex]._joints;
int rootIndex = _flowJointData[joints[0]]._parentIndex;
_jointThreads[threadIndex]._rootFramePositions.clear();

View file

@ -62,6 +62,8 @@ const float DEFAULT_INERTIA = 0.8f;
const float DEFAULT_DELTA = 0.55f;
const float DEFAULT_RADIUS = 0.01f;
const uint64_t MAX_UPDATE_FLOW_TIME_BUDGET = 2000;
struct FlowPhysicsSettings {
FlowPhysicsSettings() {};
FlowPhysicsSettings(bool active, float stiffness, float gravity, float damping, float inertia, float delta, float radius) {
@ -286,7 +288,7 @@ private:
void setJoints();
void cleanUp();
void updateJoints();
bool updateRootFramePositions(int threadIndex);
bool updateRootFramePositions(size_t threadIndex);
bool worldToJointPoint(const glm::vec3& position, const int jointIndex, glm::vec3& jointSpacePosition) const;
Rig* _rig;
float _scale { 1.0f };
@ -301,8 +303,7 @@ private:
int _deltaTime { 0 };
int _deltaTimeLimit { 4000000 };
int _updates { 0 };
QElapsedTimer _mtimer;
long _lastTime { 0 };
bool _invertThreadLoop { false };
};
#endif // hifi_Flow_h