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
+25
-9
@@ -33,6 +33,7 @@
|
||||
#include "version.hpp"
|
||||
#include "app/video_session.hpp"
|
||||
#include "app/live_matchday_events.hpp"
|
||||
#include "app/pitch_pointer.hpp"
|
||||
#include "audio/playback.hpp"
|
||||
#include "app/audio.hpp"
|
||||
#include "formats/palette.hpp"
|
||||
@@ -215,6 +216,7 @@ int main(int argc, char** argv) {
|
||||
SDL_RenderSetLogicalSize(renderer, 320, 240);
|
||||
SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 240);
|
||||
if (!texture) throw FormatError(SDL_GetError());
|
||||
app::PitchPointer pitch_pointer;
|
||||
std::vector<uint32_t> pixels(320 * 240);
|
||||
ui::LiveMatchdayScreen live_screen(data);
|
||||
ui::RealityReporterPanel reality_reporter(data);
|
||||
@@ -1702,6 +1704,7 @@ int main(int argc, char** argv) {
|
||||
std::optional<Uint64> timed_notice_presented_at;
|
||||
std::optional<Uint8> timed_notice_release;
|
||||
auto handle = [&](const ui::FlowResult& r) {
|
||||
pitch_pointer.show({}, renderer);
|
||||
if (r.request == ui::FlowRequest::end_session && !quit_confirmation.confirm()) {
|
||||
flow.reject_desk_action(english_game ? "Quit cancelled." : "Beenden abgebrochen.");
|
||||
dirty = true;
|
||||
@@ -1781,6 +1784,7 @@ int main(int argc, char** argv) {
|
||||
bool closed = false;
|
||||
const auto apply_live_pitch = [&](const ui::PitchRequest& action) {
|
||||
if (action.kind == ui::PitchRequestKind::none) return;
|
||||
pitch_pointer.show({}, renderer);
|
||||
if (action.kind == ui::PitchRequestKind::open_player_info) {
|
||||
try {
|
||||
if (action.row < 0 || size_t(action.row) >= screen.state().players.size() ||
|
||||
@@ -1820,6 +1824,7 @@ int main(int argc, char** argv) {
|
||||
};
|
||||
bool left_held = false, left_release_consumed = false, right_held = false;
|
||||
while (running && !closed) {
|
||||
pitch_pointer.show(screen.pointer_cursor(palette), renderer);
|
||||
const Image image = screen.render();
|
||||
for (size_t i = 0; i < pixels.size(); ++i)
|
||||
pixels[i] = palette.argb[image.pixels[i]];
|
||||
@@ -1880,8 +1885,10 @@ int main(int argc, char** argv) {
|
||||
scope_finished = true;
|
||||
completed = true;
|
||||
}
|
||||
pitch_pointer.show({}, renderer);
|
||||
SDL_SetWindowTitle(window, "OpenBMH - live_matchday");
|
||||
} catch (const std::exception& e) {
|
||||
pitch_pointer.show({}, renderer);
|
||||
if (scope_started && !scope_finished)
|
||||
dispatch_scope(app::LiveInterventionBoundary::abort, 2,
|
||||
selected_manager, selected_team, scope_error);
|
||||
@@ -2096,11 +2103,16 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
};
|
||||
SDL_FlushEvent(SDL_KEYUP);
|
||||
while (running && !closed) {
|
||||
while (running && (!closed || down)) {
|
||||
SDL_Event input;
|
||||
bool redrawn = false;
|
||||
while (quit_confirmation.poll(&input)) {
|
||||
if (input.type == SDL_QUIT) { running = false; break; }
|
||||
if (closed) {
|
||||
if (input.type == SDL_MOUSEBUTTONUP && down &&
|
||||
input.button.button == down->button) { down.reset(); break; }
|
||||
continue;
|
||||
}
|
||||
if (input.type == SDL_MOUSEMOTION) {
|
||||
const bool changed = table_screen ? table_screen->move(input.motion.x, input.motion.y)
|
||||
: pairings_screen ? pairings_screen->move(input.motion.x, input.motion.y)
|
||||
@@ -2119,8 +2131,7 @@ int main(int argc, char** argv) {
|
||||
else cup_screen->pointer_down(input.button.x, input.button.y,
|
||||
input.button.button == SDL_BUTTON_RIGHT);
|
||||
} else if (input.type == SDL_MOUSEBUTTONUP && down &&
|
||||
input.button.button == down->button && input.button.x == down->x &&
|
||||
input.button.y == down->y) {
|
||||
input.button.button == down->button) {
|
||||
down.reset();
|
||||
if (table_screen) table_screen->click(input.button.x, input.button.y,
|
||||
input.button.button == SDL_BUTTON_RIGHT);
|
||||
@@ -2141,19 +2152,21 @@ int main(int argc, char** argv) {
|
||||
else if (cup_screen && cup_screen->pending())
|
||||
action = *cup_screen->pending();
|
||||
if (action) { dispatch_action(*action); redrawn = true; }
|
||||
if (closed || !running) break;
|
||||
if ((closed && !down) || !running) break;
|
||||
}
|
||||
if (!running || closed) break;
|
||||
if (!running || (closed && !down)) break;
|
||||
if (closed) { SDL_Delay(8); continue; }
|
||||
if (pairings_screen && pairings_screen->tick_source_seconds(overview_source_seconds())) {
|
||||
if (pairings_screen->pending())
|
||||
dispatch_action(app::CareerSession::LiveOverviewAction{*pairings_screen->pending()});
|
||||
redrawn = true;
|
||||
}
|
||||
if (closed || !running) break;
|
||||
if ((closed && !down) || !running) break;
|
||||
if (!redrawn) SDL_Delay(8);
|
||||
}
|
||||
return running && closed;
|
||||
};
|
||||
ui::LiveScoreReveal live_score_reveal;
|
||||
std::optional<ui::LiveChanceProjection> live_chance_context;
|
||||
std::unique_ptr<ui::RealityFieldScreen> reality_field;
|
||||
ui::RealityReporterLayoutState reality_layout;
|
||||
@@ -2911,7 +2924,7 @@ int main(int argc, char** argv) {
|
||||
}, [&](const LiveBallEvent& event, const std::vector<MatchGroup>& groups,
|
||||
const GameState& state) {
|
||||
if (!running || live_skipped) return;
|
||||
const auto frame = ui::live_matchday_frame(event.minute, groups, state);
|
||||
const auto frame = live_score_reveal.project(ui::live_matchday_frame(event.minute, groups, state));
|
||||
if (frame.matches.empty()) return;
|
||||
const auto present = [&](const Image& image) {
|
||||
for (size_t i = 0; i < pixels.size(); ++i) pixels[i] = palette.argb[image.pixels[i]];
|
||||
@@ -2958,6 +2971,7 @@ int main(int argc, char** argv) {
|
||||
const GameState& state) {
|
||||
if (!running || live_skipped) return;
|
||||
const auto frame = 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);
|
||||
if (event.stage == LiveChanceStage::preview) live_chance_context = chance;
|
||||
@@ -2990,7 +3004,7 @@ int main(int argc, char** argv) {
|
||||
}, [&](const LiveShotEvent& event, const std::vector<MatchGroup>& groups,
|
||||
const GameState& state) {
|
||||
if (!running || live_skipped) return;
|
||||
const auto frame = ui::live_matchday_frame(event.minute, groups, state);
|
||||
const auto frame = live_score_reveal.project(ui::live_matchday_frame(event.minute, groups, state));
|
||||
if (frame.matches.empty()) return;
|
||||
const auto frames = live_screen.render_shot(frame, event);
|
||||
const auto shot_colors = live_screen.shot_palette(palette, event, groups, state);
|
||||
@@ -3048,7 +3062,7 @@ int main(int argc, char** argv) {
|
||||
}, [&](const LiveSetPieceEvent& event, const std::vector<MatchGroup>& groups,
|
||||
const GameState& state) {
|
||||
if (!running || live_skipped) return;
|
||||
const auto frame=ui::live_matchday_frame(event.minute,groups,state);
|
||||
const auto frame=live_score_reveal.project(ui::live_matchday_frame(event.minute,groups,state));
|
||||
if (frame.matches.empty()) return;
|
||||
const auto images=live_screen.render_set_piece(frame,event);
|
||||
LiveShotEvent palette_event;
|
||||
@@ -3915,6 +3929,7 @@ int main(int argc, char** argv) {
|
||||
throw std::runtime_error(std::string("Source modal texture: ") + SDL_GetError());
|
||||
dirty = false;
|
||||
}
|
||||
pitch_pointer.show(flow.pitch_pointer_cursor(palette), renderer);
|
||||
const int cleared = SDL_RenderClear(renderer);
|
||||
const int copied = SDL_RenderCopy(renderer, texture, nullptr, nullptr);
|
||||
if (source_modal_redraw && (cleared != 0 || copied != 0))
|
||||
@@ -3939,6 +3954,7 @@ int main(int argc, char** argv) {
|
||||
SDL_Delay(10);
|
||||
}
|
||||
SDL_StopTextInput();
|
||||
pitch_pointer.clear();
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
|
||||
#include <SDL.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace bmh::app {
|
||||
|
||||
// SDL owns pointer position; the UI supplies only the original bitmap/colors.
|
||||
class PitchPointer {
|
||||
public:
|
||||
~PitchPointer() { clear(); }
|
||||
void clear() {
|
||||
if (cursor_) {
|
||||
SDL_SetCursor(SDL_GetDefaultCursor());
|
||||
SDL_FreeCursor(cursor_);
|
||||
cursor_ = nullptr;
|
||||
}
|
||||
pixels_.reset();
|
||||
}
|
||||
void show(const std::optional<std::array<uint32_t,121>>& pixels, SDL_Renderer* renderer) {
|
||||
if (!pixels) { SDL_SetCursor(SDL_GetDefaultCursor()); return; }
|
||||
int width = 320, height = 240;
|
||||
SDL_GetRendererOutputSize(renderer, &width, &height);
|
||||
const int scale = std::max(1, std::min(width / 320, height / 240));
|
||||
if (!cursor_ || pixels != pixels_ || scale != scale_) {
|
||||
std::vector<uint32_t> enlarged(size_t(11 * scale) * size_t(11 * scale));
|
||||
for (int y = 0; y < 11 * scale; ++y) for (int x = 0; x < 11 * scale; ++x)
|
||||
enlarged[size_t(y) * size_t(11 * scale) + size_t(x)] =
|
||||
pixels->at(size_t(y / scale) * 11 + size_t(x / scale));
|
||||
SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(enlarged.data(),
|
||||
11 * scale, 11 * scale, 32, 11 * scale * 4, SDL_PIXELFORMAT_ARGB8888);
|
||||
SDL_Cursor* next = surface ? SDL_CreateColorCursor(surface, 0, 0) : nullptr;
|
||||
if (surface) SDL_FreeSurface(surface);
|
||||
if (!next) return; // A headless SDL driver may not support host cursors.
|
||||
clear(); cursor_ = next; pixels_ = pixels; scale_ = scale;
|
||||
}
|
||||
SDL_SetCursor(cursor_);
|
||||
}
|
||||
private:
|
||||
SDL_Cursor* cursor_ = nullptr;
|
||||
std::optional<std::array<uint32_t,121>> pixels_;
|
||||
int scale_ = 1;
|
||||
};
|
||||
|
||||
} // namespace bmh::app
|
||||
Reference in new issue
Block a user