From 6d9de7573202d4b2332667f2d685a0e73e7c0f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 27 Jun 2014 15:52:45 +0200 Subject: [PATCH] rename time => timestamp to avoid naming conflicts --- include/llmr/map/map.hpp | 6 ++-- include/llmr/map/source.hpp | 2 +- include/llmr/map/transform.hpp | 26 ++++++++--------- include/llmr/renderer/frame_history.hpp | 6 ++-- include/llmr/style/style.hpp | 2 +- include/llmr/util/raster.hpp | 2 +- include/llmr/util/time.hpp | 36 +++++++++++------------ include/llmr/util/transition.hpp | 16 +++++------ src/map/transform.cpp | 38 ++++++++++++------------- src/renderer/frame_history.cpp | 4 +-- src/renderer/painter_text.cpp | 4 +-- src/style/style.cpp | 2 +- src/util/raster.cpp | 4 +-- src/util/timer.cpp | 2 +- src/util/transition.cpp | 8 +++--- 15 files changed, 79 insertions(+), 79 deletions(-) diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index 2c412bd45..621fdb388 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -105,8 +105,8 @@ public: inline std::shared_ptr getSpriteAtlas() { return spriteAtlas; } inline std::shared_ptr getTexturepool() { return texturepool; } inline std::shared_ptr 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; diff --git a/include/llmr/map/source.hpp b/include/llmr/map/source.hpp index c27250858..93dabdc7c 100644 --- a/include/llmr/map/source.hpp +++ b/include/llmr/map/source.hpp @@ -58,7 +58,7 @@ private: private: // Stores the time when this source was most recently updated. - time updated = 0; + timestamp updated = 0; std::map> tiles; std::map> tile_data; diff --git a/include/llmr/map/transform.hpp b/include/llmr/map/transform.hpp index 63b75d43d..c4474ff02 100644 --- a/include/llmr/map/transform.hpp +++ b/include/llmr/map/transform.hpp @@ -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(); diff --git a/include/llmr/renderer/frame_history.hpp b/include/llmr/renderer/frame_history.hpp index e45bd527b..412fce92b 100644 --- a/include/llmr/renderer/frame_history.hpp +++ b/include/llmr/renderer/frame_history.hpp @@ -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 history; diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index 71e1997e7..73ad6d6bd 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -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); diff --git a/include/llmr/util/raster.hpp b/include/llmr/util/raster.hpp index fb3857876..cbc342d56 100644 --- a/include/llmr/util/raster.hpp +++ b/include/llmr/util/raster.hpp @@ -31,7 +31,7 @@ public: // transitions void beginFadeInTransition(); bool needsTransition() const; - void updateTransitions(time now); + void updateTransitions(timestamp now); public: // loaded image dimensions diff --git a/include/llmr/util/time.hpp b/include/llmr/util/time.hpp index f9e3cc05c..9a27cdbe3 100644 --- a/include/llmr/util/time.hpp +++ b/include/llmr/util/time.hpp @@ -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; } } diff --git a/include/llmr/util/transition.hpp b/include/llmr/util/transition.hpp index a981f6e83..3085b3455 100644 --- a/include/llmr/util/transition.hpp +++ b/include/llmr/util/transition.hpp @@ -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 interpolateFloatArray(std::array from, std::array to, double t) const; protected: - const time start, duration; + const timestamp start, duration; }; template 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 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; diff --git a/src/map/transform.cpp b/src/map/transform.cpp index adfa41c39..c7bbbfdf7 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -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>(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>(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>(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>( 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>( 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>(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 &transition) { diff --git a/src/renderer/frame_history.cpp b/src/renderer/frame_history.cpp index c93d38818..e73eaf626 100644 --- a/src/renderer/frame_history.cpp +++ b/src/renderer/frame_history.cpp @@ -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; } diff --git a/src/renderer/painter_text.cpp b/src/renderer/painter_text.cpp index 40a4edf89..47fea57c9 100644 --- a/src/renderer/painter_text.cpp +++ b/src/renderer/painter_text.cpp @@ -47,8 +47,8 @@ void Painter::renderText(TextBucket& bucket, std::shared_ptr 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 &history = frameHistory.history; diff --git a/src/style/style.cpp b/src/style/style.cpp index 87cfd81f8..d0077d719 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -201,7 +201,7 @@ bool Style::needsTransition() const { return false; } -void Style::updateTransitions(time now) { +void Style::updateTransitions(timestamp now) { uv::writelock lock(mtx); } diff --git a/src/util/raster.cpp b/src/util/raster.cpp index 82ac0bda5..d4b64d0ed 100644 --- a/src/util/raster.cpp +++ b/src/util/raster.cpp @@ -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>(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; } diff --git a/src/util/timer.cpp b/src/util/timer.cpp index 56ad4fbbe..6d4fc1135 100644 --- a/src/util/timer.cpp +++ b/src/util/timer.cpp @@ -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 diff --git a/src/util/transition.cpp b/src/util/transition.cpp index 7f4b544fe..10f94c78b 100644 --- a/src/util/transition.cpp +++ b/src/util/transition.cpp @@ -28,7 +28,7 @@ std::array transition::interpolateFloatArray(std::array from } template <> -transition::state ease_transition::update(llmr::time now) const { +transition::state ease_transition::update(timestamp now) const { float t = progress(now); if (t >= 1) { value = to; @@ -40,7 +40,7 @@ transition::state ease_transition::update(llmr::time now) const { } template <> -transition::state ease_transition::update(llmr::time now) const { +transition::state ease_transition::update(timestamp now) const { float t = progress(now); if (t >= 1) { value = to; @@ -52,7 +52,7 @@ transition::state ease_transition::update(llmr::time now) const { } template <> -transition::state ease_transition::update(llmr::time now) const { +transition::state ease_transition::update(timestamp now) const { float t = progress(now); if (t >= 1) { value = to; @@ -64,7 +64,7 @@ transition::state ease_transition::update(llmr::time now) const { } template <> -transition::state ease_transition>::update(llmr::time now) const { +transition::state ease_transition>::update(timestamp now) const { float t = progress(now); if (t >= 1) { value = to;