feat(runtime): implement shared transactional memcard with async saves
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
This commit is contained in:
@@ -12,7 +12,7 @@ use prometeu_hal::{
|
||||
};
|
||||
use prometeu_system::{CrashReport, LatestRenderFrameStore};
|
||||
|
||||
const BOOT_TICK_LIMIT: usize = 64;
|
||||
const BOOT_TICK_LIMIT: usize = 5000;
|
||||
const HOST_FRAME_ADVANCE_TICK_LIMIT: usize = 100_000;
|
||||
|
||||
/// One published logical frame plus the automation counter.
|
||||
@@ -118,6 +118,17 @@ struct HeadlessPlatform {
|
||||
}
|
||||
|
||||
impl HeadlessHost {
|
||||
/// Install storage through the shared worker. Progress is driven by ordinary host ticks.
|
||||
pub fn install_memcard(
|
||||
&mut self,
|
||||
storage: Box<dyn prometeu_hal::memcard::MemcardStorage>,
|
||||
) -> prometeu_system::memcard::image::Result<()> {
|
||||
self.firmware.os.memcard().mount_card(storage)
|
||||
}
|
||||
pub fn memcard_preparation(&mut self) -> prometeu_system::memcard::admission::PreparationState {
|
||||
self.firmware.os.memcard().admission.state
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
let clock = Arc::new(ControlledWallClock::default());
|
||||
Self::with_clock(clock.clone(), Some(clock))
|
||||
@@ -160,6 +171,20 @@ impl HeadlessHost {
|
||||
/// The transition into `GameRunning` is the last tick. The first game
|
||||
/// logical frame stays available for [`Self::advance_frame`].
|
||||
pub fn boot(&mut self, path: impl Into<String>) -> Result<(), HostError> {
|
||||
self.boot_with_choice(path, None)
|
||||
}
|
||||
pub fn boot_with_memcard_choice(
|
||||
&mut self,
|
||||
path: impl Into<String>,
|
||||
choice: prometeu_system::memcard::admission::Choice,
|
||||
) -> Result<(), HostError> {
|
||||
self.boot_with_choice(path, Some(choice))
|
||||
}
|
||||
fn boot_with_choice(
|
||||
&mut self,
|
||||
path: impl Into<String>,
|
||||
choice: Option<prometeu_system::memcard::admission::Choice>,
|
||||
) -> Result<(), HostError> {
|
||||
if self.boot_attempted {
|
||||
return Err(HostError::AlreadyBooted);
|
||||
}
|
||||
@@ -167,6 +192,7 @@ impl HeadlessHost {
|
||||
let path = path.into();
|
||||
self.firmware.boot_target = BootTarget::Cartridge { path, debug: false, debug_port: 7777 };
|
||||
|
||||
let boot_deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
|
||||
for _ in 0..BOOT_TICK_LIMIT {
|
||||
if matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
|
||||
return Ok(());
|
||||
@@ -185,7 +211,41 @@ impl HeadlessHost {
|
||||
report: None,
|
||||
});
|
||||
}
|
||||
let progress = self.firmware.os.memcard().lane.progress_stamp();
|
||||
let waiting = matches!(&self.firmware.state,FirmwareState::LoadCartridge(step) if step.needs_memcard_choice());
|
||||
if waiting {
|
||||
let Some(choice) = choice else {
|
||||
return Err(HostError::BootFailed {
|
||||
reason: "Memory-card choice required; use boot_with_memcard_choice".into(),
|
||||
report: None,
|
||||
});
|
||||
};
|
||||
self.signals = InputSignals::default();
|
||||
self.tick_once();
|
||||
self.signals = match choice {
|
||||
prometeu_system::memcard::admission::Choice::Persistent => {
|
||||
InputSignals { a_signal: true, ..Default::default() }
|
||||
}
|
||||
prometeu_system::memcard::admission::Choice::MemoryFresh => {
|
||||
InputSignals { x_signal: true, ..Default::default() }
|
||||
}
|
||||
prometeu_system::memcard::admission::Choice::MemoryExisting => {
|
||||
InputSignals { y_signal: true, ..Default::default() }
|
||||
}
|
||||
};
|
||||
}
|
||||
self.tick_once();
|
||||
self.signals = InputSignals::default();
|
||||
if matches!(self.firmware.state, FirmwareState::LoadCartridge(_)) {
|
||||
if std::time::Instant::now() >= boot_deadline {
|
||||
break;
|
||||
}
|
||||
self.firmware
|
||||
.os
|
||||
.memcard()
|
||||
.lane
|
||||
.wait_for_progress(progress, std::time::Duration::from_millis(16));
|
||||
}
|
||||
}
|
||||
|
||||
if matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
|
||||
|
||||
Reference in New Issue
Block a user