Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
clientmap.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
8#include "map.h"
9#include "camera.h"
10#include <set>
11#include <map>
12
14{
15 // Wanted drawing range
16 float wanted_range = 0.0f;
17 // Overrides limits by drawing everything
18 bool range_all = false;
19 // Allow rendering out of bounds
20 bool allow_noclip = false;
21 // show a wire frame for debugging
22 bool show_wireframe = false;
23};
24
25class Client;
26class ITextureSource;
28
29namespace irr::scene
30{
31 class IMeshBuffer;
32}
33
34namespace irr::video
35{
36 class IVideoDriver;
37}
38
39/*
40 ClientMap
41
42 This is the only map class that is able to render itself on screen.
43*/
44
45class ClientMap : public Map, public scene::ISceneNode
46{
47public:
50 RenderingEngine *rendering_engine,
51 MapDrawControl &control,
52 s32 id
53 );
54
55 bool maySaveBlocks() override
56 {
57 return false;
58 }
59
60 void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SColor light_color);
61
62 /*
63 Forcefully get a sector from somewhere
64 */
65 MapSector * emergeSector(v2s16 p) override;
66
67 /*
68 ISceneNode methods
69 */
70
71 virtual void OnRegisterSceneNode() override;
72
73 virtual void render() override;
74
75 virtual const aabb3f &getBoundingBox() const override
76 {
77 return m_box;
78 }
79
80 void getBlocksInViewRange(v3s16 cam_pos_nodes,
81 v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f);
82 void updateDrawList();
83 // @brief Calculate statistics about the map and keep the blocks alive
84 void touchMapBlocks();
85 void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length);
86 // Returns true if draw list needs updating before drawing the next frame.
88 void renderMap(video::IVideoDriver* driver, s32 pass);
89
90 void renderMapShadows(video::IVideoDriver *driver,
91 const video::SMaterial &material, s32 pass, int frame, int total_frames);
92
93 int getBackgroundBrightness(float max_d, u32 daylight_factor,
94 int oldvalue, bool *sunlight_seen_result);
95
96 void renderPostFx(CameraMode cam_mode);
97
98 // For debug printing
99 void PrintInfo(std::ostream &out) override;
100
101 const MapDrawControl & getControl() const { return m_control; }
102 f32 getWantedRange() const { return m_control.wanted_range; }
103 f32 getCameraFov() const { return m_camera_fov; }
104
105 void onSettingChanged(std::string_view name, bool all);
106
107protected:
108 // use drop() instead
109 virtual ~ClientMap();
110
111 void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override;
112private:
113 bool isMeshOccluded(MapBlock *mesh_block, u16 mesh_size, v3s16 cam_pos_nodes);
114
115 // update the vertex order in transparent mesh buffers
117
118
119 // Orders blocks by distance to the camera
121 {
122 public:
123 MapBlockComparer(const v3s16 &camera_block) : m_camera_block(camera_block) {}
124
125 bool operator() (const v3s16 &left, const v3s16 &right) const
126 {
127 auto distance_left = left.getDistanceFromSQ(m_camera_block);
128 auto distance_right = right.getDistanceFromSQ(m_camera_block);
129 return distance_left > distance_right || (distance_left == distance_right && left > right);
130 }
131
132 private:
134 };
135
136
137 // reference to a mesh buffer used when rendering the map.
140 union {
141 scene::IMeshBuffer *m_buffer;
143 };
146
147 DrawDescriptor(v3s16 pos, scene::IMeshBuffer *buffer, bool reuse_material) :
148 m_pos(pos), m_buffer(buffer), m_reuse_material(reuse_material), m_use_partial_buffer(false)
149 {}
150
153 {}
154
155 video::SMaterial &getMaterial();
157 u32 draw(video::IVideoDriver* driver);
158 };
159
162
163 aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
164 BS * 1000000, BS * 1000000, BS * 1000000);
165
167
170 f32 m_camera_fov = M_PI;
172 video::SColor m_camera_light_color = video::SColor(0xFFFFFFFF);
174
175 std::map<v3s16, MapBlock*, MapBlockComparer> m_drawlist;
176 std::vector<MapBlock*> m_keeplist;
177 std::map<v3s16, MapBlock*> m_drawlist_shadow;
179
180 std::set<v2s16> m_last_drawn_sectors;
181
186
189};
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:191
CameraMode
Definition camera.h:60
Definition clientmap.h:121
MapBlockComparer(const v3s16 &camera_block)
Definition clientmap.h:123
v3s16 m_camera_block
Definition clientmap.h:133
bool operator()(const v3s16 &left, const v3s16 &right) const
Definition clientmap.h:125
Definition clientmap.h:46
bool m_cache_anistropic_filter
Definition clientmap.h:184
std::map< v3s16, MapBlock *, MapBlockComparer > m_drawlist
Definition clientmap.h:175
void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length)
Definition clientmap.cpp:1251
bool m_enable_raytraced_culling
Definition clientmap.h:188
bool m_needs_update_transparent_meshes
Definition clientmap.h:173
ClientMap(Client *client, RenderingEngine *rendering_engine, MapDrawControl &control, s32 id)
Definition clientmap.cpp:81
void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override
Definition clientmap.cpp:1305
Client * m_client
Definition clientmap.h:160
f32 m_camera_fov
Definition clientmap.h:170
const MapDrawControl & getControl() const
Definition clientmap.h:101
virtual ~ClientMap()
Definition clientmap.cpp:126
virtual void OnRegisterSceneNode() override
Definition clientmap.cpp:168
f32 getWantedRange() const
Definition clientmap.h:102
v3s16 m_camera_offset
Definition clientmap.h:171
bool m_loops_occlusion_culler
Definition clientmap.h:187
void updateDrawList()
Definition clientmap.cpp:266
int getBackgroundBrightness(float max_d, u32 daylight_factor, int oldvalue, bool *sunlight_seen_result)
Definition clientmap.cpp:969
void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SColor light_color)
Definition clientmap.cpp:131
void renderPostFx(CameraMode cam_mode)
Definition clientmap.cpp:1054
void touchMapBlocks()
Definition clientmap.cpp:631
void onSettingChanged(std::string_view name, bool all)
Definition clientmap.cpp:110
std::map< v3s16, MapBlock * > m_drawlist_shadow
Definition clientmap.h:177
aabb3f m_box
Definition clientmap.h:163
bool maySaveBlocks() override
Definition clientmap.h:55
void renderMap(video::IVideoDriver *driver, s32 pass)
Definition clientmap.cpp:700
video::SColor m_camera_light_color
Definition clientmap.h:172
virtual const aabb3f & getBoundingBox() const override
Definition clientmap.h:75
bool m_needs_update_drawlist
Definition clientmap.h:178
virtual void render() override
Definition clientmap.cpp:181
f32 getCameraFov() const
Definition clientmap.h:103
MapSector * emergeSector(v2s16 p) override
Definition clientmap.cpp:154
std::vector< MapBlock * > m_keeplist
Definition clientmap.h:176
v3f m_camera_position
Definition clientmap.h:168
bool m_cache_trilinear_filter
Definition clientmap.h:182
RenderingEngine * m_rendering_engine
Definition clientmap.h:161
void PrintInfo(std::ostream &out) override
Definition clientmap.cpp:1089
MapDrawControl & m_control
Definition clientmap.h:166
u16 m_cache_transparency_sorting_distance
Definition clientmap.h:185
void renderMapShadows(video::IVideoDriver *driver, const video::SMaterial &material, s32 pass, int frame, int total_frames)
Definition clientmap.cpp:1094
v3f m_camera_direction
Definition clientmap.h:169
bool needsUpdateDrawList()
Definition clientmap.h:87
void updateTransparentMeshBuffers()
Definition clientmap.cpp:1310
bool m_cache_bilinear_filter
Definition clientmap.h:183
void getBlocksInViewRange(v3s16 cam_pos_nodes, v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f)
Definition clientmap.cpp:188
std::set< v2s16 > m_last_drawn_sectors
Definition clientmap.h:180
bool isMeshOccluded(MapBlock *mesh_block, u16 mesh_size, v3s16 cam_pos_nodes)
Definition clientmap.cpp:1370
Definition client.h:105
Definition texturesource.h:36
Definition mapblock.h:58
Definition mapsector.h:25
Definition map.h:101
Definition mapblock_mesh.h:135
Definition renderingengine.h:68
#define BS
Definition constants.h:61
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
core::vector3df v3f
Definition irr_v3d.h:11
Definition activeobjectmgr.cpp:11
Definition clientmap.h:30
Definition clientmap.h:35
Definition clientmap.h:138
video::SMaterial & getMaterial()
Definition clientmap.cpp:1354
bool m_use_partial_buffer
Definition clientmap.h:145
u32 draw(video::IVideoDriver *driver)
Definition clientmap.cpp:1359
scene::IMeshBuffer * m_buffer
Definition clientmap.h:141
v3s16 m_pos
Definition clientmap.h:139
DrawDescriptor(v3s16 pos, const PartialMeshBuffer *buffer)
Definition clientmap.h:151
DrawDescriptor(v3s16 pos, scene::IMeshBuffer *buffer, bool reuse_material)
Definition clientmap.h:147
bool m_reuse_material
Definition clientmap.h:144
const PartialMeshBuffer * m_partial_buffer
Definition clientmap.h:142
Definition clientmap.h:14
float wanted_range
Definition clientmap.h:16
bool allow_noclip
Definition clientmap.h:20
bool range_all
Definition clientmap.h:18
bool show_wireframe
Definition clientmap.h:22
static std::string p(std::string path)
Definition test_filesys.cpp:53