All checks were successful
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>
140 lines
3.3 KiB
Rust
140 lines
3.3 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
pub type HandleId = u32;
|
|
pub type AssetId = i32;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
|
|
#[allow(non_camel_case_types)]
|
|
pub enum BankType {
|
|
GLYPH,
|
|
SOUNDS,
|
|
// TILEMAPS,
|
|
// BLOBS,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
|
|
pub enum AssetCodec {
|
|
#[serde(rename = "NONE")]
|
|
None,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
pub struct AssetEntry {
|
|
pub asset_id: AssetId,
|
|
pub asset_name: String,
|
|
pub bank_type: BankType,
|
|
pub offset: u64,
|
|
pub size: u64,
|
|
pub decoded_size: u64,
|
|
pub codec: AssetCodec,
|
|
pub metadata: serde_json::Value,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
pub struct GlyphBankMetadata {
|
|
pub tile_size: u32,
|
|
pub width: u32,
|
|
pub height: u32,
|
|
pub palette_count: u32,
|
|
pub palette_authored: u32,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
pub struct SoundBankMetadata {
|
|
pub sample_rate: u32,
|
|
pub channels: u32,
|
|
}
|
|
|
|
impl AssetEntry {
|
|
pub fn metadata_as_glyph_bank(&self) -> Result<GlyphBankMetadata, String> {
|
|
if self.bank_type != BankType::GLYPH {
|
|
return Err(format!(
|
|
"Asset {} is not a GLYPH bank (type: {:?})",
|
|
self.asset_id, self.bank_type
|
|
));
|
|
}
|
|
serde_json::from_value(self.metadata.clone())
|
|
.map_err(|e| format!("Invalid GLYPH metadata for asset {}: {}", self.asset_id, e))
|
|
}
|
|
|
|
pub fn metadata_as_sound_bank(&self) -> Result<SoundBankMetadata, String> {
|
|
if self.bank_type != BankType::SOUNDS {
|
|
return Err(format!(
|
|
"Asset {} is not a SOUNDS bank (type: {:?})",
|
|
self.asset_id, self.bank_type
|
|
));
|
|
}
|
|
serde_json::from_value(self.metadata.clone())
|
|
.map_err(|e| format!("Invalid SOUNDS metadata for asset {}: {}", self.asset_id, e))
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
pub struct PreloadEntry {
|
|
pub asset_id: AssetId,
|
|
pub slot: usize,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[repr(i32)]
|
|
pub enum LoadStatus {
|
|
PENDING = 0,
|
|
LOADING = 1,
|
|
READY = 2,
|
|
COMMITTED = 3,
|
|
CANCELED = 4,
|
|
ERROR = 5,
|
|
UnknownHandle = 6,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
#[repr(i32)]
|
|
pub enum AssetLoadError {
|
|
AssetNotFound = 3,
|
|
SlotKindMismatch = 4,
|
|
SlotIndexInvalid = 5,
|
|
BackendError = 6,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
#[repr(i32)]
|
|
pub enum AssetOpStatus {
|
|
Ok = 0,
|
|
UnknownHandle = 1,
|
|
InvalidState = 2,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct BankStats {
|
|
pub total_bytes: usize,
|
|
pub used_bytes: usize,
|
|
pub free_bytes: usize,
|
|
pub inflight_bytes: usize,
|
|
pub slot_count: usize,
|
|
pub slots_occupied: usize,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct SlotStats {
|
|
pub asset_id: Option<AssetId>,
|
|
pub asset_name: Option<String>,
|
|
pub generation: u32,
|
|
pub resident_bytes: usize,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct SlotRef {
|
|
pub asset_type: BankType,
|
|
pub index: usize,
|
|
}
|
|
|
|
impl SlotRef {
|
|
pub fn gfx(index: usize) -> Self {
|
|
Self { asset_type: BankType::GLYPH, index }
|
|
}
|
|
|
|
pub fn audio(index: usize) -> Self {
|
|
Self { asset_type: BankType::SOUNDS, index }
|
|
}
|
|
}
|