55 lines
1.8 KiB
Rust
55 lines
1.8 KiB
Rust
use crate::firmware::firmware_state::{AppCrashesStep, FirmwareState};
|
|
use crate::firmware::prometeu_context::PrometeuContext;
|
|
use prometeu_hal::log::{LogLevel, LogSource};
|
|
use prometeu_system::CrashReport;
|
|
use prometeu_system::task::{TaskId, TaskState};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct GameRunningStep {
|
|
pub task_id: TaskId,
|
|
}
|
|
|
|
impl GameRunningStep {
|
|
pub fn new(task_id: TaskId) -> Self {
|
|
Self { task_id }
|
|
}
|
|
|
|
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
|
|
ctx.os.log(LogLevel::Info, LogSource::Pos, 0, "Entering GameRunning".to_string());
|
|
}
|
|
|
|
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
|
|
let Some(task_state) = ctx.os.task_manager.get(self.task_id).map(|task| task.state) else {
|
|
// TODO: is it panic?
|
|
let report =
|
|
CrashReport::VmPanic { message: "task is gone, panic!".to_string(), pc: None };
|
|
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
|
};
|
|
|
|
if task_state != TaskState::Foreground {
|
|
// TODO: is it panic?
|
|
let report = CrashReport::VmPanic {
|
|
message: "should be running as foreground, panic!".to_string(),
|
|
pc: None,
|
|
};
|
|
let _ = ctx.os.crash_task(self.task_id, Some(&report));
|
|
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
|
}
|
|
|
|
let result = ctx.os.tick_vm(ctx.vm, ctx.signals, ctx.hw);
|
|
|
|
if !ctx.os.vm_runtime.logical_frame_active {
|
|
ctx.hw.gfx_mut().present();
|
|
}
|
|
|
|
if let Some(report) = result {
|
|
let _ = ctx.os.crash_task(self.task_id, Some(&report));
|
|
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
|
}
|
|
|
|
None
|
|
}
|
|
|
|
pub fn on_exit(&mut self, _ctx: &mut PrometeuContext) {}
|
|
}
|