From 8be29e449016729a5562fe3b766a8169b21823f6 Mon Sep 17 00:00:00 2001 From: rachytski Date: Thu, 12 Jan 2012 21:13:38 +0400 Subject: [PATCH] removed toUint64Cell/fromUint64Cell, closed #314 --- map/screen_coverage.cpp | 2 +- map/tile_cache.cpp | 19 ++++++++++--------- map/tile_cache.hpp | 2 +- map/tile_renderer.cpp | 9 +++++++-- map/tiler.cpp | 41 ++++++++++++++--------------------------- map/tiler.hpp | 5 +---- 6 files changed, 34 insertions(+), 44 deletions(-) diff --git a/map/screen_coverage.cpp b/map/screen_coverage.cpp index 556b4958d5..c40df4a948 100644 --- a/map/screen_coverage.cpp +++ b/map/screen_coverage.cpp @@ -117,7 +117,7 @@ void ScreenCoverage::Remove(Tile const *) bool LessRectInfo::operator()(Tile const * l, Tile const * r) const { - return l->m_rectInfo.toUInt64Cell() < r->m_rectInfo.toUInt64Cell(); + return l->m_rectInfo < r->m_rectInfo; } void ScreenCoverage::SetScreen(ScreenBase const & screen) diff --git a/map/tile_cache.cpp b/map/tile_cache.cpp index c82b80f37d..a8adf6a6fa 100644 --- a/map/tile_cache.cpp +++ b/map/tile_cache.cpp @@ -13,7 +13,7 @@ TileCache::TileCache(size_t maxCacheSize) void TileCache::addTile(Tiler::RectInfo const & key, Entry const & entry) { - m_cache.Add(key.toUInt64Cell(), entry, 1); + m_cache.Add(key, entry, 1); } void TileCache::readLock() @@ -38,7 +38,8 @@ void TileCache::writeUnlock() set const TileCache::keys() const { - set keys = m_cache.Keys(); + return m_cache.Keys(); +/* set keys = m_cache.Keys(); set rects; for (set::const_iterator it = keys.begin(); it != keys.end(); ++it) @@ -48,35 +49,35 @@ set const TileCache::keys() const rects.insert(v); } - return rects; + return rects;*/ } bool TileCache::hasTile(Tiler::RectInfo const & key) { - return m_cache.HasElem(key.toUInt64Cell()); + return m_cache.HasElem(key); } void TileCache::lockTile(Tiler::RectInfo const & key) { - m_cache.LockElem(key.toUInt64Cell()); + m_cache.LockElem(key); } size_t TileCache::lockCount(Tiler::RectInfo const & key) { - return m_cache.LockCount(key.toUInt64Cell()); + return m_cache.LockCount(key); } void TileCache::unlockTile(Tiler::RectInfo const & key) { - m_cache.UnlockElem(key.toUInt64Cell()); + m_cache.UnlockElem(key); } void TileCache::touchTile(Tiler::RectInfo const & key) { - m_cache.Touch(key.toUInt64Cell()); + m_cache.Touch(key); } Tile const & TileCache::getTile(Tiler::RectInfo const & key) { - return m_cache.Find(key.toUInt64Cell()).m_tile; + return m_cache.Find(key).m_tile; } diff --git a/map/tile_cache.hpp b/map/tile_cache.hpp index dd430fdc93..316e11760f 100644 --- a/map/tile_cache.hpp +++ b/map/tile_cache.hpp @@ -35,7 +35,7 @@ public: private: - my::MRUCache m_cache; + my::MRUCache m_cache; threads::Mutex m_lock; TileCache(TileCache const & src); diff --git a/map/tile_renderer.cpp b/map/tile_renderer.cpp index b0b627eb4f..f932a7f04f 100644 --- a/map/tile_renderer.cpp +++ b/map/tile_renderer.cpp @@ -155,8 +155,13 @@ void TileRenderer::DrawTile(core::CommandsQueue::Environment const & env, std::stringstream out; out << rectInfo.m_y << ", " << rectInfo.m_x << ", " << rectInfo.m_tileScale << ", " << rectInfo.m_drawScale; - drawer->screen()->drawText(yg::FontDesc(), renderRect.Center(), yg::EPosCenter, out.str().c_str(), 0, false); -*/ + drawer->screen()->drawText(yg::FontDesc(12, yg::Color(0, 0, 0, 255), true), + renderRect.Center(), + yg::EPosCenter, + out.str().c_str(), + 0, + false);*/ + frameScreen.SetFromRect(m2::AnyRectD(rectInfo.m_rect)); m2::RectD selectRect; diff --git a/map/tiler.cpp b/map/tiler.cpp index 10856c95e5..d59a3a18dd 100644 --- a/map/tiler.cpp +++ b/map/tiler.cpp @@ -4,38 +4,17 @@ #include "../indexer/scales.hpp" #include "../base/logging.hpp" -uint64_t Tiler::RectInfo::toUInt64Cell() const -{ - /// pack y in 0-23 bits - /// pack x in 24-47 bits - /// pack tileScale in 48-55 bits - /// pack drawScale in 56-63 bits - - ASSERT(m_y <= 0xFFFFFF, ()); - ASSERT(m_x <= 0xFFFFFF, ()); - ASSERT(m_tileScale <= 0xFF, ()); - ASSERT(m_drawScale <= 0xFF, ()); - - return (m_y & 0xFFFFFF) - | ((m_x & 0xFFFFFF) << 24) - | (((uint64_t)m_tileScale & 0xFF) << 48) - | (((uint64_t)m_drawScale & 0xFF) << 56); -} - -void Tiler::RectInfo::fromUInt64Cell(uint64_t v) -{ - m_y = v & 0xFFFFFF; - m_x = (v >> 24) & 0xFFFFFF; - m_tileScale = (v >> 48) & 0xFF; - m_drawScale = (v >> 56) & 0xFF; -} - Tiler::RectInfo::RectInfo() : m_drawScale(0), m_tileScale(0), m_x(0), m_y(0) {} Tiler::RectInfo::RectInfo(int drawScale, int tileScale, int x, int y) : m_drawScale(drawScale), m_tileScale(tileScale), m_x(x), m_y(y) +{ + initRect(); +} + +void Tiler::RectInfo::initRect() { int k = 1 << m_tileScale; @@ -60,7 +39,15 @@ bool LessByDistance::operator()(Tiler::RectInfo const & l, Tiler::RectInfo const bool operator<(Tiler::RectInfo const & l, Tiler::RectInfo const & r) { - return l.toUInt64Cell() < r.toUInt64Cell(); + if (l.m_y != r.m_y) + return l.m_y < r.m_y; + if (l.m_x != r.m_x) + return l.m_x < r.m_x; + if (l.m_drawScale != r.m_drawScale) + return l.m_drawScale < r.m_drawScale; + if (l.m_tileScale != r.m_tileScale) + return l.m_tileScale < r.m_tileScale; + return false; } int Tiler::drawScale(ScreenBase const & s) const diff --git a/map/tiler.hpp b/map/tiler.hpp index 96e07e36ec..f8d89bc70f 100644 --- a/map/tiler.hpp +++ b/map/tiler.hpp @@ -22,10 +22,7 @@ public: RectInfo(); RectInfo(int drawScale, int tileScale, int x, int y); - /// pack scale, x, y into 64 bit word to use it as a cache key - uint64_t toUInt64Cell() const; - /// unpack 64bit integer and compute other parameters - void fromUInt64Cell(uint64_t v); + void initRect(); }; private: