MapViewCache.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. std::shared_ptr<MapViewModel> model;
  41. std::unique_ptr<Canvas> terrain;
  42. std::unique_ptr<Canvas> terrainTransition;
  43. std::unique_ptr<Canvas> intermediate;
  44. std::unique_ptr<MapRenderer> mapRenderer;
  45. std::unique_ptr<CAnimation> iconsStorage;
  46. Canvas getTile(const int3 & coordinates);
  47. void updateTile(const std::shared_ptr<IMapRendererContext> & context, const int3 & coordinates);
  48. std::shared_ptr<IImage> getOverlayImageForTile(const std::shared_ptr<IMapRendererContext> & context, const int3 & coordinates);
  49. public:
  50. explicit MapViewCache(const std::shared_ptr<MapViewModel> & model);
  51. ~MapViewCache();
  52. /// invalidates cache of specified object
  53. void invalidate(const std::shared_ptr<IMapRendererContext> & context, const ObjectInstanceID & object);
  54. /// updates internal terrain cache according to provided time delta
  55. void update(const std::shared_ptr<IMapRendererContext> & context);
  56. /// renders updated terrain cache onto provided canvas
  57. void render(const std::shared_ptr<IMapRendererContext> & context, Canvas & target, bool fullRedraw);
  58. /// creates snapshot of current view and stores it into internal canvas
  59. /// used for view transition, e.g. Dimension Door spell or teleporters (Subterra gates / Monolith)
  60. void createTransitionSnapshot(const std::shared_ptr<IMapRendererContext> & context);
  61. };