on_death: Fix callback number of pushed arguments (Fixes #6451)
[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 #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         // Maximum number of blocks to draw
35         u32 wanted_max_blocks = 0;
36         // show a wire frame for debugging
37         bool show_wireframe = false;
38 };
39
40 class Client;
41 class ITextureSource;
42
43 /*
44         ClientMap
45
46         This is the only map class that is able to render itself on screen.
47 */
48
49 class ClientMap : public Map, public scene::ISceneNode
50 {
51 public:
52         ClientMap(
53                         Client *client,
54                         MapDrawControl &control,
55                         s32 id
56         );
57
58         virtual ~ClientMap() = default;
59
60         s32 mapType() const
61         {
62                 return MAPTYPE_CLIENT;
63         }
64
65         void drop()
66         {
67                 ISceneNode::drop();
68         }
69
70         void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3s16 &offset)
71         {
72                 m_camera_position = pos;
73                 m_camera_direction = dir;
74                 m_camera_fov = fov;
75                 m_camera_offset = offset;
76         }
77
78         /*
79                 Forcefully get a sector from somewhere
80         */
81         MapSector * emergeSector(v2s16 p);
82
83         //void deSerializeSector(v2s16 p2d, std::istream &is);
84
85         /*
86                 ISceneNode methods
87         */
88
89         virtual void OnRegisterSceneNode();
90
91         virtual void render()
92         {
93                 video::IVideoDriver* driver = SceneManager->getVideoDriver();
94                 driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
95                 renderMap(driver, SceneManager->getSceneNodeRenderPass());
96         }
97
98         virtual const aabb3f &getBoundingBox() const
99         {
100                 return m_box;
101         }
102
103         void getBlocksInViewRange(v3s16 cam_pos_nodes,
104                 v3s16 *p_blocks_min, v3s16 *p_blocks_max);
105         void updateDrawList();
106         void renderMap(video::IVideoDriver* driver, s32 pass);
107
108         int getBackgroundBrightness(float max_d, u32 daylight_factor,
109                         int oldvalue, bool *sunlight_seen_result);
110
111         void renderPostFx(CameraMode cam_mode);
112
113         // For debug printing
114         virtual void PrintInfo(std::ostream &out);
115
116         const MapDrawControl & getControl() const { return m_control; }
117         f32 getCameraFov() const { return m_camera_fov; }
118 private:
119         Client *m_client;
120
121         aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
122                 BS * 1000000, BS * 1000000, BS * 1000000);
123
124         MapDrawControl &m_control;
125
126         v3f m_camera_position = v3f(0,0,0);
127         v3f m_camera_direction = v3f(0,0,1);
128         f32 m_camera_fov = M_PI;
129         v3s16 m_camera_offset;
130
131         std::map<v3s16, MapBlock*> m_drawlist;
132
133         std::set<v2s16> m_last_drawn_sectors;
134
135         bool m_cache_trilinear_filter;
136         bool m_cache_bilinear_filter;
137         bool m_cache_anistropic_filter;
138 };