MCPcopy Create free account
hub / github.com/clementgallet/libTAS / enterFrameBoundary

Method enterFrameBoundary

src/library/DeterministicTimer.cpp:337–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335
336
337TimeHolder DeterministicTimer::enterFrameBoundary()
338{
339 if (Global::shared_config.debug_state & SharedConfig::DEBUG_UNCONTROLLED_TIME)
340 return NonDeterministicTimer::get().enterFrameBoundary();
341
342 frame_mutex.lock();
343 LOGTRACE(LCF_TIMEGET);
344
345 insideFrameBoundary = true;
346 fakeAdvanceTimer({0, 0});
347
348 /*** First we update the state of the internal timer ***/
349
350 /* We compute by how much we should advance the timer
351 * to run exactly as the indicated framerate
352 */
353 TimeHolder timeIncrement = baseTimeIncrement;
354
355 fractional_part += fractional_increment;
356 while (fractional_part >= framerate_num)
357 {
358 timeIncrement.tv_nsec++;
359 fractional_part -= framerate_num;
360 }
361
362 /* If we have less delay than the length of a frame, we advance ticks by
363 * the remaining length. Otherwise, we don't increment ticks, and we
364 * decrement addedDelay by the time increment.
365 */
366 if (timeIncrement > addedDelay) {
367 TimeHolder deltaTicks = timeIncrement - addedDelay;
368 ticks += deltaTicks;
369 LOG(LL_DEBUG, LCF_TIMESET, "%s added %u.%09u", __func__, deltaTicks.tv_sec, deltaTicks.tv_nsec);
370 addedDelay = {0, 0};
371 }
372 else {
373 addedDelay -= timeIncrement;
374 }
375
376 return timeIncrement;
377}
378
379void DeterministicTimer::fakeAdvanceTimer(struct timespec extraTicks) {
380 fakeExtraTicks = extraTicks;

Callers 1

frameBoundaryFunction · 0.45

Calls 1

lockMethod · 0.45

Tested by

no test coverage detected