Skip to content

Commit

Permalink
libdeng2: Use the convenience typedef TimeDelta
Browse files Browse the repository at this point in the history
Instead of spelling out Time::Delta.
  • Loading branch information
skyjake committed Jan 22, 2013
1 parent d061518 commit 4f46885
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 54 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/src/updater/updatersettings.cpp
Expand Up @@ -187,7 +187,7 @@ de::NativePath UpdaterSettings::defaultDownloadPath()
de::String UpdaterSettings::lastCheckAgo() const
{
de::Time when = lastCheckTime();
de::Time::Delta delta = when.since();
de::TimeDelta delta = when.since();

int t;
if(delta < 60.0)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng1/src/concurrency.cpp
Expand Up @@ -124,7 +124,7 @@ boolean Sys_InMainThread(void)

void Thread_Sleep(int milliseconds)
{
de::Time::Delta::fromMilliSeconds(milliseconds).sleep();
de::TimeDelta::fromMilliSeconds(milliseconds).sleep();
}

thread_t Sys_StartThread(systhreadfunc_t startpos, void *parm)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libdeng2/include/de/core/clock.cpp
Expand Up @@ -40,12 +40,12 @@ void Clock::setTime(Time const &currentTime)
}
}

void Clock::advanceTime(Time::Delta const &span)
void Clock::advanceTime(TimeDelta const &span)
{
setTime(_time + span);
}

Time::Delta Clock::elapsed() const
TimeDelta Clock::elapsed() const
{
return _time - _startedAt;
}
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libdeng2/include/de/core/clock.h
Expand Up @@ -40,13 +40,13 @@ class Clock : public QObject

virtual void setTime(Time const &currentTime);

void advanceTime(Time::Delta const &span);
void advanceTime(TimeDelta const &span);

/**
* Returns the amount of time elapsed since the clock was created.
* @return Elapsed time.
*/
Time::Delta elapsed() const;
TimeDelta elapsed() const;

/**
* Returns a reference to the current time.
Expand Down
22 changes: 11 additions & 11 deletions doomsday/libdeng2/include/de/data/time.h
Expand Up @@ -119,25 +119,25 @@ class DENG2_PUBLIC Time : public ISerializable
*/
Time();

Time(Time const &other) : ISerializable(), _time(other._time) {}
Time(Time const &other);

Time(QDateTime const &t) : ISerializable(), _time(t) {}
Time(QDateTime const &t);

static Time invalidTime();

bool isValid() const;

bool operator < (Time const &t) const;

bool operator > (Time const &t) const { return t < *this; }
inline bool operator > (Time const &t) const { return t < *this; }

bool operator <= (Time const &t) const { return !(*this > t); }
inline bool operator <= (Time const &t) const { return !(*this > t); }

bool operator >= (Time const &t) const { return !(*this < t); }
inline bool operator >= (Time const &t) const { return !(*this < t); }

bool operator == (Time const &t) const;

bool operator != (Time const &t) const { return !(*this == t); }
inline bool operator != (Time const &t) const { return !(*this == t); }

/**
* Add a delta to the point of time.
Expand All @@ -155,7 +155,7 @@ class DENG2_PUBLIC Time : public ISerializable
*
* @return Modified time.
*/
Time operator - (Delta const &delta) const { return *this + (-delta); }
inline Time operator - (Delta const &delta) const { return *this + (-delta); }

/**
* Modify point of time.
Expand All @@ -173,7 +173,7 @@ class DENG2_PUBLIC Time : public ISerializable
*
* @return Reference to this Time.
*/
Time &operator -= (Delta const &delta) { return *this += -delta; }
inline Time &operator -= (Delta const &delta) { return *this += -delta; }

/**
* Difference between two times.
Expand All @@ -188,15 +188,15 @@ class DENG2_PUBLIC Time : public ISerializable
*
* @return Delta.
*/
Delta since() const { return deltaTo(Time()); }
inline Delta since() const { return deltaTo(Time()); }

