MapViewCache.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. class IImage;
  13. class CAnimation;
  14. class Canvas;
  15. class MapRenderer;
  16. class IMapRendererContext;
  17. class MapViewModel;
  18. /// Class responsible for rendering of entire map view
  19. /// uses rendering parameters provided by owner class
  20. class MapViewCache
  21. {
  22. struct TileChecksum
  23. {
  24. int tileX = std::numeric_limits<int>::min();
  25. int tileY = std::numeric_limits<int>::min();
  26. std::array<uint8_t, 8> checksum {};
  27. bool operator == (const TileChecksum & other) const
  28. {
  29. return tileX == other.tileX && tileY == other.tileY && checksum == other.checksum;
  30. }
  31. };
  32. boost::multi_array<TileChecksum, 2> terrainChecksum;
  33. boost::multi_array<bool, 2> tilesUpToDate;
  34. Point cachedPosition;
  35. int cachedLevel;
  36. std::shared_ptr<MapViewModel> model;
  37. std::unique_ptr<Canvas> terrain;
  38. std::unique_ptr<Canvas> terrainTransition;
  39. std::unique_ptr<Canvas> intermediate;
  40. std::unique_ptr<MapRenderer> mapRenderer;
  41. std::unique_ptr<CAnimation> iconsStorage;
  42. Canvas getTile(const int3 & coordinates);
  43. void updateTile(const std::shared_ptr<IMapRendererContext> & context, const int3 & coordinates);
  44. std::shared_ptr<IImage> getOverlayImageForTile(const std::shared_ptr<IMapRendererContext> & context, const int3 & coordinates);
  45. public:
  46. explicit MapViewCache(const std::shared_ptr<MapViewModel> & model);
  47. ~MapViewCache();
  48. /// updates internal terrain cache according to provided time delta
  49. void update(const std::shared_ptr<IMapRendererContext> & context);
  50. /// renders updated terrain cache onto provided canvas
  51. void render(const std::shared_ptr<IMapRendererContext> &context, Canvas & target, bool fullRedraw);
  52. };