MapRenderer.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. class MapObjectsSorter
  21. {
  22. const IMapRendererContext & context;
  23. public:
  24. explicit MapObjectsSorter(const IMapRendererContext & context);
  25. bool operator ()(const ObjectInstanceID & left, const ObjectInstanceID & right) const;
  26. bool operator ()(const CGObjectInstance * left, const CGObjectInstance * right) const;
  27. };
  28. class MapTileStorage
  29. {
  30. using TerrainAnimation = std::array<std::unique_ptr<CAnimation>, 4>;
  31. std::vector<TerrainAnimation> animations;
  32. public:
  33. explicit MapTileStorage( size_t capacity);
  34. void load(size_t index, const std::string& filename);
  35. std::shared_ptr<IImage> find(size_t fileIndex, size_t rotationIndex, size_t imageIndex );
  36. };
  37. class MapRendererTerrain
  38. {
  39. MapTileStorage storage;
  40. public:
  41. MapRendererTerrain();
  42. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  43. };
  44. class MapRendererRiver
  45. {
  46. MapTileStorage storage;
  47. public:
  48. MapRendererRiver();
  49. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  50. };
  51. class MapRendererRoad
  52. {
  53. MapTileStorage storage;
  54. public:
  55. MapRendererRoad();
  56. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  57. };
  58. class MapRendererObjects
  59. {
  60. using MapObject = ObjectInstanceID;
  61. using MapTile = std::vector<MapObject>;
  62. boost::multi_array<MapTile, 3> objects;
  63. std::map<std::string, std::shared_ptr<CAnimation>> animations;
  64. std::shared_ptr<CAnimation> getFlagAnimation(const CGObjectInstance* obj);
  65. std::shared_ptr<CAnimation> getAnimation(const CGObjectInstance* obj);
  66. std::shared_ptr<CAnimation> getAnimation(const std::string & filename);
  67. std::shared_ptr<IImage> getImage(const IMapRendererContext & context, const CGObjectInstance * obj, const std::shared_ptr<CAnimation>& animation) const;
  68. size_t getAnimationGroup(const IMapRendererContext & context, const CGObjectInstance * obj) const;
  69. void initializeObjects(const IMapRendererContext & context);
  70. void renderImage(Canvas & target, const int3 & coordinates, const CGObjectInstance * object, const std::shared_ptr<IImage>& image);
  71. void renderObject(const IMapRendererContext & context, Canvas & target, const int3 & coordinates, const CGObjectInstance* obj);
  72. public:
  73. explicit MapRendererObjects(const IMapRendererContext & context);
  74. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  75. void addObject(const IMapRendererContext & context, const CGObjectInstance * object);
  76. void removeObject(const IMapRendererContext & context, const CGObjectInstance * object);
  77. };
  78. class MapRendererBorder
  79. {
  80. std::unique_ptr<CAnimation> animation;
  81. size_t getIndexForTile(const IMapRendererContext & context, const int3 & coordinates);
  82. public:
  83. MapRendererBorder();
  84. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  85. };
  86. class MapRendererFow
  87. {
  88. std::unique_ptr<CAnimation> fogOfWarFullHide;
  89. std::unique_ptr<CAnimation> fogOfWarPartialHide;
  90. public:
  91. MapRendererFow();
  92. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  93. };
  94. class MapRendererPath
  95. {
  96. std::unique_ptr<CAnimation> pathNodes;
  97. void renderImage(Canvas & target, bool reachableToday, size_t imageIndex);
  98. void renderImageCross(Canvas & target, bool reachableToday, const int3 & curr);
  99. void renderImageArrow(Canvas & target, bool reachableToday, const int3 & curr, const int3 & prev, const int3 & next);
  100. public:
  101. MapRendererPath();
  102. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  103. };
  104. class MapRendererDebugGrid
  105. {
  106. public:
  107. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  108. };
  109. class MapRenderer
  110. {
  111. MapRendererTerrain rendererTerrain;
  112. MapRendererRiver rendererRiver;
  113. MapRendererRoad rendererRoad;
  114. MapRendererBorder rendererBorder;
  115. MapRendererFow rendererFow;
  116. MapRendererObjects rendererObjects;
  117. MapRendererPath rendererPath;
  118. MapRendererDebugGrid rendererDebugGrid;
  119. public:
  120. explicit MapRenderer(const IMapRendererContext & context);
  121. void renderTile(const IMapRendererContext & context, Canvas & target, const int3 & coordinates);
  122. void addObject(const IMapRendererContext & context, const CGObjectInstance * object);
  123. void removeObject(const IMapRendererContext & context, const CGObjectInstance * object);
  124. };