Skip to content

Commit

Permalink
Migrate to Rust 2021 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
scurest committed Jul 25, 2024
1 parent 75cb088 commit 11ca50c
Show file tree
Hide file tree
Showing 41 changed files with 145 additions and 150 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "apicula"
version = "0.1.1-dev"
authors = ["scurest <scurest@users.noreply.github.com>"]
license = "0BSD"
edition = "2021"

[dependencies]
atty = "0.2"
Expand Down
6 changes: 3 additions & 3 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//! call supply the right files to the right calls. That leaves us to figure it
//! out for ourselves. This modules contains the heuristics for that.

use cli::Args;
use db::{Database, AnimationId, TextureId, PaletteId, ModelId, PatternId, MatAnimId};
use errors::Result;
use crate::cli::Args;
use crate::db::{Database, AnimationId, TextureId, PaletteId, ModelId, PatternId, MatAnimId};
use crate::errors::Result;

/// A Connection records interrelationships between Nitro resources, namely how
/// all the other resources relate to the models.
Expand Down
18 changes: 9 additions & 9 deletions src/convert/collada/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ mod xml;
mod make_invertible;

use cgmath::{Matrix4, One};
use convert::image_namer::ImageNamer;
use db::{Database, ModelId};
use skeleton::{Skeleton, Transform, SMatrix};
use primitives::{self, Primitives, DynamicState};
use nitro::Model;
use crate::convert::image_namer::ImageNamer;
use crate::db::{Database, ModelId};
use crate::skeleton::{Skeleton, Transform, SMatrix};
use crate::primitives::{self, Primitives, DynamicState};
use crate::nitro::Model;
use time;
use util::BiVec;
use connection::Connection;
use crate::util::BiVec;
use crate::connection::Connection;
use self::xml::Xml;
use util::tree::NodeIdx;
use crate::util::tree::NodeIdx;

static FRAME_LENGTH: f64 = 1.0 / 60.0; // 60 fps

