载入中...
搜索中...
未找到
PcgLightingAmbientPhotoMode.cpp
浏览该文件的文档.
2
3#include "common/Capability.h"
4
5#include <cmath>
6
7namespace eve::daynight {
8namespace {
9bool accepts(const std::string &field) {
10 return field == "m_ambientIntensity" || field == "m_ambientSkyColor" ||
11 field == "m_ambientEquatorColor" || field == "m_ambientGroundColor" ||
12 field == "m_globalLightIntensityMultiplier";
13}
14} // namespace
15
17 if (authority_) {
18 cap::removeListener<IPhotoModeFieldSink>(this);
19 if (target_) target_->setPcgAmbientLight(baseline_).value();
20 }
21}
22
24 target_ = target;
25 if (target_) {
26 baseline_ = target_->getPcgAmbientLight();
27 state_ = baseline_;
28 }
29}
30
32 if (enabled == authority_) return;
33 if (enabled) {
34 state_.active = true;
35 if (target_) target_->setPcgAmbientLight(state_).value();
36 cap::addListener<IPhotoModeFieldSink>(this);
37 } else {
38 cap::removeListener<IPhotoModeFieldSink>(this);
39 if (target_) target_->setPcgAmbientLight(baseline_).value();
40 }
41 authority_ = enabled;
42}
43
50
52 const PhotoModeAssignment &assignment) {
53 const auto fail = [&](DiagnosticCode code, const char *message) {
55 code, message, assignment.field, {}, "daynight.pcgLightingAmbient"));
56 };
57 if (!target_)
58 return fail(DiagnosticCode::Unsupported, "day-night target is unavailable");
59 if (!accepts(assignment.field))
60 return fail(DiagnosticCode::InvalidArgument, "unsupported Pcg ambient field");
61
62 PcgAmbientLightState candidate = state_;
63 if (assignment.field == "m_ambientSkyColor" ||
64 assignment.field == "m_ambientEquatorColor" ||
65 assignment.field == "m_ambientGroundColor") {
66 const auto *value = std::get_if<PhotoModeColor>(&assignment.value);
67 if (!value || !std::isfinite(value->r) || !std::isfinite(value->g) ||
68 !std::isfinite(value->b) || value->r < 0.f || value->g < 0.f ||
69 value->b < 0.f)
71 "ambient color requires finite non-negative RGB channels");
72 float *red = &candidate.skyRed;
73 float *green = &candidate.skyGreen;
74 float *blue = &candidate.skyBlue;
75 if (assignment.field == "m_ambientEquatorColor") {
76 red = &candidate.equatorRed;
77 green = &candidate.equatorGreen;
78 blue = &candidate.equatorBlue;
79 } else if (assignment.field == "m_ambientGroundColor") {
80 red = &candidate.groundRed;
81 green = &candidate.groundGreen;
82 blue = &candidate.groundBlue;
83 }
84 *red = value->r;
85 *green = value->g;
86 *blue = value->b;
87 } else {
88 const auto *value = std::get_if<float>(&assignment.value);
89 if (!value || !std::isfinite(*value))
91 "ambient setting requires a finite float");
92 if (assignment.field == "m_ambientIntensity")
93 candidate.intensity = *value;
94 else
95 candidate.globalLightMultiplier = *value;
96 }
97
98 auto result = target_->setPcgAmbientLight(candidate);
99 if (!result.ok()) return result;
100 state_ = candidate;
101 return Result<void>::success();
102}
103
104} // namespace eve::daynight
LogicalId target
double value
std::string message
DiagnosticCode code
const std::string * accepts
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
void value() const
Mark a successful void operation as checked.
Definition Result.h:526
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 > setPcgAmbientLight(const PcgAmbientLightState &state)
Atomically replace Pcg ambient colors, intensity and direct-light multiplier.
Definition DayNight.cpp:421
void setAuthority(bool enabled)
Register or revoke ownership of the five ambient-light fields.
~PcgLightingAmbientPhotoMode() override
Pcg lighting ambient photo mode.
void setTarget(DayNight *target) noexcept
Attach a borrowed DayNight target and seed local state from it.
PhotoModeFieldAcceptance acceptsPhotoModeField(const PhotoModeAssignment &assignment) const noexcept override
Accept only Pcg ambient and global-light assignments.
Result< void > applyPhotoModeField(const PhotoModeAssignment &assignment) override
Validate and atomically project one field through DayNight.
const EditorValue * field(const EditorValue &value, const char *name)
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.
Pcg ambient-gradient colors and global direct-light multiplier.
Definition DayNight.h:61