Skip to content

Commit

Permalink
Freeze non deterministic timer during frame boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
clementgallet committed Apr 16, 2016
1 parent dfb24f8 commit 25df090
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 9 additions & 3 deletions src/libTAS/NonDeterministicTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void NonDeterministicTimer::initialize(void)
ticks.tv_nsec = 0;
lastEnterTicks = ticks;
clock_gettime_real(CLOCK_MONOTONIC, (struct timespec*)&lasttime);
frameThreadId = 0;
inFB = false;
lastEnterTime = lasttime;
lastExitTime = lasttime;
}
Expand All @@ -39,6 +39,10 @@ struct timespec NonDeterministicTimer::getTicks(void)
{
DEBUGLOGCALL(LCF_TIMEGET | LCF_FREQUENT);

/* During a frame boundary, we freeze the timer */
if (inFB)
return *(struct timespec*)&ticks;

bool isFrameThread = isMainThread();

/* Only the main thread can modify the timer */
Expand Down Expand Up @@ -73,7 +77,6 @@ struct timespec NonDeterministicTimer::getTicks(void)
}

ticks += delta;

debuglog(LCF_TIMESET|LCF_FREQUENT, __func__, " added ", delta.tv_sec * 1000000000 + delta.tv_nsec, " nsec ");

lasttime = realtime;
Expand All @@ -84,10 +87,12 @@ struct timespec NonDeterministicTimer::getTicks(void)
void NonDeterministicTimer::enterFrameBoundary()
{
DEBUGLOGCALL(LCF_TIMEGET | LCF_FRAME);
getTicks();
inFB = true;

clock_gettime_real(CLOCK_MONOTONIC, (struct timespec*)&lastEnterTime);

/* Doing the audio mixing here */
getTicks();
TimeHolder elapsedTicks = ticks - lastEnterTicks;
audiocontext.mixAllSources(*(struct timespec*)&elapsedTicks);

Expand All @@ -98,6 +103,7 @@ void NonDeterministicTimer::exitFrameBoundary()
{
DEBUGLOGCALL(LCF_TIMEGET | LCF_FRAME);
clock_gettime_real(CLOCK_MONOTONIC, (struct timespec*)&lastExitTime);
inFB = false;
}

void NonDeterministicTimer::addDelay(struct timespec delayTicks)
Expand Down
4 changes: 2 additions & 2 deletions src/libTAS/NonDeterministicTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class NonDeterministicTimer
/* Last time value of the timer */
TimeHolder lasttime;

/* Store which thread can update the timer */
pthread_t frameThreadId;
/* Are we inside a frame boundary? */
bool inFB;

/* The time of the last frame boundary enter */
TimeHolder lastEnterTicks;
Expand Down
6 changes: 0 additions & 6 deletions src/libTAS/TimeHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ class TimeHolder

/* Bring the tv_nsec value inside the range [0,999999999] */
void normalize();

struct timespec toTimeSpec()
{
struct timespec ts = {this->tv_sec, this->tv_nsec};
return ts;
}
};

#endif
Expand Down

0 comments on commit 25df090

Please sign in to comment.