loading all chunks at the same place

This commit is contained in:
2022-10-19 01:50:49 +02:00
parent f9d77ea119
commit 33628ef7bc
2 changed files with 131 additions and 72 deletions
+103 -65
View File
@@ -61,7 +61,16 @@ fn get_biome(line: &str, index: usize) -> u32 {
biome_char.to_digit(10).unwrap()
} else {
(10 + (biome_char as u8 - 'A' as u8)) as u32
}
};
}
fn get_altitude(height_columns: &Vec<&str>, columns_index: usize) -> f32 {
let height_str = height_columns[columns_index];
return if height_str == "N" {
-100.0
} else {
height_str.parse::<f32>().unwrap()
};
}
/// Returns a vertex buffer that should be rendered as `TrianglesList`.
@@ -78,91 +87,120 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
let mut vertex_data: Vec<Vertex> = Vec::new();
// TODO: load "all" ground/biomes files
// TODO: use triangle strip
let height_contents = fs::read_to_string("Extensions/LemnosLife/Map/Altis/Ground/13 13.height")
let ground_folder = "Extensions/LemnosLife/Map/Altis/Ground/";
let paths = fs::read_dir(ground_folder).unwrap();
let mut i: u32 = 0;
for path in paths {
let file_name = path
.unwrap()
.path()
.to_str()
.unwrap()
.replace("Extensions/LemnosLife/Map/Altis/Ground/", "")
.replace(".height", "");
println!("{}", file_name);
// have deleted a few height files to make it work
// TODO: use triangle strip
let height_contents = fs::read_to_string(&format!(
"Extensions/LemnosLife/Map/Altis/Ground/{}.height",
file_name
))
.expect("Unable to load ground file!");
let biomes_contents = fs::read_to_string("Extensions/LemnosLife/Map/Altis/Biomes/13 13.biomes")
let biomes_contents = fs::read_to_string(&format!(
"Extensions/LemnosLife/Map/Altis/Biomes/{}.biomes",
file_name
))
.expect("Unable to load biomes file!");
println!("alpha");
let height_lines: Vec<&str> = height_contents.split('\n').collect();
let height_lines: Vec<&str> = height_contents.split('\n').collect();
let biomes_lines: Vec<&str> = biomes_contents.split('\n').collect();
let biomes_lines: Vec<&str> = biomes_contents.split('\n').collect();
println!("beta");
let mut index: u32 = 0;
let mut index: u32 = 0;
for lines_index in 0..height_lines.len() - 1 {
let height_line = height_lines[lines_index];
let height_next_line = height_lines[lines_index + 1];
let height_columns: Vec<&str> = height_line.split(' ').collect();
let height_next_columns: Vec<&str> = height_next_line.split(' ').collect();
for lines_index in 0..height_lines.len() - 1 {
let height_line = height_lines[lines_index];
let height_next_line = height_lines[lines_index + 1];
let height_columns: Vec<&str> = height_line.split(' ').collect();
let height_next_columns: Vec<&str> = height_next_line.split(' ').collect();
let biomes_line = biomes_lines[lines_index / 2];
let biomes_line = biomes_lines[lines_index / 2];
for columns_index in 0..height_columns.len() - 1 {
let column = height_columns[columns_index].parse::<f32>().unwrap();
let column_right = height_columns[columns_index + 1].parse::<f32>().unwrap();
let column_below = height_next_columns[columns_index].parse::<f32>().unwrap();
let column_below_right = height_next_columns[columns_index + 1].parse::<f32>().unwrap();
for columns_index in 0..height_columns.len() - 1 {
let column = get_altitude(&height_columns, columns_index);
let column_right = get_altitude(&height_columns, columns_index + 1);
let column_below = get_altitude(&height_next_columns, columns_index);
let column_below_right = get_altitude(&height_next_columns, columns_index + 1);
let biome = get_biome(biomes_line, columns_index / 2);
let biome = get_biome(biomes_line, columns_index / 2);
// TODO: compute normals if necessary.
// TODO: compute normals if necessary.
// First triangle.
// First triangle.
vertex_data.push(Vertex {
altitude: column,
normal: [0.0, 0.0, 1.0],
index,
biome,
});
index += 1;
vertex_data.push(Vertex {
altitude: column,
normal: [0.0, 0.0, 1.0],
index,
biome,
});
index += 1;
vertex_data.push(Vertex {
altitude: column_right,
normal: [0.0, 0.0, 1.0],
index,
biome
});
index += 1;
vertex_data.push(Vertex {
altitude: column_right,
normal: [0.0, 0.0, 1.0],
index,
biome,
});
index += 1;
vertex_data.push(Vertex {
altitude: column_below,
normal: [0.0, 0.0, 1.0],
index,
biome
});
index += 1;
vertex_data.push(Vertex {
altitude: column_below,
normal: [0.0, 0.0, 1.0],
index,
biome,
});
index += 1;
// Second triangle.
// Second triangle.
vertex_data.push(Vertex {
altitude: column_below,
normal: [0.0, 0.0, 1.0],
index,
biome
});
index += 1;
vertex_data.push(Vertex {
altitude: column_below,
normal: [0.0, 0.0, 1.0],
index,
biome,
});
index += 1;
vertex_data.push(Vertex {
altitude: column_right,
normal: [0.0, 0.0, 1.0],
index,
biome
});
index += 1;
vertex_data.push(Vertex {
altitude: column_right,
normal: [0.0, 0.0, 1.0],
index,
biome,
});
index += 1;
vertex_data.push(Vertex {
altitude: column_below_right,
normal: [0.0, 0.0, 1.0],
index,
biome
});
index += 1;
vertex_data.push(Vertex {
altitude: column_below_right,
normal: [0.0, 0.0, 1.0],
index,
biome,
});
index += 1;
}
}
i += 1;
// i == 250 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BufferCreationError(OutOfMemory)', src/support/mod.rs:203:10
if i == 200 {
break;
}
}
println!("charlie");
glium::vertex::VertexBuffer::new(display, &vertex_data)
.unwrap()