mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
serde entity parsing
This commit is contained in:
parent
84a66e06a3
commit
f6e2a200ca
14 changed files with 682 additions and 1088 deletions
208
Cargo.lock
generated
208
Cargo.lock
generated
|
|
@ -15,6 +15,15 @@ dependencies = [
|
||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "approx"
|
name = "approx"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
|
@ -42,6 +51,12 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "beef"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "binrw"
|
name = "binrw"
|
||||||
version = "0.13.1"
|
version = "0.13.1"
|
||||||
|
|
@ -166,6 +181,12 @@ version = "0.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da"
|
checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fnv"
|
||||||
|
version = "1.0.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
|
|
@ -208,6 +229,38 @@ version = "0.2.150"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "logos"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1"
|
||||||
|
dependencies = [
|
||||||
|
"logos-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "logos-codegen"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68"
|
||||||
|
dependencies = [
|
||||||
|
"beef",
|
||||||
|
"fnv",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"regex-syntax 0.6.29",
|
||||||
|
"syn 2.0.39",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "logos-derive"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dbfc0d229f1f42d790440136d941afd806bc9e949e2bcb8faa813b0f00d1267e"
|
||||||
|
dependencies = [
|
||||||
|
"logos-codegen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lzma"
|
name = "lzma"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
|
@ -240,25 +293,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "merge"
|
name = "miette"
|
||||||
version = "0.1.0"
|
version = "5.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "10bbef93abb1da61525bbc45eeaff6473a41907d19f8f9aa5168d214e10693e9"
|
checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"merge_derive",
|
"miette-derive",
|
||||||
"num-traits",
|
"once_cell",
|
||||||
|
"thiserror",
|
||||||
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "merge_derive"
|
name = "miette-derive"
|
||||||
version = "0.1.0"
|
version = "5.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "209d075476da2e63b4b29e72a2ef627b840589588e71400a25e3565c4f849d07"
|
checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-error",
|
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 2.0.39",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -309,6 +363,32 @@ version = "3.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parse-display"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c6509d08722b53e8dafe97f2027b22ccbe3a5db83cb352931e9716b0aa44bc5c"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"parse-display-derive",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parse-display-derive"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68517892c8daf78da08c0db777fcc17e07f2f63ef70041718f8a7630ad84f341"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"regex",
|
||||||
|
"regex-syntax 0.7.5",
|
||||||
|
"structmeta",
|
||||||
|
"syn 2.0.39",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-crate"
|
name = "proc-macro-crate"
|
||||||
version = "1.3.1"
|
version = "1.3.1"
|
||||||
|
|
@ -319,30 +399,6 @@ dependencies = [
|
||||||
"toml_edit",
|
"toml_edit",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error-attr",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error-attr"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.69"
|
version = "1.0.69"
|
||||||
|
|
@ -361,6 +417,67 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[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",
|
||||||
|
"regex-syntax 0.8.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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.7.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.193"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.193"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.39",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "static_assertions"
|
name = "static_assertions"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
|
@ -455,6 +572,12 @@ version = "1.0.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.1.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vbsp"
|
name = "vbsp"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
|
@ -470,21 +593,24 @@ dependencies = [
|
||||||
"main_error",
|
"main_error",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
"obj",
|
"obj",
|
||||||
|
"serde",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"vbsp-derive",
|
"vdf-reader",
|
||||||
"zip-lzma",
|
"zip-lzma",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vbsp-derive"
|
name = "vdf-reader"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bff9669f8e9cf7a82acac623509d7dbd119b4bc90da2469f1e7501097e04c5a3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"merge",
|
"logos",
|
||||||
"proc-macro2",
|
"miette",
|
||||||
"quote",
|
"parse-display",
|
||||||
"structmeta",
|
"serde",
|
||||||
"syn 2.0.39",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,12 @@ lzma-rs = "0.3.0"
|
||||||
binrw = "0.13.1"
|
binrw = "0.13.1"
|
||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
num_enum = "0.7.1"
|
num_enum = "0.7.1"
|
||||||
vbsp-derive = { path = "derive", version = "0.1.0", features = ["__vbsp_as_self"], optional = true }
|
|
||||||
cgmath = "0.18.0"
|
cgmath = "0.18.0"
|
||||||
zip = { package = "zip-lzma", version = "0.6.3", default-features = false, features = ["lzma"] }
|
zip = { package = "zip-lzma", version = "0.6.3", default-features = false, features = ["lzma"] }
|
||||||
itertools = "0.12.0"
|
itertools = "0.12.0"
|
||||||
ahash = "0.8.6"
|
ahash = "0.8.6"
|
||||||
|
serde = "1.0.193"
|
||||||
|
vdf-reader = "0.1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
obj = "0.10"
|
obj = "0.10"
|
||||||
|
|
@ -34,6 +35,4 @@ main_error = "0.1.2"
|
||||||
opt-level = 2
|
opt-level = 2
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["typed_entities"]
|
|
||||||
typed_entities = ["vbsp-derive"]
|
|
||||||
bench = []
|
bench = []
|
||||||
|
|
|
||||||
453
derive/Cargo.lock
generated
453
derive/Cargo.lock
generated
|
|
@ -1,453 +0,0 @@
|
||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 3
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "approx"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "array-init"
|
|
||||||
version = "2.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "arrayvec"
|
|
||||||
version = "0.7.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "autocfg"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "binrw"
|
|
||||||
version = "0.13.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5a1b8720bedc0a503fd5c90bef3fbdc397144ac7efcc5610b30bde08083d7495"
|
|
||||||
dependencies = [
|
|
||||||
"array-init",
|
|
||||||
"binrw_derive",
|
|
||||||
"bytemuck",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "binrw_derive"
|
|
||||||
version = "0.13.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0741a1b1a70a36a1e7fb0316bba0828f6487a3b6e577353cf974b59fbbb92081"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
"owo-colors",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "2.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bv"
|
|
||||||
version = "0.11.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8834bb1d8ee5dc048ee3124f2c7c1afcc6bc9aed03f11e9dfd8c69470a5db340"
|
|
||||||
dependencies = [
|
|
||||||
"feature-probe",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bytemuck"
|
|
||||||
version = "1.14.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "byteorder"
|
|
||||||
version = "0.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "byteorder"
|
|
||||||
version = "1.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cgmath"
|
|
||||||
version = "0.18.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317"
|
|
||||||
dependencies = [
|
|
||||||
"approx",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crc"
|
|
||||||
version = "3.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe"
|
|
||||||
dependencies = [
|
|
||||||
"crc-catalog",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crc-catalog"
|
|
||||||
version = "2.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crc32fast"
|
|
||||||
version = "1.3.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-utils"
|
|
||||||
version = "0.8.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "either"
|
|
||||||
version = "1.9.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "equivalent"
|
|
||||||
version = "1.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "feature-probe"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hashbrown"
|
|
||||||
version = "0.14.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "indexmap"
|
|
||||||
version = "2.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
|
|
||||||
dependencies = [
|
|
||||||
"equivalent",
|
|
||||||
"hashbrown",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lzma"
|
|
||||||
version = "0.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "782ba3f542e8bc1349386c15e9dc3119ae6da96479f96b3863cc7a88bbdfd4e4"
|
|
||||||
dependencies = [
|
|
||||||
"byteorder 0.5.3",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lzma-rs"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e"
|
|
||||||
dependencies = [
|
|
||||||
"byteorder 1.5.0",
|
|
||||||
"crc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memchr"
|
|
||||||
version = "2.6.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "merge"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "10bbef93abb1da61525bbc45eeaff6473a41907d19f8f9aa5168d214e10693e9"
|
|
||||||
dependencies = [
|
|
||||||
"merge_derive",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "merge_derive"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "209d075476da2e63b4b29e72a2ef627b840589588e71400a25e3565c4f849d07"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-traits"
|
|
||||||
version = "0.2.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num_enum"
|
|
||||||
version = "0.7.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "683751d591e6d81200c39fb0d1032608b77724f34114db54f571ff1317b337c0"
|
|
||||||
dependencies = [
|
|
||||||
"num_enum_derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num_enum_derive"
|
|
||||||
version = "0.7.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6c11e44798ad209ccdd91fc192f0526a369a01234f7373e1b141c96d7cee4f0e"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-crate",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.39",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "owo-colors"
|
|
||||||
version = "3.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-crate"
|
|
||||||
version = "2.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8"
|
|
||||||
dependencies = [
|
|
||||||
"toml_edit",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error-attr",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error-attr"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.69"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.33"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "static_assertions"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "structmeta"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "78ad9e09554f0456d67a69c1584c9798ba733a5b50349a6c0d0948710523922d"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"structmeta-derive",
|
|
||||||
"syn 2.0.39",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "structmeta-derive"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a60bcaff7397072dca0017d1db428e30d5002e00b6847703e2e42005c95fbe00"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.39",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.109"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "2.0.39"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thiserror"
|
|
||||||
version = "1.0.50"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
|
|
||||||
dependencies = [
|
|
||||||
"thiserror-impl",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thiserror-impl"
|
|
||||||
version = "1.0.50"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.39",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml_datetime"
|
|
||||||
version = "0.6.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml_edit"
|
|
||||||
version = "0.20.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81"
|
|
||||||
dependencies = [
|
|
||||||
"indexmap",
|
|
||||||
"toml_datetime",
|
|
||||||
"winnow",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-ident"
|
|
||||||
version = "1.0.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "vbsp"
|
|
||||||
version = "0.2.0"
|
|
||||||
dependencies = [
|
|
||||||
"arrayvec",
|
|
||||||
"binrw",
|
|
||||||
"bitflags",
|
|
||||||
"bv",
|
|
||||||
"cgmath",
|
|
||||||
"lzma-rs",
|
|
||||||
"num_enum",
|
|
||||||
"static_assertions",
|
|
||||||
"thiserror",
|
|
||||||
"zip-lzma",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "vbsp-derive"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"merge",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"structmeta",
|
|
||||||
"syn 2.0.39",
|
|
||||||
"vbsp",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "version_check"
|
|
||||||
version = "0.9.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winnow"
|
|
||||||
version = "0.5.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zip-lzma"
|
|
||||||
version = "0.6.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b480cb31fccfb2786565c0e0712865fd6f1ea0ea850c50316f643c3948196e63"
|
|
||||||
dependencies = [
|
|
||||||
"byteorder 1.5.0",
|
|
||||||
"crc32fast",
|
|
||||||
"crossbeam-utils",
|
|
||||||
"lzma",
|
|
||||||
]
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "vbsp-derive"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
|
||||||
homepage = "https://github.com/icewind1991/vbsp"
|
|
||||||
repository = "https://github.com/icewind1991/vbsp"
|
|
||||||
description = "Derive macros used by vbsp."
|
|
||||||
license = "MIT"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
proc-macro = true
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
syn = "2.0.39"
|
|
||||||
quote = "1.0.33"
|
|
||||||
proc-macro2 = "1.0.69"
|
|
||||||
structmeta = "0.2.0"
|
|
||||||
merge = "0.1.0"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
vbsp = { version = "0.2.0", path = "..", default-features = false }
|
|
||||||
|
|
||||||
[features]
|
|
||||||
__vbsp_as_self = []
|
|
||||||
|
|
@ -1,249 +0,0 @@
|
||||||
use crate::parse_attrs;
|
|
||||||
use merge::Merge;
|
|
||||||
use proc_macro2::TokenStream;
|
|
||||||
use quote::{quote, quote_spanned, ToTokens, TokenStreamExt};
|
|
||||||
use structmeta::StructMeta;
|
|
||||||
use syn::spanned::Spanned;
|
|
||||||
use syn::{
|
|
||||||
Data, DataEnum, DataStruct, DeriveInput, Error, Field, GenericParam, Ident, LitStr, Path,
|
|
||||||
PathArguments, PathSegment, Result, Type, TypePath, Variant,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn derive_entity(input: DeriveInput) -> Result<proc_macro2::TokenStream> {
|
|
||||||
if input.generics.lifetimes().count() > 1 {
|
|
||||||
return Err(Error::new(
|
|
||||||
input.generics.span(),
|
|
||||||
"Can't derive Entity on structs or entities with more than 1 lifetime",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
let source_lifetime = input
|
|
||||||
.generics
|
|
||||||
.params
|
|
||||||
.iter()
|
|
||||||
.find(|param| matches!(param, GenericParam::Lifetime(_)));
|
|
||||||
|
|
||||||
#[cfg(feature = "__vbsp_as_self")]
|
|
||||||
let crate_name = "crate";
|
|
||||||
#[cfg(not(feature = "__vbsp_as_self"))]
|
|
||||||
let crate_name = "vbsp";
|
|
||||||
let crate_ident = Ident::new(crate_name, input.span());
|
|
||||||
|
|
||||||
match &input.data {
|
|
||||||
Data::Struct(data) => derive_entity_struct(&input, data, source_lifetime, crate_ident),
|
|
||||||
Data::Enum(data) => derive_entity_enum(&input, data, source_lifetime, crate_ident),
|
|
||||||
_ => Err(Error::new(
|
|
||||||
input.span(),
|
|
||||||
"Can only derive Entity for structs and enums",
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn derive_entity_enum(
|
|
||||||
input: &DeriveInput,
|
|
||||||
data: &DataEnum,
|
|
||||||
source_lifetime: Option<&GenericParam>,
|
|
||||||
crate_ident: Ident,
|
|
||||||
) -> Result<proc_macro2::TokenStream> {
|
|
||||||
let variants = data
|
|
||||||
.variants
|
|
||||||
.iter()
|
|
||||||
.map(EntityVariant::try_from)
|
|
||||||
.collect::<Result<Vec<EntityVariant>>>()?;
|
|
||||||
|
|
||||||
if variants
|
|
||||||
.iter()
|
|
||||||
.filter(|variant| variant.is_default())
|
|
||||||
.count()
|
|
||||||
!= 1
|
|
||||||
{
|
|
||||||
return Err(Error::new(
|
|
||||||
data.variants.span(),
|
|
||||||
"Enums must have exactly one variant with `#[entity(default)]` set",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
|
||||||
let name = &input.ident;
|
|
||||||
let lifetime_or_default = LifetimeOrAnonymous(source_lifetime);
|
|
||||||
|
|
||||||
let span = input.span();
|
|
||||||
|
|
||||||
Ok(quote_spanned! {span =>
|
|
||||||
impl #impl_generics TryFrom<#crate_ident::RawEntity<#lifetime_or_default>> for #name #ty_generics #where_clause {
|
|
||||||
type Error = #crate_ident::error::EntityParseError;
|
|
||||||
|
|
||||||
fn try_from(raw: #crate_ident::RawEntity<#source_lifetime>) -> Result<Self, Self::Error> {
|
|
||||||
let class = raw.prop("classname")?;
|
|
||||||
Ok(match class {
|
|
||||||
#(#variants)*
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn derive_entity_struct(
|
|
||||||
input: &DeriveInput,
|
|
||||||
data: &DataStruct,
|
|
||||||
source_lifetime: Option<&GenericParam>,
|
|
||||||
crate_ident: Ident,
|
|
||||||
) -> Result<proc_macro2::TokenStream> {
|
|
||||||
let fields = data
|
|
||||||
.fields
|
|
||||||
.iter()
|
|
||||||
.map(EntityField::try_from)
|
|
||||||
.collect::<Result<Vec<_>>>()?;
|
|
||||||
|
|
||||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
|
||||||
let name = &input.ident;
|
|
||||||
let lifetime_or_default = LifetimeOrAnonymous(source_lifetime);
|
|
||||||
|
|
||||||
Ok(quote! {
|
|
||||||
impl #impl_generics TryFrom<#crate_ident::RawEntity<#lifetime_or_default>> for #name #ty_generics #where_clause {
|
|
||||||
type Error = #crate_ident::error::EntityParseError;
|
|
||||||
|
|
||||||
fn try_from(raw: #crate_ident::RawEntity<#source_lifetime>) -> Result<Self, Self::Error> {
|
|
||||||
Ok(#name {
|
|
||||||
#(#fields)*
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
struct LifetimeOrAnonymous<'a>(Option<&'a GenericParam>);
|
|
||||||
|
|
||||||
impl ToTokens for LifetimeOrAnonymous<'_> {
|
|
||||||
fn to_tokens(&self, stream: &mut TokenStream) {
|
|
||||||
match &self.0 {
|
|
||||||
Some(params) => params.to_tokens(stream),
|
|
||||||
None => stream.append_all(quote! {'_}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, StructMeta, Merge)]
|
|
||||||
struct EntityFieldAttrs {
|
|
||||||
name: Option<LitStr>,
|
|
||||||
#[merge(strategy = merge::bool::overwrite_false)]
|
|
||||||
default: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EntityFieldAttrs {
|
|
||||||
pub fn name(&self) -> Option<String> {
|
|
||||||
self.name.as_ref().map(LitStr::value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct EntityField<'a> {
|
|
||||||
field: &'a Ident,
|
|
||||||
name: String,
|
|
||||||
default: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> TryFrom<&'a Field> for EntityField<'a> {
|
|
||||||
type Error = syn::Error;
|
|
||||||
|
|
||||||
fn try_from(field: &'a Field) -> Result<Self> {
|
|
||||||
let attrs: EntityFieldAttrs = parse_attrs(&field.attrs)?;
|
|
||||||
let ident = &field.ident.as_ref().ok_or(Error::new(
|
|
||||||
field.span(),
|
|
||||||
"Can't derive Entity on structs with unnamed fields",
|
|
||||||
))?;
|
|
||||||
let name = attrs.name().unwrap_or_else(|| ident.to_string());
|
|
||||||
Ok(EntityField {
|
|
||||||
field: ident,
|
|
||||||
name,
|
|
||||||
default: attrs.default,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToTokens for EntityField<'_> {
|
|
||||||
fn to_tokens(&self, stream: &mut TokenStream) {
|
|
||||||
let EntityField { field, name, .. } = &self;
|
|
||||||
let tokens = if self.default {
|
|
||||||
quote! {#field: raw.prop_parse(#name).unwrap_or_default(),}
|
|
||||||
} else {
|
|
||||||
quote! {#field: raw.prop_parse(#name)?,}
|
|
||||||
};
|
|
||||||
stream.append_all(tokens);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct EntityVariant<'a> {
|
|
||||||
name: NameOrDefault,
|
|
||||||
variant: &'a Ident,
|
|
||||||
ty: &'a Path,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EntityVariant<'_> {
|
|
||||||
fn is_default(&self) -> bool {
|
|
||||||
matches!(self.name, NameOrDefault::Default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum NameOrDefault {
|
|
||||||
Name(String),
|
|
||||||
Default,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> TryFrom<&'a Variant> for EntityVariant<'a> {
|
|
||||||
type Error = syn::Error;
|
|
||||||
|
|
||||||
fn try_from(value: &'a Variant) -> Result<Self> {
|
|
||||||
let attrs: EntityFieldAttrs = parse_attrs(&value.attrs)?;
|
|
||||||
let name = match attrs.default {
|
|
||||||
true => NameOrDefault::Default,
|
|
||||||
false => NameOrDefault::Name(attrs.name().ok_or_else(||Error::new(value.span(), "All variants must have the `#[entity(name)]` or `#[entity(default)]` attribute set"),) ?)
|
|
||||||
};
|
|
||||||
if value.fields.len() != 1 {
|
|
||||||
return Err(Error::new(
|
|
||||||
value.span(),
|
|
||||||
"All enum variants must have exactly one field",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
let field = value.fields.iter().next().unwrap();
|
|
||||||
let path = match &field.ty {
|
|
||||||
Type::Path(TypePath { path, .. }) => path,
|
|
||||||
_ => {
|
|
||||||
return Err(Error::new(
|
|
||||||
field.span(),
|
|
||||||
"Variants can only contain plain types",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(EntityVariant {
|
|
||||||
name,
|
|
||||||
variant: &value.ident,
|
|
||||||
ty: path,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToTokens for EntityVariant<'_> {
|
|
||||||
fn to_tokens(&self, stream: &mut TokenStream) {
|
|
||||||
let EntityVariant { name, variant, ty } = &self;
|
|
||||||
|
|
||||||
// strip generic/lifetime params
|
|
||||||
let ty = Path {
|
|
||||||
leading_colon: ty.leading_colon,
|
|
||||||
segments: ty
|
|
||||||
.segments
|
|
||||||
.iter()
|
|
||||||
.map(|segment| PathSegment {
|
|
||||||
ident: segment.ident.clone(),
|
|
||||||
arguments: PathArguments::None,
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
};
|
|
||||||
match name {
|
|
||||||
NameOrDefault::Default => {
|
|
||||||
stream.append_all(quote! {_ => Self::#variant(#ty::from(raw)),})
|
|
||||||
}
|
|
||||||
NameOrDefault::Name(name) => {
|
|
||||||
stream.append_all(quote! {#name => Self::#variant(#ty::try_from(raw)?),})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
use merge::Merge;
|
|
||||||
use syn::parse::Parse;
|
|
||||||
use syn::{parse_macro_input, Attribute, DeriveInput, Result};
|
|
||||||
|
|
||||||
mod entity;
|
|
||||||
|
|
||||||
#[proc_macro_derive(Entity, attributes(entity))]
|
|
||||||
pub fn derive_entity(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
|
||||||
derive_wrapper(input, entity::derive_entity)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn derive_wrapper<F: Fn(DeriveInput) -> Result<proc_macro2::TokenStream>>(
|
|
||||||
input: proc_macro::TokenStream,
|
|
||||||
derive: F,
|
|
||||||
) -> proc_macro::TokenStream {
|
|
||||||
match derive(parse_macro_input!(input as DeriveInput)) {
|
|
||||||
Ok(tokens) => tokens.into(),
|
|
||||||
Err(e) => e.into_compile_error().into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_attrs<T: Parse + Default + Merge>(attrs: &[Attribute]) -> Result<T> {
|
|
||||||
let mut result = T::default();
|
|
||||||
for attr in attrs {
|
|
||||||
let parsed = attr.parse_args()?;
|
|
||||||
result.merge(parsed);
|
|
||||||
}
|
|
||||||
Ok(result)
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
use vbsp::RawEntity;
|
|
||||||
use vbsp_derive::Entity;
|
|
||||||
|
|
||||||
#[derive(Entity)]
|
|
||||||
pub struct SpotLight {
|
|
||||||
pub angles: [f32; 3],
|
|
||||||
#[entity(name = "render_color")]
|
|
||||||
pub color: [u8; 3],
|
|
||||||
pub cone: u8,
|
|
||||||
#[entity(default)]
|
|
||||||
pub optional: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Entity)]
|
|
||||||
pub struct Lifetime<'a> {
|
|
||||||
pub model: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Entity)]
|
|
||||||
pub enum Entity<'a> {
|
|
||||||
// #[entity(name = "spot")]
|
|
||||||
// SpotLight(SpotLight),
|
|
||||||
#[entity(name = "bar")]
|
|
||||||
Foo(Lifetime<'a>),
|
|
||||||
#[entity(default)]
|
|
||||||
Unknown(RawEntity<'a>),
|
|
||||||
}
|
|
||||||
|
|
@ -6,21 +6,25 @@ fn main() -> Result<(), vbsp::BspError> {
|
||||||
let _ = args.next();
|
let _ = args.next();
|
||||||
let data = std::fs::read(args.next().expect("No demo file provided"))?;
|
let data = std::fs::read(args.next().expect("No demo file provided"))?;
|
||||||
let bsp = vbsp::Bsp::read(&data)?;
|
let bsp = vbsp::Bsp::read(&data)?;
|
||||||
// for prop in bsp.entities.iter() {
|
for prop in bsp.entities.iter() {
|
||||||
// match prop.parse() {
|
match prop.parse() {
|
||||||
// Ok(prop) => println!("{:#?}", prop),
|
Ok(prop) => {
|
||||||
// Err(e) => println!("Failed parsing {:#?}: {:#}", prop, e),
|
println!("{:#?}", prop)
|
||||||
// }
|
}
|
||||||
// }
|
Err(e) => {
|
||||||
|
println!("Failed parsing {}: {:#}", prop.as_str(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// for prop in bsp.static_props() {
|
// for prop in bsp.static_props() {
|
||||||
// dbg!(prop.deref());
|
// dbg!(prop.deref());
|
||||||
// dbg!(prop.model());
|
// dbg!(prop.model());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
for tex in bsp.textures() {
|
// for tex in bsp.textures() {
|
||||||
println!("{}", tex.name());
|
// println!("{}", tex.name());
|
||||||
}
|
// }
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::error::UnsupportedLumpVersion;
|
use crate::error::UnsupportedLumpVersion;
|
||||||
use crate::{lzma_decompress_with_header, BspError, FixedString, Vector};
|
use crate::{lzma_decompress_with_header, Angles, BspError, FixedString, Vector};
|
||||||
use binrw::{BinRead, BinReaderExt, BinResult, Endian};
|
use binrw::{BinRead, BinReaderExt, BinResult, Endian};
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use cgmath::{Deg, Quaternion, Rotation3};
|
use cgmath::Quaternion;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io::{Cursor, Read, Seek};
|
use std::io::{Cursor, Read, Seek};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
|
@ -121,7 +121,7 @@ pub struct StaticPropLumps {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct StaticPropLump {
|
pub struct StaticPropLump {
|
||||||
pub origin: Vector,
|
pub origin: Vector,
|
||||||
angles: [f32; 3],
|
angles: Angles,
|
||||||
pub prop_type: u16,
|
pub prop_type: u16,
|
||||||
pub first_leaf: u16,
|
pub first_leaf: u16,
|
||||||
pub leaf_count: u16,
|
pub leaf_count: u16,
|
||||||
|
|
@ -140,10 +140,7 @@ pub struct StaticPropLump {
|
||||||
impl StaticPropLump {
|
impl StaticPropLump {
|
||||||
/// Get the rotation of the prop as quaternion
|
/// Get the rotation of the prop as quaternion
|
||||||
pub fn rotation(&self) -> Quaternion<f32> {
|
pub fn rotation(&self) -> Quaternion<f32> {
|
||||||
// angles are applied in roll, pitch, yaw order
|
self.angles.as_quaternion()
|
||||||
Quaternion::from_angle_y(Deg(self.angles[1]))
|
|
||||||
* Quaternion::from_angle_x(Deg(self.angles[0]))
|
|
||||||
* Quaternion::from_angle_z(Deg(self.angles[2]))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -209,7 +206,7 @@ impl From<StaticPropLumpFlagsV6> for StaticPropLumpFlags {
|
||||||
#[derive(BinRead)]
|
#[derive(BinRead)]
|
||||||
struct StaticPropLumpV6 {
|
struct StaticPropLumpV6 {
|
||||||
pub origin: Vector,
|
pub origin: Vector,
|
||||||
pub angles: [f32; 3],
|
pub angles: Angles,
|
||||||
pub prop_type: u16,
|
pub prop_type: u16,
|
||||||
pub first_leaf: u16,
|
pub first_leaf: u16,
|
||||||
pub leaf_count: u16,
|
pub leaf_count: u16,
|
||||||
|
|
@ -249,7 +246,7 @@ bitflags! {
|
||||||
#[derive(BinRead)]
|
#[derive(BinRead)]
|
||||||
struct StaticPropLumpV10 {
|
struct StaticPropLumpV10 {
|
||||||
pub origin: Vector,
|
pub origin: Vector,
|
||||||
pub angles: [f32; 3],
|
pub angles: Angles,
|
||||||
pub prop_type: u16,
|
pub prop_type: u16,
|
||||||
pub first_leaf: u16,
|
pub first_leaf: u16,
|
||||||
pub leaf_count: u16,
|
pub leaf_count: u16,
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,17 @@ pub use self::game::*;
|
||||||
pub use self::prop::PropPlacement;
|
pub use self::prop::PropPlacement;
|
||||||
pub use self::vector::*;
|
pub use self::vector::*;
|
||||||
use crate::bspfile::LumpType;
|
use crate::bspfile::LumpType;
|
||||||
|
use crate::error::EntityParseError;
|
||||||
use crate::{BspResult, StringError};
|
use crate::{BspResult, StringError};
|
||||||
use arrayvec::ArrayString;
|
use arrayvec::ArrayString;
|
||||||
use binrw::error::CustomError;
|
use binrw::error::CustomError;
|
||||||
use binrw::{BinRead, BinResult, Endian};
|
use binrw::{BinRead, BinResult, Endian};
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use bv::BitVec;
|
use bv::BitVec;
|
||||||
|
use cgmath::{Deg, Quaternion, Rotation3};
|
||||||
use num_enum::{TryFromPrimitive, TryFromPrimitiveError};
|
use num_enum::{TryFromPrimitive, TryFromPrimitiveError};
|
||||||
|
use serde::de::{Error, Unexpected};
|
||||||
|
use serde::{Deserialize, Deserializer};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
@ -24,6 +28,7 @@ use std::fmt::{Debug, Display, Formatter};
|
||||||
use std::io::{Cursor, Read, Seek};
|
use std::io::{Cursor, Read, Seek};
|
||||||
use std::mem::{align_of, size_of};
|
use std::mem::{align_of, size_of};
|
||||||
use std::ops::Index;
|
use std::ops::Index;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use zip::result::ZipError;
|
use zip::result::ZipError;
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
@ -531,3 +536,42 @@ where
|
||||||
err: Box::new(e),
|
err: Box::new(e),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone, BinRead)]
|
||||||
|
pub struct Angles {
|
||||||
|
pitch: f32,
|
||||||
|
yaw: f32,
|
||||||
|
roll: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for Angles {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let str = <&str>::deserialize(deserializer)?;
|
||||||
|
str.parse()
|
||||||
|
.map_err(|_| D::Error::invalid_value(Unexpected::Other(str), &"a list of angles"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Angles {
|
||||||
|
type Err = EntityParseError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
let mut floats = s.split(' ').map(f32::from_str);
|
||||||
|
let pitch = floats.next().ok_or(EntityParseError::ElementCount)??;
|
||||||
|
let yaw = floats.next().ok_or(EntityParseError::ElementCount)??;
|
||||||
|
let roll = floats.next().ok_or(EntityParseError::ElementCount)??;
|
||||||
|
Ok(Angles { pitch, yaw, roll })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Angles {
|
||||||
|
fn as_quaternion(&self) -> Quaternion<f32> {
|
||||||
|
// angles are applied in roll, pitch, yaw order
|
||||||
|
Quaternion::from_angle_y(Deg(self.yaw))
|
||||||
|
* Quaternion::from_angle_x(Deg(self.pitch))
|
||||||
|
* Quaternion::from_angle_z(Deg(self.roll))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{Handle, PropDynamic, PropDynamicOverride, StaticPropLump, Vector};
|
use crate::{Handle, PropDynamic, PropDynamicOverride, StaticPropLump, Vector};
|
||||||
use cgmath::{Deg, Quaternion, Rotation3};
|
use cgmath::Quaternion;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PropPlacement<'a> {
|
pub struct PropPlacement<'a> {
|
||||||
|
|
@ -22,17 +22,14 @@ impl<'a> Handle<'a, StaticPropLump> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rotation(angles: [f32; 3]) -> Quaternion<f32> {
|
|
||||||
Quaternion::from_angle_y(Deg(angles[1]))
|
|
||||||
* Quaternion::from_angle_x(Deg(angles[0]))
|
|
||||||
* Quaternion::from_angle_z(Deg(angles[2]))
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> PropDynamic<'a> {
|
impl<'a> PropDynamic<'a> {
|
||||||
pub fn as_prop_placement(&self) -> PropPlacement<'a> {
|
pub fn as_prop_placement(&self) -> PropPlacement<'a> {
|
||||||
|
if self.model.contains("slide_large") | self.model.contains("resup") {
|
||||||
|
// dbg!(self);
|
||||||
|
}
|
||||||
PropPlacement {
|
PropPlacement {
|
||||||
model: self.model,
|
model: self.model,
|
||||||
rotation: rotation(self.angles),
|
rotation: self.angles.as_quaternion(),
|
||||||
scale: self.scale,
|
scale: self.scale,
|
||||||
origin: self.origin,
|
origin: self.origin,
|
||||||
skin: 0,
|
skin: 0,
|
||||||
|
|
@ -44,7 +41,7 @@ impl<'a> PropDynamicOverride<'a> {
|
||||||
pub fn as_prop_placement(&self) -> PropPlacement<'a> {
|
pub fn as_prop_placement(&self) -> PropPlacement<'a> {
|
||||||
PropPlacement {
|
PropPlacement {
|
||||||
model: self.model,
|
model: self.model,
|
||||||
rotation: rotation(self.angles),
|
rotation: self.angles.as_quaternion(),
|
||||||
scale: self.scale,
|
scale: self.scale,
|
||||||
origin: self.origin,
|
origin: self.origin,
|
||||||
skin: 0,
|
skin: 0,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
use crate::error::EntityParseError;
|
use crate::error::EntityParseError;
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
use cgmath::Vector3;
|
use cgmath::Vector3;
|
||||||
|
use serde::de::{Error, Unexpected};
|
||||||
|
use serde::{Deserialize, Deserializer};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::ops::{Add, Mul, Sub};
|
use std::ops::{Add, Mul, Sub};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, BinRead)]
|
#[derive(Debug, Clone, Copy, BinRead, Default)]
|
||||||
pub struct Vector {
|
pub struct Vector {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
pub y: f32,
|
pub y: f32,
|
||||||
|
|
@ -110,3 +112,14 @@ impl From<Vector> for Vector3<f32> {
|
||||||
Vector3::new(v.x, v.y, v.z)
|
Vector3::new(v.x, v.y, v.z)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for Vector {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let str = <&str>::deserialize(deserializer)?;
|
||||||
|
str.parse()
|
||||||
|
.map_err(|_| D::Error::invalid_value(Unexpected::Other(str), &"a vector"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,9 @@ impl<R: BinReaderExt + Read> LumpReader<R> {
|
||||||
pub fn read_entities(&mut self) -> BspResult<Entities> {
|
pub fn read_entities(&mut self) -> BspResult<Entities> {
|
||||||
let mut data: Vec<u8> = vec![0; self.length];
|
let mut data: Vec<u8> = vec![0; self.length];
|
||||||
self.inner.read_exact(&mut data)?;
|
self.inner.read_exact(&mut data)?;
|
||||||
let entities = String::from_utf8(data).map_err(|e| StringError::from(e.utf8_error()))?;
|
let entities = String::from_utf8(data)
|
||||||
|
.map_err(|e| StringError::from(e.utf8_error()))?
|
||||||
|
.to_ascii_lowercase();
|
||||||
Ok(Entities { entities })
|
Ok(Entities { entities })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue