From 7ccca1c65823b7f3bd2aca494f2c2be5307d299d Mon Sep 17 00:00:00 2001 From: UserIsntAvailable Date: Mon, 14 Oct 2024 19:37:16 -0400 Subject: [PATCH 1/6] chore: rename `engine` -> `ashen` and `ashen` -> `cli`. chore: remove not needed deps. nothing compiles though :) --- Cargo.lock | 390 +----------------- Cargo.toml | 11 +- ashen/Cargo.toml | 14 +- {engine => ashen}/src/asset/color_map.rs | 0 {engine => ashen}/src/asset/gamma_table.rs | 0 {engine => ashen}/src/asset/mod.rs | 0 .../src/asset/model/dat/frame.rs | 0 .../src/asset/model/dat/header.rs | 0 {engine => ashen}/src/asset/model/dat/mod.rs | 0 .../src/asset/model/dat/sequence.rs | 0 .../src/asset/model/dat/triangle.rs | 0 {engine => ashen}/src/asset/model/mod.rs | 0 {engine => ashen}/src/asset/pack_file.rs | 0 {engine => ashen}/src/asset/pack_info.rs | 0 {engine => ashen}/src/asset/skybox.rs | 0 .../src/asset/sound/dat/asset_header.rs | 0 .../src/asset/sound/dat/chunk_header.rs | 0 .../src/asset/sound/dat/finetune.rs | 0 .../src/asset/sound/dat/mixer.rs | 0 {engine => ashen}/src/asset/sound/dat/mod.rs | 0 .../src/asset/sound/dat/pattern_effect.rs | 0 .../src/asset/sound/dat/pattern_event.rs | 0 .../src/asset/sound/dat/t_effect.rs | 0 .../src/asset/sound/dat/t_instrument.rs | 0 .../src/asset/sound/dat/t_song.rs | 0 {engine => ashen}/src/asset/sound/mod.rs | 0 {engine => ashen}/src/asset/sound/sample.rs | 0 {engine => ashen}/src/asset/string_table.rs | 0 .../src/asset/texture/dat/mod.rs | 0 .../src/asset/texture/dat/offset.rs | 0 .../src/asset/texture/dat/size.rs | 0 .../src/asset/texture/dat/texture.rs | 0 {engine => ashen}/src/asset/texture/mod.rs | 0 {engine => ashen}/src/directory.rs | 0 {engine => ashen}/src/error.rs | 0 {engine => ashen}/src/lib.rs | 0 {engine => ashen}/src/utils/compression.rs | 0 {engine => ashen}/src/utils/format.rs | 0 {engine => ashen}/src/utils/iterator.rs | 0 {engine => ashen}/src/utils/mod.rs | 0 {engine => ashen}/src/utils/nom.rs | 0 {engine => ashen}/src/utils/test.rs | 0 {engine => ashen}/tests/loom.rs | 0 cli/Cargo.toml | 7 + {ashen => cli}/src/main.rs | 0 engine/Cargo.toml | 25 -- 46 files changed, 45 insertions(+), 402 deletions(-) rename {engine => ashen}/src/asset/color_map.rs (100%) rename {engine => ashen}/src/asset/gamma_table.rs (100%) rename {engine => ashen}/src/asset/mod.rs (100%) rename {engine => ashen}/src/asset/model/dat/frame.rs (100%) rename {engine => ashen}/src/asset/model/dat/header.rs (100%) rename {engine => ashen}/src/asset/model/dat/mod.rs (100%) rename {engine => ashen}/src/asset/model/dat/sequence.rs (100%) rename {engine => ashen}/src/asset/model/dat/triangle.rs (100%) rename {engine => ashen}/src/asset/model/mod.rs (100%) rename {engine => ashen}/src/asset/pack_file.rs (100%) rename {engine => ashen}/src/asset/pack_info.rs (100%) rename {engine => ashen}/src/asset/skybox.rs (100%) rename {engine => ashen}/src/asset/sound/dat/asset_header.rs (100%) rename {engine => ashen}/src/asset/sound/dat/chunk_header.rs (100%) rename {engine => ashen}/src/asset/sound/dat/finetune.rs (100%) rename {engine => ashen}/src/asset/sound/dat/mixer.rs (100%) rename {engine => ashen}/src/asset/sound/dat/mod.rs (100%) rename {engine => ashen}/src/asset/sound/dat/pattern_effect.rs (100%) rename {engine => ashen}/src/asset/sound/dat/pattern_event.rs (100%) rename {engine => ashen}/src/asset/sound/dat/t_effect.rs (100%) rename {engine => ashen}/src/asset/sound/dat/t_instrument.rs (100%) rename {engine => ashen}/src/asset/sound/dat/t_song.rs (100%) rename {engine => ashen}/src/asset/sound/mod.rs (100%) rename {engine => ashen}/src/asset/sound/sample.rs (100%) rename {engine => ashen}/src/asset/string_table.rs (100%) rename {engine => ashen}/src/asset/texture/dat/mod.rs (100%) rename {engine => ashen}/src/asset/texture/dat/offset.rs (100%) rename {engine => ashen}/src/asset/texture/dat/size.rs (100%) rename {engine => ashen}/src/asset/texture/dat/texture.rs (100%) rename {engine => ashen}/src/asset/texture/mod.rs (100%) rename {engine => ashen}/src/directory.rs (100%) rename {engine => ashen}/src/error.rs (100%) rename {engine => ashen}/src/lib.rs (100%) rename {engine => ashen}/src/utils/compression.rs (100%) rename {engine => ashen}/src/utils/format.rs (100%) rename {engine => ashen}/src/utils/iterator.rs (100%) rename {engine => ashen}/src/utils/mod.rs (100%) rename {engine => ashen}/src/utils/nom.rs (100%) rename {engine => ashen}/src/utils/test.rs (100%) rename {engine => ashen}/tests/loom.rs (100%) create mode 100644 cli/Cargo.toml rename {ashen => cli}/src/main.rs (100%) delete mode 100644 engine/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index d21b5aa..793d40d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "adler" @@ -8,20 +8,21 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "aho-corasick" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" -dependencies = [ - "memchr", -] - [[package]] name = "ashen" version = "0.1.0" dependencies = [ - "engine", + "assert_approx_eq", + "bitflags 2.4.2", + "const_format", + "eyre", + "fixed", + "flate2", + "image", + "itertools", + "lewton", + "nom", + "paste", ] [[package]] @@ -78,21 +79,19 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" -[[package]] -name = "cc" -version = "1.0.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cli" +version = "0.1.0" +dependencies = [ + "ashen", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -165,26 +164,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -[[package]] -name = "engine" -version = "0.1.0" -dependencies = [ - "assert_approx_eq", - "bitflags 2.4.2", - "const_format", - "eyre", - "fixed", - "flate2", - "image", - "itertools", - "lewton", - "loom", - "nom", - "paste", - "sealed", - "thiserror", -] - [[package]] name = "exr" version = "1.6.4" @@ -267,19 +246,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" -[[package]] -name = "generator" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e" -dependencies = [ - "cc", - "libc", - "log", - "rustversion", - "windows", -] - [[package]] name = "getrandom" version = "0.2.12" @@ -313,12 +279,6 @@ dependencies = [ "crunchy", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "image" version = "0.24.8" @@ -370,12 +330,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "lebe" version = "0.5.2" @@ -415,28 +369,6 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -[[package]] -name = "loom" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e045d70ddfbc984eacfa964ded019534e8f6cbf36f6410aee0ed5cefa5a9175" -dependencies = [ - "cfg-if", - "generator", - "scoped-tls", - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata 0.1.10", -] - [[package]] name = "memchr" version = "2.6.4" @@ -478,16 +410,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - [[package]] name = "num-traits" version = "0.2.17" @@ -512,12 +434,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - [[package]] name = "paste" version = "1.0.14" @@ -544,12 +460,6 @@ dependencies = [ "syn", ] -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - [[package]] name = "png" version = "0.17.11" @@ -610,89 +520,12 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "regex" -version = "1.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata 0.4.3", - "regex-syntax 0.8.2", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax 0.6.29", -] - -[[package]] -name = "regex-automata" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax 0.8.2", -] - -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - -[[package]] -name = "regex-syntax" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" - -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "sealed" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4a8caec23b7800fb97971a1c6ae365b6239aaeddfb934d6265f8505e795699d" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - [[package]] name = "simd-adler32" version = "0.3.7" @@ -725,36 +558,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", -] - [[package]] name = "tiff" version = "0.9.1" @@ -781,67 +584,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" -dependencies = [ - "matchers", - "nu-ansi-term", - "once_cell", - "regex", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", -] - [[package]] name = "typenum" version = "1.17.0" @@ -860,12 +602,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -932,94 +668,6 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "zune-inflate" version = "0.2.54" diff --git a/Cargo.toml b/Cargo.toml index a8f57e8..bb396fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,10 +2,14 @@ resolver = "2" members = [ "ashen", - "engine", + "cli", ] +[profile.release] +overflow-checks = true + + [profile.perf] inherits = "release" codegen-units = 1 @@ -13,7 +17,4 @@ incremental = false lto = "fat" opt-level = 3 panic = "abort" - -[profile.release] -debug = true -overflow-checks = true +overflow-checks = false diff --git a/ashen/Cargo.toml b/ashen/Cargo.toml index 1550ab3..ac64b93 100644 --- a/ashen/Cargo.toml +++ b/ashen/Cargo.toml @@ -4,4 +4,16 @@ version = "0.1.0" edition = "2021" [dependencies] -engine = { path = "../engine/" } +bitflags = "2.4.2" +const_format = "0.2.32" +fixed = "1.24.0" +flate2 = "1.0.28" +itertools = "0.12.0" +lewton = "0.10.2" +nom = "7.1.3" +paste = "1.0.14" + +[dev-dependencies] +assert_approx_eq = "1.1.0" +eyre = "0.6.8" +image = "0.24.8" diff --git a/engine/src/asset/color_map.rs b/ashen/src/asset/color_map.rs similarity index 100% rename from engine/src/asset/color_map.rs rename to ashen/src/asset/color_map.rs diff --git a/engine/src/asset/gamma_table.rs b/ashen/src/asset/gamma_table.rs similarity index 100% rename from engine/src/asset/gamma_table.rs rename to ashen/src/asset/gamma_table.rs diff --git a/engine/src/asset/mod.rs b/ashen/src/asset/mod.rs similarity index 100% rename from engine/src/asset/mod.rs rename to ashen/src/asset/mod.rs diff --git a/engine/src/asset/model/dat/frame.rs b/ashen/src/asset/model/dat/frame.rs similarity index 100% rename from engine/src/asset/model/dat/frame.rs rename to ashen/src/asset/model/dat/frame.rs diff --git a/engine/src/asset/model/dat/header.rs b/ashen/src/asset/model/dat/header.rs similarity index 100% rename from engine/src/asset/model/dat/header.rs rename to ashen/src/asset/model/dat/header.rs diff --git a/engine/src/asset/model/dat/mod.rs b/ashen/src/asset/model/dat/mod.rs similarity index 100% rename from engine/src/asset/model/dat/mod.rs rename to ashen/src/asset/model/dat/mod.rs diff --git a/engine/src/asset/model/dat/sequence.rs b/ashen/src/asset/model/dat/sequence.rs similarity index 100% rename from engine/src/asset/model/dat/sequence.rs rename to ashen/src/asset/model/dat/sequence.rs diff --git a/engine/src/asset/model/dat/triangle.rs b/ashen/src/asset/model/dat/triangle.rs similarity index 100% rename from engine/src/asset/model/dat/triangle.rs rename to ashen/src/asset/model/dat/triangle.rs diff --git a/engine/src/asset/model/mod.rs b/ashen/src/asset/model/mod.rs similarity index 100% rename from engine/src/asset/model/mod.rs rename to ashen/src/asset/model/mod.rs diff --git a/engine/src/asset/pack_file.rs b/ashen/src/asset/pack_file.rs similarity index 100% rename from engine/src/asset/pack_file.rs rename to ashen/src/asset/pack_file.rs diff --git a/engine/src/asset/pack_info.rs b/ashen/src/asset/pack_info.rs similarity index 100% rename from engine/src/asset/pack_info.rs rename to ashen/src/asset/pack_info.rs diff --git a/engine/src/asset/skybox.rs b/ashen/src/asset/skybox.rs similarity index 100% rename from engine/src/asset/skybox.rs rename to ashen/src/asset/skybox.rs diff --git a/engine/src/asset/sound/dat/asset_header.rs b/ashen/src/asset/sound/dat/asset_header.rs similarity index 100% rename from engine/src/asset/sound/dat/asset_header.rs rename to ashen/src/asset/sound/dat/asset_header.rs diff --git a/engine/src/asset/sound/dat/chunk_header.rs b/ashen/src/asset/sound/dat/chunk_header.rs similarity index 100% rename from engine/src/asset/sound/dat/chunk_header.rs rename to ashen/src/asset/sound/dat/chunk_header.rs diff --git a/engine/src/asset/sound/dat/finetune.rs b/ashen/src/asset/sound/dat/finetune.rs similarity index 100% rename from engine/src/asset/sound/dat/finetune.rs rename to ashen/src/asset/sound/dat/finetune.rs diff --git a/engine/src/asset/sound/dat/mixer.rs b/ashen/src/asset/sound/dat/mixer.rs similarity index 100% rename from engine/src/asset/sound/dat/mixer.rs rename to ashen/src/asset/sound/dat/mixer.rs diff --git a/engine/src/asset/sound/dat/mod.rs b/ashen/src/asset/sound/dat/mod.rs similarity index 100% rename from engine/src/asset/sound/dat/mod.rs rename to ashen/src/asset/sound/dat/mod.rs diff --git a/engine/src/asset/sound/dat/pattern_effect.rs b/ashen/src/asset/sound/dat/pattern_effect.rs similarity index 100% rename from engine/src/asset/sound/dat/pattern_effect.rs rename to ashen/src/asset/sound/dat/pattern_effect.rs diff --git a/engine/src/asset/sound/dat/pattern_event.rs b/ashen/src/asset/sound/dat/pattern_event.rs similarity index 100% rename from engine/src/asset/sound/dat/pattern_event.rs rename to ashen/src/asset/sound/dat/pattern_event.rs diff --git a/engine/src/asset/sound/dat/t_effect.rs b/ashen/src/asset/sound/dat/t_effect.rs similarity index 100% rename from engine/src/asset/sound/dat/t_effect.rs rename to ashen/src/asset/sound/dat/t_effect.rs diff --git a/engine/src/asset/sound/dat/t_instrument.rs b/ashen/src/asset/sound/dat/t_instrument.rs similarity index 100% rename from engine/src/asset/sound/dat/t_instrument.rs rename to ashen/src/asset/sound/dat/t_instrument.rs diff --git a/engine/src/asset/sound/dat/t_song.rs b/ashen/src/asset/sound/dat/t_song.rs similarity index 100% rename from engine/src/asset/sound/dat/t_song.rs rename to ashen/src/asset/sound/dat/t_song.rs diff --git a/engine/src/asset/sound/mod.rs b/ashen/src/asset/sound/mod.rs similarity index 100% rename from engine/src/asset/sound/mod.rs rename to ashen/src/asset/sound/mod.rs diff --git a/engine/src/asset/sound/sample.rs b/ashen/src/asset/sound/sample.rs similarity index 100% rename from engine/src/asset/sound/sample.rs rename to ashen/src/asset/sound/sample.rs diff --git a/engine/src/asset/string_table.rs b/ashen/src/asset/string_table.rs similarity index 100% rename from engine/src/asset/string_table.rs rename to ashen/src/asset/string_table.rs diff --git a/engine/src/asset/texture/dat/mod.rs b/ashen/src/asset/texture/dat/mod.rs similarity index 100% rename from engine/src/asset/texture/dat/mod.rs rename to ashen/src/asset/texture/dat/mod.rs diff --git a/engine/src/asset/texture/dat/offset.rs b/ashen/src/asset/texture/dat/offset.rs similarity index 100% rename from engine/src/asset/texture/dat/offset.rs rename to ashen/src/asset/texture/dat/offset.rs diff --git a/engine/src/asset/texture/dat/size.rs b/ashen/src/asset/texture/dat/size.rs similarity index 100% rename from engine/src/asset/texture/dat/size.rs rename to ashen/src/asset/texture/dat/size.rs diff --git a/engine/src/asset/texture/dat/texture.rs b/ashen/src/asset/texture/dat/texture.rs similarity index 100% rename from engine/src/asset/texture/dat/texture.rs rename to ashen/src/asset/texture/dat/texture.rs diff --git a/engine/src/asset/texture/mod.rs b/ashen/src/asset/texture/mod.rs similarity index 100% rename from engine/src/asset/texture/mod.rs rename to ashen/src/asset/texture/mod.rs diff --git a/engine/src/directory.rs b/ashen/src/directory.rs similarity index 100% rename from engine/src/directory.rs rename to ashen/src/directory.rs diff --git a/engine/src/error.rs b/ashen/src/error.rs similarity index 100% rename from engine/src/error.rs rename to ashen/src/error.rs diff --git a/engine/src/lib.rs b/ashen/src/lib.rs similarity index 100% rename from engine/src/lib.rs rename to ashen/src/lib.rs diff --git a/engine/src/utils/compression.rs b/ashen/src/utils/compression.rs similarity index 100% rename from engine/src/utils/compression.rs rename to ashen/src/utils/compression.rs diff --git a/engine/src/utils/format.rs b/ashen/src/utils/format.rs similarity index 100% rename from engine/src/utils/format.rs rename to ashen/src/utils/format.rs diff --git a/engine/src/utils/iterator.rs b/ashen/src/utils/iterator.rs similarity index 100% rename from engine/src/utils/iterator.rs rename to ashen/src/utils/iterator.rs diff --git a/engine/src/utils/mod.rs b/ashen/src/utils/mod.rs similarity index 100% rename from engine/src/utils/mod.rs rename to ashen/src/utils/mod.rs diff --git a/engine/src/utils/nom.rs b/ashen/src/utils/nom.rs similarity index 100% rename from engine/src/utils/nom.rs rename to ashen/src/utils/nom.rs diff --git a/engine/src/utils/test.rs b/ashen/src/utils/test.rs similarity index 100% rename from engine/src/utils/test.rs rename to ashen/src/utils/test.rs diff --git a/engine/tests/loom.rs b/ashen/tests/loom.rs similarity index 100% rename from engine/tests/loom.rs rename to ashen/tests/loom.rs diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 0000000..90cf372 --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "cli" +version = "0.1.0" +edition = "2021" + +[dependencies] +ashen = { path = "../ashen/" } diff --git a/ashen/src/main.rs b/cli/src/main.rs similarity index 100% rename from ashen/src/main.rs rename to cli/src/main.rs diff --git a/engine/Cargo.toml b/engine/Cargo.toml deleted file mode 100644 index f4fd223..0000000 --- a/engine/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "engine" -version = "0.1.0" -edition = "2021" - -[dependencies] -bitflags = "2.4.2" -const_format = "0.2.32" -fixed = "1.24.0" -flate2 = "1.0.28" -itertools = "0.12.0" -lewton = "0.10.2" -loom = { version = "0.7.1", optional = true } -nom = "7.1.3" -paste = "1.0.14" -sealed = "0.5.0" -thiserror = "1.0.56" - -[dev-dependencies] -assert_approx_eq = "1.1.0" -eyre = "0.6.8" -image = "0.24.8" - -[features] -loom = ["dep:loom"] From fa20872110da0af4306fb212fc1794f9101fe384 Mon Sep 17 00:00:00 2001 From: UserIsntAvailable Date: Mon, 14 Oct 2024 19:53:50 -0400 Subject: [PATCH 2/6] refactor: `AssetParser` -> `Parser`. It also removes all the `extension` things. sed sucks btw. --- ashen/src/asset/color_map.rs | 8 ++-- ashen/src/asset/gamma_table.rs | 6 +-- ashen/src/asset/mod.rs | 50 +-------------------- ashen/src/asset/model/dat/frame.rs | 11 ++--- ashen/src/asset/model/dat/header.rs | 7 +-- ashen/src/asset/model/dat/sequence.rs | 7 +-- ashen/src/asset/model/dat/triangle.rs | 9 ++-- ashen/src/asset/model/mod.rs | 7 ++- ashen/src/asset/pack_info.rs | 4 +- ashen/src/asset/skybox.rs | 5 +-- ashen/src/asset/sound/dat/asset_header.rs | 4 +- ashen/src/asset/sound/dat/chunk_header.rs | 4 +- ashen/src/asset/sound/dat/pattern_effect.rs | 7 +-- ashen/src/asset/sound/dat/pattern_event.rs | 15 +++---- ashen/src/asset/sound/dat/t_effect.rs | 6 +-- ashen/src/asset/sound/dat/t_instrument.rs | 10 ++--- ashen/src/asset/sound/dat/t_song.rs | 11 ++--- ashen/src/asset/sound/mod.rs | 6 +-- ashen/src/asset/string_table.rs | 6 +-- ashen/src/asset/texture/dat/offset.rs | 7 +-- ashen/src/asset/texture/dat/texture.rs | 5 +-- ashen/src/asset/texture/mod.rs | 12 ++--- ashen/src/lib.rs | 5 +-- 23 files changed, 68 insertions(+), 144 deletions(-) diff --git a/ashen/src/asset/color_map.rs b/ashen/src/asset/color_map.rs index 4b19571..30795b3 100644 --- a/ashen/src/asset/color_map.rs +++ b/ashen/src/asset/color_map.rs @@ -1,6 +1,6 @@ use std::ops::Deref; -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::{error, utils::nom::*}; const COLORS_COUNT: usize = 256; @@ -35,7 +35,7 @@ impl Color { } } -impl AssetParser for Color { +impl AssetParser for Color { type Output = Self; type Context<'ctx> = (); @@ -55,7 +55,7 @@ pub struct ColorMap { pub shades: Box<[[Color; COLORS_COUNT]; SHADES_COUNT]>, } -impl AssetParser for ColorMap { +impl AssetParser for ColorMap { type Output = Self; type Context<'ctx> = (); @@ -155,7 +155,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, color_map) = >::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; output_file( parsed_file_path!("color-map/monsters.png"), diff --git a/ashen/src/asset/gamma_table.rs b/ashen/src/asset/gamma_table.rs index 050536e..96d82d5 100644 --- a/ashen/src/asset/gamma_table.rs +++ b/ashen/src/asset/gamma_table.rs @@ -1,6 +1,6 @@ use std::mem; -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::{error, utils::nom::*}; const ROWS_COUNT: usize = 256; @@ -12,7 +12,7 @@ pub struct GammaTable { pub lookups: Box<[[u8; ROWS_COUNT]; COLS_COUNT]>, } -impl AssetParser for GammaTable { +impl AssetParser for GammaTable { type Output = Self; type Context<'ctx> = (); @@ -61,7 +61,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, gamma_table) = >::parser(())(&GAMMA_TABLE_DATA)?; + let (_, gamma_table) = ::parser(())(&GAMMA_TABLE_DATA)?; let gamma_table = gamma_table .lookups diff --git a/ashen/src/asset/mod.rs b/ashen/src/asset/mod.rs index 2f0838c..a3dede5 100644 --- a/ashen/src/asset/mod.rs +++ b/ashen/src/asset/mod.rs @@ -10,55 +10,7 @@ pub mod texture; use crate::utils::nom::{Input, Result}; -/// Definition for all available extensions that the engine can parse. -pub mod extension { - #[sealed::sealed] - pub trait Extension: AsRef + for<'str> TryFrom<&'str str> {} - - #[derive(Debug, thiserror::Error)] - #[error("The provided extension is invalid '{}'", self.0)] - pub struct ExtensionMismatchError(String); - - macro_rules! impl_extension { - ($(#[$docs:meta])+ $name:ident => $ext:literal) => { - $(#[$docs])+ - pub struct $name; - - impl AsRef for $name { - fn as_ref(&self) -> &str { - $ext - } - } - - impl TryFrom<&str> for $name { - type Error = ExtensionMismatchError; - - fn try_from(value: &str) -> Result { - if value == $ext { - Ok(Self) - } else { - Err(ExtensionMismatchError(value.to_owned())) - } - } - } - - #[sealed::sealed] - impl Extension for $name {} - }; - } - - impl_extension!( - /// Wildcard - Wildcard => "*" - ); - - impl_extension!( - /// Extension that implies that the asset comes from ashen's files (packfile). - Pack => "pack" - ); -} - -pub trait AssetParser +pub trait AssetParser where Self: Sized, { diff --git a/ashen/src/asset/model/dat/frame.rs b/ashen/src/asset/model/dat/frame.rs index 3c6f024..8460051 100644 --- a/ashen/src/asset/model/dat/frame.rs +++ b/ashen/src/asset/model/dat/frame.rs @@ -1,7 +1,4 @@ -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; // TODO(nenikitov): Should probably be a fancy utility class // With generics for data type and dimension @@ -12,7 +9,7 @@ pub struct Vec3 { pub z: f32, } -impl AssetParser for Vec3 { +impl AssetParser for Vec3 { type Output = Self; type Context<'ctx> = (); @@ -52,7 +49,7 @@ pub struct VertexTransform { origin: Vec3, } -impl AssetParser for ModelVertex { +impl AssetParser for ModelVertex { type Output = Self; type Context<'ctx> = VertexTransform; @@ -97,7 +94,7 @@ pub struct ModelSpecs { pub frame_size: u32, } -impl AssetParser for ModelFrame { +impl AssetParser for ModelFrame { type Output = Self; type Context<'ctx> = ModelSpecs; diff --git a/ashen/src/asset/model/dat/header.rs b/ashen/src/asset/model/dat/header.rs index 74bcb28..7f5f8dc 100644 --- a/ashen/src/asset/model/dat/header.rs +++ b/ashen/src/asset/model/dat/header.rs @@ -1,7 +1,4 @@ -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; pub struct ModelHeader { pub triangle_count: u32, @@ -18,7 +15,7 @@ pub struct ModelHeader { pub locator_nodes: [u8; 16], } -impl AssetParser for ModelHeader { +impl AssetParser for ModelHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/model/dat/sequence.rs b/ashen/src/asset/model/dat/sequence.rs index 067a25c..f603e40 100644 --- a/ashen/src/asset/model/dat/sequence.rs +++ b/ashen/src/asset/model/dat/sequence.rs @@ -1,13 +1,10 @@ -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; pub struct ModelSequence { pub frames: Vec, } -impl AssetParser for ModelSequence { +impl AssetParser for ModelSequence { type Output = Self; // TODO(nenikitov): Maybe refactor it to not accept full input. diff --git a/ashen/src/asset/model/dat/triangle.rs b/ashen/src/asset/model/dat/triangle.rs index d9f5764..f6e636f 100644 --- a/ashen/src/asset/model/dat/triangle.rs +++ b/ashen/src/asset/model/dat/triangle.rs @@ -1,7 +1,4 @@ -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; pub struct ModelPoint { pub vertex_index: u16, @@ -14,7 +11,7 @@ pub struct TextureDimensions { pub height: u32, } -impl AssetParser for ModelPoint { +impl AssetParser for ModelPoint { type Output = Self; type Context<'ctx> = &'ctx TextureDimensions; @@ -39,7 +36,7 @@ pub struct ModelTriangle { pub points: [ModelPoint; 3], } -impl AssetParser for ModelTriangle { +impl AssetParser for ModelTriangle { type Output = Self; type Context<'ctx> = TextureDimensions; diff --git a/ashen/src/asset/model/mod.rs b/ashen/src/asset/model/mod.rs index 606ba71..b9dc44f 100644 --- a/ashen/src/asset/model/mod.rs +++ b/ashen/src/asset/model/mod.rs @@ -8,7 +8,6 @@ use dat::{ }; use super::{ - extension::*, texture::{Texture, TextureSize}, AssetParser, }; @@ -21,7 +20,7 @@ pub struct Model { pub frames: Vec, } -impl AssetParser for Model { +impl AssetParser for Model { type Output = Self; type Context<'ctx> = (); @@ -95,9 +94,9 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, model) = >::parser(())(&MODEL_DATA)?; + let (_, model) = ::parser(())(&MODEL_DATA)?; let palette = { - let (_, color_map) = >::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; color_map.shades[15] }; diff --git a/ashen/src/asset/pack_info.rs b/ashen/src/asset/pack_info.rs index 1906356..44b26b1 100644 --- a/ashen/src/asset/pack_info.rs +++ b/ashen/src/asset/pack_info.rs @@ -1,6 +1,6 @@ use std::ops::Index; -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::utils::nom::*; #[derive(Debug)] @@ -9,7 +9,7 @@ pub struct PackInfo { pub size: u32, } -impl AssetParser for PackInfo { +impl AssetParser for PackInfo { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/skybox.rs b/ashen/src/asset/skybox.rs index 15090e0..ee776c8 100644 --- a/ashen/src/asset/skybox.rs +++ b/ashen/src/asset/skybox.rs @@ -1,5 +1,4 @@ use super::{ - extension::*, texture::{Texture, TextureSize}, AssetParser, }; @@ -12,7 +11,7 @@ pub struct Skybox { pub texture: Texture, } -impl AssetParser for Skybox { +impl AssetParser for Skybox { type Output = Self; type Context<'ctx> = (); @@ -51,7 +50,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, skybox) = >::parser(())(&SKYBOX_DATA)?; + let (_, skybox) = ::parser(())(&SKYBOX_DATA)?; output_file( parsed_file_path!("skyboxes/level-1.png"), diff --git a/ashen/src/asset/sound/dat/asset_header.rs b/ashen/src/asset/sound/dat/asset_header.rs index 51fdad0..a5d03a4 100644 --- a/ashen/src/asset/sound/dat/asset_header.rs +++ b/ashen/src/asset/sound/dat/asset_header.rs @@ -1,5 +1,5 @@ use crate::{ - asset::{extension::*, pack_info::PackInfo, AssetParser}, + asset::{pack_info::PackInfo, AssetParser}, utils::nom::*, }; @@ -14,7 +14,7 @@ impl SoundAssetHeader { const HEADER: &'static str = "TSND"; } -impl AssetParser for SoundAssetHeader { +impl AssetParser for SoundAssetHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/chunk_header.rs b/ashen/src/asset/sound/dat/chunk_header.rs index 3990ea4..3b7cbbf 100644 --- a/ashen/src/asset/sound/dat/chunk_header.rs +++ b/ashen/src/asset/sound/dat/chunk_header.rs @@ -1,5 +1,5 @@ use crate::{ - asset::{extension::*, pack_info::PackInfo, AssetParser}, + asset::{pack_info::PackInfo, AssetParser}, utils::nom::*, }; @@ -7,7 +7,7 @@ pub struct SoundChunkHeader { pub infos: Vec, } -impl AssetParser for SoundChunkHeader { +impl AssetParser for SoundChunkHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/pattern_effect.rs b/ashen/src/asset/sound/dat/pattern_effect.rs index b7b91a6..1d1cfe4 100644 --- a/ashen/src/asset/sound/dat/pattern_effect.rs +++ b/ashen/src/asset/sound/dat/pattern_effect.rs @@ -1,8 +1,5 @@ use super::{convert_volume, finetune::FineTune}; -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; #[derive(Debug, Clone, Copy)] pub enum Speed { @@ -130,7 +127,7 @@ impl PatternEffect { } } -impl AssetParser for Option { +impl AssetParser for Option { type Output = Self; type Context<'ctx> = bool; diff --git a/ashen/src/asset/sound/dat/pattern_event.rs b/ashen/src/asset/sound/dat/pattern_event.rs index 73651d8..1edeb04 100644 --- a/ashen/src/asset/sound/dat/pattern_event.rs +++ b/ashen/src/asset/sound/dat/pattern_event.rs @@ -3,10 +3,7 @@ use std::rc::Rc; use bitflags::bitflags; use super::{convert_volume, finetune::FineTune, pattern_effect::PatternEffect, t_instrument::*}; -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; #[derive(Default, PartialEq, Clone, Copy, Debug)] pub enum PatternEventNote { @@ -15,7 +12,7 @@ pub enum PatternEventNote { On(FineTune), } -impl AssetParser for Option { +impl AssetParser for Option { type Output = Self; type Context<'ctx> = bool; @@ -51,7 +48,7 @@ bitflags! { } } -impl AssetParser for PatternEventFlags { +impl AssetParser for PatternEventFlags { type Output = Self; type Context<'ctx> = (); @@ -71,7 +68,7 @@ impl AssetParser for PatternEventFlags { } } -impl AssetParser for Option { +impl AssetParser for Option { type Output = Self; type Context<'ctx> = (bool, &'ctx [Rc]); @@ -105,7 +102,7 @@ impl Default for PatternEventVolume { } } -impl AssetParser for Option { +impl AssetParser for Option { type Output = Self; type Context<'ctx> = bool; @@ -152,7 +149,7 @@ impl PatternEvent { } } -impl AssetParser for PatternEvent { +impl AssetParser for PatternEvent { type Output = Self; type Context<'ctx> = &'ctx [Rc]; diff --git a/ashen/src/asset/sound/dat/t_effect.rs b/ashen/src/asset/sound/dat/t_effect.rs index 1966b12..5ccdf45 100644 --- a/ashen/src/asset/sound/dat/t_effect.rs +++ b/ashen/src/asset/sound/dat/t_effect.rs @@ -5,7 +5,7 @@ use super::{ uncompress, }; use crate::{ - asset::{extension::*, sound::sample::AudioBuffer, AssetParser}, + asset::{sound::sample::AudioBuffer, AssetParser}, utils::nom::*, }; @@ -20,7 +20,7 @@ impl TEffect { } } -impl AssetParser for TEffect { +impl AssetParser for TEffect { type Output = Self; type Context<'ctx> = (); @@ -50,7 +50,7 @@ struct TEffectPointers { sample_data: u32, } -impl AssetParser for TEffectPointers { +impl AssetParser for TEffectPointers { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/t_instrument.rs b/ashen/src/asset/sound/dat/t_instrument.rs index 53972f0..f37cb01 100644 --- a/ashen/src/asset/sound/dat/t_instrument.rs +++ b/ashen/src/asset/sound/dat/t_instrument.rs @@ -4,7 +4,7 @@ use bitflags::bitflags; use super::{convert_volume, finetune::FineTune}; use crate::{ - asset::{extension::*, sound::sample::AudioBuffer, AssetParser}, + asset::{sound::sample::AudioBuffer, AssetParser}, utils::{iterator::CollectArray, nom::*}, }; @@ -16,7 +16,7 @@ bitflags! { } } -impl AssetParser for TInstrumentFlags { +impl AssetParser for TInstrumentFlags { type Output = Self; type Context<'ctx> = (); @@ -68,7 +68,7 @@ impl TInstrumentVolumeEnvelope { } } -impl AssetParser for Option { +impl AssetParser for Option { type Output = Self; type Context<'ctx> = bool; @@ -129,7 +129,7 @@ impl TInstrument { const ENVELOPE_SIZE: usize = 325; } -impl AssetParser for TInstrument { +impl AssetParser for TInstrument { type Output = Self; type Context<'ctx> = &'ctx [Rc]; @@ -214,7 +214,7 @@ pub struct TSample { pub buffer: AudioBuffer, } -impl AssetParser for TSample { +impl AssetParser for TSample { type Output = Self; type Context<'ctx> = &'ctx [i16]; diff --git a/ashen/src/asset/sound/dat/t_song.rs b/ashen/src/asset/sound/dat/t_song.rs index cbef1a4..aaac9e0 100644 --- a/ashen/src/asset/sound/dat/t_song.rs +++ b/ashen/src/asset/sound/dat/t_song.rs @@ -3,10 +3,7 @@ use std::rc::Rc; use itertools::Itertools; use super::{pattern_event::*, t_instrument::*, uncompress}; -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; pub type PatternRow = Vec; pub type Pattern = Vec; @@ -93,7 +90,7 @@ impl std::fmt::Debug for TSong { } } -impl AssetParser for TSong { +impl AssetParser for TSong { type Output = Self; type Context<'ctx> = (); @@ -188,7 +185,7 @@ struct TSongHeader { bpm: u8, } -impl AssetParser for TSongHeader { +impl AssetParser for TSongHeader { type Output = Self; type Context<'ctx> = (); @@ -232,7 +229,7 @@ struct TSongPointers { sample_data: u32, } -impl AssetParser for TSongPointers { +impl AssetParser for TSongPointers { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/mod.rs b/ashen/src/asset/sound/mod.rs index 946ccdb..f0bc1d9 100644 --- a/ashen/src/asset/sound/mod.rs +++ b/ashen/src/asset/sound/mod.rs @@ -2,7 +2,7 @@ mod dat; pub(crate) mod sample; use self::{dat::mixer::TSongMixer, sample::AudioBuffer}; -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::{ asset::sound::dat::{ asset_header::SoundAssetHeader, chunk_header::SoundChunkHeader, t_effect::TEffect, @@ -32,7 +32,7 @@ impl SoundCollection { pub const CHANNEL_COUNT: usize = 1; } -impl AssetParser for SoundCollection { +impl AssetParser for SoundCollection { type Output = Vec; type Context<'ctx> = (); @@ -78,7 +78,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, sounds) = >::parser(())(&SOUND_DATA)?; + let (_, sounds) = ::parser(())(&SOUND_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("sounds/songs/")); diff --git a/ashen/src/asset/string_table.rs b/ashen/src/asset/string_table.rs index 270d723..e4f1d6d 100644 --- a/ashen/src/asset/string_table.rs +++ b/ashen/src/asset/string_table.rs @@ -1,4 +1,4 @@ -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::utils::nom::*; pub struct StringTable { @@ -14,7 +14,7 @@ fn utf_16_string(input: &[u8]) -> Result { }) } -impl AssetParser for StringTable { +impl AssetParser for StringTable { type Output = Self; type Context<'ctx> = (); @@ -42,7 +42,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, string_table) = >::parser(())(&STRING_TABLE_DATA)?; + let (_, string_table) = ::parser(())(&STRING_TABLE_DATA)?; output_file( parsed_file_path!("strings/english-uk.txt"), diff --git a/ashen/src/asset/texture/dat/offset.rs b/ashen/src/asset/texture/dat/offset.rs index c241c80..fc1075c 100644 --- a/ashen/src/asset/texture/dat/offset.rs +++ b/ashen/src/asset/texture/dat/offset.rs @@ -1,7 +1,4 @@ -use crate::{ - asset::{extension::*, AssetParser}, - utils::nom::*, -}; +use crate::{asset::AssetParser, utils::nom::*}; pub struct TextureOffset { pub width: u16, @@ -13,7 +10,7 @@ pub struct TextureOffset { pub next_animation_texture_id: u32, } -impl AssetParser for TextureOffset { +impl AssetParser for TextureOffset { type Context<'ctx> = (); type Output = Self; diff --git a/ashen/src/asset/texture/dat/texture.rs b/ashen/src/asset/texture/dat/texture.rs index dcb4998..62479fc 100644 --- a/ashen/src/asset/texture/dat/texture.rs +++ b/ashen/src/asset/texture/dat/texture.rs @@ -4,7 +4,6 @@ use super::size::TextureSize; use crate::{ asset::{ color_map::{Color, PaletteTexture}, - extension::*, AssetParser, }, utils::nom::*, @@ -16,7 +15,7 @@ pub struct Texture { pub colors: Vec>, } -impl AssetParser for Texture { +impl AssetParser for Texture { type Output = Self; type Context<'ctx> = TextureSize; @@ -52,7 +51,7 @@ pub struct MippedTexture { pub mips: [Texture; 4], } -impl AssetParser for MippedTexture { +impl AssetParser for MippedTexture { type Output = Self; type Context<'ctx> = TextureSize; diff --git a/ashen/src/asset/texture/mod.rs b/ashen/src/asset/texture/mod.rs index 210e4f6..cd6a83a 100644 --- a/ashen/src/asset/texture/mod.rs +++ b/ashen/src/asset/texture/mod.rs @@ -3,7 +3,7 @@ mod dat; use dat::{offset::TextureOffset, texture::MippedTexture}; pub use dat::{size::TextureSize, texture::Texture}; -use super::{extension::*, AssetParser}; +use super::AssetParser; use crate::utils::{compression::decompress, nom::*}; pub enum TextureMipKind { @@ -18,7 +18,7 @@ pub enum TextureAnimationKind { pub struct TextureOffsetCollection; -impl AssetParser for TextureOffsetCollection { +impl AssetParser for TextureOffsetCollection { type Output = Vec; type Context<'ctx> = (); @@ -34,7 +34,7 @@ impl AssetParser for TextureOffsetCollection { pub struct MippedTextureCollection; -impl AssetParser for MippedTextureCollection { +impl AssetParser for MippedTextureCollection { type Output = Vec; type Context<'ctx> = &'ctx [TextureOffset]; @@ -99,12 +99,12 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, color_map) = >::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; let color_map = &color_map.shades[15]; let (_, offsets) = - >::parser(())(&TEXTURE_INFO_DATA)?; + ::parser(())(&TEXTURE_INFO_DATA)?; let (_, textures) = - >::parser(&offsets)(&TEXTURE_DATA)?; + ::parser(&offsets)(&TEXTURE_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("textures/")); diff --git a/ashen/src/lib.rs b/ashen/src/lib.rs index a6f1160..70efeaa 100644 --- a/ashen/src/lib.rs +++ b/ashen/src/lib.rs @@ -17,13 +17,12 @@ )] #![warn(unused_imports)] #![feature( - // Discussion about possible future alternatives: - // https://github.com/rust-lang/rust/pull/101179 debug_closure_helpers, - duration_consts_float, generic_const_exprs, io_error_more, let_chains, + // Discussion about possible future alternatives: + // https://github.com/rust-lang/rust/pull/101179 maybe_uninit_uninit_array_transpose, )] From 3486a6c44d7bd1a912c00dd306177f33a2835526 Mon Sep 17 00:00:00 2001 From: UserIsntAvailable Date: Mon, 14 Oct 2024 20:04:23 -0400 Subject: [PATCH 3/6] chore: actually rename `AssetParser` -> `Parser`. chore: make `asset::pack_info` public. --- ashen/src/asset/color_map.rs | 8 ++++---- ashen/src/asset/gamma_table.rs | 6 +++--- ashen/src/asset/mod.rs | 4 ++-- ashen/src/asset/model/dat/frame.rs | 8 ++++---- ashen/src/asset/model/dat/header.rs | 4 ++-- ashen/src/asset/model/dat/sequence.rs | 4 ++-- ashen/src/asset/model/dat/triangle.rs | 6 +++--- ashen/src/asset/model/mod.rs | 8 ++++---- ashen/src/asset/pack_info.rs | 4 ++-- ashen/src/asset/skybox.rs | 6 +++--- ashen/src/asset/sound/dat/asset_header.rs | 4 ++-- ashen/src/asset/sound/dat/chunk_header.rs | 4 ++-- ashen/src/asset/sound/dat/pattern_effect.rs | 4 ++-- ashen/src/asset/sound/dat/pattern_event.rs | 12 ++++++------ ashen/src/asset/sound/dat/t_effect.rs | 6 +++--- ashen/src/asset/sound/dat/t_instrument.rs | 10 +++++----- ashen/src/asset/sound/dat/t_song.rs | 8 ++++---- ashen/src/asset/sound/mod.rs | 6 +++--- ashen/src/asset/string_table.rs | 6 +++--- ashen/src/asset/texture/dat/offset.rs | 4 ++-- ashen/src/asset/texture/dat/texture.rs | 6 +++--- ashen/src/asset/texture/mod.rs | 12 ++++++------ 22 files changed, 70 insertions(+), 70 deletions(-) diff --git a/ashen/src/asset/color_map.rs b/ashen/src/asset/color_map.rs index 30795b3..aa7dde6 100644 --- a/ashen/src/asset/color_map.rs +++ b/ashen/src/asset/color_map.rs @@ -1,6 +1,6 @@ use std::ops::Deref; -use super::AssetParser; +use super::Parser; use crate::{error, utils::nom::*}; const COLORS_COUNT: usize = 256; @@ -35,7 +35,7 @@ impl Color { } } -impl AssetParser for Color { +impl Parser for Color { type Output = Self; type Context<'ctx> = (); @@ -55,7 +55,7 @@ pub struct ColorMap { pub shades: Box<[[Color; COLORS_COUNT]; SHADES_COUNT]>, } -impl AssetParser for ColorMap { +impl Parser for ColorMap { type Output = Self; type Context<'ctx> = (); @@ -155,7 +155,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ColorMap::parser(())(&COLOR_MAP_DATA)?; output_file( parsed_file_path!("color-map/monsters.png"), diff --git a/ashen/src/asset/gamma_table.rs b/ashen/src/asset/gamma_table.rs index 96d82d5..7b22ab6 100644 --- a/ashen/src/asset/gamma_table.rs +++ b/ashen/src/asset/gamma_table.rs @@ -1,6 +1,6 @@ use std::mem; -use super::AssetParser; +use super::Parser; use crate::{error, utils::nom::*}; const ROWS_COUNT: usize = 256; @@ -12,7 +12,7 @@ pub struct GammaTable { pub lookups: Box<[[u8; ROWS_COUNT]; COLS_COUNT]>, } -impl AssetParser for GammaTable { +impl Parser for GammaTable { type Output = Self; type Context<'ctx> = (); @@ -61,7 +61,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, gamma_table) = ::parser(())(&GAMMA_TABLE_DATA)?; + let (_, gamma_table) = GammaTable::parser(())(&GAMMA_TABLE_DATA)?; let gamma_table = gamma_table .lookups diff --git a/ashen/src/asset/mod.rs b/ashen/src/asset/mod.rs index a3dede5..3925edf 100644 --- a/ashen/src/asset/mod.rs +++ b/ashen/src/asset/mod.rs @@ -2,7 +2,7 @@ pub mod color_map; pub mod gamma_table; pub mod model; pub mod pack_file; -mod pack_info; +pub mod pack_info; pub mod skybox; pub mod sound; pub mod string_table; @@ -10,7 +10,7 @@ pub mod texture; use crate::utils::nom::{Input, Result}; -pub trait AssetParser +pub trait Parser where Self: Sized, { diff --git a/ashen/src/asset/model/dat/frame.rs b/ashen/src/asset/model/dat/frame.rs index 8460051..bcc1e63 100644 --- a/ashen/src/asset/model/dat/frame.rs +++ b/ashen/src/asset/model/dat/frame.rs @@ -1,4 +1,4 @@ -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; // TODO(nenikitov): Should probably be a fancy utility class // With generics for data type and dimension @@ -9,7 +9,7 @@ pub struct Vec3 { pub z: f32, } -impl AssetParser for Vec3 { +impl Parser for Vec3 { type Output = Self; type Context<'ctx> = (); @@ -49,7 +49,7 @@ pub struct VertexTransform { origin: Vec3, } -impl AssetParser for ModelVertex { +impl Parser for ModelVertex { type Output = Self; type Context<'ctx> = VertexTransform; @@ -94,7 +94,7 @@ pub struct ModelSpecs { pub frame_size: u32, } -impl AssetParser for ModelFrame { +impl Parser for ModelFrame { type Output = Self; type Context<'ctx> = ModelSpecs; diff --git a/ashen/src/asset/model/dat/header.rs b/ashen/src/asset/model/dat/header.rs index 7f5f8dc..2395cc7 100644 --- a/ashen/src/asset/model/dat/header.rs +++ b/ashen/src/asset/model/dat/header.rs @@ -1,4 +1,4 @@ -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; pub struct ModelHeader { pub triangle_count: u32, @@ -15,7 +15,7 @@ pub struct ModelHeader { pub locator_nodes: [u8; 16], } -impl AssetParser for ModelHeader { +impl Parser for ModelHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/model/dat/sequence.rs b/ashen/src/asset/model/dat/sequence.rs index f603e40..8b1f1e0 100644 --- a/ashen/src/asset/model/dat/sequence.rs +++ b/ashen/src/asset/model/dat/sequence.rs @@ -1,10 +1,10 @@ -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; pub struct ModelSequence { pub frames: Vec, } -impl AssetParser for ModelSequence { +impl Parser for ModelSequence { type Output = Self; // TODO(nenikitov): Maybe refactor it to not accept full input. diff --git a/ashen/src/asset/model/dat/triangle.rs b/ashen/src/asset/model/dat/triangle.rs index f6e636f..f708f0a 100644 --- a/ashen/src/asset/model/dat/triangle.rs +++ b/ashen/src/asset/model/dat/triangle.rs @@ -1,4 +1,4 @@ -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; pub struct ModelPoint { pub vertex_index: u16, @@ -11,7 +11,7 @@ pub struct TextureDimensions { pub height: u32, } -impl AssetParser for ModelPoint { +impl Parser for ModelPoint { type Output = Self; type Context<'ctx> = &'ctx TextureDimensions; @@ -36,7 +36,7 @@ pub struct ModelTriangle { pub points: [ModelPoint; 3], } -impl AssetParser for ModelTriangle { +impl Parser for ModelTriangle { type Output = Self; type Context<'ctx> = TextureDimensions; diff --git a/ashen/src/asset/model/mod.rs b/ashen/src/asset/model/mod.rs index b9dc44f..d63ed6b 100644 --- a/ashen/src/asset/model/mod.rs +++ b/ashen/src/asset/model/mod.rs @@ -9,7 +9,7 @@ use dat::{ use super::{ texture::{Texture, TextureSize}, - AssetParser, + Parser, }; use crate::utils::nom::*; @@ -20,7 +20,7 @@ pub struct Model { pub frames: Vec, } -impl AssetParser for Model { +impl Parser for Model { type Output = Self; type Context<'ctx> = (); @@ -94,9 +94,9 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, model) = ::parser(())(&MODEL_DATA)?; + let (_, model) = Model::parser(())(&MODEL_DATA)?; let palette = { - let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ColorMap::parser(())(&COLOR_MAP_DATA)?; color_map.shades[15] }; diff --git a/ashen/src/asset/pack_info.rs b/ashen/src/asset/pack_info.rs index 44b26b1..805fa81 100644 --- a/ashen/src/asset/pack_info.rs +++ b/ashen/src/asset/pack_info.rs @@ -1,6 +1,6 @@ use std::ops::Index; -use super::AssetParser; +use super::Parser; use crate::utils::nom::*; #[derive(Debug)] @@ -9,7 +9,7 @@ pub struct PackInfo { pub size: u32, } -impl AssetParser for PackInfo { +impl Parser for PackInfo { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/skybox.rs b/ashen/src/asset/skybox.rs index ee776c8..0e1f451 100644 --- a/ashen/src/asset/skybox.rs +++ b/ashen/src/asset/skybox.rs @@ -1,6 +1,6 @@ use super::{ texture::{Texture, TextureSize}, - AssetParser, + Parser, }; use crate::{asset::color_map::Color, utils::nom::*}; @@ -11,7 +11,7 @@ pub struct Skybox { pub texture: Texture, } -impl AssetParser for Skybox { +impl Parser for Skybox { type Output = Self; type Context<'ctx> = (); @@ -50,7 +50,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, skybox) = ::parser(())(&SKYBOX_DATA)?; + let (_, skybox) = Skybox::parser(())(&SKYBOX_DATA)?; output_file( parsed_file_path!("skyboxes/level-1.png"), diff --git a/ashen/src/asset/sound/dat/asset_header.rs b/ashen/src/asset/sound/dat/asset_header.rs index a5d03a4..9a1b1fe 100644 --- a/ashen/src/asset/sound/dat/asset_header.rs +++ b/ashen/src/asset/sound/dat/asset_header.rs @@ -1,5 +1,5 @@ use crate::{ - asset::{pack_info::PackInfo, AssetParser}, + asset::{pack_info::PackInfo, Parser}, utils::nom::*, }; @@ -14,7 +14,7 @@ impl SoundAssetHeader { const HEADER: &'static str = "TSND"; } -impl AssetParser for SoundAssetHeader { +impl Parser for SoundAssetHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/chunk_header.rs b/ashen/src/asset/sound/dat/chunk_header.rs index 3b7cbbf..c964d67 100644 --- a/ashen/src/asset/sound/dat/chunk_header.rs +++ b/ashen/src/asset/sound/dat/chunk_header.rs @@ -1,5 +1,5 @@ use crate::{ - asset::{pack_info::PackInfo, AssetParser}, + asset::{pack_info::PackInfo, Parser}, utils::nom::*, }; @@ -7,7 +7,7 @@ pub struct SoundChunkHeader { pub infos: Vec, } -impl AssetParser for SoundChunkHeader { +impl Parser for SoundChunkHeader { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/pattern_effect.rs b/ashen/src/asset/sound/dat/pattern_effect.rs index 1d1cfe4..b036aa2 100644 --- a/ashen/src/asset/sound/dat/pattern_effect.rs +++ b/ashen/src/asset/sound/dat/pattern_effect.rs @@ -1,5 +1,5 @@ use super::{convert_volume, finetune::FineTune}; -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; #[derive(Debug, Clone, Copy)] pub enum Speed { @@ -127,7 +127,7 @@ impl PatternEffect { } } -impl AssetParser for Option { +impl Parser for Option { type Output = Self; type Context<'ctx> = bool; diff --git a/ashen/src/asset/sound/dat/pattern_event.rs b/ashen/src/asset/sound/dat/pattern_event.rs index 1edeb04..991622b 100644 --- a/ashen/src/asset/sound/dat/pattern_event.rs +++ b/ashen/src/asset/sound/dat/pattern_event.rs @@ -3,7 +3,7 @@ use std::rc::Rc; use bitflags::bitflags; use super::{convert_volume, finetune::FineTune, pattern_effect::PatternEffect, t_instrument::*}; -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; #[derive(Default, PartialEq, Clone, Copy, Debug)] pub enum PatternEventNote { @@ -12,7 +12,7 @@ pub enum PatternEventNote { On(FineTune), } -impl AssetParser for Option { +impl Parser for Option { type Output = Self; type Context<'ctx> = bool; @@ -48,7 +48,7 @@ bitflags! { } } -impl AssetParser for PatternEventFlags { +impl Parser for PatternEventFlags { type Output = Self; type Context<'ctx> = (); @@ -68,7 +68,7 @@ impl AssetParser for PatternEventFlags { } } -impl AssetParser for Option { +impl Parser for Option { type Output = Self; type Context<'ctx> = (bool, &'ctx [Rc]); @@ -102,7 +102,7 @@ impl Default for PatternEventVolume { } } -impl AssetParser for Option { +impl Parser for Option { type Output = Self; type Context<'ctx> = bool; @@ -149,7 +149,7 @@ impl PatternEvent { } } -impl AssetParser for PatternEvent { +impl Parser for PatternEvent { type Output = Self; type Context<'ctx> = &'ctx [Rc]; diff --git a/ashen/src/asset/sound/dat/t_effect.rs b/ashen/src/asset/sound/dat/t_effect.rs index 5ccdf45..df24438 100644 --- a/ashen/src/asset/sound/dat/t_effect.rs +++ b/ashen/src/asset/sound/dat/t_effect.rs @@ -5,7 +5,7 @@ use super::{ uncompress, }; use crate::{ - asset::{sound::sample::AudioBuffer, AssetParser}, + asset::{sound::sample::AudioBuffer, Parser}, utils::nom::*, }; @@ -20,7 +20,7 @@ impl TEffect { } } -impl AssetParser for TEffect { +impl Parser for TEffect { type Output = Self; type Context<'ctx> = (); @@ -50,7 +50,7 @@ struct TEffectPointers { sample_data: u32, } -impl AssetParser for TEffectPointers { +impl Parser for TEffectPointers { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/dat/t_instrument.rs b/ashen/src/asset/sound/dat/t_instrument.rs index f37cb01..192419c 100644 --- a/ashen/src/asset/sound/dat/t_instrument.rs +++ b/ashen/src/asset/sound/dat/t_instrument.rs @@ -4,7 +4,7 @@ use bitflags::bitflags; use super::{convert_volume, finetune::FineTune}; use crate::{ - asset::{sound::sample::AudioBuffer, AssetParser}, + asset::{sound::sample::AudioBuffer, Parser}, utils::{iterator::CollectArray, nom::*}, }; @@ -16,7 +16,7 @@ bitflags! { } } -impl AssetParser for TInstrumentFlags { +impl Parser for TInstrumentFlags { type Output = Self; type Context<'ctx> = (); @@ -68,7 +68,7 @@ impl TInstrumentVolumeEnvelope { } } -impl AssetParser for Option { +impl Parser for Option { type Output = Self; type Context<'ctx> = bool; @@ -129,7 +129,7 @@ impl TInstrument { const ENVELOPE_SIZE: usize = 325; } -impl AssetParser for TInstrument { +impl Parser for TInstrument { type Output = Self; type Context<'ctx> = &'ctx [Rc]; @@ -214,7 +214,7 @@ pub struct TSample { pub buffer: AudioBuffer, } -impl AssetParser for TSample { +impl Parser for TSample { type Output = Self; type Context<'ctx> = &'ctx [i16]; diff --git a/ashen/src/asset/sound/dat/t_song.rs b/ashen/src/asset/sound/dat/t_song.rs index aaac9e0..a055294 100644 --- a/ashen/src/asset/sound/dat/t_song.rs +++ b/ashen/src/asset/sound/dat/t_song.rs @@ -3,7 +3,7 @@ use std::rc::Rc; use itertools::Itertools; use super::{pattern_event::*, t_instrument::*, uncompress}; -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; pub type PatternRow = Vec; pub type Pattern = Vec; @@ -90,7 +90,7 @@ impl std::fmt::Debug for TSong { } } -impl AssetParser for TSong { +impl Parser for TSong { type Output = Self; type Context<'ctx> = (); @@ -185,7 +185,7 @@ struct TSongHeader { bpm: u8, } -impl AssetParser for TSongHeader { +impl Parser for TSongHeader { type Output = Self; type Context<'ctx> = (); @@ -229,7 +229,7 @@ struct TSongPointers { sample_data: u32, } -impl AssetParser for TSongPointers { +impl Parser for TSongPointers { type Output = Self; type Context<'ctx> = (); diff --git a/ashen/src/asset/sound/mod.rs b/ashen/src/asset/sound/mod.rs index f0bc1d9..3202cf8 100644 --- a/ashen/src/asset/sound/mod.rs +++ b/ashen/src/asset/sound/mod.rs @@ -2,7 +2,7 @@ mod dat; pub(crate) mod sample; use self::{dat::mixer::TSongMixer, sample::AudioBuffer}; -use super::AssetParser; +use super::Parser; use crate::{ asset::sound::dat::{ asset_header::SoundAssetHeader, chunk_header::SoundChunkHeader, t_effect::TEffect, @@ -32,7 +32,7 @@ impl SoundCollection { pub const CHANNEL_COUNT: usize = 1; } -impl AssetParser for SoundCollection { +impl Parser for SoundCollection { type Output = Vec; type Context<'ctx> = (); @@ -78,7 +78,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, sounds) = ::parser(())(&SOUND_DATA)?; + let (_, sounds) = SoundCollection::parser(())(&SOUND_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("sounds/songs/")); diff --git a/ashen/src/asset/string_table.rs b/ashen/src/asset/string_table.rs index e4f1d6d..b5f3a03 100644 --- a/ashen/src/asset/string_table.rs +++ b/ashen/src/asset/string_table.rs @@ -1,4 +1,4 @@ -use super::AssetParser; +use super::Parser; use crate::utils::nom::*; pub struct StringTable { @@ -14,7 +14,7 @@ fn utf_16_string(input: &[u8]) -> Result { }) } -impl AssetParser for StringTable { +impl Parser for StringTable { type Output = Self; type Context<'ctx> = (); @@ -42,7 +42,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, string_table) = ::parser(())(&STRING_TABLE_DATA)?; + let (_, string_table) = StringTable::parser(())(&STRING_TABLE_DATA)?; output_file( parsed_file_path!("strings/english-uk.txt"), diff --git a/ashen/src/asset/texture/dat/offset.rs b/ashen/src/asset/texture/dat/offset.rs index fc1075c..fdd8806 100644 --- a/ashen/src/asset/texture/dat/offset.rs +++ b/ashen/src/asset/texture/dat/offset.rs @@ -1,4 +1,4 @@ -use crate::{asset::AssetParser, utils::nom::*}; +use crate::{asset::Parser, utils::nom::*}; pub struct TextureOffset { pub width: u16, @@ -10,7 +10,7 @@ pub struct TextureOffset { pub next_animation_texture_id: u32, } -impl AssetParser for TextureOffset { +impl Parser for TextureOffset { type Context<'ctx> = (); type Output = Self; diff --git a/ashen/src/asset/texture/dat/texture.rs b/ashen/src/asset/texture/dat/texture.rs index 62479fc..bc12452 100644 --- a/ashen/src/asset/texture/dat/texture.rs +++ b/ashen/src/asset/texture/dat/texture.rs @@ -4,7 +4,7 @@ use super::size::TextureSize; use crate::{ asset::{ color_map::{Color, PaletteTexture}, - AssetParser, + Parser, }, utils::nom::*, }; @@ -15,7 +15,7 @@ pub struct Texture { pub colors: Vec>, } -impl AssetParser for Texture { +impl Parser for Texture { type Output = Self; type Context<'ctx> = TextureSize; @@ -51,7 +51,7 @@ pub struct MippedTexture { pub mips: [Texture; 4], } -impl AssetParser for MippedTexture { +impl Parser for MippedTexture { type Output = Self; type Context<'ctx> = TextureSize; diff --git a/ashen/src/asset/texture/mod.rs b/ashen/src/asset/texture/mod.rs index cd6a83a..d669250 100644 --- a/ashen/src/asset/texture/mod.rs +++ b/ashen/src/asset/texture/mod.rs @@ -3,7 +3,7 @@ mod dat; use dat::{offset::TextureOffset, texture::MippedTexture}; pub use dat::{size::TextureSize, texture::Texture}; -use super::AssetParser; +use super::Parser; use crate::utils::{compression::decompress, nom::*}; pub enum TextureMipKind { @@ -18,7 +18,7 @@ pub enum TextureAnimationKind { pub struct TextureOffsetCollection; -impl AssetParser for TextureOffsetCollection { +impl Parser for TextureOffsetCollection { type Output = Vec; type Context<'ctx> = (); @@ -34,7 +34,7 @@ impl AssetParser for TextureOffsetCollection { pub struct MippedTextureCollection; -impl AssetParser for MippedTextureCollection { +impl Parser for MippedTextureCollection { type Output = Vec; type Context<'ctx> = &'ctx [TextureOffset]; @@ -99,12 +99,12 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, color_map) = ::parser(())(&COLOR_MAP_DATA)?; + let (_, color_map) = ColorMap::parser(())(&COLOR_MAP_DATA)?; let color_map = &color_map.shades[15]; let (_, offsets) = - ::parser(())(&TEXTURE_INFO_DATA)?; + TextureOffsetCollection::parser(())(&TEXTURE_INFO_DATA)?; let (_, textures) = - ::parser(&offsets)(&TEXTURE_DATA)?; + MippedTextureCollection::parser(&offsets)(&TEXTURE_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("textures/")); From 92b9e1cb88f07259c4ac8fee69c7b73161917808 Mon Sep 17 00:00:00 2001 From: UserIsntAvailable Date: Mon, 14 Oct 2024 20:22:41 -0400 Subject: [PATCH 4/6] chore: remove dangling `loom` test. --- ashen/tests/loom.rs | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 ashen/tests/loom.rs diff --git a/ashen/tests/loom.rs b/ashen/tests/loom.rs deleted file mode 100644 index f3d31ae..0000000 --- a/ashen/tests/loom.rs +++ /dev/null @@ -1,3 +0,0 @@ -#[cfg(feature = "loom")] -#[cfg(test)] -mod loom_tests {} From b1175ae34dd8dcfc57aafe07b0e7e20699964dc4 Mon Sep 17 00:00:00 2001 From: UserIsntAvailable Date: Mon, 14 Oct 2024 20:35:22 -0400 Subject: [PATCH 5/6] chore: remove `Parser::Output`. chore: ingored. --- ashen/src/asset/color_map.rs | 8 ++------ ashen/src/asset/gamma_table.rs | 4 +--- ashen/src/asset/mod.rs | 11 +---------- ashen/src/asset/model/dat/frame.rs | 12 +++-------- ashen/src/asset/model/dat/header.rs | 4 +--- ashen/src/asset/model/dat/sequence.rs | 4 +--- ashen/src/asset/model/dat/triangle.rs | 8 ++------ ashen/src/asset/model/mod.rs | 4 +--- ashen/src/asset/pack_info.rs | 4 +--- ashen/src/asset/skybox.rs | 4 +--- ashen/src/asset/sound/dat/asset_header.rs | 4 +--- ashen/src/asset/sound/dat/chunk_header.rs | 4 +--- ashen/src/asset/sound/dat/pattern_effect.rs | 4 +--- ashen/src/asset/sound/dat/pattern_event.rs | 22 +++++---------------- ashen/src/asset/sound/dat/t_effect.rs | 8 ++------ ashen/src/asset/sound/dat/t_instrument.rs | 16 ++++----------- ashen/src/asset/sound/dat/t_song.rs | 12 +++-------- ashen/src/asset/sound/mod.rs | 15 +++----------- ashen/src/asset/string_table.rs | 4 +--- ashen/src/asset/texture/dat/offset.rs | 4 +--- ashen/src/asset/texture/dat/texture.rs | 8 ++------ ashen/src/asset/texture/mod.rs | 20 ++++++------------- ashen/src/utils/test.rs | 2 +- 23 files changed, 45 insertions(+), 141 deletions(-) diff --git a/ashen/src/asset/color_map.rs b/ashen/src/asset/color_map.rs index aa7dde6..857dbf1 100644 --- a/ashen/src/asset/color_map.rs +++ b/ashen/src/asset/color_map.rs @@ -36,11 +36,9 @@ impl Color { } impl Parser for Color { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, color) = number::le_u32(input)?; Ok((input, Self::from_12_bit(color as u16))) @@ -56,11 +54,9 @@ pub struct ColorMap { } impl Parser for ColorMap { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { error::ensure_bytes_length( input, diff --git a/ashen/src/asset/gamma_table.rs b/ashen/src/asset/gamma_table.rs index 7b22ab6..c393fd5 100644 --- a/ashen/src/asset/gamma_table.rs +++ b/ashen/src/asset/gamma_table.rs @@ -13,11 +13,9 @@ pub struct GammaTable { } impl Parser for GammaTable { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { error::ensure_bytes_length( input, diff --git a/ashen/src/asset/mod.rs b/ashen/src/asset/mod.rs index 3925edf..a35555d 100644 --- a/ashen/src/asset/mod.rs +++ b/ashen/src/asset/mod.rs @@ -14,18 +14,9 @@ pub trait Parser where Self: Sized, { - /// The final value that would be returned by [`parser`]. - /// - /// _Most_ of the time this would be equal to `Self`. - /// - /// A hypothetical `TextureCollection` would return `Vec` as its output. - /// - /// [`parser`]: Self::parser - type Output; - /// Extra information passed down to the parser. type Context<'ctx>; /// Generates a new parser with the provided context. - fn parser(context: Self::Context<'_>) -> impl Fn(Input) -> Result; + fn parser(context: Self::Context<'_>) -> impl Fn(Input) -> Result; } diff --git a/ashen/src/asset/model/dat/frame.rs b/ashen/src/asset/model/dat/frame.rs index bcc1e63..d0b3589 100644 --- a/ashen/src/asset/model/dat/frame.rs +++ b/ashen/src/asset/model/dat/frame.rs @@ -10,11 +10,9 @@ pub struct Vec3 { } impl Parser for Vec3 { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, x) = number::le_i16f16(input)?; let (input, y) = number::le_i16f16(input)?; @@ -50,11 +48,9 @@ pub struct VertexTransform { } impl Parser for ModelVertex { - type Output = Self; - type Context<'ctx> = VertexTransform; - fn parser(transform: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(transform: Self::Context<'_>) -> impl Fn(Input) -> Result { macro_rules! transform { ($coordinate: ident) => { (transform.scale.$coordinate * $coordinate as f32 / -256.0 @@ -95,11 +91,9 @@ pub struct ModelSpecs { } impl Parser for ModelFrame { - type Output = Self; - type Context<'ctx> = ModelSpecs; - fn parser(model_specs: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(model_specs: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, scale) = Vec3::parser(())(input)?; let (input, origin) = Vec3::parser(())(input)?; diff --git a/ashen/src/asset/model/dat/header.rs b/ashen/src/asset/model/dat/header.rs index 2395cc7..1d879dd 100644 --- a/ashen/src/asset/model/dat/header.rs +++ b/ashen/src/asset/model/dat/header.rs @@ -16,11 +16,9 @@ pub struct ModelHeader { } impl Parser for ModelHeader { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, triangle_count) = number::le_u32(input)?; let (input, vertex_count) = number::le_u32(input)?; diff --git a/ashen/src/asset/model/dat/sequence.rs b/ashen/src/asset/model/dat/sequence.rs index 8b1f1e0..927b37b 100644 --- a/ashen/src/asset/model/dat/sequence.rs +++ b/ashen/src/asset/model/dat/sequence.rs @@ -5,14 +5,12 @@ pub struct ModelSequence { } impl Parser for ModelSequence { - type Output = Self; - // TODO(nenikitov): Maybe refactor it to not accept full input. // In other asset parts, it's parent's responsability to cut input into slices // for asset parts to parse. type Context<'ctx> = Input<'ctx>; - fn parser(full_input: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(full_input: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, frame_count) = number::le_u32(input)?; let (input, offset) = number::le_u32(input)?; diff --git a/ashen/src/asset/model/dat/triangle.rs b/ashen/src/asset/model/dat/triangle.rs index f708f0a..ccc74b4 100644 --- a/ashen/src/asset/model/dat/triangle.rs +++ b/ashen/src/asset/model/dat/triangle.rs @@ -12,11 +12,9 @@ pub struct TextureDimensions { } impl Parser for ModelPoint { - type Output = Self; - type Context<'ctx> = &'ctx TextureDimensions; - fn parser(texture_dimensions: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(texture_dimensions: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, vertex_index) = number::le_u16(input)?; @@ -37,11 +35,9 @@ pub struct ModelTriangle { } impl Parser for ModelTriangle { - type Output = Self; - type Context<'ctx> = TextureDimensions; - fn parser(texture_dimensions: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(texture_dimensions: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, points) = multi::count!(ModelPoint::parser(&texture_dimensions))(input)?; diff --git a/ashen/src/asset/model/mod.rs b/ashen/src/asset/model/mod.rs index d63ed6b..796fbb6 100644 --- a/ashen/src/asset/model/mod.rs +++ b/ashen/src/asset/model/mod.rs @@ -21,11 +21,9 @@ pub struct Model { } impl Parser for Model { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (_, header) = ModelHeader::parser(())(input)?; diff --git a/ashen/src/asset/pack_info.rs b/ashen/src/asset/pack_info.rs index 805fa81..c91ea98 100644 --- a/ashen/src/asset/pack_info.rs +++ b/ashen/src/asset/pack_info.rs @@ -10,11 +10,9 @@ pub struct PackInfo { } impl Parser for PackInfo { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, offset) = number::le_u32(input)?; diff --git a/ashen/src/asset/skybox.rs b/ashen/src/asset/skybox.rs index 0e1f451..184b4d8 100644 --- a/ashen/src/asset/skybox.rs +++ b/ashen/src/asset/skybox.rs @@ -12,11 +12,9 @@ pub struct Skybox { } impl Parser for Skybox { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, width) = number::le_u32(input)?; diff --git a/ashen/src/asset/sound/dat/asset_header.rs b/ashen/src/asset/sound/dat/asset_header.rs index 9a1b1fe..5e25931 100644 --- a/ashen/src/asset/sound/dat/asset_header.rs +++ b/ashen/src/asset/sound/dat/asset_header.rs @@ -15,11 +15,9 @@ impl SoundAssetHeader { } impl Parser for SoundAssetHeader { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, _) = bytes::tag(Self::HEADER)(input)?; diff --git a/ashen/src/asset/sound/dat/chunk_header.rs b/ashen/src/asset/sound/dat/chunk_header.rs index c964d67..8f558db 100644 --- a/ashen/src/asset/sound/dat/chunk_header.rs +++ b/ashen/src/asset/sound/dat/chunk_header.rs @@ -8,11 +8,9 @@ pub struct SoundChunkHeader { } impl Parser for SoundChunkHeader { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, count) = number::le_u32(input)?; let (input, infos) = multi::count!(PackInfo::parser(()), count as usize)(input)?; diff --git a/ashen/src/asset/sound/dat/pattern_effect.rs b/ashen/src/asset/sound/dat/pattern_effect.rs index b036aa2..3b90fcf 100644 --- a/ashen/src/asset/sound/dat/pattern_effect.rs +++ b/ashen/src/asset/sound/dat/pattern_effect.rs @@ -128,11 +128,9 @@ impl PatternEffect { } impl Parser for Option { - type Output = Self; - type Context<'ctx> = bool; - fn parser(should_parse: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(should_parse: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { use PatternEffect as E; diff --git a/ashen/src/asset/sound/dat/pattern_event.rs b/ashen/src/asset/sound/dat/pattern_event.rs index 991622b..9ee7a15 100644 --- a/ashen/src/asset/sound/dat/pattern_event.rs +++ b/ashen/src/asset/sound/dat/pattern_event.rs @@ -13,11 +13,9 @@ pub enum PatternEventNote { } impl Parser for Option { - type Output = Self; - type Context<'ctx> = bool; - fn parser(should_parse: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(should_parse: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, note) = number::le_u8(input)?; @@ -49,11 +47,9 @@ bitflags! { } impl Parser for PatternEventFlags { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, flags) = number::le_u8(input)?; @@ -69,13 +65,9 @@ impl Parser for PatternEventFlags { } impl Parser for Option { - type Output = Self; - type Context<'ctx> = (bool, &'ctx [Rc]); - fn parser( - (should_parse, instruments): Self::Context<'_>, - ) -> impl Fn(Input) -> Result { + fn parser((should_parse, instruments): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, instrument) = number::le_u8(input)?; @@ -103,11 +95,9 @@ impl Default for PatternEventVolume { } impl Parser for Option { - type Output = Self; - type Context<'ctx> = bool; - fn parser(should_parse: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(should_parse: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, volume) = number::le_u8(input)?; @@ -150,11 +140,9 @@ impl PatternEvent { } impl Parser for PatternEvent { - type Output = Self; - type Context<'ctx> = &'ctx [Rc]; - fn parser(instruments: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(instruments: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, flags) = PatternEventFlags::parser(())(input)?; diff --git a/ashen/src/asset/sound/dat/t_effect.rs b/ashen/src/asset/sound/dat/t_effect.rs index df24438..57632da 100644 --- a/ashen/src/asset/sound/dat/t_effect.rs +++ b/ashen/src/asset/sound/dat/t_effect.rs @@ -21,11 +21,9 @@ impl TEffect { } impl Parser for TEffect { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (_, pointers) = TEffectPointers::parser(())(input)?; @@ -51,11 +49,9 @@ struct TEffectPointers { } impl Parser for TEffectPointers { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, instrument) = number::le_u32(input)?; let (input, sample) = number::le_u32(input)?; diff --git a/ashen/src/asset/sound/dat/t_instrument.rs b/ashen/src/asset/sound/dat/t_instrument.rs index 192419c..78eecf4 100644 --- a/ashen/src/asset/sound/dat/t_instrument.rs +++ b/ashen/src/asset/sound/dat/t_instrument.rs @@ -17,11 +17,9 @@ bitflags! { } impl Parser for TInstrumentFlags { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, flags) = number::le_u8(input)?; @@ -69,11 +67,9 @@ impl TInstrumentVolumeEnvelope { } impl Parser for Option { - type Output = Self; - type Context<'ctx> = bool; - fn parser(has_envelope: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(has_envelope: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, begin) = number::le_u16(input)?; let (input, end) = number::le_u16(input)?; @@ -130,11 +126,9 @@ impl TInstrument { } impl Parser for TInstrument { - type Output = Self; - type Context<'ctx> = &'ctx [Rc]; - fn parser(samples: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(samples: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, flags) = TInstrumentFlags::parser(())(input)?; @@ -215,11 +209,9 @@ pub struct TSample { } impl Parser for TSample { - type Output = Self; - type Context<'ctx> = &'ctx [i16]; - fn parser(sample_data: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(sample_data: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, flags) = number::le_u8(input)?; let (input, volume) = number::le_u8(input)?; diff --git a/ashen/src/asset/sound/dat/t_song.rs b/ashen/src/asset/sound/dat/t_song.rs index a055294..15aa091 100644 --- a/ashen/src/asset/sound/dat/t_song.rs +++ b/ashen/src/asset/sound/dat/t_song.rs @@ -91,11 +91,9 @@ impl std::fmt::Debug for TSong { } impl Parser for TSong { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (header, pointers) = { let (input, header) = TSongHeader::parser(())(input)?; @@ -186,11 +184,9 @@ struct TSongHeader { } impl Parser for TSongHeader { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, song_length) = number::le_u8(input)?; let (input, restart_order) = number::le_u8(input)?; @@ -230,11 +226,9 @@ struct TSongPointers { } impl Parser for TSongPointers { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, orders) = number::le_u32(input)?; let (input, patterns) = number::le_u32(input)?; diff --git a/ashen/src/asset/sound/mod.rs b/ashen/src/asset/sound/mod.rs index 3202cf8..6988f8e 100644 --- a/ashen/src/asset/sound/mod.rs +++ b/ashen/src/asset/sound/mod.rs @@ -25,19 +25,10 @@ impl Sound { } } -pub struct SoundCollection; - -impl SoundCollection { - pub const SAMPLE_RATE: usize = 16000; - pub const CHANNEL_COUNT: usize = 1; -} - -impl Parser for SoundCollection { - type Output = Vec; - +impl Parser for Vec { type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (_, header) = SoundAssetHeader::parser(())(input)?; @@ -78,7 +69,7 @@ mod tests { #[test] #[ignore = "uses Ashen ROM files"] fn parse_rom_asset() -> eyre::Result<()> { - let (_, sounds) = SoundCollection::parser(())(&SOUND_DATA)?; + let (_, sounds) = Vec::::parser(())(&SOUND_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("sounds/songs/")); diff --git a/ashen/src/asset/string_table.rs b/ashen/src/asset/string_table.rs index b5f3a03..9121cde 100644 --- a/ashen/src/asset/string_table.rs +++ b/ashen/src/asset/string_table.rs @@ -15,11 +15,9 @@ fn utf_16_string(input: &[u8]) -> Result { } impl Parser for StringTable { - type Output = Self; - type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, count) = number::le_u32(input)?; // TODO(Unavailable): Find out what the "catholic" characters are. diff --git a/ashen/src/asset/texture/dat/offset.rs b/ashen/src/asset/texture/dat/offset.rs index fdd8806..f21c466 100644 --- a/ashen/src/asset/texture/dat/offset.rs +++ b/ashen/src/asset/texture/dat/offset.rs @@ -13,9 +13,7 @@ pub struct TextureOffset { impl Parser for TextureOffset { type Context<'ctx> = (); - type Output = Self; - - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, width) = number::le_u16(input)?; let (input, height) = number::le_u16(input)?; diff --git a/ashen/src/asset/texture/dat/texture.rs b/ashen/src/asset/texture/dat/texture.rs index bc12452..89643bb 100644 --- a/ashen/src/asset/texture/dat/texture.rs +++ b/ashen/src/asset/texture/dat/texture.rs @@ -16,11 +16,9 @@ pub struct Texture { } impl Parser for Texture { - type Output = Self; - type Context<'ctx> = TextureSize; - fn parser(size: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(size: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, colors) = multi::count!(number::le_u8, size.width * size.height)(input)?; @@ -52,11 +50,9 @@ pub struct MippedTexture { } impl Parser for MippedTexture { - type Output = Self; - type Context<'ctx> = TextureSize; - fn parser(size: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(size: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (input, mip_1) = Texture::parser(size)(input)?; let (input, mip_2) = Texture::parser(size / 2)(input)?; diff --git a/ashen/src/asset/texture/mod.rs b/ashen/src/asset/texture/mod.rs index d669250..d16e425 100644 --- a/ashen/src/asset/texture/mod.rs +++ b/ashen/src/asset/texture/mod.rs @@ -16,14 +16,10 @@ pub enum TextureAnimationKind { Animated(Vec), } -pub struct TextureOffsetCollection; - -impl Parser for TextureOffsetCollection { - type Output = Vec; - +impl Parser for Vec { type Context<'ctx> = (); - fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser((): Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let (_, offsets) = multi::many0(TextureOffset::parser(()))(input)?; @@ -32,14 +28,10 @@ impl Parser for TextureOffsetCollection { } } -pub struct MippedTextureCollection; - -impl Parser for MippedTextureCollection { - type Output = Vec; - +impl Parser for Vec { type Context<'ctx> = &'ctx [TextureOffset]; - fn parser(offsets: Self::Context<'_>) -> impl Fn(Input) -> Result { + fn parser(offsets: Self::Context<'_>) -> impl Fn(Input) -> Result { move |input| { let textures = offsets .iter() @@ -102,9 +94,9 @@ mod tests { let (_, color_map) = ColorMap::parser(())(&COLOR_MAP_DATA)?; let color_map = &color_map.shades[15]; let (_, offsets) = - TextureOffsetCollection::parser(())(&TEXTURE_INFO_DATA)?; + Vec::::parser(())(&TEXTURE_INFO_DATA)?; let (_, textures) = - MippedTextureCollection::parser(&offsets)(&TEXTURE_DATA)?; + Vec::::parser(&offsets)(&TEXTURE_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("textures/")); diff --git a/ashen/src/utils/test.rs b/ashen/src/utils/test.rs index 29de739..aeb5079 100644 --- a/ashen/src/utils/test.rs +++ b/ashen/src/utils/test.rs @@ -24,7 +24,7 @@ macro_rules! deflated_file { DEFLATED_PATH, $file ))) - .expect("deflated test ran.\nRun `cargo test -- --ingored parse_rom_packfile` before") + .expect("deflated test ran.\nRun `cargo test -- --ignored parse_rom_packfile` before.") }) }; } From db5f6bb7abce0c1794a50deaa039fd5e43b1ffda Mon Sep 17 00:00:00 2001 From: UserIsntAvailable Date: Mon, 14 Oct 2024 20:39:08 -0400 Subject: [PATCH 6/6] chore: make `rustfmt` happy. --- ashen/src/asset/texture/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ashen/src/asset/texture/mod.rs b/ashen/src/asset/texture/mod.rs index d16e425..c0638a7 100644 --- a/ashen/src/asset/texture/mod.rs +++ b/ashen/src/asset/texture/mod.rs @@ -93,10 +93,8 @@ mod tests { fn parse_rom_asset() -> eyre::Result<()> { let (_, color_map) = ColorMap::parser(())(&COLOR_MAP_DATA)?; let color_map = &color_map.shades[15]; - let (_, offsets) = - Vec::::parser(())(&TEXTURE_INFO_DATA)?; - let (_, textures) = - Vec::::parser(&offsets)(&TEXTURE_DATA)?; + let (_, offsets) = Vec::::parser(())(&TEXTURE_INFO_DATA)?; + let (_, textures) = Vec::::parser(&offsets)(&TEXTURE_DATA)?; let output_dir = PathBuf::from(parsed_file_path!("textures/"));