Synchronize match reveals and restore pitch input feedback (by Codex)
Hold scoreboard digits through chance animations, retain overview gesture ownership through moved releases, and restore original affinity swatches and colored pointer from each edition. Preserve simulation and RNG boundaries; cover source observer and UI projections. Refs: #43, #44, #45
This commit is contained in:
1 parent
86e2bfd32a
commit
540178b264
16 files changed
+269
-17
No files matched your search
@@ -243,3 +243,7 @@ bmh_add_data_test(NAME transfer_history_tests COMMAND transfer_history_tests "${
|
||||
add_executable(sportschau_ui_tests ../../tests/sportschau_ui_tests.cpp)
|
||||
target_link_libraries(sportschau_ui_tests PRIVATE bmhui)
|
||||
bmh_add_data_test(NAME sportschau_ui_tests COMMAND sportschau_ui_tests "${BMH_DATA}")
|
||||
|
||||
add_executable(live_score_reveal_tests live_score_reveal_tests.cpp)
|
||||
target_link_libraries(live_score_reveal_tests PRIVATE bmhui)
|
||||
add_test(NAME live_score_reveal_tests COMMAND live_score_reveal_tests)
|
||||
@@ -103,6 +103,9 @@ public:
|
||||
FlowResult expire_stadium_tip();
|
||||
bool in_stadium() const { return bool(stadium_); }
|
||||
bool in_pitch() const { return bool(pitch_); }
|
||||
std::optional<std::array<uint32_t,121>> pitch_pointer_cursor(const Palette& palette) const {
|
||||
return pitch_ && screen_name() == "pitch" ? pitch_->pointer_cursor(palette) : std::nullopt;
|
||||
}
|
||||
std::optional<Image> pitch_formation_save_feedback(bool restored) const;
|
||||
FlowResult pitch_held_left(int x, int y, uint64_t source_ticks);
|
||||
void consume_orphaned_pitch_release(){pitch_release_barrier_=false;}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@@ -46,6 +47,29 @@ struct LiveMatchdayFrame {
|
||||
LiveMatchdayFrame live_matchday_frame(int minute, const std::vector<MatchGroup>& groups,
|
||||
const GameState& state);
|
||||
|
||||
// The engine commits a chance before its ball/set-piece/shot presentation. Keep
|
||||
// the observed preview scores until the result hook, without delaying simulation.
|
||||
class LiveScoreReveal {
|
||||
public:
|
||||
void observe(LiveChanceStage stage, const LiveMatchdayFrame& frame) {
|
||||
if (stage == LiveChanceStage::preview) preview_ = frame;
|
||||
else preview_.reset();
|
||||
}
|
||||
LiveMatchdayFrame project(LiveMatchdayFrame frame) const {
|
||||
if (!preview_ || preview_->minute != frame.minute) return frame;
|
||||
for (auto& row : frame.matches) for (const auto& before : preview_->matches)
|
||||
if (row.home_team == before.home_team && row.away_team == before.away_team) {
|
||||
row.home_goals = before.home_goals;
|
||||
row.away_goals = before.away_goals;
|
||||
row.score_known = before.score_known;
|
||||
break;
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
private:
|
||||
std::optional<LiveMatchdayFrame> preview_;
|
||||
};
|
||||
|
||||
struct LiveChanceProjection {
|
||||
LiveChanceStage stage = LiveChanceStage::preview;
|
||||
int minute = 0, group = 0, match = 0, side = 0;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "ui/live_matchday.hpp"
|
||||
#include <stdexcept>
|
||||
using namespace bmh::ui;
|
||||
int main() {
|
||||
LiveMatchdayFrame frame;
|
||||
frame.minute=23;
|
||||
LiveMatchRow home;home.home_team=10;home.away_team=11;home.score_known=true;
|
||||
home.home_goals=2;home.away_goals=1;frame.matches.push_back(home);
|
||||
LiveMatchRow other=home;other.home_team=20;other.away_team=21;frame.matches.push_back(other);
|
||||
LiveScoreReveal reveal;
|
||||
if(reveal.project(frame)!=frame)throw std::runtime_error("idle reveal changed scores");
|
||||
for (int side : {0,1}) {
|
||||
reveal.observe(bmh::LiveChanceStage::preview,frame);
|
||||
auto resolved=frame;
|
||||
(side==0?resolved.matches[0].home_goals:resolved.matches[0].away_goals)++;
|
||||
resolved.matches[0].spectators=12500;
|
||||
// Animation frames can be rendered repeatedly without committing scores.
|
||||
for(int animation=0;animation<18;++animation) {
|
||||
const auto shown=reveal.project(resolved);
|
||||
if(shown.matches[0].home_goals!=2 || shown.matches[0].away_goals!=1 ||
|
||||
shown.matches[0].spectators!=12500 || shown.matches[1]!=resolved.matches[1])
|
||||
throw std::runtime_error("animation leaked score or replaced unrelated fields");
|
||||
}
|
||||
reveal.observe(bmh::LiveChanceStage::result,resolved);
|
||||
if(reveal.project(resolved)!=resolved)throw std::runtime_error("result did not reveal goal");
|
||||
}
|
||||
reveal.observe(bmh::LiveChanceStage::preview,frame);
|
||||
if(reveal.project(frame)!=frame)throw std::runtime_error("miss changed score");
|
||||
auto next=frame;next.minute++;
|
||||
if(reveal.project(next)!=next)throw std::runtime_error("old chance held a later minute");
|
||||
// Team identity, rather than row index, survives a reordered board.
|
||||
auto reversed=frame;std::swap(reversed.matches[0],reversed.matches[1]);
|
||||
reversed.matches[1].away_goals++;
|
||||
if(reveal.project(reversed)!=LiveMatchdayFrame{frame.minute,frame.minute_text,frame.gradient_text,
|
||||
{frame.matches[1],frame.matches[0]}})throw std::runtime_error("reordered board used wrong score");
|
||||
}
|
||||
+42
-4
@@ -3,6 +3,7 @@
|
||||
#include "ui/pitch.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
|
||||
#include "formats/savestate.hpp"
|
||||
@@ -195,7 +196,7 @@ PitchScreen::PitchScreen(const std::filesystem::path& data,LineupState state,Pit
|
||||
PitchScreen::PitchScreen(const PitchScreen& other)
|
||||
:PitchScreen(other.data_,other.state_,other.extras_){
|
||||
pending_=other.pending_;selected_=other.selected_;hovered_=other.hovered_;ghost_=other.ghost_;
|
||||
order_hover_grid_=other.order_hover_grid_;
|
||||
order_hover_grid_=other.order_hover_grid_;pointer_grid_=other.pointer_grid_;
|
||||
scroll_=other.scroll_;close_=other.close_;return_team_=other.return_team_;rejection_=other.rejection_;
|
||||
weights_dirty_=other.weights_dirty_;
|
||||
shooter_editor_open_=other.shooter_editor_open_;shooter_selection_=other.shooter_selection_;
|
||||
@@ -291,6 +292,35 @@ bool PitchScreen::automatic_page()const{
|
||||
// their respective areas even when that bit is retained underneath.
|
||||
return !shooter_editor_open_&&(extras_.native_display_word&0x18)==0x18;
|
||||
}
|
||||
std::optional<std::pair<int,int>> PitchScreen::position_feedback() const {
|
||||
if (!pointer_grid_ || close_ || !(extras_.native_display_word & 8)) return {};
|
||||
const auto row = selected_ ? selected_ : hovered_;
|
||||
if (!row || size_t(*row) >= state_.players.size()) return {};
|
||||
const auto& p = state_.players.at(size_t(*row));
|
||||
if (p.player_id < 0 || !(p.slot & 0xc000) || ((p.attributes.w364 >> 16) & 31)) return {};
|
||||
const int depth = int(exe_.u8(::bmh::layout::PitchPreferenceDepthBases + p.attributes.position())) - 2 +
|
||||
int((p.attributes.w35c >> 21 & 7) >> 1);
|
||||
const int lane = int((p.attributes.w35c >> 24 & 7) * 800 / 7);
|
||||
const auto band = [&](int x, int y) {
|
||||
return std::min(9, (std::abs(depth - x) * 100 + std::abs(lane - y * 100)) / 200);
|
||||
};
|
||||
return std::pair{band(int8_t(p.board[0x41]), int8_t(p.board[0x42])),
|
||||
band(pointer_grid_->first, pointer_grid_->second)};
|
||||
}
|
||||
std::optional<std::array<uint32_t, 121>> PitchScreen::pointer_cursor(const Palette& palette) const {
|
||||
const auto feedback = position_feedback();
|
||||
if (!feedback) return {};
|
||||
const auto band = uint32_t(feedback->second);
|
||||
const uint32_t fill = 0xff000000u |
|
||||
(uint32_t(vga_dac_rgb8(uint8_t(exe_.u8(::bmh::layout::PitchPreferenceRed + band) << 4))) << 16) |
|
||||
(uint32_t(vga_dac_rgb8(uint8_t(exe_.u8(::bmh::layout::PitchPreferenceGreen + band) << 4))) << 8);
|
||||
std::array<uint32_t, 121> pixels{};
|
||||
for (uint32_t i = 0; i < pixels.size(); ++i) {
|
||||
const auto index = exe_.u8(::bmh::layout::OriginalPointerPixels + i);
|
||||
pixels[i] = index == 0 ? 0 : index == 0x11 ? fill : palette.argb[index];
|
||||
}
|
||||
return pixels;
|
||||
}
|
||||
Image PitchScreen::render()const{
|
||||
// PitchScreen's page redraw copies the owned offscreen sheet from y=20: all
|
||||
// 190 rows when source bit 0x08 is clear, only the upper 88 rows when it is
|
||||
@@ -472,6 +502,10 @@ Image PitchScreen::render()const{
|
||||
rect(out,0x105,y+9,value,1,0);rect(out,0x103+value,y+2,1,8,0);}
|
||||
}
|
||||
}
|
||||
// Native lower-right swatches compare the current position with the pointer.
|
||||
const auto feedback = position_feedback();
|
||||
copy(out,atlas_,feedback ? 259 + feedback->first * 5 : 309,68,305,233,5,4,0xc0);
|
||||
copy(out,atlas_,feedback ? 259 + feedback->second * 5 : 309,68,312,230,5,4,0xc0);
|
||||
return out;
|
||||
}
|
||||
std::optional<std::pair<int,int>> PitchScreen::grid(int x,int y){
|
||||
@@ -570,10 +604,12 @@ PitchRequest PitchScreen::order_request(int aspect,int value){
|
||||
}
|
||||
PitchRequest PitchScreen::click(int x,int y,bool right){
|
||||
if(pending_||close_)return {};
|
||||
pointer_grid_=grid(x,y);
|
||||
const uint16_t display_word=shooter_editor_open_
|
||||
? uint16_t(extras_.native_display_word&0xff0f)
|
||||
: extras_.native_display_word;
|
||||
if(right){
|
||||
pointer_grid_.reset();
|
||||
if((display_word&0x08)==0){sheet_->click(x,y,true);close_=sheet_->close_requested();}
|
||||
else if(selected_){selected_.reset();ghost_.reset();}
|
||||
else {close_=true;zone_cover_open_=false;}
|
||||
@@ -740,11 +776,13 @@ PitchRequest PitchScreen::save_formation(int x,int y){
|
||||
pending_=r;return r;
|
||||
}
|
||||
bool PitchScreen::move(int x,int y){if(pending_||close_)return false;
|
||||
const auto old_pointer_grid=pointer_grid_;
|
||||
if((extras_.native_display_word&0x08)==0)return sheet_->move(x,y);
|
||||
pointer_grid_=grid(x,y);
|
||||
const auto old=hovered_;const auto oldghost=ghost_;hovered_=hit_row(x,y);ghost_=selected_?grid(x,y):std::nullopt;
|
||||
const auto old_grid=order_hover_grid_;
|
||||
order_hover_grid_=order_panel_open_?grid(x,y):std::nullopt;
|
||||
return old!=hovered_||oldghost!=ghost_||old_grid!=order_hover_grid_;
|
||||
return old!=hovered_||oldghost!=ghost_||old_grid!=order_hover_grid_||old_pointer_grid!=pointer_grid_;
|
||||
}
|
||||
PitchRequest PitchScreen::key(std::string_view key){
|
||||
// PitchScreen's desktop pages cancel selection/return on mouse event 8.
|
||||
@@ -916,13 +954,13 @@ void PitchScreen::acknowledge(LineupState s,PitchExtras e){
|
||||
}
|
||||
void PitchScreen::reject_action(std::string reason){if(!pending_||reason.empty())throw FormatError("pitch: rejection requires pending action and reason");
|
||||
if(sheet_->pending())sheet_=std::make_unique<LineupScreen>(data_,state_);
|
||||
pending_.reset();selected_.reset();hovered_.reset();ghost_.reset();order_hover_grid_.reset();marking_target_row_.reset();rejection_=std::move(reason);
|
||||
pending_.reset();selected_.reset();hovered_.reset();ghost_.reset();pointer_grid_.reset();order_hover_grid_.reset();marking_target_row_.reset();rejection_=std::move(reason);
|
||||
}
|
||||
void PitchScreen::resolve_local_navigation(){
|
||||
if(!pending_||pending_->kind!=PitchRequestKind::open_player_info)
|
||||
throw FormatError("pitch: only player info can resolve locally");
|
||||
if(sheet_->pending())sheet_->resolve_local_navigation(LineupRequestKind::open_player_info);
|
||||
pending_.reset();selected_.reset();hovered_.reset();ghost_.reset();rejection_.clear();
|
||||
pending_.reset();selected_.reset();hovered_.reset();ghost_.reset();pointer_grid_.reset();rejection_.clear();
|
||||
}
|
||||
std::string PitchScreen::state_json()const{std::ostringstream out;
|
||||
out<<"{\"screen\":\"pitch\",\"manager_slot\":"<<state_.manager_slot<<",\"runtime_club\":"<<state_.runtime_club
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "ui/lineup.hpp"
|
||||
#include "ui/sprite_font.hpp"
|
||||
#include "formats/palette.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace bmh::ui {
|
||||
@@ -81,6 +82,9 @@ public:
|
||||
PitchScreen(PitchScreen&&) noexcept = default;
|
||||
PitchScreen& operator=(PitchScreen&&) noexcept = default;
|
||||
Image render() const;
|
||||
// Current/proposed native distance bands, available only over the pitch.
|
||||
std::optional<std::pair<int,int>> position_feedback() const;
|
||||
std::optional<std::array<uint32_t, 121>> pointer_cursor(const Palette&) const;
|
||||
// PitchScreen: outline only, before the pending save is dispatched/ACKed.
|
||||
static constexpr int formation_save_flash_ms = 5 * 20; // DecodeTaxAnimationScript2(5)
|
||||
std::optional<Image> formation_save_feedback(bool restored) const;
|
||||
@@ -116,6 +120,7 @@ private:
|
||||
std::optional<PitchRequest> pending_;
|
||||
std::optional<int> selected_, hovered_;
|
||||
std::optional<std::pair<int,int>> ghost_;
|
||||
std::optional<std::pair<int,int>> pointer_grid_;
|
||||
std::optional<std::pair<int,int>> order_hover_grid_;
|
||||
int scroll_ = 0;
|
||||
bool close_ = false, return_team_ = false;
|
||||
|
||||
@@ -38,6 +38,35 @@ int main(int argc,char**argv){try{
|
||||
PitchScreen pitch(data,s,e);const auto pixels=pitch.render().pixels;
|
||||
check(pixels.size()==320*240&&pitch.render().pixels==pixels,"pitch render is deterministic");
|
||||
check(pitch.state().players[3].board[0x41]==3&&!pitch.pending(),"render does not mutate authoritative positions");
|
||||
auto affinity_state=s;
|
||||
affinity_state.players[3].attributes.w364=1; // defender
|
||||
affinity_state.players[3].attributes.w35c=(6u<<21)|(4u<<24);
|
||||
PitchScreen affinity(data,affinity_state,e);
|
||||
const auto affinity_initial=affinity.render();
|
||||
const auto colors=load_palette(asset_path(data,"M3PC.COL"));
|
||||
check(!affinity.position_feedback()&&!affinity.pointer_cursor(colors),
|
||||
"idle pitch leaves host cursor and position colors unmodified");
|
||||
affinity.click(30,164);affinity.move(40,164);
|
||||
check(affinity.position_feedback()==std::pair{0,0},
|
||||
"near preferred defender depth/lane uses the best native distance band");
|
||||
const auto near_cursor=affinity.pointer_cursor(colors);
|
||||
const auto near_image=affinity.render();
|
||||
affinity.move(160,208);
|
||||
check(affinity.position_feedback()==std::pair{0,9}&&
|
||||
affinity.pointer_cursor(colors)&&affinity.pointer_cursor(colors)!=near_cursor,
|
||||
"far placement reaches the worst native band and changes cursor fill");
|
||||
const auto far_image=affinity.render();
|
||||
bool swatch_changed=false;
|
||||
for(int y=230;y<234;++y)for(int x=312;x<317;++x)
|
||||
swatch_changed|=near_image.pixels[size_t(y)*320+size_t(x)]!=far_image.pixels[size_t(y)*320+size_t(x)];
|
||||
check(swatch_changed&&affinity.state().players[3].board==s.players[3].board&&!affinity.pending(),
|
||||
"original proposed-position swatch changes without moving a player or dispatching");
|
||||
affinity.move(300,220);
|
||||
check(!affinity.position_feedback()&&!affinity.pointer_cursor(colors),
|
||||
"leaving pitch restores ordinary cursor and clears affinity colors");
|
||||
affinity.click(0,0,true);
|
||||
check(affinity.render().pixels==affinity_initial.pixels&&!affinity.pointer_cursor(colors),
|
||||
"cancelled placement restores original footer and cursor");
|
||||
const auto idle_pitch=pitch.state_json();
|
||||
check(pitch.key("ESC").kind==PitchRequestKind::none&&
|
||||
pitch.key("ESCAPE").kind==PitchRequestKind::none&&
|
||||
|
||||
Reference in new issue
Block a user