Asset Entry Codec as Enum with Metadata

This commit is contained in:
2026-04-09 18:44:41 +01:00
parent 7215edfe03
commit 5faf9ac6db
12 changed files with 547 additions and 50 deletions
+20 -26
View File
@@ -2,8 +2,8 @@
use crate::memory_banks::{SoundBankPoolInstaller, TileBankPoolInstaller};
use prometeu_hal::AssetBridge;
use prometeu_hal::asset::{
AssetEntry, AssetId, AssetLoadError, AssetOpStatus, BankStats, BankType, HandleId, LoadStatus,
PreloadEntry, SlotRef, SlotStats,
AssetCodec, AssetEntry, AssetId, AssetLoadError, AssetOpStatus, BankStats, BankType, HandleId,
LoadStatus, PreloadEntry, SlotRef, SlotStats,
};
use prometeu_hal::cartridge::AssetsPayloadSource;
use prometeu_hal::color::Color;
@@ -179,10 +179,6 @@ impl AssetBridge for AssetManager {
}
impl AssetManager {
fn codec_is_none_or_legacy_raw(codec: &str) -> bool {
matches!(codec, "NONE" | "RAW")
}
fn decode_tile_bank_layout(
entry: &AssetEntry,
) -> Result<(TileSize, usize, usize, usize), String> {
@@ -242,14 +238,9 @@ impl AssetManager {
}
fn op_mode_for(entry: &AssetEntry) -> Result<AssetOpMode, String> {
match entry.bank_type {
BankType::TILES if Self::codec_is_none_or_legacy_raw(entry.codec.as_str()) => {
Ok(AssetOpMode::StageInMemory)
}
BankType::SOUNDS if Self::codec_is_none_or_legacy_raw(entry.codec.as_str()) => {
Ok(AssetOpMode::DirectFromSlice)
}
_ => Err(format!("Unsupported codec: {}", entry.codec)),
match (entry.bank_type, entry.codec) {
(BankType::TILES, AssetCodec::None) => Ok(AssetOpMode::StageInMemory),
(BankType::SOUNDS, AssetCodec::None) => Ok(AssetOpMode::DirectFromSlice),
}
}
@@ -882,6 +873,7 @@ impl AssetManager {
mod tests {
use super::*;
use crate::memory_banks::{MemoryBanks, SoundBankPoolAccess, TileBankPoolAccess};
use prometeu_hal::asset::AssetCodec;
fn expected_tile_payload_size(width: usize, height: usize) -> usize {
(width * height).div_ceil(2) + TILE_BANK_PALETTE_BYTES_V1
@@ -905,12 +897,13 @@ mod tests {
offset: 0,
size: expected_tile_payload_size(width, height) as u64,
decoded_size: expected_tile_decoded_size(width, height) as u64,
codec: "NONE".to_string(),
codec: AssetCodec::None,
metadata: serde_json::json!({
"tile_size": 16,
"width": width,
"height": height,
"palette_count": TILE_BANK_PALETTE_COUNT_V1
"palette_count": TILE_BANK_PALETTE_COUNT_V1,
"palette_authored": TILE_BANK_PALETTE_COUNT_V1
}),
}
}
@@ -964,10 +957,8 @@ mod tests {
}
#[test]
fn test_op_mode_for_tiles_raw_is_legacy_alias() {
let mut entry = test_tile_asset_entry("tiles", 16, 16);
entry.codec = "RAW".to_string();
fn test_op_mode_for_tiles_none_uses_typed_codec() {
let entry = test_tile_asset_entry("tiles", 16, 16);
assert_eq!(AssetManager::op_mode_for(&entry), Ok(AssetOpMode::StageInMemory));
}
@@ -980,9 +971,10 @@ mod tests {
offset: 0,
size: 8,
decoded_size: 8,
codec: "NONE".to_string(),
codec: AssetCodec::None,
metadata: serde_json::json!({
"sample_rate": 44100
"sample_rate": 44100,
"channels": 1
}),
};
@@ -1074,9 +1066,10 @@ mod tests {
offset: 0,
size: data.len() as u64,
decoded_size: data.len() as u64,
codec: "NONE".to_string(),
codec: AssetCodec::None,
metadata: serde_json::json!({
"sample_rate": 44100
"sample_rate": 44100,
"channels": 1
}),
};
@@ -1117,9 +1110,10 @@ mod tests {
offset: 0,
size: data.len() as u64,
decoded_size: data.len() as u64,
codec: "NONE".to_string(),
codec: AssetCodec::None,
metadata: serde_json::json!({
"sample_rate": 44100
"sample_rate": 44100,
"channels": 1
}),
};
+2 -6
View File
@@ -1,12 +1,12 @@
use crate::memory_banks::TileBankPoolAccess;
use prometeu_hal::GfxBridge;
use prometeu_hal::color::Color;
use prometeu_hal::glyph::Glyph;
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;
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.
@@ -275,11 +275,7 @@ 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_GLYPH: Glyph = Glyph { glyph_id: 0, palette_id: 0 };
const EMPTY_SPRITE: Sprite = Sprite {
glyph: EMPTY_GLYPH,