From 9451959f789aa85cffa32a7c3eec30178785b73d Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Thu, 3 Nov 2022 02:07:59 +0100 Subject: [PATCH] Use at most 16 textures for ground and structures and load a part of the ground --- src/main.rs | 24 ++++++++++++------------ src/support/mod.rs | 35 ++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9faabbc..36b3a19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ struct PerInstance { } implement_vertex!(PerInstance, w_position, w_rotation); -const STRUCTURES_TEXTURES_NUMBER: usize = 78; +const STRUCTURES_TEXTURES_NUMBER: usize = 16; //78; const STRUCTURES_TEXTURES: [&str; STRUCTURES_TEXTURES_NUMBER] = [ "redNoise.jpg", "cargoLightBlue.jpg", @@ -43,7 +43,7 @@ const STRUCTURES_TEXTURES: [&str; STRUCTURES_TEXTURES_NUMBER] = [ "30kmh.jpg", "white.jpg", "blackYellow.jpg", - "stopText.jpg", + /*"stopText.jpg", "cargoOrange.jpg", "redWhite.jpg", "grid.png", @@ -104,7 +104,7 @@ const STRUCTURES_TEXTURES: [&str; STRUCTURES_TEXTURES_NUMBER] = [ "yellowNoise.jpg", "gridFull.jpg", "rust.jpg", - "cargo.jpg", + "cargo.jpg",*/ ]; // This approach works as there isn't file names having several file extensions. @@ -126,7 +126,7 @@ static STRUCTURES_TEXTURES_REVERSED: phf::Map<&'static str, u32> = phf_map! { "30kmh" => 13, "white" => 14, "blackYellow" => 15, - "stopText" => 16, + /*"stopText" => 16, "cargoOrange" => 17, "redWhite" => 18, "grid" => 19, @@ -187,10 +187,10 @@ static STRUCTURES_TEXTURES_REVERSED: phf::Map<&'static str, u32> = phf_map! { "yellowNoise" => 74, "gridFull" => 75, "rust" => 76, - "cargo" => 77, + "cargo" => 77,*/ }; -const BIOMES_NUMBER: usize = 19; +const BIOMES_NUMBER: usize = 16; //19; const BIOMES: [&str; BIOMES_NUMBER] = [ "dirt", "grassDry", @@ -208,9 +208,9 @@ const BIOMES: [&str; BIOMES_NUMBER] = [ "mud", "stonyThistle", "marsh", - "dead", + /*"dead", "desert", - "weed", + "weed",*/ ]; fn main() { @@ -549,9 +549,9 @@ fn main() { tex13: &ground_textures[13], tex14: &ground_textures[14], tex15: &ground_textures[15], - tex16: &ground_textures[16], + /*tex16: &ground_textures[16], tex17: &ground_textures[17], - tex18: &ground_textures[18], + tex18: &ground_textures[18],*/ }; // That way we *load* far too many textures per structure but until haven't treated http://gitea.lemnoslife.com:3006/Benjamin_Loison/LemnosLife_Rust/issues/6#issuecomment-240, can't do better. @@ -575,7 +575,7 @@ fn main() { tex13: &structures_textures[13], tex14: &structures_textures[14], tex15: &structures_textures[15], - tex16: &structures_textures[16], + /*tex16: &structures_textures[16], tex17: &structures_textures[17], tex18: &structures_textures[18], tex19: &structures_textures[19], @@ -636,7 +636,7 @@ fn main() { tex74: &structures_textures[74], tex75: &structures_textures[75], tex76: &structures_textures[76], - tex77: &structures_textures[77], + tex77: &structures_textures[77],*/ }; // draw parameters diff --git a/src/support/mod.rs b/src/support/mod.rs index 738c6e6..8b06cbb 100644 --- a/src/support/mod.rs +++ b/src/support/mod.rs @@ -97,13 +97,14 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { let paths = fs::read_dir(ground_folder).unwrap(); for (i, path) in (0_u32..).zip(paths) { - let file_name = path - .unwrap() - .path() - .to_str() - .unwrap() - .replace(ground_folder, "") - .replace(".height", ""); + let file_name = path + .unwrap() + .path() + .to_str() + .unwrap() + .replace(ground_folder, "") + .replace(".height", ""); + //for file_name in ["3 13"] { println!("{}", file_name); let file_name_parts: Vec<&str> = file_name.split(' ').collect(); @@ -187,9 +188,9 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { chunk, }); // i == 250 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BufferCreationError(OutOfMemory)', src/support/mod.rs:203:10 - /*if i == 1 { + if i == 200 { break; - }*/ + } } println!("charlie"); @@ -226,7 +227,13 @@ pub fn load_wavefront(display: &Display, data: &[u8]) -> VertexBufferAny { let texture_index = if let obj::ObjMaterial::Ref(texture) = group.material.as_ref().unwrap() { - STRUCTURES_TEXTURES_REVERSED[texture] + if let Some(texture_index) = + STRUCTURES_TEXTURES_REVERSED.get(texture) + { + *texture_index + } else { + 0 + } } else { panic!() }; @@ -246,7 +253,13 @@ pub fn load_wavefront(display: &Display, data: &[u8]) -> VertexBufferAny { let texture_index = if let obj::ObjMaterial::Ref(texture) = group.material.as_ref().unwrap() { - STRUCTURES_TEXTURES_REVERSED[texture] + if let Some(texture_index) = + STRUCTURES_TEXTURES_REVERSED.get(texture) + { + *texture_index + } else { + 0 + } } else { panic!() };