feat(audio): add guest voice controls and reliable lifecycle delivery
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:
@@ -82,14 +82,21 @@ impl VirtualMachineRuntime {
|
||||
vm: &mut VirtualMachine,
|
||||
platform: &mut dyn RuntimePlatform,
|
||||
) -> Option<CrashReport> {
|
||||
if !platform.audio().ready() {
|
||||
return None;
|
||||
}
|
||||
if vm.memcard_boot_result() == Some(0) && memcard.session.boot_pending() {
|
||||
return None;
|
||||
}
|
||||
let was_memcard_boot = vm.memcard_boot_active();
|
||||
if was_memcard_boot {
|
||||
platform.audio_mut().begin_lifecycle();
|
||||
}
|
||||
if vm.call_stack_is_empty()
|
||||
&& let Err(error) = vm.prepare_boot_call()
|
||||
{
|
||||
let report = CrashReport::VmInit { error };
|
||||
platform.audio_mut().abort_frame();
|
||||
self.last_crash_report = Some(report.clone());
|
||||
return Some(report);
|
||||
}
|
||||
@@ -106,6 +113,15 @@ impl VirtualMachineRuntime {
|
||||
};
|
||||
vm.step(&mut host, &mut ctx)
|
||||
};
|
||||
// run_budget derives these terminal reasons after executing an instruction;
|
||||
// single stepping must observe the same publication/cancellation boundary.
|
||||
let step_result = if step_result.is_ok() && vm.is_halted() {
|
||||
Err(LogicalFrameEndingReason::Halted)
|
||||
} else if step_result.is_ok() && !was_memcard_boot && vm.call_stack_is_empty() {
|
||||
Err(LogicalFrameEndingReason::EndOfRom)
|
||||
} else {
|
||||
step_result
|
||||
};
|
||||
|
||||
if was_memcard_boot
|
||||
&& step_result == Err(LogicalFrameEndingReason::LifecycleComplete)
|
||||
@@ -119,9 +135,33 @@ impl VirtualMachineRuntime {
|
||||
message: format!("Memcard bootstrap failed: {error:?}: {}", memcard.diagnostic),
|
||||
pc: Some(vm.pc() as u32),
|
||||
};
|
||||
platform.audio_mut().abort_frame();
|
||||
self.last_crash_report = Some(report.clone());
|
||||
return Some(report);
|
||||
}
|
||||
if was_memcard_boot {
|
||||
match &step_result {
|
||||
Err(LogicalFrameEndingReason::LifecycleComplete) => {
|
||||
platform.audio_mut().finish_lifecycle(true)
|
||||
}
|
||||
Err(
|
||||
LogicalFrameEndingReason::Trap(_)
|
||||
| LogicalFrameEndingReason::Panic(_)
|
||||
| LogicalFrameEndingReason::Halted,
|
||||
) => platform.audio_mut().finish_lifecycle(false),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
match &step_result {
|
||||
Err(LogicalFrameEndingReason::FrameSync | LogicalFrameEndingReason::EndOfRom) => {
|
||||
platform.audio_mut().finish_frame()
|
||||
}
|
||||
Err(LogicalFrameEndingReason::Halted) => platform.audio_mut().reset(),
|
||||
Err(LogicalFrameEndingReason::Trap(_) | LogicalFrameEndingReason::Panic(_)) => {
|
||||
platform.audio_mut().abort_frame()
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
match step_result {
|
||||
Ok(())
|
||||
| Err(
|
||||
@@ -141,6 +181,7 @@ impl VirtualMachineRuntime {
|
||||
report.log_tag(),
|
||||
format!("PVM Fault during Step: {}", report),
|
||||
);
|
||||
platform.audio_mut().abort_frame();
|
||||
self.last_crash_report = Some(report.clone());
|
||||
Some(report)
|
||||
}
|
||||
@@ -153,6 +194,7 @@ impl VirtualMachineRuntime {
|
||||
report.log_tag(),
|
||||
format!("PVM Fault during Step: {}", report),
|
||||
);
|
||||
platform.audio_mut().abort_frame();
|
||||
self.last_crash_report = Some(report.clone());
|
||||
Some(report)
|
||||
}
|
||||
@@ -176,6 +218,10 @@ impl VirtualMachineRuntime {
|
||||
if self.paused && !single_step && !self.debug_step_request {
|
||||
return LogicalFrameEndingReason::Breakpoint;
|
||||
}
|
||||
if !platform.audio().lifecycle_ready() {
|
||||
return LogicalFrameEndingReason::BudgetExhausted;
|
||||
}
|
||||
platform.audio_mut().begin_lifecycle();
|
||||
let result = catch_unwind(AssertUnwindSafe(|| {
|
||||
let mut ctx = HostContext::new_platform(Some(platform));
|
||||
let mut host = VmRuntimeHost {
|
||||
@@ -200,6 +246,16 @@ impl VirtualMachineRuntime {
|
||||
let reason = result.unwrap_or_else(|payload| {
|
||||
LogicalFrameEndingReason::Panic(Self::host_panic_payload_to_string(payload))
|
||||
});
|
||||
match &reason {
|
||||
LogicalFrameEndingReason::LifecycleComplete => {
|
||||
platform.audio_mut().finish_lifecycle(true)
|
||||
}
|
||||
LogicalFrameEndingReason::BudgetExhausted | LogicalFrameEndingReason::Breakpoint => {}
|
||||
_ => {
|
||||
platform.audio_mut().finish_lifecycle(false);
|
||||
platform.audio_mut().abort_frame();
|
||||
}
|
||||
}
|
||||
if reason == LogicalFrameEndingReason::Breakpoint || single_step || self.debug_step_request
|
||||
{
|
||||
self.paused = true;
|
||||
@@ -255,6 +311,7 @@ impl VirtualMachineRuntime {
|
||||
}),
|
||||
};
|
||||
if let Some(report) = &failure {
|
||||
platform.audio_mut().abort_frame();
|
||||
self.last_crash_report = Some(report.clone());
|
||||
}
|
||||
return failure;
|
||||
@@ -277,6 +334,9 @@ impl VirtualMachineRuntime {
|
||||
return None;
|
||||
}
|
||||
|
||||
if !platform.audio().ready() {
|
||||
return None;
|
||||
}
|
||||
self.update_fs(log_service, fs, fs_state);
|
||||
if !self.logical_frame_active {
|
||||
if RenderManager::policy_for_app_mode(self.current_cartridge_app_mode)
|
||||
@@ -293,6 +353,7 @@ impl VirtualMachineRuntime {
|
||||
if self.needs_prepare_entry_call || vm.call_stack_is_empty() {
|
||||
if let Err(error) = vm.prepare_boot_call() {
|
||||
let report = CrashReport::VmInit { error };
|
||||
platform.audio_mut().abort_frame();
|
||||
self.last_crash_report = Some(report.clone());
|
||||
return Some(report);
|
||||
}
|
||||
@@ -341,6 +402,9 @@ impl VirtualMachineRuntime {
|
||||
self.atomic_telemetry.cycles_used.fetch_add(run.cycles_used, Ordering::Relaxed);
|
||||
self.atomic_telemetry.vm_steps.fetch_add(run.steps_executed, Ordering::Relaxed);
|
||||
|
||||
if run.reason == LogicalFrameEndingReason::Halted {
|
||||
platform.audio_mut().reset();
|
||||
}
|
||||
if run.reason == LogicalFrameEndingReason::Breakpoint {
|
||||
self.paused = true;
|
||||
self.debug_step_request = false;
|
||||
@@ -363,6 +427,7 @@ impl VirtualMachineRuntime {
|
||||
report.log_tag(),
|
||||
report.summary(),
|
||||
);
|
||||
platform.audio_mut().abort_frame();
|
||||
self.last_crash_report = Some(report.clone());
|
||||
return Some(report);
|
||||
}
|
||||
@@ -376,6 +441,7 @@ impl VirtualMachineRuntime {
|
||||
report.log_tag(),
|
||||
report.summary(),
|
||||
);
|
||||
platform.audio_mut().abort_frame();
|
||||
self.last_crash_report = Some(report.clone());
|
||||
return Some(report);
|
||||
}
|
||||
@@ -500,6 +566,8 @@ impl VirtualMachineRuntime {
|
||||
|
||||
log_service.reset_count();
|
||||
|
||||
// Entry return is the runtime's successful implicit frame end.
|
||||
platform.audio_mut().finish_frame();
|
||||
self.logical_frame_index += 1;
|
||||
self.logical_frame_active = false;
|
||||
self.logical_frame_remaining_cycles = 0;
|
||||
@@ -532,6 +600,7 @@ impl VirtualMachineRuntime {
|
||||
report.log_tag(),
|
||||
report.summary(),
|
||||
);
|
||||
platform.audio_mut().abort_frame();
|
||||
self.last_crash_report = Some(report.clone());
|
||||
return Some(report);
|
||||
}
|
||||
@@ -582,7 +651,7 @@ impl VirtualMachineRuntime {
|
||||
platform: &mut dyn RuntimePlatform,
|
||||
) {
|
||||
platform.game2d_frame_composer().begin_frame();
|
||||
platform.audio_mut().clear_commands();
|
||||
platform.audio_mut().begin_frame();
|
||||
self.logs_written_this_frame.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user