No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mapview.h 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. * THE SOFTWARE.
  21. */
  22. #ifndef MAPVIEW_H
  23. #define MAPVIEW_H
  24. #include "declarations.h"
  25. #include <framework/graphics/paintershaderprogram.h>
  26. #include <framework/graphics/declarations.h>
  27. #include <framework/luaengine/luaobject.h>
  28. #include <framework/core/declarations.h>
  29. #include "lightview.h"
  30. // @bindclass
  31. class MapView : public LuaObject
  32. {
  33. public:
  34. enum ViewMode {
  35. NEAR_VIEW,
  36. MID_VIEW,
  37. FAR_VIEW,
  38. HUGE_VIEW
  39. };
  40. MapView();
  41. ~MapView();
  42. void draw(const Rect& rect);
  43. private:
  44. void updateGeometry(const Size& visibleDimension, const Size& optimizedSize);
  45. void updateVisibleTilesCache(int start = 0);
  46. void requestVisibleTilesCacheUpdate() { m_mustUpdateVisibleTilesCache = true; }
  47. protected:
  48. void onTileUpdate(const Position& pos);
  49. void onMapCenterChange(const Position& pos);
  50. friend class Map;
  51. public:
  52. // floor visibility related
  53. void lockFirstVisibleFloor(int firstVisibleFloor);
  54. void unlockFirstVisibleFloor();
  55. int getLockedFirstVisibleFloor() { return m_lockedFirstVisibleFloor; }
  56. void setMultifloor(bool enable) { m_multifloor = enable; requestVisibleTilesCacheUpdate(); }
  57. bool isMultifloor() { return m_multifloor; }
  58. // map dimension related
  59. void setVisibleDimension(const Size& visibleDimension);
  60. Size getVisibleDimension() { return m_visibleDimension; }
  61. int getTileSize() { return m_tileSize; }
  62. Point getVisibleCenterOffset() { return m_visibleCenterOffset; }
  63. int getCachedFirstVisibleFloor() { return m_cachedFirstVisibleFloor; }
  64. int getCachedLastVisibleFloor() { return m_cachedLastVisibleFloor; }
  65. // view mode related
  66. void setViewMode(ViewMode viewMode);
  67. ViewMode getViewMode() { return m_viewMode; }
  68. void optimizeForSize(const Size& visibleSize);
  69. void setAutoViewMode(bool enable);
  70. bool isAutoViewModeEnabled() { return m_autoViewMode; }
  71. // camera related
  72. void followCreature(const CreaturePtr& creature);
  73. CreaturePtr getFollowingCreature() { return m_followingCreature; }
  74. bool isFollowingCreature() { return m_followingCreature && m_follow; }
  75. void setCameraPosition(const Position& pos);
  76. Position getCameraPosition();
  77. void setMinimumAmbientLight(float intensity) { m_minimumAmbientLight = intensity; }
  78. float getMinimumAmbientLight() { return m_minimumAmbientLight; }
  79. // drawing related
  80. void setDrawFlags(Otc::DrawFlags drawFlags) { m_drawFlags = drawFlags; requestVisibleTilesCacheUpdate(); }
  81. Otc::DrawFlags getDrawFlags() { return m_drawFlags; }
  82. void setDrawTexts(bool enable) { m_drawTexts = enable; }
  83. bool isDrawingTexts() { return m_drawTexts; }
  84. void setDrawNames(bool enable) { m_drawNames = enable; }
  85. bool isDrawingNames() { return m_drawNames; }
  86. void setDrawHealthBars(bool enable) { m_drawHealthBars = enable; }
  87. bool isDrawingHealthBars() { return m_drawHealthBars; }
  88. void setDrawLights(bool enable);
  89. bool isDrawingLights() { return m_drawLights; }
  90. void setDrawManaBar(bool enable) { m_drawManaBar = enable; }
  91. bool isDrawingManaBar() { return m_drawManaBar; }
  92. void move(int x, int y);
  93. void setAnimated(bool animated) { m_animated = animated; requestVisibleTilesCacheUpdate(); }
  94. bool isAnimating() { return m_animated; }
  95. void setAddLightMethod(bool add) { m_lightView->setBlendEquation(add ? Painter::BlendEquation_Add : Painter::BlendEquation_Max); }
  96. void setShader(const PainterShaderProgramPtr& shader, float fadein, float fadeout);
  97. PainterShaderProgramPtr getShader() { return m_shader; }
  98. Position getPosition(const Point& point, const Size& mapSize);
  99. MapViewPtr asMapView() { return static_self_cast<MapView>(); }
  100. private:
  101. Rect calcFramebufferSource(const Size& destSize);
  102. int calcFirstVisibleFloor();
  103. int calcLastVisibleFloor();
  104. Point transformPositionTo2D(const Position& position, const Position& relativePosition) {
  105. return Point((m_virtualCenterOffset.x + (position.x - relativePosition.x) - (relativePosition.z - position.z)) * m_tileSize,
  106. (m_virtualCenterOffset.y + (position.y - relativePosition.y) - (relativePosition.z - position.z)) * m_tileSize);
  107. }
  108. int m_lockedFirstVisibleFloor;
  109. int m_cachedFirstVisibleFloor;
  110. int m_cachedLastVisibleFloor;
  111. int m_tileSize;
  112. int m_updateTilesPos;
  113. Size m_drawDimension;
  114. Size m_visibleDimension;
  115. Size m_optimizedSize;
  116. Point m_virtualCenterOffset;
  117. Point m_visibleCenterOffset;
  118. Point m_moveOffset;
  119. Position m_customCameraPosition;
  120. stdext::boolean<true> m_mustUpdateVisibleTilesCache;
  121. stdext::boolean<true> m_mustDrawVisibleTilesCache;
  122. stdext::boolean<true> m_mustCleanFramebuffer;
  123. stdext::boolean<true> m_multifloor;
  124. stdext::boolean<true> m_animated;
  125. stdext::boolean<true> m_autoViewMode;
  126. stdext::boolean<true> m_drawTexts;
  127. stdext::boolean<true> m_drawNames;
  128. stdext::boolean<true> m_drawHealthBars;
  129. stdext::boolean<false> m_drawLights;
  130. stdext::boolean<true> m_drawManaBar;
  131. stdext::boolean<true> m_smooth;
  132. stdext::boolean<true> m_follow;
  133. std::vector<TilePtr> m_cachedVisibleTiles;
  134. std::vector<CreaturePtr> m_cachedFloorVisibleCreatures;
  135. CreaturePtr m_followingCreature;
  136. FrameBufferPtr m_framebuffer;
  137. PainterShaderProgramPtr m_shader;
  138. ViewMode m_viewMode;
  139. Otc::DrawFlags m_drawFlags;
  140. std::vector<Point> m_spiral;
  141. LightViewPtr m_lightView;
  142. float m_minimumAmbientLight;
  143. Timer m_fadeTimer;
  144. PainterShaderProgramPtr m_nextShader;
  145. float m_fadeInTime;
  146. float m_fadeOutTime;
  147. stdext::boolean<true> m_shaderSwitchDone;
  148. };
  149. #endif