Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9451959f78 | |||
| a015f318c7 |
+20
-21
@@ -4,17 +4,17 @@ extern crate glium;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate load_file;
|
extern crate load_file;
|
||||||
|
|
||||||
use std::f32::consts::PI;
|
|
||||||
use glium::texture::SrgbTexture2d;
|
use glium::texture::SrgbTexture2d;
|
||||||
use phf::phf_map;
|
use phf::phf_map;
|
||||||
|
use std::f32::consts::PI;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use crate::support::CHUNK_SIZE;
|
||||||
use glium::vertex::VertexBufferAny;
|
use glium::vertex::VertexBufferAny;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use glium::{glutin, Surface};
|
use glium::{glutin, Surface};
|
||||||
use crate::support::CHUNK_SIZE;
|
|
||||||
|
|
||||||
mod support;
|
mod support;
|
||||||
|
|
||||||
@@ -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() {
|
||||||
@@ -433,10 +433,7 @@ fn main() {
|
|||||||
let file = file_path.replace(structures_folder, "");
|
let file = file_path.replace(structures_folder, "");
|
||||||
println!("{}", file);
|
println!("{}", file);
|
||||||
structures_vertex_buffer.push((
|
structures_vertex_buffer.push((
|
||||||
file
|
file.replace(".obj", "").parse().unwrap(),
|
||||||
.replace(".obj", "")
|
|
||||||
.parse()
|
|
||||||
.unwrap(),
|
|
||||||
support::load_wavefront(&display, load_bytes!(&format!("../{}", file_path))),
|
support::load_wavefront(&display, load_bytes!(&format!("../{}", file_path))),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -494,7 +491,8 @@ fn main() {
|
|||||||
let file_name = file.replace(".objects", "");
|
let file_name = file.replace(".objects", "");
|
||||||
let file_name_parts: Vec<&str> = file_name.split(' ').collect();
|
let file_name_parts: Vec<&str> = file_name.split(' ').collect();
|
||||||
|
|
||||||
let objects_contents = fs::read_to_string(file_path).unwrap_or_else(|_| panic!("Unable to load {} file!", file_path));
|
let objects_contents = fs::read_to_string(file_path)
|
||||||
|
.unwrap_or_else(|_| panic!("Unable to load {} file!", file_path));
|
||||||
|
|
||||||
let chunk = [0, 1].map(|file_name_parts_index| {
|
let chunk = [0, 1].map(|file_name_parts_index| {
|
||||||
file_name_parts[file_name_parts_index]
|
file_name_parts[file_name_parts_index]
|
||||||
@@ -517,7 +515,8 @@ fn main() {
|
|||||||
let y: f32 = object_line_parts[2].parse().unwrap();
|
let y: f32 = object_line_parts[2].parse().unwrap();
|
||||||
let z = object_line_parts[3].parse().unwrap();
|
let z = object_line_parts[3].parse().unwrap();
|
||||||
let rotation: f32 = object_line_parts[4].parse().unwrap();
|
let rotation: f32 = object_line_parts[4].parse().unwrap();
|
||||||
let structure_per_instance: &mut Vec<PerInstance> = structures_per_instance.get_mut(structure_id).unwrap();
|
let structure_per_instance: &mut Vec<PerInstance> =
|
||||||
|
structures_per_instance.get_mut(structure_id).unwrap();
|
||||||
structure_per_instance.push(PerInstance {
|
structure_per_instance.push(PerInstance {
|
||||||
w_position: (offset_x + x, z, offset_y + y),
|
w_position: (offset_x + x, z, offset_y + y),
|
||||||
w_rotation: 2.0 * PI * rotation / 360.0,
|
w_rotation: 2.0 * PI * rotation / 360.0,
|
||||||
@@ -550,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.
|
||||||
@@ -576,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],
|
||||||
@@ -637,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
|
||||||
@@ -654,7 +653,7 @@ fn main() {
|
|||||||
|
|
||||||
let mut structures_params = ground_params.clone();
|
let mut structures_params = ground_params.clone();
|
||||||
structures_params.blend = glium::draw_parameters::Blend::alpha_blending(); // Could disable per opaque structure to optimize.
|
structures_params.blend = glium::draw_parameters::Blend::alpha_blending(); // Could disable per opaque structure to optimize.
|
||||||
// Doesn't seem to apply transparency from a structure instance to the other.
|
// Doesn't seem to apply transparency from a structure instance to the other.
|
||||||
|
|
||||||
// drawing a frame
|
// drawing a frame
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|||||||
+24
-11
@@ -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!()
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user