fixes all around gfx and prometeu render
Intrepid/Prometeu/Runtime/pipeline/head There was a failure building this commit
Intrepid/Prometeu/Runtime/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use crate::gfx_overlay::{DeferredGfxOverlay, OverlayCommand};
|
||||
use crate::memory_banks::GlyphBankPoolAccess;
|
||||
use prometeu_hal::GfxBridge;
|
||||
use prometeu_hal::color::Color;
|
||||
@@ -34,9 +33,7 @@ pub enum BlendMode {
|
||||
///
|
||||
/// `Gfx` owns the framebuffer backend and the canonical game-frame raster path
|
||||
/// consumed by `FrameComposer`. That canonical path covers scene composition,
|
||||
/// sprite composition, and fades. Public `gfx.*` primitives remain valid, but
|
||||
/// they do not define the canonical game composition contract; they belong to a
|
||||
/// separate final overlay/debug stage.
|
||||
/// sprite composition, and fades. Public `gfx.*` primitives remain valid.
|
||||
pub struct Gfx {
|
||||
/// Width of the internal framebuffer in pixels.
|
||||
w: usize,
|
||||
@@ -45,15 +42,10 @@ pub struct Gfx {
|
||||
/// Front buffer: the "VRAM" currently being displayed by the Host window.
|
||||
front: Vec<u16>,
|
||||
/// Back buffer: the working buffer where canonical game frames are composed
|
||||
/// before any final overlay/debug drain.
|
||||
back: Vec<u16>,
|
||||
|
||||
/// Shared access to graphical memory banks (tiles and palettes).
|
||||
pub glyph_banks: Arc<dyn GlyphBankPoolAccess>,
|
||||
/// Deferred overlay/debug capture kept separate from canonical game composition.
|
||||
overlay: DeferredGfxOverlay,
|
||||
/// Internal guard to replay deferred overlay commands without re-enqueueing them.
|
||||
is_draining_overlay: bool,
|
||||
/// Hardware sprite list (512 slots). Equivalent to OAM (Object Attribute Memory).
|
||||
pub sprites: [Sprite; 512],
|
||||
|
||||
@@ -298,8 +290,6 @@ impl Gfx {
|
||||
front: vec![0; len],
|
||||
back: vec![0; len],
|
||||
glyph_banks,
|
||||
overlay: DeferredGfxOverlay::default(),
|
||||
is_draining_overlay: false,
|
||||
sprites: [EMPTY_SPRITE; 512],
|
||||
sprite_count: 0,
|
||||
scene_fade_level: 31,
|
||||
@@ -319,42 +309,6 @@ impl Gfx {
|
||||
(self.w, self.h)
|
||||
}
|
||||
|
||||
pub fn begin_overlay_frame(&mut self) {
|
||||
self.overlay.begin_frame();
|
||||
}
|
||||
|
||||
pub fn overlay(&self) -> &DeferredGfxOverlay {
|
||||
&self.overlay
|
||||
}
|
||||
|
||||
pub fn drain_overlay_debug(&mut self) {
|
||||
let commands = self.overlay.take_commands();
|
||||
self.is_draining_overlay = true;
|
||||
|
||||
for command in commands {
|
||||
match command {
|
||||
OverlayCommand::FillRectBlend { x, y, w, h, color, mode } => {
|
||||
self.fill_rect_blend(x, y, w, h, color, mode)
|
||||
}
|
||||
OverlayCommand::DrawLine { x0, y0, x1, y1, color } => {
|
||||
self.draw_line(x0, y0, x1, y1, color)
|
||||
}
|
||||
OverlayCommand::DrawCircle { x, y, r, color } => self.draw_circle(x, y, r, color),
|
||||
OverlayCommand::DrawDisc { x, y, r, border_color, fill_color } => {
|
||||
self.draw_disc(x, y, r, border_color, fill_color)
|
||||
}
|
||||
OverlayCommand::DrawSquare { x, y, w, h, border_color, fill_color } => {
|
||||
self.draw_square(x, y, w, h, border_color, fill_color)
|
||||
}
|
||||
OverlayCommand::DrawText { x, y, text, color } => {
|
||||
self.draw_text(x, y, &text, color)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.is_draining_overlay = false;
|
||||
}
|
||||
|
||||
/// The buffer that the host should display (RGB565).
|
||||
pub fn front_buffer(&self) -> &[u16] {
|
||||
&self.front
|
||||
@@ -374,10 +328,6 @@ impl Gfx {
|
||||
color: Color,
|
||||
mode: BlendMode,
|
||||
) {
|
||||
if !self.is_draining_overlay {
|
||||
self.overlay.push(OverlayCommand::FillRectBlend { x, y, w, h, color, mode });
|
||||
return;
|
||||
}
|
||||
if color == Color::COLOR_KEY {
|
||||
return;
|
||||
}
|
||||
@@ -419,10 +369,6 @@ impl Gfx {
|
||||
|
||||
/// Draws a line between two points using Bresenham's algorithm.
|
||||
pub fn draw_line(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: Color) {
|
||||
if !self.is_draining_overlay {
|
||||
self.overlay.push(OverlayCommand::DrawLine { x0, y0, x1, y1, color });
|
||||
return;
|
||||
}
|
||||
if color == Color::COLOR_KEY {
|
||||
return;
|
||||
}
|
||||
@@ -455,10 +401,6 @@ impl Gfx {
|
||||
|
||||
/// Draws a circle outline using Midpoint Circle Algorithm.
|
||||
pub fn draw_circle(&mut self, xc: i32, yc: i32, r: i32, color: Color) {
|
||||
if !self.is_draining_overlay {
|
||||
self.overlay.push(OverlayCommand::DrawCircle { x: xc, y: yc, r, color });
|
||||
return;
|
||||
}
|
||||
if color == Color::COLOR_KEY {
|
||||
return;
|
||||
}
|
||||
@@ -527,10 +469,6 @@ impl Gfx {
|
||||
|
||||
/// Draws a disc (filled circle with border).
|
||||
pub fn draw_disc(&mut self, x: i32, y: i32, r: i32, border_color: Color, fill_color: Color) {
|
||||
if !self.is_draining_overlay {
|
||||
self.overlay.push(OverlayCommand::DrawDisc { x, y, r, border_color, fill_color });
|
||||
return;
|
||||
}
|
||||
self.fill_circle(x, y, r, fill_color);
|
||||
self.draw_circle(x, y, r, border_color);
|
||||
}
|
||||
@@ -560,10 +498,6 @@ impl Gfx {
|
||||
border_color: Color,
|
||||
fill_color: Color,
|
||||
) {
|
||||
if !self.is_draining_overlay {
|
||||
self.overlay.push(OverlayCommand::DrawSquare { x, y, w, h, border_color, fill_color });
|
||||
return;
|
||||
}
|
||||
self.fill_rect(x, y, w, h, fill_color);
|
||||
self.draw_rect(x, y, w, h, border_color);
|
||||
}
|
||||
@@ -863,10 +797,6 @@ impl Gfx {
|
||||
}
|
||||
|
||||
pub fn draw_text(&mut self, x: i32, y: i32, text: &str, color: Color) {
|
||||
if !self.is_draining_overlay {
|
||||
self.overlay.push(OverlayCommand::DrawText { x, y, text: text.to_string(), color });
|
||||
return;
|
||||
}
|
||||
let mut cx = x;
|
||||
for c in text.chars() {
|
||||
self.draw_char(cx, y, c, color);
|
||||
@@ -961,9 +891,7 @@ fn blend_rgb565(dst: u16, src: u16, mode: BlendMode) -> u16 {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::FrameComposer;
|
||||
use crate::asset::GlyphAssetSlotIndex;
|
||||
use crate::memory_banks::{GlyphBankPoolInstaller, MemoryBanks, SceneBankPoolAccess};
|
||||
use crate::memory_banks::{GlyphBankPoolInstaller, MemoryBanks};
|
||||
use prometeu_hal::asset::AssetId;
|
||||
use prometeu_hal::glyph_bank::TileSize;
|
||||
use prometeu_hal::scene_bank::SceneBank;
|
||||
@@ -1047,16 +975,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn make_glyph_slot_index(bindings: &[(AssetId, usize)]) -> GlyphAssetSlotIndex {
|
||||
let index = GlyphAssetSlotIndex::new();
|
||||
let mut slots = [None; 16];
|
||||
for (asset_id, slot) in bindings {
|
||||
slots[*slot] = Some(*asset_id);
|
||||
}
|
||||
index.rebuild_from_slots(&slots);
|
||||
index
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_draw_pixel() {
|
||||
let banks = Arc::new(MemoryBanks::new());
|
||||
@@ -1073,12 +991,9 @@ mod tests {
|
||||
fn test_draw_line() {
|
||||
let banks = Arc::new(MemoryBanks::new());
|
||||
let mut gfx = Gfx::new(10, 10, banks);
|
||||
gfx.begin_overlay_frame();
|
||||
gfx.draw_line(0, 0, 9, 9, Color::WHITE);
|
||||
gfx.drain_overlay_debug();
|
||||
assert_eq!(gfx.back[0], Color::WHITE.0);
|
||||
assert_eq!(gfx.back[9 * 10 + 9], Color::WHITE.0);
|
||||
assert_eq!(gfx.overlay().command_count(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1104,56 +1019,9 @@ mod tests {
|
||||
fn test_draw_square() {
|
||||
let banks = Arc::new(MemoryBanks::new());
|
||||
let mut gfx = Gfx::new(10, 10, banks);
|
||||
gfx.begin_overlay_frame();
|
||||
gfx.draw_square(2, 2, 6, 6, Color::WHITE, Color::BLACK);
|
||||
gfx.drain_overlay_debug();
|
||||
assert_eq!(gfx.back[2 * 10 + 2], Color::WHITE.0);
|
||||
assert_eq!(gfx.back[3 * 10 + 3], Color::BLACK.0);
|
||||
assert_eq!(gfx.overlay().command_count(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn draw_text_captures_overlay_command() {
|
||||
let banks = Arc::new(MemoryBanks::new());
|
||||
let mut gfx = Gfx::new(32, 18, banks);
|
||||
gfx.begin_overlay_frame();
|
||||
|
||||
gfx.draw_text(4, 5, "HUD", Color::WHITE);
|
||||
|
||||
assert_eq!(
|
||||
gfx.overlay().commands(),
|
||||
&[OverlayCommand::DrawText { x: 4, y: 5, text: "HUD".into(), color: Color::WHITE }]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlay_state_is_separate_from_frame_composer_sprite_state() {
|
||||
let banks = Arc::new(MemoryBanks::new());
|
||||
let mut gfx = Gfx::new(32, 18, Arc::clone(&banks) as Arc<dyn GlyphBankPoolAccess>);
|
||||
let mut frame_composer = FrameComposer::new(
|
||||
32,
|
||||
18,
|
||||
Arc::clone(&banks) as Arc<dyn SceneBankPoolAccess>,
|
||||
make_glyph_slot_index(&[]),
|
||||
);
|
||||
|
||||
gfx.begin_overlay_frame();
|
||||
frame_composer.begin_frame();
|
||||
frame_composer.emit_sprite(Sprite {
|
||||
glyph: Glyph { glyph_id: 0, palette_id: 0 },
|
||||
x: 1,
|
||||
y: 2,
|
||||
layer: 0,
|
||||
bank_id: 0,
|
||||
active: true,
|
||||
flip_x: false,
|
||||
flip_y: false,
|
||||
priority: 0,
|
||||
});
|
||||
gfx.draw_text(1, 1, "X", Color::WHITE);
|
||||
|
||||
assert_eq!(frame_composer.sprite_controller().sprite_count(), 1);
|
||||
assert_eq!(gfx.overlay().command_count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user