Welcome to mirror list, hosted at ThFree Co, Russian Federation.

read_manager.hpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ed6b6e138b8b8a8fa10846597764a10772f925bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once

#include "drape_frontend/custom_symbol.hpp"
#include "drape_frontend/engine_context.hpp"
#include "drape_frontend/read_mwm_task.hpp"
#include "drape_frontend/tile_info.hpp"
#include "drape_frontend/tile_utils.hpp"

#include "geometry/screenbase.hpp"

#include "drape/object_pool.hpp"
#include "drape/pointers.hpp"
#include "drape/texture_manager.hpp"

#include "base/thread_pool.hpp"

#include "std/atomic.hpp"
#include "std/mutex.hpp"
#include "std/set.hpp"
#include "std/shared_ptr.hpp"
#include "std/target_os.hpp"

namespace df
{

class MapDataProvider;
class CoverageUpdateDescriptor;

uint8_t constexpr kReadingThreadsCount = 2;

class ReadManager
{
public:
  ReadManager(ref_ptr<ThreadsCommutator> commutator, MapDataProvider & model,
              bool allow3dBuildings, bool trafficEnabled);

  void UpdateCoverage(ScreenBase const & screen, bool have3dBuildings, bool forceUpdate,
                      TTilesCollection const & tiles, ref_ptr<dp::TextureManager> texMng);
  void Invalidate(TTilesCollection const & keyStorage);
  void InvalidateAll();
  void Stop();

  bool CheckTileKey(TileKey const & tileKey) const;
  void Allow3dBuildings(bool allow3dBuildings);

  void SetTrafficEnabled(bool trafficEnabled);

  void UpdateCustomSymbols(CustomSymbols const & symbols);
  void RemoveCustomSymbols(MwmSet::MwmId const & mwmId, std::vector<FeatureID> & leftoverIds);
  void RemoveAllCustomSymbols();

private:
  void OnTaskFinished(threads::IRoutine * task);
  bool MustDropAllTiles(ScreenBase const & screen) const;

  void PushTaskBackForTileKey(TileKey const & tileKey, ref_ptr<dp::TextureManager> texMng);

  ref_ptr<ThreadsCommutator> m_commutator;

  MapDataProvider & m_model;

  drape_ptr<threads::ThreadPool> m_pool;

  ScreenBase m_currentViewport;
  bool m_have3dBuildings;
  bool m_allow3dBuildings;
  bool m_trafficEnabled;
  bool m_modeChanged;

  struct LessByTileInfo
  {
    bool operator ()(shared_ptr<TileInfo> const & l, shared_ptr<TileInfo> const & r) const
    {
      return *l < *r;
    }
  };

  using TTileSet = set<shared_ptr<TileInfo>, LessByTileInfo>;
  TTileSet m_tileInfos;

  ObjectPool<ReadMWMTask, ReadMWMTaskFactory> myPool;

  int m_counter;
  mutex m_finishedTilesMutex;
  uint64_t m_generationCounter;

  using TTileInfoCollection = buffer_vector<shared_ptr<TileInfo>, 8>;
  TTilesCollection m_activeTiles;

  CustomSymbolsContextPtr m_customSymbolsContext;

  void CancelTileInfo(shared_ptr<TileInfo> const & tileToCancel);
  void ClearTileInfo(shared_ptr<TileInfo> const & tileToClear);
  void IncreaseCounter(int value);
  void CheckFinishedTiles(TTileInfoCollection const & requestedTiles);
};

} // namespace df