From dca213208720b7a3d83c1130ed4f3b64bdf3bff1 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Mon, 28 Mar 2011 00:16:27 +0200 Subject: [PATCH] New property reporting worst-case frame latency. Shows maximum latency of any frame within the last second. --- src/Time/TimeManager.cxx | 10 ++++++++-- src/Time/TimeManager.hxx | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Time/TimeManager.cxx b/src/Time/TimeManager.cxx index 2e2389695..7d4ed5607 100644 --- a/src/Time/TimeManager.cxx +++ b/src/Time/TimeManager.cxx @@ -88,9 +88,11 @@ void TimeManager::init() _warp->getIntValue()); globals->set_time_params(_impl); -// frame/update-rate counters + // frame-rate / worst-case delay / update-rate counters _frameRate = fgGetNode("/sim/frame-rate", true); + _frameDelayMax = fgGetNode("/sim/frame-delay-max-ms", true); _lastFrameTime = 0; + _wcFrameDelayMax = 0.0; _frameCount = 0; } @@ -160,7 +162,9 @@ void TimeManager::computeTimeDeltas(double& simDt, double& realDt) SGTimeStamp currentStamp; currentStamp.stamp(); double dt = (currentStamp - _lastStamp).toSecs(); - + if (dt > _wcFrameDelayMax) + _wcFrameDelayMax = dt; + // Limit the time we need to spend in simulation loops // That means, if the /sim/max-simtime-per-frame value is strictly positive // you can limit the maximum amount of time you will do simulations for @@ -251,7 +255,9 @@ void TimeManager::computeFrameRate() // Calculate frame rate average if ((_impl->get_cur_time() != _lastFrameTime)) { _frameRate->setIntValue(_frameCount); + _frameDelayMax->setDoubleValue(_wcFrameDelayMax*1000); _frameCount = 0; + _wcFrameDelayMax = 0.0; } _lastFrameTime = _impl->get_cur_time(); diff --git a/src/Time/TimeManager.hxx b/src/Time/TimeManager.hxx index 59aa03616..edf498013 100644 --- a/src/Time/TimeManager.hxx +++ b/src/Time/TimeManager.hxx @@ -78,9 +78,11 @@ private: SGPropertyNode_ptr _longitudeDeg; SGPropertyNode_ptr _latitudeDeg; -// frame-rate / update-rate counters + // frame-rate / worst-case delay / update-rate counters SGPropertyNode_ptr _frameRate; + SGPropertyNode_ptr _frameDelayMax; time_t _lastFrameTime; + double _wcFrameDelayMax; int _frameCount; };