]> git.lizzy.rs Git - dragonfireclient.git/blob - src/clientmap.h
Script API: Make the craft recipe field 'method' consistent
[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 "camera.h"
26 #include <set>
27 #include <map>
28
29 struct MapDrawControl
30 {
31         MapDrawControl():
32                 range_all(false),
33                 wanted_range(0),
34                 wanted_max_blocks(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         // Number of blocks rendered is written here by the renderer
47         u32 blocks_drawn;
48         // Number of blocks that would have been drawn in wanted_range
49         u32 blocks_would_have_drawn;
50         // Distance to the farthest block drawn
51         float farthest_drawn;
52 };
53
54 class Client;
55 class ITextureSource;
56
57 /*
58         ClientMap
59         
60         This is the only map class that is able to render itself on screen.
61 */
62
63 class ClientMap : public Map, public scene::ISceneNode
64 {
65 public:
66         ClientMap(
67                         Client *client,
68                         IGameDef *gamedef,
69                         MapDrawControl &control,
70                         scene::ISceneNode* parent,
71                         scene::ISceneManager* mgr,
72                         s32 id
73         );
74
75         ~ClientMap();
76
77         s32 mapType() const
78         {
79                 return MAPTYPE_CLIENT;
80         }
81
82         void drop()
83         {
84                 ISceneNode::drop();
85         }
86
87         void updateCamera(v3f pos, v3f dir, f32 fov, 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(video::IVideoDriver* driver);
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         // Check if sector was drawn on last render()
134         bool sectorWasDrawn(v2s16 p)
135         {
136                 return (m_last_drawn_sectors.find(p) != m_last_drawn_sectors.end());
137         }
138         
139 private:
140         Client *m_client;
141         
142         aabb3f m_box;
143         
144         MapDrawControl &m_control;
145
146         v3f m_camera_position;
147         v3f m_camera_direction;
148         f32 m_camera_fov;
149         v3s16 m_camera_offset;
150
151         std::map<v3s16, MapBlock*> m_drawlist;
152         
153         std::set<v2s16> m_last_drawn_sectors;
154
155         bool m_cache_trilinear_filter;
156         bool m_cache_bilinear_filter;
157         bool m_cache_anistropic_filter;
158 };
159
160 #endif
161