loading all chunks at the same place
This commit is contained in:
+26
-5
@@ -4,8 +4,8 @@ extern crate glium;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate load_file;
|
extern crate load_file;
|
||||||
|
|
||||||
use std::io::Cursor;
|
|
||||||
use glium::texture::SrgbTexture2d;
|
use glium::texture::SrgbTexture2d;
|
||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use glium::{glutin, Surface};
|
use glium::{glutin, Surface};
|
||||||
@@ -13,7 +13,27 @@ use glium::{glutin, Surface};
|
|||||||
mod support;
|
mod support;
|
||||||
|
|
||||||
const BIOMES_NUMBER: usize = 19;
|
const BIOMES_NUMBER: usize = 19;
|
||||||
const BIOMES: [&str; BIOMES_NUMBER] = ["dirt", "grassDry", "grassGreen", "concrete", "soil", "beach", "seabed", "thorn", "wildField", "rock", "grassWild", "stony", "forestPine", "mud", "stonyThistle", "marsh", "dead", "desert", "weed"];
|
const BIOMES: [&str; BIOMES_NUMBER] = [
|
||||||
|
"dirt",
|
||||||
|
"grassDry",
|
||||||
|
"grassGreen",
|
||||||
|
"concrete",
|
||||||
|
"soil",
|
||||||
|
"beach",
|
||||||
|
"seabed",
|
||||||
|
"thorn",
|
||||||
|
"wildField",
|
||||||
|
"rock",
|
||||||
|
"grassWild",
|
||||||
|
"stony",
|
||||||
|
"forestPine",
|
||||||
|
"mud",
|
||||||
|
"stonyThistle",
|
||||||
|
"marsh",
|
||||||
|
"dead",
|
||||||
|
"desert",
|
||||||
|
"weed",
|
||||||
|
];
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// building the display, ie. the main object
|
// building the display, ie. the main object
|
||||||
@@ -28,9 +48,10 @@ fn main() {
|
|||||||
let textures: [SrgbTexture2d; BIOMES_NUMBER] = BIOMES.map(|biome| {
|
let textures: [SrgbTexture2d; BIOMES_NUMBER] = BIOMES.map(|biome| {
|
||||||
println!("{}", biome);
|
println!("{}", biome);
|
||||||
let image = image::load(
|
let image = image::load(
|
||||||
Cursor::new(&load_bytes!(
|
Cursor::new(&load_bytes!(&format!(
|
||||||
&format!("../Extensions/LemnosLife/Assets/Pictures/Map/Ground/{}.jpg", biome)
|
"../Extensions/LemnosLife/Assets/Pictures/Map/Ground/{}.jpg",
|
||||||
)),
|
biome
|
||||||
|
))),
|
||||||
image::ImageFormat::Jpeg,
|
image::ImageFormat::Jpeg,
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|||||||
+50
-12
@@ -61,7 +61,16 @@ fn get_biome(line: &str, index: usize) -> u32 {
|
|||||||
biome_char.to_digit(10).unwrap()
|
biome_char.to_digit(10).unwrap()
|
||||||
} else {
|
} else {
|
||||||
(10 + (biome_char as u8 - 'A' as u8)) as u32
|
(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`.
|
/// Returns a vertex buffer that should be rendered as `TrianglesList`.
|
||||||
@@ -78,17 +87,39 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
|
|||||||
|
|
||||||
let mut vertex_data: Vec<Vertex> = Vec::new();
|
let mut vertex_data: Vec<Vertex> = Vec::new();
|
||||||
|
|
||||||
// TODO: load "all" ground/biomes files
|
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
|
// TODO: use triangle strip
|
||||||
let height_contents = fs::read_to_string("Extensions/LemnosLife/Map/Altis/Ground/13 13.height")
|
let height_contents = fs::read_to_string(&format!(
|
||||||
|
"Extensions/LemnosLife/Map/Altis/Ground/{}.height",
|
||||||
|
file_name
|
||||||
|
))
|
||||||
.expect("Unable to load ground file!");
|
.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!");
|
.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;
|
||||||
|
|
||||||
@@ -101,10 +132,10 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
|
|||||||
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 {
|
for columns_index in 0..height_columns.len() - 1 {
|
||||||
let column = height_columns[columns_index].parse::<f32>().unwrap();
|
let column = get_altitude(&height_columns, columns_index);
|
||||||
let column_right = height_columns[columns_index + 1].parse::<f32>().unwrap();
|
let column_right = get_altitude(&height_columns, columns_index + 1);
|
||||||
let column_below = height_next_columns[columns_index].parse::<f32>().unwrap();
|
let column_below = get_altitude(&height_next_columns, columns_index);
|
||||||
let column_below_right = height_next_columns[columns_index + 1].parse::<f32>().unwrap();
|
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);
|
||||||
|
|
||||||
@@ -124,7 +155,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
|
|||||||
altitude: column_right,
|
altitude: column_right,
|
||||||
normal: [0.0, 0.0, 1.0],
|
normal: [0.0, 0.0, 1.0],
|
||||||
index,
|
index,
|
||||||
biome
|
biome,
|
||||||
});
|
});
|
||||||
index += 1;
|
index += 1;
|
||||||
|
|
||||||
@@ -132,7 +163,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
|
|||||||
altitude: column_below,
|
altitude: column_below,
|
||||||
normal: [0.0, 0.0, 1.0],
|
normal: [0.0, 0.0, 1.0],
|
||||||
index,
|
index,
|
||||||
biome
|
biome,
|
||||||
});
|
});
|
||||||
index += 1;
|
index += 1;
|
||||||
|
|
||||||
@@ -142,7 +173,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
|
|||||||
altitude: column_below,
|
altitude: column_below,
|
||||||
normal: [0.0, 0.0, 1.0],
|
normal: [0.0, 0.0, 1.0],
|
||||||
index,
|
index,
|
||||||
biome
|
biome,
|
||||||
});
|
});
|
||||||
index += 1;
|
index += 1;
|
||||||
|
|
||||||
@@ -150,7 +181,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
|
|||||||
altitude: column_right,
|
altitude: column_right,
|
||||||
normal: [0.0, 0.0, 1.0],
|
normal: [0.0, 0.0, 1.0],
|
||||||
index,
|
index,
|
||||||
biome
|
biome,
|
||||||
});
|
});
|
||||||
index += 1;
|
index += 1;
|
||||||
|
|
||||||
@@ -158,11 +189,18 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
|
|||||||
altitude: column_below_right,
|
altitude: column_below_right,
|
||||||
normal: [0.0, 0.0, 1.0],
|
normal: [0.0, 0.0, 1.0],
|
||||||
index,
|
index,
|
||||||
biome
|
biome,
|
||||||
});
|
});
|
||||||
index += 1;
|
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)
|
glium::vertex::VertexBuffer::new(display, &vertex_data)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|||||||
Reference in New Issue
Block a user