@@ -22,9 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
22
22
#include " mapblock_mesh.h"
23
23
#include < IMaterialRenderer.h>
24
24
#include < matrix4.h>
25
- #include " log.h"
26
25
#include " mapsector.h"
27
- #include " nodedef.h"
28
26
#include " mapblock.h"
29
27
#include " profiler.h"
30
28
#include " settings.h"
@@ -42,10 +40,7 @@ ClientMap::ClientMap(
42
40
scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
43
41
RenderingEngine::get_scene_manager(), id),
44
42
m_client(client),
45
- m_control(control),
46
- m_camera_position(0 ,0 ,0 ),
47
- m_camera_direction(0 ,0 ,1 ),
48
- m_camera_fov(M_PI)
43
+ m_control(control)
49
44
{
50
45
m_box = aabb3f (-BS*1000000 ,-BS*1000000 ,-BS*1000000 ,
51
46
BS*1000000 ,BS*1000000 ,BS*1000000 );
@@ -65,10 +60,6 @@ ClientMap::ClientMap(
65
60
66
61
}
67
62
68
- ClientMap::~ClientMap ()
69
- {
70
- }
71
-
72
63
MapSector * ClientMap::emergeSector (v2s16 p2d)
73
64
{
74
65
DSTACK (FUNCTION_NAME);
@@ -129,14 +120,13 @@ void ClientMap::getBlocksInViewRange(v3s16 cam_pos_nodes,
129
120
p_nodes_max.Z / MAP_BLOCKSIZE + 1 );
130
121
}
131
122
132
- void ClientMap::updateDrawList (video::IVideoDriver* driver )
123
+ void ClientMap::updateDrawList ()
133
124
{
134
125
ScopeProfiler sp (g_profiler, " CM::updateDrawList()" , SPT_AVG);
135
126
g_profiler->add (" CM::updateDrawList() count" , 1 );
136
127
137
- for (std::map<v3s16, MapBlock*>::iterator i = m_drawlist.begin ();
138
- i != m_drawlist.end (); ++i) {
139
- MapBlock *block = i->second ;
128
+ for (auto &i : m_drawlist) {
129
+ MapBlock *block = i.second ;
140
130
block->refDrop ();
141
131
}
142
132
m_drawlist.clear ();
@@ -183,12 +173,11 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
183
173
occlusion_culling_enabled = false ;
184
174
}
185
175
186
- for (std::map<v2s16, MapSector*>::iterator si = m_sectors.begin ();
187
- si != m_sectors.end (); ++si) {
188
- MapSector *sector = si->second ;
176
+ for (const auto §or_it : m_sectors) {
177
+ MapSector *sector = sector_it.second ;
189
178
v2s16 sp = sector->getPos ();
190
179
191
- if (m_control.range_all == false ) {
180
+ if (! m_control.range_all ) {
192
181
if (sp.X < p_blocks_min.X || sp.X > p_blocks_max.X ||
193
182
sp.Y < p_blocks_min.Z || sp.Y > p_blocks_max.Z )
194
183
continue ;
@@ -203,14 +192,11 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
203
192
204
193
u32 sector_blocks_drawn = 0 ;
205
194
206
- for (MapBlockVect::iterator i = sectorblocks.begin ();
207
- i != sectorblocks.end (); ++i) {
208
- MapBlock *block = *i;
209
-
195
+ for (auto block : sectorblocks) {
210
196
/*
211
- Compare block position to camera position, skip
212
- if not seen on display
213
- */
197
+ Compare block position to camera position, skip
198
+ if not seen on display
199
+ */
214
200
215
201
if (block->mesh )
216
202
block->mesh ->updateCameraOffset (m_camera_offset);
@@ -267,10 +253,6 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
267
253
m_last_drawn_sectors.insert (sp);
268
254
}
269
255
270
- m_control.blocks_would_have_drawn = blocks_would_have_drawn;
271
- m_control.blocks_drawn = blocks_drawn;
272
- m_control.farthest_drawn = farthest_drawn;
273
-
274
256
g_profiler->avg (" CM: blocks in range" , blocks_in_range);
275
257
g_profiler->avg (" CM: blocks occlusion culled" , blocks_occlusion_culled);
276
258
if (blocks_in_range != 0 )
@@ -389,9 +371,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
389
371
390
372
MeshBufListList drawbufs;
391
373
392
- for (std::map<v3s16, MapBlock*>::iterator i = m_drawlist.begin ();
393
- i != m_drawlist.end (); ++i) {
394
- MapBlock *block = i->second ;
374
+ for (auto &i : m_drawlist) {
375
+ MapBlock *block = i.second ;
395
376
396
377
// If the mesh of the block happened to get deleted, ignore it
397
378
if (!block->mesh )
@@ -507,12 +488,9 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
507
488
if (blocks_drawn != 0 )
508
489
g_profiler->avg (prefix + " empty blocks (frac)" ,
509
490
(float )blocks_without_stuff / blocks_drawn);
510
-
511
- /* infostream<<"renderMap(): is_transparent_pass="<<is_transparent_pass
512
- <<", rendered "<<vertex_count<<" vertices."<<std::endl;*/
513
491
}
514
492
515
- static bool getVisibleBrightness (Map *map, v3f p0, v3f dir, float step,
493
+ static bool getVisibleBrightness (Map *map, const v3f & p0, v3f dir, float step,
516
494
float step_multiplier, float start_distance, float end_distance,
517
495
INodeDefManager *ndef, u32 daylight_factor, float sunlight_min_d,
518
496
int *result, bool *sunlight_seen)
@@ -546,19 +524,20 @@ static bool getVisibleBrightness(Map *map, v3f p0, v3f dir, float step,
546
524
sunlight_min_d = 0 ;
547
525
}
548
526
}
549
- for (int i=0 ; distance < end_distance; i++){
527
+ for (int i=0 ; distance < end_distance; i++) {
550
528
pf += dir * step;
551
529
distance += step;
552
530
step *= step_multiplier;
553
531
554
532
v3s16 p = floatToInt (pf, BS);
555
533
MapNode n = map->getNodeNoEx (p);
556
- if (allow_allowing_non_sunlight_propagates && i == 0 &&
534
+ if (allow_allowing_non_sunlight_propagates && i == 0 &&
557
535
ndef->get (n).param_type == CPT_LIGHT &&
558
- !ndef->get (n).sunlight_propagates ){
536
+ !ndef->get (n).sunlight_propagates ) {
559
537
allow_non_sunlight_propagates = true ;
560
538
}
561
- if (ndef->get (n).param_type != CPT_LIGHT ||
539
+
540
+ if (ndef->get (n).param_type != CPT_LIGHT ||
562
541
(!ndef->get (n).sunlight_propagates &&
563
542
!allow_non_sunlight_propagates)){
564
543
nonlight_seen = true ;
@@ -567,9 +546,9 @@ static bool getVisibleBrightness(Map *map, v3f p0, v3f dir, float step,
567
546
break ;
568
547
continue ;
569
548
}
570
- if (distance >= sunlight_min_d && *sunlight_seen == false
571
- && nonlight_seen == false )
572
- if (n.getLight (LIGHTBANK_DAY, ndef) == LIGHT_SUN)
549
+
550
+ if (distance >= sunlight_min_d && !*sunlight_seen && !nonlight_seen )
551
+ if (n.getLight (LIGHTBANK_DAY, ndef) == LIGHT_SUN)
573
552
*sunlight_seen = true ;
574
553
noncount = 0 ;
575
554
brightness_sum += decode_light (n.getLightBlend (daylight_factor, ndef));
@@ -587,13 +566,13 @@ static bool getVisibleBrightness(Map *map, v3f p0, v3f dir, float step,
587
566
int ClientMap::getBackgroundBrightness (float max_d, u32 daylight_factor,
588
567
int oldvalue, bool *sunlight_seen_result)
589
568
{
590
- const bool debugprint = false ;
591
569
static v3f z_directions[50 ] = {
592
570
v3f (-100 , 0 , 0 )
593
571
};
594
572
static f32 z_offsets[sizeof (z_directions)/sizeof (*z_directions)] = {
595
573
-1000 ,
596
574
};
575
+
597
576
if (z_directions[0 ].X < -99 ){
598
577
for (u32 i=0 ; i<sizeof (z_directions)/sizeof (*z_directions); i++){
599
578
// Assumes FOV of 72 and 16/9 aspect ratio
@@ -605,8 +584,7 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
605
584
z_offsets[i] = 0.01 * myrand_range (0 ,100 );
606
585
}
607
586
}
608
- if (debugprint)
609
- std::cerr<<" In goes " <<PP (m_camera_direction)<<" , out comes " ;
587
+
610
588
int sunlight_seen_count = 0 ;
611
589
float sunlight_min_d = max_d*0.8 ;
612
590
if (sunlight_min_d > 35 *BS)
@@ -646,22 +624,12 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
646
624
else if (num_values_to_use >= 7 )
647
625
num_values_to_use -= num_values_to_use/3 ;
648
626
u32 first_value_i = (values.size () - num_values_to_use) / 2 ;
649
- if (debugprint){
650
- for (u32 i=0 ; i < first_value_i; i++)
651
- std::cerr<<values[i]<<" " ;
652
- std::cerr<<" [" ;
653
- }
654
- for (u32 i=first_value_i; i < first_value_i+num_values_to_use; i++){
655
- if (debugprint)
656
- std::cerr<<values[i]<<" " ;
627
+
628
+ for (u32 i=first_value_i; i < first_value_i + num_values_to_use; i++) {
657
629
brightness_sum += values[i];
658
630
brightness_count++;
659
631
}
660
- if (debugprint){
661
- std::cerr<<" ]" ;
662
- for (u32 i=first_value_i+num_values_to_use; i < values.size (); i++)
663
- std::cerr<<values[i]<<" " ;
664
- }
632
+
665
633
int ret = 0 ;
666
634
if (brightness_count == 0 ){
667
635
MapNode n = getNodeNoEx (floatToInt (m_camera_position, BS));
@@ -671,18 +639,9 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
671
639
ret = oldvalue;
672
640
}
673
641
} else {
674
- /* float pre = (float)brightness_sum / (float)brightness_count;
675
- float tmp = pre;
676
- const float d = 0.2;
677
- pre *= 1.0 + d*2;
678
- pre -= tmp * d;
679
- int preint = pre;
680
- ret = MYMAX(0, MYMIN(255, preint));*/
681
642
ret = brightness_sum / brightness_count;
682
643
}
683
- if (debugprint)
684
- std::cerr<<" Result: " <<ret<<" sunlight_seen_count="
685
- <<sunlight_seen_count<<std::endl;
644
+
686
645
*sunlight_seen_result = (sunlight_seen_count > 0 );
687
646
return ret;
688
647
}
0 commit comments