forked from organicmaps/organicmaps
Refactored storage - removed some unnecessary dependencies
This commit is contained in:
parent
8b936cc377
commit
46c7ff7125
13 changed files with 61 additions and 123 deletions
|
@ -13,7 +13,6 @@
|
|||
#include "../../../../../indexer/drawing_rules.hpp"
|
||||
|
||||
#include "../../../../../map/render_policy_st.hpp"
|
||||
#include "../../../../../map/partial_render_policy.hpp"
|
||||
#include "../../../../../map/tiling_render_policy_st.hpp"
|
||||
#include "../../../../../map/framework.hpp"
|
||||
|
||||
|
@ -48,7 +47,6 @@ namespace android
|
|||
ASSERT(g_framework == 0, ());
|
||||
g_framework = this;
|
||||
|
||||
m_work.InitStorage(m_storage);
|
||||
// @TODO refactor storage
|
||||
m_storage.ReInitCountries(false);
|
||||
}
|
||||
|
@ -88,7 +86,6 @@ namespace android
|
|||
p.m_glyphCacheID = m_rm->guiThreadGlyphCacheID();
|
||||
p.m_frameBuffer = make_shared_ptr(new yg::gl::FrameBuffer(true));
|
||||
p.m_skinName = pl.SkinName();
|
||||
p.m_useTinyStorage = true;
|
||||
|
||||
m_drawer = make_shared_ptr(new DrawerYG(p));
|
||||
}
|
||||
|
@ -117,9 +114,7 @@ namespace android
|
|||
2 * 1024 * 1024,
|
||||
1,
|
||||
yg::Rt8Bpp,
|
||||
true));
|
||||
|
||||
m_rm->initTinyStorage(300 * sizeof(yg::gl::Vertex), 600 * sizeof(unsigned short), 30);
|
||||
false));
|
||||
|
||||
Platform::FilesList fonts;
|
||||
pl.GetFontNames(fonts);
|
||||
|
@ -133,7 +128,7 @@ namespace android
|
|||
drule::rules().ForEachRule(make_all_invalid(GetPlatform().CpuCores() + 1));
|
||||
|
||||
// temporary workaround
|
||||
m_work.SetRenderPolicy(shared_ptr<RenderPolicy>(new PartialRenderPolicy(m_handle, bind(&::Framework<model::FeaturesFetcher>::DrawModel, &m_work, _1, _2, _3, _4, _5, false))));
|
||||
m_work.SetRenderPolicy(shared_ptr<RenderPolicy>(new RenderPolicyST(m_handle, bind(&::Framework<model::FeaturesFetcher>::DrawModel, &m_work, _1, _2, _3, _4, _5, false))));
|
||||
|
||||
m_rc = make_shared_ptr(new android::RenderContext());
|
||||
|
||||
|
@ -156,7 +151,7 @@ namespace android
|
|||
|
||||
storage::Storage & Framework::Storage()
|
||||
{
|
||||
return m_storage;
|
||||
return m_work.Storage();
|
||||
}
|
||||
|
||||
void Framework::Resize(int w, int h)
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
#include "../../../../../map/window_handle.hpp"
|
||||
#include "../../../../../map/feature_vec_model.hpp"
|
||||
|
||||
#include "../../../../../storage/storage.hpp"
|
||||
|
||||
namespace android
|
||||
{
|
||||
class Framework
|
||||
|
@ -30,8 +28,6 @@ namespace android
|
|||
shared_ptr<yg::gl::RenderContext> m_rc;
|
||||
|
||||
::Framework<model::FeaturesFetcher> m_work;
|
||||
storage::Storage m_storage;
|
||||
|
||||
|
||||
void CallRepaint();
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include "../../yg/internal/opengl.hpp"
|
||||
#include "../../yg/screen.hpp"
|
||||
#include "../../map/drawer_yg.hpp"
|
||||
#include "../../storage/storage.hpp"
|
||||
|
||||
typedef Framework<model::FeaturesFetcher> framework_t;
|
||||
|
||||
|
@ -19,7 +18,6 @@ typedef Framework<model::FeaturesFetcher> framework_t;
|
|||
|
||||
// @TODO Make m_framework and m_storage MapsAppDelegate properties instead of global variables.
|
||||
framework_t * m_framework = NULL;
|
||||
storage::Storage m_storage;
|
||||
|
||||
- (void) ZoomToRect: (m2::RectD const &) rect
|
||||
{
|
||||
|
@ -97,7 +95,7 @@ storage::Storage m_storage;
|
|||
|
||||
- (IBAction)OnSettingsClicked:(id)sender
|
||||
{
|
||||
[[[MapsAppDelegate theApp] settingsManager] Show:self WithStorage:&m_storage];
|
||||
[[[MapsAppDelegate theApp] settingsManager] Show:self WithStorage:&m_framework->Storage()];
|
||||
}
|
||||
|
||||
- (IBAction)OnSearchClicked:(id)sender
|
||||
|
@ -125,7 +123,6 @@ storage::Storage m_storage;
|
|||
shared_ptr<yg::ResourceManager> resourceManager = [(EAGLView*)self.view resourceManager];
|
||||
|
||||
m_framework = FrameworkFactory<model::FeaturesFetcher>::CreateFramework(windowHandle, 40);
|
||||
m_framework->InitStorage(m_storage);
|
||||
v.framework = m_framework;
|
||||
|
||||
m_StickyThreshold = 10;
|
||||
|
|
|
@ -111,25 +111,29 @@ void ForEachBenchmarkRecord(ToDo & toDo)
|
|||
}
|
||||
}
|
||||
|
||||
class FirstReaderAdder : public ReadersAdder
|
||||
struct MapsCollector
|
||||
{
|
||||
typedef ReadersAdder base_type;
|
||||
public:
|
||||
FirstReaderAdder(maps_list_t & lst) : base_type(GetPlatform(), lst) {}
|
||||
vector<string> m_maps;
|
||||
void operator() (vector<string> const & v)
|
||||
{
|
||||
if (!v[0].empty())
|
||||
if (v[0][0] == '#')
|
||||
return;
|
||||
base_type::operator() (v[0]);
|
||||
m_maps.push_back(v[0]);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TModel>
|
||||
void BenchmarkFramework<TModel>::EnumLocalMaps(typename base_type::maps_list_t & filesList)
|
||||
void BenchmarkFramework<TModel>::ReAddLocalMaps()
|
||||
{
|
||||
FirstReaderAdder adder(filesList);
|
||||
ForEachBenchmarkRecord(adder);
|
||||
// remove all previously added maps in framework constructor
|
||||
Platform::FilesList files;
|
||||
base_type::GetLocalMaps(files);
|
||||
for_each(files.begin(), files.end(), bind(&base_type::RemoveMap, this, _1));
|
||||
// add only maps needed for benchmarks
|
||||
MapsCollector collector;
|
||||
ForEachBenchmarkRecord(collector);
|
||||
for_each(collector.m_maps.begin(), collector.m_maps.end(), bind(&base_type::AddMap, this, _1));
|
||||
}
|
||||
|
||||
template <typename TModel>
|
||||
|
@ -152,6 +156,8 @@ BenchmarkFramework<TModel>::BenchmarkFramework(shared_ptr<WindowHandle> const &
|
|||
m_startTime = my::FormatCurrentTime();
|
||||
|
||||
base_type::m_informationDisplay.enableBenchmarkInfo(true);
|
||||
|
||||
ReAddLocalMaps();
|
||||
}
|
||||
|
||||
template <typename TModel>
|
||||
|
|
|
@ -60,7 +60,8 @@ private:
|
|||
|
||||
void InitBenchmark();
|
||||
|
||||
void EnumLocalMaps(typename base_type::maps_list_t & filesList);
|
||||
/// Removes all maps added in base class and adds only benchmarking maps
|
||||
void ReAddLocalMaps();
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -146,6 +146,27 @@ Framework<TModel>::Framework(shared_ptr<WindowHandle> windowHandle,
|
|||
m_informationDisplay.enableLog(isVisualLogEnabled, m_windowHandle.get());
|
||||
m_informationDisplay.setVisualScale(visScale);
|
||||
|
||||
m_model.InitClassificator();
|
||||
|
||||
// initializes model with locally downloaded maps
|
||||
LOG(LDEBUG, ("Initializing storage"));
|
||||
// add maps to the model
|
||||
Platform::FilesList maps;
|
||||
GetLocalMaps(maps);
|
||||
try
|
||||
{
|
||||
for_each(maps.begin(), maps.end(), bind(&Framework::AddMap, this, _1));
|
||||
}
|
||||
catch (RootException const & e)
|
||||
{
|
||||
LOG(LERROR, ("Can't add map: ", e.what()));
|
||||
}
|
||||
|
||||
m_storage.Init(bind(&Framework::AddMap, this, _1),
|
||||
bind(&Framework::RemoveMap, this, _1),
|
||||
bind(&Framework::InvalidateRect, this, _1));
|
||||
LOG(LDEBUG, ("Storage initialized"));
|
||||
|
||||
// set language priorities
|
||||
languages::CodesT langCodes;
|
||||
languages::GetCurrentSettings(langCodes);
|
||||
|
@ -153,20 +174,18 @@ Framework<TModel>::Framework(shared_ptr<WindowHandle> windowHandle,
|
|||
}
|
||||
|
||||
template <typename TModel>
|
||||
void Framework<TModel>::EnumLocalMaps(maps_list_t & filesList)
|
||||
void Framework<TModel>::GetLocalMaps(vector<string> & outMaps)
|
||||
{
|
||||
Platform & pl = GetPlatform();
|
||||
|
||||
outMaps.clear();
|
||||
// scan for pre-installed maps in resources
|
||||
string const resPath = pl.ResourcesDir();
|
||||
Platform::FilesList resFiles;
|
||||
pl.GetFilesInDir(resPath, "*" DATA_FILE_EXTENSION, resFiles);
|
||||
|
||||
// scan for probably updated maps in data dir
|
||||
string const dataPath = pl.WritableDir();
|
||||
Platform::FilesList dataFiles;
|
||||
pl.GetFilesInDir(dataPath, "*" DATA_FILE_EXTENSION, dataFiles);
|
||||
|
||||
// wipe out same maps from resources, which have updated
|
||||
// downloaded versions in data path
|
||||
for (Platform::FilesList::iterator it = resFiles.begin(); it != resFiles.end();)
|
||||
|
@ -177,17 +196,10 @@ void Framework<TModel>::EnumLocalMaps(maps_list_t & filesList)
|
|||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
filesList.clear();
|
||||
for_each(resFiles.begin(), resFiles.end(), ReadersAdder(pl, filesList));
|
||||
for_each(dataFiles.begin(), dataFiles.end(), ReadersAdder(pl, filesList));
|
||||
}
|
||||
catch (RootException const & e)
|
||||
{
|
||||
LOG(LERROR, ("Can't add map: ", e.what()));
|
||||
}
|
||||
for (size_t i = 0; i < resFiles.size(); ++i)
|
||||
outMaps.push_back(resFiles[i]);
|
||||
for (size_t i = 0; i < dataFiles.size(); ++i)
|
||||
outMaps.push_back(dataFiles[i]);
|
||||
}
|
||||
|
||||
template <typename TModel>
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include "../defines.hpp"
|
||||
|
||||
#include "../storage/storage.hpp"
|
||||
|
||||
#include "../indexer/mercator.hpp"
|
||||
#include "../indexer/data_header.hpp"
|
||||
#include "../indexer/scales.hpp"
|
||||
|
@ -55,39 +57,7 @@ typedef function<void (search::Result const &)> SearchCallbackT;
|
|||
class DrawerYG;
|
||||
class RenderPolicy;
|
||||
|
||||
struct PathAppender
|
||||
{
|
||||
string const & m_path;
|
||||
PathAppender(string const & path) : m_path(path) {}
|
||||
void operator()(string & elem)
|
||||
{
|
||||
elem.insert(elem.begin(), m_path.begin(), m_path.end());
|
||||
}
|
||||
};
|
||||
|
||||
class ReadersAdder
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef vector<string> maps_list_t;
|
||||
|
||||
private:
|
||||
Platform & m_pl;
|
||||
maps_list_t & m_lst;
|
||||
|
||||
public:
|
||||
ReadersAdder(Platform & pl, maps_list_t & lst) : m_pl(pl), m_lst(lst) {}
|
||||
|
||||
void operator() (string const & name)
|
||||
{
|
||||
m_lst.push_back(name);
|
||||
}
|
||||
};
|
||||
|
||||
template
|
||||
<
|
||||
class TModel
|
||||
>
|
||||
template <class TModel>
|
||||
class Framework
|
||||
{
|
||||
protected:
|
||||
|
@ -120,7 +90,7 @@ protected:
|
|||
|
||||
mutable threads::Mutex m_modelSyn;
|
||||
|
||||
// int m_tileSize;
|
||||
storage::Storage m_storage;
|
||||
|
||||
my::Timer m_timer;
|
||||
|
||||
|
@ -128,11 +98,15 @@ protected:
|
|||
|
||||
void AddMap(string const & file);
|
||||
void RemoveMap(string const & datFile);
|
||||
/// Only file names
|
||||
void GetLocalMaps(vector<string> & outMaps);
|
||||
|
||||
public:
|
||||
Framework(shared_ptr<WindowHandle> windowHandle, size_t bottomShift);
|
||||
virtual ~Framework();
|
||||
|
||||
storage::Storage & Storage() { return m_storage; }
|
||||
|
||||
void OnLocationStatusChanged(location::TLocationStatus newStatus);
|
||||
void OnGpsUpdate(location::GpsInfo const & info);
|
||||
void OnCompassUpdate(location::CompassInfo const & info);
|
||||
|
@ -144,28 +118,6 @@ public:
|
|||
|
||||
model_t & get_model();
|
||||
|
||||
typedef vector<string> maps_list_t;
|
||||
virtual void EnumLocalMaps(maps_list_t & filesList);
|
||||
|
||||
/// Initialization.
|
||||
template <class TStorage>
|
||||
void InitStorage(TStorage & storage)
|
||||
{
|
||||
m_model.InitClassificator();
|
||||
|
||||
typename TStorage::TEnumMapsFunction enumMapsFn;
|
||||
|
||||
enumMapsFn = bind(&Framework::EnumLocalMaps, this, _1);
|
||||
|
||||
LOG(LDEBUG, ("Initializing storage"));
|
||||
// initializes model with locally downloaded maps
|
||||
storage.Init(bind(&Framework::AddMap, this, _1),
|
||||
bind(&Framework::RemoveMap, this, _1),
|
||||
bind(&Framework::InvalidateRect, this, _1),
|
||||
enumMapsFn);
|
||||
LOG(LDEBUG, ("Storage initialized"));
|
||||
}
|
||||
|
||||
bool IsEmptyModel();
|
||||
|
||||
// Cleanup.
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
#include "proxystyle.hpp"
|
||||
#include "slider_ctrl.hpp"
|
||||
|
||||
#include "../storage/storage.hpp"
|
||||
|
||||
#include "../platform/settings.hpp"
|
||||
|
||||
#include <QtGui/QMouseEvent>
|
||||
|
@ -46,7 +44,7 @@ namespace qt
|
|||
m_state = EStopped;
|
||||
}
|
||||
|
||||
DrawWidget::DrawWidget(QWidget * pParent, Storage & storage)
|
||||
DrawWidget::DrawWidget(QWidget * pParent)
|
||||
: base_type(pParent),
|
||||
m_handle(new WindowHandle()),
|
||||
m_isInitialized(false),
|
||||
|
@ -57,8 +55,6 @@ namespace qt
|
|||
m_redrawInterval(100),
|
||||
m_pScale(0)
|
||||
{
|
||||
m_framework->InitStorage(storage);
|
||||
|
||||
m_timer = new QTimer(this);
|
||||
m_handle->setUpdatesEnabled(false);
|
||||
|
||||
|
|
|
@ -13,12 +13,6 @@
|
|||
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
//class FileReader;
|
||||
//template <class> class ReaderSource;
|
||||
//class FileWriter;
|
||||
|
||||
namespace storage { class Storage; }
|
||||
|
||||
namespace qt
|
||||
{
|
||||
class QScaleSlider;
|
||||
|
@ -92,7 +86,7 @@ namespace qt
|
|||
void AnimTimerElapsed();
|
||||
|
||||
public:
|
||||
DrawWidget(QWidget * pParent, storage::Storage & storage);
|
||||
DrawWidget(QWidget * pParent);
|
||||
|
||||
void SetScaleControl(QScaleSlider * pScale);
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ MainWindow::MainWindow()
|
|||
: m_updateDialog(0)
|
||||
#endif // NO_DOWNLOADER
|
||||
{
|
||||
m_pDrawWidget = new DrawWidget(this, m_storage);
|
||||
m_pDrawWidget = new DrawWidget(this);
|
||||
m_locationService.reset(CreateDesktopLocationService(*this));
|
||||
|
||||
CreateNavigationBar();
|
||||
|
@ -368,7 +368,7 @@ void MainWindow::OnPreferences()
|
|||
void MainWindow::ShowUpdateDialog()
|
||||
{
|
||||
if (!m_updateDialog)
|
||||
m_updateDialog = new UpdateDialog(this, m_storage);
|
||||
m_updateDialog = new UpdateDialog(this, m_pDrawWidget->GetFramework().Storage());
|
||||
m_updateDialog->ShowDialog();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "../storage/storage.hpp"
|
||||
|
||||
#include "../platform/location_service.hpp"
|
||||
|
||||
#include "../std/scoped_ptr.hpp"
|
||||
|
@ -29,8 +27,6 @@ namespace qt
|
|||
UpdateDialog * m_updateDialog;
|
||||
#endif // NO_DOWNLOADER
|
||||
|
||||
storage::Storage m_storage;
|
||||
|
||||
scoped_ptr<location::LocationService> m_locationService;
|
||||
|
||||
Q_OBJECT
|
||||
|
|
|
@ -45,19 +45,13 @@ namespace storage
|
|||
// }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void Storage::Init(TAddMapFunction addFunc, TRemoveMapFunction removeFunc, TUpdateRectFunction updateRectFunc, TEnumMapsFunction enumMapsFunc)
|
||||
void Storage::Init(TAddMapFunction addFunc, TRemoveMapFunction removeFunc, TUpdateRectFunction updateRectFunc)
|
||||
{
|
||||
m_currentVersion = static_cast<uint32_t>(Version::BUILD);
|
||||
|
||||
m_addMap = addFunc;
|
||||
m_removeMap = removeFunc;
|
||||
m_updateRect = updateRectFunc;
|
||||
|
||||
map_list_t filesList;
|
||||
enumMapsFunc(filesList);
|
||||
|
||||
for (map_list_t::iterator it = filesList.begin(); it != filesList.end(); ++it)
|
||||
m_addMap(*it);
|
||||
}
|
||||
|
||||
string Storage::UpdateBaseUrl() const
|
||||
|
|
|
@ -108,8 +108,7 @@ namespace storage
|
|||
/// @TODO temporarily made public for Android, refactor
|
||||
void ReInitCountries(bool forceReload);
|
||||
|
||||
/// Adds all locally downloaded maps to the model
|
||||
void Init(TAddMapFunction addFunc, TRemoveMapFunction removeFunc, TUpdateRectFunction updateRectFunc, TEnumMapsFunction enumMapFunction);
|
||||
void Init(TAddMapFunction addFunc, TRemoveMapFunction removeFunc, TUpdateRectFunction updateRectFunc);
|
||||
|
||||
/// @name Called from DownloadManager
|
||||
//@{
|
||||
|
|
Loading…
Add table
Reference in a new issue