implements PLN-0142
This commit is contained in:
parent
5ff273f167
commit
d645bbb7bd
@ -834,6 +834,11 @@ mod tests {
|
||||
assert_eq!(render_ownership_after_home.app_mode, AppMode::Shell);
|
||||
assert_eq!(render_ownership_after_home.app_id, 0);
|
||||
assert!(render_ownership_after_home.epoch > render_ownership_before_home.epoch);
|
||||
assert!(firmware.os.lifecycle().pending_game_lifecycle_events().is_empty());
|
||||
assert_eq!(
|
||||
firmware.os.vm().delivered_game_lifecycle_events().last().map(|event| event.kind),
|
||||
Some(GameLifecycleEventKind::Pause)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -874,6 +879,11 @@ mod tests {
|
||||
assert_eq!(firmware.os.lifecycle().task_state(task_id), Some(TaskState::Foreground));
|
||||
assert!(!platform.input().pad().any());
|
||||
assert!(!platform.input().touch().f().down);
|
||||
assert!(firmware.os.lifecycle().pending_game_lifecycle_events().is_empty());
|
||||
assert_eq!(
|
||||
firmware.os.vm().delivered_game_lifecycle_events().last().map(|event| event.kind),
|
||||
Some(GameLifecycleEventKind::ResumeForeground)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -37,6 +37,8 @@ impl GameRunningStep {
|
||||
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
||||
}
|
||||
|
||||
ctx.os.vm().deliver_pending_game_lifecycle_events();
|
||||
|
||||
match ctx.os.lifecycle().advance_game_pause_budget(self.task_id) {
|
||||
Ok(true) => {
|
||||
ctx.os.vm().transition_render_owner(AppMode::Shell, 0);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use crate::CrashReport;
|
||||
use crate::os::SystemOS;
|
||||
use crate::os::{GameLifecycleEvent, SystemOS};
|
||||
use crate::{RenderWorkerConfig, RenderWorkerController};
|
||||
use prometeu_hal::app_mode::AppMode;
|
||||
use prometeu_hal::cartridge::Cartridge;
|
||||
@ -31,6 +31,8 @@ impl<'a> VmFacade<'a> {
|
||||
signals: &InputSignals,
|
||||
platform: &mut dyn RuntimePlatform,
|
||||
) -> Option<CrashReport> {
|
||||
self.deliver_pending_game_lifecycle_events();
|
||||
|
||||
self.os.vm_runtime.tick(
|
||||
&mut self.os.log_service,
|
||||
&mut self.os.fs,
|
||||
@ -44,6 +46,25 @@ impl<'a> VmFacade<'a> {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn deliver_pending_game_lifecycle_events(&mut self) {
|
||||
if self.os.vm_runtime.current_cartridge_app_mode == AppMode::Game {
|
||||
let resident_game_task = self.os.foreground_stack.resident_game_task();
|
||||
let mut retained = Vec::new();
|
||||
let mut delivered = Vec::new();
|
||||
|
||||
for event in self.os.game_lifecycle_events.drain(..) {
|
||||
if Some(event.task_id) == resident_game_task {
|
||||
delivered.push(event);
|
||||
} else {
|
||||
retained.push(event);
|
||||
}
|
||||
}
|
||||
|
||||
self.os.game_lifecycle_events = retained;
|
||||
self.os.vm_runtime.deliver_game_lifecycle_events(delivered);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset(&mut self, vm: &mut VirtualMachine) {
|
||||
self.os.vm_runtime.reset(vm);
|
||||
}
|
||||
@ -80,6 +101,14 @@ impl<'a> VmFacade<'a> {
|
||||
self.os.vm_runtime.logical_frame_active
|
||||
}
|
||||
|
||||
pub fn delivered_game_lifecycle_events(&self) -> &[GameLifecycleEvent] {
|
||||
self.os.vm_runtime.delivered_game_lifecycle_events()
|
||||
}
|
||||
|
||||
pub fn take_delivered_game_lifecycle_events(&mut self) -> Vec<GameLifecycleEvent> {
|
||||
self.os.vm_runtime.take_delivered_game_lifecycle_events()
|
||||
}
|
||||
|
||||
pub fn tick_index(&self) -> u64 {
|
||||
self.os.vm_runtime.tick_index
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ impl VirtualMachineRuntime {
|
||||
gfx2d_commands: Vec::new(),
|
||||
gfxui_commands: Vec::new(),
|
||||
logs_written_this_frame: HashMap::new(),
|
||||
game_lifecycle_events_delivered: Vec::new(),
|
||||
atomic_telemetry,
|
||||
last_crash_report: None,
|
||||
certifier: Certifier::new(cap_config.unwrap_or_default()),
|
||||
@ -135,6 +136,7 @@ impl VirtualMachineRuntime {
|
||||
self.gfx2d_commands.clear();
|
||||
self.gfxui_commands.clear();
|
||||
self.logs_written_this_frame.clear();
|
||||
self.game_lifecycle_events_delivered.clear();
|
||||
|
||||
self.last_crash_report = None;
|
||||
|
||||
@ -191,6 +193,21 @@ impl VirtualMachineRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deliver_game_lifecycle_events<I>(&mut self, events: I)
|
||||
where
|
||||
I: IntoIterator<Item = GameLifecycleEvent>,
|
||||
{
|
||||
self.game_lifecycle_events_delivered.extend(events);
|
||||
}
|
||||
|
||||
pub fn delivered_game_lifecycle_events(&self) -> &[GameLifecycleEvent] {
|
||||
&self.game_lifecycle_events_delivered
|
||||
}
|
||||
|
||||
pub fn take_delivered_game_lifecycle_events(&mut self) -> Vec<GameLifecycleEvent> {
|
||||
std::mem::take(&mut self.game_lifecycle_events_delivered)
|
||||
}
|
||||
|
||||
pub fn initialize_vm(
|
||||
&mut self,
|
||||
log_service: &mut LogService,
|
||||
@ -224,3 +241,26 @@ impl VirtualMachineRuntime {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::os::{GameLifecycleEvent, GameLifecycleEventKind};
|
||||
use crate::task::TaskId;
|
||||
|
||||
#[test]
|
||||
fn vm_runtime_records_and_drains_delivered_game_lifecycle_events() {
|
||||
let mut runtime = VirtualMachineRuntime::new(None);
|
||||
let pause = GameLifecycleEvent { task_id: TaskId(7), kind: GameLifecycleEventKind::Pause };
|
||||
let resume = GameLifecycleEvent {
|
||||
task_id: TaskId(7),
|
||||
kind: GameLifecycleEventKind::ResumeForeground,
|
||||
};
|
||||
|
||||
runtime.deliver_game_lifecycle_events([pause, resume]);
|
||||
|
||||
assert_eq!(runtime.delivered_game_lifecycle_events(), &[pause, resume]);
|
||||
assert_eq!(runtime.take_delivered_game_lifecycle_events(), vec![pause, resume]);
|
||||
assert!(runtime.delivered_game_lifecycle_events().is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ mod tests;
|
||||
mod tick;
|
||||
|
||||
use crate::CrashReport;
|
||||
use crate::os::GameLifecycleEvent;
|
||||
pub use frame_scheduler::FrameScheduler;
|
||||
use prometeu_bytecode::string_materialization_count;
|
||||
use prometeu_hal::app_mode::AppMode;
|
||||
@ -49,6 +50,7 @@ pub struct VirtualMachineRuntime {
|
||||
pub gfx2d_commands: Vec<Gfx2dCommand>,
|
||||
pub gfxui_commands: Vec<GfxUiCommand>,
|
||||
pub logs_written_this_frame: HashMap<u32, u32>,
|
||||
pub game_lifecycle_events_delivered: Vec<GameLifecycleEvent>,
|
||||
pub atomic_telemetry: Arc<AtomicTelemetry>,
|
||||
pub last_crash_report: Option<CrashReport>,
|
||||
pub certifier: Certifier,
|
||||
|
||||
@ -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-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-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-04","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":"done","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":"done","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0142","file":"PLN-0142-deliver-game-lifecycle-events-to-vm-runtime.md","status":"open","created_at":"2026-07-04","updated_at":"2026-07-04","ref_decisions":["DEC-0037"]},{"id":"PLN-0143","file":"PLN-0143-guarantee-cooperative-pause-budget-tick-before-suspension.md","status":"open","created_at":"2026-07-04","updated_at":"2026-07-04","ref_decisions":["DEC-0037"]},{"id":"PLN-0144","file":"PLN-0144-suspend-resident-game-when-shell-takes-foreground.md","status":"open","created_at":"2026-07-04","updated_at":"2026-07-04","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-04","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":"done","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":"done","created_at":"2026-07-03","updated_at":"2026-07-03","ref_decisions":["DEC-0037"]},{"id":"PLN-0142","file":"PLN-0142-deliver-game-lifecycle-events-to-vm-runtime.md","status":"done","created_at":"2026-07-04","updated_at":"2026-07-04","ref_decisions":["DEC-0037"]},{"id":"PLN-0143","file":"PLN-0143-guarantee-cooperative-pause-budget-tick-before-suspension.md","status":"open","created_at":"2026-07-04","updated_at":"2026-07-04","ref_decisions":["DEC-0037"]},{"id":"PLN-0144","file":"PLN-0144-suspend-resident-game-when-shell-takes-foreground.md","status":"open","created_at":"2026-07-04","updated_at":"2026-07-04","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-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"}]}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
id: PLN-0142
|
||||
ticket: foreground-stack-game-pause-shell-vm-backed
|
||||
title: Deliver Game Lifecycle Events To VM Runtime
|
||||
status: open
|
||||
status: done
|
||||
created: 2026-07-04
|
||||
ref_decisions: [DEC-0037]
|
||||
tags: [runtime, os, lifecycle, shell, game, vm, foreground, architecture]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user