| 122 | } |
| 123 | |
| 124 | void AppImplAndroid::sleepUntilNextFrame() |
| 125 | { |
| 126 | // get current time in seconds |
| 127 | double currentSeconds = getElapsedSeconds(); |
| 128 | |
| 129 | // calculate time per frame in seconds |
| 130 | double secondsPerFrame = 1.0 / mFrameRate; |
| 131 | |
| 132 | // determine if application was frozen for a while and adjust next frame time |
| 133 | double elapsedSeconds = currentSeconds - mNextFrameTime; |
| 134 | if( elapsedSeconds > 1.0 ) { |
| 135 | int numSkipFrames = (int)(elapsedSeconds / secondsPerFrame); |
| 136 | mNextFrameTime += (numSkipFrames * secondsPerFrame); |
| 137 | } |
| 138 | |
| 139 | // determine when next frame should be drawn |
| 140 | mNextFrameTime += secondsPerFrame; |
| 141 | |
| 142 | // sleep and process messages until next frame |
| 143 | if( ( mFrameRateEnabled ) && ( mNextFrameTime > currentSeconds ) ) { |
| 144 | double sleepTime = std::max( mNextFrameTime - currentSeconds, 0.0 ); |
| 145 | unsigned long sleepMicroSecs = sleepTime*1000000L; |
| 146 | usleep(sleepMicroSecs); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | void AppImplAndroid::updateAndDraw() |
| 151 | { |
no test coverage detected