Skip to content

Commit

Permalink
libcore|Time: Disallow TimeSpan construction from an integer
Browse files Browse the repository at this point in the history
An integer might mistakenly be milliseconds where TimeSpans should
be seconds.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 4012e2f commit 408722c
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 40 deletions.
4 changes: 3 additions & 1 deletion doomsday/libs/core/include/de/data/time.h
Expand Up @@ -62,10 +62,12 @@ class DE_PUBLIC Time : public ISerializable
*
* @param seconds Length of the time span.
*/
Span(ddouble seconds = 0)
Span(ddouble seconds = 0.0)
: _seconds(seconds)
{}

Span(int) = delete; // ambiguous

/**
* Conversion to the numeric type (floating-point seconds).
*/
Expand Down
11 changes: 7 additions & 4 deletions doomsday/libs/core/include/de/widgets/animation.h
Expand Up @@ -71,9 +71,9 @@ class DE_PUBLIC Animation : public ISerializable, public Deletable
* This includes @a startDelay.
* @param startDelay Number of seconds to wait before starting the transition.
*/
void setValue(float toValue, TimeSpan transitionSpan = 0, TimeSpan startDelay = 0);
void setValue(float toValue, TimeSpan transitionSpan = 0.0, TimeSpan startDelay = 0.0);

void setValue(int toValue, TimeSpan transitionSpan = 0, TimeSpan startDelay = 0);
void setValue(int toValue, TimeSpan transitionSpan = 0.0, TimeSpan startDelay = 0.0);

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

/**
* Current value.
Expand Down Expand Up @@ -178,7 +181,7 @@ class DE_PUBLIC Animation : public ISerializable, public Deletable

static TimeSpan currentTime();

static Animation range(Style style, float from, float to, TimeSpan span, TimeSpan delay = 0);
static Animation range(Style style, float from, float to, TimeSpan span, TimeSpan delay = 0.0);

private:
DE_PRIVATE(d)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/core/include/de/widgets/animationrule.h
Expand Up @@ -47,9 +47,9 @@ class DE_PUBLIC AnimationRule : public Rule, DE_OBSERVES(Clock, TimeChange)
*/
explicit AnimationRule(Rule const &target, TimeSpan transition, Animation::Style style = Animation::EaseOut);

void set(float target, TimeSpan transition = 0, TimeSpan delay = 0);
void set(float target, TimeSpan transition = 0.0, TimeSpan delay = 0.0);

void set(Rule const &target, TimeSpan transition = 0, TimeSpan delay = 0);
void set(Rule const &target, TimeSpan transition = 0.0, TimeSpan delay = 0.0);

/**
* Sets the animation style of the rule.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/include/de/widgets/rulerectangle.h
Expand Up @@ -123,7 +123,7 @@ class DE_PUBLIC RuleRectangle : public ISizeRule
* (1, 1) to the bottom right.
* @param transition Transition time for the change.
*/
void setAnchorPoint(Vec2f const &normalizedPoint, TimeSpan const &transition = 0);
void setAnchorPoint(Vec2f const &normalizedPoint, TimeSpan const &transition = 0.0);

/**
* Returns the current rectangle as defined by the input rules.
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libs/core/src/core/loop.cpp
Expand Up @@ -31,12 +31,12 @@ static Loop *loopSingleton = nullptr;

DE_PIMPL(Loop)
{
TimeSpan interval;
bool running;
Timer timer;
TimeSpan interval;
bool running;
Timer timer;
LoopCallback mainCall;

Impl(Public *i) : Base(i), interval(0), running(false)
Impl(Public *i) : Base(i), running(false)
{
DE_ASSERT(!loopSingleton);
loopSingleton = i;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/net/socket.cpp
Expand Up @@ -86,7 +86,7 @@ struct Counters
Time periodStartedAt;
};
static LockableT<Counters> counters;
static TimeSpan const sendPeriodDuration = 5;
static TimeSpan const sendPeriodDuration = 5.0;

/// Maximum number of channels.
static duint const MAX_CHANNELS = 2;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/scriptsys/process.cpp
Expand Up @@ -147,7 +147,7 @@ DE_PIMPL(Process)
};

/// If execution continues for longer than this, a HangError is thrown.
static TimeSpan const MAX_EXECUTION_TIME = 10;
static TimeSpan const MAX_EXECUTION_TIME = 10.0;

Process::Process(Record *externalGlobalNamespace) : d(new Impl(this))
{
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/core/src/scriptsys/scriptsystem.cpp
Expand Up @@ -165,9 +165,9 @@ DE_PIMPL(ScriptSystem)

// Compile a list of all possible import locations.
importPaths.clear();
DE_FOR_EACH_CONST(ArrayValue::Elements, i, importPath->elements())
for (const auto *i : importPath->elements())
{
importPaths << (*i)->asText();
importPaths << i->asText();
}
for (const Path &path : additionalImportPaths)
{
Expand Down
7 changes: 3 additions & 4 deletions doomsday/libs/core/src/widgets/animation.cpp
Expand Up @@ -96,7 +96,6 @@ DE_PIMPL_NOREF(Animation)
Impl(float val, Style s)
: value(val)
, target(val)
, startDelay(0)
, setTime (theTime.now)
, targetTime(theTime.now)
, style(s)
Expand All @@ -113,8 +112,8 @@ DE_PIMPL_NOREF(Animation)
TimeSpan span = targetTime - setTime;

float s2 = 0;
TimeSpan peak = 0;
TimeSpan peak2 = 0;
TimeSpan peak;
TimeSpan peak2;

// Spring values.
if (style == Bounce || style == FixedBounce)
Expand Down Expand Up @@ -302,7 +301,7 @@ TimeSpan Animation::remainingTime() const
TimeSpan const now = d->currentTime();
if (now >= d->targetTime)
{
return 0;
return 0.0;
}
return d->targetTime - now;
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/core/src/widgets/animationrule.cpp
Expand Up @@ -131,7 +131,7 @@ void AnimationRule::update()
TimeSpan span = _animation.transitionTime();
if (_behavior.testFlag(DontAnimateFromZero) && fequal(_animation.target(), 0))
{
span = 0;
span = 0.0;
}
_animation.setValue(_targetRule->value(), span);
_animation.clock().audienceForPriorityTimeChange += this;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/shell/include/de/shell/abstractlink.h
Expand Up @@ -54,7 +54,7 @@ class LIBSHELL_PUBLIC AbstractLink
* @param domain Domain/IP address of the server.
* @param timeout Keep trying until this much time has passed.
*/
virtual void connectDomain(String const &domain, TimeSpan const &timeout = 0);
virtual void connectDomain(String const &domain, TimeSpan const &timeout = 0.0);

