Translated using Weblate (Polish)
[oweals/minetest.git] / src / clientmap.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2012 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
26 struct MapDrawControl
27 {
28         MapDrawControl():
29                 range_all(false),
30                 wanted_range(50),
31                 wanted_max_blocks(0),
32                 wanted_min_range(0),
33                 blocks_drawn(0),
34                 blocks_would_have_drawn(0)
35         {
36         }
37         // Overrides limits by drawing everything
38         bool range_all;
39         // Wanted drawing range
40         float wanted_range;
41         // Maximum number of blocks to draw
42         u32 wanted_max_blocks;
43         // Blocks in this range are drawn regardless of number of blocks drawn
44         float wanted_min_range;
45         // Number of blocks rendered is written here by the renderer
46         u32 blocks_drawn;
47         // Number of blocks that would have been drawn in wanted_range
48         u32 blocks_would_have_drawn;
49 };
50
51 class Client;
52 class ITextureSource;
53
54 /*
55         ClientMap
56         
57         This is the only map class that is able to render itself on screen.
58 */
59
60 class ClientMap : public Map, public scene::ISceneNode
61 {
62 public:
63         ClientMap(
64                         Client *client,
65                         IGameDef *gamedef,
66                         MapDrawControl &control,
67                         scene::ISceneNode* parent,
68                         scene::ISceneManager* mgr,
69                         s32 id
70         );
71
72         ~ClientMap();
73
74         s32 mapType() const
75         {
76                 return MAPTYPE_CLIENT;
77         }
78
79         void drop()
80         {
81                 ISceneNode::drop();
82         }
83
84         void updateCamera(v3f pos, v3f dir, f32 fov)
85         {
86                 JMutexAutoLock lock(m_camera_mutex);
87                 m_camera_position = pos;
88                 m_camera_direction = dir;
89                 m_camera_fov = fov;
90         }
91
92         /*
93                 Forcefully get a sector from somewhere
94         */
95         MapSector * emergeSector(v2s16 p);
96
97         //void deSerializeSector(v2s16 p2d, std::istream &is);
98
99         /*
100                 ISceneNode methods
101         */
102
103         virtual void OnRegisterSceneNode();
104
105         virtual void render()
106         {
107                 video::IVideoDriver* driver = SceneManager->getVideoDriver();
108                 driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
109                 renderMap(driver, SceneManager->getSceneNodeRenderPass());
110         }
111         
112         virtual const core::aabbox3d<f32>& getBoundingBox() const
113         {
114                 return m_box;
115         }
116         
117         void updateDrawList(video::IVideoDriver* driver);
118         void renderMap(video::IVideoDriver* driver, s32 pass);
119
120         int getBackgroundBrightness(float max_d, u32 daylight_factor,
121                         int oldvalue, bool *sunlight_seen_result);
122
123         void renderPostFx();
124
125         // For debug printing
126         virtual void PrintInfo(std::ostream &out);
127         
128         // Check if sector was drawn on last render()
129         bool sectorWasDrawn(v2s16 p)
130         {
131                 return (m_last_drawn_sectors.find(p) != NULL);
132         }
133         
134 private:
135         Client *m_client;
136         
137         core::aabbox3d<f32> m_box;
138         
139         MapDrawControl &m_control;
140
141         v3f m_camera_position;
142         v3f m_camera_direction;
143         f32 m_camera_fov;
144         JMutex m_camera_mutex;
145
146         core::map<v3s16, MapBlock*> m_drawlist;
147         
148         core::map<v2s16, bool> m_last_drawn_sectors;
149 };
150
151 #endif
152