dev/ajustments-asset-entry (#12)
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Reviewed-on: #12 Co-authored-by: bQUARKz <bquarkz@gmail.com> Co-committed-by: bQUARKz <bquarkz@gmail.com>
This commit was merged in pull request #12.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use crate::memory_banks::TileBankPoolAccess;
|
||||
use crate::memory_banks::GlyphBankPoolAccess;
|
||||
use prometeu_hal::GfxBridge;
|
||||
use prometeu_hal::color::Color;
|
||||
use prometeu_hal::glyph::Glyph;
|
||||
use prometeu_hal::glyph_bank::{GlyphBank, TileSize};
|
||||
use prometeu_hal::sprite::Sprite;
|
||||
use prometeu_hal::tile::Tile;
|
||||
use prometeu_hal::tile_bank::{TileBank, TileSize};
|
||||
use prometeu_hal::tile_layer::{HudTileLayer, ScrollableTileLayer, TileMap};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -56,12 +57,12 @@ pub struct Gfx {
|
||||
/// Back buffer: the "Work RAM" where new frames are composed.
|
||||
back: Vec<u16>,
|
||||
|
||||
/// 4 scrollable background layers. Each can have its own scroll (X, Y) and TileBank.
|
||||
/// 4 scrollable background layers. Each can have its own scroll (X, Y) and GlyphBank.
|
||||
pub layers: [ScrollableTileLayer; 4],
|
||||
/// 1 fixed layer for User Interface (HUD). It doesn't scroll.
|
||||
pub hud: HudTileLayer,
|
||||
/// Shared access to graphical memory banks (tiles and palettes).
|
||||
pub tile_banks: Arc<dyn TileBankPoolAccess>,
|
||||
pub glyph_banks: Arc<dyn GlyphBankPoolAccess>,
|
||||
/// Hardware sprite list (512 slots). Equivalent to OAM (Object Attribute Memory).
|
||||
pub sprites: [Sprite; 512],
|
||||
|
||||
@@ -273,9 +274,11 @@ impl GfxBridge for Gfx {
|
||||
|
||||
impl Gfx {
|
||||
/// Initializes the graphics system with a specific resolution and shared memory banks.
|
||||
pub fn new(w: usize, h: usize, tile_banks: Arc<dyn TileBankPoolAccess>) -> Self {
|
||||
pub fn new(w: usize, h: usize, glyph_banks: Arc<dyn GlyphBankPoolAccess>) -> Self {
|
||||
const EMPTY_GLYPH: Glyph = Glyph { glyph_id: 0, palette_id: 0 };
|
||||
|
||||
const EMPTY_SPRITE: Sprite = Sprite {
|
||||
tile: Tile { id: 0, flip_x: false, flip_y: false, palette_id: 0 },
|
||||
glyph: EMPTY_GLYPH,
|
||||
x: 0,
|
||||
y: 0,
|
||||
bank_id: 0,
|
||||
@@ -300,7 +303,7 @@ impl Gfx {
|
||||
back: vec![0; len],
|
||||
layers,
|
||||
hud: HudTileLayer::new(64, 32),
|
||||
tile_banks,
|
||||
glyph_banks,
|
||||
sprites: [EMPTY_SPRITE; 512],
|
||||
scene_fade_level: 31,
|
||||
scene_fade_color: Color::BLACK,
|
||||
@@ -580,14 +583,14 @@ impl Gfx {
|
||||
self.h,
|
||||
&self.priority_buckets[0],
|
||||
&self.sprites,
|
||||
&*self.tile_banks,
|
||||
&*self.glyph_banks,
|
||||
);
|
||||
|
||||
// 2. Main layers and prioritized sprites.
|
||||
// Order: Layer 0 -> Sprites 1 -> Layer 1 -> Sprites 2 ...
|
||||
for i in 0..self.layers.len() {
|
||||
let bank_id = self.layers[i].bank_id as usize;
|
||||
if let Some(bank) = self.tile_banks.tile_bank_slot(bank_id) {
|
||||
if let Some(bank) = self.glyph_banks.glyph_bank_slot(bank_id) {
|
||||
Self::draw_tile_map(
|
||||
&mut self.back,
|
||||
self.w,
|
||||
@@ -606,7 +609,7 @@ impl Gfx {
|
||||
self.h,
|
||||
&self.priority_buckets[i + 1],
|
||||
&self.sprites,
|
||||
&*self.tile_banks,
|
||||
&*self.glyph_banks,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -614,7 +617,7 @@ impl Gfx {
|
||||
Self::apply_fade_to_buffer(&mut self.back, self.scene_fade_level, self.scene_fade_color);
|
||||
|
||||
// 5. HUD: The fixed interface layer, always drawn on top of the world.
|
||||
Self::render_hud_with_pool(&mut self.back, self.w, self.h, &self.hud, &*self.tile_banks);
|
||||
Self::render_hud_with_pool(&mut self.back, self.w, self.h, &self.hud, &*self.glyph_banks);
|
||||
|
||||
// 6. HUD Fade: Independent fade effect for the UI.
|
||||
Self::apply_fade_to_buffer(&mut self.back, self.hud_fade_level, self.hud_fade_color);
|
||||
@@ -630,7 +633,7 @@ impl Gfx {
|
||||
let scroll_x = self.layers[layer_idx].scroll_x;
|
||||
let scroll_y = self.layers[layer_idx].scroll_y;
|
||||
|
||||
let bank = match self.tile_banks.tile_bank_slot(bank_id) {
|
||||
let bank = match self.glyph_banks.glyph_bank_slot(bank_id) {
|
||||
Some(b) => b,
|
||||
_ => return,
|
||||
};
|
||||
@@ -648,7 +651,7 @@ impl Gfx {
|
||||
|
||||
/// Renders the HUD (fixed position, no scroll).
|
||||
pub fn render_hud(&mut self) {
|
||||
Self::render_hud_with_pool(&mut self.back, self.w, self.h, &self.hud, &*self.tile_banks);
|
||||
Self::render_hud_with_pool(&mut self.back, self.w, self.h, &self.hud, &*self.glyph_banks);
|
||||
}
|
||||
|
||||
fn render_hud_with_pool(
|
||||
@@ -656,10 +659,10 @@ impl Gfx {
|
||||
w: usize,
|
||||
h: usize,
|
||||
hud: &HudTileLayer,
|
||||
tile_banks: &dyn TileBankPoolAccess,
|
||||
glyph_banks: &dyn GlyphBankPoolAccess,
|
||||
) {
|
||||
let bank_id = hud.bank_id as usize;
|
||||
let bank = match tile_banks.tile_bank_slot(bank_id) {
|
||||
let bank = match glyph_banks.glyph_bank_slot(bank_id) {
|
||||
Some(b) => b,
|
||||
_ => return,
|
||||
};
|
||||
@@ -673,7 +676,7 @@ impl Gfx {
|
||||
screen_w: usize,
|
||||
screen_h: usize,
|
||||
map: &TileMap,
|
||||
bank: &TileBank,
|
||||
bank: &GlyphBank,
|
||||
scroll_x: i32,
|
||||
scroll_y: i32,
|
||||
) {
|
||||
@@ -706,7 +709,7 @@ impl Gfx {
|
||||
let tile = map.tiles[map_y * map.width + map_x];
|
||||
|
||||
// Optimized skip for empty (ID 0) tiles.
|
||||
if tile.id == 0 {
|
||||
if !tile.active {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -736,7 +739,7 @@ impl Gfx {
|
||||
x: i32,
|
||||
y: i32,
|
||||
tile: Tile,
|
||||
bank: &TileBank,
|
||||
bank: &GlyphBank,
|
||||
) {
|
||||
let size = bank.tile_size as usize;
|
||||
|
||||
@@ -757,7 +760,7 @@ impl Gfx {
|
||||
let fetch_y = if tile.flip_y { size - 1 - local_y } else { local_y };
|
||||
|
||||
// 1. Get the pixel color index (0-15) from the bank.
|
||||
let px_index = bank.get_pixel_index(tile.id, fetch_x, fetch_y);
|
||||
let px_index = bank.get_pixel_index(tile.glyph.glyph_id, fetch_x, fetch_y);
|
||||
|
||||
// 2. Hardware rule: Color index 0 is always fully transparent.
|
||||
if px_index == 0 {
|
||||
@@ -765,7 +768,7 @@ impl Gfx {
|
||||
}
|
||||
|
||||
// 3. Resolve the virtual index to a real RGB565 color using the tile's assigned palette.
|
||||
let color = bank.resolve_color(tile.palette_id, px_index);
|
||||
let color = bank.resolve_color(tile.glyph.palette_id, px_index);
|
||||
|
||||
back[world_y as usize * screen_w + world_x as usize] = color.raw();
|
||||
}
|
||||
@@ -778,12 +781,12 @@ impl Gfx {
|
||||
screen_h: usize,
|
||||
bucket: &[usize],
|
||||
sprites: &[Sprite],
|
||||
tile_banks: &dyn TileBankPoolAccess,
|
||||
glyph_banks: &dyn GlyphBankPoolAccess,
|
||||
) {
|
||||
for &idx in bucket {
|
||||
let s = &sprites[idx];
|
||||
let bank_id = s.bank_id as usize;
|
||||
if let Some(bank) = tile_banks.tile_bank_slot(bank_id) {
|
||||
if let Some(bank) = glyph_banks.glyph_bank_slot(bank_id) {
|
||||
Self::draw_sprite_pixel_by_pixel(back, screen_w, screen_h, s, &bank);
|
||||
}
|
||||
}
|
||||
@@ -794,7 +797,7 @@ impl Gfx {
|
||||
screen_w: usize,
|
||||
screen_h: usize,
|
||||
sprite: &Sprite,
|
||||
bank: &TileBank,
|
||||
bank: &GlyphBank,
|
||||
) {
|
||||
// ... (same bounds/clipping calculation we already had) ...
|
||||
let size = bank.tile_size as usize;
|
||||
@@ -812,7 +815,7 @@ impl Gfx {
|
||||
let fetch_y = if sprite.flip_y { size - 1 - local_y } else { local_y };
|
||||
|
||||
// 1. Get index
|
||||
let px_index = bank.get_pixel_index(sprite.tile.id, fetch_x, fetch_y);
|
||||
let px_index = bank.get_pixel_index(sprite.glyph.glyph_id, fetch_x, fetch_y);
|
||||
|
||||
// 2. Transparency
|
||||
if px_index == 0 {
|
||||
@@ -820,7 +823,7 @@ impl Gfx {
|
||||
}
|
||||
|
||||
// 3. Resolve color via palette (from the tile inside the sprite)
|
||||
let color = bank.resolve_color(sprite.tile.palette_id, px_index);
|
||||
let color = bank.resolve_color(sprite.glyph.palette_id, px_index);
|
||||
|
||||
back[world_y as usize * screen_w + world_x as usize] = color.raw();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user