Modern UI contract: live matchdays with interventions
session.advance {live: true} runs the kickoff on its own thread and stops at
the minutes of a live match of a human manager (not at a voided one).
live.step plays on, live.substitute and live.tactics act as the original's
pitch and tactics screens during a match (open, change, close) on the
kickoff thread, live.finish plays the day to its end. Other commands answer
live_running meanwhile, read_live reports the minute and the live scores.
A missing contract decision rolls the whole live day back. Also: the
recording takes matches up to the day the kickoff ends.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
10a8f0b881
commit
822331f045
6 files changed
+386
-4
No files matched your search
@@ -18,14 +18,17 @@
|
||||
// ModernSession owns the engine state of that sequence. It never draws numbers for
|
||||
// rendering; every random draw belongs to one of the steps above.
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
@@ -1140,6 +1143,52 @@ private:
|
||||
bool loan_return_presenter_installed_ = false;
|
||||
bool loan_return_offer_presenter_installed_ = false;
|
||||
bool options_applied_ = false;
|
||||
|
||||
// --- a live kickoff of the interface contract (session.advance {live: true}) ----------------
|
||||
// The kickoff runs on its own thread and stops at the match minutes the interface asks for
|
||||
// (TurnDriver::live_minute); live.step, live.substitute, live.tactics and live.finish act while
|
||||
// it stands still, the interface thread waits meanwhile. Reads therefore never meet a running
|
||||
// engine. Declared last: destroyed first, its destructor ends a running kickoff.
|
||||
struct ContractExpiryAnswer { bool renew = false; int term = 0; uint32_t salary = 0; };
|
||||
struct LiveRun {
|
||||
std::thread worker;
|
||||
std::mutex mutex;
|
||||
std::condition_variable changed;
|
||||
bool paused = false, done = false, finish = false;
|
||||
int remaining = 1; // minutes to play before the next stop
|
||||
int minute = 0; // the minute it stands at
|
||||
MatchEngine* engine = nullptr; // valid while paused
|
||||
std::vector<MatchGroup>* groups = nullptr;
|
||||
std::function<void()> task; // an intervention, run on the kickoff thread
|
||||
TurnAdvanceResult result;
|
||||
std::string error, pending_player;
|
||||
uint64_t engine_revision = 0; // the revision the kickoff and its interventions count
|
||||
// the advance it belongs to: rollback point, answers, the hooks it replaced
|
||||
ModernState saved_state;
|
||||
WatcomRandom saved_rand;
|
||||
GameRandom saved_game;
|
||||
uint64_t base_revision = 0;
|
||||
uint32_t from_date = 0;
|
||||
std::map<std::string, ContractExpiryAnswer> answers;
|
||||
cli::Json::Array awards;
|
||||
std::function<int(GameState&, int, int)> previous_contract_hook;
|
||||
bool previous_contract_installed = false;
|
||||
SportschauPresentationHooks previous_sportschau;
|
||||
decltype(TurnDriver::live_minute) previous_live_minute;
|
||||
~LiveRun() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
finish = true;
|
||||
}
|
||||
changed.notify_all();
|
||||
if (worker.joinable()) worker.join();
|
||||
}
|
||||
};
|
||||
std::shared_ptr<LiveRun> live_; // (shared: the session is copied for staged modal work, never while live)
|
||||
// waits until the live kickoff stands still or is done (interface thread)
|
||||
void wait_live();
|
||||
// ends a finished live kickoff: hooks back, rollback on failure; the answer for `request_id`
|
||||
cli::Json finish_live(const std::string& request_id, uint64_t previous, uint64_t& revision);
|
||||
};
|
||||
|
||||
} // namespace bmh::modern::app
|
||||
Reference in new issue
Block a user