From 5381ae02b1c7878ef30f0662f01c3e41197c8da3 Mon Sep 17 00:00:00 2001 From: bQUARKz Date: Mon, 15 Jun 2026 06:00:39 +0100 Subject: [PATCH] implements PLN-0106 --- .../prometeu-host-desktop-winit/src/input.rs | 32 ++++++++++++------- .../prometeu-host-desktop-winit/src/runner.rs | 20 +++++++----- .../prometeu-host-desktop-winit/src/stats.rs | 9 +----- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/crates/host/prometeu-host-desktop-winit/src/input.rs b/crates/host/prometeu-host-desktop-winit/src/input.rs index ea58835e..7d9874ef 100644 --- a/crates/host/prometeu-host-desktop-winit/src/input.rs +++ b/crates/host/prometeu-host-desktop-winit/src/input.rs @@ -1,4 +1,3 @@ -use prometeu_drivers::hardware::Hardware; use prometeu_hal::InputSignals; use winit::event::{ElementState, MouseButton, WindowEvent}; use winit::keyboard::{KeyCode, PhysicalKey}; @@ -14,7 +13,7 @@ struct FbViewport { } impl FbViewport { - fn framebuffer_viewport(window: &Window) -> Option { + fn framebuffer_viewport(window: &Window, display_size: (usize, usize)) -> Option { let size = window.inner_size(); let win_w = size.width as f32; @@ -24,8 +23,8 @@ impl FbViewport { return None; } - let fb_w = Hardware::W as f32; - let fb_h = Hardware::H as f32; + let fb_w = display_size.0 as f32; + let fb_h = display_size.1 as f32; let scale_x = (win_w / fb_w).floor(); let scale_y = (win_h / fb_h).floor(); @@ -44,17 +43,18 @@ impl FbViewport { pub struct HostInputHandler { pub signals: InputSignals, + display_size: (usize, usize), } impl Default for HostInputHandler { fn default() -> Self { - Self::new() + Self::new((480, 270)) } } impl HostInputHandler { - pub fn new() -> Self { - Self { signals: InputSignals::default() } + pub fn new(display_size: (usize, usize)) -> Self { + Self { signals: InputSignals::default(), display_size } } pub fn handle_event(&mut self, event: &WindowEvent, window: &Window) { @@ -87,7 +87,9 @@ impl HostInputHandler { } 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.y_pos = y; } @@ -107,8 +109,13 @@ impl HostInputHandler { _ => {} } - fn window_to_fb(wx: f32, wy: f32, window: &Window) -> Option<(i32, i32)> { - let viewport = FbViewport::framebuffer_viewport(window)?; + fn window_to_fb( + 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_y = wy - viewport.y; @@ -120,7 +127,10 @@ impl HostInputHandler { let fb_x = (local_x / 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), + )) } } } diff --git a/crates/host/prometeu-host-desktop-winit/src/runner.rs b/crates/host/prometeu-host-desktop-winit/src/runner.rs index 035d251b..53235b3d 100644 --- a/crates/host/prometeu-host-desktop-winit/src/runner.rs +++ b/crates/host/prometeu-host-desktop-winit/src/runner.rs @@ -10,6 +10,7 @@ use pixels::{Pixels, PixelsBuilder, SurfaceTexture}; use prometeu_drivers::AudioCommand; use prometeu_drivers::hardware::Hardware; use prometeu_firmware::{BootTarget, Firmware, FirmwareState}; +use prometeu_hal::RuntimePlatform; use prometeu_hal::telemetry::CertificationConfig; use std::time::{Duration, Instant}; use winit::application::ApplicationHandler; @@ -152,12 +153,15 @@ impl HostRunner { firmware.os.fs().mount(Box::new(backend)); } + let hardware = Hardware::new(); + let display_size = hardware.display_size(); + Self { window: None, pixels: None, - hardware: Hardware::new(), + hardware, firmware, - input: HostInputHandler::new(), + input: HostInputHandler::new(display_size), fs_root, log_sink: HostConsoleSink::new(), frame_target_dt: Duration::from_nanos(1_000_000_000 / target_fps), @@ -228,11 +232,11 @@ impl ApplicationHandler for HostRunner { let size = window.inner_size(); let surface_texture = SurfaceTexture::new(size.width, size.height, window); - let mut pixels = - PixelsBuilder::new(Hardware::W as u32, Hardware::H as u32, surface_texture) - .present_mode(PresentMode::Fifo) // activate vsync - .build() - .expect("failed to create Pixels"); + let (display_w, display_h) = self.hardware.display_size(); + let mut pixels = PixelsBuilder::new(display_w as u32, display_h as u32, surface_texture) + .present_mode(PresentMode::Fifo) // activate vsync + .build() + .expect("failed to create Pixels"); pixels.frame_mut().fill(0); @@ -381,7 +385,7 @@ impl ApplicationHandler for HostRunner { self.audio.update_stats(&mut self.stats); // 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. let last_seq = self.log_sink.last_seq().unwrap_or(u64::MAX); diff --git a/crates/host/prometeu-host-desktop-winit/src/stats.rs b/crates/host/prometeu-host-desktop-winit/src/stats.rs index fb20f9c7..966879d7 100644 --- a/crates/host/prometeu-host-desktop-winit/src/stats.rs +++ b/crates/host/prometeu-host-desktop-winit/src/stats.rs @@ -1,4 +1,3 @@ -use prometeu_drivers::hardware::Hardware; use prometeu_firmware::Firmware; use std::time::{Duration, Instant}; use winit::window::Window; @@ -60,13 +59,7 @@ impl HostStats { } } - pub fn update( - &mut self, - now: Instant, - window: Option<&Window>, - _hardware: &Hardware, - firmware: &mut Firmware, - ) { + pub fn update(&mut self, now: Instant, window: Option<&Window>, firmware: &mut Firmware) { let stats_elapsed = now.duration_since(self.last_stats_update); if stats_elapsed >= Duration::from_secs(1) { self.current_fps = self.frames_since_last_update as f64 / stats_elapsed.as_secs_f64();