MapView.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * MapView.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 "../gui/CIntObject.h"
  12. #include "MapRendererContext.h"
  13. class Canvas;
  14. class MapRenderer;
  15. class MapRendererContext : public IMapRendererContext
  16. {
  17. uint32_t animationTime = 0;
  18. public:
  19. void advanceAnimations(uint32_t ms);
  20. int3 getMapSize() const override;
  21. bool isInMap(const int3 & coordinates) const override;
  22. const TerrainTile & getMapTile(const int3 & coordinates) const override;
  23. ObjectsVector getAllObjects() const override;
  24. const CGObjectInstance * getObject(ObjectInstanceID objectID) const override;
  25. const CGPath * currentPath() const override;
  26. bool isVisible(const int3 & coordinates) const override;
  27. uint32_t getAnimationPeriod() const override;
  28. uint32_t getAnimationTime() const override;
  29. Point tileSize() const override;
  30. bool showGrid() const override;
  31. };
  32. class MapCache
  33. {
  34. std::unique_ptr<Canvas> terrain;
  35. Point tileSize;
  36. Point viewCenter;
  37. Point viewDimensionsTiles;
  38. Point viewDimensionsPixels;
  39. Point targetDimensionsPixels;
  40. int mapLevel;
  41. std::unique_ptr<MapRendererContext> context;
  42. std::unique_ptr<MapRenderer> mapRenderer;
  43. Canvas getTile(const int3 & coordinates);
  44. void updateTile(const int3 & coordinates);
  45. public:
  46. explicit MapCache(const Point & tileSize, const Point & dimensions);
  47. ~MapCache();
  48. void setViewCenter(const Point & center, int level);
  49. Rect getVisibleAreaTiles() const;
  50. int3 getTileCenter() const;
  51. int3 getTileAtPoint(const Point & position) const;
  52. Point getViewCenter() const;
  53. void update(uint32_t timeDelta);
  54. void render(Canvas & target);
  55. };
  56. class MapView : public CIntObject
  57. {
  58. std::unique_ptr<MapCache> tilesCache;
  59. Point tileSize;
  60. public:
  61. MapView(const Point & offset, const Point & dimensions);
  62. Rect getVisibleAreaTiles() const;
  63. Point getViewCenter() const;
  64. int3 getTileCenter() const;
  65. int3 getTileAtPoint(const Point & position) const;
  66. void setViewCenter(const int3 & position);
  67. void setViewCenter(const Point & position, int level);
  68. void show(SDL_Surface * to) override;
  69. void showAll(SDL_Surface * to) override;
  70. };