Skip to content

Commit

Permalink
wip: rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
berkus committed Jan 28, 2024
1 parent 2a3a280 commit 01bbe5b
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 78 deletions.
28 changes: 17 additions & 11 deletions src/support/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
// Distributed under the Boost Software License, Version 1.0.
// (See file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
//
use byteorder::ReadBytesExt;
use crate::support::{self, resource::Chunk, Error};
use id_tree::*;
use log::*;
use std::{
fs::File,
io::{BufRead, BufReader},
use {
crate::support::{self, resource::Chunk, Error},
byteorder::ReadBytesExt,
id_tree::*,
log::*,
std::{
fs::File,
io::{BufRead, BufReader},
},
};

// Typical actor tree:
Expand Down Expand Up @@ -126,7 +128,8 @@ impl Actor {
.insert(
Node::new(ActorNode::Actor { name, visible }),
UnderNode(&current_actor),
).unwrap();
)
.unwrap();
last_actor = child_id.clone();
}
Chunk::ActorTransform(transform) => {
Expand All @@ -136,23 +139,26 @@ impl Actor {
Node::new(ActorNode::Transform(transform)),
// Transform is unconditionally attached to the last loaded actor
UnderNode(&last_actor),
).unwrap();
)
.unwrap();
}
Chunk::MaterialRef(name) => {
actor
.tree
.insert(
Node::new(ActorNode::MaterialRef(name)),
UnderNode(&current_actor),
).unwrap();
)
.unwrap();
}
Chunk::MeshFileRef(name) => {
actor
.tree
.insert(
Node::new(ActorNode::MeshfileRef(name)),
UnderNode(&current_actor),
).unwrap();
)
.unwrap();
}
Chunk::ActorNodeDown() => {
current_actor = last_actor.clone();
Expand Down
43 changes: 24 additions & 19 deletions src/support/car.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
// Distributed under the Boost Software License, Version 1.0.
// (See file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
//
use cgmath::Vector3;
use crate::support::{
actor::{Actor, ActorNode},
material::Material,
mesh::Mesh,
path_subst,
texture::PixelMap,
Error,
};
use log::*;
use std::{
collections::{HashMap, HashSet},
fs::File,
io::{BufRead, BufReader},
iter::Iterator,
path::{Path, PathBuf},
use {
crate::support::{
actor::{Actor, ActorNode},
material::Material,
mesh::Mesh,
path_subst,
texture::PixelMap,
Error,
},
cgmath::Vector3,
log::*,
std::{
collections::{HashMap, HashSet},
fs::File,
io::{BufRead, BufReader},
iter::Iterator,
path::{Path, PathBuf},
},
};

// Car assembles the gameplay object (a car in this case) from various model and texture files.
Expand Down Expand Up @@ -54,7 +56,8 @@ fn parse_vector(line: &String) -> Vector3<f32> {
/// Read systems in a single damage spec clause.
fn read_systems<Iter: Iterator<Item = String>>(input: &mut Iter) {
// read condition flag for this clause
/*let condition =*/ input.next().unwrap();
/*let condition =*/
input.next().unwrap();
// read systems count, read this many systems
let systems_count = input.next().unwrap().parse().unwrap();
for _ in 0..systems_count {
Expand Down Expand Up @@ -350,7 +353,8 @@ impl Car {
let description_file = File::open(description_file_name)?;
let description_file = BufReader::new(description_file);

let mut input_lines = description_file.lines()
let mut input_lines = description_file
.lines()
.map(|line| line.unwrap())
.filter(|line| !line.starts_with("//")) // Skip whole-line comments
.filter(|line| !line.is_empty()) // Skip empty lines
Expand Down Expand Up @@ -429,7 +433,8 @@ impl Car {
split.next().unwrap().parse().unwrap(),
String::from(split.next().unwrap()),
)
}).collect();
})
.collect();
debug!("Actors to load: {:?}", load_actors);

let reflective_material = input_lines.next().unwrap();
Expand Down
12 changes: 7 additions & 5 deletions src/support/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
// Distributed under the Boost Software License, Version 1.0.
// (See file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
//
use byteorder::ReadBytesExt;
use crate::support::{self, resource::Chunk, Error};
use std::{
fs::File,
io::{BufRead, BufReader},
use {
crate::support::{self, resource::Chunk, Error},
byteorder::ReadBytesExt,
std::{
fs::File,
io::{BufRead, BufReader},
},
};

// MAT file is an index of: material internal name, PIX file name and TAB file name.
Expand Down
16 changes: 8 additions & 8 deletions src/support/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
// Distributed under the Boost Software License, Version 1.0.
// (See file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
//
use byteorder::{BigEndian, ReadBytesExt};
#[allow(unused_imports)]
use cgmath::{InnerSpace, Vector3, Zero};
use crate::support::{self, resource::Chunk, Error, Vertex};
use std::{
fs::File,
io::{BufRead, BufReader},
use {
crate::support::{self, resource::Chunk, Error, Vertex},
byteorder::{BigEndian, ReadBytesExt},
std::{
fs::File,
io::{BufRead, BufReader},
},
};

#[derive(Copy, Clone, Default)]
Expand Down Expand Up @@ -151,8 +153,7 @@ impl Mesh {
#[cfg(test)]
mod tests {

use super::*;
use std::io::Cursor;
use {super::*, std::io::Cursor};

#[test]
fn test_load_face() {
Expand Down Expand Up @@ -194,5 +195,4 @@ mod tests {
-Vector3::unit_z()
);
}

} // tests mod
33 changes: 18 additions & 15 deletions src/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
// extern crate genmesh;
// extern crate obj;

use byteorder::{BigEndian, ReadBytesExt};
use cgmath::Vector3;
use glium::implement_vertex;
use std::{
self,
convert::From,
io::BufRead,
ops::Sub,
path::{Path, PathBuf},
thread,
time::{Duration, Instant},
use {
byteorder::{BigEndian, ReadBytesExt},
cgmath::Vector3,
glium::implement_vertex,
std::{
self,
convert::From,
io::BufRead,
ops::Sub,
path::{Path, PathBuf},
thread,
time::{Duration, Instant},
},
};

pub mod actor;
Expand Down Expand Up @@ -228,9 +230,11 @@ pub const MODEL_FILE_SUBTYPE: u16 = 0x3;
#[cfg(test)]
mod tests {

use super::*;
use byteorder::ReadBytesExt;
use std::io::{BufReader, Cursor};
use {
super::*,
byteorder::ReadBytesExt,
std::io::{BufReader, Cursor},
};

#[test]
fn test_read_c_string() {
Expand Down Expand Up @@ -262,5 +266,4 @@ mod tests {
path_subst(&Path::new("/old/file.ext"), &Path::new("path"), None)
);
}

}
30 changes: 17 additions & 13 deletions src/support/render_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
// Distributed under the Boost Software License, Version 1.0.
// (See file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
//
use cgmath::{prelude::*, Matrix4, Vector3};
use crate::support::{actor::ActorNode, camera::CameraState, car::Car, Vertex};
use glium::{
self,
index::*,
texture::{RawImage2d, SrgbTexture2d},
uniform,
uniforms::*,
Display, IndexBuffer, Program, Surface, VertexBuffer,
use {
crate::support::{actor::ActorNode, camera::CameraState, car::Car, Vertex},
cgmath::{prelude::*, Matrix4, Vector3},
glium::{
self,
index::*,
texture::{RawImage2d, SrgbTexture2d},
uniform,
uniforms::*,
Display, IndexBuffer, Program, Surface, VertexBuffer,
},
log::*,
std::{collections::HashMap, str, vec::Vec},
};
use log::*;
use std::{collections::HashMap, str, vec::Vec};

/// Provide storage for in-memory level-data - models, meshes, textures etc.
pub struct RenderManager {
Expand Down Expand Up @@ -159,7 +161,8 @@ impl RenderManager {
*key,
IndexBuffer::new(display, PrimitiveType::TrianglesList, &item).unwrap(),

Check warning on line 162 in src/support/render_manager.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/support/render_manager.rs:162:81 | 162 | IndexBuffer::new(display, PrimitiveType::TrianglesList, &item).unwrap(), | ^^^^^ help: change this to: `item` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
)
}).collect(),
})
.collect(),
);

// each material from partitioned_by_material - load and bind it in bound_textures
Expand Down Expand Up @@ -273,7 +276,8 @@ impl RenderManager {
&self.program,
&uniforms,
&params,
).unwrap();
)
.unwrap();
}
}
}
16 changes: 9 additions & 7 deletions src/support/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
// Distributed under the Boost Software License, Version 1.0.
// (See file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)
//
use byteorder::{BigEndian, ReadBytesExt};
use crate::support::{
self,
mesh::{Face, UvCoord},
read_c_string, Error, Vertex,
use {
crate::support::{
self,
mesh::{Face, UvCoord},
read_c_string, Error, Vertex,
},
byteorder::{BigEndian, ReadBytesExt},
log::*,
std::io::BufRead,
};
use log::*;
use std::io::BufRead;

// A binary resource file consisting of chunks with specific size.
// Reading from such file yields chunk results, some of these chunks are service,
Expand Down

0 comments on commit 01bbe5b

Please sign in to comment.