/**
* Difference between current time and this time.
* Returns positive deltas if current time is before this time.
*
* @return Delta.
*/
Delta until() const { return Time().deltaTo(*this); }
inline Delta until() const { return Time().deltaTo(*this); }

/**
* Difference to a later point in time.
Expand All @@ -205,7 +205,7 @@ class DENG2_PUBLIC Time : public ISerializable
*
* @return Delta.
*/
Delta deltaTo(Time const &laterTime) const { return laterTime - *this; }
inline Delta deltaTo(Time const &laterTime) const { return laterTime - *this; }

/**
* Makes a text representation of the time (default is ISO format, e.g.,
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/include/de/data/waitable.h
Expand Up @@ -50,7 +50,7 @@ class DENG2_PUBLIC Waitable

/// Wait for the specified period of time to secure the
/// resource. If timeout occurs, an exception is thrown.
void wait(Time::Delta const &timeOut);
void wait(TimeDelta const &timeOut);

/// Mark the resource as available by incrementing the
/// semaphore value.
Expand Down
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/libdeng2.h
Expand Up @@ -127,6 +127,7 @@
# define DENG2_DEBUG
# ifdef DENG2_USE_QT
# define DENG2_ASSERT(x) Q_ASSERT(x)
# include <QDebug>
# else
# define DENG2_ASSERT(x) assert(x)
# endif
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/include/de/net/socket.h
Expand Up @@ -80,7 +80,7 @@ class DENG2_PUBLIC Socket : public QObject, public Transmitter
* @param address Address to connect to.
* @param timeOut Maximum time to wait for connection.
*/
Socket(Address const &address, Time::Delta const &timeOut = 5);
Socket(Address const &address, TimeDelta const &timeOut = 5);

virtual ~Socket();

Expand Down
13 changes: 9 additions & 4 deletions doomsday/libdeng2/include/de/widgets/animation.h
Expand Up @@ -72,9 +72,9 @@ class Animation : public ISerializable
* This includes @a startDelay.
* @param startDelay Number of seconds to wait before starting the transition.
*/
void setValue(float v, Time::Delta transitionSpan = 0, Time::Delta startDelay = 0);
void setValue(float v, TimeDelta transitionSpan = 0, TimeDelta startDelay = 0);

void setValue(int v, Time::Delta transitionSpan = 0, Time::Delta startDelay = 0);
void setValue(int v, TimeDelta transitionSpan = 0, TimeDelta startDelay = 0);

/**
* Starts a new transition.
Expand All @@ -85,7 +85,7 @@ class Animation : public ISerializable
* This includes @a startDelay.
* @param startDelay Number of seconds to wait before starting the transition.
*/
void setValueFrom(float fromValue, float toValue, Time::Delta transitionSpan = 0, Time::Delta startDelay = 0);
void setValueFrom(float fromValue, float toValue, TimeDelta transitionSpan = 0, TimeDelta startDelay = 0);

/**
* Current value.
Expand All @@ -105,7 +105,7 @@ class Animation : public ISerializable
/**
* Number of seconds remaining in the ongoing transition.
*/
Time::Delta remainingTime() const;
TimeDelta remainingTime() const;

/**
* Move the current value and the target value by @a valueDelta.
Expand Down Expand Up @@ -135,6 +135,11 @@ class Animation : public ISerializable

String asText() const;

/**
* Returns the clock used for this animation.
*/
Clock const &clock();

// Implements ISerializable.
void operator >> (Writer &to) const;
void operator << (Reader &from);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/src/core/logbuffer.cpp
Expand Up @@ -32,7 +32,7 @@