Expand Down Expand Up @@ -173,7 +173,7 @@ fn library_effects(xml: &mut Xml, ctx: &Ctx) {
let params = ctx.db.textures[texture_id].params;
let alpha_type = params.format().alpha_type(params);

use nds::Alpha;
use crate::nds::Alpha;
match alpha_type {
Alpha::Opaque => false,
Alpha::Transparent | Alpha::Translucent => true,
Expand Down
2 changes: 1 addition & 1 deletion src/convert/gltf/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// three component curve onto their common domain and join them together. And
/// we need to convert the curve of rotation matrices to a curve of quaternions.

use nitro::animation::{TRSCurves, Curve};
use crate::nitro::animation::{TRSCurves, Curve};
use cgmath::{Vector3, Matrix3, Quaternion, InnerSpace, vec3};

/// Represents the domain of a Curve.
Expand Down
16 changes: 8 additions & 8 deletions src/convert/gltf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ mod object_trs;
mod curve;
mod primitive;

use nitro::Model;
use db::{Database, ModelId};
use connection::Connection;
use primitives::{Primitives, PolyType, DynamicState};
use skeleton::{Skeleton, Transform, SMatrix};
use crate::nitro::Model;
use crate::db::{Database, ModelId};
use crate::connection::Connection;
use crate::primitives::{Primitives, PolyType, DynamicState};
use crate::skeleton::{Skeleton, Transform, SMatrix};
use super::image_namer::ImageNamer;
use cgmath::Matrix4;
use json::JsonValue;
use self::gltf::{GlTF, Buffer, ByteVec, VecExt};
use self::object_trs::ObjectTRSes;
use util::{BiVec, BiMap};
use crate::util::{BiVec, BiMap};
use self::curve::{GlTFObjectCurves, CurveDomain};
use nitro::animation::Curve;
use crate::nitro::animation::Curve;
use std::collections::HashMap;
use self::primitive::encode_ngons;
use nds::Alpha;
use crate::nds::Alpha;

static FRAME_LENGTH: f32 = 1.0 / 60.0; // 60 fps

Expand Down
2 changes: 1 addition & 1 deletion src/convert/gltf/object_trs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use nitro::Model;
use crate::nitro::Model;
use cgmath::{Vector3, Quaternion, InnerSpace, One, vec3, Matrix4};

pub struct TRS {
Expand Down
2 changes: 1 addition & 1 deletion src/convert/gltf/primitive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use primitives::{Primitives, PolyType};
use crate::primitives::{Primitives, PolyType};

/// Triangulates the quads in a Primitive in the correct way for
/// FB_ngon_encoding to reconstruct them.
Expand Down
8 changes: 4 additions & 4 deletions src/convert/image_namer.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Discovers images in a Connection and assigns them names. We use these for
//! image filenames so that models know what the path to a specific image it
//! uses will be.
use db::{Database, TextureId, PaletteId};
use nitro::Name;
use crate::db::{Database, TextureId, PaletteId};
use crate::nitro::Name;
use std::collections::HashMap;
use util::namers::UniqueNamer;
use connection::Connection;
use crate::util::namers::UniqueNamer;
use crate::connection::Connection;

type ImageId = (TextureId, Option<PaletteId>);

Expand Down
16 changes: 8 additions & 8 deletions src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ mod collada;
mod image_namer;
mod gltf;

use cli::Args;
use errors::Result;
use crate::cli::Args;
use crate::errors::Result;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use util::namers::UniqueNamer;
use util::OutDir;
use db::Database;
use convert::image_namer::ImageNamer;
use connection::{Connection, ConnectionOptions};
use crate::util::namers::UniqueNamer;
use crate::util::OutDir;
use crate::db::Database;
use crate::convert::image_namer::ImageNamer;
use crate::connection::{Connection, ConnectionOptions};

pub fn main(args: &Args) -> Result<()> {
let out_dir_path = PathBuf::from(args.get_opt("output").unwrap());
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn main(args: &Args) -> Result<()> {
let texture = &db.textures[texture_id];
let palette = palette_id.map(|id| &db.palettes[id]);

use nds::decode_texture;
use crate::nds::decode_texture;
let rgba = match decode_texture(texture, palette) {
Ok(rgba) => rgba,
Err(e) => {
Expand Down
10 changes: 5 additions & 5 deletions src/db.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use cli::Args;
use crate::cli::Args;
use std::path::PathBuf;
use std::fs;
use std::collections::HashMap;
use nitro::{
use crate::nitro::{
Name, Model, Texture, Palette, Animation, Pattern,
MaterialAnimation, Container
};
use errors::Result;
use util::cur::Cur;
use crate::errors::Result;
use crate::util::cur::Cur;

pub type FileId = usize;
pub type ModelId = usize;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Database {
}
};

use nitro::container::read_container;
use crate::nitro::container::read_container;
match read_container(Cur::new(&buf)) {
Ok(cont) => {
self.add_container(file_id, cont);
Expand Down
4 changes: 2 additions & 2 deletions src/decompress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//! See: DSDecmp (https://github.com/Barubary/dsdecmp)

use std::{fmt, error, result};
use util::bits::BitField;
use util::cur::{self, Cur};
use crate::util::bits::BitField;
use crate::util::cur::{self, Cur};

pub struct DecompressResult<'a> {
/// The decompressed data.
Expand Down
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ impl Error for ErrorMsg {}

macro_rules! errmsg {
($msg:expr) => {
::errors::ErrorMsg { msg: $msg.into() }
crate::errors::ErrorMsg { msg: $msg.into() }
};
($fmt:expr, $($arg:tt)+) => {
::errors::ErrorMsg { msg: format!($fmt, $($arg)+) }
crate::errors::ErrorMsg { msg: format!($fmt, $($arg)+) }
};
}

Expand Down
14 changes: 7 additions & 7 deletions src/extract/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! Extract recognized container files from ROMs or other packed files.

use cli::Args;
use decompress;
use errors::Result;
use nitro::Container;
use nitro::container::read_container;
use crate::cli::Args;
use crate::decompress;
use crate::errors::Result;
use crate::nitro::Container;
use crate::nitro::container::read_container;
use std::collections::HashSet;
use std::fs;
use std::io::Write;
use std::path::PathBuf;
use util::cur::Cur;
use util::OutDir;
use crate::util::cur::Cur;
use crate::util::OutDir;

pub fn main(args: &Args) -> Result<()> {
let input_file = &args.free_args[0];
Expand Down
10 changes: 5 additions & 5 deletions src/info/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cli::Args;
use errors::Result;
use db::Database;
use connection::{Connection, ConnectionOptions, MaterialConnection, Match};
use crate::cli::Args;
use crate::errors::Result;
use crate::db::Database;
use crate::connection::{Connection, ConnectionOptions, MaterialConnection, Match};

pub fn main(args: &Args) -> Result<()> {
let db = Database::from_cli_args(args)?;
Expand Down Expand Up @@ -160,7 +160,7 @@ fn animation_info(db: &Database, anim_id: usize) {
for (i, trs_curves) in anim.objects_curves.iter().enumerate() {
println!(" Object {}:", i);

use nitro::animation::Curve;
use crate::nitro::animation::Curve;
fn curve_info<T>(name: &'static str, curve: &Curve<T>) {
match *curve {
Curve::None => { }
Expand Down
6 changes: 0 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@
extern crate log;
#[macro_use]
extern crate glium;
extern crate cgmath;
extern crate time;
extern crate png;
extern crate termcolor;
extern crate atty;
#[macro_use]
extern crate json;
extern crate wild;

#[macro_use]
mod errors;
Expand Down
8 changes: 4 additions & 4 deletions src/nds/decode_texture.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use nitro::{Texture, Palette};
use errors::Result;
use util::bits::BitField;
use util::cur::Cur;
use crate::nitro::{Texture, Palette};
use crate::errors::Result;
use crate::util::bits::BitField;
use crate::util::cur::Cur;

/// Pixel data stored in R8G8B8A8 format.
pub struct RGBABuf(pub Vec<u8>);
Expand Down
10 changes: 5 additions & 5 deletions src/nds/gpu_cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
//! for a reference on the DS's GPU.

use cgmath::{Point2, Point3, Vector3, vec3};
use errors::Result;
use util::bits::BitField;
use util::fixed::fix16;
use util::fixed::fix32;
use util::view::View;
use crate::errors::Result;
use crate::util::bits::BitField;
use crate::util::fixed::fix16;
use crate::util::fixed::fix32;
use crate::util::view::View;

/// DS GPU command.
pub enum GpuCmd {
Expand Down
2 changes: 1 addition & 1 deletion src/nds/texture_params.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::TextureFormat;
use util::bits::BitField;
use crate::util::bits::BitField;

#[derive(Copy, Clone)]
pub struct TextureParams(pub u32);
Expand Down
12 changes: 6 additions & 6 deletions src/nitro/animation.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use cgmath::{Matrix3, Matrix4};
use util::bits::BitField;
use util::cur::Cur;
use util::fixed::{fix16, fix32};
use nitro::Name;
use nitro::rotation::{pivot_mat, basis_mat};
use crate::util::bits::BitField;
use crate::util::cur::Cur;
use crate::util::fixed::{fix16, fix32};
use crate::nitro::Name;
use crate::nitro::rotation::{pivot_mat, basis_mat};
use std::ops::{Mul, Add};
use errors::Result;
use crate::errors::Result;

pub struct Animation {
pub name: Name,
Expand Down
18 changes: 9 additions & 9 deletions src/nitro/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
//! usually only contains JNT0s (animations), but we don't do anything to
//! enforce this. We'll read any kind of file we can get our hands on!

use errors::Result;
use nitro::{Model, Texture, Palette, Animation, Pattern, MaterialAnimation};
use nitro::info_block;
use util::cur::Cur;
use crate::errors::Result;
use crate::nitro::{Model, Texture, Palette, Animation, Pattern, MaterialAnimation};
use crate::nitro::info_block;
use crate::util::cur::Cur;

const STAMPS: [&[u8]; 5] = [b"BMD0", b"BTX0", b"BCA0", b"BTP0", b"BTA0"];

Expand Down Expand Up @@ -83,7 +83,7 @@ fn read_section(cont: &mut Container, cur: Cur) -> Result<()> {

// An MDL is a container for models.
fn add_mdl(cont: &mut Container, cur: Cur) -> Result<()> {
use nitro::model::read_model;
use crate::nitro::model::read_model;

fields!(cur, MDL0 {
stamp: [u8; 4],
Expand All @@ -105,7 +105,7 @@ fn add_mdl(cont: &mut Container, cur: Cur) -> Result<()> {

// This work is already done for us in read_tex; see that module for why.
fn add_tex(cont: &mut Container, cur: Cur) -> Result<()> {
use nitro::tex::read_tex;
use crate::nitro::tex::read_tex;

let (textures, palettes) = read_tex(cur)?;
cont.textures.extend(textures.into_iter());
Expand All @@ -116,7 +116,7 @@ fn add_tex(cont: &mut Container, cur: Cur) -> Result<()> {

// A JNT is a container for animations.
fn add_jnt(cont: &mut Container, cur: Cur) -> Result<()> {
use nitro::animation::read_animation;
use crate::nitro::animation::read_animation;

fields!(cur, JNT0 {
stamp: [u8; 4],
Expand All @@ -138,7 +138,7 @@ fn add_jnt(cont: &mut Container, cur: Cur) -> Result<()> {

// A PAT is a container for pattern animations.
fn add_pat(cont: &mut Container, cur: Cur) -> Result<()> {
use nitro::pattern::read_pattern;
use crate::nitro::pattern::read_pattern;

fields!(cur, PAT0 {
stamp: [u8; 4],
Expand All @@ -160,7 +160,7 @@ fn add_pat(cont: &mut Container, cur: Cur) -> Result<()> {

// An SRT is a container for material animations.
fn add_srt(cont: &mut Container, cur: Cur) -> Result<()> {
use nitro::material_animation::read_mat_anim;
use crate::nitro::material_animation::read_mat_anim;

fields!(cur, SRT0 {
stamp: [u8; 4],
Expand Down
8 changes: 4 additions & 4 deletions src/nitro/info_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
//! data-name pairs, where the data is usually an offset to the location
//! of some struct with the given name.

use errors::Result;
use nitro::name::Name;
use crate::errors::Result;
use crate::nitro::name::Name;
use std::fmt::Debug;
use std::iter::Zip;
use util::cur::Cur;
use util::view::{View, Viewable};
use crate::util::cur::Cur;
use crate::util::view::{View, Viewable};

pub type Iterator<'a, T> = Zip<View<'a, T>, View<'a, Name>>;

Expand Down
Loading

0 comments on commit 11ca50c

Please sign in to comment.