implements Glyph and update Tile to use active (dsc16: done)
This commit is contained in:
@@ -6,6 +6,7 @@ use prometeu_hal::tile::Tile;
|
||||
use prometeu_hal::tile_bank::{TileBank, TileSize};
|
||||
use prometeu_hal::tile_layer::{HudTileLayer, ScrollableTileLayer, TileMap};
|
||||
use std::sync::Arc;
|
||||
use prometeu_hal::glyph::Glyph;
|
||||
|
||||
/// Blending modes inspired by classic 16-bit hardware.
|
||||
/// Defines how source pixels are combined with existing pixels in the framebuffer.
|
||||
@@ -274,8 +275,14 @@ 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 {
|
||||
|
||||
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,
|
||||
@@ -706,7 +713,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;
|
||||
}
|
||||
|
||||
@@ -757,7 +764,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 +772,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();
|
||||
}
|
||||
@@ -812,7 +819,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 +827,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();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Glyph {
|
||||
pub glyph_id: u16,
|
||||
pub palette_id: u8,
|
||||
}
|
||||
@@ -26,6 +26,7 @@ pub mod tile_layer;
|
||||
pub mod touch_bridge;
|
||||
pub mod vm_fault;
|
||||
pub mod window;
|
||||
pub mod glyph;
|
||||
|
||||
pub use asset_bridge::AssetBridge;
|
||||
pub use audio_bridge::{AudioBridge, AudioOpStatus, LoopMode};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::tile::Tile;
|
||||
use crate::glyph::Glyph;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Sprite {
|
||||
pub tile: Tile,
|
||||
pub glyph: Glyph,
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub bank_id: u8,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use crate::glyph::Glyph;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Tile {
|
||||
pub id: u16,
|
||||
pub glyph: Glyph,
|
||||
pub active: bool,
|
||||
pub flip_x: bool,
|
||||
pub flip_y: bool,
|
||||
pub palette_id: u8,
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ use prometeu_hal::color::Color;
|
||||
use prometeu_hal::log::{LogLevel, LogSource};
|
||||
use prometeu_hal::sprite::Sprite;
|
||||
use prometeu_hal::syscalls::Syscall;
|
||||
use prometeu_hal::tile::Tile;
|
||||
use prometeu_hal::vm_fault::VmFault;
|
||||
use prometeu_hal::{
|
||||
AudioOpStatus, GfxOpStatus, HostContext, HostReturn, NativeInterface, SyscallId, expect_bool,
|
||||
expect_int,
|
||||
};
|
||||
use prometeu_hal::glyph::Glyph;
|
||||
|
||||
impl VirtualMachineRuntime {
|
||||
fn syscall_log_write(&mut self, level_val: i64, tag: u16, msg: String) -> Result<(), VmFault> {
|
||||
@@ -139,7 +139,7 @@ impl NativeInterface for VirtualMachineRuntime {
|
||||
let index = expect_int(args, 1)? as usize;
|
||||
let x = expect_int(args, 2)? as i32;
|
||||
let y = expect_int(args, 3)? as i32;
|
||||
let tile_id = expect_int(args, 4)? as u16;
|
||||
let glyph_id = expect_int(args, 4)? as u16;
|
||||
let palette_id = expect_int(args, 5)? as u8;
|
||||
let active = expect_bool(args, 6)?;
|
||||
let flip_x = expect_bool(args, 7)?;
|
||||
@@ -162,7 +162,10 @@ impl NativeInterface for VirtualMachineRuntime {
|
||||
}
|
||||
|
||||
*hw.gfx_mut().sprite_mut(index) = Sprite {
|
||||
tile: Tile { id: tile_id, flip_x: false, flip_y: false, palette_id },
|
||||
glyph: Glyph {
|
||||
glyph_id,
|
||||
palette_id,
|
||||
},
|
||||
x,
|
||||
y,
|
||||
bank_id,
|
||||
|
||||
Reference in New Issue
Block a user