]> git.lizzy.rs Git - minetest.git/blob - src/client/clientmap.h
Add helpful error messages if Irrlicht library / include dir are set incorrectly...
[minetest.git] / src / client / 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 #pragma once
21
22 #include "irrlichttypes_extrabloated.h"
23 #include "map.h"
24 #include "camera.h"
25 #include <set>
26 #include <map>
27
28 struct MapDrawControl
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
38 struct MeshBufList
39 {
40         video::SMaterial m;
41         std::vector<std::pair<v3s16,scene::IMeshBuffer*>> bufs;
42 };
43
44 struct MeshBufListList
45 {
46         /*!
47          * Stores the mesh buffers of the world.
48          * The array index is the material's layer.
49          * The vector part groups vertices by material.
50          */
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;
90                 m_camera_direction = dir;
91                 m_camera_fov = fov;
92                 m_camera_offset = offset;
93         }
94
95         /*
96                 Forcefully get a sector from somewhere
97         */
98         MapSector * emergeSector(v2s16 p);
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:
136         Client *m_client;
137
138         aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
139                 BS * 1000000, BS * 1000000, BS * 1000000);
140
141         MapDrawControl &m_control;
142
143         v3f m_camera_position = v3f(0,0,0);
144         v3f m_camera_direction = v3f(0,0,1);
145         f32 m_camera_fov = M_PI;
146         v3s16 m_camera_offset;
147
148         std::map<v3s16, MapBlock*> m_drawlist;
149
150         std::set<v2s16> m_last_drawn_sectors;
151
152         bool m_cache_trilinear_filter;
153         bool m_cache_bilinear_filter;
154         bool m_cache_anistropic_filter;
155 };