MapRendererContext.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * MapRendererContext.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 "IMapRendererContext.h"
  12. #include "../lib/int3.h"
  13. #include "../lib/GameConstants.h"
  14. class MapObjectsSorter
  15. {
  16. const IMapRendererContext & context;
  17. public:
  18. explicit MapObjectsSorter(const IMapRendererContext & context);
  19. bool operator()(const ObjectInstanceID & left, const ObjectInstanceID & right) const;
  20. bool operator()(const CGObjectInstance * left, const CGObjectInstance * right) const;
  21. };
  22. struct HeroAnimationState
  23. {
  24. ObjectInstanceID target;
  25. int3 tileFrom;
  26. int3 tileDest;
  27. double progress;
  28. };
  29. struct FadingAnimationState
  30. {
  31. ObjectInstanceID target;
  32. double progress;
  33. };
  34. class MapRendererContext : public IMapRendererContext
  35. {
  36. friend class MapViewController;
  37. boost::multi_array<MapObjectsList, 3> objects;
  38. //Point tileSize = Point(32, 32);
  39. uint32_t animationTime = 0;
  40. boost::optional<HeroAnimationState> movementAnimation;
  41. boost::optional<HeroAnimationState> teleportAnimation;
  42. boost::optional<FadingAnimationState> fadeOutAnimation;
  43. boost::optional<FadingAnimationState> fadeInAnimation;
  44. bool worldViewModeActive = false;
  45. public:
  46. MapRendererContext();
  47. void addObject(const CGObjectInstance * object);
  48. void addMovingObject(const CGObjectInstance * object, const int3 & tileFrom, const int3 & tileDest);
  49. void removeObject(const CGObjectInstance * object);
  50. int3 getMapSize() const final;
  51. bool isInMap(const int3 & coordinates) const final;
  52. bool isVisible(const int3 & coordinates) const override;
  53. const TerrainTile & getMapTile(const int3 & coordinates) const override;
  54. const MapObjectsList & getObjects(const int3 & coordinates) const override;
  55. const CGObjectInstance * getObject(ObjectInstanceID objectID) const override;
  56. const CGPath * currentPath() const override;
  57. size_t objectGroupIndex(ObjectInstanceID objectID) const override;
  58. Point objectImageOffset(ObjectInstanceID objectID, const int3 & coordinates) const override;
  59. double objectTransparency(ObjectInstanceID objectID) const override;
  60. size_t objectImageIndex(ObjectInstanceID objectID, size_t groupSize) const override;
  61. size_t terrainImageIndex(size_t groupSize) const override;
  62. // Point getTileSize() const override;
  63. bool showOverlay() const override;
  64. bool showGrid() const override;
  65. bool showVisitable() const override;
  66. bool showBlockable() const override;
  67. };