strafe-client-jed/src/texture.rs

39 lines
938 B
Rust
Raw Normal View History

2024-02-15 07:45:16 +00:00
use strafesnet_common::model::{TextureId,RenderConfigId,RenderConfig};
2024-02-14 03:48:47 +00:00
2024-02-15 07:45:16 +00:00
#[derive(Clone)]
2024-02-14 03:48:47 +00:00
pub enum Texture{
ImageDDS(Vec<u8>),
}
impl AsRef<[u8]> for Texture{
fn as_ref(&self)->&[u8]{
match self{
Texture::ImageDDS(data)=>data.as_ref(),
}
}
}
2024-02-15 07:45:16 +00:00
pub struct RenderConfigs{
textures:Vec<Option<Texture>>,
render_configs:Vec<RenderConfig>,
2024-02-14 03:48:47 +00:00
}
2024-02-15 07:45:16 +00:00
impl RenderConfigs{
pub(crate) const fn new(textures:Vec<Option<Texture>>,render_configs:Vec<RenderConfig>)->Self{
2024-02-14 03:48:47 +00:00
Self{
textures,
2024-02-15 07:45:16 +00:00
render_configs,
2024-02-14 03:48:47 +00:00
}
}
2024-02-15 07:45:16 +00:00
pub fn consume(self)->(
impl Iterator<Item=(TextureId,Texture)>,
impl Iterator<Item=(RenderConfigId,RenderConfig)>
){
(
self.textures.into_iter().enumerate().filter_map(|(texture_id,maybe_texture)|
maybe_texture.map(|texture|(TextureId::new(texture_id as u32),texture))
),
self.render_configs.into_iter().enumerate().map(|(render_id,render)|
(RenderConfigId::new(render_id as u32),render)
),
)
2024-02-14 03:48:47 +00:00
}
2024-02-15 07:45:16 +00:00
}