Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ the core's settings are unavailable and labels the pad chips generically. Mods r
`include/retcomm/mods.hpp` names (n64lle writes its selection to
`<title dir>/mods.toml`).

For Nintendo 64 titles, **Gameplay diagnostics** appears on the Mods page.
It records offline gameplay by default, with a saved choice for each title.
Open Replays to inspect the recordings. A save or load seals the current
recording and starts a new segment when play resumes. Automatic recording
requires a compatible runner and stays off during netplay and accessory
sessions. The usual in-session replay hotkey still works.

**The runner.** Direct mode finds `retro-core-runner` the way the launcher does
(`resolve_runner`, `src/update/runtime_update.cpp`), in this order:

Expand Down
26 changes: 26 additions & 0 deletions src/hub/hub_core_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,32 @@ bool save_play_prefs(const fs::path& data_dir, const PlayPrefs& prefs, std::stri
return write_atomically(data_dir / "play.ini", o.str(), error);
}

namespace {
fs::path diagnostics_path(const fs::path& data_dir, const std::string& title_key) {
return platform_settings_dir(data_dir, "n64") / "diagnostics" / (title_key + ".ini");
}
} // namespace

bool load_gameplay_diagnostics(const fs::path& data_dir, const std::string& title_key) {
bool enabled = true;
for_each_ini(read_text(diagnostics_path(data_dir, title_key)),
[&](const std::string& section, const std::string& key, const std::string& value) {
if (section == "diagnostics" && key == "record_gameplay") {
if (value == "0") enabled = false;
else if (value == "1") enabled = true;
}
});
return enabled;
}

bool save_gameplay_diagnostics(const fs::path& data_dir, const std::string& title_key,
bool enabled, std::string* error) {
return write_atomically(diagnostics_path(data_dir, title_key),
enabled ? "[diagnostics]\nrecord_gameplay = 1\n"
: "[diagnostics]\nrecord_gameplay = 0\n",
error);
}

// ---- display ------------------------------------------------------------------

