Skip to content

Commit b826e39

Browse files
committedOct 19, 2020
Minor clientmap improvements.
- Avoid calculating isBlockInSight for blocks without meshes. - Add metric for how many blocks the client has currently loaded. - Make some variables constant.
1 parent db9eee2 commit b826e39

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed
 

‎src/client/clientmap.cpp

+19-17
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,17 @@ void ClientMap::updateDrawList()
122122
}
123123
m_drawlist.clear();
124124

125-
v3f camera_position = m_camera_position;
126-
v3f camera_direction = m_camera_direction;
125+
const v3f camera_position = m_camera_position;
126+
const v3f camera_direction = m_camera_direction;
127+
const f32 camera_fov = m_camera_fov;
127128

128129
v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
129130
v3s16 p_blocks_min;
130131
v3s16 p_blocks_max;
131132
getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max);
132133

134+
// Number of blocks currently loaded by the client
135+
u32 blocks_loaded = 0;
133136
// Number of blocks with mesh in rendering range
134137
u32 blocks_in_range_with_mesh = 0;
135138
// Number of blocks occlusion culled
@@ -154,6 +157,7 @@ void ClientMap::updateDrawList()
154157
MapSector *sector = sector_it.second;
155158
v2s16 sp = sector->getPos();
156159

160+
blocks_loaded += sector->size();
157161
if (!m_control.range_all) {
158162
if (sp.X < p_blocks_min.X || sp.X > p_blocks_max.X ||
159163
sp.Y < p_blocks_min.Z || sp.Y > p_blocks_max.Z)
@@ -175,23 +179,20 @@ void ClientMap::updateDrawList()
175179
if not seen on display
176180
*/
177181

178-
if (block->mesh)
182+
if (block->mesh) {
179183
block->mesh->updateCameraOffset(m_camera_offset);
184+
} else {
185+
// Ignore if mesh doesn't exist
186+
continue;
187+
}
180188

181189
float range = 100000 * BS;
182190
if (!m_control.range_all)
183191
range = m_control.wanted_range * BS;
184192

185193
float d = 0.0;
186194
if (!isBlockInSight(block->getPos(), camera_position,
187-
camera_direction, m_camera_fov, range, &d))
188-
continue;
189-
190-
191-
/*
192-
Ignore if mesh doesn't exist
193-
*/
194-
if (!block->mesh)
195+
camera_direction, camera_fov, range, &d))
195196
continue;
196197

197198
blocks_in_range_with_mesh++;
@@ -222,6 +223,7 @@ void ClientMap::updateDrawList()
222223
g_profiler->avg("MapBlock meshes in range [#]", blocks_in_range_with_mesh);
223224
g_profiler->avg("MapBlocks occlusion culled [#]", blocks_occlusion_culled);
224225
g_profiler->avg("MapBlocks drawn [#]", m_drawlist.size());
226+
g_profiler->avg("MapBlocks loaded [#]", blocks_loaded);
225227
}
226228

227229
struct MeshBufList
@@ -287,13 +289,13 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
287289
/*
288290
Get animation parameters
289291
*/
290-
float animation_time = m_client->getAnimationTime();
291-
int crack = m_client->getCrackLevel();
292-
u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
292+
const float animation_time = m_client->getAnimationTime();
293+
const int crack = m_client->getCrackLevel();
294+
const u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
293295

294-
v3f camera_position = m_camera_position;
295-
v3f camera_direction = m_camera_direction;
296-
f32 camera_fov = m_camera_fov;
296+
const v3f camera_position = m_camera_position;
297+
const v3f camera_direction = m_camera_direction;
298+
const f32 camera_fov = m_camera_fov;
297299

298300
/*
299301
Get all blocks and draw all visible ones

‎src/mapsector.h

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class MapSector
6262

6363
bool empty() const { return m_blocks.empty(); }
6464

65+
int size() const { return m_blocks.size(); }
6566
protected:
6667

6768
// The pile of MapBlocks

0 commit comments

Comments
 (0)
Please sign in to comment.