From 3487b8eb1c56f23afd1f0376aa32b79596a22d18 Mon Sep 17 00:00:00 2001 From: soul-walker <31162815+soul-walker@users.noreply.github.com> Date: Tue, 13 Aug 2024 19:44:14 +0800 Subject: [PATCH] =?UTF-8?q?bevy=20ecs=20app=E7=9B=B8=E5=85=B3=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=9F=BA=E4=BA=8E=E9=81=93=E5=B2=94=E4=BB=BF=E7=9C=9F?= =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E5=B0=9D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 918 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 5 + README.md | 2 +- src/components/equipment.rs | 40 ++ src/components/mod.rs | 2 + src/events/equipment.rs | 9 + src/events/mod.rs | 10 + src/lib.rs | 10 + src/main.rs | 2 +- src/resources/mod.rs | 9 + src/simulation.rs | 46 ++ src/systems/control.rs | 52 ++ src/systems/loading.rs | 14 + src/systems/mod.rs | 6 + src/systems/turnout.rs | 81 ++++ 15 files changed, 1204 insertions(+), 2 deletions(-) create mode 100644 src/components/equipment.rs create mode 100644 src/components/mod.rs create mode 100644 src/events/equipment.rs create mode 100644 src/events/mod.rs create mode 100644 src/lib.rs create mode 100644 src/resources/mod.rs create mode 100644 src/simulation.rs create mode 100644 src/systems/control.rs create mode 100644 src/systems/loading.rs create mode 100644 src/systems/mod.rs create mode 100644 src/systems/turnout.rs diff --git a/Cargo.lock b/Cargo.lock index 625ed1f..058a337 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,924 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + +[[package]] +name = "android_log-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecc8056bf6ab9892dcd53216c83d1597487d7dacac16c8df6b877d127df9937" + +[[package]] +name = "async-executor" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7ebdfa2ebdab6b1760375fa7d6f382b9f486eac35fc994625a00e89280bdbb7" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "slab", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bevy_app" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0af99549f5de61cc91c8c23303b13aa07f97b73fbace39695dee0a0a32cec9d4" +dependencies = [ + "bevy_derive", + "bevy_ecs", + "bevy_reflect", + "bevy_tasks", + "bevy_utils", + "console_error_panic_hook", + "downcast-rs", + "thiserror", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "bevy_core" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccc7118a2865267136afb5e6a2c0aed30994e522f298b2ba0b088878e6ddf59" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_reflect", + "bevy_tasks", + "bevy_utils", + "uuid", +] + +[[package]] +name = "bevy_derive" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8675f337f374b2b8ae90539982b947d171f9adb302d00c032b823bd5231f8978" +dependencies = [ + "bevy_macro_utils", + "quote", + "syn", +] + +[[package]] +name = "bevy_ecs" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a3eed7f144811946ebfa1c740da9e3bcd6dd2dd4da844eda085249d29bc9fef" +dependencies = [ + "bevy_ecs_macros", + "bevy_ptr", + "bevy_reflect", + "bevy_tasks", + "bevy_utils", + "bitflags", + "concurrent-queue", + "fixedbitset 0.5.7", + "nonmax", + "petgraph", + "thiserror", +] + +[[package]] +name = "bevy_ecs_macros" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d523630f2eb9fde6727e6c5ea48fa708079c5345da21ffeb1a4bd8ca761830da" +dependencies = [ + "bevy_macro_utils", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bevy_log" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52f2c0c374af59007396793a51f747f6b10d74ca4acfb080ce0ade267118827b" +dependencies = [ + "android_log-sys", + "bevy_app", + "bevy_ecs", + "bevy_utils", + "tracing-log", + "tracing-subscriber", + "tracing-wasm", +] + +[[package]] +name = "bevy_macro_utils" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ec4a585ec2a6dedd4f4143c07219d120ae142121929f0d83e68d82a452cdc9b" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "toml_edit", +] + +[[package]] +name = "bevy_ptr" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ed72afbb6249a6803a3ed7bd2f68ff080d9392f550475e050b34c1e1c1e3e8f" + +[[package]] +name = "bevy_reflect" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb37e8fc3c61d04da480c95cc8c303aa7781afed6be01dae333b336af493c38e" +dependencies = [ + "bevy_ptr", + "bevy_reflect_derive", + "bevy_utils", + "downcast-rs", + "erased-serde", + "serde", + "smallvec", + "smol_str", + "thiserror", +] + +[[package]] +name = "bevy_reflect_derive" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc00d5086f5bf534b4c2dbeba549a6b8d3223515f3cb5ba4fdaabe953ec6cea" +dependencies = [ + "bevy_macro_utils", + "proc-macro2", + "quote", + "syn", + "uuid", +] + +[[package]] +name = "bevy_tasks" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84f5414c3f49c96e02ceccf5fa12fb6cfbf8b271d2a820902d6f622e9c2fa681" +dependencies = [ + "async-executor", + "futures-lite", + "wasm-bindgen-futures", +] + +[[package]] +name = "bevy_time" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3fb18cfac62098e07786e422e84b4f45f469f27ccb5b572b409500bef465f33" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_reflect", + "bevy_utils", + "crossbeam-channel", + "thiserror", +] + +[[package]] +name = "bevy_utils" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6efbe5a621b56cc4ffa41074929eca84107e242302496b9bb7550675e6bf2e7" +dependencies = [ + "ahash", + "bevy_utils_proc_macros", + "getrandom", + "hashbrown", + "thread_local", + "tracing", + "web-time", +] + +[[package]] +name = "bevy_utils_proc_macros" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36a1e91b4294cad2d08620ac062509395d4f65247b636946d6497eaeccf4dbfd" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "erased-serde" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24e2389d65ab4fab27dc2a5de7b191e1f6617d1f1c8855c0dc569c94a4cbb18d" +dependencies = [ + "serde", + "typeid", +] + +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "fixedbitset" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-lite" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[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.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "nonmax" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "610a5acd306ec67f907abe5567859a3c693fb9886eb1f012ab8f2a47bef3db51" + +[[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 = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "parking" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" + +[[package]] +name = "petgraph" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" +dependencies = [ + "fixedbitset 0.4.2", + "indexmap", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", +] + +[[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.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.4", +] + +[[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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "rtss_simulation" version = "0.1.0" +dependencies = [ + "bevy_app", + "bevy_core", + "bevy_ecs", + "bevy_log", + "bevy_time", +] + +[[package]] +name = "serde" +version = "1.0.205" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33aedb1a7135da52b7c21791455563facbbcc43d0f0f66165b42c21b3dfb150" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.205" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692d6f5ac90220161d6774db30c662202721e64aed9058d2c394f451261420c1" +dependencies = [ + "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 = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "smol_str" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd538fb6910ac1099850255cf94a94df6551fbdd602454387d0adb2d1ca6dead" +dependencies = [ + "serde", +] + +[[package]] +name = "syn" +version = "2.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[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.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "tracing-wasm" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4575c663a174420fa2d78f4108ff68f65bf2fbb7dd89f33749b6e826b3626e07" +dependencies = [ + "tracing", + "tracing-subscriber", + "wasm-bindgen", +] + +[[package]] +name = "typeid" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "059d83cc991e7a42fc37bd50941885db0888e34209f8cfd9aab07ddec03bc9cf" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "uuid" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +dependencies = [ + "getrandom", +] + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[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 = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 2a4cd21..5d1b9d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +bevy_app = "0.14.1" +bevy_core = "0.14.1" +bevy_ecs = "0.14.1" +bevy_log = "0.14.1" +bevy_time = "0.14.1" diff --git a/README.md b/README.md index e446914..fb5467b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# rtss-simulation +# 项目描述 轨道交通信号系统仿真模块 ## 环境设置说明 diff --git a/src/components/equipment.rs b/src/components/equipment.rs new file mode 100644 index 0000000..3184153 --- /dev/null +++ b/src/components/equipment.rs @@ -0,0 +1,40 @@ +use bevy_ecs::{bundle::Bundle, component::Component}; + +// 设备编号组件 +#[derive(Component, Debug, Clone, PartialEq, Eq)] +pub struct Uid(pub String); +impl Default for Uid { + fn default() -> Self { + Uid("".to_string()) + } +} + +// 两常态位置转换组件,用于像道岔位置,屏蔽门位置等 +#[derive(Component, Debug, Clone, PartialEq, Eq, Default)] +pub struct TwoNormalPositionsConversion { + // 当前实际位置,百分比值,0-100 + pub position: i32, + // 当前转换速度 + pub velocity: i32, +} + +// 道岔设备状态组件 +#[derive(Component, Debug, Clone, PartialEq, Eq, Default)] +pub struct TurnoutState { + // 定位表示 + pub db: bool, + // 反位表示 + pub fb: bool, + // 定操表示 + pub dc: bool, + // 反操表示 + pub fc: bool, +} + +// 道岔设备组件包 +#[derive(Bundle, Default)] +pub struct TurnoutBundle { + pub uid: Uid, + pub turnout_state: TurnoutState, + pub two_normal_positions_conversion: TwoNormalPositionsConversion, +} diff --git a/src/components/mod.rs b/src/components/mod.rs new file mode 100644 index 0000000..3d75eaa --- /dev/null +++ b/src/components/mod.rs @@ -0,0 +1,2 @@ +mod equipment; +pub use equipment::*; diff --git a/src/events/equipment.rs b/src/events/equipment.rs new file mode 100644 index 0000000..3872c32 --- /dev/null +++ b/src/events/equipment.rs @@ -0,0 +1,9 @@ +use bevy_ecs::event::Event; + +#[derive(Event, Debug)] +pub enum TurnoutControlEvent { + // 道岔定操 + DC, + // 道岔反操 + FC, +} diff --git a/src/events/mod.rs b/src/events/mod.rs new file mode 100644 index 0000000..2ac4e22 --- /dev/null +++ b/src/events/mod.rs @@ -0,0 +1,10 @@ +mod equipment; +use bevy_ecs::event::Event; +pub use equipment::*; + +#[derive(Event, Debug)] +pub enum SimulationControlEvent { + Pause, + Unpause, + Exit, +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a33a27d --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,10 @@ +mod components; +mod events; +mod resources; +mod simulation; +mod systems; +pub use components::*; +pub use events::*; +pub use resources::*; +pub use simulation::*; +pub use systems::*; diff --git a/src/main.rs b/src/main.rs index e7a11a9..35efc25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,3 @@ fn main() { - println!("Hello, world!"); + rtss_simulation::Simulation::new().app.run(); } diff --git a/src/resources/mod.rs b/src/resources/mod.rs new file mode 100644 index 0000000..67c1d96 --- /dev/null +++ b/src/resources/mod.rs @@ -0,0 +1,9 @@ +use std::collections::HashMap; + +use bevy_ecs::{entity::Entity, system::Resource}; + +// 用于存储设备编号与实体的映射关系的资源 +#[derive(Resource, Debug, Default)] +pub struct EquipmentUidEntityMapping { + pub turnout_mapping: HashMap, +} diff --git a/src/simulation.rs b/src/simulation.rs new file mode 100644 index 0000000..eb43b1d --- /dev/null +++ b/src/simulation.rs @@ -0,0 +1,46 @@ +use std::time::Duration; + +use crate::{ + control_simulation, handle_turnout_control, loading, simulation_status_control, + turnout_state_update, two_normal_position_transform, EquipmentUidEntityMapping, + SimulationControlEvent, +}; +use bevy_app::{prelude::*, ScheduleRunnerPlugin}; +use bevy_ecs::schedule::IntoSystemConfigs; +use bevy_log::LogPlugin; +use bevy_time::{prelude::*, TimePlugin}; + +pub struct Simulation { + pub app: App, +} + +impl Default for Simulation { + fn default() -> Self { + Self::new() + } +} + +impl Simulation { + pub fn new() -> Self { + let mut app = App::new(); + app.add_plugins(ScheduleRunnerPlugin::run_loop(Duration::from_millis(1000))) + .add_plugins(LogPlugin { + level: bevy_log::Level::DEBUG, + ..Default::default() + }) + .add_plugins(TimePlugin) + .insert_resource(Time::::from_max_delta(Duration::from_secs(5))) + .insert_resource(Time::::from_duration(Duration::from_millis(1000))) + .insert_resource(EquipmentUidEntityMapping::default()) + .add_event::() + .add_systems(Startup, loading) + .add_systems(Update, control_simulation) + .add_systems( + FixedUpdate, + (two_normal_position_transform, turnout_state_update).chain(), + ) + .observe(handle_turnout_control) + .observe(simulation_status_control); + Simulation { app } + } +} diff --git a/src/systems/control.rs b/src/systems/control.rs new file mode 100644 index 0000000..8d13b74 --- /dev/null +++ b/src/systems/control.rs @@ -0,0 +1,52 @@ +use bevy_app::AppExit; +use bevy_ecs::{ + event::EventWriter, + observer::Trigger, + system::{Commands, Res, ResMut}, +}; +use bevy_log::debug; +use bevy_time::{Time, Virtual}; + +use crate::{EquipmentUidEntityMapping, SimulationControlEvent, TurnoutControlEvent}; + +pub fn control_simulation( + time: ResMut>, + mut commands: Commands, + res_uid_mapping: Res, +) { + res_uid_mapping + .turnout_mapping + .iter() + .for_each(|(_uid, entity)| { + // debug!("Uid: {:?}, Entity: {:?}", uid, entity); + commands.trigger_targets(TurnoutControlEvent::FC, *entity); + }); + if time.elapsed_seconds() > 13.0 { + debug!("send exit event"); + commands.trigger(SimulationControlEvent::Exit); + } + // if time.elapsed_seconds() > 10.0 { + // commands.trigger(SimulationControlEvent::Pause); + // } +} + +pub fn simulation_status_control( + trigger: Trigger, + mut time: ResMut>, + mut exit: EventWriter, +) { + match trigger.event() { + SimulationControlEvent::Pause => { + debug!("Pausing simulation"); + time.pause(); + } + SimulationControlEvent::Unpause => { + debug!("Unpausing simulation"); + time.unpause(); + } + SimulationControlEvent::Exit => { + debug!("Exiting simulation"); + exit.send(AppExit::Success); + } + } +} diff --git a/src/systems/loading.rs b/src/systems/loading.rs new file mode 100644 index 0000000..4a2e669 --- /dev/null +++ b/src/systems/loading.rs @@ -0,0 +1,14 @@ +use bevy_ecs::{prelude::Commands, system::ResMut}; + +use crate::{components, EquipmentUidEntityMapping, Uid}; + +pub fn loading(mut commands: Commands, mut res_uid_mapping: ResMut) { + let uid = Uid("1".to_string()); + let et = commands.spawn(components::TurnoutBundle { + uid: uid.clone(), + ..Default::default() + }); + res_uid_mapping + .turnout_mapping + .insert(uid.0.clone(), et.id()); +} diff --git a/src/systems/mod.rs b/src/systems/mod.rs new file mode 100644 index 0000000..662e47a --- /dev/null +++ b/src/systems/mod.rs @@ -0,0 +1,6 @@ +mod control; +mod loading; +mod turnout; +pub use control::*; +pub use loading::*; +pub use turnout::*; diff --git a/src/systems/turnout.rs b/src/systems/turnout.rs new file mode 100644 index 0000000..2919b3f --- /dev/null +++ b/src/systems/turnout.rs @@ -0,0 +1,81 @@ +use bevy_ecs::{ + entity::Entity, + observer::Trigger, + system::{Query, ResMut}, +}; +use bevy_log::debug; +use bevy_time::{Fixed, Time}; + +use crate::{events::TurnoutControlEvent, TurnoutState, TwoNormalPositionsConversion, Uid}; + +// 道岔控制事件处理系统 +pub fn handle_turnout_control( + trigger: Trigger, + time: ResMut>, + mut query: Query<(&Uid, &mut TurnoutState, &mut TwoNormalPositionsConversion)>, +) { + let (uid, mut state, mut conversion) = query + .get_mut(trigger.entity()) + .expect("通过entity获取道岔异常"); + match trigger.event() { + TurnoutControlEvent::DC => { + state.dc = true; + state.fc = false; + conversion.velocity = -3000 / time.timestep().as_millis() as i32; + debug!("道岔定操处理:{:?}", uid); + } + TurnoutControlEvent::FC => { + state.dc = false; + state.fc = true; + conversion.velocity = 3000 / time.timestep().as_millis() as i32; + debug!("道岔反操处理:uid={:?}, conversion={:?}", uid, conversion); + } + } +} + +// 道岔状态更新系统 +pub fn turnout_state_update( + mut query: Query<(&Uid, &mut TurnoutState, &mut TwoNormalPositionsConversion)>, +) { + for (uid, mut state, conversion) in &mut query { + debug!( + "更新道岔状态:Uid={:?}, State={:?}, Conversion={:?}", + uid, state, conversion + ); + if conversion.velocity != 0 { + state.db = false; + state.fb = false; + } else if conversion.position == 0 { + state.db = true; + state.fb = false; + } else if conversion.position == 100 { + state.db = false; + state.fb = true; + } + } +} + +// 两常态位置转换系统 +pub fn two_normal_position_transform( + mut query: Query<(Entity, &Uid, &mut TwoNormalPositionsConversion)>, +) { + for (entity, uid, mut conversion) in &mut query { + debug!( + "Entity: {:?}, Uid: {:?}, Conversion: {:?}", + entity, uid, conversion + ); + if conversion.velocity == 0 { + continue; + } + let p = conversion.position + conversion.velocity; + if p > 100 { + conversion.position = 100; + conversion.velocity = 0; + } else if p < 0 { + conversion.position = 0; + conversion.velocity = 0; + } else { + conversion.position = p; + } + } +}