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;
  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. std::unique_ptr<Canvas> emptyFill;
  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. };