21 std::shared_ptr<const script::LoadedReactionTable> initial,
bool watch)
25 m_reload.emplace(std::move(source), std::move(initial));
29 m_known.emplace(table->tableVersion, table);
33 if (!
m_reload || frameNumber % POLL_INTERVAL_FRAMES != 0)
51 m_lastMessage = std::format(
"版 {:016x} を読んだ(物質 {}・規則 {})。次の刻みの境界で当てる{}{}",
59 if (command.type != sim::PROBE_COMMAND_TYPE_TABLE)
63 const auto known =
m_known.find(version);
65 return std::unexpected(
66 std::format(
"再生ファイルの刻み {} で反応表が版 {:016x} "
67 "に変わるが、その表を持っていない(起動時の表は版 {:016x}。"
68 "表の中身を再生ファイルに残すのは T-0193)",
72 m_scheduled.push_back({.tick = command.targetTick, .table = known->second});
79 uint64_t firstUnit, uint32_t unitCount, uint32_t unitsPerTick,
bool replaying,
bool canAddCommand,
80 uint32_t& nextSequence, std::vector<sim::ProbeCommand>& commands) {
84 const uint64_t applyTick = (firstUnit + unitsPerTick - 1) / unitsPerTick;
87 return std::unexpected(std::move(scheduled.error()));
88 }
else if (
m_waiting && canAddCommand && applyTick * unitsPerTick < firstUnit + unitCount) {
96 std::vector<sim::ProbeTableSwap> swaps;
98 const uint64_t swapUnit = it->tick * unitsPerTick;
99 if (swapUnit < firstUnit)
100 return std::unexpected(std::format(
"反応表の差し替えの刻み {} を過ぎてしまった", it->tick));
102 if (swapUnit >= firstUnit + unitCount) {
107 swaps.push_back({.tick = it->tick, .table = &it->table->table});
std::vector< Scheduled > m_scheduled
std::map< uint64_t, std::shared_ptr< const script::LoadedReactionTable > > m_known
void Poll(uint64_t frameNumber)
uint64_t m_appliedVersion
std::expected< std::vector< sim::ProbeTableSwap >, std::string > TakeSwaps(uint64_t firstUnit, uint32_t unitCount, uint32_t unitsPerTick, bool replaying, bool canAddCommand, uint32_t &nextSequence, std::vector< sim::ProbeCommand > &commands)
std::optional< script::ReactionTableHotReload > m_reload
std::string m_lastMessage
void Remember(const std::shared_ptr< const script::LoadedReactionTable > &table)
TableHotReload(script::ReactionTableSource source, std::shared_ptr< const script::LoadedReactionTable > initial, bool watch)
std::shared_ptr< const script::LoadedReactionTable > m_waiting
std::expected< void, std::string > ScheduleReplayed(std::span< const sim::ProbeCommand > commands)
std::vector< std::shared_ptr< const script::LoadedReactionTable > > m_inFlight
constexpr uint64_t POLL_INTERVAL_FRAMES
constexpr bool CommandPrecedes(const Command &a, const Command &b)
ProbeCommand MakeTableCommand(uint64_t targetTick, uint32_t sequence, uint64_t version)
uint64_t TableCommandVersion(const ProbeCommand &command)
void Log(Channel channel, Level level, FormatWithLocation< std::type_identity_t< Args >... > pattern, Args &&... args)
std::shared_ptr< const LoadedReactionTable > table