@@ -112,7 +112,9 @@ TileGenerator::TileGenerator():
112
112
m_geomY2(2048 ),
113
113
m_exhaustiveSearch(EXH_AUTO),
114
114
m_zoom(1 ),
115
- m_scales(SCALE_LEFT | SCALE_TOP)
115
+ m_scales(SCALE_LEFT | SCALE_TOP),
116
+ m_progressMax(0 ),
117
+ m_progressLast(-1 )
116
118
{
117
119
}
118
120
@@ -354,11 +356,10 @@ void TileGenerator::openDb(const std::string &input)
354
356
355
357
// Determine how we're going to traverse the database (heuristic)
356
358
if (m_exhaustiveSearch == EXH_AUTO) {
357
- using u64 = uint64_t ;
358
- u64 y_range = (m_yMax / 16 + 1 ) - (m_yMin / 16 );
359
- u64 blocks = (u64)(m_geomX2 - m_geomX) * y_range * (u64)(m_geomY2 - m_geomY);
359
+ size_t y_range = (m_yMax / 16 + 1 ) - (m_yMin / 16 );
360
+ size_t blocks = (m_geomX2 - m_geomX) * y_range * (m_geomY2 - m_geomY);
360
361
#ifndef NDEBUG
361
- std::cout << " Heuristic parameters:"
362
+ std::cerr << " Heuristic parameters:"
362
363
<< " preferRangeQueries()=" << m_db->preferRangeQueries ()
363
364
<< " y_range=" << y_range << " blocks=" << blocks << std::endl;
364
365
#endif
@@ -415,11 +416,12 @@ void TileGenerator::loadBlocks()
415
416
m_positions[pos.z ].emplace (pos.x );
416
417
}
417
418
418
- #ifndef NDEBUG
419
419
int count = 0 ;
420
420
for (const auto &it : m_positions)
421
421
count += it.second .size ();
422
- std::cout << " Loaded " << count
422
+ m_progressMax = count;
423
+ #ifndef NDEBUG
424
+ std::cerr << " Loaded " << count
423
425
<< " positions (across Z: " << m_positions.size () << " ) for rendering" << std::endl;
424
426
#endif
425
427
}
@@ -473,6 +475,7 @@ void TileGenerator::renderMap()
473
475
{
474
476
BlockDecoder blk;
475
477
const int16_t yMax = m_yMax / 16 + 1 ;
478
+ size_t count = 0 ;
476
479
477
480
auto renderSingle = [&] (int16_t xPos, int16_t zPos, BlockList &blockStack) {
478
481
m_readPixels.reset ();
@@ -519,6 +522,7 @@ void TileGenerator::renderMap()
519
522
blockStack.sort ();
520
523
521
524
renderSingle (xPos, zPos, blockStack);
525
+ reportProgress (count++);
522
526
}
523
527
postRenderRow (zPos);
524
528
}
@@ -543,17 +547,21 @@ void TileGenerator::renderMap()
543
547
blockStack.sort ();
544
548
545
549
renderSingle (xPos, zPos, blockStack);
550
+ reportProgress (count++);
546
551
}
547
552
postRenderRow (zPos);
548
553
}
549
554
} else if (m_exhaustiveSearch == EXH_FULL) {
555
+ const size_t span_y = yMax - (m_yMin / 16 );
556
+ m_progressMax = (m_geomX2 - m_geomX) * span_y * (m_geomY2 - m_geomY);
550
557
#ifndef NDEBUG
551
558
std::cerr << " Exhaustively searching "
552
- << (m_geomX2 - m_geomX) << " x" << (yMax - (m_yMin / 16 )) << " x"
559
+ << (m_geomX2 - m_geomX) << " x" << span_y << " x"
553
560
<< (m_geomY2 - m_geomY) << " blocks" << std::endl;
554
561
#endif
562
+
555
563
std::vector<BlockPos> positions;
556
- positions.reserve (yMax - (m_yMin / 16 ) );
564
+ positions.reserve (span_y );
557
565
for (int16_t zPos = m_geomY2 - 1 ; zPos >= m_geomY; zPos--) {
558
566
for (int16_t xPos = m_geomX2 - 1 ; xPos >= m_geomX; xPos--) {
559
567
positions.clear ();
@@ -565,10 +573,13 @@ void TileGenerator::renderMap()
565
573
blockStack.sort ();
566
574
567
575
renderSingle (xPos, zPos, blockStack);
576
+ reportProgress (count++);
568
577
}
569
578
postRenderRow (zPos);
570
579
}
571
580
}
581
+
582
+ reportProgress (m_progressMax);
572
583
}
573
584
574
585
void TileGenerator::renderMapBlock (const BlockDecoder &blk, const BlockPos &pos)
@@ -801,6 +812,27 @@ void TileGenerator::printUnknown()
801
812
std::cerr << " \t " << node << std::endl;
802
813
}
803
814
815
+ void TileGenerator::reportProgress (size_t count)
816
+ {
817
+ if (!m_progressMax)
818
+ return ;
819
+ int percent = count / static_cast <float >(m_progressMax) * 100 ;
820
+ if (percent == m_progressLast)
821
+ return ;
822
+ m_progressLast = percent;
823
+
824
+ // Print a nice-looking ASCII progress bar
825
+ char bar[51 ] = {0 };
826
+ memset (bar, ' ' , 50 );
827
+ int i = 0 , j = percent;
828
+ for (; j >= 2 ; j -= 2 )
829
+ bar[i++] = ' =' ;
830
+ if (j)
831
+ bar[i++] = ' -' ;
832
+ std::cout << " [" << bar << " ] " << percent << " % " << (percent == 100 ? " \n " : " \r " );
833
+ std::cout.flush ();
834
+ }
835
+
804
836
inline int TileGenerator::getImageX (int val, bool absolute) const
805
837
{
806
838
if (absolute)
0 commit comments