MapRenderer.h 5.0 KB

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