载入中...
搜索中...
未找到
PcgSpawnProgress.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4namespace eve::procgen {
5namespace { }
6Result<PcgSpawnProgressStatus> PcgSpawnProgress::updateRule(std::string name,int total,int done,int localTotal,int localDone) {
7 if(name.empty()||total<=0||done<0||done>total||localTotal<=0||localDone<0||localDone>localTotal)
9 DiagnosticCode::InvalidArgument,"valid rule counts and a nonempty spawner name are required",{}, {},"procgen.pcgSpawnProgress"));
10 title_="Spawning"; subtitle_=std::move(name)+" "+std::to_string(localDone)+" of "+std::to_string(localTotal)+" Rules";
11 totalRuleCount_=total; totalRulesCompleted_=done; spawnerRuleCount_=localTotal; spawnerRulesCompleted_=localDone;
12 ruleProgress_=0; status_=done==total?PcgSpawnProgressStatus::Completed:PcgSpawnProgressStatus::Active;
14}
16 if(status_!=PcgSpawnProgressStatus::Active||!std::isfinite(value)||value<0||value>1)
18 DiagnosticCode::InvalidArgument,"active progress and a finite fraction in [0,1] are required",{}, {},"procgen.pcgSpawnProgress"));
19 ruleProgress_=value; return Result<PcgSpawnProgressStatus>::success(status_);
20}
26PcgSpawnProgressStatus PcgSpawnProgress::clear() noexcept { title_.clear(); subtitle_.clear(); totalRuleCount_=totalRulesCompleted_=spawnerRuleCount_=spawnerRulesCompleted_=0; ruleProgress_=0; return status_=PcgSpawnProgressStatus::Hidden; }
27double PcgSpawnProgress::progress() const noexcept { return totalRuleCount_<=0?0:std::clamp((double(totalRulesCompleted_)+ruleProgress_)/double(totalRuleCount_),0.0,1.0); }
28} // namespace eve::procgen
double value
std::string name
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
PcgSpawnProgressStatus clear() noexcept
Clear the progress state.
Result< PcgSpawnProgressStatus > requestCancel()
Mark cancellation requested while retaining the snapshot.
Result< PcgSpawnProgressStatus > updateRuleFraction(double progress)
Update the current rule fraction in [0,1].
Result< PcgSpawnProgressStatus > updateRule(std::string spawnerName, int totalRuleCount, int totalRulesCompleted, int spawnerRuleCount, int spawnerRulesCompleted)
Start or advance a spawner rule and reset its fractional progress.
double progress() const noexcept
Return Pcg's inverse-lerp total progress.
PcgSpawnProgressStatus
Observable lifecycle of a Pcg spawning progress operation.