implements PLN-0140
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
use crate::CrashReport;
|
||||
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::services::foreground::{ForegroundOwner, ForegroundStackError, ResidentGame};
|
||||
use crate::services::foreground::{
|
||||
ForegroundOwner, ForegroundStackError, ResidentGame, ResidentGameState,
|
||||
};
|
||||
use crate::task::{TaskId, TaskKind, TaskState};
|
||||
|
||||
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> {
|
||||
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.task_manager.mark_suspended(task_id);
|
||||
self.os.process_manager.mark_suspended(process_id);
|
||||
self.os
|
||||
.foreground_stack
|
||||
.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(())
|
||||
}
|
||||
|
||||
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) {
|
||||
self.os.foreground_stack.return_to_hub();
|
||||
self.os.task_manager.clear_foreground();
|
||||
@@ -102,7 +139,11 @@ impl<'a> LifecycleFacade<'a> {
|
||||
ForegroundOwner::Game(owner) if owner == task_id => {
|
||||
self.os
|
||||
.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)?;
|
||||
}
|
||||
ForegroundOwner::Shell(owner) if owner == task_id => {
|
||||
@@ -132,10 +173,18 @@ impl<'a> LifecycleFacade<'a> {
|
||||
TaskKind::Game => {
|
||||
self.os
|
||||
.foreground_stack
|
||||
.set_game_foreground(task_id)
|
||||
.request_resume_game(task_id)
|
||||
.map_err(map_foreground_error)?;
|
||||
self.os.task_manager.set_foreground(task_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 => {
|
||||
self.os
|
||||
|
||||
Reference in New Issue
Block a user