载入中...
搜索中...
未找到
PcgLightingSkyboxPhotoMode.cpp
浏览该文件的文档.
2
3#include "common/Capability.h"
4
5#include <cmath>
6
7namespace eve::daynight {
8
10 if (authority_) cap::removeListener<IPhotoModeFieldSink>(this);
11}
12
14 target_ = target;
15 if (target_) state_ = target_->getPcgSkybox();
16}
17
19 if (enabled == authority_) return;
20 if (enabled) cap::addListener<IPhotoModeFieldSink>(this);
21 else cap::removeListener<IPhotoModeFieldSink>(this);
22 authority_ = enabled;
23}
24
26 const PhotoModeAssignment &assignment) const noexcept {
27 if (assignment.domain != PhotoModeDomain::Lighting)
29 return assignment.field == "m_skyboxOverride" ||
30 assignment.field == "m_skyboxRotation" ||
31 assignment.field == "m_skyboxExposure" ||
32 assignment.field == "m_skyboxTint"
35}
36
38 const PhotoModeAssignment &assignment) {
39 const auto fail = [&](DiagnosticCode code, const char *message) {
41 code, message, assignment.field, {}, "daynight.pcgLightingSkybox"));
42 };
43 if (!target_)
44 return fail(DiagnosticCode::Unsupported, "day-night target is unavailable");
45
46 PcgSkyboxState candidate = state_;
47 if (assignment.field == "m_skyboxOverride") {
48 const auto *value = std::get_if<bool>(&assignment.value);
49 if (!value)
51 "skybox override requires a bool");
52 candidate.enabled = *value;
53 } else if (assignment.field == "m_skyboxTint") {
54 const auto *value = std::get_if<PhotoModeColor>(&assignment.value);
55 if (!value || !std::isfinite(value->r) || !std::isfinite(value->g) ||
56 !std::isfinite(value->b) || value->r < 0.f || value->g < 0.f ||
57 value->b < 0.f)
59 "skybox tint requires finite non-negative RGB channels");
60 candidate.tintRed = value->r;
61 candidate.tintGreen = value->g;
62 candidate.tintBlue = value->b;
63 } else {
64 const auto *value = std::get_if<float>(&assignment.value);
65 if (!value || !std::isfinite(*value))
67 "skybox field requires a finite float");
68 if (assignment.field == "m_skyboxRotation")
69 candidate.rotationDegrees = *value;
70 else if (assignment.field == "m_skyboxExposure")
71 candidate.exposure = *value;
72 else
74 "unsupported Pcg skybox field");
75 }
76
77 auto result = target_->setPcgSkybox(candidate);
78 if (!result.ok()) return result;
79 state_ = candidate;
80 return Result<void>::success();
81}
82
83} // namespace eve::daynight
LogicalId target
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
DayNight module — a time-of-day cycle that drives the sun, sky and light.
Definition DayNight.h:94
Result< void > setPcgSkybox(const PcgSkyboxState &state)
Atomically replace Pcg's persistent skybox override.
Definition DayNight.cpp:366
void setTarget(DayNight *target) noexcept
Attach a borrowed DayNight target and seed local state from it.
void setAuthority(bool enabled)
Register or revoke ownership of the four Pcg skybox fields.
PhotoModeFieldAcceptance acceptsPhotoModeField(const PhotoModeAssignment &assignment) const noexcept override
Accept only Pcg skybox Lighting assignments.
Result< void > applyPhotoModeField(const PhotoModeAssignment &assignment) override
Validate and atomically project one field through DayNight.
~PcgLightingSkyboxPhotoMode() override
Pcg lighting skybox photo mode.
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.
Persistent Pcg skybox override settings.
Definition DayNight.h:33