namespace {
Expand Down
5 changes: 5 additions & 0 deletions src/hub/hub_core_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ struct PlayPrefs {
PlayPrefs load_play_prefs(const fs::path& data_dir);
bool save_play_prefs(const fs::path& data_dir, const PlayPrefs& prefs, std::string* error);

// The Mods page's host-only recording choice for one Nintendo 64 title.
bool load_gameplay_diagnostics(const fs::path& data_dir, const std::string& title_key);
bool save_gameplay_diagnostics(const fs::path& data_dir, const std::string& title_key,
bool enabled, std::string* error);

// ---- display ------------------------------------------------------------------

// How the hub scales the core's frame to the window (hub_picture.hpp). The
Expand Down
68 changes: 58 additions & 10 deletions src/hub/hub_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3561,6 +3561,7 @@ struct ModsPageState {
bool focus_list = false; // set by the detail column, consumed next frame
bool pending_rescan = false; // a write landed; re-read once the panel is done
bool detail = false; // the overlay: one feature's page is open
bool record_gameplay = true;
};

// Right / Left as a player produces them: d-pad, left stick, or the arrow keys
Expand All @@ -3584,11 +3585,26 @@ ModsPageState& mods_page_state() {
return s;
}

bool has_gameplay_diagnostics(const TitleRow& row) {
return row.platform == "n64" && !row.id.empty() &&
(row.kind == "core" || !row.core_manifest.empty());
}

void refresh_mods_page(HubModel& hub, const TitleRow& row) {
ModsPageState& st = mods_page_state();
st.scan = retcomm::scan_game_mods(title_game_dir(hub, row), fs::path(row.install_root),
fs::path(row.mods_state_dir));
st.title_id = row.id;
if (has_gameplay_diagnostics(row))
st.record_gameplay = retcomm::hub::load_gameplay_diagnostics(hub.paths.data_dir, row.id);
}

void set_gameplay_diagnostics(HubModel& hub, const TitleRow& row, bool enabled) {
std::string error;
if (retcomm::hub::save_gameplay_diagnostics(hub.paths.data_dir, row.id, enabled, &error))
mods_page_state().record_gameplay = enabled;
else
hub.append_log("Gameplay diagnostics: " + error);
}

// Every (package, feature) pair, flattened and grouped the way the left panel
Expand Down Expand Up @@ -3645,6 +3661,13 @@ void draw_mods_page(HubModel& hub, const Theme& th) {
ImGui::TextUnformatted(row.name.c_str());
ImGui::TextColored(th.text_muted, "%s", st.scan.root.string().c_str());
ImGui::Separator();
if (has_gameplay_diagnostics(row)) {
bool enabled = st.record_gameplay;
if (ImGui::Checkbox("Gameplay diagnostics", &enabled))
set_gameplay_diagnostics(hub, row, enabled);
ImGui::TextWrapped("Record offline gameplay automatically. Find recordings in Replays.");
ImGui::Separator();
}

auto set_all = [&](bool on) {
std::string err;
Expand Down Expand Up @@ -4109,6 +4132,15 @@ void draw_shell_mods(HubModel& hub, const Theme& th, const retcomm::hub::overlay
else if (r == 2) st.search[0] = '\0';
}
const std::string needle = st.search;
if (has_gameplay_diagnostics(row)) {
retcomm::ModPackageInfo diagnostics;
diagnostics.name = "Gameplay diagnostics";
if (mod_row_matches(diagnostics, nullptr, needle) &&
ov::setting_row(m, "gameplay_diagnostics", "Gameplay diagnostics",
st.record_gameplay ? "On" : "Off",
"Record offline gameplay automatically. Find recordings in Replays."))
set_gameplay_diagnostics(hub, row, !st.record_gameplay);
}
if (!st.scan.root_exists)
ov::muted("No mods folder yet. The engine creates mods/bundled at build time; mods/installed is where "
"packages are added.");
Expand Down Expand Up @@ -11049,6 +11081,8 @@ void apply_player_settings(retcomm::hub::PlayArgs& args, const fs::path& data_di
const std::string& title_key) {
// The overlay's settings are every core's: loaded whatever the platform.
args.prefs = retcomm::hub::load_play_prefs(data_dir);
args.record_gameplay_diagnostics = platform == "n64" && !title_key.empty() &&
retcomm::hub::load_gameplay_diagnostics(data_dir, title_key);
args.data_dir = data_dir;
args.exe_dir = exe_dir;
if (platform.empty()) {
Expand Down Expand Up @@ -11623,6 +11657,18 @@ std::string core_settings_default(const CoreSettingsPage& p,
return it == p.default_opts.end() ? (o.has_default ? o.default_value : std::string())
: it->second;
}
// The core ABI carries stored enum values. Friendly text is presentation-only.
const std::string& core_option_value_label(const retcomm::hub::CoreOptionDecl& option,
const std::string& value) {
static const std::string fit = "Fit to screen";
static const std::string original = "Original (4:3)";
if (option.key == "video.aspect") {
if (value == "fit") return fit;
if (value == "original") return original;
}
return value;
}

void draw_core_option_row(CoreSettingsPage& p, const retcomm::hub::CoreOptionDecl& o,
const Theme& th) {
std::map<std::string, std::string>& layer = p.title_scope ? p.title_opts : p.plat_opts;
Expand All @@ -11639,18 +11685,19 @@ void draw_core_option_row(CoreSettingsPage& p, const retcomm::hub::CoreOptionDec
std::string t, f;
if (o.type == "enum" && !o.values.empty()) {
settings_row(label.c_str(), th, kSettingsCtrlW);
const std::string& display = core_option_value_label(o, cur);
const std::string preview =
!p.title_scope ? (set ? cur : std::string(inherit_word) + ": " + cur)
: (cur == kTitleDeclaredValue ? std::string("Default") : cur);
!p.title_scope ? (set ? display : std::string(inherit_word) + ": " + display)
: (cur == kTitleDeclaredValue ? std::string("Default") : display);
if (ImGui::BeginCombo("##v", preview.c_str())) {
if (!p.title_scope &&
ImGui::Selectable((std::string(inherit_word) + " (" + inherited + ")").c_str(),
ImGui::Selectable((std::string(inherit_word) + " (" + core_option_value_label(o, inherited) + ")").c_str(),
!set))
layer.erase(o.key);
for (const std::string& v : o.values) {
if (p.title_scope && v == kTitleDeclaredValue) continue;
const bool chosen = (set || p.title_scope) && v == cur;
if (ImGui::Selectable(v.c_str(), chosen)) layer[o.key] = v;
if (ImGui::Selectable(core_option_value_label(o, v).c_str(), chosen)) layer[o.key] = v;
if (chosen) ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
Expand Down Expand Up @@ -11683,7 +11730,7 @@ void draw_core_option_row(CoreSettingsPage& p, const retcomm::hub::CoreOptionDec
const std::string default_value = core_settings_default(p, o);
ImGui::SetTooltip("%s\n\n%s%s%s%s", o.description.c_str(), o.key.c_str(),
has_default ? " \xC2\xB7 default " : "",
has_default ? default_value.c_str() : "",
has_default ? core_option_value_label(o, default_value).c_str() : "",
o.restart ? "\nApplies the next time a game starts." : "");
}
ImGui::PopID();
Expand Down Expand Up @@ -13480,23 +13527,24 @@ void overlay_option_row(CoreSettingsPage& p, const retcomm::hub::CoreOptionDecl&
ImGui::PushID(o.key.c_str());
std::string t, f;
if (o.type == "enum" && !o.values.empty()) {
const std::string& display = core_option_value_label(o, cur);
const std::string shown =
!p.title_scope ? (set ? cur : std::string(inherit_word) + ": " + cur)
: (cur == kTitleDeclaredValue ? std::string("Default") : cur);
!p.title_scope ? (set ? display : std::string(inherit_word) + ": " + display)
: (cur == kTitleDeclaredValue ? std::string("Default") : display);
if (ov::setting_row(m, "row", label.c_str(), shown, desc, true, p.title_scope && set))
ov::open_picker("##pick");
std::vector<ov::PickerChoice> choices;
std::vector<std::string> vals; // "" = inherit
int current = -1;
if (!p.title_scope) {
choices.push_back({std::string(inherit_word) + " (" + inherited + ")", ""});
choices.push_back({std::string(inherit_word) + " (" + core_option_value_label(o, inherited) + ")", ""});
vals.push_back("");
if (!set) current = 0;
}
for (const std::string& v : o.values) {
if (p.title_scope && v == kTitleDeclaredValue) continue;
if ((set || p.title_scope) && v == cur) current = static_cast<int>(choices.size());
choices.push_back({v, ""});
choices.push_back({core_option_value_label(o, v), ""});
vals.push_back(v);
}
const int pick = ov::picker(m, "##pick", label.c_str(), choices, current);
Expand Down Expand Up @@ -13577,7 +13625,7 @@ std::string option_summary_text(const CoreSettingsPage& p, const retcomm::hub::C
std::string t, f;
if (o.type == "bool" && bool_spelling(o, t, f))
return (o.label.empty() ? o.key : o.label) + (cur == t ? " on" : " off");
return cur.empty() ? std::string("default") : cur;
return cur.empty() ? std::string("default") : core_option_value_label(o, cur);
}

struct CoreSection {
Expand Down
74 changes: 58 additions & 16 deletions src/hub/hub_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,28 @@ constexpr std::uint64_t kTurboBudgetNs = 10 * 1000000ull;
constexpr double kTurboSoundLowMs = 40.0;
constexpr double kTurboSoundHighMs = 100.0;

// Whether the runner can lend a core a GL context (`gl 1` in its --version).
// A runner built without SDL3 -- the Android APK's -- exits on --gl, so a
// session asks for one only when the runner says it has one. Asked once per
// runner for the life of the hub; a runner that cannot be asked keeps the
// old behaviour (its start will say what is wrong).
bool runner_lends_gl(const fs::path& runner) {
static std::map<std::string, bool> known;
struct RunnerFeatures {
bool gl = true;
bool safe_interactive_recording = false;
};

// Keep the existing GL fallback when a version probe fails. Automatic
// diagnostics requires a runner that can record without blocking saves.
RunnerFeatures runner_features(const fs::path& runner) {
static std::map<std::string, RunnerFeatures> known;
const std::string key = corelink::path_utf8(runner);
if (auto it = known.find(key); it != known.end()) return it->second;
corelink::RunnerVersion v;
std::string err;
const bool gl = corelink::probe_runner(runner, v, &err) ? v.gl : true;
known.emplace(key, gl);
return gl;
RunnerFeatures features;
if (corelink::probe_runner(runner, v, &err)) {
features.gl = v.gl;
#if defined(RETRO_CORELINK_HAS_SAFE_INTERACTIVE_RECORDING)
features.safe_interactive_recording = v.safe_interactive_recording;
#endif
}
known.emplace(key, features);
return features;
}
constexpr double kTurboFadeMs = 4.0;
constexpr int kVolumeStep = 10;
Expand Down Expand Up @@ -133,7 +141,9 @@ bool PlaySession::start(const PlayArgs& args, const fs::path& runner, const fs::
spec.gpu_capabilities = gpu_frames_.capabilities();
spec.cpu_pixel_pairs = Picture::supports_pixel_pairs();
spec.save_dir = save_dir;
spec.gl = args.gl && runner_lends_gl(runner);
const RunnerFeatures features = args.gl || args.record_gameplay_diagnostics
? runner_features(runner) : RunnerFeatures{};
spec.gl = args.gl && features.gl;
if (args.gl && !spec.gl)
SDL_Log("retro-hub: %s lends no GL context (gl 0); the core runs without one",
corelink::path_utf8(runner).c_str());
Expand All @@ -142,6 +152,13 @@ bool PlaySession::start(const PlayArgs& args, const fs::path& runner, const fs::
spec.env = args.env;
spec.extra_args = args.net_args;
netplay_ = !args.net_args.empty();
recording_request_.reset();
diagnostics_recording_ = false;
diagnostics_pending_ = args.record_gameplay_diagnostics &&
features.safe_interactive_recording && !netplay_ &&
std::none_of(args.tpak_rom.begin(), args.tpak_rom.end(),
[](const std::string& rom) { return !rom.empty(); }) &&
std::none_of(args.vru_seat.begin(), args.vru_seat.end(), [](bool active) { return active; });
for (std::size_t seat = 0; seat < args.tpak_save.size(); ++seat)
if (!args.tpak_rom[seat].empty() && !args.tpak_save[seat].empty())
spec.save_files["tpak" + std::to_string(seat + 1)] = args.tpak_save[seat];
Expand Down Expand Up @@ -381,6 +398,9 @@ void PlaySession::service_states() {
}
const bool sent = save ? link_.request_save_state(state_request_.path, thumbnail)
: link_.request_load_state(state_request_.path);
if (sent && diagnostics_recording_ &&
link_.replay_status().state == corelink::ReplayState::Recording)
diagnostics_pending_ = true;
if (!sent) states_.finish(false, save, "the link could not send the request");
state_request_ = Req{};
}
Expand Down Expand Up @@ -693,6 +713,8 @@ void PlaySession::toggle_recording() {
if (state==corelink::ReplayState::Playing) {
osd_.toast("Recording is off during replay playback",SDL_GetTicksNS()); return;
}
diagnostics_pending_ = false;
diagnostics_recording_ = false;
recording_request_=state!=corelink::ReplayState::Recording;
}

Expand All @@ -706,7 +728,16 @@ void PlaySession::service_replays() {
else if (status.state==corelink::ReplayState::TakenOver) replay_message_="Live input took over";
else if (status.state==corelink::ReplayState::Recording) replay_message_="Recording replay";
else replay_message_.clear();
if (!replay_message_.empty()) osd_.toast(replay_message_,SDL_GetTicksNS(),3000);
if (!replay_message_.empty() && !diagnostics_recording_)
osd_.toast(replay_message_,SDL_GetTicksNS(),3000);
}
if (diagnostics_pending_ && !paused() && link_.can_grant()) {
diagnostics_pending_ = false;
if (link_.replays_supported() && !recording_request_ &&
(status.state == corelink::ReplayState::Idle || status.state == corelink::ReplayState::Saved)) {
diagnostics_recording_ = true;
recording_request_ = true;
}
}
if (recording_request_ && link_.can_grant()) {
const bool record=*recording_request_;
Expand All @@ -724,14 +755,24 @@ void PlaySession::service_replays() {
if (!pixels.empty()) info.pixels=retro::state::make_thumbnail(pixels.data(),w,h,w*4);
info.aspect=picture_.aspect(); preview=std::move(info);
}
if (ec || !link_.request_recording(record,path)) {
#if defined(RETRO_CORELINK_HAS_SAFE_INTERACTIVE_RECORDING)
const bool sent = !ec && link_.request_recording(record, path, diagnostics_recording_);
#else
const bool sent = !ec && link_.request_recording(record, path);
#endif
if (!sent) {
replay_message_=ec ? ec.message() : "The replay request could not be sent";
osd_.toast(replay_message_,SDL_GetTicksNS(),3000);
if (!diagnostics_recording_) osd_.toast(replay_message_,SDL_GetTicksNS(),3000);
}
else if (record) replay_preview_=std::move(preview);
recording_request_.reset();
}
if (!replay_play_.empty() && link_.can_grant()) {
if (diagnostics_recording_ && status.state==corelink::ReplayState::Recording) {
recording_request_ = false;
diagnostics_pending_ = false;
return;
}
const auto path=replay_play_; replay_play_.clear();
if (status.state==corelink::ReplayState::Recording) {
replay_message_="Stop recording before playing a replay"; return;
Expand Down Expand Up @@ -792,7 +833,7 @@ void PlaySession::draw_overlay() {
const ImVec2 disp = ImGui::GetIO().DisplaySize;
std::vector<retro::overlay::Layer> layers = osd_.layers(SDL_GetTicksNS());
ImDrawList* dl = ImGui::GetBackgroundDrawList();
if (link_.replay_status().state==corelink::ReplayState::Recording) {
if (!diagnostics_recording_ && link_.replay_status().state==corelink::ReplayState::Recording) {
dl->AddCircleFilled(ImVec2(disp.x-88.f,26.f),6.f,IM_COL32(240,48,48,255));
dl->AddText(ImVec2(disp.x-74.f,18.f),IM_COL32(255,255,255,255),"REC");
}
Expand Down Expand Up @@ -928,7 +969,8 @@ void PlaySession::draw_replays_page() {
ImGui::TextDisabled("%s | %s",state_time_text(info.saved_unix).c_str(),replay_duration(info).c_str());
ImGui::TextWrapped("%s",info.path.filename().u8string().c_str());
ImGui::TextWrapped("Play starts a fresh process. Release controls once, then use a button or stick to take over. Playback saves stay private.");
ImGui::BeginDisabled(!link_.replays_supported() || state==corelink::ReplayState::Recording || !info.sealed);
ImGui::BeginDisabled(!link_.replays_supported() ||
(state == corelink::ReplayState::Recording && !diagnostics_recording_) || !info.sealed);
if (hov::action_button("Play",true)) replay_play_=info.path;
ImGui::EndDisabled(); ImGui::SameLine();
if (hov::action_button("Export copy",false)) {
Expand Down
Loading
Loading