implemeted firmware and hardware bridge
This commit is contained in:
@@ -2,7 +2,7 @@ use crate::audio_mixer::AudioMixer;
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use pixels::{Pixels, SurfaceTexture};
|
||||
use prometeu_core::peripherals::{AudioCommand, InputSignals, OUTPUT_SAMPLE_RATE};
|
||||
use prometeu_core::LogicalHardware;
|
||||
use prometeu_core::Hardware;
|
||||
use ringbuf::traits::{Consumer, Producer, Split};
|
||||
use ringbuf::HeapRb;
|
||||
use std::sync::Arc;
|
||||
@@ -18,7 +18,7 @@ pub struct PrometeuRunner {
|
||||
window: Option<&'static Window>,
|
||||
pixels: Option<Pixels<'static>>,
|
||||
|
||||
logical_hardware: LogicalHardware,
|
||||
hardware_bridge: Box<Hardware>,
|
||||
|
||||
input_signals: InputSignals,
|
||||
|
||||
@@ -43,11 +43,8 @@ impl PrometeuRunner {
|
||||
Self {
|
||||
window: None,
|
||||
pixels: None,
|
||||
|
||||
logical_hardware: LogicalHardware::new(),
|
||||
|
||||
hardware_bridge: Hardware::new(),
|
||||
input_signals: InputSignals::default(),
|
||||
|
||||
frame_target_dt: Duration::from_nanos(1_000_000_000 / target_fps),
|
||||
last_frame_time: Instant::now(),
|
||||
accumulator: Duration::ZERO,
|
||||
@@ -148,7 +145,7 @@ impl ApplicationHandler for PrometeuRunner {
|
||||
let size = window.inner_size();
|
||||
let surface_texture = SurfaceTexture::new(size.width, size.height, window);
|
||||
|
||||
let mut pixels = Pixels::new(LogicalHardware::W as u32, LogicalHardware::H as u32, surface_texture)
|
||||
let mut pixels = Pixels::new(Hardware::W as u32, Hardware::H as u32, surface_texture)
|
||||
.expect("failed to create Pixels");
|
||||
|
||||
pixels.frame_mut().fill(0);
|
||||
@@ -183,7 +180,7 @@ impl ApplicationHandler for PrometeuRunner {
|
||||
let frame = pixels.frame_mut();
|
||||
|
||||
// Borrow imutável do core (campo diferente, ok)
|
||||
let src = self.logical_hardware.gfx.front_buffer();
|
||||
let src = self.hardware_bridge.gfx.front_buffer();
|
||||
|
||||
draw_rgb565_to_rgba8(src, frame);
|
||||
} // <- frame borrow termina aqui
|
||||
@@ -256,11 +253,11 @@ impl ApplicationHandler for PrometeuRunner {
|
||||
|
||||
// 🔥 O coração do determinismo: consome o tempo em fatias exatas de 60Hz
|
||||
while self.accumulator >= self.frame_target_dt {
|
||||
self.logical_hardware.step_frame(&self.input_signals);
|
||||
self.hardware_bridge.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.logical_hardware.audio.commands.drain(..) {
|
||||
for cmd in self.hardware_bridge.audio.commands.drain(..) {
|
||||
let _ = producer.try_push(cmd);
|
||||
}
|
||||
}
|
||||
@@ -282,11 +279,11 @@ impl ApplicationHandler for PrometeuRunner {
|
||||
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.logical_hardware.gfx.memory_usage_bytes() as f64 / 1024.0;
|
||||
let kb = self.hardware_bridge.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.logical_hardware.last_frame_cpu_time_us as f64 / frame_budget_us) * 100.0;
|
||||
let cpu_load_core = (self.hardware_bridge.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).
|
||||
@@ -297,7 +294,7 @@ impl ApplicationHandler for PrometeuRunner {
|
||||
|
||||
let title = format!(
|
||||
"PROMETEU | GFX: {:.1} KB | FPS: {:.1} | Load: {:.1}% (C) + {:.1}% (A) | Frame: tick {} logical {}",
|
||||
kb, fps, cpu_load_core, cpu_load_audio, self.logical_hardware.tick_index, self.logical_hardware.logical_frame_index
|
||||
kb, fps, cpu_load_core, cpu_load_audio, self.hardware_bridge.tick_index(), self.hardware_bridge.logical_frame_index()
|
||||
);
|
||||
window.set_title(&title);
|
||||
}
|
||||
@@ -316,13 +313,13 @@ impl ApplicationHandler for PrometeuRunner {
|
||||
/// 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 = LogicalHardware::W as f32;
|
||||
let fb_h = LogicalHardware::H as f32;
|
||||
let fb_w = Hardware::W as f32;
|
||||
let fb_h = Hardware::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, LogicalHardware::W as i32 - 1), y.clamp(0, LogicalHardware::H as i32 - 1))
|
||||
(x.clamp(0, Hardware::W as i32 - 1), y.clamp(0, Hardware::H as i32 - 1))
|
||||
}
|
||||
|
||||
/// Copia RGB565 (u16) -> RGBA8888 (u8[4]) para o frame do pixels.
|
||||
|
||||
Reference in New Issue
Block a user