]> git.lizzy.rs Git - minetest.git/blob - src/client/clientmap.h
Fix scaled world-aligned textures being aligned inconsistently for non-normal drawtypes
[minetest.git] / src / client / 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         // show a wire frame for debugging
35         bool show_wireframe = false;
36 };
37
38 struct MeshBufList
39 {
40         video::SMaterial m;
41         std::vector<std::pair<v3s16,scene::IMeshBuffer*>> bufs;
42 };
43
44 struct MeshBufListList
45 {
46         /*!
47          * Stores the mesh buffers of the world.
48          * The array index is the material's layer.
49          * The vector part groups vertices by material.
50          */
51         std::vector<MeshBufList> lists[MAX_TILE_LAYERS];
52
53         void clear();
54         void add(scene::IMeshBuffer *buf, v3s16 position, u8 layer);
55 };
56
57 class Client;
58 class ITextureSource;
59
60 /*
61         ClientMap
62
63         This is the only map class that is able to render itself on screen.
64 */
65
66 class ClientMap : public Map, public scene::ISceneNode
67 {
68 public:
69         ClientMap(
70                         Client *client,
71                         RenderingEngine *rendering_engine,
72                         MapDrawControl &control,
73                         s32 id
74         );
75
76         virtual ~ClientMap() = default;
77
78         s32 mapType() const
79         {
80                 return MAPTYPE_CLIENT;
81         }
82
83         void drop()
84         {
85                 ISceneNode::drop();
86         }
87
88         void updateCamera(const v3f &pos, const v3f &dir, f32 fov, const v3s16 &offset)
89         {
90                 m_camera_position = pos;
91                 m_camera_direction = dir;
92                 m_camera_fov = fov;
93                 m_camera_offset = offset;
94         }
95
96         /*
97                 Forcefully get a sector from somewhere
98         */
99         MapSector * emergeSector(v2s16 p);
100
101         //void deSerializeSector(v2s16 p2d, std::istream &is);
102
103         /*
104                 ISceneNode methods
105         */
106
107         virtual void OnRegisterSceneNode();
108
109         virtual void render()
110         {
111                 video::IVideoDriver* driver = SceneManager->getVideoDriver();
112                 driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
113                 renderMap(driver, SceneManager->getSceneNodeRenderPass());
114         }
115
116         virtual const aabb3f &getBoundingBox() const
117         {
118                 return m_box;
119         }
120
121         void getBlocksInViewRange(v3s16 cam_pos_nodes,
122                 v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f);
123         void updateDrawList();
124         void updateDrawListShadow(const v3f &shadow_light_pos, const v3f &shadow_light_dir, float shadow_range);
125         void renderMap(video::IVideoDriver* driver, s32 pass);
126
127         void renderMapShadows(video::IVideoDriver *driver,
128                         const video::SMaterial &material, s32 pass, int frame, int total_frames);
129
130         int getBackgroundBrightness(float max_d, u32 daylight_factor,
131                         int oldvalue, bool *sunlight_seen_result);
132
133         void renderPostFx(CameraMode cam_mode);
134
135         // For debug printing
136         virtual void PrintInfo(std::ostream &out);
137
138         const MapDrawControl & getControl() const { return m_control; }
139         f32 getWantedRange() const { return m_control.wanted_range; }
140         f32 getCameraFov() const { return m_camera_fov; }
141
142 private:
143         Client *m_client;
144         RenderingEngine *m_rendering_engine;
145
146         aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
147                 BS * 1000000, BS * 1000000, BS * 1000000);
148
149         MapDrawControl &m_control;
150
151         v3f m_camera_position = v3f(0,0,0);
152         v3f m_camera_direction = v3f(0,0,1);
153         f32 m_camera_fov = M_PI;
154         v3s16 m_camera_offset;
155
156         std::map<v3s16, MapBlock*> m_drawlist;
157         std::map<v3s16, MapBlock*> m_drawlist_shadow;
158
159         std::set<v2s16> m_last_drawn_sectors;
160
161         bool m_cache_trilinear_filter;
162         bool m_cache_bilinear_filter;
163         bool m_cache_anistropic_filter;
164         bool m_added_to_shadow_renderer{false};
165 };