Skip to content

Commit 334ec4b

Browse files
sapiersapier
sapier
authored and
sapier
committed
Avoid doing a full material compare if not even first texture does match
1 parent 35ec385 commit 334ec4b

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

src/clientmap.cpp

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ClientMap::ClientMap(
5858
ClientMap::~ClientMap()
5959
{
6060
/*JMutexAutoLock lock(mesh_mutex);
61-
61+
6262
if(mesh != NULL)
6363
{
6464
mesh->drop();
@@ -76,15 +76,15 @@ MapSector * ClientMap::emergeSector(v2s16 p2d)
7676
catch(InvalidPositionException &e)
7777
{
7878
}
79-
79+
8080
// Create a sector
8181
ClientMapSector *sector = new ClientMapSector(this, p2d, m_gamedef);
82-
82+
8383
{
8484
//JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
8585
m_sectors[p2d] = sector;
8686
}
87-
87+
8888
return sector;
8989
}
9090

@@ -95,7 +95,7 @@ void ClientMap::deSerializeSector(v2s16 p2d, std::istream &is)
9595
ClientMapSector *sector = NULL;
9696

9797
//JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
98-
98+
9999
core::map<v2s16, MapSector*>::Node *n = m_sectors.find(p2d);
100100

101101
if(n != NULL)
@@ -198,7 +198,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
198198
p_nodes_max.X / MAP_BLOCKSIZE + 1,
199199
p_nodes_max.Y / MAP_BLOCKSIZE + 1,
200200
p_nodes_max.Z / MAP_BLOCKSIZE + 1);
201-
201+
202202
// Number of blocks in rendering range
203203
u32 blocks_in_range = 0;
204204
// Number of blocks occlusion culled
@@ -223,7 +223,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
223223
{
224224
MapSector *sector = si->second;
225225
v2s16 sp = sector->getPos();
226-
226+
227227
if(m_control.range_all == false)
228228
{
229229
if(sp.X < p_blocks_min.X
@@ -235,13 +235,13 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
235235

236236
std::list< MapBlock * > sectorblocks;
237237
sector->getBlocks(sectorblocks);
238-
238+
239239
/*
240240
Loop through blocks in sector
241241
*/
242242

243243
u32 sector_blocks_drawn = 0;
244-
244+
245245
std::list< MapBlock * >::iterator i;
246246
for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
247247
{
@@ -251,10 +251,10 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
251251
Compare block position to camera position, skip
252252
if not seen on display
253253
*/
254-
254+
255255
if (block->mesh != NULL)
256256
block->mesh->updateCameraOffset(m_camera_offset);
257-
257+
258258
float range = 100000 * BS;
259259
if(m_control.range_all == false)
260260
range = m_control.wanted_range * BS;
@@ -273,7 +273,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
273273
continue;*/
274274

275275
blocks_in_range++;
276-
276+
277277
/*
278278
Ignore if mesh doesn't exist
279279
*/
@@ -334,7 +334,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
334334
blocks_occlusion_culled++;
335335
continue;
336336
}
337-
337+
338338
// This block is in range. Reset usage timer.
339339
block->resetUsageTimer();
340340

@@ -383,18 +383,25 @@ struct MeshBufList
383383
struct MeshBufListList
384384
{
385385
std::list<MeshBufList> lists;
386-
386+
387387
void clear()
388388
{
389389
lists.clear();
390390
}
391-
391+
392392
void add(scene::IMeshBuffer *buf)
393393
{
394394
for(std::list<MeshBufList>::iterator i = lists.begin();
395395
i != lists.end(); ++i){
396396
MeshBufList &l = *i;
397-
if(l.m == buf->getMaterial()){
397+
video::SMaterial &m = buf->getMaterial();
398+
399+
// comparing a full material is quite expensive so we don't do it if
400+
// not even first texture is equal
401+
if (l.m.TextureLayer[0].Texture != m.TextureLayer[0].Texture)
402+
continue;
403+
404+
if (l.m == m) {
398405
l.bufs.push_back(buf);
399406
return;
400407
}
@@ -411,7 +418,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
411418
DSTACK(__FUNCTION_NAME);
412419

413420
bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT;
414-
421+
415422
std::string prefix;
416423
if(pass == scene::ESNRP_SOLID)
417424
prefix = "CM: solid: ";
@@ -432,7 +439,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
432439

433440
/*
434441
Get time for measuring timeout.
435-
442+
436443
Measuring time is very useful for long delays when the
437444
machine is swapping a lot.
438445
*/
@@ -456,7 +463,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
456463
*/
457464

458465
v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
459-
466+
460467
v3s16 box_nodes_d = m_control.wanted_range * v3s16(1,1,1);
461468

462469
v3s16 p_nodes_min = cam_pos_nodes - box_nodes_d;
@@ -472,14 +479,14 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
472479
p_nodes_max.X / MAP_BLOCKSIZE + 1,
473480
p_nodes_max.Y / MAP_BLOCKSIZE + 1,
474481
p_nodes_max.Z / MAP_BLOCKSIZE + 1);
475-
482+
476483
u32 vertex_count = 0;
477484
u32 meshbuffer_count = 0;
478-
485+
479486
// For limiting number of mesh animations per frame
480487
u32 mesh_animate_count = 0;
481488
u32 mesh_animate_count_far = 0;
482-
489+
483490
// Blocks that were drawn and had a mesh
484491
u32 blocks_drawn = 0;
485492
// Blocks which had a corresponding meshbuffer for this pass
@@ -505,7 +512,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
505512
// If the mesh of the block happened to get deleted, ignore it
506513
if(block->mesh == NULL)
507514
continue;
508-
515+
509516
float d = 0.0;
510517
if(isBlockInSight(block->getPos(), camera_position,
511518
camera_direction, camera_fov,
@@ -577,9 +584,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
577584
}
578585
}
579586
}
580-
587+
581588
std::list<MeshBufList> &lists = drawbufs.lists;
582-
589+
583590
int timecheck_counter = 0;
584591
for(std::list<MeshBufList>::iterator i = lists.begin();
585592
i != lists.end(); ++i)
@@ -601,9 +608,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
601608
}
602609

603610
MeshBufList &list = *i;
604-
611+
605612
driver->setMaterial(list.m);
606-
613+
607614
for(std::list<scene::IMeshBuffer*>::iterator j = list.bufs.begin();
608615
j != list.bufs.end(); ++j)
609616
{
@@ -660,13 +667,13 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
660667
#endif
661668
}
662669
} // ScopeProfiler
663-
670+
664671
// Log only on solid pass because values are the same
665672
if(pass == scene::ESNRP_SOLID){
666673
g_profiler->avg("CM: animated meshes", mesh_animate_count);
667674
g_profiler->avg("CM: animated meshes (far)", mesh_animate_count_far);
668675
}
669-
676+
670677
g_profiler->avg(prefix+"vertices drawn", vertex_count);
671678
if(blocks_had_pass_meshbuf != 0)
672679
g_profiler->avg(prefix+"meshbuffers per block",
@@ -717,7 +724,7 @@ static bool getVisibleBrightness(Map *map, v3f p0, v3f dir, float step,
717724
pf += dir * step;
718725
distance += step;
719726
step *= step_multiplier;
720-
727+
721728
v3s16 p = floatToInt(pf, BS);
722729
MapNode n = map->getNodeNoEx(p);
723730
if(allow_allowing_non_sunlight_propagates && i == 0 &&

0 commit comments

Comments
 (0)