/**
* Opens a connection to a server over the network.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/shell/include/de/shell/link.h
Expand Up @@ -45,7 +45,7 @@ class LIBSHELL_PUBLIC Link : public AbstractLink
* @param domain Domain/IP address of the server.
* @param timeout Keep trying until this much time has passed.
*/
Link(String const &domain, TimeSpan const &timeout = 0);
Link(String const &domain, TimeSpan const &timeout = 0.0);

/**
* Opens a connection to a server over the network.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/shell/src/abstractlink.cpp
Expand Up @@ -163,7 +163,7 @@ void AbstractLink::connectHost(Address const &address)

d->status = Connecting;
d->startedTryingAt = Time();
d->timeout = 0;
d->timeout = 0.0;
}

void AbstractLink::takeOver(Socket *openSocket)
Expand All @@ -189,7 +189,7 @@ void AbstractLink::disconnect()
{
DE_ASSERT(d->socket.get() != nullptr);

d->timeout = 0;
d->timeout = 0.0;
d->socket->close(); // emits signal

d->status = Disconnected;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/shell/src/localserver.cpp
Expand Up @@ -175,7 +175,7 @@ bool LocalServer::isRunning() const
Link *LocalServer::openLink()
{
if (!isRunning()) return nullptr;
return new Link(String::format("localhost:%d", d->port), 30);
return new Link(String::format("localhost:%d", d->port), 30.0);
}

NativePath LocalServer::errorLogPath() const
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libs/shell/src/serverfinder.cpp
Expand Up @@ -29,7 +29,7 @@

namespace de { namespace shell {

static TimeSpan MSG_EXPIRATION_SECS = 4;
static TimeSpan MSG_EXPIRATION_SECS = 4.0;

DE_PIMPL(ServerFinder)
, DE_OBSERVES(Beacon, Discovery)
Expand Down Expand Up @@ -137,7 +137,7 @@ ServerFinder::ServerFinder() : d(new Impl(this))

if (!App::appExists() || !App::commandLine().has("-nodiscovery"))
{
d->beacon.discover(0 /* no timeout */, 2);
d->beacon.discover(0.0 /* no timeout */, 2.0);
}
}
catch (Beacon::PortError const &er)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/tests/test_timer/main.cpp
Expand Up @@ -35,14 +35,14 @@ int main(int argc, char **argv)

Timer quittingTime;
debug("Timer %p created", &quittingTime);
quittingTime.setInterval(3);
quittingTime.setInterval(3.0);
quittingTime.setSingleShot(true);
quittingTime.audienceForTrigger() += [&](){ app.quit(12345); };
quittingTime.start();

Timer test;
test.audienceForTrigger() += [](){ debug("Testing!"); };
test.start(1);
test.start(1.0);

int code = app.exec();
debug("Event loop returned %i", code);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/tools/shell-text/src/shellapp.cpp
Expand Up @@ -178,7 +178,7 @@ void ShellApp::openConnection(String const &address)
LOG_NET_NOTE("Opening connection to %s") << address;

// Keep trying to connect to 30 seconds.
d->link = new Link(address, 30);
d->link = new Link(address, 30.0);
d->status->setShellLink(d->link);

d->link->audienceForPacketsReady() += [this]() { handleIncomingPackets(); };
Expand Down
15 changes: 6 additions & 9 deletions doomsday/tools/shell-text/src/statuswidget.cpp
Expand Up @@ -25,16 +25,13 @@ using namespace de::shell;

DE_PIMPL(StatusWidget)
{
Link * link;
Link * link{nullptr};
Timer updateTimer;
String gameMode;
String rules;
String mapId;

Impl(Public &i) : Base(i), link(nullptr)
{
//updateTimer = new QTimer(thisPublic);
}
Impl(Public * i) : Base(i) {}

void refresh()
{
Expand All @@ -43,7 +40,7 @@ DE_PIMPL(StatusWidget)

void linkConnected()
{
updateTimer.start(1000);
updateTimer.start(1.0);
self().redraw();
}

Expand All @@ -55,7 +52,7 @@ DE_PIMPL(StatusWidget)
};

StatusWidget::StatusWidget(String const &name)
: Widget(name), d(new Impl(*this))
: Widget(name), d(new Impl(this))
{
d->updateTimer.audienceForTrigger() += [this]() { d->refresh(); };
}
Expand All @@ -78,8 +75,8 @@ void StatusWidget::setShellLink(Link *link)
void StatusWidget::setGameState(String const &mode, String const &rules, String const &mapId)
{
d->gameMode = mode;
d->rules = rules;
d->mapId = mapId;
d->rules = rules;
d->mapId = mapId;

redraw();
}
Expand Down

0 comments on commit 408722c

Please sign in to comment.