Luanti 5.18.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 <ISceneNode.h>
10#include <map>
11#include <functional>
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 RenderingEngine;
27
28enum CameraMode : int;
29
30namespace scene
31{
32 class IMeshBuffer;
33}
34
35namespace video
36{
37 class IVideoDriver;
38}
39
41 std::vector<scene::IMeshBuffer*> buf;
42 u8 age = 0;
43
44 void drop();
45};
46
47using CachedMeshBuffers = std::unordered_map<std::string, CachedMeshBuffer>;
48
49using ModifyMaterialCallback = std::function<void(video::SMaterial& /* material */, bool /* is_foliage */)>;
50
51/*
52 ClientMap
53
54 This is the only map class that is able to render itself on screen.
55*/
56
57class ClientMap : public Map, public scene::ISceneNode
58{
59public:
62 RenderingEngine *rendering_engine,
63 MapDrawControl &control,
64 s32 id
65 );
66
67 bool maySaveBlocks() override
68 {
69 return false;
70 }
71
72 void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SColor light_color);
73
74 /*
75 Forcefully get a sector from somewhere
76 */
77 MapSector * emergeSector(v2s16 p) override;
78
79 /*
80 ISceneNode methods
81 */
82
83 virtual void OnRegisterSceneNode() override;
84
85 virtual void render() override;
86
87 virtual const aabb3f &getBoundingBox() const override
88 {
89 return m_box;
90 }
91
92 void getBlocksInViewRange(v3s16 cam_pos_nodes,
93 v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f);
94
95 void updateDrawList();
97 void clearDrawList();
98
100 void touchMapBlocks();
101
102 void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length);
103 void clearDrawListShadow();
104
105 // Returns true if draw list needs updating before drawing the next frame.
107
108 void renderMap(video::IVideoDriver* driver, s32 pass);
109
110 void renderMapShadows(video::IVideoDriver *driver,
111 ModifyMaterialCallback cb, s32 pass, int frame, int total_frames);
112
113 int getBackgroundBrightness(float max_d, u32 daylight_factor,
114 int oldvalue, bool *sunlight_seen_result);
115
116 void renderPostFx(CameraMode cam_mode);
117
119
120 // For debug printing
121 void PrintInfo(std::ostream &out) override;
122
123 const MapDrawControl & getControl() const { return m_control; }
124 f32 getWantedRange() const { return m_control.wanted_range; }
125 f32 getCameraFov() const { return m_camera_fov; }
126
127 void onSettingChanged(std::string_view name, bool all);
128
129protected:
130 // use drop() instead
131 virtual ~ClientMap();
132
133 void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override;
134private:
135 bool isMeshOccluded(MapBlock *mesh_block, u16 mesh_size, v3s16 cam_pos_nodes);
136
137 bool useLoopsCuller() const;
138
139 // update the vertex order in transparent mesh buffers
141
142 // Orders blocks by distance to the camera
144 {
145 public:
146 MapBlockComparer(const v3s16 &camera_block) : m_camera_block(camera_block) {}
147
148 bool operator() (const v3s16 &left, const v3s16 &right) const
149 {
150 auto distance_left = left.getDistanceFromSQ(m_camera_block);
151 auto distance_right = right.getDistanceFromSQ(m_camera_block);
152 return distance_left > distance_right || (distance_left == distance_right && left > right);
153 }
154
155 private:
157 };
158
161
162 aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
163 BS * 1000000, BS * 1000000, BS * 1000000);
164
166
169 f32 m_camera_fov = M_PI;
171 video::SColor m_camera_light_color = video::SColor(0xFFFFFFFF);
173
174 std::map<v3s16, MapBlock*, MapBlockComparer> m_drawlist;
175 // List of additional blocks to keep (relevant with mesh_chunk > 1, since
176 // not all blocks contain a mesh)
177 std::vector<MapBlock*> m_keeplist;
178 std::map<v3s16, MapBlock*> m_drawlist_shadow;
181
187
190};
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:205
MapBlockComparer(const v3s16 &camera_block)
Definition clientmap.h:146
v3s16 m_camera_block
Definition clientmap.h:156
bool operator()(const v3s16 &left, const v3s16 &right) const
Definition clientmap.h:148
bool m_cache_anistropic_filter
Definition clientmap.h:184
bool useLoopsCuller() const
Definition clientmap.cpp:220
std::map< v3s16, MapBlock *, MapBlockComparer > m_drawlist
Definition clientmap.h:174
void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length)
Definition clientmap.cpp:1565
bool m_enable_raytraced_culling
Definition clientmap.h:189
bool m_needs_update_transparent_meshes
Definition clientmap.h:172
ClientMap(Client *client, RenderingEngine *rendering_engine, MapDrawControl &control, s32 id)
Definition clientmap.cpp:159
void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override
Definition clientmap.cpp:1615
Client * m_client
Definition clientmap.h:159
f32 m_camera_fov
Definition clientmap.h:169
const MapDrawControl & getControl() const
Definition clientmap.h:123
virtual ~ClientMap()
Definition clientmap.cpp:206
virtual void OnRegisterSceneNode() override
Definition clientmap.cpp:286
f32 getWantedRange() const
Definition clientmap.h:124
bool m_cache_transparency_sorting_group_by_buffers
Definition clientmap.h:185
v3s16 m_camera_offset
Definition clientmap.h:170
bool m_loops_occlusion_culler
Definition clientmap.h:188
void updateDrawList()
Definition clientmap.cpp:399
int getBackgroundBrightness(float max_d, u32 daylight_factor, int oldvalue, bool *sunlight_seen_result)
Definition clientmap.cpp:1310
void invalidateMapBlockMesh(MapBlockMesh *mesh)
Definition clientmap.cpp:1194
void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SColor light_color)
Definition clientmap.cpp:241
void renderPostFx(CameraMode cam_mode)
Definition clientmap.cpp:1395
void touchMapBlocks()
Calculate statistics about the map and keep the blocks alive.
Definition clientmap.cpp:752
void onSettingChanged(std::string_view name, bool all)
Definition clientmap.cpp:187
std::map< v3s16, MapBlock * > m_drawlist_shadow
Definition clientmap.h:178
aabb3f m_box
Definition clientmap.h:162
bool maySaveBlocks() override
Definition clientmap.h:67
void renderMap(video::IVideoDriver *driver, s32 pass)
Definition clientmap.cpp:998
video::SColor m_camera_light_color
Definition clientmap.h:171
virtual const aabb3f & getBoundingBox() const override
Definition clientmap.h:87
bool m_needs_update_drawlist
Definition clientmap.h:179
virtual void render() override
Definition clientmap.cpp:299
f32 getCameraFov() const
Definition clientmap.h:125
MapSector * emergeSector(v2s16 p) override
Definition clientmap.cpp:272
std::vector< MapBlock * > m_keeplist
Definition clientmap.h:177
v3f m_camera_position
Definition clientmap.h:167
bool m_cache_trilinear_filter
Definition clientmap.h:182
RenderingEngine * m_rendering_engine
Definition clientmap.h:160
void renderMapShadows(video::IVideoDriver *driver, ModifyMaterialCallback cb, s32 pass, int frame, int total_frames)
Definition clientmap.cpp:1435
void PrintInfo(std::ostream &out) override
Definition clientmap.cpp:1430
CachedMeshBuffers m_dynamic_buffers
Definition clientmap.h:180
void clearDrawList()
clears m_drawlist and m_keeplist
Definition clientmap.cpp:384
MapDrawControl & m_control
Definition clientmap.h:165
u16 m_cache_transparency_sorting_distance
Definition clientmap.h:186
v3f m_camera_direction
Definition clientmap.h:168
bool needsUpdateDrawList()
Definition clientmap.h:106
void clearDrawListShadow()
Definition clientmap.cpp:1553
void updateTransparentMeshBuffers()
Definition clientmap.cpp:1620
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:306
bool isMeshOccluded(MapBlock *mesh_block, u16 mesh_size, v3s16 cam_pos_nodes)
Definition clientmap.cpp:1681
Definition client.h:107
Definition mapblock_mesh.h:178
Definition mapblock.h:58
Definition mapsector.h:23
Map(IGameDef *gamedef)
Definition map.cpp:24
Definition renderingengine.h:64
std::function< void(video::SMaterial &, bool)> ModifyMaterialCallback
Definition clientmap.h:49
std::unordered_map< std::string, CachedMeshBuffer > CachedMeshBuffers
Definition clientmap.h:47
#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 camera.h:24
Definition clientmap.h:36
CameraMode
Definition player.h:148
Definition clientmap.h:40
void drop()
Definition clientmap.cpp:133
std::vector< scene::IMeshBuffer * > buf
Definition clientmap.h:41
u8 age
Definition clientmap.h:42
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:73