dev/asset-management #6

Merged
bquarkz merged 16 commits from dev/asset-management into master 2026-01-22 15:22:14 +00:00
5 changed files with 14 additions and 14 deletions
Showing only changes of commit 4fe9c6d81d - Show all commits

View File

@ -46,11 +46,11 @@ impl Firmware {
///
/// This method is called exactly once per Host frame (60Hz).
/// It updates peripheral signals and delegates the logic to the current state.
pub fn step_frame(&mut self, signals: &InputSignals, hw: &mut dyn HardwareBridge) {
pub fn tick(&mut self, signals: &InputSignals, hw: &mut dyn HardwareBridge) {
// 0. Process asset commits at the beginning of the frame boundary.
hw.assets_mut().apply_commits();
// 1. Update peripheral state using the latest signals from the Host.
// 1. Update the peripheral state using the latest signals from the Host.
// This ensures input is consistent throughout the entire update.
hw.pad_mut().begin_frame(signals);
hw.touch_mut().begin_frame(signals);

View File

@ -11,7 +11,7 @@ impl GameRunningStep {
}
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
let result = ctx.os.step_frame(ctx.vm, ctx.signals, ctx.hw);
let result = ctx.os.tick(ctx.vm, ctx.signals, ctx.hw);
if !ctx.os.logical_frame_active {
ctx.hw.gfx_mut().present();

View File

@ -21,7 +21,7 @@ impl HubHomeStep {
ctx.hub.window_manager.remove_window(focused_id);
} else {
// System App runs here, drawing over the Hub background
error = ctx.os.step_frame(ctx.vm, ctx.signals, ctx.hw);
error = ctx.os.tick(ctx.vm, ctx.signals, ctx.hw);
}
}

View File

@ -188,8 +188,8 @@ impl PrometeuOS {
/// This method is responsible for managing the logical frame lifecycle.
/// A single host tick might execute a full logical frame, part of it,
/// or multiple frames depending on the configured slices.
pub fn step_frame(&mut self, vm: &mut VirtualMachine, signals: &InputSignals, hw: &mut dyn HardwareBridge) -> Option<String> {
let start = std::time::Instant::now();
pub fn tick(&mut self, vm: &mut VirtualMachine, signals: &InputSignals, hw: &mut dyn HardwareBridge) -> Option<String> {
let start = Instant::now();
self.tick_index += 1;
// If the system is paused, we don't advance unless there's a debug step request.
@ -214,13 +214,13 @@ impl PrometeuOS {
}
// 2. Budget Allocation
// Determine how many cycles we can run in this host tick.
// Determines how many cycles we can run in this host tick.
let budget = std::cmp::min(Self::SLICE_PER_TICK, self.logical_frame_remaining_cycles);
// 3. VM Execution
if budget > 0 {
// Run the VM until budget is hit or FRAME_SYNC is reached.
let run_result = vm.run_budget(budget, self, hw);
// Run the VM until the budget is hit or FRAME_SYNC is reached.
let run_result = vm.run_budget(budget, self, hw); // internally dispatch to frame on SDK
match run_result {
Ok(run) => {
@ -416,12 +416,12 @@ mod tests {
os.initialize_vm(&mut vm, &cartridge);
// First tick
os.step_frame(&mut vm, &signals, &mut hw);
os.tick(&mut vm, &signals, &mut hw);
let cycles_after_tick_1 = vm.cycles;
assert!(cycles_after_tick_1 >= PrometeuOS::CYCLES_PER_LOGICAL_FRAME);
// Second tick - Now it SHOULD NOT gain more budget
os.step_frame(&mut vm, &signals, &mut hw);
os.tick(&mut vm, &signals, &mut hw);
let cycles_after_tick_2 = vm.cycles;
// FIX: It should not have consumed cycles in the second tick because the logical frame budget ended
@ -457,7 +457,7 @@ mod tests {
os.initialize_vm(&mut vm, &cartridge);
// First tick
os.step_frame(&mut vm, &signals, &mut hw);
os.tick(&mut vm, &signals, &mut hw);
let cycles_after_tick_1 = vm.cycles;
// Should have stopped at FrameSync
@ -465,7 +465,7 @@ mod tests {
assert!(cycles_after_tick_1 < PrometeuOS::CYCLES_PER_LOGICAL_FRAME);
// Second tick - Should reset the budget and run a bit more until the next FrameSync
os.step_frame(&mut vm, &signals, &mut hw);
os.tick(&mut vm, &signals, &mut hw);
let cycles_after_tick_2 = vm.cycles;
assert!(cycles_after_tick_2 > cycles_after_tick_1, "VM should have consumed more cycles because FrameSync reset the budget");

View File

@ -266,7 +266,7 @@ impl ApplicationHandler for HostRunner {
while self.accumulator >= self.frame_target_dt {
// Unless the debugger is waiting for a 'start' command, advance the system.
if !self.debugger.waiting_for_start {
self.firmware.step_frame(&self.input.signals, &mut self.hardware);
self.firmware.tick(&self.input.signals, &mut self.hardware);
}
// Sync virtual audio commands to the physical mixer.