diff --git a/docs/release/1.0.9/RELEASE_NOTES.md b/docs/release/1.0.9/RELEASE_NOTES.md index c4aa796..cc1e847 100644 --- a/docs/release/1.0.9/RELEASE_NOTES.md +++ b/docs/release/1.0.9/RELEASE_NOTES.md @@ -28,6 +28,10 @@ compared with the engine; every difference found was ported and documented. was inverted in the port (older players were recycled the wrong way round); this is fixed. - **Season end.** Retirement and leave rules for the player slots. +- **Live match statistics.** The chance counters at the bottom of the live + matchday screen counted a chance as soon as the engine logged it, before the + presentation started. They are now held back like the score and appear with + the result of the chance. ## What was measured, what was derived @@ -47,9 +51,9 @@ in the source as a known gap). ## Open points -Reported by the Diamond author and not changed here: bug in "fetch player from -transfer market / check offers", and the chance counters at the bottom of the -match screen count up slightly too early. Earlier open points remain: the +Reported by the Diamond author and not changed here: the bug in "fetch player +from transfer market / check offers" (exact steps still to be reproduced). +Earlier open points remain: the "player card: original atlas bounds" error (#77), sporadic double clicks (#58) and the macOS match scene speed (#70). diff --git a/src/app/main.cpp b/src/app/main.cpp index 0054132..91c4d6f 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -3291,7 +3291,10 @@ int main(int argc, char** argv) { }, [&](const LiveChanceEvent& event, const std::vector& groups, const GameState& state) { if (!running || live_skipped) return; - const auto frame = ui::live_matchday_frame(event.minute, groups, state); + // Preview: the chance is already in the event log, but its statistics must not count yet. + const auto frame = event.stage == LiveChanceStage::preview + ? ui::live_matchday_frame_before_chance(event.minute, groups, state, event) + : ui::live_matchday_frame(event.minute, groups, state); live_score_reveal.observe(event.stage, frame); if (frame.matches.empty()) return; const auto chance = ui::live_chance_projection(event, groups, state, season_exe); diff --git a/src/ui/live_matchday.cpp b/src/ui/live_matchday.cpp index 3c14470..114ae10 100644 --- a/src/ui/live_matchday.cpp +++ b/src/ui/live_matchday.cpp @@ -140,6 +140,18 @@ LiveMatchdayFrame live_matchday_frame(int minute, const std::vector& return frame; } +LiveMatchdayFrame live_matchday_frame_before_chance(int minute, const std::vector& groups, + const GameState& state, const LiveChanceEvent& event) { + // MatchEngine::chance writes two log pairs (outcome, then kind/distance) = 4 words before the preview hook. + // The copy is small: chances are rare and only the log of one group is shortened. + if (event.group < 0 || size_t(event.group) >= groups.size() || groups[size_t(event.group)].log.size() < 4) + return live_matchday_frame(minute, groups, state); + std::vector before = groups; + auto& log = before[size_t(event.group)].log; + log.resize(log.size() - 4); + return live_matchday_frame(minute, before, state); +} + LiveChanceProjection live_chance_projection(const LiveChanceEvent& event, const std::vector& groups, const GameState& state, const LeImage& exe) { if (event.group < 0 || size_t(event.group) >= groups.size() || event.match < 0 || diff --git a/src/ui/live_matchday.hpp b/src/ui/live_matchday.hpp index 47f250e..6ce5641 100644 --- a/src/ui/live_matchday.hpp +++ b/src/ui/live_matchday.hpp @@ -51,8 +51,14 @@ struct LiveMatchdayFrame { LiveMatchdayFrame live_matchday_frame(int minute, const std::vector& groups, const GameState& state); +// Frame of the matchday as it looked before the chance of the event was written to the event log. The engine +// logs a chance (two log pairs) before its preview hook, so the statistics rows (chances, shots, ...) would +// otherwise count it before the presentation has even started. +LiveMatchdayFrame live_matchday_frame_before_chance(int minute, const std::vector& groups, + const GameState& state, const LiveChanceEvent& event); + // The engine commits a chance before its ball/set-piece/shot presentation. Keep -// the observed preview scores until the result hook, without delaying simulation. +// the observed preview scores and statistics until the result hook, without delaying simulation. class LiveScoreReveal { public: void observe(LiveChanceStage stage, const LiveMatchdayFrame& frame) { @@ -66,6 +72,8 @@ public: row.home_goals = before.home_goals; row.away_goals = before.away_goals; row.score_known = before.score_known; + row.home_stats = before.home_stats; + row.away_stats = before.away_stats; break; } return frame; diff --git a/src/ui/live_score_reveal_tests.cpp b/src/ui/live_score_reveal_tests.cpp index fbfeb53..625627b 100644 --- a/src/ui/live_score_reveal_tests.cpp +++ b/src/ui/live_score_reveal_tests.cpp @@ -26,6 +26,18 @@ int main() { reveal.observe(bmh::LiveChanceStage::result,resolved); if(reveal.project(resolved)!=resolved)throw std::runtime_error("result did not reveal goal"); } + // Statistics (chances, shots, ...) count a chance only at its result, like the score. + { + LiveScoreReveal stats_reveal; + stats_reveal.observe(bmh::LiveChanceStage::preview,frame); + auto counted=frame;counted.matches[0].home_stats={11,4,2,1};counted.matches[0].away_stats={11,3,0,0}; + counted.matches[0].home_stats[1]++; + const auto shown=stats_reveal.project(counted); + if(shown.matches[0].home_stats!=frame.matches[0].home_stats||shown.matches[0].away_stats!=frame.matches[0].away_stats|| + shown.matches[1]!=counted.matches[1])throw std::runtime_error("statistics counted before the result"); + stats_reveal.observe(bmh::LiveChanceStage::result,counted); + if(stats_reveal.project(counted)!=counted)throw std::runtime_error("result did not reveal statistics"); + } reveal.observe(bmh::LiveChanceStage::preview,frame); if(reveal.project(frame)!=frame)throw std::runtime_error("miss changed score"); auto next=frame;next.minute++;