MapRenderer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * MapRenderer.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. VCMI_LIB_NAMESPACE_BEGIN
  12. class int3;
  13. class ObjectInstanceID;
  14. class CGObjectInstance;
  15. VCMI_LIB_NAMESPACE_END
  16. class CAnimation;
  17. class IImage;
  18. class Canvas;
  19. class IMapRendererContext;
  20. enum class EImageBlitMode : uint8_t;
  21. class MapTileStorage
  22. {
  23. using TerrainAnimation = std::array<std::unique_ptr<CAnimation>, 4>;
  24. std::vector<TerrainAnimation> animations;
  25. public:
  26. explicit MapTileStorage(size_t capacity);
  27. void load(size_t index, const std::string & filename, EImageBlitMode blitMode);
  28. std::shared_ptr<IImage> find(size_t fileIndex, size_t rotationIndex, size_t imageIndex);
  29. };
  30. class MapRendererTerrain
  31. {
  32. MapTileStorage storage;
  33. public:
  34. MapRendererTerrain();
  35. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  36. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  37. };
  38. class MapRendererRiver
  39. {
  40. MapTileStorage storage;
  41. public:
  42. MapRendererRiver();
  43. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  44. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  45. };
  46. class MapRendererRoad
  47. {
  48. MapTileStorage storage;
  49. public:
  50. MapRendererRoad();
  51. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  52. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  53. };
  54. class MapRendererObjects
  55. {
  56. std::unordered_map<std::string, std::shared_ptr<CAnimation>> animations;
  57. std::shared_ptr<CAnimation> getBaseAnimation(const CGObjectInstance * obj);
  58. std::shared_ptr<CAnimation> getFlagAnimation(const CGObjectInstance * obj);
  59. std::shared_ptr<CAnimation> getOverlayAnimation(const CGObjectInstance * obj);
  60. std::shared_ptr<CAnimation> getAnimation(const std::string & filename, bool generateMovementGroups);
  61. std::shared_ptr<IImage> getImage(IMapRendererContext & context, const CGObjectInstance * obj, const std::shared_ptr<CAnimation> & animation) const;
  62. void renderImage(IMapRendererContext & context, Canvas & target, const int3 & coordinates, const CGObjectInstance * object, const std::shared_ptr<IImage> & image);
  63. void renderObject(IMapRendererContext & context, Canvas & target, const int3 & coordinates, const CGObjectInstance * obj);
  64. public:
  65. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  66. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  67. };
  68. class MapRendererBorder
  69. {
  70. std::unique_ptr<CAnimation> animation;
  71. size_t getIndexForTile(IMapRendererContext & context, const int3 & coordinates);
  72. public:
  73. MapRendererBorder();
  74. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  75. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  76. };
  77. class MapRendererFow
  78. {
  79. std::unique_ptr<CAnimation> fogOfWarFullHide;
  80. std::unique_ptr<CAnimation> fogOfWarPartialHide;
  81. public:
  82. MapRendererFow();
  83. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  84. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  85. };
  86. class MapRendererPath
  87. {
  88. std::unique_ptr<CAnimation> pathNodes;
  89. size_t selectImageReachability(bool reachableToday, size_t imageIndex);
  90. size_t selectImageCross(bool reachableToday, const int3 & curr);
  91. size_t selectImageArrow(bool reachableToday, const int3 & curr, const int3 & prev, const int3 & next);
  92. size_t selectImage(IMapRendererContext & context, const int3 & coordinates);
  93. public:
  94. MapRendererPath();
  95. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  96. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  97. };
  98. class MapRendererOverlay
  99. {
  100. std::shared_ptr<IImage> imageGrid;
  101. std::shared_ptr<IImage> imageVisitable;
  102. std::shared_ptr<IImage> imageBlocked;
  103. std::shared_ptr<IImage> imageSpellRange;
  104. public:
  105. MapRendererOverlay();
  106. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  107. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  108. };
  109. class MapRenderer
  110. {
  111. MapRendererTerrain rendererTerrain;
  112. MapRendererRiver rendererRiver;
  113. MapRendererRoad rendererRoad;
  114. MapRendererBorder rendererBorder;
  115. MapRendererFow rendererFow;
  116. MapRendererObjects rendererObjects;
  117. MapRendererPath rendererPath;
  118. MapRendererOverlay rendererOverlay;
  119. public:
  120. using TileChecksum = std::array<uint8_t, 8>;
  121. TileChecksum getTileChecksum(IMapRendererContext & context, const int3 & coordinates);
  122. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  123. };