C++11 patchset 9: move hardcoded init parameters to class definitions (part 1) (...
[oweals/minetest.git] / src / clientmap.h
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 #ifndef CLIENTMAP_HEADER
21 #define CLIENTMAP_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24 #include "map.h"
25 #include "camera.h"
26 #include <set>
27 #include <map>
28
29 struct MapDrawControl
30 {
31         // Overrides limits by drawing everything
32         bool range_all = false;
33         // Wanted drawing range
34         float wanted_range = 0.0f;
35         // Maximum number of blocks to draw
36         u32 wanted_max_blocks = 0;
37         // show a wire frame for debugging
38         bool show_wireframe = false;
39         // Number of blocks rendered is written here by the renderer
40         u32 blocks_drawn = 0;
41         // Number of blocks that would have been drawn in wanted_range
42         u32 blocks_would_have_drawn = 0;
43         // Distance to the farthest block drawn
44         float farthest_drawn = 0;
45 };
46
47 class Client;
48 class ITextureSource;
49
50 /*
51         ClientMap
52
53         This is the only map class that is able to render itself on screen.
54 */
55
56 class ClientMap : public Map, public scene::ISceneNode
57 {
58 public:
59         ClientMap(
60                         Client *client,
61                         MapDrawControl &control,
62                         scene::ISceneNode* parent,
63                         scene::ISceneManager* mgr,
64                         s32 id
65         );
66
67         ~ClientMap();
68
69         s32 mapType() const
70         {
71                 return MAPTYPE_CLIENT;
72         }
73
74         void drop()
75         {
76                 ISceneNode::drop();
77         }
78
79         void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset)
80         {
81                 m_camera_position = pos;
82                 m_camera_direction = dir;
83                 m_camera_fov = fov;
84                 m_camera_offset = offset;
85         }
86
87         /*
88                 Forcefully get a sector from somewhere
89         */
90         MapSector * emergeSector(v2s16 p);
91
92         //void deSerializeSector(v2s16 p2d, std::istream &is);
93
94         /*
95                 ISceneNode methods
96         */
97
98         virtual void OnRegisterSceneNode();
99
100         virtual void render()
101         {
102                 video::IVideoDriver* driver = SceneManager->getVideoDriver();
103                 driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
104                 renderMap(driver, SceneManager->getSceneNodeRenderPass());
105         }
106
107         virtual const aabb3f &getBoundingBox() const
108         {
109                 return m_box;
110         }
111
112         void getBlocksInViewRange(v3s16 cam_pos_nodes,
113                 v3s16 *p_blocks_min, v3s16 *p_blocks_max);
114         void updateDrawList(video::IVideoDriver* driver);
115         void renderMap(video::IVideoDriver* driver, s32 pass);
116
117         int getBackgroundBrightness(float max_d, u32 daylight_factor,
118                         int oldvalue, bool *sunlight_seen_result);
119
120         void renderPostFx(CameraMode cam_mode);
121
122         // For debug printing
123         virtual void PrintInfo(std::ostream &out);
124
125         const MapDrawControl & getControl() const { return m_control; }
126         f32 getCameraFov() const { return m_camera_fov; }
127 private:
128         Client *m_client;
129
130         aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
131                 BS * 1000000, BS * 1000000, BS * 1000000);
132
133         MapDrawControl &m_control;
134
135         v3f m_camera_position;
136         v3f m_camera_direction = v3f(0,0,1);
137         f32 m_camera_fov = M_PI;
138         v3s16 m_camera_offset;
139
140         std::map<v3s16, MapBlock*> m_drawlist;
141
142         std::set<v2s16> m_last_drawn_sectors;
143
144         bool m_cache_trilinear_filter;
145         bool m_cache_bilinear_filter;
146         bool m_cache_anistropic_filter;
147 };
148
149 #endif
150