App::handle: the presenters passed to the controller are named members
handle() was 1,628 lines: the call of serve_flow_request with 22 presenter lambdas written inline. They are member functions now (present_live_minute, observe_live_minute, animate_ball / chance / shot / set_piece / booking / shootout, present_reality, choose_transfer_offer, present_transfer_decision, present_season_checkpoint, show_club_information, ask_advertising_renewal, ask_national_friendly, ...), as are its two local helpers (present_live_lineup, present_running_overview). handle() keeps 111 lines. handle() is never re-entered (its callers are the service functions and run(), none of which is reached from inside it), so its ten locals became members that handle() resets where they were declared. The bodies moved unchanged. Verified: robot (234 commands, live match included), UI walk, 9 careers identical; 211 of 211 tests. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
71aeb7cc61
commit
99200f1dc8
1 file changed
+178
-95
+178
-95
@@ -1014,49 +1014,19 @@ struct App {
|
|||||||
|
|
||||||
std::optional<Uint8> timed_notice_release;
|
std::optional<Uint8> timed_notice_release;
|
||||||
|
|
||||||
// =====================================================================================
|
|
||||||
// Handling FlowResults (requests from the UI flow)
|
// --- the request in service (state of App::handle and of the presenters it passes on) ---
|
||||||
// =====================================================================================
|
// handle() is never re-entered: every presenter below runs inside one handle() call.
|
||||||
// Called by the main loop for every ui::FlowResult. It handles quitting and the process
|
|
||||||
// timer, then passes the request to app::serve_flow_request() together with the
|
bool live_skipped;
|
||||||
// presenter lambdas defined inside, which the engine may call back synchronously.
|
|
||||||
auto handle(const ui::FlowResult& r) {
|
uint64_t live_overview_sequence;
|
||||||
pitch_pointer.show({}, renderer);
|
|
||||||
// A quit request must be confirmed by the player; otherwise the desk reports it as cancelled.
|
|
||||||
if (r.request == ui::FlowRequest::end_session && !quit_confirmation.confirm()) {
|
|
||||||
flow.reject_desk_action(english_game ? "Quit cancelled." : "Beenden abgebrochen.");
|
|
||||||
dirty = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Play the sounds the desk queued during this action.
|
|
||||||
if (const auto* desk = flow.desktop())
|
|
||||||
for (const auto id : desk->take_sound_ids()) app::original_audio_command(playback, id);
|
|
||||||
// Process timer: kickoff and quitting stop it; opening the menus 10, 11, 19 and 29
|
|
||||||
// (save/load, settings, new manager) pauses it.
|
|
||||||
if (r.request == ui::FlowRequest::kickoff || r.request == ui::FlowRequest::end_session) {
|
|
||||||
// DeskDate clears CareerSession_DispatchStrengths_ExecutableField2 before returning to the match caller.
|
|
||||||
process_timer.stop(); process_timer_owner.reset(); process_timer_frame.reset();
|
|
||||||
} else if (r.desk_action.kind == ui::DeskRequestKind::open_menu &&
|
|
||||||
(r.desk_action.menu_kind == 10 || r.desk_action.menu_kind == 11 ||
|
|
||||||
r.desk_action.menu_kind == 19 || r.desk_action.menu_kind == 29)) {
|
|
||||||
// ApplySettingsFile suspends save/load, settings and new-manager waits.
|
|
||||||
process_timer.pause(process_source_seconds()); process_timer_frame.reset();
|
|
||||||
}
|
|
||||||
// Confirmed quit: end the program at once, without advancing the calendar or saving.
|
|
||||||
if (r.request == ui::FlowRequest::end_session) {
|
|
||||||
// DeskDate's confirmed socket exit tears down the running
|
|
||||||
// session without a calendar turn, RNG draw, or implicit save.
|
|
||||||
running = false;
|
|
||||||
dirty = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dirty |= r.changed;
|
|
||||||
bool live_skipped = false;
|
|
||||||
uint64_t live_overview_sequence = 0;
|
|
||||||
std::optional<Image> outcome_backdrop;
|
std::optional<Image> outcome_backdrop;
|
||||||
|
|
||||||
// Live-match intervention: opens the lineup/pitch screen for the clicked team and runs it
|
// Live-match intervention: opens the lineup/pitch screen for the clicked team and runs it
|
||||||
// until closed. Returns true if the intervention was completed successfully.
|
// until closed. Returns true if the intervention was completed successfully.
|
||||||
auto present_live_lineup = [&](int minute, MatchEngine& engine, std::vector<MatchGroup>& groups,
|
auto present_live_lineup(int minute, MatchEngine& engine, std::vector<MatchGroup>& groups,
|
||||||
GameState& state, uint64_t& live_revision, int selected_team, int selected_opponent,
|
GameState& state, uint64_t& live_revision, int selected_team, int selected_opponent,
|
||||||
const app::LiveLineupDispatcher& dispatch, const app::LiveTacticsDispatcher& dispatch_tactic,
|
const app::LiveLineupDispatcher& dispatch, const app::LiveTacticsDispatcher& dispatch_tactic,
|
||||||
const app::LivePitchDispatcher& dispatch_pitch,
|
const app::LivePitchDispatcher& dispatch_pitch,
|
||||||
@@ -1227,14 +1197,16 @@ struct App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return completed;
|
return completed;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Callback type through which the overview screen asks the engine for its actions.
|
// Callback type through which the overview screen asks the engine for its actions.
|
||||||
using RunningOverviewDispatcher = std::function<std::optional<app::CareerSession::LiveOverviewDispatch>(
|
using RunningOverviewDispatcher = std::function<std::optional<app::CareerSession::LiveOverviewDispatch>(
|
||||||
const app::CareerSession::LiveOverviewAction&, std::string&,
|
const app::CareerSession::LiveOverviewAction&, std::string&,
|
||||||
const app::TransferOfferTeamInfoPresenter&)>;
|
const app::TransferOfferTeamInfoPresenter&)>;
|
||||||
|
|
||||||
// Presents the overview shown while the matchday is running (league table, other games,
|
// Presents the overview shown while the matchday is running (league table, other games,
|
||||||
// statistics) in its own loop, driven by the engine's overview dispatcher.
|
// statistics) in its own loop, driven by the engine's overview dispatcher.
|
||||||
const auto present_running_overview = [&](std::optional<app::CareerSession::LiveOverviewProjection> projection,
|
auto present_running_overview(std::optional<app::CareerSession::LiveOverviewProjection> projection,
|
||||||
const GameState& state, uint64_t& live_revision,
|
const GameState& state, uint64_t& live_revision,
|
||||||
const RunningOverviewDispatcher& dispatch_overview,
|
const RunningOverviewDispatcher& dispatch_overview,
|
||||||
const PhaseResultRequest* phase_result) {
|
const PhaseResultRequest* phase_result) {
|
||||||
@@ -1506,24 +1478,24 @@ struct App {
|
|||||||
if (!redrawn) SDL_Delay(8);
|
if (!redrawn) SDL_Delay(8);
|
||||||
}
|
}
|
||||||
return running && closed;
|
return running && closed;
|
||||||
};
|
}
|
||||||
|
|
||||||
// State used by the live-match presenters below.
|
// State used by the live-match presenters below.
|
||||||
ui::LiveScoreReveal live_score_reveal;
|
ui::LiveScoreReveal live_score_reveal;
|
||||||
|
|
||||||
std::optional<ui::LiveChanceProjection> live_chance_context;
|
std::optional<ui::LiveChanceProjection> live_chance_context;
|
||||||
|
|
||||||
std::unique_ptr<ui::RealityFieldScreen> reality_field;
|
std::unique_ptr<ui::RealityFieldScreen> reality_field;
|
||||||
|
|
||||||
ui::RealityReporterLayoutState reality_layout;
|
ui::RealityReporterLayoutState reality_layout;
|
||||||
|
|
||||||
Image reality_pristine, reality_surface;
|
Image reality_pristine, reality_surface;
|
||||||
|
|
||||||
Palette reality_colors;
|
Palette reality_colors;
|
||||||
// Hand the flow result to the controller. The arguments after the audio ones are the
|
|
||||||
// presenter callbacks the engine may call synchronously (live frame, incoming transfers,
|
|
||||||
// transfer decisions, season checkpoints, tax, highscore, promotion, cup draw, offers,
|
|
||||||
// club/player screens, notices, poaching, contracts, ...). The returned message is
|
|
||||||
// printed to stderr by the caller; "career_complete" ends the program.
|
|
||||||
const std::string message = app::serve_flow_request(flow, r, session, data, save_directory, seed, revision,
|
|
||||||
playback, audio_session, music_enabled,
|
|
||||||
// Callback per simulated match minute: shows the live matchday frame (unless skipped)
|
// Callback per simulated match minute: shows the live matchday frame (unless skipped)
|
||||||
// and waits frame_delay ms, taken from --live-frame-ms or from the game's own speed setting.
|
// and waits frame_delay ms, taken from --live-frame-ms or from the game's own speed setting.
|
||||||
[&](int minute, const std::vector<MatchGroup>& groups, const GameState& state) {
|
auto present_live_minute(int minute, const std::vector<MatchGroup>& groups, const GameState& state) {
|
||||||
if (!running) return;
|
if (!running) return;
|
||||||
bool live_frame_shown = false;
|
bool live_frame_shown = false;
|
||||||
if (!live_skipped) {
|
if (!live_skipped) {
|
||||||
@@ -1539,10 +1511,11 @@ struct App {
|
|||||||
int(ui::live_delay_milliseconds(state.memory.u8(::bmh::layout::Main_FormatError_ExecutableField)));
|
int(ui::live_delay_milliseconds(state.memory.u8(::bmh::layout::Main_FormatError_ExecutableField)));
|
||||||
if (live_frame_shown && !live_skipped && frame_delay > 0)
|
if (live_frame_shown && !live_skipped && frame_delay > 0)
|
||||||
SDL_Delay(Uint32(frame_delay));
|
SDL_Delay(Uint32(frame_delay));
|
||||||
},
|
}
|
||||||
|
|
||||||
// Callback for an incoming transfer offer: modal decision screen. Returns the chosen bid
|
// Callback for an incoming transfer offer: modal decision screen. Returns the chosen bid
|
||||||
// index, or -1 for decline, nothing to choose or quit.
|
// index, or -1 for decline, nothing to choose or quit.
|
||||||
[&](const GameState& state, const TransferOfferListView& offers) -> int {
|
auto choose_transfer_offer(const GameState& state, const TransferOfferListView& offers) -> int {
|
||||||
if (!running) return -1;
|
if (!running) return -1;
|
||||||
auto view = transfer_view(state, offers, offers.seller_manager);
|
auto view = transfer_view(state, offers, offers.seller_manager);
|
||||||
ui::IncomingTransferScreen offer_screen(data,
|
ui::IncomingTransferScreen offer_screen(data,
|
||||||
@@ -1590,10 +1563,11 @@ struct App {
|
|||||||
SDL_Delay(10);
|
SDL_Delay(10);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
},
|
}
|
||||||
|
|
||||||
// Callback that presents a transfer decision already settled by the engine: last-week
|
// Callback that presents a transfer decision already settled by the engine: last-week
|
||||||
// dialog, confirmation, or the animated evaluation of the bids. Clicks cannot change it.
|
// dialog, confirmation, or the animated evaluation of the bids. Clicks cannot change it.
|
||||||
[&](const GameState& state, const TransferDecisionEvent& decision) {
|
auto present_transfer_decision(const GameState& state, const TransferDecisionEvent& decision) {
|
||||||
if (!running) return;
|
if (!running) return;
|
||||||
if (decision.kind == TransferDecisionEventKind::last_week) {
|
if (decision.kind == TransferDecisionEventKind::last_week) {
|
||||||
auto view = ui::transfer_last_week_dialog(state, decision);
|
auto view = ui::transfer_last_week_dialog(state, decision);
|
||||||
@@ -1655,10 +1629,11 @@ struct App {
|
|||||||
if (confirmation ? decision_screen.confirmation_dismissed() : decision_screen.outcome_dismissed()) return;
|
if (confirmation ? decision_screen.confirmation_dismissed() : decision_screen.outcome_dismissed()) return;
|
||||||
SDL_Delay(10);
|
SDL_Delay(10);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// Callback at season-transition checkpoints; only the one for the German entrants does
|
// Callback at season-transition checkpoints; only the one for the German entrants does
|
||||||
// anything: it shows the entrant screens, each closed by a mouse release.
|
// anything: it shows the entrant screens, each closed by a mouse release.
|
||||||
[&](const char* checkpoint, const GameState& state) {
|
auto present_season_checkpoint(const char* checkpoint, const GameState& state) {
|
||||||
if (!running || std::strcmp(checkpoint, "the German entrants (CompetitionWinnerScreen)") != 0) return;
|
if (!running || std::strcmp(checkpoint, "the German entrants (CompetitionWinnerScreen)") != 0) return;
|
||||||
// SeasonEntrantsFromGame / CompetitionWinnerScreen: show the three owned Original
|
// SeasonEntrantsFromGame / CompetitionWinnerScreen: show the three owned Original
|
||||||
// projections while the transition is suspended at its checkpoint.
|
// projections while the transition is suspended at its checkpoint.
|
||||||
@@ -1682,28 +1657,22 @@ struct App {
|
|||||||
if (!dismissed) SDL_Delay(10);
|
if (!dismissed) SDL_Delay(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Further callbacks: tax, highscore, promotion and cup draw presenters (defined above).
|
}
|
||||||
}, tax_presenter, [this](auto&&... a) -> decltype(auto) { return show_highscore(std::forward<decltype(a)>(a)...); }, promotion_presenter, cup_draw_presenter,
|
|
||||||
// Pending-offer hooks exist only for kickoff; market sale hooks for kickoff and for
|
|
||||||
// transfer market / outgoing transfer submenu actions.
|
|
||||||
r.request == ui::FlowRequest::kickoff
|
|
||||||
? make_pending_offer_hooks(flow.render()) : PendingOfferHooks{},
|
|
||||||
app::PendingOfferEntryPolicy::normal_interactive,
|
|
||||||
(r.request == ui::FlowRequest::kickoff || (r.request == ui::FlowRequest::submenu_action &&
|
|
||||||
(std::holds_alternative<ui::TransferMarketRequest>(r.submenu_action) ||
|
|
||||||
std::holds_alternative<ui::OutgoingTransferRequest>(r.submenu_action))
|
|
||||||
)) ? make_market_sale_hooks(flow.render()) : HumanBuyerSaleHooks{},
|
|
||||||
app::HumanBuyerMarketEntryPolicy::normal_interactive,
|
|
||||||
// Callback: club information screen (true if the program is still running).
|
// Callback: club information screen (true if the program is still running).
|
||||||
[&](app::ClubModalServices& services,int team,const Image&) {
|
auto show_club_information(app::ClubModalServices& services,int team,const Image&) {
|
||||||
return present_club_information(services,team) && running;
|
return present_club_information(services,team) && running;
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: player detail card.
|
// Next callback: player detail card.
|
||||||
}, [&](app::ClubModalServices& services,const ClubPlayerDetailSelection& selection,const Image& parent) {
|
auto show_player_detail(app::ClubModalServices& services,const ClubPlayerDetailSelection& selection,const Image& parent) {
|
||||||
// Direct1b556 already owns persistent bbcde=1. The shared
|
// Direct1b556 already owns persistent bbcde=1. The shared
|
||||||
//ClubPlayerDetailFromGame presenter never restores a temporary club mode here.
|
//ClubPlayerDetailFromGame presenter never restores a temporary club mode here.
|
||||||
return present_player_detail(services,selection,parent).has_value() && running;
|
return present_player_detail(services,selection,parent).has_value() && running;
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: stadium construction payment notice, shown over the investment detail.
|
// Next callback: stadium construction payment notice, shown over the investment detail.
|
||||||
}, [&](const GameState& staged, const ConstructionNotice& notice) {
|
auto present_construction_notice(const GameState& staged, const ConstructionNotice& notice) {
|
||||||
if (!flow.stadium()) throw std::runtime_error("construction notice has no stadium owner");
|
if (!flow.stadium()) throw std::runtime_error("construction notice has no stadium owner");
|
||||||
// The Original payment notices restore the investment detail,
|
// The Original payment notices restore the investment detail,
|
||||||
// after the tip question has returned, before the outer ACK.
|
// after the tip question has returned, before the outer ACK.
|
||||||
@@ -1719,8 +1688,10 @@ struct App {
|
|||||||
? "OpenBMH - stadium_funds_notice" : "OpenBMH - stadium_sponsor_notice";
|
? "OpenBMH - stadium_funds_notice" : "OpenBMH - stadium_sponsor_notice";
|
||||||
if (present_pending_dialog(staged, view, backdrop, title, effective_options) == PendingOfferAnswer::unsupported)
|
if (present_pending_dialog(staged, view, backdrop, title, effective_options) == PendingOfferAnswer::unsupported)
|
||||||
throw std::runtime_error("construction notice presenter stopped");
|
throw std::runtime_error("construction notice presenter stopped");
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: season ticket compensation notice.
|
// Next callback: season ticket compensation notice.
|
||||||
}, [&](const GameState& staged, const SeasonTicketCompensationNotice& notice) {
|
auto present_ticket_compensation_notice(const GameState& staged, const SeasonTicketCompensationNotice& notice) {
|
||||||
if (!flow.stadium()) throw std::runtime_error("compensation notice has no stadium owner");
|
if (!flow.stadium()) throw std::runtime_error("compensation notice has no stadium owner");
|
||||||
const Image backdrop = flow.stadium()->construction_notice_backdrop();
|
const Image backdrop = flow.stadium()->construction_notice_backdrop();
|
||||||
auto view = ui::season_ticket_compensation_notice_dialog(staged, season_exe, notice);
|
auto view = ui::season_ticket_compensation_notice_dialog(staged, season_exe, notice);
|
||||||
@@ -1730,11 +1701,11 @@ struct App {
|
|||||||
"OpenBMH - stadium_ticket_compensation_notice",
|
"OpenBMH - stadium_ticket_compensation_notice",
|
||||||
ui::GameEndRenderOptions{owner.plain_background, owner.gradient_text}) == PendingOfferAnswer::unsupported)
|
ui::GameEndRenderOptions{owner.plain_background, owner.gradient_text}) == PendingOfferAnswer::unsupported)
|
||||||
throw std::runtime_error("compensation notice presenter stopped");
|
throw std::runtime_error("compensation notice presenter stopped");
|
||||||
}, sportschau_presenter,
|
}
|
||||||
|
|
||||||
// Callback: advertising contract renewal. A question gives renew/decline; a sponsor's
|
// Callback: advertising contract renewal. A question gives renew/decline; a sponsor's
|
||||||
// refusal is a notice that gives acknowledged; anything else aborts.
|
// refusal is a notice that gives acknowledged; anything else aborts.
|
||||||
[&](const GameState& staged, const AdvertisingRenewal& renewal, const Image& backdrop)
|
auto ask_advertising_renewal(const GameState& staged, const AdvertisingRenewal& renewal, const Image& backdrop) -> app::CareerSession::AdvertisingRenewalPresentation {
|
||||||
-> app::CareerSession::AdvertisingRenewalPresentation {
|
|
||||||
if (!running) return app::CareerSession::AdvertisingRenewalPresentation::abort;
|
if (!running) return app::CareerSession::AdvertisingRenewalPresentation::abort;
|
||||||
const int manager = int(staged.memory.u8(::bmh::layout::ActiveManager));
|
const int manager = int(staged.memory.u8(::bmh::layout::ActiveManager));
|
||||||
if (renewal.status == AdvertisingRenewal::Status::offered) {
|
if (renewal.status == AdvertisingRenewal::Status::offered) {
|
||||||
@@ -1752,18 +1723,19 @@ struct App {
|
|||||||
return app::CareerSession::AdvertisingRenewalPresentation::acknowledged;
|
return app::CareerSession::AdvertisingRenewalPresentation::acknowledged;
|
||||||
}
|
}
|
||||||
return app::CareerSession::AdvertisingRenewalPresentation::abort;
|
return app::CareerSession::AdvertisingRenewalPresentation::abort;
|
||||||
}, poach_player_selector,
|
}
|
||||||
|
|
||||||
// Callback: shows the poaching attempt's notices one after another.
|
// Callback: shows the poaching attempt's notices one after another.
|
||||||
[&](const GameState& staged,const PoachStart& attempt,const Image& backdrop) {
|
auto present_poach_notices(const GameState& staged,const PoachStart& attempt,const Image& backdrop) {
|
||||||
for(const auto& message:attempt.messages)
|
for(const auto& message:attempt.messages)
|
||||||
if(present_pending_dialog(staged,ui::poach_notice_from_game(staged,attempt,message),backdrop,
|
if(present_pending_dialog(staged,ui::poach_notice_from_game(staged,attempt,message),backdrop,
|
||||||
"OpenBMH - poach_notice")==PendingOfferAnswer::unsupported)
|
"OpenBMH - poach_notice")==PendingOfferAnswer::unsupported)
|
||||||
throw FormatError("poach: notice presenter stopped");
|
throw FormatError("poach: notice presenter stopped");
|
||||||
}, [this](auto&&... a) -> decltype(auto) { return contract_expiry_presenter(std::forward<decltype(a)>(a)...); },
|
}
|
||||||
|
|
||||||
// Callback: national friendly question. Returns yes/no, or std::nullopt when unsupported
|
// Callback: national friendly question. Returns yes/no, or std::nullopt when unsupported
|
||||||
// or the program is quitting.
|
// or the program is quitting.
|
||||||
[&](const GameState& staged,ui::TaxDialogProjection view,const Image& backdrop)
|
auto ask_national_friendly(const GameState& staged,ui::TaxDialogProjection view,const Image& backdrop) ->std::optional<bool> {
|
||||||
->std::optional<bool> {
|
|
||||||
if(!running)return {};
|
if(!running)return {};
|
||||||
const auto answer=present_pending_dialog(staged,std::move(view),backdrop,
|
const auto answer=present_pending_dialog(staged,std::move(view),backdrop,
|
||||||
"OpenBMH - national_friendly_question");
|
"OpenBMH - national_friendly_question");
|
||||||
@@ -1773,8 +1745,8 @@ struct App {
|
|||||||
press.reset();
|
press.reset();
|
||||||
if(answer==PendingOfferAnswer::unsupported)return {};
|
if(answer==PendingOfferAnswer::unsupported)return {};
|
||||||
return answer==PendingOfferAnswer::yes;
|
return answer==PendingOfferAnswer::yes;
|
||||||
// The loan-return presenters (defined above), then the live match observer.
|
}
|
||||||
}, [this](auto&&... a) -> decltype(auto) { return loan_return_presenter(std::forward<decltype(a)>(a)...); }, [this](auto&&... a) -> decltype(auto) { return loan_return_offer_presenter(std::forward<decltype(a)>(a)...); },
|
|
||||||
// =====================================================================================
|
// =====================================================================================
|
||||||
// Live match observer
|
// Live match observer
|
||||||
// =====================================================================================
|
// =====================================================================================
|
||||||
@@ -1783,7 +1755,7 @@ struct App {
|
|||||||
// keys for overview/table/settings open their modal screens (key letters come from the
|
// keys for overview/table/settings open their modal screens (key letters come from the
|
||||||
// game executable), clicks on the top strip open an overview or the settings, and clicks
|
// game executable), clicks on the top strip open an overview or the settings, and clicks
|
||||||
// on the scoreboard rows open the lineup (left) or tactics (right) of that team.
|
// on the scoreboard rows open the lineup (left) or tactics (right) of that team.
|
||||||
[&](int minute, MatchEngine& engine, std::vector<MatchGroup>& groups,
|
auto observe_live_minute(int minute, MatchEngine& engine, std::vector<MatchGroup>& groups,
|
||||||
GameState& state, uint64_t& live_revision,
|
GameState& state, uint64_t& live_revision,
|
||||||
const app::LiveLineupDispatcher& dispatch,
|
const app::LiveLineupDispatcher& dispatch,
|
||||||
const app::LiveTacticsDispatcher& dispatch_tactic,
|
const app::LiveTacticsDispatcher& dispatch_tactic,
|
||||||
@@ -2284,9 +2256,11 @@ struct App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (quit) running = false;
|
if (quit) running = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: environment/settings notice dialog. Returns false when the program is
|
// Next callback: environment/settings notice dialog. Returns false when the program is
|
||||||
// quitting or the dialog could not be shown.
|
// quitting or the dialog could not be shown.
|
||||||
}, [&](const GameState& staged, ui::TaxDialogProjection view, const Image& backdrop) {
|
auto present_environment_notice(const GameState& staged, ui::TaxDialogProjection view, const Image& backdrop) {
|
||||||
if (!running) return false;
|
if (!running) return false;
|
||||||
const bool settings_notice = flow.in_settings() && flow.pending_settings();
|
const bool settings_notice = flow.in_settings() && flow.pending_settings();
|
||||||
const bool shown = present_pending_dialog(staged, std::move(view), backdrop,
|
const bool shown = present_pending_dialog(staged, std::move(view), backdrop,
|
||||||
@@ -2298,9 +2272,11 @@ struct App {
|
|||||||
SDL_FlushEvents(SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP);
|
SDL_FlushEvents(SDL_MOUSEMOTION, SDL_MOUSEBUTTONUP);
|
||||||
}
|
}
|
||||||
return shown;
|
return shown;
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: a lineup change forced by a live match event; runs the same lineup
|
// Next callback: a lineup change forced by a live match event; runs the same lineup
|
||||||
// screen as the click on the scoreboard. It must complete unless the program quits.
|
// screen as the click on the scoreboard. It must complete unless the program quits.
|
||||||
}, [&](const LiveMatchEvent& event, MatchEngine& engine,
|
auto present_live_event_lineup(const LiveMatchEvent& event, MatchEngine& engine,
|
||||||
std::vector<MatchGroup>& groups, GameState& state, uint64_t& live_revision,
|
std::vector<MatchGroup>& groups, GameState& state, uint64_t& live_revision,
|
||||||
const app::LiveLineupDispatcher& dispatch,
|
const app::LiveLineupDispatcher& dispatch,
|
||||||
const app::LiveTacticsDispatcher& dispatch_tactic,
|
const app::LiveTacticsDispatcher& dispatch_tactic,
|
||||||
@@ -2313,6 +2289,8 @@ struct App {
|
|||||||
if (!running) return; // SDL_QUIT aborts the Source scope without failing the event.
|
if (!running) return; // SDL_QUIT aborts the Source scope without failing the event.
|
||||||
if (!completed)
|
if (!completed)
|
||||||
throw FormatError("The Source event line-up did not complete.");
|
throw FormatError("The Source event line-up did not complete.");
|
||||||
|
}
|
||||||
|
|
||||||
// =====================================================================================
|
// =====================================================================================
|
||||||
// Live match animation callbacks
|
// Live match animation callbacks
|
||||||
// =====================================================================================
|
// =====================================================================================
|
||||||
@@ -2323,7 +2301,7 @@ struct App {
|
|||||||
// input stays queued for the per-minute observer.
|
// input stays queued for the per-minute observer.
|
||||||
//
|
//
|
||||||
// Callback: ball movement frames of one displacement.
|
// Callback: ball movement frames of one displacement.
|
||||||
}, [&](const LiveBallEvent& event, const std::vector<MatchGroup>& groups,
|
auto animate_ball(const LiveBallEvent& event, const std::vector<MatchGroup>& groups,
|
||||||
const GameState& state) {
|
const GameState& state) {
|
||||||
if (!running || live_skipped) return;
|
if (!running || live_skipped) return;
|
||||||
const auto frame = live_score_reveal.project(ui::live_matchday_frame(event.minute, groups, state));
|
const auto frame = live_score_reveal.project(ui::live_matchday_frame(event.minute, groups, state));
|
||||||
@@ -2367,8 +2345,10 @@ struct App {
|
|||||||
SDL_SetWindowTitle(window, "OpenBMH - live_matchday");
|
SDL_SetWindowTitle(window, "OpenBMH - live_matchday");
|
||||||
present(live_screen.render(frame));
|
present(live_screen.render(frame));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: a scoring chance, shown as a preview and again as its result.
|
// Next callback: a scoring chance, shown as a preview and again as its result.
|
||||||
}, [&](const LiveChanceEvent& event, const std::vector<MatchGroup>& groups,
|
auto animate_chance(const LiveChanceEvent& event, const std::vector<MatchGroup>& groups,
|
||||||
const GameState& state) {
|
const GameState& state) {
|
||||||
if (!running || live_skipped) return;
|
if (!running || live_skipped) return;
|
||||||
// Preview: the chance is already in the event log, but its statistics must not count yet.
|
// Preview: the chance is already in the event log, but its statistics must not count yet.
|
||||||
@@ -2402,9 +2382,11 @@ struct App {
|
|||||||
(saved < 6 ? saved / 2 : saved) * 20;
|
(saved < 6 ? saved / 2 : saved) * 20;
|
||||||
if (delay > 0) SDL_Delay(Uint32(delay));
|
if (delay > 0) SDL_Delay(Uint32(delay));
|
||||||
if (event.stage == LiveChanceStage::result) live_chance_context.reset();
|
if (event.stage == LiveChanceStage::result) live_chance_context.reset();
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: shot animation, drawn with the shot's own palette. After the frames it
|
// Next callback: shot animation, drawn with the shot's own palette. After the frames it
|
||||||
// either waits for a click or applies the saved pause.
|
// either waits for a click or applies the saved pause.
|
||||||
}, [&](const LiveShotEvent& event, const std::vector<MatchGroup>& groups,
|
auto animate_shot(const LiveShotEvent& event, const std::vector<MatchGroup>& groups,
|
||||||
const GameState& state) {
|
const GameState& state) {
|
||||||
if (!running || live_skipped) return;
|
if (!running || live_skipped) return;
|
||||||
const auto frame = live_score_reveal.project(ui::live_matchday_frame(event.minute, groups, state));
|
const auto frame = live_score_reveal.project(ui::live_matchday_frame(event.minute, groups, state));
|
||||||
@@ -2458,8 +2440,10 @@ struct App {
|
|||||||
const int delay = live_frame_ms_explicit ? live_frame_ms : (saved < 6 ? saved / 2 : saved) * 20;
|
const int delay = live_frame_ms_explicit ? live_frame_ms : (saved < 6 ? saved / 2 : saved) * 20;
|
||||||
if (delay > 0) SDL_Delay(Uint32(delay));
|
if (delay > 0) SDL_Delay(Uint32(delay));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: set piece animation frames (first frame held 40 retraces at 70 Hz).
|
// Next callback: set piece animation frames (first frame held 40 retraces at 70 Hz).
|
||||||
}, [&](const LiveSetPieceEvent& event, const std::vector<MatchGroup>& groups,
|
auto animate_set_piece(const LiveSetPieceEvent& event, const std::vector<MatchGroup>& groups,
|
||||||
const GameState& state) {
|
const GameState& state) {
|
||||||
if (!running || live_skipped) return;
|
if (!running || live_skipped) return;
|
||||||
const auto frame=live_score_reveal.project(ui::live_matchday_frame(event.minute,groups,state));
|
const auto frame=live_score_reveal.project(ui::live_matchday_frame(event.minute,groups,state));
|
||||||
@@ -2484,8 +2468,10 @@ struct App {
|
|||||||
if (delay>0) SDL_Delay(Uint32(delay));
|
if (delay>0) SDL_Delay(Uint32(delay));
|
||||||
}
|
}
|
||||||
if (running && !live_frame_ms_explicit) SDL_Delay(200); // LiveMatchdayFrame
|
if (running && !live_frame_ms_explicit) SDL_Delay(200); // LiveMatchdayFrame
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: booking/injury box; pause row 3 for kind 0, otherwise 4.
|
// Next callback: booking/injury box; pause row 3 for kind 0, otherwise 4.
|
||||||
}, [&](const LiveBookingEvent& event, const std::vector<MatchGroup>& groups,
|
auto animate_booking(const LiveBookingEvent& event, const std::vector<MatchGroup>& groups,
|
||||||
const GameState& state) {
|
const GameState& state) {
|
||||||
if (!running || live_skipped) return;
|
if (!running || live_skipped) return;
|
||||||
const auto frame=ui::live_matchday_frame(event.minute,groups,state);
|
const auto frame=ui::live_matchday_frame(event.minute,groups,state);
|
||||||
@@ -2509,9 +2495,11 @@ struct App {
|
|||||||
if (delay>0) SDL_Delay(Uint32(delay));
|
if (delay>0) SDL_Delay(Uint32(delay));
|
||||||
// EventImpl clears the box after its pause; no Source click wait here.
|
// EventImpl clears the box after its pause; no Source click wait here.
|
||||||
SDL_SetWindowTitle(window,"OpenBMH - live_matchday");present(live_screen.render(frame));
|
SDL_SetWindowTitle(window,"OpenBMH - live_matchday");present(live_screen.render(frame));
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: penalty shootout step; the saved pause is repeated 4 times for the
|
// Next callback: penalty shootout step; the saved pause is repeated 4 times for the
|
||||||
// preview and twice for the result.
|
// preview and twice for the result.
|
||||||
}, [&](const LiveShootoutEvent& event, const std::vector<MatchGroup>& groups,
|
auto animate_shootout(const LiveShootoutEvent& event, const std::vector<MatchGroup>& groups,
|
||||||
const GameState& state) {
|
const GameState& state) {
|
||||||
if (!running || live_skipped) return;
|
if (!running || live_skipped) return;
|
||||||
const auto frame=ui::live_matchday_frame(event.minute,groups,state);
|
const auto frame=ui::live_matchday_frame(event.minute,groups,state);
|
||||||
@@ -2530,10 +2518,12 @@ struct App {
|
|||||||
const int saved=state.memory.has(::bmh::layout::Main_FormatError_RuntimeField6)?state.memory.u8(::bmh::layout::Main_FormatError_RuntimeField6):0;
|
const int saved=state.memory.has(::bmh::layout::Main_FormatError_RuntimeField6)?state.memory.u8(::bmh::layout::Main_FormatError_RuntimeField6):0;
|
||||||
const int delay=live_frame_ms_explicit?live_frame_ms:(saved<6?saved/2:saved)*20;
|
const int delay=live_frame_ms_explicit?live_frame_ms:(saved<6?saved/2:saved)*20;
|
||||||
for (int i=0;i<repeats && running;++i) if (delay>0) SDL_Delay(Uint32(delay));
|
for (int i=0;i<repeats && running;++i) if (delay>0) SDL_Delay(Uint32(delay));
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: reality mode (running commentary with a moving field). Stages: begin
|
// Next callback: reality mode (running commentary with a moving field). Stages: begin
|
||||||
// (builds the screens), one call per round, settling and end. Returns true when the
|
// (builds the screens), one call per round, settling and end. Returns true when the
|
||||||
// player ended it with ESC or a right press, or when the program quits.
|
// player ended it with ESC or a right press, or when the program quits.
|
||||||
}, [&](const LiveRealityEvent& event, const std::vector<MatchGroup>& groups,
|
auto present_reality(const LiveRealityEvent& event, const std::vector<MatchGroup>& groups,
|
||||||
const GameState& state) -> bool {
|
const GameState& state) -> bool {
|
||||||
if (!running || live_skipped) return false;
|
if (!running || live_skipped) return false;
|
||||||
const auto frame = ui::live_matchday_frame(event.minute,groups,state);
|
const auto frame = ui::live_matchday_frame(event.minute,groups,state);
|
||||||
@@ -2604,9 +2594,11 @@ struct App {
|
|||||||
quit_confirmation.peep(&input,1,SDL_GETEVENT,SDL_MOUSEBUTTONDOWN,SDL_MOUSEBUTTONDOWN);return true;
|
quit_confirmation.peep(&input,1,SDL_GETEVENT,SDL_MOUSEBUTTONDOWN,SDL_MOUSEBUTTONDOWN);return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Next callback: results viewer at the end of a match phase; throws if it was stopped
|
// Next callback: results viewer at the end of a match phase; throws if it was stopped
|
||||||
// before being acknowledged.
|
// before being acknowledged.
|
||||||
}, [&](const PhaseResultRequest& request, const std::vector<MatchGroup>& groups,
|
auto present_phase_result(const PhaseResultRequest& request, const std::vector<MatchGroup>& groups,
|
||||||
const GameState& state) {
|
const GameState& state) {
|
||||||
if (!running) throw FormatError("phase results: presentation stopped");
|
if (!running) throw FormatError("phase results: presentation stopped");
|
||||||
const auto frame = ui::live_matchday_frame(request.phase_end_minute, groups, state);
|
const auto frame = ui::live_matchday_frame(request.phase_end_minute, groups, state);
|
||||||
@@ -2619,7 +2611,98 @@ struct App {
|
|||||||
return session->dispatch_phase_results(action, revision, dispatch_error, team_info);
|
return session->dispatch_phase_results(action, revision, dispatch_error, team_info);
|
||||||
}, &request);
|
}, &request);
|
||||||
if (!closed) throw FormatError("phase results: viewer stopped before Source ACK");
|
if (!closed) throw FormatError("phase results: viewer stopped before Source ACK");
|
||||||
}, true);
|
}
|
||||||
|
|
||||||
|
// =====================================================================================
|
||||||
|
// Handling FlowResults (requests from the UI flow)
|
||||||
|
// =====================================================================================
|
||||||
|
// Called by the main loop for every ui::FlowResult. It handles quitting and the process
|
||||||
|
// timer, then passes the request to app::serve_flow_request() together with the
|
||||||
|
// presenter lambdas defined inside, which the engine may call back synchronously.
|
||||||
|
auto handle(const ui::FlowResult& r) {
|
||||||
|
pitch_pointer.show({}, renderer);
|
||||||
|
// A quit request must be confirmed by the player; otherwise the desk reports it as cancelled.
|
||||||
|
if (r.request == ui::FlowRequest::end_session && !quit_confirmation.confirm()) {
|
||||||
|
flow.reject_desk_action(english_game ? "Quit cancelled." : "Beenden abgebrochen.");
|
||||||
|
dirty = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Play the sounds the desk queued during this action.
|
||||||
|
if (const auto* desk = flow.desktop())
|
||||||
|
for (const auto id : desk->take_sound_ids()) app::original_audio_command(playback, id);
|
||||||
|
// Process timer: kickoff and quitting stop it; opening the menus 10, 11, 19 and 29
|
||||||
|
// (save/load, settings, new manager) pauses it.
|
||||||
|
if (r.request == ui::FlowRequest::kickoff || r.request == ui::FlowRequest::end_session) {
|
||||||
|
// DeskDate clears CareerSession_DispatchStrengths_ExecutableField2 before returning to the match caller.
|
||||||
|
process_timer.stop(); process_timer_owner.reset(); process_timer_frame.reset();
|
||||||
|
} else if (r.desk_action.kind == ui::DeskRequestKind::open_menu &&
|
||||||
|
(r.desk_action.menu_kind == 10 || r.desk_action.menu_kind == 11 ||
|
||||||
|
r.desk_action.menu_kind == 19 || r.desk_action.menu_kind == 29)) {
|
||||||
|
// ApplySettingsFile suspends save/load, settings and new-manager waits.
|
||||||
|
process_timer.pause(process_source_seconds()); process_timer_frame.reset();
|
||||||
|
}
|
||||||
|
// Confirmed quit: end the program at once, without advancing the calendar or saving.
|
||||||
|
if (r.request == ui::FlowRequest::end_session) {
|
||||||
|
// DeskDate's confirmed socket exit tears down the running
|
||||||
|
// session without a calendar turn, RNG draw, or implicit save.
|
||||||
|
running = false;
|
||||||
|
dirty = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dirty |= r.changed;
|
||||||
|
live_skipped = false; // (a member now; fresh for every request like the former local)
|
||||||
|
live_overview_sequence = 0; // (a member now; fresh for every request like the former local)
|
||||||
|
outcome_backdrop = std::optional<Image>{}; // (a member now; fresh for every request like the former local)
|
||||||
|
// State used by the live-match presenters below.
|
||||||
|
live_score_reveal = ui::LiveScoreReveal{}; // (a member now; fresh for every request like the former local)
|
||||||
|
live_chance_context = std::optional<ui::LiveChanceProjection>{}; // (a member now; fresh for every request like the former local)
|
||||||
|
reality_field.reset(); // (a member now; fresh for every request like the former local)
|
||||||
|
reality_layout = ui::RealityReporterLayoutState{}; // (a member now; fresh for every request like the former local)
|
||||||
|
reality_pristine = Image{}; reality_surface = Image{}; // (a member now; fresh for every request like the former local)
|
||||||
|
reality_colors = Palette{}; // (a member now; fresh for every request like the former local)
|
||||||
|
// Hand the flow result to the controller. The arguments after the audio ones are the
|
||||||
|
// presenter callbacks the engine may call synchronously (live frame, incoming transfers,
|
||||||
|
// transfer decisions, season checkpoints, tax, highscore, promotion, cup draw, offers,
|
||||||
|
// club/player screens, notices, poaching, contracts, ...). The returned message is
|
||||||
|
// printed to stderr by the caller; "career_complete" ends the program.
|
||||||
|
const std::string message = app::serve_flow_request(flow, r, session, data, save_directory, seed, revision,
|
||||||
|
playback, audio_session, music_enabled,
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return present_live_minute(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return choose_transfer_offer(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return present_transfer_decision(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return present_season_checkpoint(std::forward<decltype(a)>(a)...); },
|
||||||
|
// Further callbacks: tax, highscore, promotion and cup draw presenters (defined above).
|
||||||
|
tax_presenter, [this](auto&&... a) -> decltype(auto) { return show_highscore(std::forward<decltype(a)>(a)...); }, promotion_presenter, cup_draw_presenter,
|
||||||
|
// Pending-offer hooks exist only for kickoff; market sale hooks for kickoff and for
|
||||||
|
// transfer market / outgoing transfer submenu actions.
|
||||||
|
r.request == ui::FlowRequest::kickoff
|
||||||
|
? make_pending_offer_hooks(flow.render()) : PendingOfferHooks{},
|
||||||
|
app::PendingOfferEntryPolicy::normal_interactive,
|
||||||
|
(r.request == ui::FlowRequest::kickoff || (r.request == ui::FlowRequest::submenu_action &&
|
||||||
|
(std::holds_alternative<ui::TransferMarketRequest>(r.submenu_action) ||
|
||||||
|
std::holds_alternative<ui::OutgoingTransferRequest>(r.submenu_action))
|
||||||
|
)) ? make_market_sale_hooks(flow.render()) : HumanBuyerSaleHooks{},
|
||||||
|
app::HumanBuyerMarketEntryPolicy::normal_interactive,
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return show_club_information(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return show_player_detail(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return present_construction_notice(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return present_ticket_compensation_notice(std::forward<decltype(a)>(a)...); }, sportschau_presenter,
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return ask_advertising_renewal(std::forward<decltype(a)>(a)...); }, poach_player_selector,
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return present_poach_notices(std::forward<decltype(a)>(a)...); }, [this](auto&&... a) -> decltype(auto) { return contract_expiry_presenter(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return ask_national_friendly(std::forward<decltype(a)>(a)...); },
|
||||||
|
// The loan-return presenters (defined above), then the live match observer.
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return loan_return_presenter(std::forward<decltype(a)>(a)...); }, [this](auto&&... a) -> decltype(auto) { return loan_return_offer_presenter(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return observe_live_minute(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return present_environment_notice(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return present_live_event_lineup(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return animate_ball(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return animate_chance(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return animate_shot(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return animate_set_piece(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return animate_booking(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return animate_shootout(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return present_reality(std::forward<decltype(a)>(a)...); },
|
||||||
|
[this](auto&&... a) -> decltype(auto) { return present_phase_result(std::forward<decltype(a)>(a)...); }, true);
|
||||||
// In -debug mode every request and its outcome is logged.
|
// In -debug mode every request and its outcome is logged.
|
||||||
if (app::debug::enabled()) app::debug::log("request " + std::to_string(int(r.request)) + (message.empty() ? std::string(" ok") : " -> " + message));
|
if (app::debug::enabled()) app::debug::log("request " + std::to_string(int(r.request)) + (message.empty() ? std::string(" ok") : " -> " + message));
|
||||||
// The controller reports the end of the career by this message: leave the main loop.
|
// The controller reports the end of the career by this message: leave the main loop.
|
||||||
|
|||||||
Reference in new issue
Block a user