clean up and organize
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use prometeu_core::peripherals::{AudioCommand, Channel, LoopMode, MAX_CHANNELS, OUTPUT_SAMPLE_RATE};
|
||||
use prometeu_core::hardware::{AudioCommand, Channel, LoopMode, MAX_CHANNELS, OUTPUT_SAMPLE_RATE};
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
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::firmware::Firmware;
|
||||
use prometeu_core::hardware::{AudioCommand, InputSignals, OUTPUT_SAMPLE_RATE};
|
||||
use prometeu_core::Hardware;
|
||||
use ringbuf::traits::{Consumer, Producer, Split};
|
||||
use ringbuf::HeapRb;
|
||||
@@ -18,7 +19,8 @@ pub struct PrometeuRunner {
|
||||
window: Option<&'static Window>,
|
||||
pixels: Option<Pixels<'static>>,
|
||||
|
||||
hardware_bridge: Box<Hardware>,
|
||||
hardware: Hardware,
|
||||
firmware: Firmware,
|
||||
|
||||
input_signals: InputSignals,
|
||||
|
||||
@@ -43,7 +45,8 @@ impl PrometeuRunner {
|
||||
Self {
|
||||
window: None,
|
||||
pixels: None,
|
||||
hardware_bridge: Hardware::new(),
|
||||
hardware: Hardware::new(),
|
||||
firmware: Firmware::new(),
|
||||
input_signals: InputSignals::default(),
|
||||
frame_target_dt: Duration::from_nanos(1_000_000_000 / target_fps),
|
||||
last_frame_time: Instant::now(),
|
||||
@@ -180,7 +183,7 @@ impl ApplicationHandler for PrometeuRunner {
|
||||
let frame = pixels.frame_mut();
|
||||
|
||||
// Borrow imutável do core (campo diferente, ok)
|
||||
let src = self.hardware_bridge.gfx.front_buffer();
|
||||
let src = self.hardware.gfx.front_buffer();
|
||||
|
||||
draw_rgb565_to_rgba8(src, frame);
|
||||
} // <- frame borrow termina aqui
|
||||
@@ -253,11 +256,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.hardware_bridge.step_frame(&self.input_signals);
|
||||
self.firmware.step_frame(&self.input_signals, &mut self.hardware);
|
||||
|
||||
// Envia comandos de áudio gerados neste frame para a thread de áudio
|
||||
if let Some(producer) = &mut self.audio_producer {
|
||||
for cmd in self.hardware_bridge.audio.commands.drain(..) {
|
||||
for cmd in self.hardware.audio.commands.drain(..) {
|
||||
let _ = producer.try_push(cmd);
|
||||
}
|
||||
}
|
||||
@@ -279,11 +282,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.hardware_bridge.gfx.memory_usage_bytes() as f64 / 1024.0;
|
||||
let kb = self.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.hardware_bridge.last_frame_cpu_time_us() as f64 / frame_budget_us) * 100.0;
|
||||
let cpu_load_core = (self.firmware.os.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).
|
||||
@@ -294,7 +297,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.hardware_bridge.tick_index(), self.hardware_bridge.logical_frame_index()
|
||||
kb, fps, cpu_load_core, cpu_load_audio, self.firmware.os.tick_index, self.firmware.os.logical_frame_index
|
||||
);
|
||||
window.set_title(&title);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user