Luanti 5.19.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
103 void getBlocksWithMeshes(std::vector<v3s16> &out);
104
105 void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length);
106 void clearDrawListShadow();
107
108 // Returns true if draw list needs updating before drawing the next frame.
110
111 void renderMap(video::IVideoDriver* driver, s32 pass);
112
113 void renderMapShadows(video::IVideoDriver *driver,
114 ModifyMaterialCallback cb, s32 pass, int frame, int total_frames);
115
116 int getBackgroundBrightness(float max_d, u32 daylight_factor,
117 int oldvalue, bool *sunlight_seen_result);
118
119 void renderPostFx(CameraMode cam_mode);
120
122
123 // For debug printing
124 void PrintInfo(std::ostream &out) override;
125
126 const MapDrawControl & getControl() const { return m_control; }
127 f32 getWantedRange() const { return m_control.wanted_range; }
128 f32 getCameraFov() const { return m_camera_fov; }
129
130 void onSettingChanged(std::string_view name, bool all);
131
132protected:
133 // use drop() instead
134 virtual ~ClientMap();
135
136 void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override;
137private:
138 bool isMeshOccluded(MapBlock *mesh_block, u16 mesh_size, v3s16 cam_pos_nodes);
139
140 bool useLoopsCuller() const;
141
142 // update the vertex order in transparent mesh buffers
144
145 // Orders blocks by distance to the camera
147 {
148 public:
149 MapBlockComparer(const v3s16 &camera_block) : m_camera_block(camera_block) {}
150
151 bool operator() (const v3s16 &left, const v3s16 &right) const
152 {
153 auto distance_left = left.getDistanceFromSQ(m_camera_block);
154 auto distance_right = right.getDistanceFromSQ(m_camera_block);
155 return distance_left > distance_right || (distance_left == distance_right && left > right);
156 }
157
158 private:
160 };
161
164
165 aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
166 BS * 1000000, BS * 1000000, BS * 1000000);
167
169
172 f32 m_camera_fov = M_PI;
174 video::SColor m_camera_light_color = video::SColor(0xFFFFFFFF);
176
177 std::map<v3s16, MapBlock*, MapBlockComparer> m_drawlist;
178 // List of additional blocks to keep (relevant with mesh_chunk > 1, since
179 // not all blocks contain a mesh)
180 std::vector<MapBlock*> m_keeplist;
181 std::map<v3s16, MapBlock*> m_drawlist_shadow;
184
190
193};
MapBlockComparer(const v3s16 &camera_block)
Definition clientmap.h:149
v3s16 m_camera_block
Definition clientmap.h:159
bool operator()(const v3s16 &left, const v3s16 &right) const
Definition clientmap.h:151
Definition clientmap.h:58
bool m_cache_anistropic_filter
Definition clientmap.h:187
bool useLoopsCuller() const
Definition clientmap.cpp:220
std::map< v3s16, MapBlock *, MapBlockComparer > m_drawlist
Definition clientmap.h:177
void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length)
Definition clientmap.cpp:1592
bool m_enable_raytraced_culling
Definition clientmap.h:192
bool m_needs_update_transparent_meshes
Definition clientmap.h:175
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:1642
Client * m_client
Definition clientmap.h:162
f32 m_camera_fov
Definition clientmap.h:172
const MapDrawControl & getControl() const
Definition clientmap.h:126
virtual void OnRegisterSceneNode() override
Definition clientmap.cpp:286
f32 getWantedRange() const
Definition clientmap.h:127
bool m_cache_transparency_sorting_group_by_buffers
Definition clientmap.h:188
v3s16 m_camera_offset
Definition clientmap.h:173
bool m_loops_occlusion_culler
Definition clientmap.h:191
void updateDrawList()
Definition clientmap.cpp:399
int getBackgroundBrightness(float max_d, u32 daylight_factor, int oldvalue, bool *sunlight_seen_result)
Definition clientmap.cpp:1337
void invalidateMapBlockMesh(MapBlockMesh *mesh)
Definition clientmap.cpp:1221
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:1422
void touchMapBlocks()
Calculate statistics about the map and keep the blocks alive.
Definition clientmap.cpp:750
void onSettingChanged(std::string_view name, bool all)
Definition clientmap.cpp:187
std::map< v3s16, MapBlock * > m_drawlist_shadow
Definition clientmap.h:181
aabb3f m_box
Definition clientmap.h:165
bool maySaveBlocks() override
Definition clientmap.h:67
void renderMap(video::IVideoDriver *driver, s32 pass)
Definition clientmap.cpp:1025
void getBlocksWithMeshes(std::vector< v3s16 > &out)
returns a distance-sorted list of all block mesh positions
Definition clientmap.cpp:821
video::SColor m_camera_light_color
Definition clientmap.h:174
virtual const aabb3f & getBoundingBox() const override
Definition clientmap.h:87
bool m_needs_update_drawlist
Definition clientmap.h:182
virtual void render() override
Definition clientmap.cpp:299
f32 getCameraFov() const
Definition clientmap.h:128
MapSector * emergeSector(v2s16 p) override
Definition clientmap.cpp:272
std::vector< MapBlock * > m_keeplist
Definition clientmap.h:180
v3f m_camera_position
Definition clientmap.h:170
bool m_cache_trilinear_filter
Definition clientmap.h:185
RenderingEngine * m_rendering_engine
Definition clientmap.h:163
void renderMapShadows(video::IVideoDriver *driver, ModifyMaterialCallback cb, s32 pass, int frame, int total_frames)
Definition clientmap.cpp:1462
void PrintInfo(std::ostream &out) override
Definition clientmap.cpp:1457
CachedMeshBuffers m_dynamic_buffers
Definition clientmap.h:183
void clearDrawList()
clears m_drawlist and m_keeplist
Definition clientmap.cpp:384
MapDrawControl & m_control
Definition clientmap.h:168
u16 m_cache_transparency_sorting_distance
Definition clientmap.h:189
v3f m_camera_direction
Definition clientmap.h:171
bool needsUpdateDrawList()
Definition clientmap.h:109
void clearDrawListShadow()
Definition clientmap.cpp:1580
void updateTransparentMeshBuffers()
Definition clientmap.cpp:1647
bool m_cache_bilinear_filter
Definition clientmap.h:186
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:1708
Definition client.h:108
Definition mapblock_mesh.h:179
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