@@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
39
39
#include " serialization.h"
40
40
#include " util/serialize.h"
41
41
#include " util/numeric.h"
42
+ #include " util/directiontables.h"
42
43
#include " filesys.h"
43
44
#include " log.h"
44
45
#include " mapgen_carpathian.h"
@@ -435,7 +436,8 @@ void Mapgen::setLighting(u8 light, v3s16 nmin, v3s16 nmax)
435
436
}
436
437
437
438
438
- void Mapgen::lightSpread (VoxelArea &a, v3s16 p, u8 light)
439
+ void Mapgen::lightSpread (VoxelArea &a, std::queue<std::pair<v3s16, u8>> &queue,
440
+ const v3s16 &p, u8 light)
439
441
{
440
442
if (light <= 1 || !a.contains (p))
441
443
return ;
@@ -455,8 +457,8 @@ void Mapgen::lightSpread(VoxelArea &a, v3s16 p, u8 light)
455
457
// Bail out only if we have no more light from either bank to propogate, or
456
458
// we hit a solid block that light cannot pass through.
457
459
if ((light_day <= (n.param1 & 0x0F ) &&
458
- light_night <= (n.param1 & 0xF0 )) ||
459
- !ndef->get (n).light_propagates )
460
+ light_night <= (n.param1 & 0xF0 )) ||
461
+ !ndef->get (n).light_propagates )
460
462
return ;
461
463
462
464
// Since this recursive function only terminates when there is no light from
@@ -467,12 +469,8 @@ void Mapgen::lightSpread(VoxelArea &a, v3s16 p, u8 light)
467
469
468
470
n.param1 = light;
469
471
470
- lightSpread (a, p + v3s16 (0 , 0 , 1 ), light);
471
- lightSpread (a, p + v3s16 (0 , 1 , 0 ), light);
472
- lightSpread (a, p + v3s16 (1 , 0 , 0 ), light);
473
- lightSpread (a, p - v3s16 (0 , 0 , 1 ), light);
474
- lightSpread (a, p - v3s16 (0 , 1 , 0 ), light);
475
- lightSpread (a, p - v3s16 (1 , 0 , 0 ), light);
472
+ // add to queue
473
+ queue.emplace (p, light);
476
474
}
477
475
478
476
@@ -525,9 +523,10 @@ void Mapgen::propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow)
525
523
}
526
524
527
525
528
- void Mapgen::spreadLight (v3s16 nmin, v3s16 nmax)
526
+ void Mapgen::spreadLight (const v3s16 & nmin, const v3s16 & nmax)
529
527
{
530
528
// TimeTaker t("spreadLight");
529
+ std::queue<std::pair<v3s16, u8>> queue;
531
530
VoxelArea a (nmin, nmax);
532
531
533
532
for (int z = a.MinEdge .Z ; z <= a.MaxEdge .Z ; z++) {
@@ -551,18 +550,24 @@ void Mapgen::spreadLight(v3s16 nmin, v3s16 nmax)
551
550
552
551
u8 light = n.param1 ;
553
552
if (light) {
554
- lightSpread (a, v3s16 (x, y, z + 1 ), light);
555
- lightSpread (a, v3s16 (x, y + 1 , z ), light);
556
- lightSpread (a, v3s16 (x + 1 , y, z ), light);
557
- lightSpread (a, v3s16 (x, y, z - 1 ), light);
558
- lightSpread (a, v3s16 (x, y - 1 , z ), light);
559
- lightSpread (a, v3s16 (x - 1 , y, z ), light);
553
+ const v3s16 p (x, y, z);
554
+ // spread to all 6 neighbor nodes
555
+ for (const auto &dir : g_6dirs)
556
+ lightSpread (a, queue, p + dir, light);
560
557
}
561
558
}
562
559
}
563
560
}
564
561
565
- // printf("spreadLight: %dms\n", t.stop());
562
+ while (!queue.empty ()) {
563
+ const auto &i = queue.front ();
564
+ // spread to all 6 neighbor nodes
565
+ for (const auto &dir : g_6dirs)
566
+ lightSpread (a, queue, i.first + dir, i.second );
567
+ queue.pop ();
568
+ }
569
+
570
+ // printf("spreadLight: %lums\n", t.stop());
566
571
}
567
572
568
573
@@ -877,7 +882,7 @@ void MapgenBasic::generateDungeons(s16 max_stone_y)
877
882
return ;
878
883
879
884
PseudoRandom ps (blockseed + 70033 );
880
-
885
+
881
886
DungeonParams dp;
882
887
883
888
dp.np_alt_wall =
0 commit comments