11 {
return {dataId,
priority, std::move(transform), wholeTree}; }
14 std::uint16_t
priority, std::int32_t
x, std::int32_t
y)
noexcept
19 float x,
float z)
noexcept
30 std::expected<void, CommandQueueError> SequenceCommandQueue::enqueueValidated(
35 pending_.push_back(std::move(command));
44 return enqueueValidated(std::move(command));
50 return enqueueValidated(command);
56 return enqueueValidated(std::move(command));
64 return enqueueValidated(command);
70 return enqueueValidated(command);
76 return enqueueValidated(command);
82 return enqueueValidated(command);
88 return enqueueValidated(command);
96 return enqueueValidated(command);
107 return enqueueValidated(command);
111 std::uint8_t renderSlot)
const noexcept
113 if (renderSlot >= viewportStates_.size() || !viewportStates_[renderSlot])
115 return &*viewportStates_[renderSlot];
119 std::uint8_t renderSlot)
const noexcept
121 if (renderSlot >= cameraStates_.size() || !cameraStates_[renderSlot])
return nullptr;
122 return &*cameraStates_[renderSlot];
127 if (nestingLevel_ == std::numeric_limits<int>::max())
129 return ++nestingLevel_;
134 cycleEvents_.clear();
136 if (nestingLevel_ == std::numeric_limits<int>::min())
139 if (nestingLevel_ == 0 && !pending_.empty())
144 const auto updated = runtime_.
update(parentClock_);
145 const auto events = runtime_.
events();
146 cycleEvents_.assign(events.begin(), events.end());
147 cycleError_ = updated ? std::nullopt : std::optional<RuntimeError>(updated.error());
149 return nestingLevel_;
152 std::expected<void, RuntimeError>
162 void SequenceCommandQueue::drain()
165 while (nestingLevel_ <= 0 && !pending_.empty())
167 auto command = std::move(pending_.front());
168 pending_.pop_front();
169 std::visit([
this](
auto&&
value)
171 using Command = std::remove_cvref_t<
decltype(
value)>;
172 if constexpr (std::is_same_v<Command, StartSequenceCommand>)
174 const auto result = runtime_.
start(
176 std::move(
value.initialTransform),
value.labelOverride);
178 result ? std::optional<SequenceNodeId>(*result) : std::
nullopt,
181 else if constexpr (std::is_same_v<Command, StopSequenceCommand>)
185 outcomes_.push_back(SequenceCommandOutcome{
188 else if constexpr (std::is_same_v<Command, MoveSequenceCommand>)
192 outcomes_.push_back(SequenceCommandOutcome{
195 else if constexpr (std::is_same_v<Command, SetSequenceEndingActionCommand>)
200 {}, result ? *result : 0
U,
201 result ? std::nullopt : std::optional<RuntimeError>(result.error())});
203 else if constexpr (std::is_same_v<Command, SetSequenceVolumeCommand>)
207 outcomes_.push_back(SequenceCommandOutcome{
210 else if constexpr (std::is_same_v<Command, SetSequencePitchCommand>)
214 outcomes_.push_back(SequenceCommandOutcome{
217 else if constexpr (std::is_same_v<Command, SetSequencePanningCommand>)
221 outcomes_.push_back(SequenceCommandOutcome{
224 else if constexpr (std::is_same_v<Command, ForceRedrawSequenceCommand>)
228 outcomes_.push_back(SequenceCommandOutcome{
231 else if constexpr (std::is_same_v<Command, SetViewportCommand>)
234 outcomes_.push_back(SequenceCommandOutcome{
240 outcomes_.push_back(SequenceCommandOutcome{
243 }, std::move(command));
245 if (!outcomes_.empty() &&
248 !outcomes_.back().error)
250 const auto events = runtime_.
events();
251 outcomes_.back().events.assign(events.begin(), events.end());
259 cycleEvents_.clear();
262 if (nestingLevel_ <= 0) drain();
264 const auto events = runtime_.
events();
265 cycleEvents_.assign(events.begin(), events.end());
266 if (!updated) cycleError_ = updated.error();
272 return static_cast<int>((100U * pending_.size()) /
Capacity);
SequenceCommandQueue(SequenceRuntime &runtime) noexcept
static constexpr std::size_t Capacity
int percentageFull() const noexcept
const SetCameraCommand * cameraState(std::uint8_t renderSlot) const noexcept
std::expected< int, CommandQueueError > execute()
std::expected< void, RuntimeError > updateCycle(std::int32_t parentClock)
std::expected< void, RuntimeError > processUserCommands()
const SetViewportCommand * viewportState(std::uint8_t renderSlot) const noexcept
std::expected< void, CommandQueueError > enqueue(StartSequenceCommand command)
std::expected< int, CommandQueueError > collect()
std::size_t setPitchMatching(data::DataId id, std::uint16_t priority, std::uint16_t pitch, bool wholeTree=false)
std::size_t forceRedrawMatching(data::DataId id, std::uint16_t priority, bool wholeTree=false)
std::expected< void, RuntimeError > update(std::int32_t parentClock)
std::size_t moveMatching(data::DataId id, std::uint16_t priority, const SequenceTransform &transform, bool wholeTree=false)
std::size_t setPanningMatching(data::DataId id, std::uint16_t priority, std::int8_t panning, bool wholeTree=false)
std::size_t stopMatching(data::DataId id, std::uint16_t priority, bool wholeTree=false)
std::expected< std::size_t, RuntimeError > setEndingActionMatching(data::DataId id, std::uint16_t priority, std::uint8_t action, bool wholeTree=false)
std::expected< SequenceNodeId, RuntimeError > start(std::shared_ptr< const SequenceProgram > program, std::uint16_t priority=0, ClockStartOptions options={}, std::optional< SequenceTransform > initialTransform=std::nullopt, std::uint8_t labelOverride=0)
std::size_t setVolumeMatching(data::DataId id, std::uint16_t priority, std::uint8_t volume, bool wholeTree=false)
std::span< const SequenceEvent > events() const noexcept
constexpr std::uint8_t MonopolyRenderSlotCount
MoveSequenceCommand makeMoveTheWorks(data::DataId dataId, std::uint16_t priority, SequenceTransform transform, bool wholeTree) noexcept
Matrix3D moveRySTxzTransform(float yaw, float scale, float x, float z) noexcept
std::variant< std::monostate, Matrix2D, Matrix3D > SequenceTransform
SequenceTransform moveXYTransform(std::int32_t x, std::int32_t y) noexcept
std::variant< StartSequenceCommand, StopSequenceCommand, MoveSequenceCommand, SetSequenceEndingActionCommand, SetSequenceVolumeCommand, SetSequencePitchCommand, SetSequencePanningCommand, ForceRedrawSequenceCommand, SetViewportCommand, SetCameraCommand > SequenceCommand
MoveSequenceCommand makeMoveXY(data::DataId dataId, std::uint16_t priority, std::int32_t x, std::int32_t y) noexcept
MoveSequenceCommand makeMoveRySTxz(data::DataId dataId, std::uint16_t priority, float yaw, float scale, float x, float z) noexcept
std::shared_ptr< const SequenceProgram > program