adjustments over frame composer contract - agnostic tile size
This commit is contained in:
@@ -79,6 +79,21 @@ pub struct Gfx {
|
||||
|
||||
const GLYPH_UNKNOWN: [u8; 5] = [0x7, 0x7, 0x7, 0x7, 0x7];
|
||||
|
||||
struct RenderTarget<'a> {
|
||||
back: &'a mut [u16],
|
||||
screen_w: usize,
|
||||
screen_h: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct CachedTileDraw<'a> {
|
||||
x: i32,
|
||||
y: i32,
|
||||
entry: CachedTileEntry,
|
||||
bank: &'a GlyphBank,
|
||||
tile_size: prometeu_hal::glyph_bank::TileSize,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn glyph_for_char(c: char) -> &'static [u8; 5] {
|
||||
match c.to_ascii_uppercase() {
|
||||
@@ -629,6 +644,7 @@ impl Gfx {
|
||||
request: &LayerCopyRequest,
|
||||
glyph_banks: &dyn GlyphBankPoolAccess,
|
||||
) {
|
||||
let mut target = RenderTarget { back, screen_w, screen_h };
|
||||
let layer_cache = &cache.layers[request.layer_index];
|
||||
if !layer_cache.valid {
|
||||
return;
|
||||
@@ -657,52 +673,43 @@ impl Gfx {
|
||||
}
|
||||
|
||||
Self::draw_cached_tile_pixels(
|
||||
back,
|
||||
screen_w,
|
||||
screen_h,
|
||||
screen_tile_x,
|
||||
screen_tile_y,
|
||||
entry,
|
||||
&bank,
|
||||
request.tile_size,
|
||||
&mut target,
|
||||
CachedTileDraw {
|
||||
x: screen_tile_x,
|
||||
y: screen_tile_y,
|
||||
entry,
|
||||
bank: &bank,
|
||||
tile_size: request.tile_size,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_cached_tile_pixels(
|
||||
back: &mut [u16],
|
||||
screen_w: usize,
|
||||
screen_h: usize,
|
||||
x: i32,
|
||||
y: i32,
|
||||
entry: CachedTileEntry,
|
||||
bank: &GlyphBank,
|
||||
tile_size: prometeu_hal::glyph_bank::TileSize,
|
||||
) {
|
||||
let size = tile_size as usize;
|
||||
fn draw_cached_tile_pixels(target: &mut RenderTarget<'_>, tile: CachedTileDraw<'_>) {
|
||||
let size = tile.tile_size as usize;
|
||||
|
||||
for local_y in 0..size {
|
||||
let world_y = y + local_y as i32;
|
||||
if world_y < 0 || world_y >= screen_h as i32 {
|
||||
let world_y = tile.y + local_y as i32;
|
||||
if world_y < 0 || world_y >= target.screen_h as i32 {
|
||||
continue;
|
||||
}
|
||||
|
||||
for local_x in 0..size {
|
||||
let world_x = x + local_x as i32;
|
||||
if world_x < 0 || world_x >= screen_w as i32 {
|
||||
let world_x = tile.x + local_x as i32;
|
||||
if world_x < 0 || world_x >= target.screen_w as i32 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let fetch_x = if entry.flip_x() { size - 1 - local_x } else { local_x };
|
||||
let fetch_y = if entry.flip_y() { size - 1 - local_y } else { local_y };
|
||||
let px_index = bank.get_pixel_index(entry.glyph_id, fetch_x, fetch_y);
|
||||
let fetch_x = if tile.entry.flip_x() { size - 1 - local_x } else { local_x };
|
||||
let fetch_y = if tile.entry.flip_y() { size - 1 - local_y } else { local_y };
|
||||
let px_index = tile.bank.get_pixel_index(tile.entry.glyph_id, fetch_x, fetch_y);
|
||||
if px_index == 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let color = bank.resolve_color(entry.palette_id, px_index);
|
||||
back[world_y as usize * screen_w + world_x as usize] = color.raw();
|
||||
let color = tile.bank.resolve_color(tile.entry.palette_id, px_index);
|
||||
target.back[world_y as usize * target.screen_w + world_x as usize] = color.raw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user