@@ -58,7 +58,7 @@ ClientMap::ClientMap(
58
58
ClientMap::~ClientMap ()
59
59
{
60
60
/* JMutexAutoLock lock(mesh_mutex);
61
-
61
+
62
62
if(mesh != NULL)
63
63
{
64
64
mesh->drop();
@@ -76,15 +76,15 @@ MapSector * ClientMap::emergeSector(v2s16 p2d)
76
76
catch (InvalidPositionException &e)
77
77
{
78
78
}
79
-
79
+
80
80
// Create a sector
81
81
ClientMapSector *sector = new ClientMapSector (this , p2d, m_gamedef);
82
-
82
+
83
83
{
84
84
// JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
85
85
m_sectors[p2d] = sector;
86
86
}
87
-
87
+
88
88
return sector;
89
89
}
90
90
@@ -95,7 +95,7 @@ void ClientMap::deSerializeSector(v2s16 p2d, std::istream &is)
95
95
ClientMapSector *sector = NULL;
96
96
97
97
//JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
98
-
98
+
99
99
core::map<v2s16, MapSector*>::Node *n = m_sectors.find(p2d);
100
100
101
101
if(n != NULL)
@@ -198,7 +198,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
198
198
p_nodes_max.X / MAP_BLOCKSIZE + 1 ,
199
199
p_nodes_max.Y / MAP_BLOCKSIZE + 1 ,
200
200
p_nodes_max.Z / MAP_BLOCKSIZE + 1 );
201
-
201
+
202
202
// Number of blocks in rendering range
203
203
u32 blocks_in_range = 0 ;
204
204
// Number of blocks occlusion culled
@@ -223,7 +223,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
223
223
{
224
224
MapSector *sector = si->second ;
225
225
v2s16 sp = sector->getPos ();
226
-
226
+
227
227
if (m_control.range_all == false )
228
228
{
229
229
if (sp.X < p_blocks_min.X
@@ -235,13 +235,13 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
235
235
236
236
std::list< MapBlock * > sectorblocks;
237
237
sector->getBlocks (sectorblocks);
238
-
238
+
239
239
/*
240
240
Loop through blocks in sector
241
241
*/
242
242
243
243
u32 sector_blocks_drawn = 0 ;
244
-
244
+
245
245
std::list< MapBlock * >::iterator i;
246
246
for (i=sectorblocks.begin (); i!=sectorblocks.end (); i++)
247
247
{
@@ -251,10 +251,10 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
251
251
Compare block position to camera position, skip
252
252
if not seen on display
253
253
*/
254
-
254
+
255
255
if (block->mesh != NULL )
256
256
block->mesh ->updateCameraOffset (m_camera_offset);
257
-
257
+
258
258
float range = 100000 * BS;
259
259
if (m_control.range_all == false )
260
260
range = m_control.wanted_range * BS;
@@ -273,7 +273,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
273
273
continue;*/
274
274
275
275
blocks_in_range++;
276
-
276
+
277
277
/*
278
278
Ignore if mesh doesn't exist
279
279
*/
@@ -334,7 +334,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
334
334
blocks_occlusion_culled++;
335
335
continue ;
336
336
}
337
-
337
+
338
338
// This block is in range. Reset usage timer.
339
339
block->resetUsageTimer ();
340
340
@@ -383,18 +383,25 @@ struct MeshBufList
383
383
struct MeshBufListList
384
384
{
385
385
std::list<MeshBufList> lists;
386
-
386
+
387
387
void clear ()
388
388
{
389
389
lists.clear ();
390
390
}
391
-
391
+
392
392
void add (scene::IMeshBuffer *buf)
393
393
{
394
394
for (std::list<MeshBufList>::iterator i = lists.begin ();
395
395
i != lists.end (); ++i){
396
396
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) {
398
405
l.bufs .push_back (buf);
399
406
return ;
400
407
}
@@ -411,7 +418,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
411
418
DSTACK (__FUNCTION_NAME);
412
419
413
420
bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT;
414
-
421
+
415
422
std::string prefix;
416
423
if (pass == scene::ESNRP_SOLID)
417
424
prefix = " CM: solid: " ;
@@ -432,7 +439,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
432
439
433
440
/*
434
441
Get time for measuring timeout.
435
-
442
+
436
443
Measuring time is very useful for long delays when the
437
444
machine is swapping a lot.
438
445
*/
@@ -456,7 +463,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
456
463
*/
457
464
458
465
v3s16 cam_pos_nodes = floatToInt (camera_position, BS);
459
-
466
+
460
467
v3s16 box_nodes_d = m_control.wanted_range * v3s16 (1 ,1 ,1 );
461
468
462
469
v3s16 p_nodes_min = cam_pos_nodes - box_nodes_d;
@@ -472,14 +479,14 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
472
479
p_nodes_max.X / MAP_BLOCKSIZE + 1 ,
473
480
p_nodes_max.Y / MAP_BLOCKSIZE + 1 ,
474
481
p_nodes_max.Z / MAP_BLOCKSIZE + 1 );
475
-
482
+
476
483
u32 vertex_count = 0 ;
477
484
u32 meshbuffer_count = 0 ;
478
-
485
+
479
486
// For limiting number of mesh animations per frame
480
487
u32 mesh_animate_count = 0 ;
481
488
u32 mesh_animate_count_far = 0 ;
482
-
489
+
483
490
// Blocks that were drawn and had a mesh
484
491
u32 blocks_drawn = 0 ;
485
492
// Blocks which had a corresponding meshbuffer for this pass
@@ -505,7 +512,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
505
512
// If the mesh of the block happened to get deleted, ignore it
506
513
if (block->mesh == NULL )
507
514
continue ;
508
-
515
+
509
516
float d = 0.0 ;
510
517
if (isBlockInSight (block->getPos (), camera_position,
511
518
camera_direction, camera_fov,
@@ -577,9 +584,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
577
584
}
578
585
}
579
586
}
580
-
587
+
581
588
std::list<MeshBufList> &lists = drawbufs.lists ;
582
-
589
+
583
590
int timecheck_counter = 0 ;
584
591
for (std::list<MeshBufList>::iterator i = lists.begin ();
585
592
i != lists.end (); ++i)
@@ -601,9 +608,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
601
608
}
602
609
603
610
MeshBufList &list = *i;
604
-
611
+
605
612
driver->setMaterial (list.m );
606
-
613
+
607
614
for (std::list<scene::IMeshBuffer*>::iterator j = list.bufs .begin ();
608
615
j != list.bufs .end (); ++j)
609
616
{
@@ -660,13 +667,13 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
660
667
#endif
661
668
}
662
669
} // ScopeProfiler
663
-
670
+
664
671
// Log only on solid pass because values are the same
665
672
if (pass == scene::ESNRP_SOLID){
666
673
g_profiler->avg (" CM: animated meshes" , mesh_animate_count);
667
674
g_profiler->avg (" CM: animated meshes (far)" , mesh_animate_count_far);
668
675
}
669
-
676
+
670
677
g_profiler->avg (prefix+" vertices drawn" , vertex_count);
671
678
if (blocks_had_pass_meshbuf != 0 )
672
679
g_profiler->avg (prefix+" meshbuffers per block" ,
@@ -717,7 +724,7 @@ static bool getVisibleBrightness(Map *map, v3f p0, v3f dir, float step,
717
724
pf += dir * step;
718
725
distance += step;
719
726
step *= step_multiplier;
720
-
727
+
721
728
v3s16 p = floatToInt (pf, BS);
722
729
MapNode n = map->getNodeNoEx (p);
723
730
if (allow_allowing_non_sunlight_propagates && i == 0 &&
0 commit comments