Jazz2::Compatibility::ConversionProgress class

Reports how far a conversion of the original game files has got.

The conversion is the only part of the first start that takes long enough to be worth showing — on a slow device it isn't over by the time the intro video is, so the loading screen that follows it shows a progress bar instead of only the spinner.

A step of the conversion is handed a reporter over the part of the whole that it is responsible for, so it doesn't have to know where in the whole that part sits — it reports 0 to 1 of its own work and Narrow() maps that into the enclosing range. The callback is not owned, which keeps a reporter cheap to copy and to pass by value, so whoever owns it has to keep it alive for as long as the conversion runs.

Reported from whatever thread drives the conversion — the parallel initialization thread in the game — so the callback must not touch anything that the main thread owns.

Constructors, destructors, conversion operators

ConversionProgress() noexcept
Creates a reporter that discards everything reported to it.
ConversionProgress(Function<void(float)>* callback) explicit noexcept
Creates a reporter that reports the whole range to the specified callback.

Public functions

auto IsActive() const -> bool noexcept
Returns true if anything listens to the reported progress.
void Report(float value) const
Reports the progress of the current range, from 0 to 1.
void ReportStep(std::int32_t current, std::int32_t total) const
Reports the progress of the current range as current out of total steps.
auto Narrow(float from, float to) const -> ConversionProgress noexcept
Returns a reporter over the specified sub-range of the current range.

Function documentation

bool Jazz2::Compatibility::ConversionProgress::IsActive() const noexcept

Returns true if anything listens to the reported progress.

A measurement that is only needed to report progress — counting the files to be converted ahead of time, for example — can be skipped entirely otherwise.

ConversionProgress Jazz2::Compatibility::ConversionProgress::Narrow(float from, float to) const noexcept

Returns a reporter over the specified sub-range of the current range.

Both bounds are fractions of the current range, so a step that takes up its last tenth is handed Narrow(0.9f, 1.0f) however large the current range itself is.