namespace de {

Time::Delta const FLUSH_INTERVAL = .2; // seconds
TimeDelta const FLUSH_INTERVAL = .2; // seconds

namespace internal {

Expand Down
26 changes: 16 additions & 10 deletions doomsday/libdeng2/src/data/time.cpp
Expand Up @@ -48,27 +48,27 @@ class SleeperThread : public QThread

} // namespace internal

duint64 Time::Delta::asMilliSeconds() const
duint64 TimeDelta::asMilliSeconds() const
{
return duint64(_seconds * 1000);
}

ddouble Time::Delta::asMinutes() const
ddouble TimeDelta::asMinutes() const
{
return _seconds / 60;
}

ddouble Time::Delta::asHours() const
ddouble TimeDelta::asHours() const
{
return _seconds / 3600;
}

ddouble Time::Delta::asDays() const
ddouble TimeDelta::asDays() const
{
return asHours() / 24;
}

void Time::Delta::sleep() const
void TimeDelta::sleep() const
{
if(_seconds < 60)
{
Expand All @@ -80,29 +80,35 @@ void Time::Delta::sleep() const
}
}

void Time::Delta::operator >> (Writer &to) const
void TimeDelta::operator >> (Writer &to) const
{
to << _seconds;
}

void Time::Delta::operator << (Reader &from)
void TimeDelta::operator << (Reader &from)
{
from >> _seconds;
}

Time::Delta Time::Delta::operator + (ddouble const &d) const
TimeDelta TimeDelta::operator + (ddouble const &d) const
{
return _seconds + d;
}

Time::Delta Time::Delta::operator - (ddouble const &d) const
TimeDelta TimeDelta::operator - (ddouble const &d) const
{
return _seconds - d;
}

Time::Time() : _time(QDateTime::currentDateTime())
{}

Time::Time(Time const &other) : ISerializable(), _time(other._time)
{}

Time::Time(QDateTime const &t) : ISerializable(), _time(t)
{}

Time Time::invalidTime()
{
return Time(QDateTime());
Expand Down Expand Up @@ -136,7 +142,7 @@ Time &Time::operator += (Delta const &delta)
return *this;
}

Time::Delta Time::operator - (Time const &earlierTime) const
TimeDelta Time::operator - (Time const &earlierTime) const
{
#ifdef DENG2_QT_4_7_OR_NEWER
return earlierTime._time.msecsTo(_time) / 1000.0;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libdeng2/src/data/timevalue.cpp
Expand Up @@ -57,12 +57,12 @@ dint TimeValue::compare(Value const &value) const

void TimeValue::sum(Value const &value)
{
_time += Time::Delta(value.asNumber());
_time += TimeDelta(value.asNumber());
}

void TimeValue::subtract(Value const &subtrahend)
{
_time -= Time::Delta(subtrahend.asNumber());
_time -= TimeDelta(subtrahend.asNumber());
}

void TimeValue::operator >> (Writer &to) const
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/src/data/waitable.cpp
Expand Up @@ -35,7 +35,7 @@ void Waitable::wait()
wait(WAITABLE_TIMEOUT);
}

void Waitable::wait(Time::Delta const &timeOut)
void Waitable::wait(TimeDelta const &timeOut)
{
// Wait until the resource becomes available.
if(!_semaphore.tryAcquire(1, int(timeOut.asMilliSeconds())))
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/src/net/socket.cpp
Expand Up @@ -366,7 +366,7 @@ struct Socket::Instance
}
};

Socket::Socket(Address const &address, Time::Delta const &timeOut)
Socket::Socket(Address const &address, TimeDelta const &timeOut)
{
LOG_AS("Socket");

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/src/scriptsys/process.cpp
Expand Up @@ -31,7 +31,7 @@ using namespace de;
using std::auto_ptr;

/// If execution continues for longer than this, a HangError is thrown.
static Time::Delta const MAX_EXECUTION_TIME = 10;
static TimeDelta const MAX_EXECUTION_TIME = 10;

Process::Process(Record *externalGlobalNamespace) : _state(STOPPED), _workingPath("/")
{
Expand Down

0 comments on commit 4f46885

Please sign in to comment.