MapRenderer.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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(const IMapRendererContext & context, const int3 & coordinates);
  36. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  37. };
  38. class MapRendererRiver
  39. {
  40. MapTileStorage storage;
  41. public:
  42. MapRendererRiver();
  43. uint8_t checksum(const IMapRendererContext & context, const int3 & coordinates);
  44. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  45. };
  46. class MapRendererRoad
  47. {
  48. MapTileStorage storage;
  49. public:
  50. MapRendererRoad();
  51. uint8_t checksum(const IMapRendererContext & context, const int3 & coordinates);
  52. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  53. };
  54. class MapRendererObjects
  55. {
  56. std::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(const IMapRendererContext & context, const CGObjectInstance * obj, const std::shared_ptr<CAnimation> & animation) const;
  62. void renderImage(const IMapRendererContext & context, Canvas & target, const int3 & coordinates, const CGObjectInstance * object, const std::shared_ptr<IImage> & image);
  63. void renderObject(const IMapRendererContext & context, Canvas & target, const int3 & coordinates, const CGObjectInstance * obj);
  64. public:
  65. uint8_t checksum(const IMapRendererContext & context, const int3 & coordinates);
  66. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  67. };
  68. class MapRendererBorder
  69. {
  70. std::unique_ptr<CAnimation> animation;
  71. size_t getIndexForTile(const IMapRendererContext & context, const int3 & coordinates);
  72. public:
  73. MapRendererBorder();
  74. uint8_t checksum(const IMapRendererContext & context, const int3 & coordinates);
  75. void renderTile(const 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(const IMapRendererContext & context, const int3 & coordinates);
  84. void renderTile(const 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(const IMapRendererContext & context, const int3 & coordinates);
  93. public:
  94. MapRendererPath();
  95. uint8_t checksum(const IMapRendererContext & context, const int3 & coordinates);
  96. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  97. };
  98. class MapRendererDebug
  99. {
  100. std::shared_ptr<IImage> imageGrid;
  101. std::shared_ptr<IImage> imageVisitable;
  102. std::shared_ptr<IImage> imageBlockable;
  103. public:
  104. MapRendererDebug();
  105. uint8_t checksum(const IMapRendererContext & context, const int3 & coordinates);
  106. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  107. };
  108. class MapRendererOverlay
  109. {
  110. std::unique_ptr<CAnimation> iconsStorage;
  111. public:
  112. MapRendererOverlay();
  113. uint8_t checksum(const IMapRendererContext & context, const int3 & coordinates);
  114. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  115. };
  116. class MapRenderer
  117. {
  118. MapRendererTerrain rendererTerrain;
  119. MapRendererRiver rendererRiver;
  120. MapRendererRoad rendererRoad;
  121. MapRendererBorder rendererBorder;
  122. MapRendererFow rendererFow;
  123. MapRendererObjects rendererObjects;
  124. MapRendererPath rendererPath;
  125. MapRendererDebug rendererDebug;
  126. public:
  127. using TileChecksum = std::array<uint8_t, 8>;
  128. TileChecksum getTileChecksum(const IMapRendererContext & context, const int3 & coordinates);
  129. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  130. };