11 constexpr float Pi = 3.14159265358979323846F;
12 constexpr std::array<std::array<std::uint8_t, 3>, 6>
PlayerColours{{
23 ratio = std::clamp(ratio, 0.0F, 1.0F);
25 return 0.5F - 0.5F * std::cos(ratio *
Pi);
26 return 0.5F + 0.5F * std::sin((ratio - 0.5F) *
Pi);
30 const std::array<float, 3>& start,
31 const std::array<float, 3>& end,
float ratio)
noexcept
34 start[0] + (end[0] - start[0]) * ratio,
35 start[1] + (end[1] - start[1]) * ratio,
36 start[2] + (end[2] - start[2]) * ratio};
50 std::uint8_t
colour)
noexcept
52 constexpr float Magnifier = 0.75F / 255.0F;
62 spotlightActive_ =
false;
66 fixedRatioValue_ = 0.0F;
67 startTarget_ = {240.0F, 300.0F, 240.0F};
68 endTarget_ = startTarget_;
69 currentTarget_ = startTarget_;
70 currentColour_ = {1.0F, 1.0F, 1.0F};
75 void BoardLightingController::beginSpotlight(std::uint64_t tick)
noexcept
77 spotlightActive_ =
true;
79 fixedRatioValue_ = 0.0F;
80 startTarget_ = {240.0F, 300.0F, 240.0F};
81 endTarget_ = startTarget_;
82 currentTarget_ = startTarget_;
83 moveStartTick_ = tick;
87 std::array<float, 3> BoardLightingController::interpolatedTarget(
88 std::uint64_t tick)
const noexcept
90 float ratio = fixedRatioValue_;
93 if (moveEndTick_ == moveStartTick_)
96 ratio =
static_cast<float>(tick - moveStartTick_) /
97 static_cast<float>(moveEndTick_ - moveStartTick_);
101 ratio = std::clamp(ratio, 0.0F, 1.0F);
102 return lerp3(startTarget_, endTarget_, ratio);
105 void BoardLightingController::updateSpotlightMotion(
106 const BoardLightingInputs&
inputs)
noexcept
108 for (std::uint64_t
t = 0;
t <
inputs.numberOfTicks; ++
t)
116 moveStartTick_ =
inputs.tick;
117 moveEndTick_ =
inputs.tick;
120 if (endTarget_[0] < 420.0F)
125 else if (endTarget_[0] > 0.0F)
132 if (endTarget_[2] < 420.0F)
137 else if (endTarget_[2] > 0.0F)
142 else if (!
inputs.tokenAnimationActive)
144 if (endTarget_ !=
inputs.tokenPosition)
146 startTarget_ = currentTarget_;
147 endTarget_ =
inputs.tokenPosition;
149 moveStartTick_ =
inputs.tick;
155 startTarget_ = currentTarget_;
156 endTarget_ =
inputs.tokenPosition;
161 currentTarget_ = interpolatedTarget(
inputs.tick);
164 void BoardLightingController::updateSpotlightColour(
165 const BoardLightingInputs&
inputs)
noexcept
168 for (std::uint64_t
t = 0;
t <
inputs.numberOfTicks; ++
t)
173 std::expected<engine::World3DLighting, std::string>
176 if (
inputs.numberOfTicks == 0)
182 return std::unexpected(
183 "board spotlight player colour is outside legacy 0..5 range");
186 lighting_.
ambient = {ambient, ambient, ambient};
190 0.86F * 0.35F, 0.77F * 0.35F};
193 lighting_.
sun.
color = {0.28F, 0.28F, 0.28F};
199 spotlightActive_ =
false;
202 if (!spotlightActive_)
203 beginSpotlight(
inputs.tick);
205 updateSpotlightMotion(
inputs);
206 updateSpotlightColour(
inputs);
209 currentTarget_[1] + 200.0F, currentTarget_[2]};
std::expected< engine::World3DLighting, std::string > tick(const BoardLightingInputs &inputs)
constexpr std::uint64_t SpotlightIdleDelayTicks
constexpr float SpotlightColourIncrement
constexpr float SpotlightIdleIncrement
constexpr std::uint64_t SpotlightFocusMoveTicks
constexpr float SpotlightFollowRatio
std::array< float, 3 > direction
std::array< float, 3 > color
World3DDirectionalLight sun
std::array< float, 3 > ambient
World3DDirectionalLight boardReflection
World3DSpotLight spotlight
std::array< float, 3 > attenuation
std::array< float, 3 > color
std::array< float, 3 > position
std::array< float, 3 > direction