Use at most 16 textures for ground and structures and load a part of the ground

This commit is contained in:
Benjamin Loison
2022-11-03 02:07:59 +01:00
parent a015f318c7
commit 9451959f78
2 changed files with 36 additions and 23 deletions
+12 -12
View File
@@ -25,7 +25,7 @@ struct PerInstance {
} }
implement_vertex!(PerInstance, w_position, w_rotation); 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] = [ const STRUCTURES_TEXTURES: [&str; STRUCTURES_TEXTURES_NUMBER] = [
"redNoise.jpg", "redNoise.jpg",
"cargoLightBlue.jpg", "cargoLightBlue.jpg",
@@ -43,7 +43,7 @@ const STRUCTURES_TEXTURES: [&str; STRUCTURES_TEXTURES_NUMBER] = [
"30kmh.jpg", "30kmh.jpg",
"white.jpg", "white.jpg",
"blackYellow.jpg", "blackYellow.jpg",
"stopText.jpg", /*"stopText.jpg",
"cargoOrange.jpg", "cargoOrange.jpg",
"redWhite.jpg", "redWhite.jpg",
"grid.png", "grid.png",
@@ -104,7 +104,7 @@ const STRUCTURES_TEXTURES: [&str; STRUCTURES_TEXTURES_NUMBER] = [
"yellowNoise.jpg", "yellowNoise.jpg",
"gridFull.jpg", "gridFull.jpg",
"rust.jpg", "rust.jpg",
"cargo.jpg", "cargo.jpg",*/
]; ];
// This approach works as there isn't file names having several file extensions. // 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, "30kmh" => 13,
"white" => 14, "white" => 14,
"blackYellow" => 15, "blackYellow" => 15,
"stopText" => 16, /*"stopText" => 16,
"cargoOrange" => 17, "cargoOrange" => 17,
"redWhite" => 18, "redWhite" => 18,
"grid" => 19, "grid" => 19,
@@ -187,10 +187,10 @@ static STRUCTURES_TEXTURES_REVERSED: phf::Map<&'static str, u32> = phf_map! {
"yellowNoise" => 74, "yellowNoise" => 74,
"gridFull" => 75, "gridFull" => 75,
"rust" => 76, "rust" => 76,
"cargo" => 77, "cargo" => 77,*/
}; };
const BIOMES_NUMBER: usize = 19; const BIOMES_NUMBER: usize = 16; //19;
const BIOMES: [&str; BIOMES_NUMBER] = [ const BIOMES: [&str; BIOMES_NUMBER] = [
"dirt", "dirt",
"grassDry", "grassDry",
@@ -208,9 +208,9 @@ const BIOMES: [&str; BIOMES_NUMBER] = [
"mud", "mud",
"stonyThistle", "stonyThistle",
"marsh", "marsh",
"dead", /*"dead",
"desert", "desert",
"weed", "weed",*/
]; ];
fn main() { fn main() {
@@ -549,9 +549,9 @@ fn main() {
tex13: &ground_textures[13], tex13: &ground_textures[13],
tex14: &ground_textures[14], tex14: &ground_textures[14],
tex15: &ground_textures[15], tex15: &ground_textures[15],
tex16: &ground_textures[16], /*tex16: &ground_textures[16],
tex17: &ground_textures[17], 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. // 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], tex13: &structures_textures[13],
tex14: &structures_textures[14], tex14: &structures_textures[14],
tex15: &structures_textures[15], tex15: &structures_textures[15],
tex16: &structures_textures[16], /*tex16: &structures_textures[16],
tex17: &structures_textures[17], tex17: &structures_textures[17],
tex18: &structures_textures[18], tex18: &structures_textures[18],
tex19: &structures_textures[19], tex19: &structures_textures[19],
@@ -636,7 +636,7 @@ fn main() {
tex74: &structures_textures[74], tex74: &structures_textures[74],
tex75: &structures_textures[75], tex75: &structures_textures[75],
tex76: &structures_textures[76], tex76: &structures_textures[76],
tex77: &structures_textures[77], tex77: &structures_textures[77],*/
}; };
// draw parameters // draw parameters
+24 -11
View File
@@ -97,13 +97,14 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
let paths = fs::read_dir(ground_folder).unwrap(); let paths = fs::read_dir(ground_folder).unwrap();
for (i, path) in (0_u32..).zip(paths) { for (i, path) in (0_u32..).zip(paths) {
let file_name = path let file_name = path
.unwrap() .unwrap()
.path() .path()
.to_str() .to_str()
.unwrap() .unwrap()
.replace(ground_folder, "") .replace(ground_folder, "")
.replace(".height", ""); .replace(".height", "");
//for file_name in ["3 13"] {
println!("{}", file_name); println!("{}", file_name);
let file_name_parts: Vec<&str> = file_name.split(' ').collect(); let file_name_parts: Vec<&str> = file_name.split(' ').collect();
@@ -187,9 +188,9 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
chunk, chunk,
}); });
// i == 250 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BufferCreationError(OutOfMemory)', src/support/mod.rs:203:10 // 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; break;
}*/ }
} }
println!("charlie"); println!("charlie");
@@ -226,7 +227,13 @@ pub fn load_wavefront(display: &Display, data: &[u8]) -> VertexBufferAny {
let texture_index = if let obj::ObjMaterial::Ref(texture) = let texture_index = if let obj::ObjMaterial::Ref(texture) =
group.material.as_ref().unwrap() group.material.as_ref().unwrap()
{ {
STRUCTURES_TEXTURES_REVERSED[texture] if let Some(texture_index) =
STRUCTURES_TEXTURES_REVERSED.get(texture)
{
*texture_index
} else {
0
}
} else { } else {
panic!() panic!()
}; };
@@ -246,7 +253,13 @@ pub fn load_wavefront(display: &Display, data: &[u8]) -> VertexBufferAny {
let texture_index = if let obj::ObjMaterial::Ref(texture) = let texture_index = if let obj::ObjMaterial::Ref(texture) =
group.material.as_ref().unwrap() group.material.as_ref().unwrap()
{ {
STRUCTURES_TEXTURES_REVERSED[texture] if let Some(texture_index) =
STRUCTURES_TEXTURES_REVERSED.get(texture)
{
*texture_index
} else {
0
}
} else { } else {
panic!() panic!()
}; };