implements PLN-0140
This commit is contained in:
parent
29e002c5f3
commit
1b29b2f985
@ -170,6 +170,14 @@ impl Firmware {
|
|||||||
|
|
||||||
pub fn request_home_from_host(&mut self) {
|
pub fn request_home_from_host(&mut self) {
|
||||||
self.os.info(LogSource::Pos, "Host requested Home/SystemOS".to_string());
|
self.os.info(LogSource::Pos, "Host requested Home/SystemOS".to_string());
|
||||||
|
if let FirmwareState::GameRunning(step) = &self.state {
|
||||||
|
if let Err(error) = self.os.lifecycle().request_home_from_game(step.task_id) {
|
||||||
|
self.os.warn(
|
||||||
|
LogSource::Pos,
|
||||||
|
format!("Home/SystemOS request could not pause Game: {error:?}"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +196,10 @@ mod tests {
|
|||||||
use prometeu_system::process::ProcessState;
|
use prometeu_system::process::ProcessState;
|
||||||
use prometeu_system::task::{TaskId, TaskState};
|
use prometeu_system::task::{TaskId, TaskState};
|
||||||
use prometeu_system::windows::WindowOwner;
|
use prometeu_system::windows::WindowOwner;
|
||||||
use prometeu_system::{CrashReport, discover_games_root};
|
use prometeu_system::{
|
||||||
|
CrashReport, ForegroundOwner, GameLifecycleEventKind, ResidentGameState,
|
||||||
|
discover_games_root,
|
||||||
|
};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::atomic::{AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicU64, Ordering};
|
||||||
@ -732,6 +743,44 @@ mod tests {
|
|||||||
assert_eq!(firmware.os.windows().window_count(), 0);
|
assert_eq!(firmware.os.windows().window_count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn host_home_request_pauses_then_suspends_game_before_next_vm_tick() {
|
||||||
|
let mut firmware = Firmware::new(None);
|
||||||
|
let mut platform = TestPlatform::new();
|
||||||
|
let signals = InputSignals::default();
|
||||||
|
|
||||||
|
firmware.load_cartridge(valid_cartridge(AppMode::Game));
|
||||||
|
firmware.tick(&signals, &mut platform);
|
||||||
|
|
||||||
|
let task_id = match &firmware.state {
|
||||||
|
FirmwareState::GameRunning(step) => step.task_id,
|
||||||
|
other => panic!("expected GameRunning state, got {:?}", other),
|
||||||
|
};
|
||||||
|
let tick_index_before_home = firmware.os.vm().tick_index();
|
||||||
|
|
||||||
|
firmware.request_home_from_host();
|
||||||
|
|
||||||
|
assert_eq!(firmware.os.lifecycle().foreground_owner(), ForegroundOwner::Game(task_id));
|
||||||
|
assert_eq!(
|
||||||
|
firmware.os.lifecycle().resident_game().map(|game| game.state),
|
||||||
|
Some(ResidentGameState::PauseRequested { remaining_ticks: 1 })
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
firmware.os.lifecycle().pending_game_lifecycle_events().last().map(|event| event.kind),
|
||||||
|
Some(GameLifecycleEventKind::Pause)
|
||||||
|
);
|
||||||
|
|
||||||
|
firmware.tick(&signals, &mut platform);
|
||||||
|
|
||||||
|
assert!(matches!(firmware.state, FirmwareState::HubHome(_)));
|
||||||
|
assert_eq!(firmware.os.lifecycle().task_state(task_id), Some(TaskState::Suspended));
|
||||||
|
assert_eq!(
|
||||||
|
firmware.os.lifecycle().process_state_for_task(task_id),
|
||||||
|
Ok(ProcessState::Suspended)
|
||||||
|
);
|
||||||
|
assert_eq!(firmware.os.vm().tick_index(), tick_index_before_home);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn direct_game_boot_does_not_depend_on_userland_run_cart_syscall() {
|
fn direct_game_boot_does_not_depend_on_userland_run_cart_syscall() {
|
||||||
assert!(Syscall::from_u32(0x0002).is_none());
|
assert!(Syscall::from_u32(0x0002).is_none());
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use crate::firmware::firmware_state::{AppCrashesStep, FirmwareState};
|
use crate::firmware::firmware_state::{AppCrashesStep, FirmwareState, HubHomeStep};
|
||||||
use crate::firmware::prometeu_context::PrometeuContext;
|
use crate::firmware::prometeu_context::PrometeuContext;
|
||||||
use prometeu_hal::log::{LogLevel, LogSource};
|
use prometeu_hal::log::{LogLevel, LogSource};
|
||||||
use prometeu_system::CrashReport;
|
use prometeu_system::CrashReport;
|
||||||
@ -36,6 +36,19 @@ impl GameRunningStep {
|
|||||||
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match ctx.os.lifecycle().advance_game_pause_budget(self.task_id) {
|
||||||
|
Ok(true) => return Some(FirmwareState::HubHome(HubHomeStep)),
|
||||||
|
Ok(false) => {}
|
||||||
|
Err(_) => {
|
||||||
|
let report = CrashReport::VmPanic {
|
||||||
|
message: "failed to advance game pause budget".to_string(),
|
||||||
|
pc: None,
|
||||||
|
};
|
||||||
|
let _ = ctx.os.lifecycle().crash_task(self.task_id, Some(&report));
|
||||||
|
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let result = ctx.os.vm().tick(ctx.vm, ctx.signals, ctx.platform);
|
let result = ctx.os.vm().tick(ctx.vm, ctx.signals, ctx.platform);
|
||||||
|
|
||||||
if let Some(report) = result {
|
if let Some(report) = result {
|
||||||
|
|||||||
@ -4,7 +4,10 @@ mod programs;
|
|||||||
mod services;
|
mod services;
|
||||||
|
|
||||||
pub use crash_report::CrashReport;
|
pub use crash_report::CrashReport;
|
||||||
pub use os::{LifecycleError, LifecycleOperation, SystemOS};
|
pub use os::{
|
||||||
|
DEFAULT_GAME_PAUSE_BUDGET_TICKS, GameLifecycleEvent, GameLifecycleEventKind, LifecycleError,
|
||||||
|
LifecycleOperation, SystemOS,
|
||||||
|
};
|
||||||
pub use programs::{NativeShellApp, PrometeuHub, SystemProfileAction, SystemProfileUpdate};
|
pub use programs::{NativeShellApp, PrometeuHub, SystemProfileAction, SystemProfileUpdate};
|
||||||
pub use prometeu_hal::{RenderWorkerBackend, RenderWorkerFrameSink};
|
pub use prometeu_hal::{RenderWorkerBackend, RenderWorkerFrameSink};
|
||||||
pub use services::async_work::{
|
pub use services::async_work::{
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
use crate::CrashReport;
|
use crate::CrashReport;
|
||||||
use crate::os::SystemOS;
|
use crate::os::SystemOS;
|
||||||
use crate::os::{LifecycleError, LifecycleOperation};
|
use crate::os::{
|
||||||
|
DEFAULT_GAME_PAUSE_BUDGET_TICKS, GameLifecycleEvent, GameLifecycleEventKind, LifecycleError,
|
||||||
|
LifecycleOperation,
|
||||||
|
};
|
||||||
use crate::process::{ProcessId, ProcessState};
|
use crate::process::{ProcessId, ProcessState};
|
||||||
use crate::services::foreground::{ForegroundOwner, ForegroundStackError, ResidentGame};
|
use crate::services::foreground::{
|
||||||
|
ForegroundOwner, ForegroundStackError, ResidentGame, ResidentGameState,
|
||||||
|
};
|
||||||
use crate::task::{TaskId, TaskKind, TaskState};
|
use crate::task::{TaskId, TaskKind, TaskState};
|
||||||
|
|
||||||
pub struct LifecycleFacade<'a> {
|
pub struct LifecycleFacade<'a> {
|
||||||
@ -79,15 +84,47 @@ impl<'a> LifecycleFacade<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_home_from_game(&mut self, task_id: TaskId) -> Result<(), LifecycleError> {
|
pub fn request_home_from_game(&mut self, task_id: TaskId) -> Result<(), LifecycleError> {
|
||||||
let process_id = process_id_for_task(self.os, task_id)?;
|
let _process_id = process_id_for_task(self.os, task_id)?;
|
||||||
|
let previous = self.os.foreground_stack.resident_game();
|
||||||
|
|
||||||
self.os.foreground_stack.request_home_from_game(task_id).map_err(map_foreground_error)?;
|
self.os
|
||||||
self.os.task_manager.mark_suspended(task_id);
|
.foreground_stack
|
||||||
self.os.process_manager.mark_suspended(process_id);
|
.request_home_from_game(task_id, DEFAULT_GAME_PAUSE_BUDGET_TICKS)
|
||||||
|
.map_err(map_foreground_error)?;
|
||||||
|
|
||||||
|
if !matches!(
|
||||||
|
previous.map(|game| game.state),
|
||||||
|
Some(ResidentGameState::PauseRequested { .. } | ResidentGameState::PausedSuspended)
|
||||||
|
) {
|
||||||
|
self.os
|
||||||
|
.game_lifecycle_events
|
||||||
|
.push(GameLifecycleEvent { task_id, kind: GameLifecycleEventKind::Pause });
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn advance_game_pause_budget(&mut self, task_id: TaskId) -> Result<bool, LifecycleError> {
|
||||||
|
let expired =
|
||||||
|
self.os.foreground_stack.advance_pause_budget(task_id).map_err(map_foreground_error)?;
|
||||||
|
|
||||||
|
if expired {
|
||||||
|
let process_id = process_id_for_task(self.os, task_id)?;
|
||||||
|
self.os.task_manager.mark_suspended(task_id);
|
||||||
|
self.os.process_manager.mark_suspended(process_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(expired)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pending_game_lifecycle_events(&self) -> &[GameLifecycleEvent] {
|
||||||
|
&self.os.game_lifecycle_events
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn take_game_lifecycle_events(&mut self) -> Vec<GameLifecycleEvent> {
|
||||||
|
std::mem::take(&mut self.os.game_lifecycle_events)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn return_to_hub(&mut self) {
|
pub fn return_to_hub(&mut self) {
|
||||||
self.os.foreground_stack.return_to_hub();
|
self.os.foreground_stack.return_to_hub();
|
||||||
self.os.task_manager.clear_foreground();
|
self.os.task_manager.clear_foreground();
|
||||||
@ -102,7 +139,11 @@ impl<'a> LifecycleFacade<'a> {
|
|||||||
ForegroundOwner::Game(owner) if owner == task_id => {
|
ForegroundOwner::Game(owner) if owner == task_id => {
|
||||||
self.os
|
self.os
|
||||||
.foreground_stack
|
.foreground_stack
|
||||||
.request_home_from_game(task_id)
|
.request_home_from_game(task_id, DEFAULT_GAME_PAUSE_BUDGET_TICKS)
|
||||||
|
.map_err(map_foreground_error)?;
|
||||||
|
self.os
|
||||||
|
.foreground_stack
|
||||||
|
.advance_pause_budget(task_id)
|
||||||
.map_err(map_foreground_error)?;
|
.map_err(map_foreground_error)?;
|
||||||
}
|
}
|
||||||
ForegroundOwner::Shell(owner) if owner == task_id => {
|
ForegroundOwner::Shell(owner) if owner == task_id => {
|
||||||
@ -132,10 +173,18 @@ impl<'a> LifecycleFacade<'a> {
|
|||||||
TaskKind::Game => {
|
TaskKind::Game => {
|
||||||
self.os
|
self.os
|
||||||
.foreground_stack
|
.foreground_stack
|
||||||
.set_game_foreground(task_id)
|
.request_resume_game(task_id)
|
||||||
.map_err(map_foreground_error)?;
|
.map_err(map_foreground_error)?;
|
||||||
self.os.task_manager.set_foreground(task_id);
|
self.os.task_manager.set_foreground(task_id);
|
||||||
self.os.process_manager.mark_running(process_id);
|
self.os.process_manager.mark_running(process_id);
|
||||||
|
self.os.game_lifecycle_events.push(GameLifecycleEvent {
|
||||||
|
task_id,
|
||||||
|
kind: GameLifecycleEventKind::ResumeForeground,
|
||||||
|
});
|
||||||
|
self.os
|
||||||
|
.foreground_stack
|
||||||
|
.complete_resume_game(task_id)
|
||||||
|
.map_err(map_foreground_error)?;
|
||||||
}
|
}
|
||||||
TaskKind::Shell => {
|
TaskKind::Shell => {
|
||||||
self.os
|
self.os
|
||||||
|
|||||||
@ -1,6 +1,20 @@
|
|||||||
use crate::process::ProcessId;
|
use crate::process::ProcessId;
|
||||||
use crate::task::{TaskId, TaskState};
|
use crate::task::{TaskId, TaskState};
|
||||||
|
|
||||||
|
pub const DEFAULT_GAME_PAUSE_BUDGET_TICKS: u8 = 1;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum GameLifecycleEventKind {
|
||||||
|
Pause,
|
||||||
|
ResumeForeground,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub struct GameLifecycleEvent {
|
||||||
|
pub task_id: TaskId,
|
||||||
|
pub kind: GameLifecycleEventKind,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum LifecycleOperation {
|
pub enum LifecycleOperation {
|
||||||
SetForeground,
|
SetForeground,
|
||||||
|
|||||||
@ -3,5 +3,8 @@ mod lifecycle;
|
|||||||
mod system_os;
|
mod system_os;
|
||||||
|
|
||||||
pub use facades::{FsFacade, LifecycleFacade, SessionsFacade, VmFacade, WindowFacade};
|
pub use facades::{FsFacade, LifecycleFacade, SessionsFacade, VmFacade, WindowFacade};
|
||||||
pub use lifecycle::{LifecycleError, LifecycleOperation};
|
pub use lifecycle::{
|
||||||
|
DEFAULT_GAME_PAUSE_BUDGET_TICKS, GameLifecycleEvent, GameLifecycleEventKind, LifecycleError,
|
||||||
|
LifecycleOperation,
|
||||||
|
};
|
||||||
pub use system_os::SystemOS;
|
pub use system_os::SystemOS;
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
use crate::VirtualMachineRuntime;
|
use crate::VirtualMachineRuntime;
|
||||||
use crate::fs::{FsState, VirtualFS};
|
use crate::fs::{FsState, VirtualFS};
|
||||||
use crate::os::{FsFacade, LifecycleFacade, SessionsFacade, VmFacade, WindowFacade};
|
use crate::os::{
|
||||||
|
FsFacade, GameLifecycleEvent, LifecycleFacade, SessionsFacade, VmFacade, WindowFacade,
|
||||||
|
};
|
||||||
use crate::process::ProcessManager;
|
use crate::process::ProcessManager;
|
||||||
use crate::services::foreground::ForegroundStack;
|
use crate::services::foreground::ForegroundStack;
|
||||||
use crate::services::memcard::MemcardService;
|
use crate::services::memcard::MemcardService;
|
||||||
@ -16,6 +18,7 @@ pub struct SystemOS {
|
|||||||
pub(super) process_manager: ProcessManager,
|
pub(super) process_manager: ProcessManager,
|
||||||
pub(super) task_manager: TaskManager,
|
pub(super) task_manager: TaskManager,
|
||||||
pub(super) foreground_stack: ForegroundStack,
|
pub(super) foreground_stack: ForegroundStack,
|
||||||
|
pub(super) game_lifecycle_events: Vec<GameLifecycleEvent>,
|
||||||
pub(super) window_manager: WindowManager,
|
pub(super) window_manager: WindowManager,
|
||||||
pub(super) log_service: LogService,
|
pub(super) log_service: LogService,
|
||||||
pub(super) fs: VirtualFS,
|
pub(super) fs: VirtualFS,
|
||||||
@ -36,6 +39,7 @@ impl SystemOS {
|
|||||||
process_manager: ProcessManager::new(),
|
process_manager: ProcessManager::new(),
|
||||||
task_manager: TaskManager::new(),
|
task_manager: TaskManager::new(),
|
||||||
foreground_stack: ForegroundStack::new(),
|
foreground_stack: ForegroundStack::new(),
|
||||||
|
game_lifecycle_events: Vec::new(),
|
||||||
window_manager: WindowManager::new(),
|
window_manager: WindowManager::new(),
|
||||||
log_service,
|
log_service,
|
||||||
fs: VirtualFS::new(),
|
fs: VirtualFS::new(),
|
||||||
@ -136,7 +140,7 @@ impl SystemOS {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::os::{LifecycleError, LifecycleOperation};
|
use crate::os::{GameLifecycleEventKind, LifecycleError, LifecycleOperation};
|
||||||
use crate::process::ProcessState;
|
use crate::process::ProcessState;
|
||||||
use crate::services::foreground::{ForegroundOwner, ResidentGame, ResidentGameState};
|
use crate::services::foreground::{ForegroundOwner, ResidentGame, ResidentGameState};
|
||||||
use crate::task::{TaskId, TaskState};
|
use crate::task::{TaskId, TaskState};
|
||||||
@ -195,12 +199,30 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn home_request_moves_game_to_resident_suspended_and_hub_foreground() {
|
fn home_request_notifies_game_before_budget_suspends_it() {
|
||||||
let mut os = SystemOS::new(None);
|
let mut os = SystemOS::new(None);
|
||||||
let task_id = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
let task_id = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||||
|
|
||||||
os.lifecycle().request_home_from_game(task_id).expect("home request should succeed");
|
os.lifecycle().request_home_from_game(task_id).expect("home request should succeed");
|
||||||
|
|
||||||
|
assert_eq!(os.lifecycle().foreground_owner(), ForegroundOwner::Game(task_id));
|
||||||
|
assert_eq!(
|
||||||
|
os.lifecycle().resident_game(),
|
||||||
|
Some(ResidentGame {
|
||||||
|
task_id,
|
||||||
|
state: ResidentGameState::PauseRequested { remaining_ticks: 1 },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
os.lifecycle().pending_game_lifecycle_events()[0].kind,
|
||||||
|
GameLifecycleEventKind::Pause
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
os.task_manager.get(task_id).expect("task should exist").state,
|
||||||
|
TaskState::Foreground
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(os.lifecycle().advance_game_pause_budget(task_id).expect("budget should advance"));
|
||||||
assert_eq!(os.lifecycle().foreground_owner(), ForegroundOwner::Hub);
|
assert_eq!(os.lifecycle().foreground_owner(), ForegroundOwner::Hub);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
os.lifecycle().resident_game(),
|
os.lifecycle().resident_game(),
|
||||||
@ -218,6 +240,7 @@ mod tests {
|
|||||||
let mut os = SystemOS::new(None);
|
let mut os = SystemOS::new(None);
|
||||||
let game = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
let game = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||||
os.lifecycle().request_home_from_game(game).expect("home request should succeed");
|
os.lifecycle().request_home_from_game(game).expect("home request should succeed");
|
||||||
|
os.lifecycle().advance_game_pause_budget(game).expect("budget should expire");
|
||||||
let shell = os.sessions().create_vm_shell_task(7, "Settings");
|
let shell = os.sessions().create_vm_shell_task(7, "Settings");
|
||||||
|
|
||||||
assert_eq!(os.lifecycle().foreground_owner(), ForegroundOwner::Shell(shell));
|
assert_eq!(os.lifecycle().foreground_owner(), ForegroundOwner::Shell(shell));
|
||||||
@ -284,6 +307,10 @@ mod tests {
|
|||||||
TaskState::Foreground
|
TaskState::Foreground
|
||||||
);
|
);
|
||||||
assert_eq!(process_state_for_task(&os, task_id), ProcessState::Running);
|
assert_eq!(process_state_for_task(&os, task_id), ProcessState::Running);
|
||||||
|
assert_eq!(
|
||||||
|
os.lifecycle().pending_game_lifecycle_events().last().map(|event| event.kind),
|
||||||
|
Some(GameLifecycleEventKind::ResumeForeground)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@ -10,6 +10,8 @@ pub enum ForegroundOwner {
|
|||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum ResidentGameState {
|
pub enum ResidentGameState {
|
||||||
Foreground,
|
Foreground,
|
||||||
|
PauseRequested { remaining_ticks: u8 },
|
||||||
|
ResumeRequested,
|
||||||
PausedSuspended,
|
PausedSuspended,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,12 +72,81 @@ impl ForegroundStack {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_home_from_game(&mut self, task_id: TaskId) -> Result<(), ForegroundStackError> {
|
pub fn request_home_from_game(
|
||||||
|
&mut self,
|
||||||
|
task_id: TaskId,
|
||||||
|
pause_budget_ticks: u8,
|
||||||
|
) -> Result<(), ForegroundStackError> {
|
||||||
match self.resident_game {
|
match self.resident_game {
|
||||||
Some(game) if game.task_id == task_id => {
|
Some(game) if game.task_id == task_id => {
|
||||||
|
if !matches!(
|
||||||
|
game.state,
|
||||||
|
ResidentGameState::PauseRequested { .. } | ResidentGameState::PausedSuspended
|
||||||
|
) {
|
||||||
|
self.resident_game = Some(ResidentGame {
|
||||||
|
task_id,
|
||||||
|
state: ResidentGameState::PauseRequested {
|
||||||
|
remaining_ticks: pause_budget_ticks.max(1),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => Err(ForegroundStackError::TaskIsNotResidentGame(task_id)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn advance_pause_budget(&mut self, task_id: TaskId) -> Result<bool, ForegroundStackError> {
|
||||||
|
match self.resident_game {
|
||||||
|
Some(game)
|
||||||
|
if game.task_id == task_id
|
||||||
|
&& matches!(
|
||||||
|
game.state,
|
||||||
|
ResidentGameState::PauseRequested { remaining_ticks: 1 }
|
||||||
|
) =>
|
||||||
|
{
|
||||||
self.resident_game =
|
self.resident_game =
|
||||||
Some(ResidentGame { task_id, state: ResidentGameState::PausedSuspended });
|
Some(ResidentGame { task_id, state: ResidentGameState::PausedSuspended });
|
||||||
self.owner = ForegroundOwner::Hub;
|
self.owner = ForegroundOwner::Hub;
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
Some(game)
|
||||||
|
if game.task_id == task_id
|
||||||
|
&& matches!(game.state, ResidentGameState::PauseRequested { .. }) =>
|
||||||
|
{
|
||||||
|
let ResidentGameState::PauseRequested { remaining_ticks } = game.state else {
|
||||||
|
unreachable!();
|
||||||
|
};
|
||||||
|
self.resident_game = Some(ResidentGame {
|
||||||
|
task_id,
|
||||||
|
state: ResidentGameState::PauseRequested {
|
||||||
|
remaining_ticks: remaining_ticks.saturating_sub(1).max(1),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
Some(game) if game.task_id == task_id => Ok(false),
|
||||||
|
_ => Err(ForegroundStackError::TaskIsNotResidentGame(task_id)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn request_resume_game(&mut self, task_id: TaskId) -> Result<(), ForegroundStackError> {
|
||||||
|
match self.resident_game {
|
||||||
|
Some(game) if game.task_id == task_id => {
|
||||||
|
self.resident_game =
|
||||||
|
Some(ResidentGame { task_id, state: ResidentGameState::ResumeRequested });
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => Err(ForegroundStackError::TaskIsNotResidentGame(task_id)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn complete_resume_game(&mut self, task_id: TaskId) -> Result<(), ForegroundStackError> {
|
||||||
|
match self.resident_game {
|
||||||
|
Some(game) if game.task_id == task_id => {
|
||||||
|
self.resident_game =
|
||||||
|
Some(ResidentGame { task_id, state: ResidentGameState::Foreground });
|
||||||
|
self.owner = ForegroundOwner::Game(task_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(ForegroundStackError::TaskIsNotResidentGame(task_id)),
|
_ => Err(ForegroundStackError::TaskIsNotResidentGame(task_id)),
|
||||||
@ -159,13 +230,32 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn home_request_moves_resident_game_to_paused_suspended() {
|
fn home_request_moves_resident_game_to_pause_requested() {
|
||||||
let mut stack = ForegroundStack::new();
|
let mut stack = ForegroundStack::new();
|
||||||
let game = TaskId(3);
|
let game = TaskId(3);
|
||||||
|
|
||||||
stack.set_game_foreground(game).expect("game should be foreground");
|
stack.set_game_foreground(game).expect("game should be foreground");
|
||||||
stack.request_home_from_game(game).expect("home request should suspend game");
|
stack.request_home_from_game(game, 2).expect("home request should pause game");
|
||||||
|
|
||||||
|
assert_eq!(stack.owner(), ForegroundOwner::Game(game));
|
||||||
|
assert_eq!(
|
||||||
|
stack.resident_game(),
|
||||||
|
Some(ResidentGame {
|
||||||
|
task_id: game,
|
||||||
|
state: ResidentGameState::PauseRequested { remaining_ticks: 2 },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pause_budget_expiry_suspends_game_and_returns_to_hub() {
|
||||||
|
let mut stack = ForegroundStack::new();
|
||||||
|
let game = TaskId(3);
|
||||||
|
|
||||||
|
stack.set_game_foreground(game).expect("game should be foreground");
|
||||||
|
stack.request_home_from_game(game, 1).expect("home request should pause game");
|
||||||
|
|
||||||
|
assert!(stack.advance_pause_budget(game).expect("budget should advance"));
|
||||||
assert_eq!(stack.owner(), ForegroundOwner::Hub);
|
assert_eq!(stack.owner(), ForegroundOwner::Hub);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stack.resident_game(),
|
stack.resident_game(),
|
||||||
@ -173,6 +263,30 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn resume_request_precedes_game_foreground_restore() {
|
||||||
|
let mut stack = ForegroundStack::new();
|
||||||
|
let game = TaskId(3);
|
||||||
|
|
||||||
|
stack.set_game_foreground(game).expect("game should be foreground");
|
||||||
|
stack.request_home_from_game(game, 1).expect("home request should pause game");
|
||||||
|
stack.advance_pause_budget(game).expect("budget should expire");
|
||||||
|
|
||||||
|
stack.request_resume_game(game).expect("resume should be requested");
|
||||||
|
assert_eq!(stack.owner(), ForegroundOwner::Hub);
|
||||||
|
assert_eq!(
|
||||||
|
stack.resident_game(),
|
||||||
|
Some(ResidentGame { task_id: game, state: ResidentGameState::ResumeRequested })
|
||||||
|
);
|
||||||
|
|
||||||
|
stack.complete_resume_game(game).expect("resume should complete");
|
||||||
|
assert_eq!(stack.owner(), ForegroundOwner::Game(game));
|
||||||
|
assert_eq!(
|
||||||
|
stack.resident_game(),
|
||||||
|
Some(ResidentGame { task_id: game, state: ResidentGameState::Foreground })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn shell_foreground_keeps_resident_game() {
|
fn shell_foreground_keeps_resident_game() {
|
||||||
let mut stack = ForegroundStack::new();
|
let mut stack = ForegroundStack::new();
|
||||||
@ -180,7 +294,8 @@ mod tests {
|
|||||||
let shell = TaskId(4);
|
let shell = TaskId(4);
|
||||||
|
|
||||||
stack.set_game_foreground(game).expect("game should be foreground");
|
stack.set_game_foreground(game).expect("game should be foreground");
|
||||||
stack.request_home_from_game(game).expect("home request should suspend game");
|
stack.request_home_from_game(game, 1).expect("home request should suspend game");
|
||||||
|
stack.advance_pause_budget(game).expect("budget should expire");
|
||||||
stack.set_shell_foreground(shell).expect("shell should become foreground");
|
stack.set_shell_foreground(shell).expect("shell should become foreground");
|
||||||
|
|
||||||
assert_eq!(stack.owner(), ForegroundOwner::Shell(shell));
|
assert_eq!(stack.owner(), ForegroundOwner::Shell(shell));
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
{"type":"discussion","id":"DSC-0043","status":"open","ticket":"system-os-cartridge-switch-orchestrator","title":"SystemOS Cartridge Switch Orchestrator","created_at":"2026-07-03","updated_at":"2026-07-03","tags":["runtime","os","lifecycle","game","cartridge","architecture"],"agendas":[{"id":"AGD-0044","file":"AGD-0044-systemos-cartridge-switch-orchestrator.md","status":"open","created_at":"2026-07-03","updated_at":"2026-07-03"}],"decisions":[],"plans":[],"lessons":[]}
|
{"type":"discussion","id":"DSC-0043","status":"open","ticket":"system-os-cartridge-switch-orchestrator","title":"SystemOS Cartridge Switch Orchestrator","created_at":"2026-07-03","updated_at":"2026-07-03","tags":["runtime","os","lifecycle","game","cartridge","architecture"],"agendas":[{"id":"AGD-0044","file":"AGD-0044-systemos-cartridge-switch-orchestrator.md","status":"open","created_at":"2026-07-03","updated_at":"2026-07-03"}],"decisions":[],"plans":[],"lessons":[]}
|
||||||
{"type":"discussion","id":"DSC-0039","status":"abandoned","ticket":"render-pipeline-family-and-future-3d","title":"Render Pipeline Family and Future 3D","created_at":"2026-06-04","updated_at":"2026-06-04","tags":["gfx","renderer","runtime","architecture","pipeline"],"agendas":[{"id":"AGD-0039","file":"AGD-0039-render-pipeline-family-and-future-3d.md","status":"abandoned","created_at":"2026-06-04","updated_at":"2026-06-04","_override_reason":"User explicitly chose to close this agenda without a new decision because DSC-0038 already established enough architecture for future extension, and 3D is intentionally deferred."}],"decisions":[],"plans":[],"lessons":[],"_override_reason":"User explicitly chose to close this agenda without a new decision because DSC-0038 already established enough architecture for future extension, and 3D is intentionally deferred."}
|
{"type":"discussion","id":"DSC-0039","status":"abandoned","ticket":"render-pipeline-family-and-future-3d","title":"Render Pipeline Family and Future 3D","created_at":"2026-06-04","updated_at":"2026-06-04","tags":["gfx","renderer","runtime","architecture","pipeline"],"agendas":[{"id":"AGD-0039","file":"AGD-0039-render-pipeline-family-and-future-3d.md","status":"abandoned","created_at":"2026-06-04","updated_at":"2026-06-04","_override_reason":"User explicitly chose to close this agenda without a new decision because DSC-0038 already established enough architecture for future extension, and 3D is intentionally deferred."}],"decisions":[],"plans":[],"lessons":[],"_override_reason":"User explicitly chose to close this agenda without a new decision because DSC-0038 already established enough architecture for future extension, and 3D is intentionally deferred."}
|
||||||
{"type":"discussion","id":"DSC-0040","status":"done","ticket":"vm-render-parallel-execution-boundary","title":"VM and Render Parallel Execution Boundary","created_at":"2026-06-04","updated_at":"2026-06-06","tags":["runtime","renderer","vm","concurrency","architecture","perf"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0048","file":"discussion/lessons/DSC-0040-vm-render-parallel-execution-boundary/LSN-0048-render-workers-need-a-closed-packet-contract.md","status":"done","created_at":"2026-06-06","updated_at":"2026-06-06"}]}
|
{"type":"discussion","id":"DSC-0040","status":"done","ticket":"vm-render-parallel-execution-boundary","title":"VM and Render Parallel Execution Boundary","created_at":"2026-06-04","updated_at":"2026-06-06","tags":["runtime","renderer","vm","concurrency","architecture","perf"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0048","file":"discussion/lessons/DSC-0040-vm-render-parallel-execution-boundary/LSN-0048-render-workers-need-a-closed-packet-contract.md","status":"done","created_at":"2026-06-06","updated_at":"2026-06-06"}]}
|
||||||
{"type":"discussion","id":"DSC-0041","status":"in_progress","ticket":"foreground-stack-game-pause-shell-vm-backed","title":"Foreground Stack, Game Pause, and VM-Backed Shell Coexistence","created_at":"2026-06-05","updated_at":"2026-07-03","tags":["runtime","os","lifecycle","shell","game","vm","foreground","architecture"],"agendas":[{"id":"AGD-0041","file":"AGD-0041-foreground-stack-game-pause-shell-vm-backed.md","status":"accepted","created_at":"2026-06-05","updated_at":"2026-07-03"}],"decisions":[{"id":"DEC-0037","file":"DEC-0037-foreground-stack-and-game-pause-contract.md","status":"accepted","created_at":"2026-07-03","updated_at":"2026-07-03","ref_agenda":"AGD-0041"}],"plans":[{"id":"PLN-0136","file":"PLN-0136-route-desktop-home-key-outside-guest-input.md","status":"done","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0137","file":"PLN-0137-implement-systemos-foreground-stack-state.md","status":"done","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0138","file":"PLN-0138-specify-foreground-pause-and-home-contract.md","status":"done","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0139","file":"PLN-0139-validate-game-home-shell-game-end-to-end.md","status":"open","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0140","file":"PLN-0140-deliver-game-pause-resume-and-suspension.md","status":"open","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0141","file":"PLN-0141-integrate-render-audio-and-input-pause-boundaries.md","status":"open","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]}],"lessons":[]}
|
{"type":"discussion","id":"DSC-0041","status":"in_progress","ticket":"foreground-stack-game-pause-shell-vm-backed","title":"Foreground Stack, Game Pause, and VM-Backed Shell Coexistence","created_at":"2026-06-05","updated_at":"2026-07-03","tags":["runtime","os","lifecycle","shell","game","vm","foreground","architecture"],"agendas":[{"id":"AGD-0041","file":"AGD-0041-foreground-stack-game-pause-shell-vm-backed.md","status":"accepted","created_at":"2026-06-05","updated_at":"2026-07-03"}],"decisions":[{"id":"DEC-0037","file":"DEC-0037-foreground-stack-and-game-pause-contract.md","status":"accepted","created_at":"2026-07-03","updated_at":"2026-07-03","ref_agenda":"AGD-0041"}],"plans":[{"id":"PLN-0136","file":"PLN-0136-route-desktop-home-key-outside-guest-input.md","status":"done","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0137","file":"PLN-0137-implement-systemos-foreground-stack-state.md","status":"done","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0138","file":"PLN-0138-specify-foreground-pause-and-home-contract.md","status":"done","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0139","file":"PLN-0139-validate-game-home-shell-game-end-to-end.md","status":"open","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0140","file":"PLN-0140-deliver-game-pause-resume-and-suspension.md","status":"done","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0141","file":"PLN-0141-integrate-render-audio-and-input-pause-boundaries.md","status":"open","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]}],"lessons":[]}
|
||||||
{"type":"discussion","id":"DSC-0042","status":"done","ticket":"real-render-worker-establishment","title":"Real Render Worker Establishment","created_at":"2026-06-06","updated_at":"2026-06-20","tags":["runtime","renderer","worker","concurrency","host","hal","architecture"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0049","file":"discussion/lessons/DSC-0042-real-render-worker-establishment/LSN-0049-render-worker-publication-boundary.md","status":"done","created_at":"2026-06-20","updated_at":"2026-06-20"}]}
|
{"type":"discussion","id":"DSC-0042","status":"done","ticket":"real-render-worker-establishment","title":"Real Render Worker Establishment","created_at":"2026-06-06","updated_at":"2026-06-20","tags":["runtime","renderer","worker","concurrency","host","hal","architecture"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0049","file":"discussion/lessons/DSC-0042-real-render-worker-establishment/LSN-0049-render-worker-publication-boundary.md","status":"done","created_at":"2026-06-20","updated_at":"2026-06-20"}]}
|
||||||
{"type":"discussion","id":"DSC-0038","status":"done","ticket":"render-frame-packet-boundary","title":"Logical Render Pipelines and Command Packets","created_at":"2026-05-25","updated_at":"2026-06-04","tags":["gfx","renderer","runtime","frame-composer","architecture","ui","pipeline"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0047","file":"discussion/lessons/DSC-0038-render-frame-packet-boundary/LSN-0047-typed-render-submissions-preserve-domain-boundaries.md","status":"done","created_at":"2026-06-04","updated_at":"2026-06-04"}]}
|
{"type":"discussion","id":"DSC-0038","status":"done","ticket":"render-frame-packet-boundary","title":"Logical Render Pipelines and Command Packets","created_at":"2026-05-25","updated_at":"2026-06-04","tags":["gfx","renderer","runtime","frame-composer","architecture","ui","pipeline"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0047","file":"discussion/lessons/DSC-0038-render-frame-packet-boundary/LSN-0047-typed-render-submissions-preserve-domain-boundaries.md","status":"done","created_at":"2026-06-04","updated_at":"2026-06-04"}]}
|
||||||
{"type":"discussion","id":"DSC-0035","status":"done","ticket":"task-owned-shell-windows","title":"Agenda - Task-Owned Shell Windows","created_at":"2026-05-15","updated_at":"2026-05-15","tags":["runtime","os","task","window-manager","shell","lifecycle"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0044","file":"discussion/lessons/DSC-0035-task-owned-shell-windows/LSN-0044-task-window-liveness-belongs-to-the-task.md","status":"done","created_at":"2026-05-15","updated_at":"2026-05-15"}]}
|
{"type":"discussion","id":"DSC-0035","status":"done","ticket":"task-owned-shell-windows","title":"Agenda - Task-Owned Shell Windows","created_at":"2026-05-15","updated_at":"2026-05-15","tags":["runtime","os","task","window-manager","shell","lifecycle"],"agendas":[],"decisions":[],"plans":[],"lessons":[{"id":"LSN-0044","file":"discussion/lessons/DSC-0035-task-owned-shell-windows/LSN-0044-task-window-liveness-belongs-to-the-task.md","status":"done","created_at":"2026-05-15","updated_at":"2026-05-15"}]}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
id: PLN-0140
|
id: PLN-0140
|
||||||
ticket: foreground-stack-game-pause-shell-vm-backed
|
ticket: foreground-stack-game-pause-shell-vm-backed
|
||||||
title: Deliver Game Pause Resume and Suspension
|
title: Deliver Game Pause Resume and Suspension
|
||||||
status: open
|
status: done
|
||||||
created: 2026-07-03
|
created: 2026-07-03
|
||||||
ref_decisions: [DEC-0037]
|
ref_decisions: [DEC-0037]
|
||||||
tags: [runtime, os, vm, lifecycle, pause, suspension]
|
tags: [runtime, os, vm, lifecycle, pause, suspension]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user