Luanti 5.11.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 // Orders blocks by distance to the camera
120 {
121 public:
122 MapBlockComparer(const v3s16 &camera_block) : m_camera_block(camera_block) {}
123
124 bool operator() (const v3s16 &left, const v3s16 &right) const
125 {
126 auto distance_left = left.getDistanceFromSQ(m_camera_block);
127 auto distance_right = right.getDistanceFromSQ(m_camera_block);
128 return distance_left > distance_right || (distance_left == distance_right && left > right);
129 }
130
131 private:
133 };
134
137
138 aabb3f m_box = aabb3f(-BS * 1000000, -BS * 1000000, -BS * 1000000,
139 BS * 1000000, BS * 1000000, BS * 1000000);
140
142
145 f32 m_camera_fov = M_PI;
147 video::SColor m_camera_light_color = video::SColor(0xFFFFFFFF);
149
150 std::map<v3s16, MapBlock*, MapBlockComparer> m_drawlist;
151 std::vector<MapBlock*> m_keeplist;
152 std::map<v3s16, MapBlock*> m_drawlist_shadow;
154
160
163};
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:191
CameraMode
Definition camera.h:60
Definition clientmap.h:120
MapBlockComparer(const v3s16 &camera_block)
Definition clientmap.h:122
v3s16 m_camera_block
Definition clientmap.h:132
bool operator()(const v3s16 &left, const v3s16 &right) const
Definition clientmap.h:124
Definition clientmap.h:46
bool m_cache_anistropic_filter
Definition clientmap.h:157
std::map< v3s16, MapBlock *, MapBlockComparer > m_drawlist
Definition clientmap.h:150
void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length)
Definition clientmap.cpp:1384
bool m_enable_raytraced_culling
Definition clientmap.h:162
bool m_needs_update_transparent_meshes
Definition clientmap.h:148
ClientMap(Client *client, RenderingEngine *rendering_engine, MapDrawControl &control, s32 id)
Definition clientmap.cpp:144
void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override
Definition clientmap.cpp:1438
Client * m_client
Definition clientmap.h:135
f32 m_camera_fov
Definition clientmap.h:145
const MapDrawControl & getControl() const
Definition clientmap.h:101
virtual ~ClientMap()
Definition clientmap.cpp:191
virtual void OnRegisterSceneNode() override
Definition clientmap.cpp:233
f32 getWantedRange() const
Definition clientmap.h:102
bool m_cache_transparency_sorting_group_by_buffers
Definition clientmap.h:158
v3s16 m_camera_offset
Definition clientmap.h:146
bool m_loops_occlusion_culler
Definition clientmap.h:161
void updateDrawList()
Definition clientmap.cpp:331
int getBackgroundBrightness(float max_d, u32 daylight_factor, int oldvalue, bool *sunlight_seen_result)
Definition clientmap.cpp:1124
void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SColor light_color)
Definition clientmap.cpp:196
void renderPostFx(CameraMode cam_mode)
Definition clientmap.cpp:1209
void touchMapBlocks()
Definition clientmap.cpp:696
void onSettingChanged(std::string_view name, bool all)
Definition clientmap.cpp:172
std::map< v3s16, MapBlock * > m_drawlist_shadow
Definition clientmap.h:152
aabb3f m_box
Definition clientmap.h:138
bool maySaveBlocks() override
Definition clientmap.h:55
void renderMap(video::IVideoDriver *driver, s32 pass)
Definition clientmap.cpp:880
video::SColor m_camera_light_color
Definition clientmap.h:147
virtual const aabb3f & getBoundingBox() const override
Definition clientmap.h:75
bool m_needs_update_drawlist
Definition clientmap.h:153
virtual void render() override
Definition clientmap.cpp:246
f32 getCameraFov() const
Definition clientmap.h:103
MapSector * emergeSector(v2s16 p) override
Definition clientmap.cpp:219
std::vector< MapBlock * > m_keeplist
Definition clientmap.h:151
v3f m_camera_position
Definition clientmap.h:143
bool m_cache_trilinear_filter
Definition clientmap.h:155
RenderingEngine * m_rendering_engine
Definition clientmap.h:136
void PrintInfo(std::ostream &out) override
Definition clientmap.cpp:1244
MapDrawControl & m_control
Definition clientmap.h:141
u16 m_cache_transparency_sorting_distance
Definition clientmap.h:159
void renderMapShadows(video::IVideoDriver *driver, const video::SMaterial &material, s32 pass, int frame, int total_frames)
Definition clientmap.cpp:1249
v3f m_camera_direction
Definition clientmap.h:144
bool needsUpdateDrawList()
Definition clientmap.h:87
void updateTransparentMeshBuffers()
Definition clientmap.cpp:1443
bool m_cache_bilinear_filter
Definition clientmap.h:156
void getBlocksInViewRange(v3s16 cam_pos_nodes, v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f)
Definition clientmap.cpp:253
bool isMeshOccluded(MapBlock *mesh_block, u16 mesh_size, v3s16 cam_pos_nodes)
Definition clientmap.cpp:1504
Definition client.h:104
Definition texturesource.h:36
Definition mapblock.h:58
Definition mapsector.h:25
Definition map.h:101
Definition mapblock_mesh.h:134
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: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:55