clientmap.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "irrlichttypes_extrabloated.h"
  18. #include "map.h"
  19. #include "camera.h"
  20. #include <set>
  21. #include <map>
  22. struct MapDrawControl
  23. {
  24. // Overrides limits by drawing everything
  25. bool range_all = false;
  26. // Wanted drawing range
  27. float wanted_range = 0.0f;
  28. // Maximum number of blocks to draw
  29. u32 wanted_max_blocks = 0;
  30. // show a wire frame for debugging
  31. bool show_wireframe = false;
  32. };
  33. class Client;
  34. class ITextureSource;
  35. /*
  36. ClientMap
  37. This is the only map class that is able to render itself on screen.
  38. */
  39. class ClientMap : public Map, public scene::ISceneNode
  40. {
  41. public:
  42. ClientMap(
  43. Client *client,
  44. MapDrawControl &control,
  45. s32 id
  46. );
  47. virtual ~ClientMap() = default;
  48. s32 mapType() const
  49. {
  50. return MAPTYPE_CLIENT;
  51. }
  52. void drop()
  53. {
  54. ISceneNode::drop();
  55. }
  56. void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3s16 &offset)
  57. {
  58. m_camera_position = pos;
  59. m_camera_direction = dir;
  60. m_camera_fov = fov;
  61. m_camera_offset = offset;
  62. }
  63. /*
  64. Forcefully get a sector from somewhere
  65. */
  66. MapSector * emergeSector(v2s16 p);
  67. //void deSerializeSector(v2s16 p2d, std::istream &is);
  68. /*
  69. ISceneNode methods
  70. */
  71. virtual void OnRegisterSceneNode();
  72. virtual void render()
  73. {
  74. video::IVideoDriver* driver = SceneManager->getVideoDriver();
  75. driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
  76. renderMap(driver, SceneManager->getSceneNodeRenderPass());
  77. }
  78. virtual const aabb3f &getBoundingBox() const
  79. {
  80. return m_box;
  81. }
  82. void getBlocksInViewRange(v3s16 cam_pos_nodes,
  83. v3s16 *p_blocks_min, v3s16 *p_blocks_max);
  84. void updateDrawList();
  85. void renderMap(video::IVideoDriver* driver, s32 pass);
  86. int getBackgroundBrightness(float max_d, u32 daylight_factor,
  87. int oldvalue, bool *sunlight_seen_result);
  88. void renderPostFx(CameraMode cam_mode);
  89. // For debug printing
  90. virtual void PrintInfo(std::ostream &out);
  91. const MapDrawControl & getControl() const { return m_control; }
  92. f32 getCameraFov() const { return m_camera_fov; }
  93. private:
  94. Client *m_client;
  95. aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
  96. BS * 1000000, BS * 1000000, BS * 1000000);
  97. MapDrawControl &m_control;
  98. v3f m_camera_position = v3f(0,0,0);
  99. v3f m_camera_direction = v3f(0,0,1);
  100. f32 m_camera_fov = M_PI;
  101. v3s16 m_camera_offset;
  102. std::map<v3s16, MapBlock*> m_drawlist;
  103. std::set<v2s16> m_last_drawn_sectors;
  104. bool m_cache_trilinear_filter;
  105. bool m_cache_bilinear_filter;
  106. bool m_cache_anistropic_filter;
  107. };