improve v0.1, and add docs

This commit is contained in:
Nilton Constantino
2026-01-12 18:37:53 +00:00
parent 41c93fa0a3
commit 552fa4e187
17 changed files with 3590 additions and 11 deletions
+4
View File
@@ -18,6 +18,10 @@ impl Color {
Self((r5 << 11) | (g6 << 5) | b5)
}
pub const fn gray_scale(c: u8) -> Self {
Self::rgb(c, c, c)
}
pub const fn from_raw(raw: u16) -> Self {
Self(raw)
}
+9 -6
View File
@@ -1,8 +1,8 @@
use crate::peripherals::{Gfx, InputSignals, Pad, Touch};
use crate::peripherals::{BlendMode, Gfx, InputSignals, Pad, Touch};
use crate::Color;
/// PROMETEU "hardware lógico" (v0).
/// O Host alimenta INPUT/TOUCH e chama `step_frame()` em 60Hz.
/// O Host alimenta INPUT SIGNALS e chama `step_frame()` em 60Hz.
pub struct Machine {
pub gfx: Gfx,
pub pad: Pad,
@@ -54,7 +54,10 @@ impl Machine {
Color::rgb(0xFF, 0x40, 0x40)
};
self.gfx.fill_rect(x, y, 24, 24, color);
// game
self.gfx.fill_rect(x, y, 20, 20, color);
// smoke
self.gfx.fill_rect_blend(140, 0, 40, 180, Color::gray_scale(0x88), BlendMode::Half)
}
/// Final do frame: troca buffers.
@@ -63,8 +66,8 @@ impl Machine {
}
fn demo_pos(&self) -> (i32, i32) {
let t = (self.frame_index % 280) as i32;
let z = (self.pad.a.hold_frames % 140) as i32;
(20 + t, z)
let x = (self.frame_index % 300) as i32;
let y = (self.pad.a.hold_frames % 160) as i32;
(x, y)
}
}
+1
View File
@@ -4,6 +4,7 @@ mod touch;
mod input_signal;
pub use gfx::Gfx;
pub use gfx::BlendMode;
pub use input_signal::InputSignals;
pub use pad::Pad;
pub use touch::Touch;
+7 -5
View File
@@ -29,7 +29,7 @@ struct PrometeuApp {
input_signals: InputSignals,
frame_dt: Duration,
frame_target_dt: Duration,
next_frame: Instant,
}
@@ -38,10 +38,12 @@ impl PrometeuApp {
Self {
window: None,
pixels: None,
input_signals: InputSignals::default(),
machine: Machine::new(),
frame_dt: Duration::from_nanos(1_000_000_000 / 60),
input_signals: InputSignals::default(),
frame_target_dt: Duration::from_nanos(1_000_000_000 / 60),
next_frame: Instant::now(),
}
}
@@ -67,7 +69,7 @@ impl PrometeuApp {
}
}
impl ApplicationHandler for PrometeuApp {
impl ApplicationHandler for PrometeuApp {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
let attrs = WindowAttributes::default()
.with_title("PROMETEU - host_desktop")
@@ -181,7 +183,7 @@ impl ApplicationHandler for PrometeuApp {
let now = Instant::now();
if now >= self.next_frame {
self.next_frame += self.frame_dt;
self.next_frame += self.frame_target_dt;
// executa 1 frame do PROMETEU
self.machine.step_frame(&self.input_signals);