Skip to content
Draft
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
- Now: each button is drawn where it sits on your controller: A at the bottom, B at the right, X at the left, Y at the top. A remapped button layout is followed the same way
- Until **Set up again** has run, the prompt stays as it was

### Link Play
- **Split screen:** two to four players on one PC (#684). **Link Play > Split screen > Start split screen** in the launcher runs the game once per player, each in a window of their own that shares the screen (two halves, or a quarter each), and the others join player 1's world on their own
- **Join player 1 automatically** (on): once every player has loaded their save, the others are taken to player 1's world. Nobody walks to the PC or opens the Link Play menu, and it works before the game unlocks Link Play, from the first minutes of a new game. A waiting screen covers a joining player's picture until they are there. Off: the players meet through the game's Link Play menu, as in any Link Play session
- **Start next to player 1** (on): a player who joined starts where player 1 stands, not at the PC, where the game lets a visitor arrive. A new game's first cave cannot be reached from the PC. Switch it off once player 1 can be reached from there
- Each player plays one controller; player 1 can play with the keyboard and mouse instead
- Every other player is a profile with a save of their own; one without a save starts from a copy of player 1's
- The other players' windows are silent unless you turn their sound on. Each game needs about 7 GB of memory: 32 GB is recommended for two players, 64 GB for four

### For developers
- Split screen is one process per player: the runtime's `[split]` keys (`runtime/include/nxrt/split.h`, `runtime/src/gfx/play/play_split.cpp`) keep a window in its part of the screen and give it one controller, the launcher's `split.rs` starts the group with those keys in each process's environment, and `pkp_save_uuid.cpp` gives a copied save a player UUID of its own
- `[split] meet` and `together` (`pkp_split_session.cpp`): the game layer makes the requests the game's multiplayer menu makes of its Link Play session manager (open a session, search, join), on the game thread, and takes a visitor to the first player with the game's own warp of a player. `pkp_wait_screen.{h,cpp}` is a waiting screen over the picture that any feature can show

## 0.13.8 (build Q: Quokka Hotfix a5)

**Update:** press **Update** in the launcher, then **Set up again** (it relinks the game; saves and shaders are kept, no shader is translated again).
Expand Down
5 changes: 4 additions & 1 deletion game-build/src/pkp_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,14 @@ int main(int argc, char** argv) {
nxrt::play::DisplayConfig disp;
if (!headless) {
disp = nxrt::play::display(); // controls.ini: window size, present mode, frame cap
nxrt::platform::init();
nxrt::platform::InitOptions po;
po.place_windows = disp.places_window;
nxrt::platform::init(po);
nxrt::platform::WindowDesc wd;
wd.title = nxrt::game::info().title;
wd.width = disp.width;
wd.height = disp.height;
wd.focusable = disp.takes_focus;
if (!nxrt::platform::create_window(wd)) die("cannot create the game window. The game needs a graphics driver with Vulkan 1.3: update the driver for your graphics card and try again. The reason is in pkp.log.");
}
nxrt::gfx::DeviceDesc dd;
Expand Down
45 changes: 35 additions & 10 deletions launcher/src-tauri/src/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ use crate::config::load_config;
use crate::guard::{ensure_idle, Need};
use crate::paths::game_dir_of;
use crate::readiness::readiness;
use crate::{play, profiles, settings};
use crate::{play, profiles, settings, split};

/// `without_mods`: this one start runs without mods (the runtime's [mods] off, passed in the game's environment only).
#[tauri::command]
pub fn play(app: AppHandle, without_mods: Option<bool>) -> Result<(), String> {
// an update may be preparing: Play waits only for its swap, and holds it off until this game has started (play::start)
let updates = app.updates();
let _swap = updates.hold_swap();
ensure_idle(&app, &[Need::Swap, Need::Storage])?;
let cfg = load_config(&app);
/// What both ways of starting the game check and write first: nothing that Play must wait for is busy, setup is finished, pkp.ini
/// names the dump and the active profile. Returns the game folder and the launcher's options.
fn ready_to_play(app: &AppHandle) -> Result<(std::path::PathBuf, crate::config::Config), String> {
ensure_idle(app, &[Need::Swap, Need::Storage])?;
let cfg = load_config(app);
let probe = readiness(&cfg);
if probe.readiness.kind != "ready" {
return Err(probe.readiness.detail);
Expand All @@ -29,7 +26,35 @@ pub fn play(app: AppHandle, without_mods: Option<bool>) -> Result<(), String> {
settings::ensure_play_paths(&dir, &paths.exefs, &paths.romfs, &paths.romfs_base, &paths.aoc_dir)?;
}
profiles::apply_active(&dir)?;
play::start(&app, &dir, &cfg, without_mods.unwrap_or(false))
Ok((dir, cfg))
}

/// `without_mods`: this one start runs without mods (the runtime's [mods] off, passed in the game's environment only).
#[tauri::command]
pub fn play(app: AppHandle, without_mods: Option<bool>) -> Result<(), String> {
// an update may be preparing: Play waits only for its swap, and holds it off until this game has started (play::start)
let updates = app.updates();
let _swap = updates.hold_swap();
let (dir, cfg) = ready_to_play(&app)?;
play::start(&app, &dir, &cfg, without_mods.unwrap_or(false), None)
}

/// Split screen: the game once per player, the active profile in the first window and the other players in theirs (split.rs).
#[tauri::command]
pub fn play_split(app: AppHandle, options: split::Options) -> Result<(), String> {
let updates = app.updates();
let _swap = updates.hold_swap();
// the other players' saves are made before the start: no game may hold the save folder open
ensure_idle(&app, &[Need::Game("The game is running. Close it first, then start split screen.")])?;
let (dir, cfg) = ready_to_play(&app)?;
let group = split::prepare(&dir, &options)?;
play::start(&app, &dir, &cfg, false, Some(group))
}

/// Who would play split screen: the active profile, and the profiles that can be the other players.
#[tauri::command]
pub fn split_players(app: AppHandle) -> split::Players {
split::players(&crate::config::game_dir(&app))
}

#[tauri::command]
Expand Down
3 changes: 3 additions & 0 deletions launcher/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ mod setup_job;
mod setuplog;
mod shader_archive;
mod shaders;
mod split;
mod steam;
mod steam_cmds;
mod states;
Expand Down Expand Up @@ -160,6 +161,8 @@ fn main() {
settings_cmds::write_settings,
settings_cmds::prompt_icon_pack,
launch::play,
launch::play_split,
launch::split_players,
setup_job::setup_status,
setup_job::start_setup,
setup_job::preflight,
Expand Down
44 changes: 36 additions & 8 deletions launcher/src-tauri/src/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ fn report_files(dir: &Path, started: SystemTime) -> Vec<ReportFile> {
.collect()
}

pub fn start(app: &AppHandle, game_dir: &Path, cfg: &Config, without_mods: bool) -> Result<(), String> {
/// `split`: split screen (split.rs). The game is started once per player, the other windows once the first runs, and they end with
/// the first. Everything else (the status, the save backups, the shaders afterwards) follows the first window, the player's own game.
pub fn start(app: &AppHandle, game_dir: &Path, cfg: &Config, without_mods: bool, split: Option<crate::split::Group>) -> Result<(), String> {
let (minimize, discord) = (cfg.minimize_on_play, cfg.discord_presence);
let gentle = cfg.gentle_build;
{
Expand Down Expand Up @@ -115,13 +117,18 @@ pub fn start(app: &AppHandle, game_dir: &Path, cfg: &Config, without_mods: bool)
eprintln!("branding: {e}");
}
// Calculate after shader preparation, immediately before the process starts, so a long preparation cannot age the offset.
let mut cmd = match crate::events::override_for(&dir).and_then(|clock| game_command(&exe, &dir, clock, without_mods)) {
let clock = crate::events::override_for(&dir);
let first_log = split.as_ref().map_or("pkp.log", |p| p.first.log.as_str());
let mut cmd = match clock.clone().and_then(|clock| game_command(&exe, &dir, clock, without_mods, first_log)) {
Ok(c) => c,
Err(e) => {
set_status(&app2, Status { state: GameState::Exited, crashed: true, message: format!("Could not start pkp.exe: {}", e), ..Default::default() });
return;
}
};
if let Some(pair) = &split {
pair.first.apply(&mut cmd);
}
let started = SystemTime::now();
let mut child = match cmd.spawn() {
Ok(c) => c,
Expand All @@ -130,7 +137,22 @@ pub fn start(app: &AppHandle, game_dir: &Path, cfg: &Config, without_mods: bool)
return;
}
};
set_status(&app2, Status { state: GameState::Running, message: format!("pkp.exe started (process {})", child.id()), ..Default::default() });
// split screen: the other windows, with the same clock. One that does not start leaves the others their game.
let mut others = vec![];
let mut window_notes = String::new();
for (i, window) in split.iter().flat_map(|group| &group.others).enumerate() {
let spawned = clock.clone().and_then(|clock| game_command(&exe, &dir, clock, without_mods, &window.log)).and_then(|mut c| {
window.apply(&mut c);
c.spawn().map_err(|e| e.to_string())
});
match spawned {
Ok(c) => others.push(c),
Err(e) => window_notes.push_str(&format!(" Window {} did not start: {}.", i + 2, e)),
}
}
// (the page reads the start of this message: action.js gamePhase)
let dot = if window_notes.is_empty() { "" } else { "." };
set_status(&app2, Status { state: GameState::Running, message: format!("pkp.exe started (process {}){}{}", child.id(), dot, window_notes), ..Default::default() });
if minimize {
if let Some(w) = app2.get_webview_window("main") {
let _ = w.minimize();
Expand All @@ -141,6 +163,11 @@ pub fn start(app: &AppHandle, game_dir: &Path, cfg: &Config, without_mods: bool)
let presence = crate::presence::Watch::start(discord);
let online = crate::online::Watch::start(&app2, &dir);
let result = wait_with_memory_guard(&mut child);
// the first window closed: the others go with it (one may have been closed before; then there is nothing to end)
for c in others.iter_mut() {
let _ = c.kill();
let _ = c.wait();
}
online.finish();
presence.finish();
backups.finish();
Expand Down Expand Up @@ -172,7 +199,7 @@ pub fn start(app: &AppHandle, game_dir: &Path, cfg: &Config, without_mods: bool)
(None, Some(c)) => format!("pkp.exe exited with code {} (0x{:08X}).", c, c as u32),
(None, None) => "pkp.exe was ended by the system.".to_string(),
};
set_status(&app2, Status { state: GameState::Exited, code, crashed, files, message: message + &prep + &shaders });
set_status(&app2, Status { state: GameState::Exited, code, crashed, files, message: message + &window_notes + &prep + &shaders });
if minimize {
if let Some(w) = app2.get_webview_window("main") {
let _ = w.unminimize();
Expand All @@ -184,15 +211,16 @@ pub fn start(app: &AppHandle, game_dir: &Path, cfg: &Config, without_mods: bool)
}

/// How Play starts the game: `pkp` in its folder on macOS and Linux, `pkp.exe` on Windows (host.rs). Every path (exefs, romfs, shader
/// cache) comes from pkp.ini next to it. `without_mods`: this start runs without mods.
fn game_command(exe: &Path, dir: &Path, clock: Option<crate::events::ClockOverride>, without_mods: bool) -> Result<std::process::Command, String> {
/// cache) comes from pkp.ini next to it. `without_mods`: this start runs without mods. `log`: the log file, relative to the folder
/// (pkp.log; split screen's other windows have their own).
fn game_command(exe: &Path, dir: &Path, clock: Option<crate::events::ClockOverride>, without_mods: bool, log: &str) -> Result<std::process::Command, String> {
if !crate::host::native_game() {
crate::host::sync_runtime_files(&crate::paths::exe_dir(), dir)?; // pkp_rt.dll and the ASTC decoders: Windows files
}
#[cfg(target_os = "macos")]
crate::host::sync_macos_runtime(dir)?; // libpkp_rt.dylib and MoltenVK: a launcher update brings newer ones
let mut cmd = std::process::Command::new(exe);
cmd.current_dir(dir).args(["--log", "pkp.log"]);
cmd.current_dir(dir).args(["--log", log]);
// macOS: the folder is not the release's installed layout (no exefs/main next to the binary), so name the settings file;
// the game reads exefs and romfs from it.
if crate::host::native_game() && dir.join(crate::settings::PKP_INI).is_file() {
Expand Down Expand Up @@ -259,7 +287,7 @@ pub fn run_cli(game_dir: &Path, tools: &Path) -> i32 {
Err(e) => return fail(e),
};
let backups = crate::savebackup::Watch::start(game_dir); // the same save backups as Play in the window
let status = game_command(&exe, game_dir, clock, false).and_then(|mut c| {
let status = game_command(&exe, game_dir, clock, false, "pkp.log").and_then(|mut c| {
let mut child = c.spawn().map_err(|e| format!("Could not start {}: {}", crate::host::game_exe_name(), e))?;
wait_with_memory_guard(&mut child).map_err(|e| format!("Lost track of {}: {}", crate::host::game_exe_name(), e))
});
Expand Down
24 changes: 20 additions & 4 deletions launcher/src-tauri/src/saveimport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,31 @@ fn put_back(old: &[PathBuf], bacc: &Path) {
/// Brings `src` (a folder holding G00 and S00, optionally B00) in as the game's committed account save. The source is only read. The
/// caller has checked that the game is not running.
pub fn import(save_dir: &Path, key: &str, src: &Path) -> Result<Report, String> {
let canon = |p: &Path| fs::canonicalize(p).unwrap_or_else(|_| p.to_path_buf());
if is_save_folder(src) && canon(src).starts_with(canon(save_dir)) {
return Err(format!("{} is inside the save folder the game plays. Pick a copy outside it.", fwd(src)));
}
place(save_dir, key, src)
}

/// One account's save as a copy of another's in the same save folder (split screen's second player starts from the first player's
/// save). Only for an account that has no save yet: `to_key`'s folder must not exist. The source is only read; the caller has checked
/// that the game is not running.
pub fn copy_account(save_dir: &Path, from_key: &str, to_key: &str) -> Result<Report, String> {
let acc = save_dir.join("account");
if from_key == to_key || acc.join(to_key).exists() {
return Err(format!("{} already holds a save.", fwd(&acc.join(to_key))));
}
place(save_dir, to_key, &acc.join(from_key))
}

/// The copy itself: `src` staged beside the account folder, an old save moved aside, the copy put in its place, its .meta written.
fn place(save_dir: &Path, key: &str, src: &Path) -> Result<Report, String> {
if !is_save_folder(src) {
return Err(format!("{} holds no Pokopia save (no G00 and S00 folders).", fwd(src)));
}
let acc = save_dir.join("account");
let root = acc.join(key);
let canon = |p: &Path| fs::canonicalize(p).unwrap_or_else(|_| p.to_path_buf());
if canon(src).starts_with(canon(save_dir)) {
return Err(format!("{} is inside the save folder the game plays. Pick a copy outside it.", fwd(src)));
}
fs::create_dir_all(&acc).map_err(|e| format!("Cannot create {}: {}", fwd(&acc), e))?;
let t = crate::fsutil::file_stamp();

Expand Down
Loading
Loading