Migrate to Rust 2021 edition

This commit is contained in:
scurest 2024-07-24 20:49:12 -05:00
parent 75cb088d31
commit 11ca50c0dc
41 changed files with 145 additions and 150 deletions

View File

@ -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"

View File

@ -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.

View File

@ -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
@ -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,

View File

@ -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.

View File

@ -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

View File

@ -1,4 +1,4 @@
use nitro::Model;
use crate::nitro::Model;
use cgmath::{Vector3, Quaternion, InnerSpace, One, vec3, Matrix4};
pub struct TRS {

View File

@ -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.

View File

@ -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>);

View File

@ -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());
@ -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) => {

View File

@ -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;
@ -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);

View File

@ -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.

View File

@ -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)+) }
};
}

View File

@ -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];

View File

@ -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)?;
@ -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 => { }

View File

@ -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;

View File

@ -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>);

View File

@ -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 {

View File

@ -1,5 +1,5 @@
use super::TextureFormat;
use util::bits::BitField;
use crate::util::bits::BitField;
#[derive(Copy, Clone)]
pub struct TextureParams(pub u32);

View File

@ -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,

View File

@ -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"];
@ -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],
@ -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());
@ -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],
@ -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],
@ -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],

View File

@ -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>>;

View File

@ -1,12 +1,12 @@
// HIGHLY INCOMPLETE!!!
use super::animation::Curve;
use util::cur::Cur;
use util::view::Viewable;
use util::fixed::fix16;
use crate::util::cur::Cur;
use crate::util::view::Viewable;
use crate::util::fixed::fix16;
use cgmath::{Matrix4, vec3};
use nitro::Name;
use errors::Result;
use crate::nitro::Name;
use crate::errors::Result;
use super::info_block;
/// Material animation. Does things like UV matrix animation.

View File

