implements PLN-0106

This commit is contained in:
bQUARKz 2026-06-15 06:00:39 +01:00
parent 1d6b799960
commit 5381ae02b1
Signed by: bquarkz
SSH Key Fingerprint: SHA256:Z7dgqoglWwoK6j6u4QC87OveEq74WOhFN+gitsxtkf8
3 changed files with 34 additions and 27 deletions

View File

@ -1,4 +1,3 @@
use prometeu_drivers::hardware::Hardware;
use prometeu_hal::InputSignals; use prometeu_hal::InputSignals;
use winit::event::{ElementState, MouseButton, WindowEvent}; use winit::event::{ElementState, MouseButton, WindowEvent};
use winit::keyboard::{KeyCode, PhysicalKey}; use winit::keyboard::{KeyCode, PhysicalKey};
@ -14,7 +13,7 @@ struct FbViewport {
} }
impl FbViewport { impl FbViewport {
fn framebuffer_viewport(window: &Window) -> Option<FbViewport> { fn framebuffer_viewport(window: &Window, display_size: (usize, usize)) -> Option<FbViewport> {
let size = window.inner_size(); let size = window.inner_size();
let win_w = size.width as f32; let win_w = size.width as f32;
@ -24,8 +23,8 @@ impl FbViewport {
return None; return None;
} }
let fb_w = Hardware::W as f32; let fb_w = display_size.0 as f32;
let fb_h = Hardware::H as f32; let fb_h = display_size.1 as f32;
let scale_x = (win_w / fb_w).floor(); let scale_x = (win_w / fb_w).floor();
let scale_y = (win_h / fb_h).floor(); let scale_y = (win_h / fb_h).floor();
@ -44,17 +43,18 @@ impl FbViewport {
pub struct HostInputHandler { pub struct HostInputHandler {
pub signals: InputSignals, pub signals: InputSignals,
display_size: (usize, usize),
} }
impl Default for HostInputHandler { impl Default for HostInputHandler {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new((480, 270))
} }
} }
impl HostInputHandler { impl HostInputHandler {
pub fn new() -> Self { pub fn new(display_size: (usize, usize)) -> Self {
Self { signals: InputSignals::default() } Self { signals: InputSignals::default(), display_size }
} }
pub fn handle_event(&mut self, event: &WindowEvent, window: &Window) { pub fn handle_event(&mut self, event: &WindowEvent, window: &Window) {
@ -87,7 +87,9 @@ impl HostInputHandler {
} }
WindowEvent::CursorMoved { position, .. } => { WindowEvent::CursorMoved { position, .. } => {
if let Some((x, y)) = window_to_fb(position.x as f32, position.y as f32, window) { if let Some((x, y)) =
window_to_fb(position.x as f32, position.y as f32, window, self.display_size)
{
self.signals.x_pos = x; self.signals.x_pos = x;
self.signals.y_pos = y; self.signals.y_pos = y;
} }
@ -107,8 +109,13 @@ impl HostInputHandler {
_ => {} _ => {}
} }
fn window_to_fb(wx: f32, wy: f32, window: &Window) -> Option<(i32, i32)> { fn window_to_fb(
let viewport = FbViewport::framebuffer_viewport(window)?; wx: f32,
wy: f32,
window: &Window,
display_size: (usize, usize),
) -> Option<(i32, i32)> {
let viewport = FbViewport::framebuffer_viewport(window, display_size)?;
let local_x = wx - viewport.x; let local_x = wx - viewport.x;
let local_y = wy - viewport.y; let local_y = wy - viewport.y;
@ -120,7 +127,10 @@ impl HostInputHandler {
let fb_x = (local_x / viewport.scale).floor() as i32; let fb_x = (local_x / viewport.scale).floor() as i32;
let fb_y = (local_y / viewport.scale).floor() as i32; let fb_y = (local_y / viewport.scale).floor() as i32;
Some((fb_x.clamp(0, Hardware::W as i32 - 1), fb_y.clamp(0, Hardware::H as i32 - 1))) Some((
fb_x.clamp(0, display_size.0 as i32 - 1),
fb_y.clamp(0, display_size.1 as i32 - 1),
))
} }
} }
} }

View File

@ -10,6 +10,7 @@ use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
use prometeu_drivers::AudioCommand; use prometeu_drivers::AudioCommand;
use prometeu_drivers::hardware::Hardware; use prometeu_drivers::hardware::Hardware;
use prometeu_firmware::{BootTarget, Firmware, FirmwareState}; use prometeu_firmware::{BootTarget, Firmware, FirmwareState};
use prometeu_hal::RuntimePlatform;
use prometeu_hal::telemetry::CertificationConfig; use prometeu_hal::telemetry::CertificationConfig;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use winit::application::ApplicationHandler; use winit::application::ApplicationHandler;
@ -152,12 +153,15 @@ impl HostRunner {
firmware.os.fs().mount(Box::new(backend)); firmware.os.fs().mount(Box::new(backend));
} }
let hardware = Hardware::new();
let display_size = hardware.display_size();
Self { Self {
window: None, window: None,
pixels: None, pixels: None,
hardware: Hardware::new(), hardware,
firmware, firmware,
input: HostInputHandler::new(), input: HostInputHandler::new(display_size),
fs_root, fs_root,
log_sink: HostConsoleSink::new(), log_sink: HostConsoleSink::new(),
frame_target_dt: Duration::from_nanos(1_000_000_000 / target_fps), frame_target_dt: Duration::from_nanos(1_000_000_000 / target_fps),
@ -228,8 +232,8 @@ impl ApplicationHandler for HostRunner {
let size = window.inner_size(); let size = window.inner_size();
let surface_texture = SurfaceTexture::new(size.width, size.height, window); let surface_texture = SurfaceTexture::new(size.width, size.height, window);
let mut pixels = let (display_w, display_h) = self.hardware.display_size();
PixelsBuilder::new(Hardware::W as u32, Hardware::H as u32, surface_texture) let mut pixels = PixelsBuilder::new(display_w as u32, display_h as u32, surface_texture)
.present_mode(PresentMode::Fifo) // activate vsync .present_mode(PresentMode::Fifo) // activate vsync
.build() .build()
.expect("failed to create Pixels"); .expect("failed to create Pixels");
@ -381,7 +385,7 @@ impl ApplicationHandler for HostRunner {
self.audio.update_stats(&mut self.stats); self.audio.update_stats(&mut self.stats);
// Update technical statistics displayed in the window title. // Update technical statistics displayed in the window title.
self.stats.update(now, self.window, &self.hardware, &mut self.firmware); self.stats.update(now, self.window, &mut self.firmware);
// Synchronize system logs to the host console. // Synchronize system logs to the host console.
let last_seq = self.log_sink.last_seq().unwrap_or(u64::MAX); let last_seq = self.log_sink.last_seq().unwrap_or(u64::MAX);

View File

@ -1,4 +1,3 @@
use prometeu_drivers::hardware::Hardware;
use prometeu_firmware::Firmware; use prometeu_firmware::Firmware;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use winit::window::Window; use winit::window::Window;
@ -60,13 +59,7 @@ impl HostStats {
} }
} }
pub fn update( pub fn update(&mut self, now: Instant, window: Option<&Window>, firmware: &mut Firmware) {
&mut self,
now: Instant,
window: Option<&Window>,
_hardware: &Hardware,
firmware: &mut Firmware,
) {
let stats_elapsed = now.duration_since(self.last_stats_update); let stats_elapsed = now.duration_since(self.last_stats_update);
if stats_elapsed >= Duration::from_secs(1) { if stats_elapsed >= Duration::from_secs(1) {
self.current_fps = self.frames_since_last_update as f64 / stats_elapsed.as_secs_f64(); self.current_fps = self.frames_since_last_update as f64 / stats_elapsed.as_secs_f64();