removed toUint64Cell/fromUint64Cell, closed #314

This commit is contained in:
rachytski 2012-01-12 21:13:38 +04:00 committed by Alex Zolotarev
parent 17a67319e5
commit 8be29e4490
6 changed files with 34 additions and 44 deletions

View file

@ -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)

View file

@ -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<Tiler::RectInfo> const TileCache::keys() const
{
set<uint64_t> keys = m_cache.Keys();
return m_cache.Keys();
/* set<uint64_t> keys = m_cache.Keys();
set<Tiler::RectInfo> rects;
for (set<uint64_t>::const_iterator it = keys.begin(); it != keys.end(); ++it)
@ -48,35 +49,35 @@ set<Tiler::RectInfo> 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;
}

View file

@ -35,7 +35,7 @@ public:
private:
my::MRUCache<uint64_t, Entry, EntryValueTraits> m_cache;
my::MRUCache<Tiler::RectInfo, Entry, EntryValueTraits> m_cache;
threads::Mutex m_lock;
TileCache(TileCache const & src);

View file

@ -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;

View file

@ -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

View file

@ -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: