rename time => timestamp to avoid naming conflicts

This commit is contained in:
Konstantin Käfer
2014-06-27 15:52:45 +02:00
parent 6de9d9769e
commit 6d9de75732
15 changed files with 79 additions and 79 deletions

View File

@@ -105,8 +105,8 @@ public:
inline std::shared_ptr<SpriteAtlas> getSpriteAtlas() { return spriteAtlas; }
inline std::shared_ptr<Texturepool> getTexturepool() { return texturepool; }
inline std::shared_ptr<uv::loop> getLoop() { return loop; }
inline time getAnimationTime() const { return animationTime; }
inline time getTime() const { return animationTime; }
inline timestamp getAnimationTime() const { return animationTime; }
inline timestamp getTime() const { return animationTime; }
private:
// uv async callbacks
@@ -163,7 +163,7 @@ private:
std::string styleJSON = "";
bool debug = false;
time animationTime = 0;
timestamp animationTime = 0;
int indent = 0;

View File

@@ -58,7 +58,7 @@ private:
private:
// Stores the time when this source was most recently updated.
time updated = 0;
timestamp updated = 0;
std::map<Tile::ID, std::unique_ptr<Tile>> tiles;
std::map<Tile::ID, std::weak_ptr<TileData>> tile_data;

View File

@@ -23,18 +23,18 @@ public:
uint16_t fb_width, uint16_t fb_height);
// Position
void moveBy(double dx, double dy, time duration = 0);
void setLonLat(double lon, double lat, time duration = 0);
void setLonLatZoom(double lon, double lat, double zoom, time duration = 0);
void moveBy(double dx, double dy, timestamp duration = 0);
void setLonLat(double lon, double lat, timestamp duration = 0);
void setLonLatZoom(double lon, double lat, double zoom, timestamp duration = 0);
void getLonLat(double& lon, double& lat) const;
void getLonLatZoom(double& lon, double& lat, double& zoom) const;
void startPanning();
void stopPanning();
// Zoom
void scaleBy(double ds, double cx = -1, double cy = -1, time duration = 0);
void setScale(double scale, double cx = -1, double cy = -1, time duration = 0);
void setZoom(double zoom, time duration = 0);
void scaleBy(double ds, double cx = -1, double cy = -1, timestamp duration = 0);
void setScale(double scale, double cx = -1, double cy = -1, timestamp duration = 0);
void setZoom(double zoom, timestamp duration = 0);
double getZoom() const;
double getScale() const;
void startScaling();
@@ -43,8 +43,8 @@ public:
double getMaxZoom() const;
// Angle
void rotateBy(double sx, double sy, double ex, double ey, time duration = 0);
void setAngle(double angle, time duration = 0);
void rotateBy(double sx, double sy, double ex, double ey, timestamp duration = 0);
void setAngle(double angle, timestamp duration = 0);
void setAngle(double angle, double cx, double cy);
double getAngle() const;
void startRotating();
@@ -53,7 +53,7 @@ public:
// Transitions
bool needsTransition() const;
void updateTransitions(time now);
void updateTransitions(timestamp now);
void cancelTransitions();
// Transform state
@@ -63,10 +63,10 @@ public:
private:
// Functions prefixed with underscores will *not* perform any locks. It is the caller's
// responsibility to lock this object.
void _moveBy(double dx, double dy, time duration = 0);
void _setScale(double scale, double cx, double cy, time duration = 0);
void _setScaleXY(double new_scale, double xn, double yn, time duration = 0);
void _setAngle(double angle, time duration = 0);
void _moveBy(double dx, double dy, timestamp duration = 0);
void _setScale(double scale, double cx, double cy, timestamp duration = 0);
void _setScaleXY(double new_scale, double xn, double yn, timestamp duration = 0);
void _setAngle(double angle, timestamp duration = 0);
void _clearPanning();
void _clearRotating();
void _clearScaling();

View File

