Minetest  5.4.0
clientmap.h
Go to the documentation of this file.
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #pragma once
21 
23 #include "map.h"
24 #include "camera.h"
25 #include <set>
26 #include <map>
27 
29 {
30  // Overrides limits by drawing everything
31  bool range_all = false;
32  // Wanted drawing range
33  float wanted_range = 0.0f;
34  // show a wire frame for debugging
35  bool show_wireframe = false;
36 };
37 
39 {
40  video::SMaterial m;
41  std::vector<std::pair<v3s16,scene::IMeshBuffer*>> bufs;
42 };
43 
45 {
51  std::vector<MeshBufList> lists[MAX_TILE_LAYERS];
52 
53  void clear();
54  void add(scene::IMeshBuffer *buf, v3s16 position, u8 layer);
55 };
56 
57 class Client;
58 class ITextureSource;
59 
60 /*
61  ClientMap
62 
63  This is the only map class that is able to render itself on screen.
64 */
65 
66 class ClientMap : public Map, public scene::ISceneNode
67 {
68 public:
69  ClientMap(
70  Client *client,
71  MapDrawControl &control,
72  s32 id
73  );
74 
75  virtual ~ClientMap() = default;
76 
77  s32 mapType() const
78  {
79  return MAPTYPE_CLIENT;
80  }
81 
82  void drop()
83  {
84  ISceneNode::drop();
85  }
86 
87  void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3s16 &offset)
88  {
89  m_camera_position = pos;
91  m_camera_fov = fov;
92  m_camera_offset = offset;
93  }
94 
95  /*
96  Forcefully get a sector from somewhere
97  */
99 
100  //void deSerializeSector(v2s16 p2d, std::istream &is);
101 
102  /*
103  ISceneNode methods
104  */
105 
106  virtual void OnRegisterSceneNode();
107 
108  virtual void render()
109  {
110  video::IVideoDriver* driver = SceneManager->getVideoDriver();
111  driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
112  renderMap(driver, SceneManager->getSceneNodeRenderPass());
113  }
114 
115  virtual const aabb3f &getBoundingBox() const
116  {
117  return m_box;
118  }
119 
120  void getBlocksInViewRange(v3s16 cam_pos_nodes,
121  v3s16 *p_blocks_min, v3s16 *p_blocks_max);
122  void updateDrawList();
123  void renderMap(video::IVideoDriver* driver, s32 pass);
124 
125  int getBackgroundBrightness(float max_d, u32 daylight_factor,
126  int oldvalue, bool *sunlight_seen_result);
127 
128  void renderPostFx(CameraMode cam_mode);
129 
130  // For debug printing
131  virtual void PrintInfo(std::ostream &out);
132 
133  const MapDrawControl & getControl() const { return m_control; }
134  f32 getCameraFov() const { return m_camera_fov; }
135 private:
137 
138  aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
139  BS * 1000000, BS * 1000000, BS * 1000000);
140 
142 
145  f32 m_camera_fov = M_PI;
147 
148  std::map<v3s16, MapBlock*> m_drawlist;
149 
150  std::set<v2s16> m_last_drawn_sectors;
151 
155 };
static v2f dir(const v2f &pos_dist)
Definition: camera.cpp:240
CameraMode
Definition: camera.h:71
Definition: clientmap.h:67
bool m_cache_anistropic_filter
Definition: clientmap.h:154
s32 mapType() const
Definition: clientmap.h:77
virtual void PrintInfo(std::ostream &out)
Definition: clientmap.cpp:604
Client * m_client
Definition: clientmap.h:136
virtual void OnRegisterSceneNode()
Definition: clientmap.cpp:108
f32 m_camera_fov
Definition: clientmap.h:145
ClientMap(Client *client, MapDrawControl &control, s32 id)
Definition: clientmap.cpp:65
v3s16 m_camera_offset
Definition: clientmap.h:146
void updateDrawList()
Definition: clientmap.cpp:146
int getBackgroundBrightness(float max_d, u32 daylight_factor, int oldvalue, bool *sunlight_seen_result)
Definition: clientmap.cpp:492
void getBlocksInViewRange(v3s16 cam_pos_nodes, v3s16 *p_blocks_min, v3s16 *p_blocks_max)
Definition: clientmap.cpp:119
void renderPostFx(CameraMode cam_mode)
Definition: clientmap.cpp:576
void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3s16 &offset)
Definition: clientmap.h:87
std::map< v3s16, MapBlock * > m_drawlist
Definition: clientmap.h:148
virtual ~ClientMap()=default
aabb3f m_box
Definition: clientmap.h:138
void renderMap(video::IVideoDriver *driver, s32 pass)
Definition: clientmap.cpp:261
MapSector * emergeSector(v2s16 p)
Definition: clientmap.cpp:94
f32 getCameraFov() const
Definition: clientmap.h:134
v3f m_camera_position
Definition: clientmap.h:143
bool m_cache_trilinear_filter
Definition: clientmap.h:152
const MapDrawControl & getControl() const
Definition: clientmap.h:133
virtual void render()
Definition: clientmap.h:108
virtual const aabb3f & getBoundingBox() const
Definition: clientmap.h:115
MapDrawControl & m_control
Definition: clientmap.h:141
v3f m_camera_direction
Definition: clientmap.h:144
void drop()
Definition: clientmap.h:82
bool m_cache_bilinear_filter
Definition: clientmap.h:153
std::set< v2s16 > m_last_drawn_sectors
Definition: clientmap.h:150
Definition: client.h:109
Definition: tile.h:86
Definition: mapsector.h:40
Definition: map.h:123
#define BS
Definition: constants.h:74
core::aabbox3d< f32 > aabb3f
Definition: irr_aabb3d.h:26
core::vector2d< s16 > v2s16
Definition: irr_v2d.h:27
core::vector3d< s16 > v3s16
Definition: irr_v3d.h:28
core::vector3df v3f
Definition: irr_v3d.h:26
#define MAPTYPE_CLIENT
Definition: map.h:59
Definition: activeobjectmgr.cpp:25
Definition: clientmap.h:29
float wanted_range
Definition: clientmap.h:33
bool range_all
Definition: clientmap.h:31
bool show_wireframe
Definition: clientmap.h:35
Definition: clientmap.h:45
void add(scene::IMeshBuffer *buf, v3s16 position, u8 layer)
Definition: clientmap.cpp:41
void clear()
Definition: clientmap.cpp:35
std::vector< MeshBufList > lists[MAX_TILE_LAYERS]
Definition: clientmap.h:51
Definition: clientmap.h:39
video::SMaterial m
Definition: clientmap.h:40
std::vector< std::pair< v3s16, scene::IMeshBuffer * > > bufs
Definition: clientmap.h:41
std::string p(std::string path)
Definition: test_filepath.cpp:59
#define MAX_TILE_LAYERS
Definition: tile.h:183