Update of /cvsroot/csp/APPLICATIONS/CSPFlightSim/Source
In directory sc8-pr-cvs1:/tmp/cvs-serv22143
Modified Files:
CSPFlightSim.cpp
Log Message:
Initial time fix. (prevents extra long first frame)
Long timestep fix. (could cause physics instability/segfaults)
Frame rate buffer overflow fix.
Index: CSPFlightSim.cpp
===================================================================
RCS file: /cvsroot/csp/APPLICATIONS/CSPFlightSim/Source/CSPFlightSim.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** CSPFlightSim.cpp 18 Dec 2002 01:38:47 -0000 1.6
--- CSPFlightSim.cpp 19 Dec 2002 08:56:37 -0000 1.7
***************
*** 57,60 ****
--- 57,61 ----
osg::Timer _timer;
osg::Timer_t _initialTick, _lastFrameTick, _frameTick;
+ double _timeStep, _frameTime, _timeLag = 0.0;
osg::Timer_t clockTick()
***************
*** 69,76 ****
--- 70,94 ----
// update time from the current frame update and the previous one.
+ // the timestep for updates is restricted to 1 second max. greater
+ // delays will accumulate in _timeLag to be made up in subsequent
+ // frames. this prevents long delays from destabilizing the update
+ // computations.
osg::Timer_t updateFrameTick()
{
_lastFrameTick = _frameTick;
_frameTick = _timer.tick();
+ _frameTime = _timer.delta_s(_lastFrameTick,_frameTick);
+ _timeStep = _frameTime + _timeLag;
+ if (_timeStep > 1.0) {
+ _timeLag = _timeStep - 1.0;
+ _timeStep = 1.0;
+ }
+ if (_timeStep < 0.01) {
+ // todo: microsleep
+ _timeStep = 0.01;
+ _timeLag = 0.0;
+ } else {
+ _timeLag = 0.0;
+ }
return _frameTick;
}
***************
*** 78,87 ****
double frameSeconds()
{
! return _timer.delta_s(_lastFrameTick,_frameTick);
}
double frameRate()
{
! return 1.0/frameSeconds();
}
--- 96,106 ----
double frameSeconds()
{
! return _frameTime; //_timer.delta_s(_lastFrameTick,_frameTick);
}
double frameRate()
{
! if (_frameTime < 0.005) return 200.0;
! return 1.0/_frameTime; //frameSeconds();
}
***************
*** 193,196 ****
--- 212,221 ----
CSP_LOG(CSP_APP, CSP_DEBUG, "CSPFlightSim::Run..." );
m_bFreezeSim = false;
+
+ // reset to frame time so we don't jump in one frame through
+ // all the time it took to initialize. just a hack for now.
+ _initialTick = _timer.tick();
+ _frameTick = _initialTick;
+ _lastFrameTick = _initialTick;
try
***************
*** 199,203 ****
{
updateFrameTick();
! float dt = frameSeconds();
g_pSimTime->updateSimTime(dt);
--- 224,228 ----
{
updateFrameTick();
! float dt = _timeStep; //frameSeconds();
g_pSimTime->updateSimTime(dt);
***************
*** 529,533 ****
{
int width = m_SDLScreen->w;
! char buffer[128];
StandardVector3 direction = g_pPlayerObject->getDirection();
StandardVector3 upVector = g_pPlayerObject->getUpDirection();
--- 554,558 ----
{
int width = m_SDLScreen->w;
! char buffer[256];
StandardVector3 direction = g_pPlayerObject->getDirection();
StandardVector3 upVector = g_pPlayerObject->getUpDirection();
***************
*** 551,556 ****
void CSPFlightSim::ShowStats(float fps)
{
! char framerate[30];
! char buffer[128];
static float maxFps = 0.0, minFps = 500.0;
--- 576,581 ----
void CSPFlightSim::ShowStats(float fps)
{
! char framerate[64];
! char buffer[256];
static float maxFps = 0.0, minFps = 500.0;
|