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:
@@ -28,6 +28,8 @@ pub struct SystemOS {
|
||||
pub(super) memcard: MemcardService,
|
||||
pub(super) open_files: HashMap<u32, String>,
|
||||
pub(super) next_handle: u32,
|
||||
io_controller: Option<crate::AsyncWorkLaneController>,
|
||||
io_bound: bool,
|
||||
}
|
||||
|
||||
impl SystemOS {
|
||||
@@ -50,6 +52,8 @@ impl SystemOS {
|
||||
memcard: MemcardService::new(),
|
||||
open_files: HashMap::new(),
|
||||
next_handle: 1,
|
||||
io_controller: None,
|
||||
io_bound: false,
|
||||
};
|
||||
|
||||
os.log(LogLevel::Info, LogSource::Pos, 0, "PrometeuOS starting...".to_string());
|
||||
@@ -57,6 +61,55 @@ impl SystemOS {
|
||||
os
|
||||
}
|
||||
|
||||
pub fn memcard(&mut self) -> &mut MemcardService {
|
||||
&mut self.memcard
|
||||
}
|
||||
|
||||
/// Host/player operations are admitted only while gameplay is suspended.
|
||||
pub fn replace_memcard(
|
||||
&mut self,
|
||||
storage: Box<dyn prometeu_hal::memcard::MemcardStorage>,
|
||||
load_existing: bool,
|
||||
) -> crate::memcard::image::Result<()> {
|
||||
if let Some(task) = self.foreground_stack.resident_game_task()
|
||||
&& self
|
||||
.task_manager
|
||||
.get(task)
|
||||
.is_none_or(|t| t.state != crate::task::TaskState::Suspended)
|
||||
{
|
||||
return Err(crate::memcard::image::Error::AccessDenied);
|
||||
}
|
||||
self.memcard.replace_card(storage, load_existing)
|
||||
}
|
||||
pub fn detach_memcard(&mut self) -> crate::memcard::image::Result<()> {
|
||||
if let Some(task) = self.foreground_stack.resident_game_task()
|
||||
&& self
|
||||
.task_manager
|
||||
.get(task)
|
||||
.is_none_or(|t| t.state != crate::task::TaskState::Suspended)
|
||||
{
|
||||
return Err(crate::memcard::image::Error::AccessDenied);
|
||||
}
|
||||
if self.memcard.host_faulted() {
|
||||
return Err(crate::memcard::image::Error::ReadOnly);
|
||||
}
|
||||
self.memcard.session.detach()?;
|
||||
self.memcard.admission.state = crate::memcard::admission::PreparationState::Ready;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Called outside guest/frame execution, including while a game is suspended.
|
||||
pub fn poll_background_io(&mut self, platform: &mut dyn prometeu_hal::RuntimePlatform) {
|
||||
if !self.io_bound && platform.assets_mut().bind_background_work(self.memcard.lane.clone()) {
|
||||
self.io_controller = Some(crate::AsyncWorkLaneController::start(
|
||||
crate::AsyncWorkLaneConfig::default(),
|
||||
self.memcard.lane.clone(),
|
||||
));
|
||||
self.io_bound = true;
|
||||
}
|
||||
self.memcard.poll(std::time::Instant::now());
|
||||
}
|
||||
|
||||
pub fn log(&mut self, level: LogLevel, source: LogSource, tag: u16, msg: String) {
|
||||
self.vm_runtime.log(&mut self.log_service, level, source, tag, msg);
|
||||
}
|
||||
@@ -136,7 +189,7 @@ impl SystemOS {
|
||||
pub(super) fn clear_cartridge_service_state(&mut self) {
|
||||
self.open_files.clear();
|
||||
self.next_handle = 1;
|
||||
self.memcard.clear_all_staging();
|
||||
self.memcard.session.end_session();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +211,7 @@ mod tests {
|
||||
|
||||
fn session_test_cartridge(app_mode: AppMode, app_id: u32, title: &str) -> Cartridge {
|
||||
Cartridge {
|
||||
memcard_slots: None,
|
||||
app_id,
|
||||
title: title.to_string(),
|
||||
app_version: "1.0.0".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user