Skip to content

Commit

Permalink
Fixed|libdeng2|Time: Deserializing a Time instance
Browse files Browse the repository at this point in the history
IssueID #1748
  • Loading branch information
skyjake committed Apr 16, 2014
1 parent 10af4c8 commit e39e9de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doomsday/libdeng2/include/de/core/highperformancetimer.h
Expand Up @@ -37,6 +37,11 @@ class DENG2_PUBLIC HighPerformanceTimer
*/
TimeDelta elapsed() const;

/**
* Returns the time when the timer was started.
*/
Time startedAt() const;

private:
DENG2_PRIVATE(d)
};
Expand Down
7 changes: 7 additions & 0 deletions doomsday/libdeng2/src/core/highperformancetimer.cpp
Expand Up @@ -28,11 +28,13 @@ static duint32 const WARP_INTERVAL = 12 * 60 * 60 * 1000;

DENG2_PIMPL_NOREF(HighPerformanceTimer), public Lockable
{
QDateTime origin;
QTime startedAt;
duint64 timerOffset; /// Range extension. QTime only provides a 24h range.

Instance() : timerOffset(0)
{
origin = QDateTime::currentDateTime();
startedAt.start();
}

Expand Down Expand Up @@ -62,4 +64,9 @@ TimeDelta HighPerformanceTimer::elapsed() const
return TimeDelta(d->milliSeconds() / 1000.0);
}

Time HighPerformanceTimer::startedAt() const
{
return d->origin;
}

} // namespace de
16 changes: 16 additions & 0 deletions doomsday/libdeng2/src/data/time.cpp
Expand Up @@ -452,6 +452,22 @@ void Time::operator << (Reader &from)

from >> d->highPerfElapsed;
}

if((flags & HAS_DATETIME) && (flags & HAS_HIGH_PERF))
{
// If both are present, the high-performance time should be synced
// with current high-perf timer.
if(d->dateTime < highPerfTimer.startedAt().asDateTime())
{
// Current high-performance timer was started after this time;
// we can't represent the time as high performance delta.
d->flags &= ~Instance::HighPerformance;
}
else
{
d->highPerfElapsed = highPerfTimer.startedAt().deltaTo(d->dateTime);
}
}
}
else
{
Expand Down

0 comments on commit e39e9de

Please sign in to comment.