Preserve live reconnect endpoints and execute QA commands between frames

This commit is contained in:
shen
2026-10-18 16:43:51 -07:00
parent 95f1c30be2
commit ab516feb7b
14 changed files with 175 additions and 6 deletions
+6
View File
@@ -187,3 +187,9 @@ The cache includes every specialization value, while alpha reference, fog and te
`--generic-shaders` / `MT_GENERIC_SHADERS=1` disables specialization for rendering comparisons.
Android Adreno 512 starts in 30 FPS saver mode when no frame-rate preference exists; saved preferences and test overrides take priority.
See [Mi 8 Lite measurements](../../docs/XIAOMI8LITE-ADAPTATION-20260930.md).
### Local QA commands between frames
`--py-command-file /absolute/path/command.py` optionally consumes local Python commands between script frames, while the script fiber is parked. Publish a complete file with atomic rename. Commands are removed before execution, including on a Python error; files over 1 MiB are rejected. This is an explicit development hook like `--py-exec`, disabled when omitted. Do not execute login/focus/phase changes from a test window's `OnUpdate`: those callbacks run during the native window-list traversal.
When reopening login, the selected live endpoint is retained instead of the packed legacy login address. A later manual server selection or explicit channel change still selects its own target; the successful game entry becomes the saved endpoint. No credentials are stored by this adapter.
+11 -2
View File
@@ -7,6 +7,7 @@
#include "host_util.h"
#include "native_audio.h"
#include "perf_log.h"
#include "python_command_file.h"
#include "texture_decode.h"
#include "ui_scale.h"
#include "ui_quality.h"
@@ -40,6 +41,7 @@ namespace mt_host {
// --py-exec: a test hook run once the auto-login run reaches the GameWindow (or, with --login-screen,
// once the LoginWindow is up).
std::string g_py_exec_after_login;
std::string g_py_command_file;
// --perf-log / MT_PERF_LOG=1: src/host/perf_log.h.
bool g_perf_log = false;
@@ -236,7 +238,7 @@ int run_live_client(
std::snprintf(
conn_cmd,
sizeof(conn_cmd),
"_stream.SetConnectInfo('%s', %d, '%s', %d)\n"
"__import__('mt_live_endpoint').Configure(_stream, '%s', %d, '%s', %d)\n"
"_w = _stream.curPhaseWindow\n"
"_w._LoginWindow__OpenServerBoard()",
server_host.c_str(),
@@ -257,7 +259,7 @@ int run_live_client(
std::snprintf(
login_cmd,
sizeof(login_cmd),
"_stream.SetConnectInfo('%s', %d, '%s', %d)\n"
"__import__('mt_live_endpoint').Configure(_stream, '%s', %d, '%s', %d)\n"
"_w = _stream.curPhaseWindow\n"
"_w._LoginWindow__OpenLoginBoard()\n"
"_w.idEditLine.SetText('%s')\n"
@@ -458,6 +460,13 @@ int run_live_client(
}
};
while ((frames == 0 || completed < frames) && renderer.poll(true) && PythonBoot::IsAppLooping()) {
// The script fiber is parked here. UI callbacks can change focus/order/phase safely before traversal.
if (!g_py_command_file.empty()) {
std::string command_error;
if (!consume_python_command_file(g_py_command_file,py_exec,command_error) && !command_error.empty())
std::cerr << command_error << '\n';
if (!PythonBoot::IsAppLooping()) break;
}
apply_policy();
save_ui_height_if_changed();
double pace_ms = 0.0;
+2
View File
@@ -10,6 +10,8 @@ class VulkanWindow;
// --py-exec: a test hook run once the auto-login run reaches the GameWindow (or, with --login-screen,
// once the LoginWindow is up).
extern std::string g_py_exec_after_login;
// --py-command-file: optional local QA commands executed while the script fiber is parked.
extern std::string g_py_command_file;
// --perf-log / MT_PERF_LOG=1: src/host/perf_log.h.
extern bool g_perf_log;
+1
View File
@@ -137,6 +137,7 @@ int main(int argc, char** argv) {
else if (arg == "--show-fps") show_fps = true;
#ifdef MT_NATIVE_HAS_LIVE_CLIENT
else if (arg == "--py-exec" && i+1 < argc) g_py_exec_after_login = argv[++i];
else if (arg == "--py-command-file" && i+1 < argc) g_py_command_file = argv[++i];
else if (arg == "--perf-log") g_perf_log = true;
else if (arg == "--fps-cap" && i+1 < argc) g_fps_cap = std::max(0, std::stoi(argv[++i]));
else if (arg == "--refresh-rate" && i+1 < argc) g_refresh_rate = std::max(0, std::stoi(argv[++i]));
+32
View File
@@ -0,0 +1,32 @@
#pragma once
// Optional local QA input, consumed between script frames, never from a window OnUpdate callback.
#include <filesystem>
#include <fstream>
#include <string>
namespace mt_host {
template<class Execute>
bool consume_python_command_file(const std::string& path, Execute execute, std::string& error) {
if (path.empty()) return true;
std::error_code ec;
const bool exists=std::filesystem::exists(path,ec);
if (ec) { error="cannot inspect Python command file";return false; }
if (!exists) return true;
const auto size=std::filesystem::file_size(path,ec);
if (ec) { error="cannot stat Python command file";return false; }
if (size>1024*1024) {
std::filesystem::remove(path,ec);
error="Python command file exceeds 1 MiB";return false;
}
std::ifstream in(path,std::ios::binary);
if (!in) { error="cannot read Python command file";return false; }
std::string code(static_cast<std::size_t>(size),'\0');
if (size && !in.read(&code[0],static_cast<std::streamsize>(size))) {
error="incomplete Python command file";return false;
}
in.close();
// A failed command must not execute again on the next frame. Producers publish with atomic rename.
if (!std::filesystem::remove(path,ec) || ec) { error="cannot consume Python command file";return false; }
return execute(code);
}
}