From 1bfada54ea057efb7f596da5a457532f0fcb8605 Mon Sep 17 00:00:00 2001 From: rachytski Date: Tue, 14 Feb 2012 18:31:35 +0400 Subject: [PATCH] precalculating the minimum size of TileCache. --- .../jni/com/mapswithme/platform/Platform.cpp | 42 +++++++++++++------ map/screen_coverage.cpp | 4 +- platform/platform.hpp | 2 + platform/platform_qt.cpp | 7 +++- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp index b4178a978f..b56fd54f73 100644 --- a/android/jni/com/mapswithme/platform/Platform.cpp +++ b/android/jni/com/mapswithme/platform/Platform.cpp @@ -17,26 +17,38 @@ public: double const log2 = log(2.0); - screenWidth = static_cast(pow(2.0, ceil(log(double(screenWidth)) / log2))); - screenHeight = static_cast(pow(2.0, ceil(log(double(screenHeight)) / log2))); + size_t ceiledScreenWidth = static_cast(pow(2.0, ceil(log(double(screenWidth)) / log2))); + size_t ceiledScreenHeight = static_cast(pow(2.0, ceil(log(double(screenHeight)) / log2))); - size_t screenSize = max(screenWidth, screenHeight); + size_t ceiledScreenSize = max(ceiledScreenWidth, ceiledScreenHeight); - m_tileSize = min(max(max(screenWidth, screenHeight) / 2, 128), 512); + m_tileSize = min(max(ceiledScreenSize / 2, (size_t)128), (size_t)512); int k = static_cast((256.0 / m_tileSize) * (256.0 / m_tileSize)); /// calculating how much tiles we need for the screen of such size - /// pure magic ;) + m_maxTilesCount = 0; - double rotatedScreenCircleDiameter = sqrt(screenSize * screenSize + screenSize * screenSize); - int tilesOnOneSide = ceil(rotatedScreenCircleDiameter / (m_tileSize / 1.05 / 2)); - /// hardcoding the fact, that we are computing screen coverage - /// on slightly enlarged screen rect to produce effect of precaching. - ++tilesOnOneSide; - int singleScreenTilesCount = tilesOnOneSide * tilesOnOneSide; - m_maxTilesCount = singleScreenTilesCount * 2; + m_preCachingDepth = 3; + + /// calculating for non-rotated screen + + for (unsigned i = 0; i < m_preCachingDepth; ++i) + { + /// minimum size of tile on the screen + int minTileSize = floor((m_tileSize << i) / 1.05 / 2.0) - 1; + int tilesOnXSide = ceil(screenWidth / minTileSize) + 1; + int tilesOnYSide = ceil(screenHeight / minTileSize) + 1; + /// tiles in the single screen + int singleScreenTilesCount = tilesOnXSide * tilesOnYSide; + + int curLevelTilesCount = singleScreenTilesCount * 2; + + m_maxTilesCount += curLevelTilesCount; + + LOG(LINFO, ("on", i, "depth we need", curLevelTilesCount, "tiles")); + } LOG(LINFO, ("minimum amount of tiles needed is", m_maxTilesCount)); @@ -70,6 +82,7 @@ public: string m_skinName; int m_maxTilesCount; size_t m_tileSize; + size_t m_preCachingDepth; }; double Platform::VisualScale() const @@ -92,6 +105,11 @@ int Platform::TileSize() const return m_impl->m_tileSize; } +int Platform::PreCachingDepth() const +{ + return m_impl->m_preCachingDepth; +} + namespace android { Platform::~Platform() diff --git a/map/screen_coverage.cpp b/map/screen_coverage.cpp index 81f719e92e..b6a3cfacd5 100644 --- a/map/screen_coverage.cpp +++ b/map/screen_coverage.cpp @@ -1,5 +1,7 @@ #include "../base/SRC_FIRST.hpp" +#include "../platform/platform.hpp" + #include "../std/bind.hpp" #include "../std/set.hpp" #include "../std/algorithm.hpp" @@ -174,7 +176,7 @@ void ScreenCoverage::SetScreen(ScreenBase const & screen) TileSet prevTiles; m_tiler.currentLevelTiles(allRects); - m_tiler.prevLevelTiles(allPrevRects, 1); + m_tiler.prevLevelTiles(allPrevRects, GetPlatform().PreCachingDepth()); TileCache * tileCache = &m_tileRenderer->GetTileCache(); diff --git a/platform/platform.hpp b/platform/platform.hpp index e73832d640..6991f2db8a 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -120,6 +120,8 @@ public: int VideoMemoryLimit() const; + int PreCachingDepth() const; + string DeviceName() const; int ScaleEtalonSize() const; diff --git a/platform/platform_qt.cpp b/platform/platform_qt.cpp index cf6d25b979..92f987b467 100644 --- a/platform/platform_qt.cpp +++ b/platform/platform_qt.cpp @@ -71,7 +71,12 @@ void Platform::GetFontNames(FilesList & res) const int Platform::MaxTilesCount() const { - return 100; + return 200; +} + +int Platform::PreCachingDepth() const +{ + return 3; } int Platform::TileSize() const