MapRendererContext.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/ConstTransitivePtr.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class int3;
  14. class Point;
  15. class CGObjectInstance;
  16. class CGHeroInstance;
  17. class ObjectInstanceID;
  18. struct TerrainTile;
  19. struct CGPath;
  20. VCMI_LIB_NAMESPACE_END
  21. class IMapRendererContext
  22. {
  23. public:
  24. using MapObject = ObjectInstanceID;
  25. using MapObjectsList = std::vector<MapObject>;
  26. virtual ~IMapRendererContext() = default;
  27. /// returns dimensions of current map
  28. virtual int3 getMapSize() const = 0;
  29. /// returns true if chosen coordinates exist on map
  30. virtual bool isInMap(const int3 & coordinates) const = 0;
  31. /// returns tile by selected coordinates. Coordinates MUST be valid
  32. virtual const TerrainTile & getMapTile(const int3 & coordinates) const = 0;
  33. /// returns all objects visible on specified tile
  34. virtual const MapObjectsList & getObjects(const int3 & coordinates) const = 0;
  35. /// returns specific object by ID, or nullptr if not found
  36. virtual const CGObjectInstance * getObject(ObjectInstanceID objectID) const = 0;
  37. /// returns path of currently active hero, or nullptr if none
  38. virtual const CGPath * currentPath() const = 0;
  39. /// returns true if specified tile is visible in current context
  40. virtual bool isVisible(const int3 & coordinates) const = 0;
  41. virtual size_t objectGroupIndex(ObjectInstanceID objectID) const = 0;
  42. virtual Point objectImageOffset(ObjectInstanceID objectID, const int3 & coordinates) const = 0;
  43. /// returns object animation transparency. IF set to 0, object will not be visible
  44. virtual double objectTransparency(ObjectInstanceID objectID) const = 0;
  45. /// returns animation frame for selected object
  46. virtual size_t objectImageIndex(ObjectInstanceID objectID, size_t groupSize) const = 0;
  47. /// returns size of ouput tile, in pixels. 32x32 for "standard" map, may be smaller for world view mode
  48. virtual Point getTileSize() const = 0;
  49. /// if true, map grid should be visible on map
  50. virtual bool showGrid() const = 0;
  51. };
  52. class IMapObjectObserver
  53. {
  54. public:
  55. IMapObjectObserver();
  56. virtual ~IMapObjectObserver();
  57. virtual bool hasOngoingAnimations() = 0;
  58. /// Plays fade-in animation and adds object to map
  59. virtual void onObjectFadeIn(const CGObjectInstance * obj) {}
  60. /// Plays fade-out animation and removed object from map
  61. virtual void onObjectFadeOut(const CGObjectInstance * obj) {}
  62. /// Adds object to map instantly, with no animation
  63. virtual void onObjectInstantAdd(const CGObjectInstance * obj) {}
  64. /// Removes object from map instantly, with no animation
  65. virtual void onObjectInstantRemove(const CGObjectInstance * obj) {}
  66. /// Perform hero teleportation animation with terrain fade animation
  67. virtual void onHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) {}
  68. /// Perform hero movement animation, moving hero across terrain
  69. virtual void onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest) {}
  70. /// Instantly rotates hero to face destination tile
  71. virtual void onHeroRotated(const CGHeroInstance * obj, const int3 & from, const int3 & dest) {}
  72. };