# HG changeset patch # User Emmanuel Gil Peyrot # Date 1609809392 -3600 # Node ID 21b186be259067f17ad8ee35d8550497bd79af5d # Parent 4d91790cf8ab10271878ccdda87d5e91a96bad58 Split the Rust version into multiple crates. diff --git a/Cargo.toml b/Cargo.toml --- a/Cargo.toml +++ b/Cargo.toml @@ -1,20 +1,14 @@ -[package] -name = "touhou" -version = "0.1.0" -authors = ["Emmanuel Gil Peyrot "] -edition = "2018" -description = "A collection of tools to work with Touhou data" -homepage = "https://pytouhou.linkmauve.fr" -license = "GPL-3.0-or-later" +[workspace] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +members = [ + "formats", + "interpreters", + "runners", + "utils", +] -[dependencies] -nom = { version = "6", default-features = false, features = ["alloc"] } -encoding_rs = "0.8" -image = { version = "0.23", default-features = false, features = ["png", "jpeg"] } -bitflags = "1" -luminance = "0.39" -luminance-glfw = { version = "0.12", default-features = false, features = ["log-errors"] } -luminance-derive = "0.5" -ears = "0.8" +[patch.crates-io] +touhou-formats = { path = "formats" } +touhou-interpreters = { path = "interpreters" } +touhou-runners = { path = "runners" } +touhou-utils = { path = "utils" } diff --git a/formats/Cargo.toml b/formats/Cargo.toml new file mode 100644 --- /dev/null +++ b/formats/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "touhou-formats" +version = "0.1.0" +authors = ["Emmanuel Gil Peyrot "] +edition = "2018" +description = "Collection of parsers for Touhou formats" +homepage = "https://pytouhou.linkmauve.fr" +license = "GPL-3.0-or-later" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +nom = { version = "6", default-features = false, features = ["alloc"] } +encoding_rs = "0.8" +bitflags = "1" +touhou-utils = "*" diff --git a/examples/dump_ecl.rs b/formats/src/bin/dump_ecl.rs rename from examples/dump_ecl.rs rename to formats/src/bin/dump_ecl.rs --- a/examples/dump_ecl.rs +++ b/formats/src/bin/dump_ecl.rs @@ -1,10 +1,16 @@ -use touhou::th06::ecl::{Ecl, CallMain, CallSub, Rank}; +use touhou_formats::th06::ecl::{Ecl, CallMain, CallSub, Rank}; use std::env; use std::path::Path; +use std::fs::File; +use std::io::{self, BufReader, Read}; -#[path = "common.rs"] -mod common; -use common::{load_file_into_vec}; +pub fn load_file_into_vec>(filename: P) -> io::Result> { + let file = File::open(filename)?; + let mut file = BufReader::new(file); + let mut buf = Vec::new(); + file.read_to_end(&mut buf)?; + Ok(buf) +} fn format_rank(rank: &Rank) -> String { format!("{}{}{}{}", if rank.contains(Rank::EASY) { 'E' } else { ' ' }, diff --git a/formats/src/lib.rs b/formats/src/lib.rs new file mode 100644 --- /dev/null +++ b/formats/src/lib.rs @@ -0,0 +1,6 @@ +#![feature(concat_idents)] +#![deny(missing_docs)] + +//! Touhou formats. + +pub mod th06; diff --git a/src/th06/anm0.rs b/formats/src/th06/anm0.rs rename from src/th06/anm0.rs rename to formats/src/th06/anm0.rs diff --git a/src/th06/ecl.rs b/formats/src/th06/ecl.rs rename from src/th06/ecl.rs rename to formats/src/th06/ecl.rs diff --git a/src/th06/mod.rs b/formats/src/th06/mod.rs rename from src/th06/mod.rs rename to formats/src/th06/mod.rs --- a/src/th06/mod.rs +++ b/formats/src/th06/mod.rs @@ -2,10 +2,5 @@ pub mod pbg3; pub mod anm0; -pub mod anm0_vm; pub mod ecl; -pub mod ecl_vm; pub mod std; -pub mod std_vm; -pub mod enemy; -pub mod interpolator; diff --git a/src/th06/pbg3.rs b/formats/src/th06/pbg3.rs rename from src/th06/pbg3.rs rename to formats/src/th06/pbg3.rs --- a/src/th06/pbg3.rs +++ b/formats/src/th06/pbg3.rs @@ -6,8 +6,8 @@ //! PBG3 files are merely a bitstream composed of a header, a file //! table, and LZSS-compressed files. -use crate::util::bitstream::BitStream; -use crate::util::lzss; +use touhou_utils::bitstream::BitStream; +use touhou_utils::lzss; use std::fs::File; use std::io; use std::collections::hash_map::{self, HashMap}; diff --git a/src/th06/std.rs b/formats/src/th06/std.rs rename from src/th06/std.rs rename to formats/src/th06/std.rs diff --git a/interpreters/Cargo.toml b/interpreters/Cargo.toml new file mode 100644 --- /dev/null +++ b/interpreters/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "touhou-interpreters" +version = "0.1.0" +authors = ["Emmanuel Gil Peyrot "] +edition = "2018" +description = "Interpreters for Touhou games" +homepage = "https://pytouhou.linkmauve.fr" +license = "GPL-3.0-or-later" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +touhou-formats = "*" +touhou-utils = "*" diff --git a/src/lib.rs b/interpreters/src/lib.rs rename from src/lib.rs rename to interpreters/src/lib.rs --- a/src/lib.rs +++ b/interpreters/src/lib.rs @@ -1,7 +1,6 @@ #![deny(missing_docs)] #![feature(concat_idents)] -//! Crate implementing various Touhou formats. +//! Crate implementing interpreters for various Touhou formats. -pub mod util; pub mod th06; diff --git a/src/th06/anm0_vm.rs b/interpreters/src/th06/anm0.rs rename from src/th06/anm0_vm.rs rename to interpreters/src/th06/anm0.rs --- a/src/th06/anm0_vm.rs +++ b/interpreters/src/th06/anm0.rs @@ -1,14 +1,14 @@ //! Animation runner. -use crate::th06::anm0::{ +use touhou_formats::th06::anm0::{ Script, Anm0, Call, Instruction, }; use crate::th06::interpolator::{Interpolator1, Interpolator2, Interpolator3, Formula}; -use crate::util::math::Mat4; -use crate::util::prng::Prng; +use touhou_utils::math::Mat4; +use touhou_utils::prng::Prng; use std::cell::RefCell; use std::rc::{Rc, Weak}; diff --git a/src/th06/ecl_vm.rs b/interpreters/src/th06/ecl.rs rename from src/th06/ecl_vm.rs rename to interpreters/src/th06/ecl.rs --- a/src/th06/ecl_vm.rs +++ b/interpreters/src/th06/ecl.rs @@ -1,8 +1,8 @@ //! ECL runner. -use crate::th06::ecl::{Ecl, SubInstruction}; +use touhou_formats::th06::ecl::{Ecl, SubInstruction}; use crate::th06::enemy::{Enemy, Offset, BulletAttributes, Position}; -use crate::util::prng::Prng; +use touhou_utils::prng::Prng; use std::cell::RefCell; use std::rc::Rc; diff --git a/src/th06/enemy.rs b/interpreters/src/th06/enemy.rs rename from src/th06/enemy.rs rename to interpreters/src/th06/enemy.rs --- a/src/th06/enemy.rs +++ b/interpreters/src/th06/enemy.rs @@ -1,10 +1,10 @@ //! Module providing an Enemy struct, to be changed by EclRunner. -use crate::th06::anm0::Anm0; -use crate::th06::anm0_vm::{Sprite, AnmRunner}; -use crate::th06::ecl::Rank; +use touhou_formats::th06::anm0::Anm0; +use touhou_formats::th06::ecl::Rank; +use crate::th06::anm0::{Sprite, AnmRunner}; use crate::th06::interpolator::{Interpolator1, Interpolator2}; -use crate::util::prng::Prng; +use touhou_utils::prng::Prng; use std::cell::RefCell; use std::collections::HashMap; use std::rc::{Rc, Weak}; diff --git a/src/th06/interpolator.rs b/interpreters/src/th06/interpolator.rs rename from src/th06/interpolator.rs rename to interpreters/src/th06/interpolator.rs diff --git a/src/th06/std_vm.rs b/interpreters/src/th06/std.rs rename from src/th06/std_vm.rs rename to interpreters/src/th06/std.rs --- a/src/th06/std_vm.rs +++ b/interpreters/src/th06/std.rs @@ -1,8 +1,8 @@ //! Interpreter of STD files. -use crate::th06::std::{Stage, Call, Instruction}; +use touhou_formats::th06::std::{Stage, Call, Instruction}; use crate::th06::interpolator::{Interpolator3, Formula}; -use crate::util::math::{Mat4, setup_camera}; +use touhou_utils::math::{Mat4, setup_camera}; use std::cell::RefCell; use std::rc::Rc; diff --git a/Cargo.toml b/runners/Cargo.toml copy from Cargo.toml copy to runners/Cargo.toml --- a/Cargo.toml +++ b/runners/Cargo.toml @@ -1,19 +1,19 @@ [package] -name = "touhou" +name = "touhou-runners" version = "0.1.0" authors = ["Emmanuel Gil Peyrot "] edition = "2018" -description = "A collection of tools to work with Touhou data" +description = "Runners for Touhou games" homepage = "https://pytouhou.linkmauve.fr" license = "GPL-3.0-or-later" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -nom = { version = "6", default-features = false, features = ["alloc"] } -encoding_rs = "0.8" +touhou-formats = "*" +touhou-interpreters = "*" +touhou-utils = "*" image = { version = "0.23", default-features = false, features = ["png", "jpeg"] } -bitflags = "1" luminance = "0.39" luminance-glfw = { version = "0.12", default-features = false, features = ["log-errors"] } luminance-derive = "0.5" diff --git a/examples/anmrenderer.rs b/runners/src/bin/anmrenderer.rs rename from examples/anmrenderer.rs rename to runners/src/bin/anmrenderer.rs --- a/examples/anmrenderer.rs +++ b/runners/src/bin/anmrenderer.rs @@ -8,18 +8,16 @@ use luminance::tess::{Mode, TessBuilder} use luminance::texture::Dim2; use luminance_derive::{Semantics, Vertex, UniformInterface}; use luminance_glfw::{Action, Key, WindowEvent, GlfwSurface, Surface, WindowDim, WindowOpt}; -use touhou::th06::anm0::Anm0; -use touhou::th06::anm0_vm::{AnmRunner, Sprite, Vertex as FakeVertex}; -use touhou::util::math::{perspective, setup_camera}; -use touhou::util::prng::Prng; +use touhou_formats::th06::anm0::Anm0; +use touhou_interpreters::th06::anm0::{AnmRunner, Sprite, Vertex as FakeVertex}; +use touhou_utils::math::{perspective, setup_camera}; +use touhou_utils::prng::Prng; use std::cell::RefCell; use std::rc::Rc; use std::env; use std::path::Path; -#[path = "common.rs"] -mod common; -use common::{load_file_into_vec, load_anm_image, LoadedTexture}; +use touhou_runners::common::{load_file_into_vec, load_anm_image, LoadedTexture}; const VS: &str = r#" in ivec3 in_position; diff --git a/examples/eclrenderer.rs b/runners/src/bin/eclrenderer.rs rename from examples/eclrenderer.rs rename to runners/src/bin/eclrenderer.rs --- a/examples/eclrenderer.rs +++ b/runners/src/bin/eclrenderer.rs @@ -8,21 +8,19 @@ use luminance::tess::{Mode, TessBuilder} use luminance::texture::Dim2; use luminance_derive::{Semantics, Vertex, UniformInterface}; use luminance_glfw::{Action, Key, WindowEvent, GlfwSurface, Surface, WindowDim, WindowOpt}; -use touhou::th06::anm0::Anm0; -use touhou::th06::anm0_vm::{Sprite, Vertex as FakeVertex}; -use touhou::th06::ecl::{Ecl, Rank}; -use touhou::th06::ecl_vm::EclRunner; -use touhou::th06::enemy::{Enemy, Game, Position}; -use touhou::util::math::{perspective, setup_camera}; -use touhou::util::prng::Prng; +use touhou_formats::th06::anm0::Anm0; +use touhou_formats::th06::ecl::{Ecl, Rank}; +use touhou_interpreters::th06::anm0::{Sprite, Vertex as FakeVertex}; +use touhou_interpreters::th06::ecl::EclRunner; +use touhou_interpreters::th06::enemy::{Enemy, Game, Position}; +use touhou_utils::math::{perspective, setup_camera}; +use touhou_utils::prng::Prng; use std::cell::RefCell; use std::rc::Rc; use std::env; use std::path::Path; -#[path = "common.rs"] -mod common; -use common::{load_file_into_vec, load_anm_image, LoadedTexture}; +use touhou_runners::common::{load_file_into_vec, load_anm_image, LoadedTexture}; const VS: &str = r#" in ivec3 in_position; diff --git a/examples/menu.rs b/runners/src/bin/menu.rs rename from examples/menu.rs rename to runners/src/bin/menu.rs --- a/examples/menu.rs +++ b/runners/src/bin/menu.rs @@ -9,19 +9,17 @@ use luminance::tess::{Mode, TessBuilder} use luminance::texture::Dim2; use luminance_derive::{Semantics, Vertex, UniformInterface}; use luminance_glfw::{Action, Key, WindowEvent, GlfwSurface, Surface, WindowDim, WindowOpt}; -use touhou::th06::pbg3; -use touhou::th06::anm0::Anm0; -use touhou::th06::anm0_vm::{AnmRunner, Sprite, Vertex as FakeVertex}; -use touhou::util::math::{perspective, setup_camera, ortho_2d}; -use touhou::util::prng::Prng; +use touhou_formats::th06::pbg3; +use touhou_formats::th06::anm0::Anm0; +use touhou_interpreters::th06::anm0::{AnmRunner, Sprite, Vertex as FakeVertex}; +use touhou_utils::math::{perspective, setup_camera, ortho_2d}; +use touhou_utils::prng::Prng; use std::cell::RefCell; use std::rc::Rc; use std::env; use std::path::Path; -#[path = "common.rs"] -mod common; -use common::LoadedTexture; +use touhou_runners::common::{self, LoadedTexture}; const VS: &str = r#" in ivec3 in_position; diff --git a/examples/stagerunner.rs b/runners/src/bin/stagerunner.rs rename from examples/stagerunner.rs rename to runners/src/bin/stagerunner.rs --- a/examples/stagerunner.rs +++ b/runners/src/bin/stagerunner.rs @@ -8,21 +8,19 @@ use luminance::tess::{Mode, TessBuilder} use luminance::texture::Dim2Array; use luminance_derive::{Semantics, Vertex, UniformInterface}; use luminance_glfw::{Action, Key, WindowEvent, GlfwSurface, Surface, WindowDim, WindowOpt}; -use touhou::th06::anm0::Anm0; -use touhou::th06::anm0_vm::Vertex as FakeVertex; -use touhou::th06::ecl::{Ecl, Rank, MainInstruction}; -use touhou::th06::ecl_vm::EclRunner; -use touhou::th06::enemy::{Enemy, Game, Position}; -use touhou::util::math::{perspective, setup_camera}; -use touhou::util::prng::Prng; +use touhou_formats::th06::anm0::Anm0; +use touhou_formats::th06::ecl::{Ecl, Rank, MainInstruction}; +use touhou_interpreters::th06::anm0::Vertex as FakeVertex; +use touhou_interpreters::th06::ecl::EclRunner; +use touhou_interpreters::th06::enemy::{Enemy, Game, Position}; +use touhou_utils::math::{perspective, setup_camera}; +use touhou_utils::prng::Prng; use std::cell::RefCell; use std::rc::Rc; use std::env; use std::path::Path; -#[path = "common.rs"] -mod common; -use common::{load_file_into_vec, load_multiple_anm_images, LoadedTexture}; +use touhou_runners::common::{load_file_into_vec, load_multiple_anm_images, LoadedTexture}; const VS: &str = r#" in ivec3 in_position; diff --git a/examples/stdrenderer.rs b/runners/src/bin/stdrenderer.rs rename from examples/stdrenderer.rs rename to runners/src/bin/stdrenderer.rs --- a/examples/stdrenderer.rs +++ b/runners/src/bin/stdrenderer.rs @@ -8,20 +8,18 @@ use luminance::tess::{Mode, TessBuilder, use luminance::texture::Dim2; use luminance_derive::{Semantics, Vertex, UniformInterface}; use luminance_glfw::{Action, Key, WindowEvent, GlfwSurface, Surface, WindowDim, WindowOpt}; -use touhou::th06::anm0::Anm0; -use touhou::th06::anm0_vm::{AnmRunner, Sprite, Vertex as FakeVertex}; -use touhou::th06::std::{Stage, Position, Box2D}; -use touhou::th06::std_vm::StageRunner; -use touhou::util::prng::Prng; -use touhou::util::math::perspective; +use touhou_formats::th06::anm0::Anm0; +use touhou_formats::th06::std::{Stage, Position, Box2D}; +use touhou_interpreters::th06::anm0::{AnmRunner, Sprite, Vertex as FakeVertex}; +use touhou_interpreters::th06::std::StageRunner; +use touhou_utils::prng::Prng; +use touhou_utils::math::perspective; use std::cell::RefCell; use std::rc::Rc; use std::env; use std::path::Path; -#[path = "common.rs"] -mod common; -use common::{load_file_into_vec, load_anm_image, LoadedTexture}; +use touhou_runners::common::{load_file_into_vec, load_anm_image, LoadedTexture}; const VS: &str = r#" in ivec3 in_position; diff --git a/examples/common.rs b/runners/src/common.rs rename from examples/common.rs rename to runners/src/common.rs --- a/examples/common.rs +++ b/runners/src/common.rs @@ -2,7 +2,7 @@ use image::{GenericImageView, DynamicIma use luminance::pixel::{NormRGB8UI, NormRGBA8UI}; use luminance::texture::{Dim2, Dim2Array, Sampler, Texture, GenMipmaps}; use luminance_glfw::GlfwSurface; -use touhou::th06::anm0::Anm0; +use touhou_formats::th06::anm0::Anm0; use std::fs::File; use std::io::{self, BufReader, Read}; use std::path::Path; diff --git a/utils/Cargo.toml b/utils/Cargo.toml new file mode 100644 --- /dev/null +++ b/utils/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "touhou-utils" +version = "0.1.0" +authors = ["Emmanuel Gil Peyrot "] +edition = "2018" +description = "Utilities for Touhou games" +homepage = "https://pytouhou.linkmauve.fr" +license = "GPL-3.0-or-later" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/util/bitstream.rs b/utils/src/bitstream.rs rename from src/util/bitstream.rs rename to utils/src/bitstream.rs diff --git a/src/util/mod.rs b/utils/src/lib.rs rename from src/util/mod.rs rename to utils/src/lib.rs diff --git a/src/util/lzss.rs b/utils/src/lzss.rs rename from src/util/lzss.rs rename to utils/src/lzss.rs --- a/src/util/lzss.rs +++ b/utils/src/lzss.rs @@ -1,7 +1,7 @@ //! LZSS implementation. use std::io; -use crate::util::bitstream::BitStream; +use crate::bitstream::BitStream; /// Decompresses a LZSS-compressed file. pub fn decompress(bitstream: &mut BitStream, size: usize, dictionary_size: usize, offset_size: usize, length_size: usize, minimum_match_length: usize) -> io::Result> { diff --git a/src/util/math.rs b/utils/src/math.rs rename from src/util/math.rs rename to utils/src/math.rs diff --git a/src/util/prng.rs b/utils/src/prng.rs rename from src/util/prng.rs rename to utils/src/prng.rs