Luanti 5.15.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 // update the vertex order in transparent mesh buffers
139
140 // Orders blocks by distance to the camera
142 {
143 public:
144 MapBlockComparer(const v3s16 &camera_block) : m_camera_block(camera_block) {}
145
146 bool operator() (const v3s16 &left, const v3s16 &right) const
147 {
148 auto distance_left = left.getDistanceFromSQ(m_camera_block);
149 auto distance_right = right.getDistanceFromSQ(m_camera_block);
150 return distance_left > distance_right || (distance_left == distance_right && left > right);
151 }
152
153 private:
155 };
156
159
160 aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
161 BS * 1000000, BS * 1000000, BS * 1000000);
162
164
167 f32 m_camera_fov = M_PI;
169 video::SColor m_camera_light_color = video::SColor(0xFFFFFFFF);
171
172 std::map<v3s16, MapBlock*, MapBlockComparer> m_drawlist;
173 // List of additional blocks to keep (relevant with mesh_chunk > 1, since
174 // not all blocks contain a mesh)
175 std::vector<MapBlock*> m_keeplist;
176 std::map<v3s16, MapBlock*> m_drawlist_shadow;
179
185
188};
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:207
Definition clientmap.h:142
MapBlockComparer(const v3s16 &camera_block)
Definition clientmap.h:144
v3s16 m_camera_block
Definition clientmap.h:154
bool operator()(const v3s16 &left, const v3s16 &right) const
Definition clientmap.h:146
Definition clientmap.h:58
bool m_cache_anistropic_filter
Definition clientmap.h:182
std::map< v3s16, MapBlock *, MapBlockComparer > m_drawlist
Definition clientmap.h:172
void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length)
Definition clientmap.cpp:1548
bool m_enable_raytraced_culling
Definition clientmap.h:187
bool m_needs_update_transparent_meshes
Definition clientmap.h:170
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:1598
Client * m_client
Definition clientmap.h:157
f32 m_camera_fov
Definition clientmap.h:167
const MapDrawControl & getControl() const
Definition clientmap.h:123
virtual ~ClientMap()
Definition clientmap.cpp:206
virtual void OnRegisterSceneNode() override
Definition clientmap.cpp:265
f32 getWantedRange() const
Definition clientmap.h:124
bool m_cache_transparency_sorting_group_by_buffers
Definition clientmap.h:183
v3s16 m_camera_offset
Definition clientmap.h:168
bool m_loops_occlusion_culler
Definition clientmap.h:186
void updateDrawList()
Definition clientmap.cpp:378
int getBackgroundBrightness(float max_d, u32 daylight_factor, int oldvalue, bool *sunlight_seen_result)
Definition clientmap.cpp:1293
void invalidateMapBlockMesh(MapBlockMesh *mesh)
Definition clientmap.cpp:1177
void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SColor light_color)
Definition clientmap.cpp:220
void renderPostFx(CameraMode cam_mode)
Definition clientmap.cpp:1378
void touchMapBlocks()
Calculate statistics about the map and keep the blocks alive.
Definition clientmap.cpp:734
void onSettingChanged(std::string_view name, bool all)
Definition clientmap.cpp:187
std::map< v3s16, MapBlock * > m_drawlist_shadow
Definition clientmap.h:176
aabb3f m_box
Definition clientmap.h:160
bool maySaveBlocks() override
Definition clientmap.h:67
void renderMap(video::IVideoDriver *driver, s32 pass)
Definition clientmap.cpp:981
video::SColor m_camera_light_color
Definition clientmap.h:169
virtual const aabb3f & getBoundingBox() const override
Definition clientmap.h:87
bool m_needs_update_drawlist
Definition clientmap.h:177
virtual void render() override
Definition clientmap.cpp:278
f32 getCameraFov() const
Definition clientmap.h:125
MapSector * emergeSector(v2s16 p) override
Definition clientmap.cpp:251
std::vector< MapBlock * > m_keeplist
Definition clientmap.h:175
v3f m_camera_position
Definition clientmap.h:165
bool m_cache_trilinear_filter
Definition clientmap.h:180
RenderingEngine * m_rendering_engine
Definition clientmap.h:158
void renderMapShadows(video::IVideoDriver *driver, ModifyMaterialCallback cb, s32 pass, int frame, int total_frames)
Definition clientmap.cpp:1418
void PrintInfo(std::ostream &out) override
Definition clientmap.cpp:1413
CachedMeshBuffers m_dynamic_buffers
Definition clientmap.h:178
void clearDrawList()
clears m_drawlist and m_keeplist
Definition clientmap.cpp:363
MapDrawControl & m_control
Definition clientmap.h:163
u16 m_cache_transparency_sorting_distance
Definition clientmap.h:184
v3f m_camera_direction
Definition clientmap.h:166
bool needsUpdateDrawList()
Definition clientmap.h:106
void clearDrawListShadow()
Definition clientmap.cpp:1536
void updateTransparentMeshBuffers()
Definition clientmap.cpp:1603
bool m_cache_bilinear_filter
Definition clientmap.h:181
void getBlocksInViewRange(v3s16 cam_pos_nodes, v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f)
Definition clientmap.cpp:285
bool isMeshOccluded(MapBlock *mesh_block, u16 mesh_size, v3s16 cam_pos_nodes)
Definition clientmap.cpp:1664
Definition client.h:106
Definition mapblock_mesh.h:176
Definition mapblock.h:58
Definition mapsector.h:23
Definition map.h:100
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:127
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:64