use boxed str

This commit is contained in:
Quaternions 2024-02-14 14:45:10 -08:00
parent f58cf4ec2a
commit f3174cd191

View File

@ -1,11 +1,10 @@
use std::io::Read;
use std::path::PathBuf;
use std::collections::HashMap;
use crate::texture::{Texture,Textures};
use strafesnet_common::model::{MeshId,TextureId};
pub struct TextureLoader{
texture_paths:HashMap<PathBuf,TextureId>,
texture_paths:HashMap<Box<str>,TextureId>,
}
impl TextureLoader{
pub fn acquire_texture_id(&mut self,name:&str)->TextureId{
@ -14,7 +13,7 @@ impl TextureLoader{
}
}
pub struct MeshLoader{
mesh_paths:HashMap<PathBuf,MeshId>,
mesh_paths:HashMap<Box<str>,MeshId>,
}
impl MeshLoader{
pub fn acquire_mesh_id(&mut self,name:&str)->MeshId{
@ -43,7 +42,7 @@ impl Loader{
pub fn load_textures(&self)->Result<Textures,std::io::Error>{
let mut texture_data=vec![Vec::<u8>::new();self.texture_loader.texture_paths.len()];
for (texture_path,texture_id) in &self.texture_loader.texture_paths{
let path=std::path::PathBuf::from(format!("textures/{}.dds",texture_path.display()));
let path=std::path::PathBuf::from(format!("textures/{}.dds",texture_path));
if let Ok(mut file)=std::fs::File::open(path){
//TODO: parallel
file.read_to_end(texture_data.get_mut(texture_id.get() as usize).unwrap())?;