MapRenderer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. std::shared_ptr<CAnimation> getBaseAnimation(const CGObjectInstance * obj);
  60. std::shared_ptr<CAnimation> getFlagAnimation(const CGObjectInstance * obj);
  61. std::shared_ptr<CAnimation> getOverlayAnimation(const CGObjectInstance * obj);
  62. std::shared_ptr<CAnimation> getAnimation(const AnimationPath & filename, bool generateMovementGroups, bool enableOverlay);
  63. std::shared_ptr<IImage> getImage(IMapRendererContext & context, const CGObjectInstance * obj, const std::shared_ptr<CAnimation> & animation) const;
  64. void renderImage(IMapRendererContext & context, Canvas & target, const int3 & coordinates, const CGObjectInstance * object, const std::shared_ptr<IImage> & image);
  65. void renderObject(IMapRendererContext & context, Canvas & target, const int3 & coordinates, const CGObjectInstance * obj);
  66. public:
  67. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  68. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  69. };
  70. class MapRendererBorder
  71. {
  72. std::shared_ptr<CAnimation> animation;
  73. size_t getIndexForTile(IMapRendererContext & context, const int3 & coordinates);
  74. public:
  75. MapRendererBorder();
  76. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  77. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  78. };
  79. class MapRendererFow
  80. {
  81. std::shared_ptr<CAnimation> fogOfWarFullHide;
  82. std::shared_ptr<CAnimation> fogOfWarPartialHide;
  83. public:
  84. MapRendererFow();
  85. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  86. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  87. };
  88. class MapRendererPath
  89. {
  90. std::shared_ptr<CAnimation> pathNodes;
  91. size_t selectImageReachability(bool reachableToday, size_t imageIndex);
  92. size_t selectImageCross(bool reachableToday, const int3 & curr);
  93. size_t selectImageArrow(bool reachableToday, const int3 & curr, const int3 & prev, const int3 & next);
  94. size_t selectImage(IMapRendererContext & context, const int3 & coordinates);
  95. public:
  96. MapRendererPath();
  97. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  98. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  99. };
  100. class MapRendererOverlay
  101. {
  102. std::shared_ptr<IImage> imageGrid;
  103. std::shared_ptr<IImage> imageVisitable;
  104. std::shared_ptr<IImage> imageBlocked;
  105. std::shared_ptr<IImage> imageSpellRange;
  106. public:
  107. MapRendererOverlay();
  108. uint8_t checksum(IMapRendererContext & context, const int3 & coordinates);
  109. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  110. };
  111. class MapRenderer
  112. {
  113. MapRendererTerrain rendererTerrain;
  114. MapRendererRiver rendererRiver;
  115. MapRendererRoad rendererRoad;
  116. MapRendererBorder rendererBorder;
  117. MapRendererFow rendererFow;
  118. MapRendererObjects rendererObjects;
  119. MapRendererPath rendererPath;
  120. MapRendererOverlay rendererOverlay;
  121. public:
  122. using TileChecksum = std::array<uint8_t, 8>;
  123. TileChecksum getTileChecksum(IMapRendererContext & context, const int3 & coordinates);
  124. void renderTile(IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  125. };