rename Machine -> LogicalHardware

This commit is contained in:
2026-03-24 13:40:12 +00:00
parent d1c87ef6e7
commit 85a5f2d63f
5 changed files with 38 additions and 37 deletions
+14 -13
View File
@@ -6,7 +6,7 @@ mod audio_mixer;
use audio_mixer::AudioMixer;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use prometeu_core::peripherals::{AudioCommand, InputSignals, OUTPUT_SAMPLE_RATE};
use prometeu_core::Machine;
use prometeu_core::LogicalHardware;
use ringbuf::traits::{Consumer, Producer, Split};
use ringbuf::HeapRb;
use std::sync::Arc;
@@ -32,7 +32,7 @@ struct PrometeuApp {
window: Option<&'static Window>,
pixels: Option<Pixels<'static>>,
machine: Machine,
logical_hardware: LogicalHardware,
input_signals: InputSignals,
@@ -58,7 +58,7 @@ impl PrometeuApp {
window: None,
pixels: None,
machine: Machine::new(),
logical_hardware: LogicalHardware::new(),
input_signals: InputSignals::default(),
@@ -160,7 +160,7 @@ impl ApplicationHandler for PrometeuApp {
let size = window.inner_size();
let surface_texture = SurfaceTexture::new(size.width, size.height, window);
let mut pixels = Pixels::new(Machine::W as u32, Machine::H as u32, surface_texture)
let mut pixels = Pixels::new(LogicalHardware::W as u32, LogicalHardware::H as u32, surface_texture)
.expect("failed to create Pixels");
pixels.frame_mut().fill(0);
@@ -195,7 +195,7 @@ impl ApplicationHandler for PrometeuApp {
let frame = pixels.frame_mut();
// Borrow imutável do core (campo diferente, ok)
let src = self.machine.gfx.front_buffer();
let src = self.logical_hardware.gfx.front_buffer();
draw_rgb565_to_rgba8(src, frame);
} // <- frame borrow termina aqui
@@ -268,11 +268,11 @@ impl ApplicationHandler for PrometeuApp {
// 🔥 O coração do determinismo: consome o tempo em fatias exatas de 60Hz
while self.accumulator >= self.frame_target_dt {
self.machine.step_frame(&self.input_signals);
self.logical_hardware.step_frame(&self.input_signals);
// Envia comandos de áudio gerados neste frame para a thread de áudio
if let Some(producer) = &mut self.audio_producer {
for cmd in self.machine.audio.commands.drain(..) {
for cmd in self.logical_hardware.audio.commands.drain(..) {
let _ = producer.try_push(cmd);
}
}
@@ -294,10 +294,11 @@ impl ApplicationHandler for PrometeuApp {
if stats_elapsed >= Duration::from_secs(1) {
if let Some(window) = self.window {
let fps = self.frames_since_last_update as f64 / stats_elapsed.as_secs_f64();
let kb = self.machine.gfx.memory_usage_bytes() as f64 / 1024.0;
let kb = self.logical_hardware.gfx.memory_usage_bytes() as f64 / 1024.0;
// comparação fixa sempre contra 60Hz, manter mesmo quando fazer teste de stress na CPU
let frame_budget_us = 16666.0;
let cpu_load_core = (self.machine.last_frame_cpu_time_us as f64 / frame_budget_us) * 100.0;
let cpu_load_core = (self.logical_hardware.last_frame_cpu_time_us as f64 / frame_budget_us) * 100.0;
let cpu_load_audio = if self.audio_load_samples > 0 {
// O load real é (tempo total processando) / (tempo total de parede).
@@ -308,7 +309,7 @@ impl ApplicationHandler for PrometeuApp {
let title = format!(
"PROMETEU | GFX: {:.1} KB | FPS: {:.1} | Load: {:.1}% (C) + {:.1}% (A) | Frame: {}",
kb, fps, cpu_load_core, cpu_load_audio, self.machine.frame_index
kb, fps, cpu_load_core, cpu_load_audio, self.logical_hardware.frame_index
);
window.set_title(&title);
}
@@ -327,13 +328,13 @@ impl ApplicationHandler for PrometeuApp {
/// Depois podemos fazer letterbox/aspect-ratio correto.
fn window_to_fb(wx: f32, wy: f32, window: &Window) -> (i32, i32) {
let size = window.inner_size();
let fb_w = Machine::W as f32;
let fb_h = Machine::H as f32;
let fb_w = LogicalHardware::W as f32;
let fb_h = LogicalHardware::H as f32;
let x = (wx * fb_w / size.width as f32).floor() as i32;
let y = (wy * fb_h / size.height as f32).floor() as i32;
(x.clamp(0, Machine::W as i32 - 1), y.clamp(0, Machine::H as i32 - 1))
(x.clamp(0, LogicalHardware::W as i32 - 1), y.clamp(0, LogicalHardware::H as i32 - 1))
}
/// Copia RGB565 (u16) -> RGBA8888 (u8[4]) para o frame do pixels.