add process and task managers
This commit is contained in:
@@ -1,19 +1,48 @@
|
||||
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 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());
|
||||
ctx.os.vm_runtime.log(
|
||||
LogLevel::Info,
|
||||
LogSource::Pos,
|
||||
0,
|
||||
"Entering GameRunning".to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
|
||||
let result = ctx.os.tick(ctx.vm, ctx.signals, ctx.hw);
|
||||
let Some(task) = ctx.os.task_manager.get(self.task_id) 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 !ctx.os.logical_frame_active {
|
||||
if task.state != TaskState::Foreground {
|
||||
// TODO: is it panic?
|
||||
let report = CrashReport::VmPanic {
|
||||
message: "should be running as foreground, panic!".to_string(),
|
||||
pc: None,
|
||||
};
|
||||
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
||||
}
|
||||
|
||||
let result = ctx.os.vm_runtime.tick(ctx.vm, ctx.signals, ctx.hw);
|
||||
|
||||
if !ctx.os.vm_runtime.logical_frame_active {
|
||||
ctx.hw.gfx_mut().present();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user