changeset 757:21b186be2590

Split the Rust version into multiple crates.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 05 Jan 2021 02:16:32 +0100
parents 4d91790cf8ab
children daa23a4ff24d
files Cargo.toml examples/anmrenderer.rs examples/common.rs examples/dump_ecl.rs examples/eclrenderer.rs examples/menu.rs examples/stagerunner.rs examples/stdrenderer.rs formats/Cargo.toml formats/src/bin/dump_ecl.rs formats/src/lib.rs formats/src/th06/anm0.rs formats/src/th06/ecl.rs formats/src/th06/mod.rs formats/src/th06/pbg3.rs formats/src/th06/std.rs interpreters/Cargo.toml interpreters/src/lib.rs interpreters/src/th06/anm0.rs interpreters/src/th06/ecl.rs interpreters/src/th06/enemy.rs interpreters/src/th06/interpolator.rs interpreters/src/th06/std.rs runners/Cargo.toml runners/src/bin/anmrenderer.rs runners/src/bin/eclrenderer.rs runners/src/bin/menu.rs runners/src/bin/stagerunner.rs runners/src/bin/stdrenderer.rs runners/src/common.rs src/lib.rs src/th06/anm0.rs src/th06/anm0_vm.rs src/th06/ecl.rs src/th06/ecl_vm.rs src/th06/enemy.rs src/th06/interpolator.rs src/th06/mod.rs src/th06/pbg3.rs src/th06/std.rs src/th06/std_vm.rs src/util/bitstream.rs src/util/lzss.rs src/util/math.rs src/util/mod.rs src/util/prng.rs utils/Cargo.toml utils/src/bitstream.rs utils/src/lib.rs utils/src/lzss.rs utils/src/math.rs utils/src/prng.rs
diffstat 29 files changed, 125 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,20 +1,14 @@
-[package]
-name = "touhou"
-version = "0.1.0"
-authors = ["Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>"]
-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" }
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 <linkmauve@linkmauve.fr>"]
+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 = "*"
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<P: AsRef<Path>>(filename: P) -> io::Result<Vec<u8>> {
+    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 { ' ' },
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;
rename from src/th06/anm0.rs
rename to formats/src/th06/anm0.rs
rename from src/th06/ecl.rs
rename to formats/src/th06/ecl.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;
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};
rename from src/th06/std.rs
rename to formats/src/th06/std.rs
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 <linkmauve@linkmauve.fr>"]
+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 = "*"
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;
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};
 
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;
 
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};
rename from src/th06/interpolator.rs
rename to interpreters/src/th06/interpolator.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;
 
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 <linkmauve@linkmauve.fr>"]
 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"
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;
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;
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;
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;
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;
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;
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 <linkmauve@linkmauve.fr>"]
+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]
rename from src/util/bitstream.rs
rename to utils/src/bitstream.rs
rename from src/util/mod.rs
rename to utils/src/lib.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<R: io::Read + io::Seek>(bitstream: &mut BitStream<R>, size: usize, dictionary_size: usize, offset_size: usize, length_size: usize, minimum_match_length: usize) -> io::Result<Vec<u8>> {
rename from src/util/math.rs
rename to utils/src/math.rs
rename from src/util/prng.rs
rename to utils/src/prng.rs