载入中...
搜索中...
未找到
PcgLightingTimePhotoMode.cpp
浏览该文件的文档.
2
3#include "common/Capability.h"
4#include "daynight/DayNight.h"
5
6#include <cmath>
7
8namespace eve::daynight {
9
11 if (authority_) cap::removeListener<IPhotoModeFieldSink>(this);
12}
13
15 if (enabled == authority_) return;
16 if (enabled) cap::addListener<IPhotoModeFieldSink>(this);
17 else cap::removeListener<IPhotoModeFieldSink>(this);
18 authority_ = enabled;
19}
20
22 const PhotoModeAssignment& assignment) const noexcept {
24 return assignment.field == "m_pcgTime" || assignment.field == "m_pcgTimeScale" ||
25 assignment.field == "m_pcgTimeOfDayEnabled"
28}
29
31 const auto fail = [&](DiagnosticCode code, const char* message) {
33 Diagnostic::error(code, message, assignment.field, {}, "daynight.pcgLightingTime"));
34 };
35 if (!target_) return fail(DiagnosticCode::Unsupported, "day-night target is unavailable");
36
37 if (assignment.field == "m_pcgTimeOfDayEnabled") {
38 const auto* value = std::get_if<bool>(&assignment.value);
39 if (!value) return fail(DiagnosticCode::InvalidArgument, "time-of-day enabled requires a bool");
40 target_->setPaused(!*value);
41 return Result<void>::success();
42 }
43 const auto* value = std::get_if<float>(&assignment.value);
44 if (!value || !std::isfinite(*value))
45 return fail(DiagnosticCode::InvalidArgument, "Pcg time field requires a finite float");
46 if (assignment.field == "m_pcgTime") {
47 if (*value < 0.f || *value > 24.f)
48 return fail(DiagnosticCode::InvalidArgument, "Pcg time must be in [0,24]");
49 target_->setTimeOfDay(*value);
50 } else if (assignment.field == "m_pcgTimeScale") {
51 if (*value < 0.f || *value > 200.f)
52 return fail(DiagnosticCode::InvalidArgument, "Pcg time scale must be in [0,200]");
53 target_->setSpeed(*value);
54 } else {
55 return fail(DiagnosticCode::InvalidArgument, "unsupported Pcg lighting-time field");
56 }
57 return Result<void>::success();
58}
59
60} // namespace eve::daynight
double value
std::string message
DiagnosticCode code
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
void setPaused(bool paused)
Sets the paused.
Definition DayNight.cpp:302
void setSpeed(float hoursPerRealHour)
Sets the speed.
Definition DayNight.cpp:300
void setTimeOfDay(float hours)
Sets the time of day.
Definition DayNight.cpp:293
~PcgLightingTimePhotoMode() override
Pcg lighting time photo mode.
Result< void > applyPhotoModeField(const PhotoModeAssignment &assignment) override
Applies photo mode field.
PhotoModeFieldAcceptance acceptsPhotoModeField(const PhotoModeAssignment &assignment) const noexcept override
Accepts photo mode field.
void setAuthority(bool enabled)
Register or revoke this instance as owner of the three Pcg time fields.
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
PhotoModeFieldAcceptance
Capability implemented by the composition root that routes assignments to domain owners.
bool enabled
One reversible field assignment in a photo-mode transaction.