Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
SequenceCommands.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "SequenceRuntime.hpp"
4
5#include <array>
6#include <cstddef>
7#include <cstdint>
8#include <deque>
9#include <expected>
10#include <memory>
11#include <optional>
12#include <span>
13#include <variant>
14#include <vector>
15
16namespace monopoly::sequence
17{
20
22 {
23 std::shared_ptr<const SequenceProgram> program;
24 std::uint16_t priority{};
26 std::optional<SequenceTransform> initialTransform;
27 std::uint8_t labelOverride{};
28 };
30 {
32 std::uint16_t priority{};
33 bool wholeTree{};
34 };
36 {
38 std::uint16_t priority{};
39 std::uint8_t action{};
40 bool wholeTree{};
41 };
43 {
45 std::uint16_t priority{};
46 std::uint8_t volume{100};
47 bool wholeTree{};
48 };
50 {
52 std::uint16_t priority{};
53 std::uint16_t pitch{};
54 bool wholeTree{};
55 };
57 {
59 std::uint16_t priority{};
60 std::int8_t panning{};
61 bool wholeTree{};
62 };
71 {
73 std::uint16_t priority{};
74 bool wholeTree{};
75 };
76 inline constexpr std::uint8_t MonopolyRenderSlotCount = 5;
78 {
79 std::int32_t left{}, top{}, right{}, bottom{};
80 auto operator<=>(const SequenceViewportRect&) const = default;
81 };
88 {
89 std::uint8_t renderSlot{};
90 std::uint8_t cameraNumber{};
91 std::array<float, 3> position{};
92 std::array<float, 3> forwards{0.0F, 0.0F, 1.0F};
93 std::array<float, 3> up{0.0F, 1.0F, 0.0F};
94 float fieldOfView{0.7853981633974483F};
95 float nearPlane{1.0F};
96 float farPlane{5000.0F};
97 };
98
104
106 std::uint16_t priority, SequenceTransform transform,
107 bool wholeTree = false) noexcept;
108 [[nodiscard]] MoveSequenceCommand makeMoveXY(data::DataId dataId,
109 std::uint16_t priority, std::int32_t x, std::int32_t y) noexcept;
110 [[nodiscard]] MoveSequenceCommand makeMoveRySTxz(data::DataId dataId,
111 std::uint16_t priority, float yaw, float scale,
112 float x, float z) noexcept;
113
115 {
117 std::optional<SequenceNodeId> startedNode;
118 std::size_t matched{};
119 std::optional<RuntimeError> error;
120 std::vector<SequenceEvent> events;
121 };
122
123 // Owner-thread FIFO matching Monopoly's non-immediate ArtLib configuration.
124 // Commands remain queued while the Collect/Execute nesting level is positive.
125 // Chaining is deliberately absent: active Monopoly callers always pass an
126 // empty chain target, so the legacy waiting/dechained lists are not implied.
128 {
129 public:
130 static constexpr std::size_t Capacity = 500;
131
132 explicit SequenceCommandQueue(SequenceRuntime& runtime) noexcept;
133
134 [[nodiscard]] std::expected<void, CommandQueueError> enqueue(
135 StartSequenceCommand command);
136 [[nodiscard]] std::expected<void, CommandQueueError> enqueue(
137 StopSequenceCommand command);
138 [[nodiscard]] std::expected<void, CommandQueueError> enqueue(
139 MoveSequenceCommand command);
140 [[nodiscard]] std::expected<void, CommandQueueError> enqueue(
142 [[nodiscard]] std::expected<void, CommandQueueError> enqueue(
144 [[nodiscard]] std::expected<void, CommandQueueError> enqueue(
146 [[nodiscard]] std::expected<void, CommandQueueError> enqueue(
148 [[nodiscard]] std::expected<void, CommandQueueError> enqueue(
150 [[nodiscard]] std::expected<void, CommandQueueError> enqueue(
151 SetViewportCommand command);
152 [[nodiscard]] std::expected<void, CommandQueueError> enqueue(
153 SetCameraCommand command);
154
156 std::uint8_t renderSlot) const noexcept;
158 std::uint8_t renderSlot) const noexcept;
159 [[nodiscard]] std::expected<int, CommandQueueError> collect();
160 // Exactly zero drains immediately by running a zero-time update cycle.
161 // Like the source, unmatched extra Execute calls make the level negative.
162 [[nodiscard]] std::expected<int, CommandQueueError> execute();
163 [[nodiscard]] std::expected<void, RuntimeError> processUserCommands();
164 [[nodiscard]] std::expected<void, RuntimeError> updateCycle(std::int32_t parentClock);
165
166 [[nodiscard]] std::size_t pendingCount() const noexcept { return pending_.size(); }
168 [[nodiscard]] int nestingLevel() const noexcept { return nestingLevel_; }
169 [[nodiscard]] std::span<const SequenceCommandOutcome> outcomes() const noexcept
170 { return outcomes_; }
171 [[nodiscard]] std::span<const SequenceEvent> cycleEvents() const noexcept
172 { return cycleEvents_; }
173 [[nodiscard]] const std::optional<RuntimeError>& lastCycleError() const noexcept
174 { return cycleError_; }
175
176 private:
177 [[nodiscard]] std::expected<void, CommandQueueError> enqueueValidated(SequenceCommand command);
178 void drain();
179
180 SequenceRuntime& runtime_;
181 std::deque<SequenceCommand> pending_;
182 std::vector<SequenceCommandOutcome> outcomes_;
183 std::vector<SequenceEvent> cycleEvents_;
184 std::optional<RuntimeError> cycleError_;
185 std::array<std::optional<SetViewportCommand>, MonopolyRenderSlotCount> viewportStates_{};
186 std::array<std::optional<SetCameraCommand>, MonopolyRenderSlotCount> cameraStates_{};
187 int nestingLevel_{};
188 std::int32_t parentClock_{};
189 };
190}
std::uint16_t priority
unsigned index
Kind kind
float yaw
int z
std::span< const SequenceCommandOutcome > outcomes() 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()
std::size_t pendingCount() const noexcept
const SetViewportCommand * viewportState(std::uint8_t renderSlot) const noexcept
std::span< const SequenceEvent > cycleEvents() const noexcept
const std::optional< RuntimeError > & lastCycleError() const noexcept
std::expected< void, CommandQueueError > enqueue(StartSequenceCommand command)
std::expected< int, CommandQueueError > collect()
std::uint32_t DataId
Definition DataBanks.hpp:10
constexpr std::uint8_t MonopolyRenderSlotCount
MoveSequenceCommand makeMoveTheWorks(data::DataId dataId, std::uint16_t priority, SequenceTransform transform, bool wholeTree) noexcept
std::variant< std::monostate, Matrix2D, Matrix3D > SequenceTransform
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::optional< SequenceNodeId > startedNode
auto operator<=>(const SequenceViewportRect &) const =default
std::shared_ptr< const SequenceProgram > program
std::optional< SequenceTransform > initialTransform