@ -1,12 +1,12 @@
use cgmath::{Matrix3, Matrix4, One, vec3, Vector3};
use errors::Result;
use nitro::info_block;
use nitro::Name;
use nds::TextureParams;
use nitro::render_cmds::Op;
use util::bits::BitField;
use util::cur::Cur;
use util::fixed::{fix16, fix32};
use crate::errors::Result;
use crate::nitro::info_block;
use crate::nitro::Name;
use crate::nds::TextureParams;
use crate::nitro::render_cmds::Op;
use crate::util::bits::BitField;
use crate::util::cur::Cur;
use crate::util::fixed::{fix16, fix32};
/// NSBMD model.
pub struct Model {
@ -360,7 +360,7 @@ fn read_object(mut cur: Cur, name: Name) -> Result<Object> {
let b = fx16(cur.next::<u16>()?);
let select = flags.bits(4,8);
let neg = flags.bits(8,12);
use nitro::rotation::pivot_mat;
use crate::nitro::rotation::pivot_mat;
rot = Some(pivot_mat(select, neg, a, b));
} else if r == 0 {
let m = cur.next_n::<u16>(8)?;

View File

@ -1,5 +1,5 @@
use std::fmt::{self, Write};
use util::view::Viewable;
use crate::util::view::Viewable;
/// Sixteen-byte NUL-padded ASCII(?) string, used as human-readable names
/// in Nitro files.

View File

@ -1,6 +1,6 @@
use util::cur::Cur;
use nitro::Name;
use errors::Result;
use crate::util::cur::Cur;
use crate::nitro::Name;
use crate::errors::Result;
use super::info_block;
/// A pattern animation changes the images that the materials of a model use as

View File

@ -1,7 +1,7 @@
//! Render commands for model files.
use errors::Result;
use util::cur::Cur;
use crate::errors::Result;
use crate::util::cur::Cur;
pub struct SkinTerm {
pub weight: f32,

View File

@ -6,8 +6,8 @@
//! actually be a rotation (ie. orthogonal of determinant +1).
use cgmath::{Matrix3, vec3};
use util::bits::BitField;
use util::fixed::fix16;
use crate::util::bits::BitField;
use crate::util::fixed::fix16;
pub fn pivot_mat(select: u16, neg: u16, a: f64, b: f64) -> Matrix3<f64> {
if select >= 9 {

View File

@ -1,9 +1,9 @@
use std::rc::Rc;
use nitro::Name;
use nitro::info_block;
use errors::Result;
use util::cur::Cur;
use nds::{TextureParams, TextureFormat};
use crate::nitro::Name;
use crate::nitro::info_block;
use crate::errors::Result;
use crate::util::cur::Cur;
use crate::nds::{TextureParams, TextureFormat};
pub struct Texture {
pub name: Name,

View File

@ -8,8 +8,8 @@
//! This is then further consumed by both the viewer and the COLLADA writer.
use cgmath::{Matrix4, Point2, Transform, InnerSpace, vec4, Zero};
use nitro::Model;
use nitro::render_cmds::SkinTerm;
use crate::nitro::Model;
use crate::nitro::render_cmds::SkinTerm;
use std::default::Default;
use std::ops::Range;
@ -89,7 +89,7 @@ implement_vertex!(Vertex, position, texcoord, color, normal);
impl Primitives {
pub fn build(model: &Model, poly_type: PolyType, state: DynamicState) -> Primitives {
let mut b = Builder::new(model, poly_type, state);
use nitro::render_cmds::Op;
use crate::nitro::render_cmds::Op;
for op in &model.render_ops {
match *op {
Op::LoadMatrix { stack_pos } => b.load_matrix(stack_pos),
@ -364,7 +364,7 @@ impl<'a, 'b> Builder<'a, 'b> {
}
fn run_gpu_cmds(b: &mut Builder, commands: &[u8]) {
use nds::gpu_cmds::{CmdParser, GpuCmd};
use crate::nds::gpu_cmds::{CmdParser, GpuCmd};
let interpreter = CmdParser::new(commands);
for cmd_res in interpreter {

View File

@ -114,8 +114,8 @@ use cgmath::{Matrix4, SquareMatrix, One, ApproxEq};
use super::vertex_record::VertexRecord;
use super::{SMatrix, AMatrix};
use super::{Skeleton, Joint, Transform, Weight, WeightsOfs};
use nitro::Model;
use util::tree::{Tree, NodeIdx};
use crate::nitro::Model;
use crate::util::tree::{Tree, NodeIdx};
pub fn build_skeleton(vr: &VertexRecord, model: &Model, objects: &[Matrix4<f64>]) -> Skeleton {
let mut b = Builder::new(model, objects);

View File

@ -56,8 +56,8 @@ mod joint_tree;
pub use self::symbolic_matrix::{SMatrix, AMatrix};
use cgmath::Matrix4;
use nitro::Model;
use util::tree::{Tree, NodeIdx};
use crate::nitro::Model;
use crate::util::tree::{Tree, NodeIdx};
/// Skeleton (or skin) for a model.
pub struct Skeleton {

View File

@ -2,8 +2,8 @@
//! matrix is applied to each vertex.
use super::symbolic_matrix::{SMatrix, AMatrix};
use nitro::Model;
use nitro::render_cmds::SkinTerm;
use crate::nitro::Model;
use crate::nitro::render_cmds::SkinTerm;
type MatrixIdx = u16;
@ -19,7 +19,7 @@ pub struct VertexRecord {
impl VertexRecord {
pub fn build_for_model(model: &Model) -> VertexRecord {
let mut b = Builder::new(model);
use nitro::render_cmds::Op;
use crate::nitro::render_cmds::Op;
for op in &model.render_ops {
match *op {
Op::LoadMatrix { stack_pos } => b.load_matrix(stack_pos),
@ -112,7 +112,7 @@ impl<'a> Builder<'a> {
fn draw(&mut self, piece_idx: u8) {
let piece = &self.model.pieces[piece_idx as usize];
use nds::gpu_cmds::{CmdParser, GpuCmd};
use crate::nds::gpu_cmds::{CmdParser, GpuCmd};
let interpreter = CmdParser::new(&piece.gpu_commands);
for cmd_res in interpreter {

View File

@ -1,6 +1,6 @@
use std::{fmt, error};
use std::ops::Add;
use util::view::{View, Viewable};
use crate::util::view::{View, Viewable};
/// A pointer into a buffer of bytes. Used for binary file parsing.
#[derive(Copy, Clone)]

View File

@ -30,13 +30,13 @@ macro_rules! field_helper2 {
($cur:ident, (fix16($s:expr,$i:expr,$f:expr))) => {
{
let x = $cur.next::<u16>()?;
::util::fixed::fix16(x, $s, $i, $f)
crate::util::fixed::fix16(x, $s, $i, $f)
}
};
($cur:ident, (fix32($s:expr,$i:expr,$f:expr))) => {
{
let x = $cur.next::<u32>()?;
::util::fixed::fix32(x, $s, $i, $f)
crate::util::fixed::fix32(x, $s, $i, $f)
}
};
($cur:ident, Cur) => { $cur.clone() };

View File

@ -1,6 +1,6 @@
//! Fixed-point to `f64` conversions.
use util::bits::BitField;
use crate::util::bits::BitField;
/// Reads a fixed-point number from a `u32`.
///

View File

@ -1,7 +1,7 @@
use std::io::ErrorKind;
use std::path::PathBuf;
use std::fs;
use errors::Result;
use crate::errors::Result;
/// Directory for putting output files in. Will be created lazily when the first
/// file is created.

View File

@ -1,8 +1,8 @@
use glium::glutin::{self, dpi::{LogicalSize, PhysicalSize, PhysicalPosition}};
use glium::glutin::event_loop::ControlFlow;
use super::viewer::Viewer;
use db::Database;
use connection::Connection;
use crate::db::Database;
use crate::connection::Connection;
pub fn main_loop(db: Database, conn: Connection) {
let window_builder = glutin::window::WindowBuilder::new()

View File

@ -3,10 +3,10 @@ mod main_loop;
mod viewer;
mod fps;
use cli::Args;
use db::Database;
use connection::{Connection, ConnectionOptions};
use errors::Result;
use crate::cli::Args;
use crate::db::Database;
use crate::connection::{Connection, ConnectionOptions};
use crate::errors::Result;
/// Initial window width.
pub static WINDOW_WIDTH: u32 = 640;

View File

@ -4,10 +4,10 @@ pub mod texture_cache;
pub use self::eye::Eye;
use cgmath::{PerspectiveFov, Rad, Matrix4};
use db::Database;
use crate::db::Database;
use glium::{VertexBuffer, IndexBuffer, Frame, Surface, Program, Display};
use nitro::Model;
use primitives::{Primitives, DrawCall, Vertex};
use crate::nitro::Model;
use crate::primitives::{Primitives, DrawCall, Vertex};
use self::texture_cache::{TextureCache, ImageId};
use super::{Z_NEAR, Z_FAR, FOV_Y};

View File

@ -1,7 +1,7 @@
use std::collections::HashMap;
use db::{Database, TextureId, PaletteId};
use crate::db::{Database, TextureId, PaletteId};
use glium::{Display, Texture2d, texture::RawImage2d};
use nds;
use crate::nds;
// TODO: move somewhere more important.
pub type ImageId = (TextureId, Option<PaletteId>);

View File

@ -1,13 +1,13 @@
use std::ops::Range;
use super::model_viewer::{ModelViewer, MaterialTextureBinding};
use db::{Database, ModelId, AnimationId, PatternId, MatAnimId, FileId};
use connection::Connection;
use crate::db::{Database, ModelId, AnimationId, PatternId, MatAnimId, FileId};
use crate::connection::Connection;
use glium::Display;
use glium::{Frame, Surface};
use glium::glutin::event::{ElementState, ModifiersState};
use glium::glutin::event::VirtualKeyCode;
use nitro::{Model, Animation, Pattern, MaterialAnimation};
use primitives::{Primitives, PolyType, DynamicState};
use crate::nitro::{Model, Animation, Pattern, MaterialAnimation};
use crate::primitives::{Primitives, PolyType, DynamicState};
use cgmath::{Matrix4, InnerSpace, Vector3, vec3, vec2};
use super::fps::FpsCounter;
use super::{FRAMERATE, BG_COLOR};