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