Robot: play the window program from a script, for regression tests

A test hook for src/app/main.cpp, which the headless tools bypass. With
OPENBMH_ROBOT=<script> and OPENBMH_ROBOT_LOG=<file> (usually with the SDL
dummy video and audio drivers) the game reads clicks and keys from the script
instead of the mouse, waits after each command until the picture has settled
and writes its fingerprint; OPENBMH_ROBOT_SHOTS=<dir> also saves the pictures.
The events go through SDL's queue, so they take the path of real input.

Hooks: app::present() replaces the 31 SDL_RenderPresent calls of main.cpp,
QuitConfirmation::poll() lets the robot queue its next command when no input
is waiting, and a robot run answers the quit question itself. Without the
environment variables nothing changes.

Verified: a script of 234 commands (title, new career, season start
presentations, every desk icon, two matchdays with the live match) gives the
same file in three runs; 211 of 211 tests; careers and UI walk identical.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude committed 2026-11-10 15:36:08 +01:00
1 parent b7f748688c
commit ff32ef1dbc
3 files changed
+300 -32

No files matched your search

+11
View File
@@ -10,6 +10,8 @@
#include <functional>
#include <utility>
#include "app/robot.hpp"
namespace bmh::app {
// OpenBMH deviates from the original: confirms application exit with a localized native dialog, with cancellation selected by default.
@@ -47,6 +49,15 @@ public:
while (SDL_PollEvent(event)) {
if (event->type != SDL_QUIT || confirm()) return 1;
}
// No input waiting: a robot run (app/robot.hpp, inactive in normal play) may queue the
// events of its next script command now.
Robot& robot = Robot::instance();
if (robot.active()) {
robot.idle();
while (SDL_PollEvent(event)) {
if (event->type != SDL_QUIT || confirm()) return 1;
}
}
return 0;
}