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