@@ -11,7 +11,7 @@
namespace llmr {
struct FrameSnapshot {
explicit inline FrameSnapshot(time timestamp, float z) : timestamp(timestamp), z(z) {}
explicit inline FrameSnapshot(timestamp timestamp, float z) : timestamp(timestamp), z(z) {}
float timestamp;
float z;
};
@@ -19,9 +19,9 @@ struct FrameSnapshot {
class FrameHistory {
public:
// Record frame history that will be used to calculate fading params
void record(time now, float zoom);
void record(timestamp now, float zoom);
bool needsAnimation(time duration) const;
bool needsAnimation(timestamp duration) const;
public:
std::deque<FrameSnapshot> history;

View File

@@ -61,7 +61,7 @@ public:
void cascade(float z);
bool needsTransition() const;
void updateTransitions(time now);
void updateTransitions(timestamp now);
void cancelTransitions();
void setDefaultTransitionDuration(uint64_t duration_milliseconds = 0);

View File

@@ -31,7 +31,7 @@ public:
// transitions
void beginFadeInTransition();
bool needsTransition() const;
void updateTransitions(time now);
void updateTransitions(timestamp now);
public:
// loaded image dimensions

View File

@@ -5,7 +5,7 @@
namespace llmr {
typedef uint64_t time;
typedef uint64_t timestamp;
namespace util {
@@ -13,29 +13,29 @@ namespace util {
// Returns time in nanoseconds since an arbitrary point in the past. This has
// no relation to the current time, but is continuously increasing, so
// comparisons between different timestamps produce meaningful values.
inline time now() {
inline timestamp now() {
return uv_hrtime();
}
}
// used for time conversions
constexpr time operator"" _nanoseconds (long double ns) { return ns; }
constexpr time operator"" _nanosecond (long double ns) { return ns; }
constexpr time operator"" _microseconds (long double us) { return us * 1e3; }
constexpr time operator"" _microsecond (long double us) { return us * 1e3; }
constexpr time operator"" _milliseconds (long double ms) { return ms * 1e6; }
constexpr time operator"" _millisecond (long double ms) { return ms * 1e6; }
constexpr time operator"" _seconds (long double s) { return s * 1e9; }
constexpr time operator"" _second (long double s) { return s * 1e9; }
constexpr timestamp operator"" _nanoseconds (long double ns) { return ns; }
constexpr timestamp operator"" _nanosecond (long double ns) { return ns; }
constexpr timestamp operator"" _microseconds (long double us) { return us * 1e3; }
constexpr timestamp operator"" _microsecond (long double us) { return us * 1e3; }
constexpr timestamp operator"" _milliseconds (long double ms) { return ms * 1e6; }
constexpr timestamp operator"" _millisecond (long double ms) { return ms * 1e6; }
constexpr timestamp operator"" _seconds (long double s) { return s * 1e9; }
constexpr timestamp operator"" _second (long double s) { return s * 1e9; }
constexpr time operator"" _nanoseconds (unsigned long long ns) { return ns; }
constexpr time operator"" _nanosecond (unsigned long long ns) { return ns; }
constexpr time operator"" _microseconds (unsigned long long us) { return us * 1e3; }
constexpr time operator"" _microsecond (unsigned long long us) { return us * 1e3; }
constexpr time operator"" _milliseconds (unsigned long long ms) { return ms * 1e6; }
constexpr time operator"" _millisecond (unsigned long long ms) { return ms * 1e6; }
constexpr time operator"" _seconds (unsigned long long s) { return s * 1e9; }
constexpr time operator"" _second (unsigned long long s) { return s * 1e9; }
constexpr timestamp operator"" _nanoseconds (unsigned long long ns) { return ns; }
constexpr timestamp operator"" _nanosecond (unsigned long long ns) { return ns; }
constexpr timestamp operator"" _microseconds (unsigned long long us) { return us * 1e3; }
constexpr timestamp operator"" _microsecond (unsigned long long us) { return us * 1e3; }
constexpr timestamp operator"" _milliseconds (unsigned long long ms) { return ms * 1e6; }
constexpr timestamp operator"" _millisecond (unsigned long long ms) { return ms * 1e6; }
constexpr timestamp operator"" _seconds (unsigned long long s) { return s * 1e9; }
constexpr timestamp operator"" _second (unsigned long long s) { return s * 1e9; }
}

View File

@@ -15,18 +15,18 @@ public:
complete
};
inline transition(time start, time duration)
inline transition(timestamp start, timestamp duration)
: start(start),
duration(duration) {}
inline float progress(time now) const {
inline float progress(timestamp now) const {
if (duration == 0) return 1;
if (start > now) return 0;
return (float)(now - start) / duration;
}
virtual state update(time now) const = 0;
virtual state update(timestamp now) const = 0;
virtual ~transition();
protected:
@@ -36,19 +36,19 @@ protected:
std::array<float, 2> interpolateFloatArray(std::array<float, 2> from, std::array<float, 2> to, double t) const;
protected:
const time start, duration;
const timestamp start, duration;
};
template <typename T>
class ease_transition : public transition {
public:
ease_transition(T from, T to, T& value, time start, time duration)
ease_transition(T from, T to, T& value, timestamp start, timestamp duration)
: transition(start, duration),
from(from),
to(to),
value(value) {}
state update(time now) const;
state update(timestamp now) const;
private:
const T from, to;
@@ -59,12 +59,12 @@ private:
template <typename T>
class timeout : public transition {
public:
timeout(T final_value, T& value, time start, time duration)
timeout(T final_value, T& value, timestamp start, timestamp duration)
: transition(start, duration),
final_value(final_value),
value(value) {}
state update(time now) const {
state update(timestamp now) const {
if (progress(now) >= 1) {
value = final_value;
return complete;

View File

@@ -44,13 +44,13 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio,
#pragma mark - Position
void Transform::moveBy(const double dx, const double dy, const time duration) {
void Transform::moveBy(const double dx, const double dy, const timestamp duration) {
uv::writelock lock(mtx);
_moveBy(dx, dy, duration);
}
void Transform::_moveBy(const double dx, const double dy, const time duration) {
void Transform::_moveBy(const double dx, const double dy, const timestamp duration) {
// This is only called internally, so we don't need a lock here.
final.x = current.x + std::cos(current.angle) * dx + std::sin(current.angle) * dy;
@@ -69,7 +69,7 @@ void Transform::_moveBy(const double dx, const double dy, const time duration) {
current.y = final.y;
} else {
// Use a common start time for all of the transitions to avoid divergent transitions.
time start = util::now();
timestamp start = util::now();
transitions.emplace_front(
std::make_shared<util::ease_transition<double>>(current.x, final.x, current.x, start, duration));
transitions.emplace_front(
@@ -79,7 +79,7 @@ void Transform::_moveBy(const double dx, const double dy, const time duration) {
platform::notify_map_change();
}
void Transform::setLonLat(const double lon, const double lat, const time duration) {
void Transform::setLonLat(const double lon, const double lat, const timestamp duration) {
uv::writelock lock(mtx);
const double f = std::fmin(std::fmax(std::sin(D2R * lat), -0.9999), 0.9999);
@@ -90,7 +90,7 @@ void Transform::setLonLat(const double lon, const double lat, const time duratio
}
void Transform::setLonLatZoom(const double lon, const double lat, const double zoom,
const time duration) {
const timestamp duration) {
uv::writelock lock(mtx);
double new_scale = std::pow(2.0, zoom);
@@ -128,7 +128,7 @@ void Transform::startPanning() {
// Add a 200ms timeout for resetting this to false
current.panning = true;
time start = util::now();
timestamp start = util::now();
pan_timeout = std::make_shared<util::timeout<bool>>(false, current.panning, start, 200_milliseconds);
transitions.emplace_front(pan_timeout);
}
@@ -149,7 +149,7 @@ void Transform::_clearPanning() {
#pragma mark - Zoom
void Transform::scaleBy(const double ds, const double cx, const double cy, const time duration) {
void Transform::scaleBy(const double ds, const double cx, const double cy, const timestamp duration) {
uv::writelock lock(mtx);
// clamp scale to min/max values
@@ -164,13 +164,13 @@ void Transform::scaleBy(const double ds, const double cx, const double cy, const
}
void Transform::setScale(const double scale, const double cx, const double cy,
const time duration) {
const timestamp duration) {
uv::writelock lock(mtx);
_setScale(scale, cx, cy, duration);
}
void Transform::setZoom(const double zoom, const time duration) {
void Transform::setZoom(const double zoom, const timestamp duration) {
uv::writelock lock(mtx);
_setScale(std::pow(2.0, zoom), -1, -1, duration);
@@ -195,7 +195,7 @@ void Transform::startScaling() {
// Add a 200ms timeout for resetting this to false
current.scaling = true;
time start = util::now();
timestamp start = util::now();
scale_timeout = std::make_shared<util::timeout<bool>>(false, current.scaling, start, 200_milliseconds);
transitions.emplace_front(scale_timeout);
}
@@ -228,7 +228,7 @@ void Transform::_clearScaling() {
}
}
void Transform::_setScale(double new_scale, double cx, double cy, const time duration) {
void Transform::_setScale(double new_scale, double cx, double cy, const timestamp duration) {
// This is only called internally, so we don't need a lock here.
// Ensure that we don't zoom in further than the maximum allowed.
@@ -262,7 +262,7 @@ void Transform::_setScale(double new_scale, double cx, double cy, const time dur
}
void Transform::_setScaleXY(const double new_scale, const double xn, const double yn,
const time duration) {
const timestamp duration) {
// This is only called internally, so we don't need a lock here.
final.scale = new_scale;
@@ -280,7 +280,7 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl
current.y = final.y;
} else {
// Use a common start time for all of the transitions to avoid divergent transitions.
time start = util::now();
timestamp start = util::now();
transitions.emplace_front(std::make_shared<util::ease_transition<double>>(
current.scale, final.scale, current.scale, start, duration));
transitions.emplace_front(
@@ -313,7 +313,7 @@ void Transform::constrain(double& scale, double& y) const {
#pragma mark - Angle
void Transform::rotateBy(const double start_x, const double start_y, const double end_x,
const double end_y, const time duration) {
const double end_y, const timestamp duration) {
uv::writelock lock(mtx);
double center_x = current.width / 2, center_y = current.height / 2;
@@ -343,7 +343,7 @@ void Transform::rotateBy(const double start_x, const double start_y, const doubl
_setAngle(ang, duration);
}
void Transform::setAngle(const double new_angle, const time duration) {
void Transform::setAngle(const double new_angle, const timestamp duration) {
uv::writelock lock(mtx);
_setAngle(new_angle, duration);
@@ -367,7 +367,7 @@ void Transform::setAngle(const double new_angle, const double cx, const double c
}
}
void Transform::_setAngle(double new_angle, const time duration) {
void Transform::_setAngle(double new_angle, const timestamp duration) {
// This is only called internally, so we don't need a lock here.
while (new_angle > M_PI)
@@ -383,7 +383,7 @@ void Transform::_setAngle(double new_angle, const time duration) {
if (duration == 0) {
current.angle = final.angle;
} else {
time start = util::now();
timestamp start = util::now();
transitions.emplace_front(std::make_shared<util::ease_transition<double>>(
current.angle, final.angle, current.angle, start, duration));
}
@@ -404,7 +404,7 @@ void Transform::startRotating() {
// Add a 200ms timeout for resetting this to false
current.rotating = true;
time start = util::now();
timestamp start = util::now();
rotate_timeout = std::make_shared<util::timeout<bool>>(false, current.rotating, start, 200_milliseconds);
transitions.emplace_front(rotate_timeout);
}
@@ -437,7 +437,7 @@ bool Transform::needsTransition() const {
return !transitions.empty();
}
void Transform::updateTransitions(const time now) {
void Transform::updateTransitions(const timestamp now) {
uv::writelock lock(mtx);
transitions.remove_if([now](const std::shared_ptr<util::transition> &transition) {

View File

@@ -3,7 +3,7 @@
using namespace llmr;
// Record frame history that will be used to calculate fading params
void FrameHistory::record(time now, float zoom) {
void FrameHistory::record(timestamp now, float zoom) {
// first frame ever
if (!history.size()) {
history.emplace_back(FrameSnapshot{0, zoom});
@@ -15,7 +15,7 @@ void FrameHistory::record(time now, float zoom) {
}
}
bool FrameHistory::needsAnimation(const time duration) const {
bool FrameHistory::needsAnimation(const timestamp duration) const {
if (!history.size()) {
return false;
}

View File

@@ -47,8 +47,8 @@ void Painter::renderText(TextBucket& bucket, std::shared_ptr<StyleLayer> layer_d
textShader->setZoom((map.getState().getNormalizedZoom() - zoomAdjust) * 10); // current zoom level
// Label fading
const time duration = 300_milliseconds;
const time currentTime = util::now();
const timestamp duration = 300_milliseconds;
const timestamp currentTime = util::now();
std::deque<FrameSnapshot> &history = frameHistory.history;

View File

@@ -201,7 +201,7 @@ bool Style::needsTransition() const {
return false;
}
void Style::updateTransitions(time now) {
void Style::updateTransitions(timestamp now) {
uv::writelock lock(mtx);
}

View File

@@ -69,7 +69,7 @@ void Raster::bind(bool linear) {
}
void Raster::beginFadeInTransition() {
time start = util::now();
timestamp start = util::now();
fade_transition = std::make_shared<util::ease_transition<double>>(opacity, 1.0, opacity, start, 250_milliseconds);
}
@@ -77,7 +77,7 @@ bool Raster::needsTransition() const {
return fade_transition != nullptr;
}
void Raster::updateTransitions(time now) {
void Raster::updateTransitions(timestamp now) {
if (fade_transition->update(now) == util::transition::complete) {
fade_transition = nullptr;
}

View File

@@ -18,7 +18,7 @@ timer::timer(const std::string &name) : name(name), start(now()) {
}
void timer::report(const std::string &name) {
time duration = now() - start;
timestamp duration = now() - start;
std::cerr << std::string((indent - 1) * 4, ' ')
<< name << ": "
<< (double)(duration) / 1_millisecond

View File

@@ -28,7 +28,7 @@ std::array<float, 2> transition::interpolateFloatArray(std::array<float, 2> from
}
template <>
transition::state ease_transition<double>::update(llmr::time now) const {
transition::state ease_transition<double>::update(timestamp now) const {
float t = progress(now);
if (t >= 1) {
value = to;
@@ -40,7 +40,7 @@ transition::state ease_transition<double>::update(llmr::time now) const {
}
template <>
transition::state ease_transition<llmr::Color>::update(llmr::time now) const {
transition::state ease_transition<llmr::Color>::update(timestamp now) const {
float t = progress(now);
if (t >= 1) {
value = to;
@@ -52,7 +52,7 @@ transition::state ease_transition<llmr::Color>::update(llmr::time now) const {
}
template <>
transition::state ease_transition<float>::update(llmr::time now) const {
transition::state ease_transition<float>::update(timestamp now) const {
float t = progress(now);
if (t >= 1) {
value = to;
@@ -64,7 +64,7 @@ transition::state ease_transition<float>::update(llmr::time now) const {
}
template <>
transition::state ease_transition<std::array<float, 2>>::update(llmr::time now) const {
transition::state ease_transition<std::array<float, 2>>::update(timestamp now) const {
float t = progress(now);
if (t >= 1) {
value = to;