MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / _SetGeneratingWorldProgress

Function _SetGeneratingWorldProgress

src/genworld_gui.cpp:1463–1515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1461}
1462
1463static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
1464{
1465 static const int percent_table[] = {0, 5, 14, 17, 20, 40, 55, 60, 65, 80, 85, 95, 99, 100 };
1466 static_assert(lengthof(percent_table) == GWP_CLASS_COUNT + 1);
1467 assert(cls < GWP_CLASS_COUNT);
1468
1469 /* Check if we really are generating the world.
1470 * For example, placing trees via the SE also calls this function, but
1471 * shouldn't try to update the progress.
1472 */
1473 if (!HasModalProgress()) return;
1474
1475 if (IsGeneratingWorldAborted()) {
1476 HandleGeneratingWorldAbortion();
1477 return;
1478 }
1479
1480 if (total == 0) {
1481 assert(GenWorldStatus::cls == _generation_class_table[cls]);
1482 GenWorldStatus::current += progress;
1483 assert(GenWorldStatus::current <= GenWorldStatus::total);
1484 } else {
1485 GenWorldStatus::cls = _generation_class_table[cls];
1486 GenWorldStatus::current = progress;
1487 GenWorldStatus::total = total;
1488 GenWorldStatus::percent = percent_table[cls];
1489 }
1490
1491 /* Percentage is about the number of completed tasks, so 'current - 1' */
1492 GenWorldStatus::percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (GenWorldStatus::current == 0 ? 0 : GenWorldStatus::current - 1) / GenWorldStatus::total;
1493
1494 if (_network_dedicated) {
1495 static uint last_percent = 0;
1496
1497 /* Never display 0% */
1498 if (GenWorldStatus::percent == 0) return;
1499 /* Reset if percent is lower than the last recorded */
1500 if (GenWorldStatus::percent < last_percent) last_percent = 0;
1501 /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
1502 if (GenWorldStatus::percent % 5 != 0 && GenWorldStatus::percent <= last_percent + 5) return;
1503 /* Never show steps smaller than 2%, even if it is a mod 5% */
1504 if (GenWorldStatus::percent <= last_percent + 2) return;
1505
1506 Debug(net, 3, "Map generation percentage complete: {}", GenWorldStatus::percent);
1507 last_percent = GenWorldStatus::percent;
1508
1509 return;
1510 }
1511
1512 SetWindowDirty(WC_MODAL_PROGRESS, 0);
1513
1514 VideoDriver::GetInstance()->GameLoopPause();
1515}
1516
1517/**
1518 * Set the total of a stage of the world generation.

Callers 2

Calls 5

HasModalProgressFunction · 0.85
IsGeneratingWorldAbortedFunction · 0.85
SetWindowDirtyFunction · 0.85
GameLoopPauseMethod · 0.80

Tested by

no test coverage detected