MapViewCache.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * MapViewCache.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../../lib/Point.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class ObjectInstanceID;
  14. VCMI_LIB_NAMESPACE_END
  15. class IImage;
  16. class CAnimation;
  17. class Canvas;
  18. class MapRenderer;
  19. class IMapRendererContext;
  20. class MapViewModel;
  21. /// Class responsible for rendering of entire map view
  22. /// uses rendering parameters provided by owner class
  23. class MapViewCache
  24. {
  25. struct TileChecksum
  26. {
  27. int tileX = std::numeric_limits<int>::min();
  28. int tileY = std::numeric_limits<int>::min();
  29. std::array<uint8_t, 8> checksum{};
  30. bool operator==(const TileChecksum & other) const
  31. {
  32. return tileX == other.tileX && tileY == other.tileY && checksum == other.checksum;
  33. }
  34. };
  35. boost::multi_array<TileChecksum, 2> terrainChecksum;
  36. boost::multi_array<bool, 2> tilesUpToDate;
  37. Point cachedSize;
  38. Point cachedPosition;
  39. int cachedLevel;
  40. bool overlayWasVisible;
  41. std::shared_ptr<MapViewModel> model;
  42. std::unique_ptr<Canvas> terrain;
  43. std::unique_ptr<Canvas> terrainTransition;
  44. std::unique_ptr<Canvas> intermediate;
  45. std::unique_ptr<MapRenderer> mapRenderer;
  46. std::shared_ptr<CAnimation> iconsStorage;
  47. Canvas getTile(const int3 & coordinates);
  48. void updateTile(const std::shared_ptr<IMapRendererContext> & context, const int3 & coordinates);
  49. std::shared_ptr<IImage> getOverlayImageForTile(const std::shared_ptr<IMapRendererContext> & context, const int3 & coordinates);
  50. public:
  51. explicit MapViewCache(const std::shared_ptr<MapViewModel> & model);
  52. ~MapViewCache();
  53. /// invalidates cache of specified object
  54. void invalidate(const std::shared_ptr<IMapRendererContext> & context, const ObjectInstanceID & object);
  55. /// updates internal terrain cache according to provided time delta
  56. void update(const std::shared_ptr<IMapRendererContext> & context);
  57. /// renders updated terrain cache onto provided canvas
  58. void render(const std::shared_ptr<IMapRendererContext> & context, Canvas & target, bool fullRedraw);
  59. /// creates snapshot of current view and stores it into internal canvas
  60. /// used for view transition, e.g. Dimension Door spell or teleporters (Subterra gates / Monolith)
  61. void createTransitionSnapshot(const std::shared_ptr<IMapRendererContext> & context);
  62. };