diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 04df54c4..62014162 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -10,7 +10,7 @@ There's also the `market_update` which updates the markets and determines which To handle user interactions, Egregoria uses a Server-Client model. This ensures Egregoria's state cannot be easily corrupted and enables [Deterministic Lockstep](https://gafferongames.com/post/deterministic_lockstep/) networking. -The [`WorldCommand`](https://github.com/Uriopass/Egregoria/blob/master/egregoria/src/engine_interaction.rs#L32) enum encodes theses possible mutations. +The [`WorldCommand`](https://github.com/Uriopass/Egregoria/blob/master/simulation/src/engine_interaction.rs#L32) enum encodes theses possible mutations. For rendering+audio, all the render state is specifically NOT contained along the simulated entities. Instead of saying "this road has this mesh" with the rest of the `Road`'s definition, it is entirely determined on the rendering side and cached. @@ -26,16 +26,16 @@ This is a (not up-to-date) codemap to showcase the different crate's usages and Approximately sorted by importance. -## `egregoria` +## `simulation` The main crate, which contains all the simulation logic. It is itself composed of the following subsystems: -### `egregoria/economy` +### `simulation/economy` Everything related to the market. Doesn't contain the economic actors. -## `egregoria/map` +## `simulation/map` Contains all the map related data. It contains the data about: - Roads/intersections/lanes/lots @@ -45,15 +45,15 @@ Contains all the map related data. It contains the data about: It is only raw data and operators (e.g. build this road here), but it doesn't contain any simulation logic per se. -### `egregoria/map_dynamic` +### `simulation/map_dynamic` This contains all the dynamism around the map, like the pathfinding, routing, parking and itinerary systems. -### `egregoria/transportation` +### `simulation/transportation` This module handles vehicles and pedestrians, it contains all the complex rules around traffic and how to handle intersections. -### `egregoria/souls` +### `simulation/souls` This module contains all the AI related to the companies and the humans in the world. This is where companies decide to employ people, and where people decide to buy some bread. @@ -121,7 +121,7 @@ All the UI related code is in the `native_app` crate, more specifically in the ` ## Simulation/Gameplay -All the simulation code is in the `egregoria` crate. The different modules of this crate are explained in the codemap. +All the simulation code is in the `simulation` crate. The different modules of this crate are explained in the codemap. Try to keep the different aspects of the simulation decoupled so that it is easier to reason about. ## 3D Graphics diff --git a/Cargo.lock b/Cargo.lock index 6ff6dce3..5db737cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,9 +20,9 @@ checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" [[package]] name = "addr2line" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -57,9 +57,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a" +checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" dependencies = [ "memchr", ] @@ -193,9 +193,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", @@ -307,22 +307,22 @@ checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "bytemuck" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" +checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192" +checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -353,9 +353,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.82" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "jobserver", "libc", @@ -682,14 +682,14 @@ dependencies = [ "proc-macro2", "quote", "semver", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] name = "deranged" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" +checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" [[package]] name = "derive_more" @@ -750,30 +750,6 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "egregoria" -version = "0.1.0" -dependencies = [ - "arc-swap", - "common", - "derive_more", - "easybench", - "egui-inspect", - "flat_spatial", - "geom", - "inline_tweak", - "lazy_static", - "log", - "ordered-float", - "pathfinding", - "profiling", - "quickcheck", - "rayon", - "serde", - "serde-big-array", - "slotmapd", -] - [[package]] name = "egui" version = "0.22.0" @@ -945,9 +921,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" dependencies = [ "errno-dragonfly", "libc", @@ -1058,9 +1034,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.3" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "glob" @@ -1082,9 +1058,9 @@ dependencies = [ [[package]] name = "gltf" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fe8d5192923fbd783c15e74627de8e27c97e1e3dec22bf54515a407249febf" +checksum = "ad2dcfb6dd7a66f9eb3d181a29dcfb22d146b0bcdc2e1ed1713cbf03939a88ea" dependencies = [ "base64", "byteorder", @@ -1096,21 +1072,21 @@ dependencies = [ [[package]] name = "gltf-derive" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec223c88f017861193ae128239aff8fbc4478f38a036d9d7b2ce10a52b46b1f2" +checksum = "f2cbcea5dd47e7ad4e9ee6f040384fcd7204bbf671aa4f9e7ca7dfc9bfa1de20" dependencies = [ "inflections", "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] name = "gltf-json" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b1ba7523fcf32541f4aec96e13024c255d928eab3223f99ab945045f2a6de18" +checksum = "7d5b810806b78dde4b71a95cc0e6fdcab34c4c617da3574df166f9987be97d03" dependencies = [ "gltf-derive", "serde", @@ -1205,9 +1181,9 @@ name = "headless" version = "0.1.0" dependencies = [ "common", - "egregoria", "log", "networking", + "simulation", "structopt", ] @@ -1561,9 +1537,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" [[package]] name = "memmap2" @@ -1666,7 +1642,6 @@ version = "0.4.3" dependencies = [ "bytemuck", "common", - "egregoria", "egui", "egui-inspect", "egui_extras", @@ -1682,6 +1657,7 @@ dependencies = [ "profiling", "rayon", "serde", + "simulation", "slotmapd", "winit", ] @@ -1866,7 +1842,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -1925,9 +1901,9 @@ dependencies = [ [[package]] name = "object" -version = "0.31.1" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" dependencies = [ "memchr", ] @@ -1990,9 +1966,9 @@ dependencies = [ [[package]] name = "ordered-float" -version = "3.9.0" +version = "3.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126d3e6f3926bfb0fb24495b4f4da50626f547e54956594748e3d8882a0320b4" +checksum = "2a54938017eacd63036332b4ae5c8a49fc8c0c1d6d629893057e4f13609edd06" dependencies = [ "num-traits", ] @@ -2070,9 +2046,9 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pin-project-lite" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pkg-config" @@ -2138,9 +2114,9 @@ dependencies = [ [[package]] name = "profiling" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46b2164ebdb1dfeec5e337be164292351e11daf63a05174c6776b2f47460f0c9" +checksum = "45f10e75d83c7aec79a6aa46f897075890e156b105eebe51cfa0abce51af025f" dependencies = [ "profiling-procmacros", "tracy-client", @@ -2148,12 +2124,12 @@ dependencies = [ [[package]] name = "profiling-procmacros" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "097bf8b99121dfb8c75eed54dfbdbdb1d53e372c53d2353e8a15aad2a479249d" +checksum = "74c55e9e629af5298a40e0fa106435b2da30484c4ec76b41d19bc4d00dd8b903" dependencies = [ "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -2239,14 +2215,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.3" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" +checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.6", - "regex-syntax 0.7.4", + "regex-automata 0.3.8", + "regex-syntax 0.7.5", ] [[package]] @@ -2260,13 +2236,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" +checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.4", + "regex-syntax 0.7.5", ] [[package]] @@ -2277,9 +2253,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "renderdoc-sys" @@ -2310,9 +2286,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.8" +version = "0.38.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" +checksum = "c0c3dde1fc030af041adc40e79c0e7fbcf431dd24870053d187d7c66e4b87453" dependencies = [ "bitflags 2.4.0", "errno", @@ -2375,9 +2351,9 @@ checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" [[package]] name = "serde" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] @@ -2393,13 +2369,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -2424,9 +2400,9 @@ dependencies = [ [[package]] name = "shlex" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" [[package]] name = "simd-adler32" @@ -2446,6 +2422,30 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "simulation" +version = "0.1.0" +dependencies = [ + "arc-swap", + "common", + "derive_more", + "easybench", + "egui-inspect", + "flat_spatial", + "geom", + "inline_tweak", + "lazy_static", + "log", + "ordered-float", + "pathfinding", + "profiling", + "quickcheck", + "rayon", + "serde", + "serde-big-array", + "slotmapd", +] + [[package]] name = "slotmap" version = "1.0.6" @@ -2560,9 +2560,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.29" +version = "2.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398" dependencies = [ "proc-macro2", "quote", @@ -2589,22 +2589,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.47" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" +checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.47" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" +checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -2619,9 +2619,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.25" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" +checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48" dependencies = [ "deranged", "itoa", @@ -2640,9 +2640,9 @@ checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.11" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" +checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572" dependencies = [ "time-core", ] @@ -2724,7 +2724,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -2851,9 +2851,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "walkdir" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" dependencies = [ "same-file", "winapi-util", @@ -2886,7 +2886,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", "wasm-bindgen-shared", ] @@ -2920,7 +2920,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3362,9 +3362,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.5.14" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d09770118a7eb1ccaf4a594a221334119a44a814fcb0d31c5b85e83e97227a97" +checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" dependencies = [ "memchr", ] @@ -3391,6 +3391,6 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.16" +version = "0.8.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47430998a7b5d499ccee752b41567bc3afc57e1327dc855b1a2aa44ce29b5fa1" +checksum = "1eee6bf5926be7cf998d7381a9a23d833fd493f6a8034658a9505a4dc4b20444" diff --git a/Cargo.toml b/Cargo.toml index 1233975c..2c8c2bbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ members = [ "assets_gui", "common", - "egregoria", + "simulation", "egui-inspect", "egui-inspect-derive", "engine", @@ -36,7 +36,7 @@ opt-level = 2 [profile.dev.package.common] opt-level = 2 -[profile.dev.package.egregoria] +[profile.dev.package.simulation] opt-level = 1 [profile.dev.package.native_app] diff --git a/headless/Cargo.toml b/headless/Cargo.toml index 3827f24e..f34e6020 100644 --- a/headless/Cargo.toml +++ b/headless/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -egregoria = { path = "../egregoria" } +simulation = { path = "../simulation" } networking = { path = "../networking" } common = { path = "../common" } structopt = "0.3.21" diff --git a/headless/src/main.rs b/headless/src/main.rs index 8fe7cf97..1f43359e 100644 --- a/headless/src/main.rs +++ b/headless/src/main.rs @@ -1,8 +1,8 @@ use common::logger::MyLog; use common::unwrap_or; -use egregoria::engine_interaction::WorldCommands; -use egregoria::Egregoria; use networking::{Frame, Server, ServerConfiguration, ServerPollResult}; +use simulation::engine_interaction::WorldCommands; +use simulation::Simulation; use std::time::{Duration, Instant}; use structopt::StructOpt; @@ -32,18 +32,18 @@ struct Opt { fn main() { let opt: Opt = Opt::from_args(); MyLog::init(); - egregoria::init::init(); + simulation::init::init(); log::info!("starting server with version: {}", VERSION); - let mut w = unwrap_or!(Egregoria::load_from_disk("world"), { + let mut w = unwrap_or!(Simulation::load_from_disk("world"), { log::info!("savegame not found defaulting to empty"); - Egregoria::new(true) + Simulation::new(true) }); - let mut sched = Egregoria::schedule(); + let mut sched = Simulation::schedule(); - let mut server: Server = match Server::start(ServerConfiguration { + let mut server: Server = match Server::start(ServerConfiguration { start_frame: Frame(w.get_tick()), period: Duration::from_millis(opt.timestep), port: opt.port, diff --git a/native_app/Cargo.toml b/native_app/Cargo.toml index 88149a51..72601b00 100644 --- a/native_app/Cargo.toml +++ b/native_app/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] bytemuck = "1.7.2" -egregoria = { path = "../egregoria" } +simulation = { path = "../simulation" } geom = { path = "../geom" } engine = { path = "../engine" } common = { path = "../common" } diff --git a/native_app/src/audio/ambient.rs b/native_app/src/audio/ambient.rs index b52392e7..f2023e1c 100644 --- a/native_app/src/audio/ambient.rs +++ b/native_app/src/audio/ambient.rs @@ -1,10 +1,10 @@ use crate::uiworld::UiWorld; use common::AudioKind; -use egregoria::map::Terrain; -use egregoria::Egregoria; use engine::{AudioContext, ControlHandle, Stereo}; use geom::{lerp, vec2, Camera, Vec2, AABB}; use oddio::{Cycle, Gain}; +use simulation::map::Terrain; +use simulation::Simulation; /// Ambient sounds /// These are sounds that are played in the background @@ -38,9 +38,9 @@ impl Ambient { Self { wind, forest } } - pub fn update(&mut self, goria: &Egregoria, uiworld: &mut UiWorld) { + pub fn update(&mut self, sim: &Simulation, uiworld: &mut UiWorld) { let eye = uiworld.read::().eye(); - let map = goria.map(); + let map = sim.map(); let h = eye.z; diff --git a/native_app/src/audio/car_sounds.rs b/native_app/src/audio/car_sounds.rs index 781d0742..52d84c65 100644 --- a/native_app/src/audio/car_sounds.rs +++ b/native_app/src/audio/car_sounds.rs @@ -1,11 +1,11 @@ use crate::uiworld::UiWorld; use common::AudioKind; -use egregoria::physics::CollisionWorld; -use egregoria::Egregoria; use engine::{AudioContext, ControlHandle, Stereo}; use flat_spatial::grid::GridHandle; use geom::{Camera, AABB}; use oddio::{Cycle, Gain, Seek, Speed, Stop}; +use simulation::physics::CollisionWorld; +use simulation::Simulation; use slotmapd::SecondaryMap; /// CarSound is the sound of a single car @@ -37,8 +37,8 @@ impl CarSounds { } } - pub fn update(&mut self, goria: &Egregoria, uiworld: &mut UiWorld, ctx: &mut AudioContext) { - let coworld = goria.read::(); + pub fn update(&mut self, sim: &Simulation, uiworld: &mut UiWorld, ctx: &mut AudioContext) { + let coworld = sim.read::(); let campos = uiworld.read::().eye(); let cambox = AABB::new(campos.xy(), campos.xy()).expand(100.0); @@ -79,7 +79,7 @@ impl CarSounds { .sqrt(), ) { let (pos, obj) = coworld.get(h).unwrap(); - if !matches!(obj.group, egregoria::physics::PhysicsGroup::Vehicles) { + if !matches!(obj.group, simulation::physics::PhysicsGroup::Vehicles) { continue; } @@ -144,7 +144,7 @@ impl CarSounds { let cars_on_screen = coworld .query_aabb(cambox.ll, cambox.ur) .filter_map(|(h, _)| coworld.get(h)) - .filter(|(_, obj)| matches!(obj.group, egregoria::physics::PhysicsGroup::Vehicles)) + .filter(|(_, obj)| matches!(obj.group, simulation::physics::PhysicsGroup::Vehicles)) .count(); if let Some(ref mut s) = self.generic_car_sound { s.control::, _>().set_amplitude_ratio( diff --git a/native_app/src/audio/mod.rs b/native_app/src/audio/mod.rs index da1eeab0..2146ea03 100644 --- a/native_app/src/audio/mod.rs +++ b/native_app/src/audio/mod.rs @@ -2,8 +2,8 @@ use crate::audio::ambient::Ambient; use crate::audio::car_sounds::CarSounds; use crate::audio::music::Music; use crate::uiworld::UiWorld; -use egregoria::Egregoria; use engine::AudioContext; +use simulation::Simulation; mod ambient; mod car_sounds; @@ -36,9 +36,9 @@ impl GameAudio { } } - pub fn update(&mut self, goria: &Egregoria, uiworld: &mut UiWorld, ctx: &mut AudioContext) { + pub fn update(&mut self, sim: &Simulation, uiworld: &mut UiWorld, ctx: &mut AudioContext) { self.music.update(ctx); - self.ambiant.update(goria, uiworld); - self.carsounds.update(goria, uiworld, ctx); + self.ambiant.update(sim, uiworld); + self.carsounds.update(sim, uiworld, ctx); } } diff --git a/native_app/src/game_loop.rs b/native_app/src/game_loop.rs index 14624850..23be0a90 100644 --- a/native_app/src/game_loop.rs +++ b/native_app/src/game_loop.rs @@ -6,10 +6,10 @@ use winit::event_loop::ControlFlow; use crate::rendering::immediate::{ImmediateDraw, ImmediateSound}; use common::History; -use egregoria::utils::time::GameTime; -use egregoria::Egregoria; use engine::{Context, FrameContext, Tesselator}; use geom::{vec2, vec3, Camera, LinearColor}; +use simulation::utils::time::GameTime; +use simulation::Simulation; use crate::audio::GameAudio; use crate::gui::windows::debug::DebugObjs; @@ -19,13 +19,13 @@ use crate::inputmap::{Bindings, InputAction, InputMap}; use crate::rendering::{InstancedRender, MapRenderOptions, MapRenderer, OrbitCamera}; use crate::uiworld::{SaveLoadState, UiWorld}; use common::saveload::Encoder; -use egregoria::utils::scheduler::SeqSchedule; +use simulation::utils::scheduler::SeqSchedule; pub const VERSION: &str = include_str!("../../VERSION"); /// State is the main struct that contains all the state of the game and game UI. pub struct State { - pub goria: Arc>, + pub sim: Arc>, pub uiw: UiWorld, pub game_schedule: SeqSchedule, @@ -44,9 +44,9 @@ impl engine::framework::State for State { Gui::set_style(&ctx.egui.egui); log::info!("loaded egui_render"); - let goria: Egregoria = - Egregoria::load_from_disk("world").unwrap_or_else(|| Egregoria::new(true)); - let game_schedule = Egregoria::schedule(); + let sim: Simulation = + Simulation::load_from_disk("world").unwrap_or_else(|| Simulation::new(true)); + let game_schedule = Simulation::schedule(); let mut uiworld = UiWorld::init(); let mut bindings = uiworld.write::(); @@ -79,13 +79,13 @@ impl engine::framework::State for State { uiw: uiworld, game_schedule, instanced_renderer: InstancedRender::new(&mut ctx.gfx), - map_renderer: MapRenderer::new(&mut ctx.gfx, &goria), + map_renderer: MapRenderer::new(&mut ctx.gfx, &sim), gui, all_audio: GameAudio::new(&mut ctx.audio), - goria: Arc::new(RwLock::new(goria)), + sim: Arc::new(RwLock::new(sim)), immtess: Tesselator::new(&mut ctx.gfx, None, 1.0), }; - me.goria.write().unwrap().map().dispatch_all(); + me.sim.write().unwrap().map().dispatch_all(); me } @@ -95,7 +95,7 @@ impl engine::framework::State for State { let mut slstate = self.uiw.write::(); if slstate.please_save && !slstate.saving_status.load(Ordering::SeqCst) { slstate.please_save = false; - let cpy = self.goria.clone(); + let cpy = self.sim.clone(); slstate.saving_status.store(true, Ordering::SeqCst); let status = slstate.saving_status.clone(); std::thread::spawn(move || { @@ -106,15 +106,15 @@ impl engine::framework::State for State { } drop(slstate); - crate::network::goria_update(self); + crate::network::sim_update(self); if std::mem::take(&mut self.uiw.write::().render_reset) { self.reset(ctx); } if !ctx.egui.last_mouse_captured { - let goria = self.goria.read().unwrap(); - let map = goria.map(); + let sim = self.sim.read().unwrap(); + let map = sim.map(); let unproj = self .uiw .read::() @@ -130,7 +130,7 @@ impl engine::framework::State for State { !ctx.egui.last_kb_captured, !ctx.egui.last_mouse_captured, ); - crate::gui::run_ui_systems(&self.goria.read().unwrap(), &mut self.uiw); + crate::gui::run_ui_systems(&self.sim.read().unwrap(), &mut self.uiw); self.uiw.write::().all.add_value(ctx.delta); self.uiw.write::().per_game_system = self.game_schedule.times(); @@ -144,16 +144,16 @@ impl engine::framework::State for State { manage_settings(ctx, &self.uiw.read::()); self.manage_io(ctx); - self.map_renderer.update(&self.goria.read().unwrap(), ctx); + self.map_renderer.update(&self.sim.read().unwrap(), ctx); ctx.gfx - .set_time(self.goria.read().unwrap().read::().timestamp as f32); + .set_time(self.sim.read().unwrap().read::().timestamp as f32); for (sound, kind) in self.uiw.write::().orders.drain(..) { ctx.audio.play(sound, kind); } self.all_audio - .update(&self.goria.read().unwrap(), &mut self.uiw, &mut ctx.audio); + .update(&self.sim.read().unwrap(), &mut self.uiw, &mut ctx.audio); FollowEntity::update_camera(self); self.uiw.camera_mut().update(ctx); @@ -163,16 +163,16 @@ impl engine::framework::State for State { fn render(&mut self, ctx: &mut FrameContext<'_>) { profiling::scope!("game_loop::render"); let start = Instant::now(); - let goria = self.goria.read().unwrap(); + let sim = self.sim.read().unwrap(); self.immtess.meshbuilder.clear(); let camera = self.uiw.read::(); camera.cull_tess(&mut self.immtess); - let time: GameTime = *self.goria.read().unwrap().read::(); + let time: GameTime = *self.sim.read().unwrap().read::(); self.map_renderer.render( - &goria.map(), + &sim.map(), time.seconds, &camera.camera, &camera.frustrum, @@ -185,13 +185,13 @@ impl engine::framework::State for State { ); self.instanced_renderer - .render(&self.goria.read().unwrap(), ctx); + .render(&self.sim.read().unwrap(), ctx); { let objs = self.uiw.read::(); for (val, _, obj) in &objs.0 { if *val { - obj(&mut self.immtess, &goria, &self.uiw); + obj(&mut self.immtess, &sim, &self.uiw); } } } @@ -259,16 +259,16 @@ impl engine::framework::State for State { } fn render_gui(&mut self, ui: &egui::Context) { - let goria = self.goria.read().unwrap(); - self.gui.render(ui, &mut self.uiw, &goria); + let sim = self.sim.read().unwrap(); + self.gui.render(ui, &mut self.uiw, &sim); } } impl State { fn reset(&mut self, ctx: &mut Context) { ctx.gfx.lamplights.reset(&ctx.gfx.device, &ctx.gfx.queue); - self.map_renderer = MapRenderer::new(&mut ctx.gfx, &self.goria.read().unwrap()); - self.goria.write().unwrap().map().dispatch_all(); + self.map_renderer = MapRenderer::new(&mut ctx.gfx, &self.sim.read().unwrap()); + self.sim.write().unwrap().map().dispatch_all(); ctx.gfx.update_simplelit_bg(); } @@ -297,7 +297,7 @@ impl State { .try_into() .unwrap(); drop(camera); - let c = egregoria::config(); + let c = simulation::config(); params.grass_col = c.grass_col.into(); params.sand_col = c.sand_col.into(); params.sea_col = c.sea_col.into(); @@ -305,8 +305,8 @@ impl State { } fn manage_io(&mut self, ctx: &mut Context) { - let goria = self.goria.read().unwrap(); - let map = goria.map(); + let sim = self.sim.read().unwrap(); + let map = sim.map(); // self.camera.movespeed = settings.camera_sensibility / 100.0; self.uiw.camera_mut().camera_movement( ctx, diff --git a/native_app/src/gui/addtrain.rs b/native_app/src/gui/addtrain.rs index 99383f17..1419b498 100644 --- a/native_app/src/gui/addtrain.rs +++ b/native_app/src/gui/addtrain.rs @@ -3,16 +3,16 @@ use crate::gui::PotentialCommands; use crate::inputmap::{InputAction, InputMap}; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; -use egregoria::engine_interaction::WorldCommand; -use egregoria::map::LaneKind; -use egregoria::transportation::train::{train_length, wagons_positions_for_render}; -use egregoria::Egregoria; use geom::{Color, OBB}; +use simulation::engine_interaction::WorldCommand; +use simulation::map::LaneKind; +use simulation::transportation::train::{train_length, wagons_positions_for_render}; +use simulation::Simulation; use std::option::Option::None; /// Addtrain handles the "Adding a train" tool /// It allows to add a train to any rail lane -pub fn addtrain(goria: &Egregoria, uiworld: &mut UiWorld) { +pub fn addtrain(sim: &Simulation, uiworld: &mut UiWorld) { profiling::scope!("gui::addtrain"); let tool = *uiworld.read::(); if !matches!(tool, Tool::Train) { @@ -23,7 +23,7 @@ pub fn addtrain(goria: &Egregoria, uiworld: &mut UiWorld) { let mut potential = uiworld.write::(); let mut draw = uiworld.write::(); - let map = goria.map(); + let map = sim.map(); let commands = &mut *uiworld.commands(); let mpos = unwrap_ret!(inp.unprojected); @@ -34,7 +34,7 @@ pub fn addtrain(goria: &Egregoria, uiworld: &mut UiWorld) { Some(x) => x, None => { draw.circle(mpos, 10.0) - .color(egregoria::config().gui_danger); + .color(simulation::config().gui_danger); return; } }; @@ -53,11 +53,11 @@ pub fn addtrain(goria: &Egregoria, uiworld: &mut UiWorld) { }; if dist <= trainlength { - drawtrain(egregoria::config().gui_danger); + drawtrain(simulation::config().gui_danger); return; } - drawtrain(egregoria::config().gui_primary); + drawtrain(simulation::config().gui_primary); let cmd = WorldCommand::AddTrain { dist, diff --git a/native_app/src/gui/bulldozer.rs b/native_app/src/gui/bulldozer.rs index da2fef77..17271a41 100644 --- a/native_app/src/gui/bulldozer.rs +++ b/native_app/src/gui/bulldozer.rs @@ -3,9 +3,9 @@ use crate::gui::specialbuilding::SpecialBuildingResource; use crate::inputmap::{InputAction, InputMap}; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; -use egregoria::map::{BuildingKind, Map, ProjectFilter, ProjectKind}; -use egregoria::Egregoria; use egui_inspect::Inspect; +use simulation::map::{BuildingKind, Map, ProjectFilter, ProjectKind}; +use simulation::Simulation; #[derive(Copy, Clone, Default, Inspect)] pub struct BulldozerState { @@ -14,7 +14,7 @@ pub struct BulldozerState { /// Bulldozer tool /// Allows to remove roads, intersections and buildings -pub fn bulldozer(goria: &Egregoria, uiworld: &mut UiWorld) { +pub fn bulldozer(sim: &Simulation, uiworld: &mut UiWorld) { profiling::scope!("gui::bulldozer"); let tool: &Tool = &uiworld.read::(); @@ -23,7 +23,7 @@ pub fn bulldozer(goria: &Egregoria, uiworld: &mut UiWorld) { } let inp: &InputMap = &uiworld.read::(); - let map: &Map = &goria.map(); + let map: &Map = &sim.map(); let draw: &mut ImmediateDraw = &mut uiworld.write::(); let mut commands = uiworld.commands(); let state: &BulldozerState = &uiworld.read::(); @@ -34,9 +34,9 @@ pub fn bulldozer(goria: &Egregoria, uiworld: &mut UiWorld) { cur_proj.kind, ProjectKind::Inter(_) | ProjectKind::Road(_) | ProjectKind::Building(_) ) { - egregoria::config().gui_danger + simulation::config().gui_danger } else { - egregoria::config().gui_disabled + simulation::config().gui_disabled }; draw.circle(cur_proj.pos.up(0.5), 2.0).color(col); diff --git a/native_app/src/gui/chat.rs b/native_app/src/gui/chat.rs index dbbb0392..c2ade8ea 100644 --- a/native_app/src/gui/chat.rs +++ b/native_app/src/gui/chat.rs @@ -1,12 +1,12 @@ use egui::panel::TopBottomSide; use egui::{Align2, Color32, Frame, RichText, ScrollArea, TextBuffer, TopBottomPanel}; -use egregoria::engine_interaction::WorldCommand; -use egregoria::multiplayer::chat::{Message, MessageKind}; -use egregoria::multiplayer::MultiplayerState; -use egregoria::utils::time::{GameInstant, GameTime, SECONDS_PER_REALTIME_SECOND}; -use egregoria::Egregoria; use geom::Color; +use simulation::engine_interaction::WorldCommand; +use simulation::multiplayer::chat::{Message, MessageKind}; +use simulation::multiplayer::MultiplayerState; +use simulation::utils::time::{GameInstant, GameTime, SECONDS_PER_REALTIME_SECOND}; +use simulation::Simulation; use crate::inputmap::{InputAction, InputMap}; use crate::uiworld::UiWorld; @@ -17,15 +17,15 @@ pub struct GUIChatState { chat_bar_showed: bool, } -pub fn chat(ui: &egui::Context, uiw: &mut UiWorld, goria: &Egregoria) { +pub fn chat(ui: &egui::Context, uiw: &mut UiWorld, sim: &Simulation) { const MAX_MESSAGES: usize = 30; let mut state = uiw.write::(); let one_minute_ago = GameInstant { - timestamp: goria.read::().instant().timestamp + timestamp: sim.read::().instant().timestamp - 120.0 * SECONDS_PER_REALTIME_SECOND as f64, }; - let mstate = goria.read::(); + let mstate = sim.read::(); let just_opened = uiw .read::() @@ -109,7 +109,7 @@ pub fn chat(ui: &egui::Context, uiw: &mut UiWorld, goria: &Egregoria) { message: Message { name: "player".to_string(), text: msg, - sent_at: goria.read::().instant(), + sent_at: sim.read::().instant(), color: Color::WHITE, kind: MessageKind::PlayerChat, }, diff --git a/native_app/src/gui/follow.rs b/native_app/src/gui/follow.rs index 202482a9..31f089a9 100644 --- a/native_app/src/gui/follow.rs +++ b/native_app/src/gui/follow.rs @@ -1,7 +1,7 @@ use crate::game_loop::State; use crate::inputmap::{InputAction, InputMap}; -use egregoria::AnyEntity; use egui::Ui; +use simulation::AnyEntity; /// FollowEntity is a component that tells the camera to follow an entity /// Entity is defined by a function that returns the position of the entity @@ -39,7 +39,7 @@ impl FollowEntity { } if let Some(e) = state.uiw.read::().0 { - if let Some(pos) = state.goria.read().unwrap().pos_any(e) { + if let Some(pos) = state.sim.read().unwrap().pos_any(e) { state.uiw.camera_mut().follow(pos); } } diff --git a/native_app/src/gui/inspect/inspect_building.rs b/native_app/src/gui/inspect/inspect_building.rs index 63e51cb4..c39690cb 100644 --- a/native_app/src/gui/inspect/inspect_building.rs +++ b/native_app/src/gui/inspect/inspect_building.rs @@ -1,22 +1,22 @@ use crate::uiworld::UiWorld; -use egregoria::economy::{ItemRegistry, Market}; -use egregoria::engine_interaction::WorldCommand; -use egregoria::{Egregoria, SoulID}; use egui::{Context, Ui, Widget}; +use simulation::economy::{ItemRegistry, Market}; +use simulation::engine_interaction::WorldCommand; +use simulation::{Simulation, SoulID}; use crate::gui::inspect::entity_link; use crate::gui::item_icon; -use egregoria::map::{Building, BuildingID, BuildingKind, Zone, MAX_ZONE_AREA}; -use egregoria::map_dynamic::BuildingInfos; -use egregoria::souls::freight_station::FreightTrainState; -use egregoria::souls::goods_company::{GoodsCompanyRegistry, Recipe}; use egui_inspect::{Inspect, InspectArgs, InspectVec2Rotation}; +use simulation::map::{Building, BuildingID, BuildingKind, Zone, MAX_ZONE_AREA}; +use simulation::map_dynamic::BuildingInfos; +use simulation::souls::freight_station::FreightTrainState; +use simulation::souls::goods_company::{GoodsCompanyRegistry, Recipe}; /// Inspect a specific building, showing useful information about it -pub fn inspect_building(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: BuildingID) { - let map = goria.map(); +pub fn inspect_building(uiworld: &mut UiWorld, sim: &Simulation, ui: &Context, id: BuildingID) { + let map = sim.map(); let Some(building) = map.buildings().get(id) else { return; }; - let gregistry = goria.read::(); + let gregistry = sim.read::(); let title: &str = match building.kind { BuildingKind::House => "House", @@ -35,12 +35,12 @@ pub fn inspect_building(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, } match building.kind { - BuildingKind::House => render_house(ui, uiworld, goria, building), + BuildingKind::House => render_house(ui, uiworld, sim, building), BuildingKind::GoodsCompany(_) => { - render_goodscompany(ui, uiworld, goria, building); + render_goodscompany(ui, uiworld, sim, building); } BuildingKind::RailFreightStation => { - render_freightstation(ui, uiworld, goria, building); + render_freightstation(ui, uiworld, sim, building); } BuildingKind::TrainStation => {} BuildingKind::ExternalTrading => {} @@ -70,26 +70,26 @@ pub fn inspect_building(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, }); } -fn render_house(ui: &mut Ui, uiworld: &mut UiWorld, goria: &Egregoria, b: &Building) { - let binfos = goria.read::(); +fn render_house(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b: &Building) { + let binfos = sim.read::(); let Some(info) = binfos.get(b.id) else { return; }; let Some(SoulID::Human(owner)) = info.owner else { return; }; ui.horizontal(|ui| { ui.label("Owner"); - entity_link(uiworld, goria, ui, owner); + entity_link(uiworld, sim, ui, owner); }); ui.label("Currently in the house:"); for &soul in info.inside.iter() { let SoulID::Human(soul) = soul else { continue; }; - entity_link(uiworld, goria, ui, soul); + entity_link(uiworld, sim, ui, soul); } } -fn render_freightstation(ui: &mut Ui, uiworld: &mut UiWorld, goria: &Egregoria, b: &Building) { - let Some(SoulID::FreightStation(owner)) = goria.read::().owner(b.id) else { return; }; - let Some(freight) = goria.world().get(owner) else { return; }; +fn render_freightstation(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b: &Building) { + let Some(SoulID::FreightStation(owner)) = sim.read::().owner(b.id) else { return; }; + let Some(freight) = sim.world().get(owner) else { return; }; ui.label(format!("Waiting cargo: {}", freight.f.waiting_cargo)); ui.label(format!("Wanted cargo: {}", freight.f.wanted_cargo)); @@ -98,7 +98,7 @@ fn render_freightstation(ui: &mut Ui, uiworld: &mut UiWorld, goria: &Egregoria, ui.label("Trains:"); for (tid, state) in &freight.f.trains { ui.horizontal(|ui| { - entity_link(uiworld, goria, ui, *tid); + entity_link(uiworld, sim, ui, *tid); match state { FreightTrainState::Arriving => { ui.label("Arriving"); @@ -114,16 +114,16 @@ fn render_freightstation(ui: &mut Ui, uiworld: &mut UiWorld, goria: &Egregoria, } } -fn render_goodscompany(ui: &mut Ui, uiworld: &mut UiWorld, goria: &Egregoria, b: &Building) { - let owner = goria.read::().owner(b.id); +fn render_goodscompany(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b: &Building) { + let owner = sim.read::().owner(b.id); let Some(SoulID::GoodsCompany(c_id)) = owner else { return; }; - let Some(c) = goria.world().companies.get(c_id) else { return; }; + let Some(c) = sim.world().companies.get(c_id) else { return; }; let goods = &c.comp; let workers = &c.workers; - let market = goria.read::(); - let itemregistry = goria.read::(); + let market = sim.read::(); + let itemregistry = sim.read::(); let max_workers = goods.max_workers; egui::ProgressBar::new(workers.0.len() as f32 / max_workers as f32) .text(format!("workers: {}/{}", workers.0.len(), max_workers)) @@ -132,7 +132,7 @@ fn render_goodscompany(ui: &mut Ui, uiworld: &mut UiWorld, goria: &Egregoria, b: if let Some(driver) = goods.driver { ui.horizontal(|ui| { ui.label("Driver is"); - entity_link(uiworld, goria, ui, driver); + entity_link(uiworld, sim, ui, driver); }); } let productivity = goods.productivity(workers.0.len(), b.zone.as_ref()); @@ -144,7 +144,7 @@ fn render_goodscompany(ui: &mut Ui, uiworld: &mut UiWorld, goria: &Egregoria, b: .ui(ui); } - render_recipe(ui, uiworld, goria, &goods.recipe); + render_recipe(ui, uiworld, sim, &goods.recipe); egui::ProgressBar::new(goods.progress) .show_percentage() @@ -166,8 +166,8 @@ fn render_goodscompany(ui: &mut Ui, uiworld: &mut UiWorld, goria: &Egregoria, b: } } -fn render_recipe(ui: &mut Ui, uiworld: &UiWorld, goria: &Egregoria, recipe: &Recipe) { - let registry = goria.read::(); +fn render_recipe(ui: &mut Ui, uiworld: &UiWorld, sim: &Simulation, recipe: &Recipe) { + let registry = sim.read::(); if recipe.consumption.is_empty() { ui.label("No Inputs"); diff --git a/native_app/src/gui/inspect/inspect_debug.rs b/native_app/src/gui/inspect/inspect_debug.rs index 1da421ba..8050a85f 100644 --- a/native_app/src/gui/inspect/inspect_debug.rs +++ b/native_app/src/gui/inspect/inspect_debug.rs @@ -1,13 +1,13 @@ use crate::gui::follow::FollowEntity; use crate::uiworld::UiWorld; -use egregoria::economy::{ItemRegistry, Market}; -use egregoria::transportation::Location; -use egregoria::{ - AnyEntity, CompanyEnt, Egregoria, FreightStationEnt, HumanEnt, SoulID, TrainEnt, VehicleEnt, - WagonEnt, -}; use egui::Ui; use egui_inspect::{Inspect, InspectArgs}; +use simulation::economy::{ItemRegistry, Market}; +use simulation::transportation::Location; +use simulation::{ + AnyEntity, CompanyEnt, FreightStationEnt, HumanEnt, Simulation, SoulID, TrainEnt, VehicleEnt, + WagonEnt, +}; /// Inspect window /// Allows to inspect an entity @@ -16,7 +16,7 @@ pub struct InspectRenderer { } impl InspectRenderer { - pub fn render(&mut self, uiworld: &mut UiWorld, goria: &Egregoria, ui: &mut Ui) { + pub fn render(&mut self, uiworld: &mut UiWorld, sim: &Simulation, ui: &mut Ui) { let entity = self.entity; ui.label(format!("{:?}", self.entity)); @@ -27,32 +27,32 @@ impl InspectRenderer { match entity { AnyEntity::VehicleID(x) => { - >::render(goria.get(x).unwrap(), "", ui, &args) + >::render(sim.get(x).unwrap(), "", ui, &args) } AnyEntity::TrainID(x) => { - >::render(goria.get(x).unwrap(), "", ui, &args) + >::render(sim.get(x).unwrap(), "", ui, &args) } AnyEntity::WagonID(x) => { - >::render(goria.get(x).unwrap(), "", ui, &args) + >::render(sim.get(x).unwrap(), "", ui, &args) } AnyEntity::FreightStationID(x) => { >::render( - goria.get(x).unwrap(), + sim.get(x).unwrap(), "", ui, &args, ) } AnyEntity::CompanyID(x) => { - >::render(goria.get(x).unwrap(), "", ui, &args) + >::render(sim.get(x).unwrap(), "", ui, &args) } AnyEntity::HumanID(x) => { - >::render(goria.get(x).unwrap(), "", ui, &args) + >::render(sim.get(x).unwrap(), "", ui, &args) } } if let AnyEntity::VehicleID(id) = entity { - for (hid, h) in goria.world().humans.iter() { + for (hid, h) in sim.world().humans.iter() { if h.location == Location::Vehicle(id) && ui .small_button(&*format!("inspect inside vehicle: {hid:?}")) @@ -65,8 +65,8 @@ impl InspectRenderer { } /* - if let Some(coll) = goria.comp::(self.entity) { - if let Some((pos, po)) = goria.read::().get(coll.0) { + if let Some(coll) = sim.comp::(self.entity) { + if let Some((pos, po)) = sim.read::().get(coll.0) { egui::CollapsingHeader::new("Physics Object").show(ui, |ui| { >::render(&pos, "pos", ui, &InspectArgs::default()); >::render( @@ -96,8 +96,8 @@ impl InspectRenderer { } if let Ok(soul) = SoulID::try_from(entity) { - let market = goria.read::(); - let registry = goria.read::(); + let market = sim.read::(); + let registry = sim.read::(); let mut capitals = vec![]; let mut borders = vec![]; let mut sellorders = vec![]; diff --git a/native_app/src/gui/inspect/inspect_human.rs b/native_app/src/gui/inspect/inspect_human.rs index f3536bed..cadc1092 100644 --- a/native_app/src/gui/inspect/inspect_human.rs +++ b/native_app/src/gui/inspect/inspect_human.rs @@ -1,18 +1,18 @@ use egui::{Context, Widget}; -use egregoria::economy::{ItemRegistry, Market}; -use egregoria::map_dynamic::Destination; -use egregoria::souls::desire::WorkKind; -use egregoria::transportation::Location; -use egregoria::{Egregoria, HumanID}; +use simulation::economy::{ItemRegistry, Market}; +use simulation::map_dynamic::Destination; +use simulation::souls::desire::WorkKind; +use simulation::transportation::Location; +use simulation::{HumanID, Simulation}; use crate::gui::inspect::{building_link, follow_button}; use crate::gui::item_icon; use crate::uiworld::UiWorld; /// Inspect a specific building, showing useful information about it -pub fn inspect_human(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: HumanID) -> bool { - let Some(human) = goria.get(id) else { return false; }; +pub fn inspect_human(uiworld: &mut UiWorld, sim: &Simulation, ui: &Context, id: HumanID) -> bool { + let Some(human) = sim.get(id) else { return false; }; let mut is_open = true; egui::Window::new("Human") @@ -34,7 +34,7 @@ pub fn inspect_human(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: Location::Building(x) => { ui.horizontal(|ui| { ui.label("In a building:"); - building_link(uiworld, goria, ui, x); + building_link(uiworld, sim, ui, x); }); } } @@ -47,7 +47,7 @@ pub fn inspect_human(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: Destination::Building(b) => { ui.horizontal(|ui| { ui.label("Going to building"); - building_link(uiworld, goria, ui, *b); + building_link(uiworld, sim, ui, *b); }); } } @@ -55,7 +55,7 @@ pub fn inspect_human(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: ui.horizontal(|ui| { ui.label("House is"); - building_link(uiworld, goria, ui, human.home.house); + building_link(uiworld, sim, ui, human.home.house); }); ui.label(format!("Last ate: {}", human.food.last_ate)); @@ -63,7 +63,7 @@ pub fn inspect_human(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: if let Some(ref x) = human.work { ui.horizontal(|ui| { ui.label("Working at"); - building_link(uiworld, goria, ui, x.workplace); + building_link(uiworld, sim, ui, x.workplace); match x.kind { WorkKind::Driver { .. } => { ui.label("as a driver"); @@ -93,8 +93,8 @@ pub fn inspect_human(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: ui.label("Work"); }); - let market = goria.read::(); - let itemregistry = goria.read::(); + let market = sim.read::(); + let itemregistry = sim.read::(); ui.add_space(10.0); diff --git a/native_app/src/gui/inspect/inspect_train.rs b/native_app/src/gui/inspect/inspect_train.rs index 67c07be0..ca931189 100644 --- a/native_app/src/gui/inspect/inspect_train.rs +++ b/native_app/src/gui/inspect/inspect_train.rs @@ -1,10 +1,10 @@ use crate::gui::inspect::follow_button; use crate::uiworld::UiWorld; -use egregoria::{Egregoria, TrainID}; use egui::Context; +use simulation::{Simulation, TrainID}; -pub fn inspect_train(uiworld: &mut UiWorld, goria: &Egregoria, ui: &Context, id: TrainID) -> bool { - let Some(t) = goria.get(id) else { return false; }; +pub fn inspect_train(uiworld: &mut UiWorld, sim: &Simulation, ui: &Context, id: TrainID) -> bool { + let Some(t) = sim.get(id) else { return false; }; let mut is_open = true; egui::Window::new("Train") diff --git a/native_app/src/gui/inspect/inspect_vehicle.rs b/native_app/src/gui/inspect/inspect_vehicle.rs index c9e099b1..2f32869e 100644 --- a/native_app/src/gui/inspect/inspect_vehicle.rs +++ b/native_app/src/gui/inspect/inspect_vehicle.rs @@ -1,16 +1,16 @@ use crate::gui::inspect::{entity_link, follow_button}; use crate::uiworld::UiWorld; -use egregoria::transportation::VehicleState; -use egregoria::{Egregoria, VehicleID}; use egui::Context; +use simulation::transportation::VehicleState; +use simulation::{Simulation, VehicleID}; pub fn inspect_vehicle( uiworld: &mut UiWorld, - goria: &Egregoria, + sim: &Simulation, ui: &Context, id: VehicleID, ) -> bool { - let Some(v) = goria.get(id) else { return false; }; + let Some(v) = sim.get(id) else { return false; }; let name = format!("{:?}", v.vehicle.kind); @@ -39,11 +39,11 @@ pub fn inspect_vehicle( } } - for (human_id, human) in &goria.world().humans { + for (human_id, human) in &sim.world().humans { if human.router.personal_car == Some(id) { ui.horizontal(|ui| { ui.label("Owned by"); - entity_link(uiworld, goria, ui, human_id); + entity_link(uiworld, sim, ui, human_id); }); } } diff --git a/native_app/src/gui/inspect/mod.rs b/native_app/src/gui/inspect/mod.rs index fa1f6986..d46e357a 100644 --- a/native_app/src/gui/inspect/mod.rs +++ b/native_app/src/gui/inspect/mod.rs @@ -2,13 +2,13 @@ use crate::gui::inspect::inspect_train::inspect_train; use crate::gui::windows::debug::DebugState; use crate::gui::{FollowEntity, InspectedBuilding, InspectedEntity}; use crate::uiworld::UiWorld; -use egregoria::map::BuildingID; -use egregoria::{AnyEntity, Egregoria}; use egui::{Context, Ui, Window}; use inspect_building::inspect_building; use inspect_debug::InspectRenderer; use inspect_human::inspect_human; use inspect_vehicle::inspect_vehicle; +use simulation::map::BuildingID; +use simulation::{AnyEntity, Simulation}; use slotmapd::Key; mod inspect_building; @@ -17,11 +17,11 @@ mod inspect_human; mod inspect_train; mod inspect_vehicle; -pub fn inspector(ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { +pub fn inspector(ui: &Context, uiworld: &mut UiWorld, sim: &Simulation) { profiling::scope!("topgui::inspector"); let inspected_building = *uiworld.read::(); if let Some(b) = inspected_building.e { - inspect_building(uiworld, goria, ui, b); + inspect_building(uiworld, sim, ui, b); } let e = unwrap_or!(uiworld.read::().e, return); @@ -31,18 +31,18 @@ pub fn inspector(ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { let mut is_open = true; match e { AnyEntity::HumanID(id) if !force_debug_inspect => { - is_open = inspect_human(uiworld, goria, ui, id); + is_open = inspect_human(uiworld, sim, ui, id); } AnyEntity::VehicleID(id) if !force_debug_inspect => { - is_open = inspect_vehicle(uiworld, goria, ui, id); + is_open = inspect_vehicle(uiworld, sim, ui, id); } AnyEntity::WagonID(id) if !force_debug_inspect => { - let Some(w) = goria.world().get(id) else { return; }; + let Some(w) = sim.world().get(id) else { return; }; let train_id = w.itfollower.leader; uiworld.write::().e = Some(AnyEntity::TrainID(train_id)); } AnyEntity::TrainID(id) if !force_debug_inspect => { - is_open = inspect_train(uiworld, goria, ui, id); + is_open = inspect_train(uiworld, sim, ui, id); } _ => { Window::new("Inspect") @@ -52,7 +52,7 @@ pub fn inspector(ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { .open(&mut is_open) .show(ui, |ui| { let mut ins = InspectRenderer { entity: e }; - ins.render(uiworld, goria, ui); + ins.render(uiworld, sim, ui); uiworld.write::().e = Some(ins.entity); }); } @@ -63,23 +63,23 @@ pub fn inspector(ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { } } -pub fn building_link(uiworld: &mut UiWorld, goria: &Egregoria, ui: &mut Ui, b: BuildingID) { +pub fn building_link(uiworld: &mut UiWorld, sim: &Simulation, ui: &mut Ui, b: BuildingID) { if ui.link(format!("{:?}", b.data())).clicked() { uiworld.write::().e = Some(b); - if let Some(b) = goria.map().buildings().get(b) { + if let Some(b) = sim.map().buildings().get(b) { uiworld.camera_mut().targetpos = b.door_pos; } } } -pub fn entity_link(uiworld: &mut UiWorld, goria: &Egregoria, ui: &mut Ui, e: impl Into) { - entity_link_inner(uiworld, goria, ui, e.into()) +pub fn entity_link(uiworld: &mut UiWorld, sim: &Simulation, ui: &mut Ui, e: impl Into) { + entity_link_inner(uiworld, sim, ui, e.into()) } -fn entity_link_inner(uiworld: &mut UiWorld, goria: &Egregoria, ui: &mut Ui, e: AnyEntity) { +fn entity_link_inner(uiworld: &mut UiWorld, sim: &Simulation, ui: &mut Ui, e: AnyEntity) { let linkname = match e { AnyEntity::HumanID(id) => { - if let Some(human) = goria.world().humans.get(id) { + if let Some(human) = sim.world().humans.get(id) { human.personal_info.name.to_string() } else { "???".to_string() @@ -90,7 +90,7 @@ fn entity_link_inner(uiworld: &mut UiWorld, goria: &Egregoria, ui: &mut Ui, e: A if ui.link(linkname).clicked() { uiworld.write::().e = Some(e); - if goria.pos_any(e).is_some() { + if sim.pos_any(e).is_some() { uiworld.write::().0 = Some(e); } } diff --git a/native_app/src/gui/inspected_aura.rs b/native_app/src/gui/inspected_aura.rs index 886462be..81b7638c 100644 --- a/native_app/src/gui/inspected_aura.rs +++ b/native_app/src/gui/inspected_aura.rs @@ -2,26 +2,26 @@ use crate::gui::selectable::select_radius; use crate::gui::{InspectedBuilding, InspectedEntity}; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; -use egregoria::transportation::Location; -use egregoria::{AnyEntity, Egregoria}; use geom::Color; +use simulation::transportation::Location; +use simulation::{AnyEntity, Simulation}; /// InspectedAura shows the circle around the inspected entity -pub fn inspected_aura(goria: &Egregoria, uiworld: &mut UiWorld) { +pub fn inspected_aura(sim: &Simulation, uiworld: &mut UiWorld) { profiling::scope!("gui::inspected_aura"); let inspected = uiworld.write::(); let inspected_b = uiworld.write::(); - let map = goria.map(); + let map = sim.map(); let mut draw = uiworld.write::(); if let Some(sel) = inspected.e { - let mut pos = goria.pos_any(sel); + let mut pos = sim.pos_any(sel); if let AnyEntity::HumanID(id) = sel { - let loc = &goria.world().get(id).unwrap().location; + let loc = &sim.world().get(id).unwrap().location; match *loc { Location::Outside => {} - Location::Vehicle(v) => pos = goria.pos(v), + Location::Vehicle(v) => pos = sim.pos(v), Location::Building(b) => pos = map.buildings().get(b).map(|b| b.door_pos), } } @@ -45,6 +45,6 @@ pub fn inspected_aura(goria: &Egregoria, uiworld: &mut UiWorld) { } draw.obb(b.obb, b.height + 0.01) - .color(egregoria::config().gui_primary); + .color(simulation::config().gui_primary); } } diff --git a/native_app/src/gui/lotbrush.rs b/native_app/src/gui/lotbrush.rs index d7879e1c..519c2111 100644 --- a/native_app/src/gui/lotbrush.rs +++ b/native_app/src/gui/lotbrush.rs @@ -2,9 +2,9 @@ use super::Tool; use crate::inputmap::{InputAction, InputMap}; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; -use egregoria::map::{LotKind, ProjectFilter, ProjectKind}; -use egregoria::Egregoria; use serde::{Deserialize, Serialize}; +use simulation::map::{LotKind, ProjectFilter, ProjectKind}; +use simulation::Simulation; #[derive(Serialize, Deserialize)] pub struct LotBrushResource { @@ -14,13 +14,13 @@ pub struct LotBrushResource { /// Lot brush tool /// Allows to build houses on lots -pub fn lotbrush(goria: &Egregoria, uiworld: &mut UiWorld) { +pub fn lotbrush(sim: &Simulation, uiworld: &mut UiWorld) { profiling::scope!("gui::lotbrush"); let res = uiworld.read::(); let tool = *uiworld.read::(); let inp = uiworld.read::(); let mut draw = uiworld.write::(); - let map = goria.map(); + let map = sim.map(); let commands = &mut *uiworld.commands(); if !matches!(tool, Tool::LotBrush) { @@ -30,8 +30,8 @@ pub fn lotbrush(goria: &Egregoria, uiworld: &mut UiWorld) { let kind = res.kind; let mut col = match kind { - LotKind::Unassigned => egregoria::config().lot_unassigned_col, - LotKind::Residential => egregoria::config().lot_residential_col, + LotKind::Unassigned => simulation::config().lot_unassigned_col, + LotKind::Residential => simulation::config().lot_residential_col, }; col.a = 0.2; diff --git a/native_app/src/gui/mod.rs b/native_app/src/gui/mod.rs index 65d5f2fc..4be6de74 100644 --- a/native_app/src/gui/mod.rs +++ b/native_app/src/gui/mod.rs @@ -6,10 +6,10 @@ use egui::{ColorImage, ImageData, TextureHandle, TextureId, TextureOptions}; use serde::{Deserialize, Serialize}; use crate::uiworld::UiWorld; -use egregoria::engine_interaction::WorldCommand; -use egregoria::map::BuildingID; -use egregoria::{AnyEntity, Egregoria}; use roadbuild::RoadBuildResource; +use simulation::engine_interaction::WorldCommand; +use simulation::map::BuildingID; +use simulation::{AnyEntity, Simulation}; pub mod addtrain; pub mod bulldozer; @@ -29,19 +29,19 @@ pub mod zoneedit; pub use follow::FollowEntity; pub use topgui::*; -pub fn run_ui_systems(goria: &Egregoria, uiworld: &mut UiWorld) { +pub fn run_ui_systems(sim: &Simulation, uiworld: &mut UiWorld) { profiling::scope!("gui::run_ui_systems"); - bulldozer::bulldozer(goria, uiworld); - inspected_aura::inspected_aura(goria, uiworld); - lotbrush::lotbrush(goria, uiworld); - roadbuild::roadbuild(goria, uiworld); - roadeditor::roadeditor(goria, uiworld); - specialbuilding::specialbuilding(goria, uiworld); - addtrain::addtrain(goria, uiworld); - zoneedit::zoneedit(goria, uiworld); + bulldozer::bulldozer(sim, uiworld); + inspected_aura::inspected_aura(sim, uiworld); + lotbrush::lotbrush(sim, uiworld); + roadbuild::roadbuild(sim, uiworld); + roadeditor::roadeditor(sim, uiworld); + specialbuilding::specialbuilding(sim, uiworld); + addtrain::addtrain(sim, uiworld); + zoneedit::zoneedit(sim, uiworld); // run last so other systems can have the chance to cancel select - selectable::selectable(goria, uiworld); + selectable::selectable(sim, uiworld); } #[derive(Default, Clone, Debug)] diff --git a/native_app/src/gui/roadbuild.rs b/native_app/src/gui/roadbuild.rs index c0b207b8..06f645bf 100644 --- a/native_app/src/gui/roadbuild.rs +++ b/native_app/src/gui/roadbuild.rs @@ -3,13 +3,13 @@ use crate::inputmap::{InputAction, InputMap}; use crate::rendering::immediate::{ImmediateDraw, ImmediateSound}; use crate::uiworld::UiWorld; use common::AudioKind; -use egregoria::engine_interaction::{WorldCommand, WorldCommands}; -use egregoria::map::{ - Intersection, LanePatternBuilder, Map, MapProject, ProjectFilter, ProjectKind, PylonPosition, -}; -use egregoria::Egregoria; use geom::{BoldLine, BoldSpline, Camera, PolyLine, ShapeEnum, Spline}; use geom::{PolyLine3, Spline3, Vec2, Vec3}; +use simulation::engine_interaction::{WorldCommand, WorldCommands}; +use simulation::map::{ + Intersection, LanePatternBuilder, Map, MapProject, ProjectFilter, ProjectKind, PylonPosition, +}; +use simulation::Simulation; use BuildState::{Hover, Interpolation, Start}; use ProjectKind::{Building, Ground, Inter, Road}; @@ -31,7 +31,7 @@ pub struct RoadBuildResource { /// Road building tool /// Allows to build roads and intersections -pub fn roadbuild(goria: &Egregoria, uiworld: &mut UiWorld) { +pub fn roadbuild(sim: &Simulation, uiworld: &mut UiWorld) { profiling::scope!("gui::roadbuild"); let state = &mut *uiworld.write::(); let immdraw = &mut *uiworld.write::(); @@ -39,7 +39,7 @@ pub fn roadbuild(goria: &Egregoria, uiworld: &mut UiWorld) { let potential_command = &mut *uiworld.write::(); let mut inp = uiworld.write::(); let tool = *uiworld.read::(); - let map = &*goria.map(); + let map = &*sim.map(); let commands: &mut WorldCommands = &mut uiworld.commands(); let cam = &*uiworld.read::(); @@ -67,7 +67,7 @@ pub fn roadbuild(goria: &Egregoria, uiworld: &mut UiWorld) { if state.snap_to_grid && log_camheight < cutoff { let alpha = 1.0 - log_camheight / cutoff; - let col = egregoria::config().gui_primary.a(alpha); + let col = simulation::config().gui_primary.a(alpha); let screen = AABB::new(unproj.xy(), unproj.xy()).expand(300.0); let startx = (screen.ll.x / grid_size).ceil() * grid_size; let starty = (screen.ll.y / grid_size).ceil() * grid_size; @@ -362,9 +362,9 @@ impl RoadBuildResource { let mut proj_pos = proj.pos; proj_pos.z += 0.1; let col = if is_valid { - egregoria::config().gui_primary + simulation::config().gui_primary } else { - egregoria::config().gui_danger + simulation::config().gui_danger }; let interf = |ang: Vec2, proj: MapProject| match proj.kind { @@ -438,7 +438,7 @@ impl RoadBuildResource { terrain_height, pos, .. - } in egregoria::map::Road::pylons_positions(&p, &map.terrain) + } in simulation::map::Road::pylons_positions(&p, &map.terrain) { immdraw .circle(pos.xy().z(terrain_height + 0.1), patwidth * 0.5) diff --git a/native_app/src/gui/roadeditor.rs b/native_app/src/gui/roadeditor.rs index 3ecea9ae..087c45f0 100644 --- a/native_app/src/gui/roadeditor.rs +++ b/native_app/src/gui/roadeditor.rs @@ -2,10 +2,10 @@ use crate::gui::Tool; use crate::inputmap::{InputAction, InputMap}; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; -use egregoria::map::{IntersectionID, LightPolicy, TurnPolicy}; -use egregoria::map::{ProjectFilter, ProjectKind}; -use egregoria::Egregoria; use geom::Color; +use simulation::map::{IntersectionID, LightPolicy, TurnPolicy}; +use simulation::map::{ProjectFilter, ProjectKind}; +use simulation::Simulation; #[derive(Clone)] pub struct IntersectionComponent { @@ -22,13 +22,13 @@ pub struct RoadEditorResource { /// RoadEditor tool /// Allows to edit intersections properties like turns and signals -pub fn roadeditor(goria: &Egregoria, uiworld: &mut UiWorld) { +pub fn roadeditor(sim: &Simulation, uiworld: &mut UiWorld) { profiling::scope!("gui::roadeditor"); let tool = uiworld.read::(); let inp = uiworld.read::(); let mut state = uiworld.write::(); let mut imm_draw = uiworld.write::(); - let map = goria.map(); + let map = sim.map(); let commands = &mut *uiworld.commands(); if !matches!(*tool, Tool::RoadEditor) { @@ -68,14 +68,14 @@ pub fn roadeditor(goria: &Egregoria, uiworld: &mut UiWorld) { if Some(id) != state.inspect.as_ref().map(|x| x.id) { proj_pos = cur_proj.pos; } - proj_col = egregoria::config().gui_primary; + proj_col = simulation::config().gui_primary; } else { - proj_col = egregoria::config().gui_disabled; + proj_col = simulation::config().gui_disabled; } if inp.act.contains(&InputAction::Select) { if let ProjectKind::Inter(id) = cur_proj.kind { - proj_col = egregoria::config().gui_success; + proj_col = simulation::config().gui_success; proj_pos = cur_proj.pos; let inter = &map.intersections()[id]; state.inspect = Some(IntersectionComponent { diff --git a/native_app/src/gui/selectable.rs b/native_app/src/gui/selectable.rs index 27d18e49..cddecf1e 100644 --- a/native_app/src/gui/selectable.rs +++ b/native_app/src/gui/selectable.rs @@ -1,9 +1,9 @@ use crate::gui::{InspectedBuilding, InspectedEntity, Tool}; use crate::inputmap::{InputAction, InputMap}; use crate::uiworld::UiWorld; -use egregoria::map::ProjectFilter; -use egregoria::{AnyEntity, Egregoria}; use geom::Vec2; +use simulation::map::ProjectFilter; +use simulation::{AnyEntity, Simulation}; pub fn select_radius(id: AnyEntity) -> f32 { match id { @@ -17,7 +17,7 @@ pub fn select_radius(id: AnyEntity) -> f32 { } /// Selectable allows to select entities by clicking on them -pub fn selectable(goria: &Egregoria, uiworld: &mut UiWorld) { +pub fn selectable(sim: &Simulation, uiworld: &mut UiWorld) { profiling::scope!("gui::selectable"); let mut inspected = uiworld.write::(); let mut inspected_b = uiworld.write::(); @@ -30,7 +30,7 @@ pub fn selectable(goria: &Egregoria, uiworld: &mut UiWorld) { { let unproj = unwrap_ret!(inp.unprojected); - let w = goria.world(); + let w = sim.world(); inspected.dist2 = f32::INFINITY; inspected.e = None; @@ -54,7 +54,7 @@ pub fn selectable(goria: &Egregoria, uiworld: &mut UiWorld) { inspected_b.e = None; if inspected.e.is_none() { let unproj = unwrap_ret!(inp.unprojected); - let map = goria.map(); + let map = sim.map(); inspected_b.e = map .spatial_map() .query(unproj.xy(), ProjectFilter::BUILDING) @@ -65,13 +65,13 @@ pub fn selectable(goria: &Egregoria, uiworld: &mut UiWorld) { inspected_b.dontclear = false; if let Some(e) = inspected.e { - if !goria.world().contains(e) { + if !sim.world().contains(e) { inspected.e = None; } } if let Some(b) = inspected_b.e { - if !goria.map().buildings().contains_key(b) { + if !sim.map().buildings().contains_key(b) { inspected_b.e = None; } } diff --git a/native_app/src/gui/specialbuilding.rs b/native_app/src/gui/specialbuilding.rs index 33c80d5a..733c082f 100644 --- a/native_app/src/gui/specialbuilding.rs +++ b/native_app/src/gui/specialbuilding.rs @@ -4,11 +4,11 @@ use crate::inputmap::{InputAction, InputMap}; use crate::rendering::immediate::{ImmediateDraw, ImmediateSound}; use crate::uiworld::UiWorld; use common::AudioKind; -use egregoria::engine_interaction::WorldCommand; -use egregoria::map::{ProjectFilter, ProjectKind}; -use egregoria::Egregoria; use geom::{Degrees, Intersect, Vec3, OBB}; use ordered_float::OrderedFloat; +use simulation::engine_interaction::WorldCommand; +use simulation::map::{ProjectFilter, ProjectKind}; +use simulation::Simulation; use std::borrow::Cow; pub struct SpecialBuildArgs { @@ -33,7 +33,7 @@ pub struct SpecialBuildingResource { /// SpecialBuilding tool /// Allows to build special buildings like farms, factories, etc. -pub fn specialbuilding(goria: &Egregoria, uiworld: &mut UiWorld) { +pub fn specialbuilding(sim: &Simulation, uiworld: &mut UiWorld) { profiling::scope!("gui::specialbuilding"); let mut state = uiworld.write::(); let tool = *uiworld.read::(); @@ -41,7 +41,7 @@ pub fn specialbuilding(goria: &Egregoria, uiworld: &mut UiWorld) { let mut draw = uiworld.write::(); let mut sound = uiworld.write::(); - let map = goria.map(); + let map = sim.map(); let commands = &mut *uiworld.commands(); @@ -87,9 +87,9 @@ pub fn specialbuilding(goria: &Egregoria, uiworld: &mut UiWorld) { let mut draw = |obb, red| { let p = asset.to_string(); let col = if red { - egregoria::config().special_building_invalid_col + simulation::config().special_building_invalid_col } else { - egregoria::config().special_building_col + simulation::config().special_building_col }; if p.ends_with(".png") || p.ends_with(".jpg") { diff --git a/native_app/src/gui/topgui.rs b/native_app/src/gui/topgui.rs index 7aa20917..0e920a59 100644 --- a/native_app/src/gui/topgui.rs +++ b/native_app/src/gui/topgui.rs @@ -10,14 +10,6 @@ use crate::gui::{ErrorTooltip, PotentialCommands, RoadBuildResource, Tool, UiTex use crate::inputmap::{InputAction, InputMap}; use crate::uiworld::{SaveLoadState, UiWorld}; use common::saveload::Encoder; -use egregoria::economy::{Government, Item, ItemRegistry, Money}; -use egregoria::engine_interaction::WorldCommand; -use egregoria::map::{ - BuildingGen, BuildingKind, LanePatternBuilder, LightPolicy, MapProject, TurnPolicy, Zone, -}; -use egregoria::souls::goods_company::GoodsCompanyRegistry; -use egregoria::utils::time::{GameTime, SECONDS_PER_HOUR}; -use egregoria::Egregoria; use egui::{ Align2, Color32, Context, Frame, Id, LayerId, Response, RichText, Rounding, Stroke, Style, Ui, Widget, Window, @@ -25,6 +17,14 @@ use egui::{ use egui_inspect::{Inspect, InspectArgs}; use geom::{Polygon, Vec2}; use serde::{Deserialize, Serialize}; +use simulation::economy::{Government, Item, ItemRegistry, Money}; +use simulation::engine_interaction::WorldCommand; +use simulation::map::{ + BuildingGen, BuildingKind, LanePatternBuilder, LightPolicy, MapProject, TurnPolicy, Zone, +}; +use simulation::souls::goods_company::GoodsCompanyRegistry; +use simulation::utils::time::{GameTime, SECONDS_PER_HOUR}; +use simulation::Simulation; use std::sync::atomic::Ordering; use std::time::{Duration, Instant}; @@ -68,7 +68,7 @@ impl Gui { } /// Root GUI entrypoint - pub fn render(&mut self, ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { + pub fn render(&mut self, ui: &Context, uiworld: &mut UiWorld, sim: &Simulation) { profiling::scope!("topgui::render"); self.auto_save(uiworld); @@ -76,22 +76,22 @@ impl Gui { return; } - self.time_controls(ui, uiworld, goria); + self.time_controls(ui, uiworld, sim); - self.menu_bar(ui, uiworld, goria); + self.menu_bar(ui, uiworld, sim); - inspector(ui, uiworld, goria); + inspector(ui, uiworld, sim); - chat(ui, uiworld, goria); + chat(ui, uiworld, sim); - self.windows.render(ui, uiworld, goria); + self.windows.render(ui, uiworld, sim); - Self::toolbox(ui, uiworld, goria); + Self::toolbox(ui, uiworld, sim); - self.tooltip(ui, uiworld, goria); + self.tooltip(ui, uiworld, sim); } - pub fn tooltip(&mut self, ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { + pub fn tooltip(&mut self, ui: &Context, uiworld: &mut UiWorld, sim: &Simulation) { profiling::scope!("gui::tooltip"); let tooltip = std::mem::take(&mut *uiworld.write::()); if let Some(msg) = tooltip.msg { @@ -112,7 +112,7 @@ impl Gui { let pot = &mut uiworld.write::().0; let cost: Money = pot .drain(..) - .map(|cmd| Government::action_cost(&cmd, goria)) + .map(|cmd| Government::action_cost(&cmd, sim)) .sum(); if cost == Money::default() { @@ -120,7 +120,7 @@ impl Gui { } egui::show_tooltip(ui, Id::new("tooltip_command_cost"), |ui| { - if cost > goria.read::().money { + if cost > sim.read::().money { ui.colored_label(Color32::RED, format!("{cost} too expensive")); } else { ui.label(cost.to_string()); @@ -148,7 +148,7 @@ impl Gui { } } - pub fn toolbox(ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { + pub fn toolbox(ui: &Context, uiworld: &mut UiWorld, sim: &Simulation) { profiling::scope!("topgui::toolbox"); #[derive(Copy, Clone)] pub enum Tab { @@ -510,10 +510,10 @@ impl Gui { } let building_select_w = 200.0; - let registry = goria.read::(); + let registry = sim.read::(); let gbuildings = registry.descriptions.values().peekable(); - let iregistry = goria.read::(); + let iregistry = sim.read::(); if matches!(*uiworld.read::(), Tab::Roadbuilding) { Window::new("Buildings") @@ -606,9 +606,9 @@ impl Gui { } } - pub fn time_controls(&mut self, ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { + pub fn time_controls(&mut self, ui: &Context, uiworld: &mut UiWorld, sim: &Simulation) { profiling::scope!("topgui::time_controls"); - let time = goria.read::().daytime; + let time = sim.read::().daytime; let warp = &mut uiworld.write::().time_warp; let depause_warp = &mut self.depause_warp; if uiworld @@ -684,7 +684,7 @@ impl Gui { }); } - pub fn menu_bar(&mut self, ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { + pub fn menu_bar(&mut self, ui: &Context, uiworld: &mut UiWorld, sim: &Simulation) { profiling::scope!("topgui::menu_bar"); //let _t = ui.push_style_var(StyleVar::ItemSpacing([3.0, 0.0])); @@ -706,7 +706,7 @@ impl Gui { uiworld.save_to_disk(); } - ui.label(format!("Money: {}", goria.read::().money)); + ui.label(format!("Money: {}", sim.read::().money)); let mut estate = uiworld.write::(); diff --git a/native_app/src/gui/windows/config.rs b/native_app/src/gui/windows/config.rs index 19e243bc..f1f97921 100644 --- a/native_app/src/gui/windows/config.rs +++ b/native_app/src/gui/windows/config.rs @@ -1,16 +1,16 @@ use crate::uiworld::UiWorld; -use egregoria::Config; -use egregoria::Egregoria; use egui_inspect::{Inspect, InspectArgs}; +use simulation::Config; +use simulation::Simulation; /// Config window /// Allows to change the real-time dev-only config -pub fn config(window: egui::Window<'_>, ui: &egui::Context, _: &mut UiWorld, _: &Egregoria) { +pub fn config(window: egui::Window<'_>, ui: &egui::Context, _: &mut UiWorld, _: &Simulation) { window .default_size([600.0, 500.0]) .vscroll(true) .show(ui, |ui| { - let mut config = (**egregoria::config()).clone(); + let mut config = (**simulation::config()).clone(); let args = InspectArgs { header: Some(false), @@ -18,7 +18,7 @@ pub fn config(window: egui::Window<'_>, ui: &egui::Context, _: &mut UiWorld, _: ..InspectArgs::default() }; if >::render_mut(&mut config, "", ui, &args) { - egregoria::update_config(config); + simulation::update_config(config); } }); } diff --git a/native_app/src/gui/windows/debug.rs b/native_app/src/gui/windows/debug.rs index abbfbd0d..d66609f5 100644 --- a/native_app/src/gui/windows/debug.rs +++ b/native_app/src/gui/windows/debug.rs @@ -3,20 +3,20 @@ use crate::game_loop::Timings; use crate::gui::InspectedEntity; use crate::uiworld::UiWorld; -use egregoria::map_dynamic::ParkingManagement; -use egregoria::physics::CollisionWorld; -use egregoria::utils::time::{GameTime, Tick, SECONDS_PER_DAY}; -use egregoria::{Egregoria, TrainID}; +use simulation::map_dynamic::ParkingManagement; +use simulation::physics::CollisionWorld; +use simulation::utils::time::{GameTime, Tick, SECONDS_PER_DAY}; +use simulation::{Simulation, TrainID}; use crate::inputmap::InputMap; -use egregoria::engine_interaction::WorldCommand; -use egregoria::map::{ - IntersectionID, Map, MapSubscriber, RoadSegmentKind, TraverseKind, UpdateType, -}; -use egregoria::transportation::train::TrainReservations; use egui::Widget; use engine::Tesselator; use geom::{Camera, Color, LinearColor, Spline3, Vec2}; +use simulation::engine_interaction::WorldCommand; +use simulation::map::{ + IntersectionID, Map, MapSubscriber, RoadSegmentKind, TraverseKind, UpdateType, +}; +use simulation::transportation::train::TrainReservations; #[derive(Default)] pub struct DebugState { @@ -28,7 +28,7 @@ pub struct DebugObjs( pub Vec<( bool, &'static str, - fn(&mut Tesselator, &Egregoria, &UiWorld) -> Option<()>, + fn(&mut Tesselator, &Simulation, &UiWorld) -> Option<()>, )>, ); @@ -68,7 +68,7 @@ pub fn debug( window: egui::Window<'_>, ui: &egui::Context, uiworld: &mut UiWorld, - goria: &Egregoria, + sim: &Simulation, ) { window.show(ui, |ui| { let mut objs = uiworld.write::(); @@ -81,8 +81,8 @@ pub fn debug( ); drop(objs); - let time = goria.read::().timestamp; - let daysecleft = SECONDS_PER_DAY - goria.read::().daytime.daysec(); + let time = sim.read::().timestamp; + let daysecleft = SECONDS_PER_DAY - sim.read::().daytime.daysec(); if ui.small_button("set night").clicked() { uiworld @@ -113,10 +113,10 @@ pub fn debug( ui.label(format!( "World timestamp: {:.1}", - goria.read::().timestamp + sim.read::().timestamp )); - ui.label(format!("Tick: {}", goria.read::().0)); + ui.label(format!("Tick: {}", sim.read::().0)); let timings = uiworld.read::(); let mouse = uiworld.read::().unprojected; @@ -171,8 +171,8 @@ pub fn debug( ); } - ui.label(format!("{} pedestrians", goria.world().humans.len())); - ui.label(format!("{} vehicles", goria.world().vehicles.len())); + ui.label(format!("{} pedestrians", sim.world().humans.len())); + ui.label(format!("{} vehicles", sim.world().vehicles.len())); ui.separator(); ui.label("Game system times"); @@ -189,8 +189,8 @@ pub fn debug( }); } -pub fn debug_spline(tess: &mut Tesselator, goria: &Egregoria, _: &UiWorld) -> Option<()> { - for road in goria.map().roads().values() { +pub fn debug_spline(tess: &mut Tesselator, sim: &Simulation, _: &UiWorld) -> Option<()> { + for road in sim.map().roads().values() { if let RoadSegmentKind::Curved((fr_dr, to_der)) = road.segment { let fr = road.points.first(); let to = road.points.last(); @@ -209,21 +209,17 @@ pub fn debug_spline(tess: &mut Tesselator, goria: &Egregoria, _: &UiWorld) Some(()) } -pub fn debug_lots(tess: &mut Tesselator, goria: &Egregoria, _: &UiWorld) -> Option<()> { +pub fn debug_lots(tess: &mut Tesselator, sim: &Simulation, _: &UiWorld) -> Option<()> { tess.set_color(Color::RED); - for lot in goria.map().lots().values() { + for lot in sim.map().lots().values() { tess.draw_circle(lot.shape.corners[0].z(lot.height), 1.0); } Some(()) } -pub fn debug_road_points( - tess: &mut Tesselator, - goria: &Egregoria, - _: &UiWorld, -) -> Option<()> { - let map = goria.map(); +pub fn debug_road_points(tess: &mut Tesselator, sim: &Simulation, _: &UiWorld) -> Option<()> { + let map = sim.map(); tess.set_color(Color::RED.a(0.5)); for (_, road) in map.roads() { for (_, p) in road.points.as_slice().iter().enumerate() { @@ -261,12 +257,12 @@ pub fn debug_road_points( pub fn debug_connectivity( tess: &mut Tesselator, - goria: &Egregoria, + sim: &Simulation, uiw: &UiWorld, ) -> Option<()> { - use egregoria::map::pathfinding_crate::directed::strongly_connected_components::strongly_connected_components; + use simulation::map::pathfinding_crate::directed::strongly_connected_components::strongly_connected_components; let mut state = uiw.write::(); - let map = goria.map(); + let map = sim.map(); if state.connectivity.0.is_none() { state.connectivity.0 = Some(map.subscribe(UpdateType::Road)); @@ -320,8 +316,8 @@ fn draw_spline(tess: &mut Tesselator, mut sp: Spline3) { tess.draw_circle(sp.to - sp.to_derivative, 0.7); } -fn debug_coworld(tess: &mut Tesselator, goria: &Egregoria, _: &UiWorld) -> Option<()> { - let coworld = goria.read::(); +fn debug_coworld(tess: &mut Tesselator, sim: &Simulation, _: &UiWorld) -> Option<()> { + let coworld = sim.read::(); tess.set_color(Color::new(0.8, 0.8, 0.9, 0.5)); for h in coworld.handles() { @@ -332,8 +328,8 @@ fn debug_coworld(tess: &mut Tesselator, goria: &Egregoria, _: &UiWorld) -> } /* -pub fn debug_obb(tess: &mut Tesselator Option<()> { - let time = goria.read::(); +pub fn debug_obb(tess: &mut Tesselator Option<()> { + let time = sim.read::(); let mouse = uiworld.read::().unprojected; let time = time.timestamp * 0.2; @@ -394,9 +390,9 @@ pub fn debug_obb(tess: &mut Tesselator, goria: &Egregoria, _: &UiWorld) -> Option<()> { - let map: &Map = &goria.map(); - let pm = goria.read::(); +pub fn debug_parking(tess: &mut Tesselator, sim: &Simulation, _: &UiWorld) -> Option<()> { + let map: &Map = &sim.map(); + let pm = sim.read::(); for (id, spot) in map.parking.all_spots() { let color = if pm.is_spot_free(id) { @@ -414,11 +410,11 @@ pub fn debug_parking(tess: &mut Tesselator, goria: &Egregoria, _: &UiWorld pub fn debug_trainreservations( tess: &mut Tesselator, - goria: &Egregoria, + sim: &Simulation, uiworld: &UiWorld, ) -> Option<()> { - let reservs = goria.read::(); - let map = goria.map(); + let reservs = sim.read::(); + let map = sim.map(); tess.set_color(LinearColor::new(0.8, 0.3, 0.3, 1.0)); for (id, poses) in &reservs.localisations { let points = match id { @@ -441,7 +437,7 @@ pub fn debug_trainreservations( let inter = unwrap_cont!(map.intersections().get(*inter)); tess.draw_circle(inter.pos.up(0.3), 3.0); - let p = unwrap_cont!(goria.pos(*e)); + let p = unwrap_cont!(sim.pos(*e)); tess.set_color(LinearColor::new(0.2, 0.2, 0.2, 1.0)); tess.draw_stroke(inter.pos.up(0.5), p, 2.0); @@ -449,7 +445,7 @@ pub fn debug_trainreservations( let selected = uiworld.read::().e?; let t_id: TrainID = selected.try_into().ok()?; - let t = goria.world().trains.get(t_id)?; + let t = sim.world().trains.get(t_id)?; let travers = t.it.get_travers()?; let dist_to_next = travers @@ -459,7 +455,7 @@ pub fn debug_trainreservations( - t.res.cur_travers_dist; let stop_dist = t.speed.0 * t.speed.0 / (2.0 * t.locomotive.dec_force); - for (v, _, _, _) in egregoria::transportation::train::traverse_forward( + for (v, _, _, _) in simulation::transportation::train::traverse_forward( &map, &t.it, stop_dist + 15.0, @@ -487,14 +483,14 @@ pub fn debug_trainreservations( pub fn debug_pathfinder( tess: &mut Tesselator, - goria: &Egregoria, + sim: &Simulation, uiworld: &UiWorld, ) -> Option<()> { - let map: &Map = &goria.map(); + let map: &Map = &sim.map(); let selected = uiworld.read::().e?; - let pos = goria.pos_any(selected)?; + let pos = sim.pos_any(selected)?; - let itinerary = goria.world().it_any(selected)?; + let itinerary = sim.world().it_any(selected)?; tess.set_color(LinearColor::GREEN); tess.draw_polyline( @@ -549,8 +545,8 @@ pub fn debug_pathfinder( } /* -pub fn debug_rays(tess: &mut Tesselator Option<()> { - let time = goria.read::(); +pub fn debug_rays(tess: &mut Tesselator Option<()> { + let time = sim.read::(); let time = time.timestamp * 0.2; let c = time.cos() as f32; let s = time.sin() as f32; @@ -583,8 +579,8 @@ pub fn debug_rays(tess: &mut Tesselator, goria: &Egregoria, _: &UiWorld) -> Option<()> { - let map: &Map = &goria.map(); +pub fn debug_spatialmap(tess: &mut Tesselator, sim: &Simulation, _: &UiWorld) -> Option<()> { + let map: &Map = &sim.map(); for r in map.spatial_map().debug_grid() { tess.set_color(LinearColor::BLUE.a(0.1)); tess.draw_rect_cos_sin( diff --git a/native_app/src/gui/windows/economy.rs b/native_app/src/gui/windows/economy.rs index 2e6462c4..7013f54e 100644 --- a/native_app/src/gui/windows/economy.rs +++ b/native_app/src/gui/windows/economy.rs @@ -1,12 +1,12 @@ use crate::uiworld::UiWorld; use common::timestep::UP_DT; -use egregoria::economy::{ - EcoStats, ItemHistories, ItemRegistry, Market, HISTORY_SIZE, LEVEL_FREQS, LEVEL_NAMES, -}; -use egregoria::Egregoria; use egui::plot::{Line, PlotPoints}; use egui::{Align2, Color32, Ui}; use geom::Color; +use simulation::economy::{ + EcoStats, ItemHistories, ItemRegistry, Market, HISTORY_SIZE, LEVEL_FREQS, LEVEL_NAMES, +}; +use simulation::Simulation; use slotmapd::Key; use std::cmp::Reverse; use std::collections::HashSet; @@ -32,15 +32,15 @@ struct EconomyState { /// Economy window /// Shows the economy stats -pub fn economy(window: egui::Window<'_>, ui: &egui::Context, uiw: &mut UiWorld, goria: &Egregoria) { +pub fn economy(window: egui::Window<'_>, ui: &egui::Context, uiw: &mut UiWorld, sim: &Simulation) { uiw.check_present(|| EconomyState { curlevel: 0, tab: EconomyTab::ImportExports, hist_type: Default::default(), }); let mut state = uiw.write::(); - let ecostats = goria.read::(); - let registry = goria.read::(); + let ecostats = sim.read::(); + let registry = sim.read::(); window .anchor(Align2::CENTER_CENTER, [0.0, 0.0]) @@ -282,7 +282,7 @@ pub fn economy(window: egui::Window<'_>, ui: &egui::Context, uiw: &mut UiWorld, } EconomyTab::MarketPrices => { ui.push_id(3, |ui| { - render_market_prices(goria, ui); + render_market_prices(sim, ui); }); } } @@ -290,9 +290,9 @@ pub fn economy(window: egui::Window<'_>, ui: &egui::Context, uiw: &mut UiWorld, }); } -fn render_market_prices(goria: &Egregoria, ui: &mut Ui) { - let registry = goria.read::(); - let market = goria.read::(); +fn render_market_prices(sim: &Simulation, ui: &mut Ui) { + let registry = sim.read::(); + let market = sim.read::(); egui::Grid::new("marketprices").show(ui, |ui| { for (id, market) in market.iter() { ui.label(®istry[*id].name); diff --git a/native_app/src/gui/windows/load.rs b/native_app/src/gui/windows/load.rs index 291688cf..191f1ccc 100644 --- a/native_app/src/gui/windows/load.rs +++ b/native_app/src/gui/windows/load.rs @@ -1,7 +1,7 @@ #![allow(unused)] use crate::uiworld::{SaveLoadState, UiWorld}; -use egregoria::Egregoria; use egui::{Color32, DroppedFile, Widget}; +use simulation::Simulation; use std::path::PathBuf; #[derive(Default)] @@ -12,7 +12,7 @@ pub struct LoadState { /// Load window /// Allows to load a replay from disk and play it -pub fn load(window: egui::Window<'_>, ui: &egui::Context, uiw: &mut UiWorld, _: &Egregoria) { +pub fn load(window: egui::Window<'_>, ui: &egui::Context, uiw: &mut UiWorld, _: &Simulation) { window.show(ui, |ui| { let mut lstate = uiw.write::(); @@ -23,17 +23,17 @@ pub fn load(window: egui::Window<'_>, ui: &egui::Context, uiw: &mut UiWorld, _: }); if ui.button("New Game").clicked() { - uiw.write::().please_load_goria = Some(Egregoria::new(true)); + uiw.write::().please_load_sim = Some(Simulation::new(true)); } if has_save { if ui.button("Load world/world_replay.json").clicked() { - let replay = Egregoria::load_replay_from_disk("world"); + let replay = Simulation::load_replay_from_disk("world"); if let Some(replay) = replay { - let (goria, loader) = Egregoria::from_replay(replay); + let (sim, loader) = Simulation::from_replay(replay); uiw.write::().please_load = Some(loader); - uiw.write::().please_load_goria = Some(goria); + uiw.write::().please_load_sim = Some(sim); } else { lstate.load_fail = "Failed to load replay".to_string(); } diff --git a/native_app/src/gui/windows/mod.rs b/native_app/src/gui/windows/mod.rs index 621be10d..384cb71f 100644 --- a/native_app/src/gui/windows/mod.rs +++ b/native_app/src/gui/windows/mod.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::inputmap::{InputAction, InputMap}; use crate::uiworld::UiWorld; -use egregoria::Egregoria; +use simulation::Simulation; mod config; pub mod debug; @@ -19,22 +19,22 @@ pub trait GUIWindow: Send + Sync { window: egui::Window<'_>, ui: &Context, uiworld: &mut UiWorld, - goria: &Egregoria, + sim: &Simulation, ); } impl GUIWindow for F where - F: Fn(egui::Window<'_>, &Context, &mut UiWorld, &Egregoria) + Send + Sync, + F: Fn(egui::Window<'_>, &Context, &mut UiWorld, &Simulation) + Send + Sync, { fn render_window( &mut self, window: egui::Window<'_>, ui: &Context, uiworld: &mut UiWorld, - goria: &Egregoria, + sim: &Simulation, ) { - self(window, ui, uiworld, goria); + self(window, ui, uiworld, sim); } } @@ -89,7 +89,7 @@ impl GUIWindows { } } - pub fn render(&mut self, ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { + pub fn render(&mut self, ui: &Context, uiworld: &mut UiWorld, sim: &Simulation) { profiling::scope!("windows::render"); if uiworld .write::() @@ -104,7 +104,7 @@ impl GUIWindows { } for (ws, opened) in self.windows.iter_mut().zip(self.opened.iter_mut()) { if *opened { - ws.w.render_window(egui::Window::new(ws.name).open(opened), ui, uiworld, goria); + ws.w.render_window(egui::Window::new(ws.name).open(opened), ui, uiworld, sim); } } } diff --git a/native_app/src/gui/windows/network.rs b/native_app/src/gui/windows/network.rs index 63016b12..7fbb9572 100644 --- a/native_app/src/gui/windows/network.rs +++ b/native_app/src/gui/windows/network.rs @@ -1,9 +1,9 @@ use crate::network::NetworkState; use crate::uiworld::UiWorld; use common::saveload::Encoder; -use egregoria::Egregoria; use egui::{Context, RichText, Ui}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use simulation::Simulation; use std::collections::BTreeMap; pub struct NetworkConnectionInfo { @@ -17,7 +17,7 @@ pub struct NetworkConnectionInfo { /// Network window /// Allows to connect to a server or start a server #[cfg(feature = "multiplayer")] -pub fn network(window: egui::Window<'_>, ui: &Context, uiworld: &mut UiWorld, goria: &Egregoria) { +pub fn network(window: egui::Window<'_>, ui: &Context, uiworld: &mut UiWorld, sim: &Simulation) { window.show(ui, |ui| { let mut state = uiworld.write::(); let mut info = uiworld.write::(); @@ -41,7 +41,7 @@ pub fn network(window: egui::Window<'_>, ui: &Context, uiworld: &mut UiWorld, go } if ui.small_button("Start server").clicked() { - if let Some(server) = crate::network::start_server(&mut info, goria) { + if let Some(server) = crate::network::start_server(&mut info, sim) { *state = NetworkState::Server(server); } } @@ -60,25 +60,25 @@ pub fn network(window: egui::Window<'_>, ui: &Context, uiworld: &mut UiWorld, go } NetworkState::Client(ref client) => { ui.label(client.lock().unwrap().describe()); - show_hashes(ui, goria, &mut info); + show_hashes(ui, sim, &mut info); } NetworkState::Server(ref server) => { ui.label("Running server"); ui.label(server.lock().unwrap().describe()); - show_hashes(ui, goria, &mut info); + show_hashes(ui, sim, &mut info); } } }); } -fn show_hashes(ui: &mut Ui, goria: &Egregoria, info: &mut NetworkConnectionInfo) { +fn show_hashes(ui: &mut Ui, sim: &Simulation, info: &mut NetworkConnectionInfo) { ui.checkbox(&mut info.show_hashes, "show hashes"); if !info.show_hashes { return; } - if goria.get_tick() % 100 == 0 || info.hashes.is_empty() { - info.hashes = goria.hashes(); + if sim.get_tick() % 100 == 0 || info.hashes.is_empty() { + info.hashes = sim.hashes(); } for (name, hash) in &info.hashes { diff --git a/native_app/src/gui/windows/settings.rs b/native_app/src/gui/windows/settings.rs index b4ca528d..3da9e481 100644 --- a/native_app/src/gui/windows/settings.rs +++ b/native_app/src/gui/windows/settings.rs @@ -2,10 +2,10 @@ use crate::game_loop::Timings; use crate::inputmap::{Bindings, InputMap}; use crate::uiworld::UiWorld; use common::saveload::Encoder; -use egregoria::Egregoria; use egui::{Align2, Context, Widget}; use egui_extras::Column; use engine::GfxContext; +use simulation::Simulation; use std::time::{Duration, Instant}; use winit::window::Fullscreen; @@ -149,7 +149,7 @@ impl AsRef for AutoSaveEvery { /// Settings window /// This window is used to change the settings of the game -pub fn settings(window: egui::Window<'_>, ui: &Context, uiworld: &mut UiWorld, _: &Egregoria) { +pub fn settings(window: egui::Window<'_>, ui: &Context, uiworld: &mut UiWorld, _: &Simulation) { let mut settings = uiworld.write::(); let [_, h]: [f32; 2] = ui.available_rect().size().into(); diff --git a/native_app/src/gui/zoneedit.rs b/native_app/src/gui/zoneedit.rs index 60efa822..e4587b8a 100644 --- a/native_app/src/gui/zoneedit.rs +++ b/native_app/src/gui/zoneedit.rs @@ -2,11 +2,11 @@ use crate::gui::{ErrorTooltip, InspectedBuilding, PotentialCommands}; use crate::inputmap::{InputAction, InputMap}; use crate::rendering::immediate::ImmediateDraw; use crate::uiworld::UiWorld; -use egregoria::engine_interaction::WorldCommand; -use egregoria::map::{ProjectFilter, ProjectKind, Zone, MAX_ZONE_AREA}; -use egregoria::Egregoria; use geom::{Polygon, Vec2}; use ordered_float::OrderedFloat; +use simulation::engine_interaction::WorldCommand; +use simulation::map::{ProjectFilter, ProjectKind, Zone, MAX_ZONE_AREA}; +use simulation::Simulation; use std::borrow::Cow; #[derive(Debug, Copy, Clone, Default)] @@ -18,7 +18,7 @@ pub struct ZoneEditState { /// ZoneEdit tool /// Allows to edit the zone of a building like a farm field or solarpanel field -pub fn zoneedit(goria: &Egregoria, uiworld: &mut UiWorld) { +pub fn zoneedit(sim: &Simulation, uiworld: &mut UiWorld) { profiling::scope!("gui::zoneedit"); let mut inspected_b = uiworld.write::(); let mut state = uiworld.write::(); @@ -26,7 +26,7 @@ pub fn zoneedit(goria: &Egregoria, uiworld: &mut UiWorld) { let Some(bid) = inspected_b.e else { state.offset = None; return; }; - let map = goria.map(); + let map = sim.map(); let Some(b) = map.buildings().get(bid) else { return; }; let Some(ref zone) = b.zone else { return; }; @@ -82,9 +82,9 @@ pub fn zoneedit(goria: &Egregoria, uiworld: &mut UiWorld) { let base_col = if !isvalid { uiworld.write::().msg = Some(Cow::Owned(invalidmsg)); uiworld.write::().isworld = true; - egregoria::config().gui_danger + simulation::config().gui_danger } else { - egregoria::config().gui_primary + simulation::config().gui_primary }; for (p1, p2) in newpoly.iter().zip(newpoly.iter().cycle().skip(1)) { @@ -122,7 +122,7 @@ pub fn zoneedit(goria: &Egregoria, uiworld: &mut UiWorld) { for (i, &p) in newpoly.iter().enumerate() { if Some((i, p, false)) == closest { draw.circle(p.z(1.1), 6.0) - .color(egregoria::config().gui_success); + .color(simulation::config().gui_success); continue; } @@ -132,7 +132,7 @@ pub fn zoneedit(goria: &Egregoria, uiworld: &mut UiWorld) { for (i, p) in newpoly.segments().map(|s| s.center()).enumerate() { if Some((i, p, true)) == closest { draw.circle(p.z(1.1), 3.0) - .color(egregoria::config().gui_success); + .color(simulation::config().gui_success); continue; } diff --git a/native_app/src/init.rs b/native_app/src/init.rs index 5d81b07c..11f64acd 100644 --- a/native_app/src/init.rs +++ b/native_app/src/init.rs @@ -17,14 +17,14 @@ use crate::network::NetworkState; use crate::rendering::immediate::{ImmediateDraw, ImmediateSound}; use crate::uiworld::{ReceivedCommands, UiWorld}; use common::saveload::Encoder; -use egregoria::engine_interaction::WorldCommands; use serde::de::DeserializeOwned; use serde::Serialize; +use simulation::engine_interaction::WorldCommands; /// init is called at the beginning of the program to initialize the globals /// It is mostly to register types for serialization and initialization of the engine pub fn init() { - egregoria::init::init(); + simulation::init::init(); register_resource::("settings"); #[cfg(feature = "multiplayer")] register_resource::("netinfo"); diff --git a/native_app/src/main.rs b/native_app/src/main.rs index 388c1d3a..7f7fb545 100644 --- a/native_app/src/main.rs +++ b/native_app/src/main.rs @@ -4,7 +4,7 @@ extern crate common; #[macro_use] -extern crate egregoria; +extern crate simulation; #[allow(unused_imports)] #[macro_use] diff --git a/native_app/src/network.rs b/native_app/src/network.rs index e2fc53a6..c8bffe01 100644 --- a/native_app/src/network.rs +++ b/native_app/src/network.rs @@ -3,9 +3,9 @@ use crate::game_loop::{State, Timings}; use crate::gui::windows::settings::Settings; use crate::uiworld::{ReceivedCommands, SaveLoadState}; use common::timestep::Timestep; -use egregoria::engine_interaction::{WorldCommand, WorldCommands}; -use egregoria::utils::scheduler::SeqSchedule; -use egregoria::Egregoria; +use simulation::engine_interaction::{WorldCommand, WorldCommands}; +use simulation::utils::scheduler::SeqSchedule; +use simulation::Simulation; impl Default for NetworkState { fn default() -> Self { @@ -22,21 +22,21 @@ mod inner { Singleplayer(Timestep), } - pub fn goria_update(state: &mut State) { + pub fn sim_update(state: &mut State) { super::handle_singleplayer(state); } } #[allow(dead_code)] fn handle_singleplayer(state: &mut State) { - let mut goria = unwrap_orr!(state.goria.try_write(), return); // mut for tick + let mut sim = unwrap_orr!(state.sim.try_write(), return); // mut for tick let timewarp = state.uiw.read::().time_warp; let mut commands = std::mem::take(&mut *state.uiw.write::()); *state.uiw.write::() = ReceivedCommands::default(); if handle_replay( - &mut goria, + &mut sim, &mut state.game_schedule, &mut state.uiw.write::(), ) { @@ -50,7 +50,7 @@ fn handle_singleplayer(state: &mut State) { if has_commands && commands.iter().all(WorldCommand::is_instant) { for v in commands.iter() { - v.apply(&mut goria); + v.apply(&mut sim); } commands = WorldCommands::default(); has_commands = false; @@ -64,7 +64,7 @@ fn handle_singleplayer(state: &mut State) { let mut commands_once = Some(commands.clone()); step.prepare_frame(timewarp); while step.tick() || (has_commands && commands_once.is_some()) { - let t = goria.tick(sched, commands_once.take().unwrap_or_default().as_ref()); + let t = sim.tick(sched, commands_once.take().unwrap_or_default().as_ref()); timings.world_update.add_value(t.as_secs_f32()); } @@ -76,17 +76,17 @@ fn handle_singleplayer(state: &mut State) { } fn handle_replay( - goria: &mut Egregoria, + sim: &mut Simulation, schedule: &mut SeqSchedule, slstate: &mut SaveLoadState, ) -> bool { - if let Some(new_goria) = slstate.please_load_goria.take() { - *goria = new_goria; + if let Some(new_sim) = slstate.please_load_sim.take() { + *sim = new_sim; slstate.render_reset = true; - log::info!("replaced goria"); + log::info!("replaced sim"); } if let Some(ref mut replay) = slstate.please_load { - if replay.advance_tick(goria, schedule) { + if replay.advance_tick(sim, schedule) { slstate.please_load = None; log::info!("finished loading replay"); } @@ -102,16 +102,16 @@ mod inner { use crate::network::handle_replay; use crate::uiworld::{ReceivedCommands, SaveLoadState}; use common::timestep::Timestep; - use egregoria::engine_interaction::WorldCommands; - use egregoria::Egregoria; use networking::{ ConnectConf, Frame, PollResult, ServerConfiguration, ServerPollResult, VirtualClientConf, }; + use simulation::engine_interaction::WorldCommands; + use simulation::Simulation; use std::net::ToSocketAddrs; use std::sync::Mutex; - pub type Client = Mutex>; - pub type Server = Mutex>; + pub type Client = Mutex>; + pub type Server = Mutex>; #[allow(clippy::large_enum_variant)] pub enum NetworkState { @@ -120,7 +120,7 @@ mod inner { Server(Server), } - pub fn goria_update(state: &mut State) { + pub fn sim_update(state: &mut State) { if matches!( *state.uiw.read::(), NetworkState::Singleplayer(_) @@ -129,13 +129,13 @@ mod inner { return; } - let mut goria = unwrap_orr!(state.goria.try_write(), return); // mut for tick + let mut sim = unwrap_orr!(state.sim.try_write(), return); // mut for tick let commands = std::mem::take(&mut *state.uiw.write::()); *state.uiw.write::() = ReceivedCommands::default(); if handle_replay( - &mut goria, + &mut sim, &mut state.game_schedule, &mut state.uiw.write::(), ) { @@ -152,7 +152,7 @@ mod inner { server .get_mut() .unwrap() - .poll(&goria, Frame(goria.get_tick()), Some(commands)); + .poll(&sim, Frame(sim.get_tick()), Some(commands)); match polled { ServerPollResult::Wait(commands) => { if let Some(commands) = commands { @@ -173,8 +173,8 @@ mod inner { PollResult::Input(inputs) => { inputs_to_apply = Some(inputs); } - PollResult::GameWorld(commands, prepared_goria) => { - *goria = prepared_goria; + PollResult::GameWorld(commands, prepared_sim) => { + *sim = prepared_sim; *state.uiw.write::() = commands; } PollResult::Disconnect(reason) => { @@ -191,13 +191,13 @@ mod inner { if let Some(inputs) = inputs_to_apply { let mut merged = WorldCommands::default(); for frame_commands in inputs { - assert_eq!(frame_commands.frame.0, goria.get_tick() + 1); + assert_eq!(frame_commands.frame.0, sim.get_tick() + 1); let commands: WorldCommands = frame_commands .inputs .iter() .map(|x| x.inp.clone()) .collect(); - let t = goria.tick(&mut state.game_schedule, commands.as_ref()); + let t = sim.tick(&mut state.game_schedule, commands.as_ref()); state .uiw .write::() @@ -216,9 +216,9 @@ mod inner { } } - pub fn start_server(info: &mut NetworkConnectionInfo, goria: &Egregoria) -> Option { + pub fn start_server(info: &mut NetworkConnectionInfo, sim: &Simulation) -> Option { let server = match networking::Server::start(ServerConfiguration { - start_frame: Frame(goria.get_tick()), + start_frame: Frame(sim.get_tick()), period: common::timestep::UP_DT, port: None, virtual_client: Some(VirtualClientConf { diff --git a/native_app/src/rendering/entity_render.rs b/native_app/src/rendering/entity_render.rs index d59e7947..4043995a 100644 --- a/native_app/src/rendering/entity_render.rs +++ b/native_app/src/rendering/entity_render.rs @@ -1,9 +1,9 @@ -use egregoria::transportation::train::RailWagonKind; -use egregoria::transportation::{Location, VehicleKind}; -use egregoria::Egregoria; use engine::meshload::load_mesh; use engine::{FrameContext, GfxContext, InstancedMeshBuilder, MeshInstance, SpriteBatchBuilder}; use geom::{LinearColor, Vec3, V3}; +use simulation::transportation::train::RailWagonKind; +use simulation::transportation::{Location, VehicleKind}; +use simulation::Simulation; /// Render all entities using instanced rendering for performance pub struct InstancedRender { @@ -35,12 +35,12 @@ impl InstancedRender { } } - pub fn render(&mut self, goria: &Egregoria, fctx: &mut FrameContext<'_>) { + pub fn render(&mut self, sim: &Simulation, fctx: &mut FrameContext<'_>) { profiling::scope!("entity_render::render"); self.cars.instances.clear(); self.trucks.instances.clear(); self.pedestrians.instances.clear(); - for v in goria.world().vehicles.values() { + for v in sim.world().vehicles.values() { let trans = &v.trans; let instance = MeshInstance { pos: trans.position, @@ -58,7 +58,7 @@ impl InstancedRender { self.locomotives.instances.clear(); self.wagons_passenger.instances.clear(); self.wagons_freight.instances.clear(); - for wagon in goria.world().wagons.values() { + for wagon in sim.world().wagons.values() { let trans = &wagon.trans; let instance = MeshInstance { pos: trans.position, @@ -79,7 +79,7 @@ impl InstancedRender { } } - for p in goria.world().humans.values() { + for p in sim.world().humans.values() { if matches!(p.location, Location::Outside) { self.pedestrians.instances.push(MeshInstance { pos: p @@ -93,7 +93,7 @@ impl InstancedRender { } self.path_not_found.clear(); - for (_, (trans, itin)) in goria.world().query_trans_itin() { + for (_, (trans, itin)) in sim.world().query_trans_itin() { let Some(wait) = itin.is_wait_for_reroute() else { continue }; if wait == 0 { continue; diff --git a/native_app/src/rendering/map_rendering/lamps.rs b/native_app/src/rendering/map_rendering/lamps.rs index 9ca22a49..04499efa 100644 --- a/native_app/src/rendering/map_rendering/lamps.rs +++ b/native_app/src/rendering/map_rendering/lamps.rs @@ -1,10 +1,10 @@ use common::{FastMap, FastSet}; -use egregoria::map::{ - chunk_id, Chunk, ChunkID, Map, MapSubscriber, ProjectFilter, ProjectKind, UpdateType, -}; use engine::{Context, LampLights, LightChunkID}; use flat_spatial::AABBGrid; use geom::{Vec3, AABB3, V3}; +use simulation::map::{ + chunk_id, Chunk, ChunkID, Map, MapSubscriber, ProjectFilter, ProjectKind, UpdateType, +}; pub struct LampsRender { lamp_memory: FastMap>, diff --git a/native_app/src/rendering/map_rendering/map_mesh.rs b/native_app/src/rendering/map_rendering/map_mesh.rs index 77ca6f32..9c812d63 100644 --- a/native_app/src/rendering/map_rendering/map_mesh.rs +++ b/native_app/src/rendering/map_rendering/map_mesh.rs @@ -1,12 +1,5 @@ use crate::rendering::MapRenderOptions; use common::FastMap; -use egregoria::map::{ - chunk_id, Building, BuildingKind, CanonicalPosition, Chunk, ChunkID, Intersection, LaneKind, - Lanes, LotKind, Map, MapSubscriber, ProjectFilter, ProjectKind, PylonPosition, Road, Roads, - Terrain, Turn, TurnKind, UpdateType, CROSSWALK_WIDTH, -}; -use egregoria::souls::goods_company::GoodsCompanyRegistry; -use egregoria::Egregoria; use engine::earcut::earcut; use engine::meshload::load_mesh; use engine::{ @@ -14,6 +7,13 @@ use engine::{ MeshInstance, MeshVertex, MetallicRoughness, SpriteBatch, SpriteBatchBuilder, Tesselator, }; use geom::{minmax, vec2, vec3, Color, LinearColor, PolyLine3, Polygon, Radians, Vec2, Vec3}; +use simulation::map::{ + chunk_id, Building, BuildingKind, CanonicalPosition, Chunk, ChunkID, Intersection, LaneKind, + Lanes, LotKind, Map, MapSubscriber, ProjectFilter, ProjectKind, PylonPosition, Road, Roads, + Terrain, Turn, TurnKind, UpdateType, CROSSWALK_WIDTH, +}; +use simulation::souls::goods_company::GoodsCompanyRegistry; +use simulation::Simulation; use std::ops::{Mul, Neg}; use std::rc::Rc; @@ -47,14 +47,14 @@ struct MapBuilders { } impl MapMeshHandler { - pub fn new(gfx: &mut GfxContext, goria: &Egregoria) -> Self { + pub fn new(gfx: &mut GfxContext, sim: &Simulation) -> Self { let arrow_builder = SpriteBatchBuilder::from_path(gfx, "assets/sprites/arrow_one_way.png"); let mut buildsprites = FastMap::default(); let mut buildmeshes = FastMap::default(); let mut zonemeshes = FastMap::default(); - for descr in goria.read::().descriptions.values() { + for descr in sim.read::().descriptions.values() { let asset = &descr.asset_location; if !asset.ends_with(".png") && !asset.ends_with(".jpg") { continue; @@ -68,7 +68,7 @@ impl MapMeshHandler { ); } - for (asset, bkind) in goria + for (asset, bkind) in sim .read::() .descriptions .values() @@ -97,7 +97,7 @@ impl MapMeshHandler { buildmeshes.insert(bkind, InstancedMeshBuilder::new(m)); } - for descr in goria.read::().descriptions.values() { + for descr in sim.read::().descriptions.values() { let Some(ref z) = descr.zone else { continue }; let floor = &z.floor; let filler = &z.filler; @@ -166,8 +166,8 @@ impl MapMeshHandler { Self { builders, cache: Default::default(), - road_sub: goria.map().subscribe(UpdateType::Road), - building_sub: goria.map().subscribe(UpdateType::Building), + road_sub: sim.map().subscribe(UpdateType::Road), + building_sub: sim.map().subscribe(UpdateType::Building), } } @@ -548,10 +548,10 @@ impl MapBuilders { self.tess_map.meshbuilder.clear(); self.tess_lots.meshbuilder.clear(); - let low_col: LinearColor = egregoria::config().road_low_col.into(); - let mid_col: LinearColor = egregoria::config().road_mid_col.into(); - let hig_col: LinearColor = egregoria::config().road_hig_col.into(); - let line_col: LinearColor = egregoria::config().road_line_col.into(); + let low_col: LinearColor = simulation::config().road_low_col.into(); + let mid_col: LinearColor = simulation::config().road_mid_col.into(); + let hig_col: LinearColor = simulation::config().road_hig_col.into(); + let line_col: LinearColor = simulation::config().road_line_col.into(); let objs = map.spatial_map().query( Chunk::rect(chunk), @@ -723,8 +723,8 @@ impl MapBuilders { for lot in chunk_lots { let lot = &lots[lot]; let col = match lot.kind { - LotKind::Unassigned => egregoria::config().lot_unassigned_col, - LotKind::Residential => egregoria::config().lot_residential_col, + LotKind::Unassigned => simulation::config().lot_unassigned_col, + LotKind::Residential => simulation::config().lot_residential_col, }; self.tess_lots.set_color(col); self.tess_lots @@ -742,7 +742,7 @@ fn add_polyon( dir, }: PylonPosition, ) { - let color = LinearColor::from(egregoria::config().road_pylon_col); + let color = LinearColor::from(simulation::config().road_pylon_col); let color: [f32; 4] = color.into(); let up = pos.up(-0.2); @@ -942,7 +942,7 @@ fn intersection_mesh( polygon.simplify(); - let col = LinearColor::from(egregoria::config().road_mid_col).into(); + let col = LinearColor::from(simulation::config().road_mid_col).into(); tess.meshbuilder.extend_with(move |vertices, add_idx| { vertices.extend(polygon.iter().map(|pos| MeshVertex { position: pos.z(inter.pos.z - 0.001).into(), diff --git a/native_app/src/rendering/map_rendering/mod.rs b/native_app/src/rendering/map_rendering/mod.rs index fc33694d..c51a119f 100644 --- a/native_app/src/rendering/map_rendering/mod.rs +++ b/native_app/src/rendering/map_rendering/mod.rs @@ -1,10 +1,10 @@ -use egregoria::map::{ - Lane, LaneID, LaneKind, Map, ProjectFilter, ProjectKind, TrafficBehavior, CHUNK_SIZE, -}; -use egregoria::Egregoria; use engine::{Context, FrameContext, GfxContext, Water}; use geom::{Camera, Circle, InfiniteFrustrum, Intersect3}; use map_mesh::MapMeshHandler; +use simulation::map::{ + Lane, LaneID, LaneKind, Map, ProjectFilter, ProjectKind, TrafficBehavior, CHUNK_SIZE, +}; +use simulation::Simulation; use terrain::TerrainRender; use crate::rendering::immediate::ImmediateDraw; @@ -31,23 +31,23 @@ pub struct MapRenderOptions { } impl MapRenderer { - pub fn new(gfx: &mut GfxContext, goria: &Egregoria) -> Self { - let w = goria.map().terrain.width; - let h = goria.map().terrain.height; + pub fn new(gfx: &mut GfxContext, sim: &Simulation) -> Self { + let w = sim.map().terrain.width; + let h = sim.map().terrain.height; defer!(log::info!("finished init of road render")); MapRenderer { - meshb: MapMeshHandler::new(gfx, goria), - trees: TreesRender::new(gfx, &goria.map()), - terrain: TerrainRender::new(gfx, goria), + meshb: MapMeshHandler::new(gfx, sim), + trees: TreesRender::new(gfx, &sim.map()), + terrain: TerrainRender::new(gfx, sim), water: Water::new(gfx, (w * CHUNK_SIZE) as f32, (h * CHUNK_SIZE) as f32), - lamps: LampsRender::new(&goria.map()), + lamps: LampsRender::new(&sim.map()), } } - pub fn update(&mut self, goria: &Egregoria, ctx: &mut Context) { + pub fn update(&mut self, sim: &Simulation, ctx: &mut Context) { profiling::scope!("update map renderer"); - let map = goria.map(); + let map = sim.map(); self.lamps.update(&map, ctx); self.terrain.update(ctx, &map); } diff --git a/native_app/src/rendering/map_rendering/terrain.rs b/native_app/src/rendering/map_rendering/terrain.rs index 0954f018..082a0567 100644 --- a/native_app/src/rendering/map_rendering/terrain.rs +++ b/native_app/src/rendering/map_rendering/terrain.rs @@ -1,8 +1,8 @@ -use egregoria::map::{Map, MapSubscriber, UpdateType, CHUNK_RESOLUTION, CHUNK_SIZE}; -use egregoria::Egregoria; use engine::terrain::TerrainRender as EngineTerrainRender; use engine::{Context, FrameContext, GfxContext}; use geom::{Camera, InfiniteFrustrum}; +use simulation::map::{Map, MapSubscriber, UpdateType, CHUNK_RESOLUTION, CHUNK_SIZE}; +use simulation::Simulation; const CSIZE: usize = CHUNK_SIZE as usize; const CRESO: usize = CHUNK_RESOLUTION; @@ -13,17 +13,17 @@ pub struct TerrainRender { } impl TerrainRender { - pub fn new(gfx: &mut GfxContext, goria: &Egregoria) -> Self { - let w = goria.map().terrain.width; - let h = goria.map().terrain.height; + pub fn new(gfx: &mut GfxContext, sim: &Simulation) -> Self { + let w = sim.map().terrain.width; + let h = sim.map().terrain.height; let grass = gfx.texture("assets/sprites/grass.jpg", "grass"); let terrain = - EngineTerrainRender::new(gfx, w, h, egregoria::config().border_col.into(), grass); + EngineTerrainRender::new(gfx, w, h, simulation::config().border_col.into(), grass); /* - let ter = &goria.map().terrain; + let ter = &sim.map().terrain; let minchunk = *ter.chunks.keys().min().unwrap(); let maxchunk = *ter.chunks.keys().max().unwrap(); terrain.update_borders(minchunk, maxchunk, gfx, &|p| ter.height(p)); @@ -31,7 +31,7 @@ impl TerrainRender { Self { terrain, - terrain_sub: goria.map().subscribe(UpdateType::Terrain), + terrain_sub: sim.map().subscribe(UpdateType::Terrain), } } diff --git a/native_app/src/rendering/map_rendering/trees.rs b/native_app/src/rendering/map_rendering/trees.rs index 911950f9..057cb14e 100644 --- a/native_app/src/rendering/map_rendering/trees.rs +++ b/native_app/src/rendering/map_rendering/trees.rs @@ -1,11 +1,11 @@ use common::FastMap; -use egregoria::map::{ChunkID, Map, MapSubscriber, UpdateType, CHUNK_SIZE}; use engine::meshload::load_mesh; use engine::wgpu::RenderPass; use engine::{ Drawable, FrameContext, GfxContext, InstancedMesh, InstancedMeshBuilder, MeshInstance, }; use geom::{vec3, vec4, Camera, InfiniteFrustrum, Intersect3, LinearColor, Matrix4, Vec3, AABB3}; +use simulation::map::{ChunkID, Map, MapSubscriber, UpdateType, CHUNK_SIZE}; use std::ops::Mul; pub struct TreesRender { diff --git a/native_app/src/rendering/orbit_camera.rs b/native_app/src/rendering/orbit_camera.rs index 097451ac..2be47fa7 100644 --- a/native_app/src/rendering/orbit_camera.rs +++ b/native_app/src/rendering/orbit_camera.rs @@ -1,10 +1,10 @@ use crate::gui::windows::settings::Settings; use crate::inputmap::{InputAction, InputMap}; use common::saveload::Encoder; -use egregoria::map::pathfinding_crate::num_traits::Pow; -use egregoria::map::CHUNK_SIZE; use engine::{Context, Tesselator}; use geom::{vec4, Camera, InfiniteFrustrum, Matrix4, Plane, Radians, Ray3, Vec2, Vec3, AABB}; +use simulation::map::pathfinding_crate::num_traits::Pow; +use simulation::map::CHUNK_SIZE; /// CameraHandler3D is the camera handler for the 3D view /// It controls the camera using an orbit view diff --git a/native_app/src/uiworld.rs b/native_app/src/uiworld.rs index a65525c1..a47a8b00 100644 --- a/native_app/src/uiworld.rs +++ b/native_app/src/uiworld.rs @@ -1,7 +1,7 @@ use crate::init::{INIT_FUNCS, SAVELOAD_FUNCS}; -use egregoria::engine_interaction::{WorldCommand, WorldCommands}; -use egregoria::utils::resources::{Ref, RefMut, Resources}; -use egregoria::{Egregoria, EgregoriaReplayLoader}; +use simulation::engine_interaction::{WorldCommand, WorldCommands}; +use simulation::utils::resources::{Ref, RefMut, Resources}; +use simulation::{Simulation, SimulationReplayLoader}; use std::any::Any; use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -13,8 +13,8 @@ pub struct UiWorld { #[derive(Default)] pub struct SaveLoadState { - pub please_load: Option, - pub please_load_goria: Option, + pub please_load: Option, + pub please_load_sim: Option, pub render_reset: bool, pub please_save: bool, pub saving_status: Arc, diff --git a/egregoria/Cargo.toml b/simulation/Cargo.toml similarity index 97% rename from egregoria/Cargo.toml rename to simulation/Cargo.toml index 589ab8c0..b876bc30 100644 --- a/egregoria/Cargo.toml +++ b/simulation/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "egregoria" +name = "simulation" version = "0.1.0" authors = ["Douady Pâris "] edition = "2021" diff --git a/egregoria/clippy.toml b/simulation/clippy.toml similarity index 100% rename from egregoria/clippy.toml rename to simulation/clippy.toml diff --git a/egregoria/src/economy/ecostats.rs b/simulation/src/economy/ecostats.rs similarity index 100% rename from egregoria/src/economy/ecostats.rs rename to simulation/src/economy/ecostats.rs diff --git a/egregoria/src/economy/government.rs b/simulation/src/economy/government.rs similarity index 89% rename from egregoria/src/economy/government.rs rename to simulation/src/economy/government.rs index c5881a5f..e443857f 100644 --- a/egregoria/src/economy/government.rs +++ b/simulation/src/economy/government.rs @@ -1,7 +1,7 @@ use crate::economy::Money; use crate::engine_interaction::WorldCommand; use crate::map::{LanePattern, MapProject, MAX_ZONE_AREA}; -use crate::{BuildingKind, Egregoria, GoodsCompanyRegistry}; +use crate::{BuildingKind, GoodsCompanyRegistry, Simulation}; use serde::{Deserialize, Serialize}; /// The government represents the player. @@ -19,7 +19,7 @@ impl Default for Government { } impl Government { - pub fn action_cost(action: &WorldCommand, goria: &Egregoria) -> Money { + pub fn action_cost(action: &WorldCommand, sim: &Simulation) -> Money { Money::new_bucks(match action { WorldCommand::MapBuildHouse(_) => 100, WorldCommand::AddTrain { n_wagons, .. } => 1000 + 100 * (*n_wagons as i64), @@ -30,10 +30,10 @@ impl Government { building: bid, zone: z, } => { - let m = goria.map(); + let m = sim.map(); let Some(b) = m.buildings.get(*bid) else { return Money::ZERO; }; let Some(gc) = b.kind.as_goods_company() else { return Money::ZERO; }; - let registry = goria.read::(); + let registry = sim.read::(); let zonedescr = registry.descriptions[gc].zone.as_ref().unwrap(); let oldarea = b.zone.as_ref().map_or(0.0, |z| z.area); @@ -51,7 +51,7 @@ impl Government { } WorldCommand::MapBuildSpecialBuilding { kind: x, .. } => match x { BuildingKind::GoodsCompany(x) => { - let descr = &goria.read::().descriptions[*x]; + let descr = &sim.read::().descriptions[*x]; descr.price + descr .zone diff --git a/egregoria/src/economy/item.rs b/simulation/src/economy/item.rs similarity index 100% rename from egregoria/src/economy/item.rs rename to simulation/src/economy/item.rs diff --git a/egregoria/src/economy/market.rs b/simulation/src/economy/market.rs similarity index 100% rename from egregoria/src/economy/market.rs rename to simulation/src/economy/market.rs diff --git a/egregoria/src/economy/mod.rs b/simulation/src/economy/mod.rs similarity index 100% rename from egregoria/src/economy/mod.rs rename to simulation/src/economy/mod.rs diff --git a/egregoria/src/engine_interaction.rs b/simulation/src/engine_interaction.rs similarity index 80% rename from egregoria/src/engine_interaction.rs rename to simulation/src/engine_interaction.rs index 1ff85df7..1f9e942b 100644 --- a/egregoria/src/engine_interaction.rs +++ b/simulation/src/engine_interaction.rs @@ -20,7 +20,7 @@ use crate::transportation::train::{spawn_train, RailWagonKind}; use crate::transportation::{spawn_parked_vehicle_with_spot, unpark, VehicleKind}; use crate::utils::rand_provider::RandProvider; use crate::utils::time::{GameTime, Tick}; -use crate::{Egregoria, EgregoriaOptions, Replay}; +use crate::{SimulationOptions, Replay, Simulation}; #[derive(Clone, Default)] pub struct WorldCommands { @@ -31,7 +31,7 @@ defer_serialize!(WorldCommands, Vec); #[derive(Debug, Clone, Serialize, Deserialize)] pub enum WorldCommand { - Init(Box), + Init(Box), MapRemoveIntersection(IntersectionID), MapRemoveRoad(RoadID), MapRemoveBuilding(BuildingID), @@ -201,24 +201,24 @@ impl WorldCommand { ) } - pub fn apply(&self, goria: &mut Egregoria) { - let cost = Government::action_cost(self, goria); - goria.write::().money -= cost; + pub fn apply(&self, sim: &mut Simulation) { + let cost = Government::action_cost(self, sim); + sim.write::().money -= cost; - let mut rep = goria.resources.write::(); + let mut rep = sim.resources.write::(); if rep.enabled { - let tick = goria.read::(); + let tick = sim.read::(); rep.commands.push((*tick, self.clone())); } drop(rep); match *self { - MapRemoveIntersection(id) => goria.map_mut().remove_intersection(id), - MapRemoveRoad(id) => drop(goria.map_mut().remove_road(id)), - MapRemoveBuilding(id) => drop(goria.map_mut().remove_building(id)), + MapRemoveIntersection(id) => sim.map_mut().remove_intersection(id), + MapRemoveRoad(id) => drop(sim.map_mut().remove_road(id)), + MapRemoveBuilding(id) => drop(sim.map_mut().remove_building(id)), MapBuildHouse(id) => { - if let Some(build) = goria.map_mut().build_house(id) { - let mut infos = goria.write::(); + if let Some(build) = sim.map_mut().build_house(id) { + let mut infos = sim.write::(); infos.insert(build); } } @@ -228,10 +228,10 @@ impl WorldCommand { inter, ref pat, } => { - goria.write::().make_connection(from, to, inter, pat); + sim.write::().make_connection(from, to, inter, pat); } MapMakeMultipleConnections(ref projects, ref links) => { - let mut map = goria.map_mut(); + let mut map = sim.map_mut(); let mut inters = BTreeMap::new(); for (from, to, interpoint, pat) in links { let mut fromproj = projects[*from]; @@ -258,7 +258,7 @@ impl WorldCommand { inter: id, turn: tp, light: lp, - } => goria.map_mut().update_intersection(id, move |i| { + } => sim.map_mut().update_intersection(id, move |i| { i.light_policy = lp; i.turn_policy = tp; }), @@ -269,65 +269,62 @@ impl WorldCommand { ref zone, } => { if let Some(id) = - goria - .write::() + sim.write::() .build_special_building(&obb, kind, gen, zone.clone()) { - goria.write::().insert(id); + sim.write::().insert(id); } } - SetGameTime(gt) => *goria.write::() = gt, + SetGameTime(gt) => *sim.write::() = gt, AddTrain { dist, n_wagons, lane, } => { - spawn_train(goria, dist, n_wagons, lane, RailWagonKind::Freight); + spawn_train(sim, dist, n_wagons, lane, RailWagonKind::Freight); } - MapLoadParis => load_parismap(&mut goria.map_mut()), + MapLoadParis => load_parismap(&mut sim.map_mut()), MapLoadTestField { pos, size, spacing } => { - load_testfield(&mut goria.map_mut(), pos, size, spacing) + load_testfield(&mut sim.map_mut(), pos, size, spacing) } Init(ref opts) => { if opts.save_replay { - let mut rep = goria.resources.write::(); + let mut rep = sim.resources.write::(); rep.enabled = true; - let tick = goria.read::(); + let tick = sim.read::(); rep.commands.push((*tick, Init(opts.clone()))); } if opts.terrain_size > 0 { - generate_terrain(goria, opts.terrain_size); + generate_terrain(sim, opts.terrain_size); } - goria - .resources - .insert::(EgregoriaOptions::clone(opts)); + sim.resources + .insert::(SimulationOptions::clone(opts)); } UpdateZone { building, ref zone } => { - let mut map = goria.map_mut(); + let mut map = sim.map_mut(); map.update_zone(building, move |z| *z = zone.clone()); } SpawnRandomCars { n_cars } => { for _ in 0..n_cars { - let mut pm = goria.write::(); - let map = goria.map(); - let mut rng = goria.write::(); + let mut pm = sim.write::(); + let map = sim.map(); + let mut rng = sim.write::(); let Some(spot) = pm.reserve_random_free_spot(&map.parking, rng.next_u64()) else { continue; }; drop((map, pm, rng)); - let Some(v_id) = spawn_parked_vehicle_with_spot(goria, VehicleKind::Car, spot) else { continue; }; - unpark(goria, v_id); + let Some(v_id) = spawn_parked_vehicle_with_spot(sim, VehicleKind::Car, spot) else { continue; }; + unpark(sim, v_id); - goria.write::().vehicles.insert(v_id); + sim.write::().vehicles.insert(v_id); } } SendMessage { ref message } => { - goria - .write::() + sim.write::() .chat .add_message(message.clone()); } @@ -335,11 +332,11 @@ impl WorldCommand { } } -fn generate_terrain(goria: &mut Egregoria, size: u32) { +fn generate_terrain(sim: &mut Simulation, size: u32) { info!("generating terrain.."); let t = Instant::now(); - goria.map_mut().terrain = Terrain::new(size, size); + sim.map_mut().terrain = Terrain::new(size, size); info!("took {}s", t.elapsed().as_secs_f32()); let c = vec3(3000.0 + 72.2 / 2.0, 200.0 / 2.0 + 1.0, 0.3); @@ -349,14 +346,14 @@ fn generate_terrain(goria: &mut Egregoria, size: u32) { let pat = LanePatternBuilder::new().rail(true).build(); - goria.map_mut().make_connection( + sim.map_mut().make_connection( MapProject::ground(c - offy * 100.0), MapProject::ground(c + offy * 120.0), None, &pat, ); - if goria + if sim .map_mut() .build_special_building( &obb, diff --git a/egregoria/src/init.rs b/simulation/src/init.rs similarity index 89% rename from egregoria/src/init.rs rename to simulation/src/init.rs index 968132f9..e7ae9c60 100644 --- a/egregoria/src/init.rs +++ b/simulation/src/init.rs @@ -20,8 +20,8 @@ use crate::utils::time::Tick; use crate::world::{CompanyEnt, FreightStationEnt, HumanEnt, TrainEnt, VehicleEnt, WagonEnt}; use crate::World; use crate::{ - add_souls_to_empty_buildings, utils, CollisionWorld, Egregoria, EgregoriaOptions, GameTime, - ParCommandBuffer, RandProvider, Replay, RunnableSystem, RNG_SEED, SECONDS_PER_DAY, + add_souls_to_empty_buildings, utils, CollisionWorld, GameTime, ParCommandBuffer, RandProvider, + Replay, RunnableSystem, Simulation, SimulationOptions, RNG_SEED, SECONDS_PER_DAY, SECONDS_PER_HOUR, }; use common::saveload::{Bincode, Encoder}; @@ -45,7 +45,7 @@ pub fn init() { register_system("freight_station", freight_station_system); register_system("random_vehicles", random_vehicles_update); - register_system_goria("add_souls_to_empty_buildings", add_souls_to_empty_buildings); + register_system_sim("add_souls_to_empty_buildings", add_souls_to_empty_buildings); register_resource_noserialize::(); register_resource_noserialize::(); @@ -57,7 +57,7 @@ pub fn init() { register_resource_noserialize::>(); register_resource_noinit::("market"); register_resource_noinit::("ecostats"); - register_resource_noinit::("egregoriaoptions"); + register_resource_noinit::("simoptions"); register_init(init_market); @@ -79,13 +79,13 @@ pub fn init() { } pub struct InitFunc { - pub f: Box, + pub f: Box, } pub(crate) struct SaveLoadFunc { pub name: &'static str, - pub save: Box Vec + 'static>, - pub load: Box) + 'static>, + pub save: Box Vec + 'static>, + pub load: Box) + 'static>, } pub(crate) struct GSystem { @@ -99,7 +99,7 @@ pub(crate) static mut GSYSTEMS: Vec = Vec::new(); fn register_init(s: fn(&mut World, &mut Resources)) { unsafe { INIT_FUNCS.push(InitFunc { - f: Box::new(move |goria| s(&mut goria.world, &mut goria.resources)), + f: Box::new(move |sim| s(&mut sim.world, &mut sim.resources)), }); } } @@ -109,7 +109,7 @@ fn register_system(name: &'static str, s: fn(&mut World, &mut Resources)) { GSYSTEMS.push(GSystem { s: Box::new(move || { Box::new(utils::scheduler::RunnableFn { - f: move |goria| s(&mut goria.world, &mut goria.resources), + f: move |sim| s(&mut sim.world, &mut sim.resources), name, }) }), @@ -117,7 +117,7 @@ fn register_system(name: &'static str, s: fn(&mut World, &mut Resources)) { } } -fn register_system_goria(name: &'static str, s: fn(&mut Egregoria)) { +fn register_system_sim(name: &'static str, s: fn(&mut Simulation)) { unsafe { GSYSTEMS.push(GSystem { s: Box::new(move || Box::new(utils::scheduler::RunnableFn { f: s, name })), diff --git a/egregoria/src/lib.rs b/simulation/src/lib.rs similarity index 92% rename from egregoria/src/lib.rs rename to simulation/src/lib.rs index 1d309d11..d012ff5f 100644 --- a/egregoria/src/lib.rs +++ b/simulation/src/lib.rs @@ -104,7 +104,7 @@ impl TryFrom for SoulID { debug_inspect_impl!(SoulID); -pub struct Egregoria { +pub struct Simulation { pub(crate) world: World, resources: Resources, } @@ -113,21 +113,21 @@ const RNG_SEED: u64 = 123; const VERSION: &str = include_str!("../../VERSION"); #[derive(Debug, Copy, Clone, Serialize, Deserialize)] -pub struct EgregoriaOptions { +pub struct SimulationOptions { pub terrain_size: u32, pub save_replay: bool, } -impl Default for EgregoriaOptions { +impl Default for SimulationOptions { fn default() -> Self { - EgregoriaOptions { + SimulationOptions { terrain_size: 50, save_replay: true, } } } -impl Egregoria { +impl Simulation { pub fn schedule() -> SeqSchedule { let mut schedule = SeqSchedule::default(); unsafe { @@ -139,15 +139,15 @@ impl Egregoria { schedule } - pub fn new(gen_terrain: bool) -> Egregoria { - Self::new_with_options(EgregoriaOptions { + pub fn new(gen_terrain: bool) -> Simulation { + Self::new_with_options(SimulationOptions { terrain_size: if gen_terrain { 50 } else { 0 }, ..Default::default() }) } - pub fn from_replay(replay: Replay) -> (Egregoria, EgregoriaReplayLoader) { - let mut goria = Egregoria { + pub fn from_replay(replay: Replay) -> (Simulation, SimulationReplayLoader) { + let mut sim = Simulation { world: Default::default(), resources: Default::default(), }; @@ -156,13 +156,13 @@ impl Egregoria { unsafe { for s in &INIT_FUNCS { - (s.f)(&mut goria); + (s.f)(&mut sim); } } ( - goria, - EgregoriaReplayLoader { + sim, + SimulationReplayLoader { replay, pastt: Tick::default(), idx: 0, @@ -172,8 +172,8 @@ impl Egregoria { ) } - pub fn new_with_options(opts: EgregoriaOptions) -> Egregoria { - let mut goria = Egregoria { + pub fn new_with_options(opts: SimulationOptions) -> Simulation { + let mut sim = Simulation { world: Default::default(), resources: Default::default(), }; @@ -183,20 +183,20 @@ impl Egregoria { unsafe { for s in &INIT_FUNCS { - (s.f)(&mut goria); + (s.f)(&mut sim); } } - Init(Box::new(opts)).apply(&mut goria); + Init(Box::new(opts)).apply(&mut sim); let start_commands: Vec<(u32, WorldCommand)> = common::saveload::JSON::decode(START_COMMANDS.as_bytes()).unwrap(); for (_, command) in start_commands { - command.apply(&mut goria); + command.apply(&mut sim); } - goria + sim } pub fn world_res(&mut self) -> (&mut World, &mut Resources) { @@ -238,7 +238,7 @@ impl Egregoria { game_schedule: &mut SeqSchedule, commands: impl IntoIterator, ) -> Duration { - profiling::scope!("egregoria::tick"); + profiling::scope!("simulation::tick"); let t = Instant::now(); // It is very important that the first thing being done is applying commands // so that instant commands work on single player but the game is still deterministic @@ -290,8 +290,8 @@ impl Egregoria { } pub fn load_from_disk(save_name: &str) -> Option { - let goria: Egregoria = common::saveload::CompressedBincode::load(save_name).ok()?; - Some(goria) + let sim: Simulation = common::saveload::CompressedBincode::load(save_name).ok()?; + Some(sim) } pub fn save_to_disk(&self, save_name: &str) { @@ -347,12 +347,12 @@ impl Egregoria { } } -impl Serialize for Egregoria { +impl Serialize for Simulation { fn serialize(&self, serializer: S) -> Result where S: Serializer, { - log::info!("serializing egregoria"); + log::info!("serializing sim state"); let t = Instant::now(); let mut m: FastMap> = FastMap::default(); @@ -365,7 +365,7 @@ impl Serialize for Egregoria { log::info!("took {}s to serialize resources", t.elapsed().as_secs_f32()); - let v = EgregoriaSer { + let v = SimulationSer { world: &self.world, version: VERSION.to_string(), res: m, @@ -377,28 +377,28 @@ impl Serialize for Egregoria { } #[derive(Serialize)] -struct EgregoriaSer<'a> { +struct SimulationSer<'a> { world: &'a World, version: String, res: FastMap>, } #[derive(Deserialize)] -struct EgregoriaDeser { +struct SimulationDeser { world: World, version: String, res: FastMap>, } -impl<'de> Deserialize<'de> for Egregoria { +impl<'de> Deserialize<'de> for Simulation { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { - log::info!("deserializing egregoria"); + log::info!("deserializing sim state"); let t = Instant::now(); - let mut goriadeser = ::deserialize(deserializer)?; + let mut simdeser = ::deserialize(deserializer)?; log::info!( "took {}s to deserialize base deser", @@ -406,35 +406,35 @@ impl<'de> Deserialize<'de> for Egregoria { ); let cur_version_parts = VERSION.split('.').collect::>(); - let deser_parts = goriadeser.version.split('.').collect::>(); + let deser_parts = simdeser.version.split('.').collect::>(); if cur_version_parts[0] != deser_parts[0] || (cur_version_parts[0] == "0" && cur_version_parts[1] != deser_parts[1]) { log::warn!( "incompatible version, save might be corrupted! save is: {} - game is: {}", - goriadeser.version, + simdeser.version, VERSION ); } - let mut goria = Self { + let mut sim = Self { world: World::default(), resources: Resources::default(), }; unsafe { for s in &INIT_FUNCS { - (s.f)(&mut goria); + (s.f)(&mut sim); } } - goria.world = goriadeser.world; + sim.world = simdeser.world; unsafe { for l in &SAVELOAD_FUNCS { - if let Some(data) = goriadeser.res.remove(l.name) { - (l.load)(&mut goria, data); + if let Some(data) = simdeser.res.remove(l.name) { + (l.load)(&mut sim, data); } } } @@ -444,7 +444,7 @@ impl<'de> Deserialize<'de> for Egregoria { t.elapsed().as_secs_f32() ); - Ok(goria) + Ok(sim) } } diff --git a/egregoria/src/map/change_detection.rs b/simulation/src/map/change_detection.rs similarity index 100% rename from egregoria/src/map/change_detection.rs rename to simulation/src/map/change_detection.rs diff --git a/egregoria/src/map/light_policy.rs b/simulation/src/map/light_policy.rs similarity index 100% rename from egregoria/src/map/light_policy.rs rename to simulation/src/map/light_policy.rs diff --git a/egregoria/src/map/map.rs b/simulation/src/map/map.rs similarity index 100% rename from egregoria/src/map/map.rs rename to simulation/src/map/map.rs diff --git a/egregoria/src/map/mod.rs b/simulation/src/map/mod.rs similarity index 100% rename from egregoria/src/map/mod.rs rename to simulation/src/map/mod.rs diff --git a/egregoria/src/map/objects/building.rs b/simulation/src/map/objects/building.rs similarity index 100% rename from egregoria/src/map/objects/building.rs rename to simulation/src/map/objects/building.rs diff --git a/egregoria/src/map/objects/intersection.rs b/simulation/src/map/objects/intersection.rs similarity index 100% rename from egregoria/src/map/objects/intersection.rs rename to simulation/src/map/objects/intersection.rs diff --git a/egregoria/src/map/objects/lane.rs b/simulation/src/map/objects/lane.rs similarity index 100% rename from egregoria/src/map/objects/lane.rs rename to simulation/src/map/objects/lane.rs diff --git a/egregoria/src/map/objects/lot.rs b/simulation/src/map/objects/lot.rs similarity index 100% rename from egregoria/src/map/objects/lot.rs rename to simulation/src/map/objects/lot.rs diff --git a/egregoria/src/map/objects/parking.rs b/simulation/src/map/objects/parking.rs similarity index 100% rename from egregoria/src/map/objects/parking.rs rename to simulation/src/map/objects/parking.rs diff --git a/egregoria/src/map/objects/road.rs b/simulation/src/map/objects/road.rs similarity index 100% rename from egregoria/src/map/objects/road.rs rename to simulation/src/map/objects/road.rs diff --git a/egregoria/src/map/objects/turn.rs b/simulation/src/map/objects/turn.rs similarity index 100% rename from egregoria/src/map/objects/turn.rs rename to simulation/src/map/objects/turn.rs diff --git a/egregoria/src/map/pathfinding.rs b/simulation/src/map/pathfinding.rs similarity index 100% rename from egregoria/src/map/pathfinding.rs rename to simulation/src/map/pathfinding.rs diff --git a/egregoria/src/map/procgen/building.rs b/simulation/src/map/procgen/building.rs similarity index 100% rename from egregoria/src/map/procgen/building.rs rename to simulation/src/map/procgen/building.rs diff --git a/egregoria/src/map/procgen/heightmap.rs b/simulation/src/map/procgen/heightmap.rs similarity index 100% rename from egregoria/src/map/procgen/heightmap.rs rename to simulation/src/map/procgen/heightmap.rs diff --git a/egregoria/src/map/procgen/presets.rs b/simulation/src/map/procgen/presets.rs similarity index 100% rename from egregoria/src/map/procgen/presets.rs rename to simulation/src/map/procgen/presets.rs diff --git a/egregoria/src/map/serializing.rs b/simulation/src/map/serializing.rs similarity index 100% rename from egregoria/src/map/serializing.rs rename to simulation/src/map/serializing.rs diff --git a/egregoria/src/map/spatial_map.rs b/simulation/src/map/spatial_map.rs similarity index 100% rename from egregoria/src/map/spatial_map.rs rename to simulation/src/map/spatial_map.rs diff --git a/egregoria/src/map/terrain.rs b/simulation/src/map/terrain.rs similarity index 100% rename from egregoria/src/map/terrain.rs rename to simulation/src/map/terrain.rs diff --git a/egregoria/src/map/traffic_control.rs b/simulation/src/map/traffic_control.rs similarity index 100% rename from egregoria/src/map/traffic_control.rs rename to simulation/src/map/traffic_control.rs diff --git a/egregoria/src/map/traversable.rs b/simulation/src/map/traversable.rs similarity index 100% rename from egregoria/src/map/traversable.rs rename to simulation/src/map/traversable.rs diff --git a/egregoria/src/map/turn_policy.rs b/simulation/src/map/turn_policy.rs similarity index 100% rename from egregoria/src/map/turn_policy.rs rename to simulation/src/map/turn_policy.rs diff --git a/egregoria/src/map_dynamic/binfos.rs b/simulation/src/map_dynamic/binfos.rs similarity index 100% rename from egregoria/src/map_dynamic/binfos.rs rename to simulation/src/map_dynamic/binfos.rs diff --git a/egregoria/src/map_dynamic/dispatch.rs b/simulation/src/map_dynamic/dispatch.rs similarity index 100% rename from egregoria/src/map_dynamic/dispatch.rs rename to simulation/src/map_dynamic/dispatch.rs diff --git a/egregoria/src/map_dynamic/itinerary.rs b/simulation/src/map_dynamic/itinerary.rs similarity index 100% rename from egregoria/src/map_dynamic/itinerary.rs rename to simulation/src/map_dynamic/itinerary.rs diff --git a/egregoria/src/map_dynamic/mod.rs b/simulation/src/map_dynamic/mod.rs similarity index 100% rename from egregoria/src/map_dynamic/mod.rs rename to simulation/src/map_dynamic/mod.rs diff --git a/egregoria/src/map_dynamic/parking.rs b/simulation/src/map_dynamic/parking.rs similarity index 100% rename from egregoria/src/map_dynamic/parking.rs rename to simulation/src/map_dynamic/parking.rs diff --git a/egregoria/src/map_dynamic/router.rs b/simulation/src/map_dynamic/router.rs similarity index 97% rename from egregoria/src/map_dynamic/router.rs rename to simulation/src/map_dynamic/router.rs index 456e31bc..6327daa5 100644 --- a/egregoria/src/map_dynamic/router.rs +++ b/simulation/src/map_dynamic/router.rs @@ -214,7 +214,7 @@ pub fn routing_update_system(world: &mut World, resources: &mut Resources) { } } RoutingStep::Unpark(vehicle) => { - cbuf_vehicle.exec_ent(vehicle, move |goria| unpark(goria, vehicle)); + cbuf_vehicle.exec_ent(vehicle, move |sim| unpark(sim, vehicle)); } RoutingStep::GetInVehicle(vehicle) => { if !world.vehicles.contains_key(vehicle) { @@ -263,9 +263,9 @@ fn walk_inside(body: HumanID, h: &mut HumanEnt, cbuf: &ParCommandBuffer, loc: &mut Location) { *loc = Location::Outside; - cbuf.exec_ent(body, move |goria| { - let coll = put_pedestrian_in_coworld(&mut goria.write::(), pos); - let h = unwrap_ret!(goria.world.humans.get_mut(body)); + cbuf.exec_ent(body, move |sim| { + let coll = put_pedestrian_in_coworld(&mut sim.write::(), pos); + let h = unwrap_ret!(sim.world.humans.get_mut(body)); h.trans.position = pos; h.collider = Some(coll); }); diff --git a/egregoria/src/multiplayer/chat.rs b/simulation/src/multiplayer/chat.rs similarity index 100% rename from egregoria/src/multiplayer/chat.rs rename to simulation/src/multiplayer/chat.rs diff --git a/egregoria/src/multiplayer/mod.rs b/simulation/src/multiplayer/mod.rs similarity index 100% rename from egregoria/src/multiplayer/mod.rs rename to simulation/src/multiplayer/mod.rs diff --git a/egregoria/src/physics/mod.rs b/simulation/src/physics/mod.rs similarity index 92% rename from egregoria/src/physics/mod.rs rename to simulation/src/physics/mod.rs index 511724c4..5148f7ab 100644 --- a/egregoria/src/physics/mod.rs +++ b/simulation/src/physics/mod.rs @@ -1,6 +1,6 @@ use crate::transportation::Vehicle; use crate::utils::resources::Resources; -use crate::{Egregoria, World}; +use crate::{Simulation, World}; use egui_inspect::Inspect; use egui_inspect::InspectVec2Rotation; use flat_spatial::grid::GridHandle; @@ -62,9 +62,9 @@ pub struct Collider(pub GridHandle); debug_inspect_impl!(Collider); impl Collider { - pub fn destroy(self) -> impl FnOnce(&mut Egregoria) { - move |goria| { - let cw = &mut goria.write::(); + pub fn destroy(self) -> impl FnOnce(&mut Simulation) { + move |sim| { + let cw = &mut sim.write::(); cw.remove_maintain(self.0); } } diff --git a/egregoria/src/souls/desire/buyfood.rs b/simulation/src/souls/desire/buyfood.rs similarity index 100% rename from egregoria/src/souls/desire/buyfood.rs rename to simulation/src/souls/desire/buyfood.rs diff --git a/egregoria/src/souls/desire/home.rs b/simulation/src/souls/desire/home.rs similarity index 100% rename from egregoria/src/souls/desire/home.rs rename to simulation/src/souls/desire/home.rs diff --git a/egregoria/src/souls/desire/mod.rs b/simulation/src/souls/desire/mod.rs similarity index 100% rename from egregoria/src/souls/desire/mod.rs rename to simulation/src/souls/desire/mod.rs diff --git a/egregoria/src/souls/desire/work.rs b/simulation/src/souls/desire/work.rs similarity index 100% rename from egregoria/src/souls/desire/work.rs rename to simulation/src/souls/desire/work.rs diff --git a/egregoria/src/souls/first_names.txt b/simulation/src/souls/first_names.txt similarity index 100% rename from egregoria/src/souls/first_names.txt rename to simulation/src/souls/first_names.txt diff --git a/egregoria/src/souls/freight_station.rs b/simulation/src/souls/freight_station.rs similarity index 97% rename from egregoria/src/souls/freight_station.rs rename to simulation/src/souls/freight_station.rs index 8dcdd0e8..eed42753 100644 --- a/egregoria/src/souls/freight_station.rs +++ b/simulation/src/souls/freight_station.rs @@ -6,7 +6,7 @@ use crate::utils::resources::Resources; use crate::utils::time::{GameTime, Tick}; use crate::world::{FreightStationEnt, FreightStationID, TrainID}; use crate::World; -use crate::{Egregoria, ParCommandBuffer, SoulID}; +use crate::{ParCommandBuffer, Simulation, SoulID}; use geom::Transform; use serde::{Deserialize, Serialize}; @@ -34,10 +34,10 @@ pub struct FreightStation { } pub fn freight_station_soul( - goria: &mut Egregoria, + sim: &mut Simulation, building: BuildingID, ) -> Option { - let map = goria.map(); + let map = sim.map(); let f = FreightStation { building, @@ -54,13 +54,12 @@ pub fn freight_station_soul( drop(map); - let id = goria.world.insert(FreightStationEnt { + let id = sim.world.insert(FreightStationEnt { f, trans: Transform::new_dir(pos.z(height), axis[1].z(0.0).normalize()), }); - goria - .write::() + sim.write::() .set_owner(building, SoulID::FreightStation(id)); Some(id) diff --git a/egregoria/src/souls/goods_company.rs b/simulation/src/souls/goods_company.rs similarity index 93% rename from egregoria/src/souls/goods_company.rs rename to simulation/src/souls/goods_company.rs index 943a1eb3..de3f8dd5 100644 --- a/egregoria/src/souls/goods_company.rs +++ b/simulation/src/souls/goods_company.rs @@ -7,7 +7,7 @@ use crate::utils::resources::Resources; use crate::utils::time::GameTime; use crate::world::{CompanyEnt, HumanEnt, HumanID, VehicleID}; use crate::World; -use crate::{Egregoria, ParCommandBuffer, SoulID}; +use crate::{ParCommandBuffer, Simulation, SoulID}; use common::descriptions::{GoodsCompanyDescriptionJSON, ZoneDescription}; use common::saveload::Encoder; use egui_inspect::Inspect; @@ -207,15 +207,15 @@ impl GoodsCompany { } } -pub fn company_soul(goria: &mut Egregoria, company: GoodsCompany) -> Option { - let map = goria.map(); +pub fn company_soul(sim: &mut Simulation, company: GoodsCompany) -> Option { + let map = sim.map(); let b = map.buildings().get(company.building)?; let door_pos = b.door_pos; let obb = b.obb; let height = b.height; drop(map); - let id = goria.world.insert(CompanyEnt { + let id = sim.world.insert(CompanyEnt { trans: Transform::new(obb.center().z(height)), comp: company, workers: Default::default(), @@ -223,22 +223,21 @@ pub fn company_soul(goria: &mut Egregoria, company: GoodsCompany) -> Option().id("job-opening"); + let job_opening = sim.read::().id("job-opening"); { - let m = &mut *goria.write::(); + let m = &mut *sim.write::(); m.produce(soul, job_opening, company.max_workers); m.sell_all(soul, door_pos.xy(), job_opening, 0); company.recipe.init(soul, door_pos.xy(), m); } - goria - .write::() + sim.write::() .set_owner(company.building, soul); Some(soul) @@ -283,8 +282,8 @@ pub fn company_system(world: &mut World, res: &mut Resources) { if let Some(owner_build) = find_trade_place(trade.seller, b.door_pos.xy(), binfos, map) { - cbuf.exec_ent(me, move |goria| { - let (world, res) = goria.world_res(); + cbuf.exec_ent(me, move |sim| { + let (world, res) = sim.world_res(); if let Some(SoulID::FreightStation(owner)) = res.read::().owner(owner_build) { @@ -314,8 +313,8 @@ pub fn company_system(world: &mut World, res: &mut Resources) { log::warn!("driver can't find the place to deliver for {:?}", &trade); return; }; - cbuf.exec_ent(me, move |goria| { - let Some(h) = goria.world.humans.get_mut(driver) else { return; }; + cbuf.exec_ent(me, move |sim| { + let Some(h) = sim.world.humans.get_mut(driver) else { return; }; let Some(w) = h.work.as_mut() else { return; }; let WorkKind::Driver { deliver_order, @@ -346,8 +345,8 @@ pub fn company_system(world: &mut World, res: &mut Resources) { let offset = common::rand::randu(common::hash_u64(worker) as u32); let b = c.comp.building; - cbuf_human.exec_ent(worker, move |goria| { - let Some(w) = goria.world.humans.get_mut(worker) else { return }; + cbuf_human.exec_ent(worker, move |sim| { + let Some(w) = sim.world.humans.get_mut(worker) else { return }; w.work = Some(Work::new(b, kind, offset)); }); } diff --git a/egregoria/src/souls/human.rs b/simulation/src/souls/human.rs similarity index 88% rename from egregoria/src/souls/human.rs rename to simulation/src/souls/human.rs index fd817cbf..f4da7c83 100644 --- a/egregoria/src/souls/human.rs +++ b/simulation/src/souls/human.rs @@ -11,7 +11,7 @@ use crate::utils::resources::Resources; use crate::utils::time::GameTime; use crate::world::{FreightStationEnt, HumanEnt, HumanID, VehicleID}; use crate::World; -use crate::{BuildingKind, Egregoria, Map, ParCommandBuffer, SoulID}; +use crate::{BuildingKind, Map, ParCommandBuffer, Simulation, SoulID}; use egui_inspect::Inspect; use geom::Transform; use lazy_static::lazy_static; @@ -229,28 +229,28 @@ pub fn update_decision( } } -pub fn spawn_human(goria: &mut Egregoria, house: BuildingID) -> Option { +pub fn spawn_human(sim: &mut Simulation, house: BuildingID) -> Option { profiling::scope!("spawn_human"); - let map = goria.map(); + let map = sim.map(); let housepos = map.buildings().get(house)?.door_pos; drop(map); - let _color = random_pedestrian_shirt_color(&mut goria.write::()); + let _color = random_pedestrian_shirt_color(&mut sim.write::()); - let hpos = goria.map().buildings().get(house)?.door_pos; - let p = Pedestrian::new(&mut goria.write::()); + let hpos = sim.map().buildings().get(house)?.door_pos; + let p = Pedestrian::new(&mut sim.write::()); - let registry = goria.read::(); - let time = goria.read::().instant(); + let registry = sim.read::(); + let time = sim.read::().instant(); let food = BuyFood::new(time, ®istry); drop(registry); - let car = spawn_parked_vehicle(goria, VehicleKind::Car, housepos); + let car = spawn_parked_vehicle(sim, VehicleKind::Car, housepos); - let personal_info = Box::new(PersonalInfo::new(&mut goria.write::())); + let personal_info = Box::new(PersonalInfo::new(&mut sim.write::())); - let id = goria.world.insert(HumanEnt { + let id = sim.world.insert(HumanEnt { trans: Transform::new(hpos), location: Location::Building(house), pedestrian: p, @@ -267,12 +267,12 @@ pub fn spawn_human(goria: &mut Egregoria, house: BuildingID) -> Option }); let soul = SoulID::Human(id); - let mut m = goria.write::(); - let registry = goria.read::(); + let mut m = sim.write::(); + let registry = sim.read::(); m.buy(soul, housepos.xy(), registry.id("job-opening"), 1); - goria.write::().get_in(house, soul); - goria.write::().set_owner(house, soul); + sim.write::().get_in(house, soul); + sim.write::().set_owner(house, soul); Some(id) } diff --git a/egregoria/src/souls/mod.rs b/simulation/src/souls/mod.rs similarity index 81% rename from egregoria/src/souls/mod.rs rename to simulation/src/souls/mod.rs index 0b7e5f09..e4344ad7 100644 --- a/egregoria/src/souls/mod.rs +++ b/simulation/src/souls/mod.rs @@ -4,7 +4,7 @@ use crate::souls::freight_station::freight_station_soul; use crate::souls::goods_company::{company_soul, CompanyKind, GoodsCompany, GoodsCompanyRegistry}; use crate::souls::human::spawn_human; use crate::transportation::{spawn_parked_vehicle, VehicleKind}; -use crate::Egregoria; +use crate::Simulation; use geom::Vec3; use std::collections::BTreeMap; @@ -16,10 +16,10 @@ pub mod goods_company; pub mod human; /// Adds souls to empty buildings -pub(crate) fn add_souls_to_empty_buildings(goria: &mut Egregoria) { +pub(crate) fn add_souls_to_empty_buildings(sim: &mut Simulation) { profiling::scope!("souls::add_souls_to_empty_buildings"); - let map = goria.map(); - let infos = goria.read::(); + let map = sim.map(); + let infos = sim.read::(); let mut empty_buildings: BTreeMap> = BTreeMap::default(); for (id, building) in map.buildings() { @@ -43,7 +43,7 @@ pub(crate) fn add_souls_to_empty_buildings(goria: &mut Egregoria) { .iter() .take(50) { - spawn_human(goria, build_id); + spawn_human(sim, build_id); n_souls_added += 1; } @@ -52,7 +52,7 @@ pub(crate) fn add_souls_to_empty_buildings(goria: &mut Egregoria) { .unwrap_or(&vec![]) .iter() { - freight_station_soul(goria, build_id); + freight_station_soul(sim, build_id); n_souls_added += 1; } @@ -61,15 +61,15 @@ pub(crate) fn add_souls_to_empty_buildings(goria: &mut Egregoria) { .filter_map(|(kind, v)| kind.as_goods_company().zip(Some(v))) .flat_map(|(bkind, v)| v.iter().map(move |x| (bkind, x))) { - let registry = goria.read::(); + let registry = sim.read::(); let des = &unwrap_or!(registry.descriptions.get(bkind), continue); let ckind = des.kind; - let mk_trucks = |goria: &mut Egregoria| { + let mk_trucks = |sim: &mut Simulation| { let mut trucks = vec![]; if let CompanyKind::Factory { n_trucks } = ckind { for _ in 0..n_trucks { - trucks.extend(spawn_parked_vehicle(goria, VehicleKind::Truck, pos)) + trucks.extend(spawn_parked_vehicle(sim, VehicleKind::Truck, pos)) } if trucks.is_empty() { return None; @@ -87,11 +87,11 @@ pub(crate) fn add_souls_to_empty_buildings(goria: &mut Egregoria) { driver: None, trucks: { drop(registry); - unwrap_or!(mk_trucks(goria), continue) + unwrap_or!(mk_trucks(sim), continue) }, }; - company_soul(goria, comp); + company_soul(sim, comp); n_souls_added += 1; } diff --git a/egregoria/src/souls/names.txt b/simulation/src/souls/names.txt similarity index 100% rename from egregoria/src/souls/names.txt rename to simulation/src/souls/names.txt diff --git a/egregoria/src/tests/mod.rs b/simulation/src/tests/mod.rs similarity index 88% rename from egregoria/src/tests/mod.rs rename to simulation/src/tests/mod.rs index e64d0bbd..79232e9b 100644 --- a/egregoria/src/tests/mod.rs +++ b/simulation/src/tests/mod.rs @@ -6,7 +6,7 @@ use crate::map::{BuildingID, LanePatternBuilder, ProjectFilter}; use crate::map_dynamic::BuildingInfos; use crate::utils::scheduler::SeqSchedule; use crate::utils::time::Tick; -use crate::{Egregoria, EgregoriaOptions}; +use crate::{SimulationOptions, Simulation}; use common::logger::MyLog; use common::saveload::Encoder; use geom::{Vec2, Vec3}; @@ -15,7 +15,7 @@ mod test_iso; mod vehicles; pub(crate) struct TestCtx { - pub g: Egregoria, + pub g: Simulation, sched: SeqSchedule, } @@ -24,12 +24,12 @@ impl TestCtx { MyLog::init(); crate::init::init(); - let g = Egregoria::new_with_options(EgregoriaOptions { + let g = Simulation::new_with_options(SimulationOptions { terrain_size: 1, save_replay: false, ..Default::default() }); - let sched = Egregoria::schedule(); + let sched = Simulation::schedule(); Self { g, sched } } @@ -69,7 +69,7 @@ impl TestCtx { .tick(&mut self.sched, WorldCommands::default().as_ref()); let serialized = common::saveload::Bincode::encode(&self.g).unwrap(); - let deserialized: Egregoria = common::saveload::Bincode::decode(&serialized).unwrap(); + let deserialized: Simulation = common::saveload::Bincode::decode(&serialized).unwrap(); let testhashes = self.g.hashes(); for (key, hash) in deserialized.hashes().iter() { diff --git a/egregoria/src/tests/test_iso.rs b/simulation/src/tests/test_iso.rs similarity index 92% rename from egregoria/src/tests/test_iso.rs rename to simulation/src/tests/test_iso.rs index 216f55b5..a9a5b300 100644 --- a/egregoria/src/tests/test_iso.rs +++ b/simulation/src/tests/test_iso.rs @@ -3,7 +3,7 @@ use crate::map::{LanePatternBuilder, Map, MapProject, ProjectKind}; use crate::utils::scheduler::SeqSchedule; use crate::utils::time::Tick; use crate::World; -use crate::{Egregoria, Replay}; +use crate::{Replay, Simulation}; use common::logger::MyLog; use common::saveload::{Bincode, Encoder}; use geom::vec3; @@ -228,13 +228,13 @@ fn test_world_survives_serde() { MyLog::init(); let replay: Replay = common::saveload::JSONPretty::decode(REPLAY).unwrap(); - let (mut goria, mut loader) = Egregoria::from_replay(replay.clone()); - let (mut goria2, mut loader2) = Egregoria::from_replay(replay); + let (mut sim, mut loader) = Simulation::from_replay(replay.clone()); + let (mut sim2, mut loader2) = Simulation::from_replay(replay); let mut s = SeqSchedule::default(); //let mut idx = 0; - while !loader.advance_tick(&mut goria, &mut s) { - loader2.advance_tick(&mut goria2, &mut s); + while !loader.advance_tick(&mut sim, &mut s) { + loader2.advance_tick(&mut sim2, &mut s); /* let next_idx = idx @@ -247,7 +247,7 @@ fn test_world_survives_serde() { match command { WorldCommand::MapMakeConnection { from, to, .. } => { println!("{:?} {:?}", tick, command); - let map = goria.map(); + let map = sim.map(); check_coherent(&*map, *from); println!("ho"); @@ -259,36 +259,36 @@ fn test_world_survives_serde() { idx = next_idx;*/ - let tick = goria.read::().0; + let tick = sim.read::().0; if tick % 1000 != 0 || (tick < 7840) { continue; } println!( "--- tick {} ({}/{})", - goria.read::().0, + sim.read::().0, loader.pastt.0, loader.replay.commands.last().unwrap().0 .0 ); - let ser = common::saveload::Bincode::encode(&goria).unwrap(); - let mut deser: Egregoria = common::saveload::Bincode::decode(&ser).unwrap(); + let ser = common::saveload::Bincode::encode(&sim).unwrap(); + let mut deser: Simulation = common::saveload::Bincode::decode(&ser).unwrap(); - if !deser.is_equal(&goria) { + if !deser.is_equal(&sim) { println!("not equal"); deser.save_to_disk("world"); - goria.save_to_disk("world2"); + sim.save_to_disk("world2"); assert!(false); } - if !deser.is_equal(&goria2) { + if !deser.is_equal(&sim2) { println!("not equal"); deser.save_to_disk("world"); - goria2.save_to_disk("world2"); + sim2.save_to_disk("world2"); assert!(false); } - std::mem::swap(&mut deser, &mut goria2); + std::mem::swap(&mut deser, &mut sim2); } - goria.save_to_disk("world2"); + sim.save_to_disk("world2"); } diff --git a/egregoria/src/tests/vehicles.rs b/simulation/src/tests/vehicles.rs similarity index 100% rename from egregoria/src/tests/vehicles.rs rename to simulation/src/tests/vehicles.rs diff --git a/egregoria/src/tests/world_replay.json b/simulation/src/tests/world_replay.json similarity index 100% rename from egregoria/src/tests/world_replay.json rename to simulation/src/tests/world_replay.json diff --git a/egregoria/src/transportation/mod.rs b/simulation/src/transportation/mod.rs similarity index 100% rename from egregoria/src/transportation/mod.rs rename to simulation/src/transportation/mod.rs diff --git a/egregoria/src/transportation/pedestrian.rs b/simulation/src/transportation/pedestrian.rs similarity index 100% rename from egregoria/src/transportation/pedestrian.rs rename to simulation/src/transportation/pedestrian.rs diff --git a/egregoria/src/transportation/road.rs b/simulation/src/transportation/road.rs similarity index 100% rename from egregoria/src/transportation/road.rs rename to simulation/src/transportation/road.rs diff --git a/egregoria/src/transportation/testing_vehicles.rs b/simulation/src/transportation/testing_vehicles.rs similarity index 100% rename from egregoria/src/transportation/testing_vehicles.rs rename to simulation/src/transportation/testing_vehicles.rs diff --git a/egregoria/src/transportation/train.rs b/simulation/src/transportation/train.rs similarity index 98% rename from egregoria/src/transportation/train.rs rename to simulation/src/transportation/train.rs index 4981aee6..e41306d8 100644 --- a/egregoria/src/transportation/train.rs +++ b/simulation/src/transportation/train.rs @@ -2,7 +2,7 @@ use crate::map::{IntersectionID, LaneID, Map, TraverseKind}; use crate::map_dynamic::ItineraryFollower; use crate::utils::resources::Resources; use crate::world::{TrainEnt, TrainID, WagonEnt}; -use crate::{Egregoria, GameTime, Itinerary, ItineraryLeader, Speed, World}; +use crate::{GameTime, Itinerary, ItineraryLeader, Simulation, Speed, World}; use egui_inspect::Inspect; use geom::{PolyLine3, Polyline3Queue, Transform, Vec3}; use ordered_float::OrderedFloat; @@ -82,13 +82,13 @@ pub fn train_length(n_wagons: u32) -> f32 { } pub fn spawn_train( - goria: &mut Egregoria, + sim: &mut Simulation, dist: f32, n_wagons: u32, lane: LaneID, kind: RailWagonKind, ) -> Option { - let (world, res) = goria.world_res(); + let (world, res) = sim.world_res(); let map = res.read::(); let lane = map.lanes().get(lane)?; diff --git a/egregoria/src/transportation/vehicle.rs b/simulation/src/transportation/vehicle.rs similarity index 82% rename from egregoria/src/transportation/vehicle.rs rename to simulation/src/transportation/vehicle.rs index f000d304..8e40c195 100644 --- a/egregoria/src/transportation/vehicle.rs +++ b/simulation/src/transportation/vehicle.rs @@ -3,7 +3,7 @@ use crate::physics::{Collider, CollisionWorld, PhysicsGroup, PhysicsObject}; use crate::utils::rand_provider::RandProvider; use crate::utils::time::GameInstant; use crate::world::{VehicleEnt, VehicleID}; -use crate::Egregoria; +use crate::Simulation; use egui_inspect::Inspect; use geom::Transform; use geom::{Color, Spline3, Vec3}; @@ -45,8 +45,8 @@ pub struct Vehicle { } #[must_use] -pub fn put_vehicle_in_coworld(goria: &Egregoria, w: f32, trans: Transform) -> Collider { - Collider(goria.write::().insert( +pub fn put_vehicle_in_coworld(sim: &Simulation, w: f32, trans: Transform) -> Collider { + Collider(sim.write::().insert( trans.position.xy(), PhysicsObject { dir: trans.dir.xy(), @@ -104,60 +104,60 @@ impl VehicleKind { } } -pub fn unpark(goria: &mut Egregoria, vehicle: VehicleID) { - let v = unwrap_ret!(goria.world.vehicles.get_mut(vehicle)); +pub fn unpark(sim: &mut Simulation, vehicle: VehicleID) { + let v = unwrap_ret!(sim.world.vehicles.get_mut(vehicle)); let w = v.vehicle.kind.width(); let trans = v.trans; if let VehicleState::Parked(spot) = std::mem::replace(&mut v.vehicle.state, VehicleState::Driving) { - goria.write::().free(spot); + sim.write::().free(spot); } else { log::warn!("Trying to unpark {:?} that wasn't parked", vehicle); } - let coll = put_vehicle_in_coworld(goria, w, trans); + let coll = put_vehicle_in_coworld(sim, w, trans); - let v = unwrap_ret!(goria.world.vehicles.get_mut(vehicle)); + let v = unwrap_ret!(sim.world.vehicles.get_mut(vehicle)); v.collider = Some(coll); } pub fn spawn_parked_vehicle( - goria: &mut Egregoria, + sim: &mut Simulation, kind: VehicleKind, near: Vec3, ) -> Option { - let map = goria.map(); - let mut pm = goria.write::(); + let map = sim.map(); + let mut pm = sim.write::(); let spot_id = pm.reserve_near(near, &map).ok()?; drop((map, pm)); - spawn_parked_vehicle_with_spot(goria, kind, spot_id) + spawn_parked_vehicle_with_spot(sim, kind, spot_id) } pub fn spawn_parked_vehicle_with_spot( - goria: &mut Egregoria, + sim: &mut Simulation, kind: VehicleKind, spot_id: SpotReservation, ) -> Option { - let map = goria.map(); + let map = sim.map(); let it = Itinerary::NONE; let pos = spot_id.get(&map.parking).unwrap().trans; // Unwrap ok: Gotten using reserve_near drop(map); let tint = match kind { - VehicleKind::Car => get_random_car_color(&mut goria.write::()), + VehicleKind::Car => get_random_car_color(&mut sim.write::()), _ => Color::WHITE, }; - let vehicle = Vehicle::new(kind, spot_id, tint, &mut goria.write::()); + let vehicle = Vehicle::new(kind, spot_id, tint, &mut sim.write::()); - Some(make_vehicle_entity(goria, pos, vehicle, it, false)) + Some(make_vehicle_entity(sim, pos, vehicle, it, false)) } pub fn make_vehicle_entity( - goria: &mut Egregoria, + sim: &mut Simulation, trans: Transform, vehicle: Vehicle, it: Itinerary, @@ -167,9 +167,9 @@ pub fn make_vehicle_entity( let mut collider = None; if mk_collider { - collider = Some(put_vehicle_in_coworld(goria, w, trans)); + collider = Some(put_vehicle_in_coworld(sim, w, trans)); } - goria.world.insert(VehicleEnt { + sim.world.insert(VehicleEnt { trans, speed: Default::default(), vehicle, diff --git a/egregoria/src/utils/config.rs b/simulation/src/utils/config.rs similarity index 100% rename from egregoria/src/utils/config.rs rename to simulation/src/utils/config.rs diff --git a/egregoria/src/utils/mod.rs b/simulation/src/utils/mod.rs similarity index 100% rename from egregoria/src/utils/mod.rs rename to simulation/src/utils/mod.rs diff --git a/egregoria/src/utils/par_command_buffer.rs b/simulation/src/utils/par_command_buffer.rs similarity index 67% rename from egregoria/src/utils/par_command_buffer.rs rename to simulation/src/utils/par_command_buffer.rs index 595948a5..2da42ca0 100644 --- a/egregoria/src/utils/par_command_buffer.rs +++ b/simulation/src/utils/par_command_buffer.rs @@ -1,20 +1,20 @@ use crate::utils::resources::Resources; use crate::world::Entity; -use crate::Egregoria; +use crate::Simulation; use std::sync::Mutex; -pub trait GoriaDrop: Entity { - fn goria_drop(self, id: Self::ID, res: &mut Resources); +pub trait SimDrop: Entity { + fn sim_drop(self, id: Self::ID, res: &mut Resources); } -type ExecType = Box FnOnce(&'a mut Egregoria) + Send>; +type ExecType = Box FnOnce(&'a mut Simulation) + Send>; -pub struct ParCommandBuffer { +pub struct ParCommandBuffer { to_kill: Mutex>, exec_ent: Mutex>, } -impl Default for ParCommandBuffer { +impl Default for ParCommandBuffer { fn default() -> Self { Self { to_kill: Default::default(), @@ -24,7 +24,7 @@ impl Default for ParCommandBuffer { } #[allow(clippy::unwrap_used)] -impl ParCommandBuffer { +impl ParCommandBuffer { pub fn kill(&self, e: E::ID) { self.to_kill.lock().unwrap().push(e); } @@ -33,7 +33,7 @@ impl ParCommandBuffer { self.to_kill.lock().unwrap().extend_from_slice(e); } - pub fn exec_ent(&self, e: E::ID, f: impl for<'a> FnOnce(&'a mut Egregoria) + 'static + Send) { + pub fn exec_ent(&self, e: E::ID, f: impl for<'a> FnOnce(&'a mut Simulation) + 'static + Send) { self.exec_ent.lock().unwrap().push((e, Box::new(f))); } @@ -42,15 +42,15 @@ impl ParCommandBuffer { e: E::ID, f: impl for<'a> FnOnce(&'a mut T) + 'static + Send, ) { - self.exec_ent(e, move |goria| { - f(&mut *goria.write::()); + self.exec_ent(e, move |sim| { + f(&mut *sim.write::()); }) } - pub fn apply(goria: &mut Egregoria) { + pub fn apply(sim: &mut Simulation) { profiling::scope!("par_command_buffer::apply"); let mut deleted: Vec = std::mem::take( - &mut *goria + &mut *sim .write::>() .to_kill .get_mut() @@ -60,13 +60,13 @@ impl ParCommandBuffer { deleted.sort_unstable(); for entity in deleted { - let Some(v) = E::storage_mut(&mut goria.world).remove(entity) else { continue }; + let Some(v) = E::storage_mut(&mut sim.world).remove(entity) else { continue }; - E::goria_drop(v, entity, &mut goria.resources); + E::sim_drop(v, entity, &mut sim.resources); } let mut exec_ent = std::mem::take( - &mut *goria + &mut *sim .write::>() .exec_ent .get_mut() @@ -76,7 +76,7 @@ impl ParCommandBuffer { exec_ent.sort_unstable_by_key(|(id, _)| *id); for (_, exec) in exec_ent { - exec(goria); + exec(sim); } } } diff --git a/egregoria/src/utils/rand_provider.rs b/simulation/src/utils/rand_provider.rs similarity index 100% rename from egregoria/src/utils/rand_provider.rs rename to simulation/src/utils/rand_provider.rs diff --git a/egregoria/src/utils/replay.rs b/simulation/src/utils/replay.rs similarity index 84% rename from egregoria/src/utils/replay.rs rename to simulation/src/utils/replay.rs index cf135ab4..f1768085 100644 --- a/egregoria/src/utils/replay.rs +++ b/simulation/src/utils/replay.rs @@ -1,7 +1,7 @@ use crate::engine_interaction::WorldCommand; use crate::utils::scheduler::SeqSchedule; use crate::utils::time::Tick; -use crate::Egregoria; +use crate::Simulation; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Default, Serialize, Deserialize)] @@ -10,7 +10,7 @@ pub struct Replay { pub commands: Vec<(Tick, WorldCommand)>, } -pub struct EgregoriaReplayLoader { +pub struct SimulationReplayLoader { pub replay: Replay, pub pastt: Tick, pub idx: usize, @@ -18,9 +18,9 @@ pub struct EgregoriaReplayLoader { pub advance_n_ticks: usize, } -impl EgregoriaReplayLoader { +impl SimulationReplayLoader { /// Returns true if the replay is finished - pub fn advance_tick(&mut self, goria: &mut Egregoria, schedule: &mut SeqSchedule) -> bool { + pub fn advance_tick(&mut self, sim: &mut Simulation, schedule: &mut SeqSchedule) -> bool { // iterate through tick grouped commands let mut ticks_left = if self.speed == 0 { let v = self.advance_n_ticks; @@ -32,7 +32,7 @@ impl EgregoriaReplayLoader { while self.idx < self.replay.commands.len() && ticks_left > 0 { let curt = self.replay.commands[self.idx].0; while self.pastt < curt { - goria.tick(schedule, &[]); + sim.tick(schedule, &[]); self.pastt.0 += 1; ticks_left -= 1; if ticks_left == 0 { @@ -52,7 +52,7 @@ impl EgregoriaReplayLoader { self.pastt, command_slice.len() ); - goria.tick(schedule, command_slice.iter().map(|(_, c)| c)); + sim.tick(schedule, command_slice.iter().map(|(_, c)| c)); self.pastt.0 += 1; ticks_left -= 1; } diff --git a/egregoria/src/utils/resources.rs b/simulation/src/utils/resources.rs similarity index 100% rename from egregoria/src/utils/resources.rs rename to simulation/src/utils/resources.rs diff --git a/egregoria/src/utils/scheduler.rs b/simulation/src/utils/scheduler.rs similarity index 62% rename from egregoria/src/utils/scheduler.rs rename to simulation/src/utils/scheduler.rs index b08381c1..0ad59907 100644 --- a/egregoria/src/utils/scheduler.rs +++ b/simulation/src/utils/scheduler.rs @@ -1,22 +1,22 @@ use crate::world::{CompanyEnt, HumanEnt, TrainEnt, VehicleEnt, WagonEnt}; -use crate::{Egregoria, FreightStationEnt, ParCommandBuffer}; +use crate::{FreightStationEnt, ParCommandBuffer, Simulation}; use common::History; use ordered_float::OrderedFloat; use std::time::Instant; pub trait RunnableSystem { - fn run(&self, goria: &mut Egregoria); + fn run(&self, sim: &mut Simulation); fn name(&self) -> &'static str; } -pub struct RunnableFn { +pub struct RunnableFn { pub f: F, pub name: &'static str, } -impl RunnableSystem for RunnableFn { - fn run(&self, goria: &mut Egregoria) { - (self.f)(goria) +impl RunnableSystem for RunnableFn { + fn run(&self, sim: &mut Simulation) { + (self.f)(sim) } fn name(&self) -> &'static str { @@ -36,19 +36,19 @@ impl SeqSchedule { } #[inline(never)] - pub fn execute(&mut self, goria: &mut Egregoria) { + pub fn execute(&mut self, sim: &mut Simulation) { profiling::scope!("scheduler::execute"); for (sys, h) in &mut self.systems { let start = Instant::now(); - sys.run(goria); + sys.run(sim); - ParCommandBuffer::::apply(goria); - ParCommandBuffer::::apply(goria); - ParCommandBuffer::::apply(goria); - ParCommandBuffer::::apply(goria); - ParCommandBuffer::::apply(goria); - ParCommandBuffer::::apply(goria); + ParCommandBuffer::::apply(sim); + ParCommandBuffer::::apply(sim); + ParCommandBuffer::::apply(sim); + ParCommandBuffer::::apply(sim); + ParCommandBuffer::::apply(sim); + ParCommandBuffer::::apply(sim); let elapsed = start.elapsed(); diff --git a/egregoria/src/utils/time.rs b/simulation/src/utils/time.rs similarity index 100% rename from egregoria/src/utils/time.rs rename to simulation/src/utils/time.rs diff --git a/egregoria/src/world.rs b/simulation/src/world.rs similarity index 95% rename from egregoria/src/world.rs rename to simulation/src/world.rs index 57278935..d7661ecf 100644 --- a/egregoria/src/world.rs +++ b/simulation/src/world.rs @@ -10,7 +10,7 @@ use crate::souls::goods_company::GoodsCompany; use crate::souls::human::{HumanDecision, PersonalInfo}; use crate::transportation::train::{Locomotive, LocomotiveReservation, RailWagon}; use crate::transportation::{Location, Pedestrian, Vehicle, VehicleKind, VehicleState}; -use crate::utils::par_command_buffer::GoriaDrop; +use crate::utils::par_command_buffer::SimDrop; use crate::utils::resources::Resources; use crate::{impl_entity, impl_trans, SoulID}; use derive_more::{From, TryInto}; @@ -62,8 +62,8 @@ pub struct VehicleEnt { pub collider: Option, } -impl GoriaDrop for VehicleEnt { - fn goria_drop(mut self, id: VehicleID, res: &mut Resources) { +impl SimDrop for VehicleEnt { + fn sim_drop(mut self, id: VehicleID, res: &mut Resources) { if let Some(collider) = self.collider { res.write::().remove_maintain(collider.0); } @@ -101,8 +101,8 @@ pub struct HumanEnt { pub personal_info: Box, } -impl GoriaDrop for HumanEnt { - fn goria_drop(mut self, id: HumanID, res: &mut Resources) { +impl SimDrop for HumanEnt { + fn sim_drop(mut self, id: HumanID, res: &mut Resources) { if let Some(collider) = self.collider { res.write::().remove_maintain(collider.0); } @@ -125,8 +125,8 @@ pub struct TrainEnt { pub leader: ItineraryLeader, } -impl GoriaDrop for TrainEnt { - fn goria_drop(self, id: TrainID, res: &mut Resources) { +impl SimDrop for TrainEnt { + fn sim_drop(self, id: TrainID, res: &mut Resources) { res.write::() .unregister(DispatchID::FreightTrain(id)); } @@ -140,8 +140,8 @@ pub struct WagonEnt { pub itfollower: ItineraryFollower, } -impl GoriaDrop for WagonEnt { - fn goria_drop(self, _: WagonID, _: &mut Resources) {} +impl SimDrop for WagonEnt { + fn sim_drop(self, _: WagonID, _: &mut Resources) {} } #[derive(Inspect, Serialize, Deserialize)] @@ -150,8 +150,8 @@ pub struct FreightStationEnt { pub f: FreightStation, } -impl GoriaDrop for FreightStationEnt { - fn goria_drop(self, id: FreightStationID, res: &mut Resources) { +impl SimDrop for FreightStationEnt { + fn sim_drop(self, id: FreightStationID, res: &mut Resources) { res.write::().remove(SoulID::FreightStation(id)); let mut d = res.write::(); @@ -171,8 +171,8 @@ pub struct CompanyEnt { pub bought: Bought, } -impl GoriaDrop for CompanyEnt { - fn goria_drop(self, id: CompanyID, res: &mut Resources) { +impl SimDrop for CompanyEnt { + fn sim_drop(self, id: CompanyID, res: &mut Resources) { res.write::().remove(SoulID::GoodsCompany(id)); } }