MapRenderer.h 4.8 KB

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