From 4ebfbdde0f04ef623c3e630be0dcda69965643d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Mon, 8 Mar 2021 23:40:02 +0100 Subject: [PATCH] Move Specs code to own common_ecs create, put tracy and macros into common_base --- Cargo.lock | 33 ++++++- Cargo.toml | 2 + client/Cargo.toml | 1 + client/src/lib.rs | 2 +- common/Cargo.toml | 4 +- common/base/Cargo.toml | 16 ++++ common/base/src/lib.rs | 85 +++++++++++++++++++ common/{src/util => base/src}/userdata_dir.rs | 4 +- common/ecs/Cargo.toml | 19 +++++ common/ecs/src/lib.rs | 7 ++ common/{ => ecs}/src/metrics.rs | 0 common/{ => ecs}/src/system.rs | 4 +- common/src/clock.rs | 2 +- common/src/lib.rs | 5 +- common/src/path.rs | 2 +- common/src/ray.rs | 3 +- common/src/region.rs | 6 +- common/src/util/mod.rs | 75 ---------------- common/sys/Cargo.toml | 2 + common/sys/src/aura.rs | 2 +- common/sys/src/beam.rs | 2 +- common/sys/src/buff.rs | 2 +- common/sys/src/character_behavior.rs | 2 +- common/sys/src/controller.rs | 2 +- common/sys/src/lib.rs | 2 +- common/sys/src/melee.rs | 2 +- common/sys/src/mount.rs | 2 +- common/sys/src/phys.rs | 5 +- common/sys/src/projectile.rs | 2 +- common/sys/src/shockwave.rs | 2 +- common/sys/src/state.rs | 4 +- common/sys/src/stats.rs | 2 +- server-cli/Cargo.toml | 1 + server-cli/src/main.rs | 7 +- server-cli/src/settings.rs | 2 +- server/Cargo.toml | 3 + server/src/events/mod.rs | 6 +- server/src/events/player.rs | 2 +- server/src/lib.rs | 2 +- server/src/rtsim/load_chunks.rs | 6 +- server/src/rtsim/mod.rs | 2 +- server/src/rtsim/tick.rs | 2 +- server/src/rtsim/unload_chunks.rs | 2 +- server/src/sys/agent.rs | 2 +- server/src/sys/entity_sync.rs | 2 +- server/src/sys/invite_timeout.rs | 2 +- server/src/sys/metrics.rs | 32 ++++--- server/src/sys/mod.rs | 2 +- server/src/sys/msg/character_screen.rs | 2 +- server/src/sys/msg/general.rs | 2 +- server/src/sys/msg/in_game.rs | 2 +- server/src/sys/msg/ping.rs | 2 +- server/src/sys/object.rs | 2 +- server/src/sys/persistence.rs | 6 +- server/src/sys/sentinel.rs | 2 +- server/src/sys/subscription.rs | 2 +- server/src/sys/terrain.rs | 2 +- server/src/sys/terrain_sync.rs | 7 +- server/src/sys/waypoint.rs | 2 +- voxygen/Cargo.toml | 2 + voxygen/src/ecs/sys.rs | 2 +- voxygen/src/ecs/sys/floater.rs | 2 +- voxygen/src/ecs/sys/interpolation.rs | 2 +- voxygen/src/hud/mod.rs | 2 +- voxygen/src/lib.rs | 3 +- voxygen/src/menu/char_selection/mod.rs | 3 +- voxygen/src/menu/main/mod.rs | 3 +- voxygen/src/mesh/greedy.rs | 2 +- voxygen/src/mesh/terrain.rs | 2 +- voxygen/src/render/renderer.rs | 6 +- voxygen/src/run.rs | 2 +- voxygen/src/scene/camera.rs | 3 +- voxygen/src/scene/figure/mod.rs | 2 +- voxygen/src/scene/mod.rs | 2 +- voxygen/src/scene/particle.rs | 2 +- voxygen/src/scene/terrain.rs | 2 +- voxygen/src/scene/terrain/watcher.rs | 2 +- voxygen/src/session.rs | 2 +- voxygen/src/settings.rs | 2 +- voxygen/src/singleplayer.rs | 2 +- voxygen/src/ui/graphic/pixel_art.rs | 6 +- voxygen/src/ui/ice/mod.rs | 2 +- voxygen/src/ui/ice/renderer/mod.rs | 3 +- voxygen/src/ui/mod.rs | 3 +- voxygen/src/window.rs | 2 +- 85 files changed, 282 insertions(+), 193 deletions(-) create mode 100644 common/base/Cargo.toml create mode 100644 common/base/src/lib.rs rename common/{src/util => base/src}/userdata_dir.rs (96%) create mode 100644 common/ecs/Cargo.toml create mode 100644 common/ecs/src/lib.rs rename common/{ => ecs}/src/metrics.rs (100%) rename common/{ => ecs}/src/system.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 8133a96275..ab21be8a38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5588,6 +5588,7 @@ dependencies = [ "tracing-subscriber", "vek 0.14.1", "veloren-common", + "veloren-common-base", "veloren-common-net", "veloren-common-sys", "veloren-network", @@ -5604,10 +5605,8 @@ dependencies = [ "crossbeam-channel", "crossbeam-utils 0.8.1", "csv", - "directories-next", "dot_vox", "enum-iterator", - "float-cmp", "hashbrown 0.9.1", "image", "indexmap", @@ -5632,6 +5631,26 @@ dependencies = [ "tracy-client", "uuid", "vek 0.14.1", + "veloren-common-base", +] + +[[package]] +name = "veloren-common-base" +version = "0.8.0" +dependencies = [ + "directories-next", + "tracing", + "tracy-client", +] + +[[package]] +name = "veloren-common-ecs" +version = "0.8.0" +dependencies = [ + "float-cmp", + "specs", + "tracing", + "veloren-common-base", ] [[package]] @@ -5668,6 +5687,8 @@ dependencies = [ "tracy-client", "vek 0.14.1", "veloren-common", + "veloren-common-base", + "veloren-common-ecs", "veloren-common-net", "veloren-plugin-api", "wasmer", @@ -5759,6 +5780,7 @@ dependencies = [ "itertools 0.9.0", "lazy_static", "libsqlite3-sys", + "num_cpus", "portpicker", "prometheus", "prometheus-hyper", @@ -5775,6 +5797,8 @@ dependencies = [ "tracing", "vek 0.14.1", "veloren-common", + "veloren-common-base", + "veloren-common-ecs", "veloren-common-net", "veloren-common-sys", "veloren-network", @@ -5800,6 +5824,7 @@ dependencies = [ "tracing-tracy", "tui", "veloren-common", + "veloren-common-base", "veloren-common-net", "veloren-server", ] @@ -5862,6 +5887,8 @@ dependencies = [ "vek 0.14.1", "veloren-client", "veloren-common", + "veloren-common-base", + "veloren-common-ecs", "veloren-common-net", "veloren-common-sys", "veloren-server", @@ -6691,4 +6718,4 @@ dependencies = [ name = "xml-rs" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a" \ No newline at end of file +checksum = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a" diff --git a/Cargo.toml b/Cargo.toml index ed1f6b9a39..793897b575 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,8 @@ cargo-features = ["named-profiles","profile-overrides"] [workspace] members = [ "common", + "common/base", + "common/ecs", "common/net", "common/sys", "client", diff --git a/client/Cargo.toml b/client/Cargo.toml index 15bc63c5eb..950f3c4b53 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -12,6 +12,7 @@ default = ["simd"] [dependencies] common = { package = "veloren-common", path = "../common", features = ["no-assets"] } +common-base = { package = "veloren-common-base", path = "../common/base" } common-sys = { package = "veloren-common-sys", path = "../common/sys", default-features = false } common-net = { package = "veloren-common-net", path = "../common/net" } network = { package = "veloren-network", path = "../network", features = ["compression"], default-features = false } diff --git a/client/src/lib.rs b/client/src/lib.rs index b9b1de4210..7b7232a5d1 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -33,12 +33,12 @@ use common::{ grid::Grid, outcome::Outcome, recipe::RecipeBook, - span, terrain::{block::Block, neighbors, BiomeKind, SitesKind, TerrainChunk, TerrainChunkSize}, trade::{PendingTrade, TradeAction, TradeId, TradeResult}, uid::{Uid, UidAllocator}, vol::RectVolSize, }; +use common_base::span; use common_net::{ msg::{ self, validate_chat_msg, world_msg::SiteInfo, ChatMsgValidationError, ClientGeneral, diff --git a/common/Cargo.toml b/common/Cargo.toml index 2d614c40a3..fa7e19bcb6 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -14,6 +14,8 @@ default = ["simd"] [dependencies] +common-base = { package = "veloren-common-base", path = "base" } + # Serde serde = { version = "1.0.110", features = ["derive", "rc"] } @@ -36,7 +38,6 @@ uuid = { version = "0.8.1", default-features = false, features = ["serde", "v4"] rand = "0.8" # Assets -directories-next = "2.0" dot_vox = "4.0" image = { version = "0.23.12", default-features = false, features = ["png"] } @@ -68,7 +69,6 @@ specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "9fab7b3 [dev-dependencies] #bench criterion = "0.3" -float-cmp = "0.8.0" [[bench]] name = "chonk_benchmark" diff --git a/common/base/Cargo.toml b/common/base/Cargo.toml new file mode 100644 index 0000000000..5b9877b67d --- /dev/null +++ b/common/base/Cargo.toml @@ -0,0 +1,16 @@ +[package] +authors = ["Marcel Märtens "] +edition = "2018" +name = "veloren-common-base" +description = "minimal dependency for crates to now depend on whole common" +version = "0.8.0" + +[features] +tracy = ["tracy-client"] + +[dependencies] +tracing = { version = "0.1", default-features = false } +directories-next = "2.0" + +# Tracy +tracy-client = { version = "0.10.0", optional = true } \ No newline at end of file diff --git a/common/base/src/lib.rs b/common/base/src/lib.rs new file mode 100644 index 0000000000..e08ac271ec --- /dev/null +++ b/common/base/src/lib.rs @@ -0,0 +1,85 @@ +#![feature(fundamental)] + +pub mod userdata_dir; + +pub use userdata_dir::userdata_dir; + +#[cfg(feature = "tracy")] pub use tracy_client; + +// https://discordapp.com/channels/676678179678715904/676685797524766720/723358438943621151 +#[macro_export] +macro_rules! span { + ($guard_name:tt, $level:ident, $name:expr, $($fields:tt)*) => { + let span = tracing::span!(tracing::Level::$level, $name, $($fields)*); + let $guard_name = span.enter(); + }; + ($guard_name:tt, $level:ident, $name:expr) => { + let span = tracing::span!(tracing::Level::$level, $name); + let $guard_name = span.enter(); + }; + ($guard_name:tt, $name:expr) => { + #[cfg(not(feature = "tracy"))] + let span = tracing::span!(tracing::Level::TRACE, $name); + #[cfg(not(feature = "tracy"))] + let $guard_name = span.enter(); + // Directly use `tracy_client` to decrease overhead for better timing + #[cfg(feature = "tracy")] + let $guard_name = $crate::tracy_client::Span::new( + $name, + "", + module_path!(), + line!(), + // No callstack since this has significant overhead + 0, + ); + }; + ($guard_name:tt, $no_tracy_name:expr, $tracy_name:expr) => { + #[cfg(not(feature = "tracy"))] + $crate::span!($guard_name, $no_tracy_name); + #[cfg(feature = "tracy")] + $crate::span!($guard_name, $tracy_name); + }; +} + +/// There's no guard, but really this is actually the guard +pub struct GuardlessSpan { + span: tracing::Span, + subscriber: tracing::Dispatch, +} + +impl GuardlessSpan { + pub fn new(span: tracing::Span) -> Self { + let subscriber = tracing::dispatcher::get_default(|d| d.clone()); + if let Some(id) = span.id() { + subscriber.enter(&id) + } + Self { span, subscriber } + } +} + +impl Drop for GuardlessSpan { + fn drop(&mut self) { + if let Some(id) = self.span.id() { + self.subscriber.exit(&id) + } + } +} + +#[macro_export] +macro_rules! no_guard_span { + ($level:ident, $name:expr, $($fields:tt)*) => { + GuardlessSpan::new( + tracing::span!(tracing::Level::$level, $name, $($fields)*) + ) + }; + ($level:ident, $name:expr) => { + GuardlessSpan::new( + tracing::span!(tracing::Level::$level, $name) + ) + }; + ($name:expr) => { + GuardlessSpan::new( + tracing::span!(tracing::Level::TRACE, $name) + ) + }; +} diff --git a/common/src/util/userdata_dir.rs b/common/base/src/userdata_dir.rs similarity index 96% rename from common/src/util/userdata_dir.rs rename to common/base/src/userdata_dir.rs index 51f08520b9..a114589558 100644 --- a/common/src/util/userdata_dir.rs +++ b/common/base/src/userdata_dir.rs @@ -63,7 +63,7 @@ pub fn userdata_dir(workspace: bool, strategy: Option<&str>, manifest_dir: &str) #[macro_export] macro_rules! userdata_dir_workspace { () => { - $crate::util::userdata_dir::userdata_dir( + $crate::userdata_dir::userdata_dir( true, option_env!("VELOREN_USERDATA_STRATEGY"), env!("CARGO_MANIFEST_DIR"), @@ -74,7 +74,7 @@ macro_rules! userdata_dir_workspace { #[macro_export] macro_rules! userdata_dir_no_workspace { () => { - $crate::util::userdata_dir::userdata_dir( + $crate::userdata_dir::userdata_dir( false, option_env!("VELOREN_USERDATA_STRATEGY"), env!("CARGO_MANIFEST_DIR"), diff --git a/common/ecs/Cargo.toml b/common/ecs/Cargo.toml new file mode 100644 index 0000000000..8fb6a99719 --- /dev/null +++ b/common/ecs/Cargo.toml @@ -0,0 +1,19 @@ +[package] +authors = ["Marcel Märtens "] +edition = "2018" +name = "veloren-common-ecs" +version = "0.8.0" + +[features] + +[dependencies] + +tracing = { version = "0.1", default-features = false } +common-base = { package = "veloren-common-base", path = "../base" } + +# ECS +specs = { git = "https://github.com/amethyst/specs.git", features = ["serde", "storage-event-control"], rev = "d4435bdf496cf322c74886ca09dd8795984919b4" } + +[dev-dependencies] +#bench +float-cmp = "0.8.0" \ No newline at end of file diff --git a/common/ecs/src/lib.rs b/common/ecs/src/lib.rs new file mode 100644 index 0000000000..2c96a68c35 --- /dev/null +++ b/common/ecs/src/lib.rs @@ -0,0 +1,7 @@ +mod metrics; +mod system; + +pub use metrics::{PhysicsMetrics, SysMetrics}; +pub use system::{ + dispatch, gen_stats, run_now, CpuTimeStats, CpuTimeline, Job, Origin, ParMode, Phase, System, +}; diff --git a/common/src/metrics.rs b/common/ecs/src/metrics.rs similarity index 100% rename from common/src/metrics.rs rename to common/ecs/src/metrics.rs diff --git a/common/src/system.rs b/common/ecs/src/system.rs similarity index 99% rename from common/src/system.rs rename to common/ecs/src/system.rs index 36eb5697da..349f16d30f 100644 --- a/common/src/system.rs +++ b/common/ecs/src/system.rs @@ -191,7 +191,7 @@ pub fn gen_stats( /// /// ``` /// use specs::Read; -/// pub use veloren_common::system::{Job, Origin, ParMode, Phase, System}; +/// pub use veloren_common_ecs::{Job, Origin, ParMode, Phase, System}; /// # use std::time::Duration; /// pub struct Sys; /// impl<'a> System<'a> for Sys { @@ -251,7 +251,7 @@ where type SystemData = (T::SystemData, ReadExpect<'a, SysMetrics>); fn run(&mut self, data: Self::SystemData) { - crate::span!(_guard, "run", &format!("{}::Sys::run", T::NAME)); + common_base::span!(_guard, "run", &format!("{}::Sys::run", T::NAME)); self.cpu_stats.reset(); T::run(self, data.0); self.cpu_stats.end(); diff --git a/common/src/clock.rs b/common/src/clock.rs index 26446b51f8..0eed375d95 100644 --- a/common/src/clock.rs +++ b/common/src/clock.rs @@ -1,4 +1,4 @@ -use crate::span; +use common_base::span; use ordered_float::NotNan; use std::{ collections::VecDeque, diff --git a/common/src/lib.rs b/common/src/lib.rs index 7bbad0249a..cd1c62c9bd 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -42,8 +42,8 @@ pub mod generation; #[cfg(not(target_arch = "wasm32"))] pub mod lottery; #[cfg(not(target_arch = "wasm32"))] -pub mod metrics; -#[cfg(not(target_arch = "wasm32"))] pub mod npc; +#[cfg(not(target_arch = "wasm32"))] +pub mod npc; #[cfg(not(target_arch = "wasm32"))] pub mod outcome; #[cfg(not(target_arch = "wasm32"))] pub mod path; @@ -61,7 +61,6 @@ pub mod spiral; #[cfg(not(target_arch = "wasm32"))] pub mod states; #[cfg(not(target_arch = "wasm32"))] pub mod store; -pub mod system; #[cfg(not(target_arch = "wasm32"))] pub mod terrain; #[cfg(not(target_arch = "wasm32"))] pub mod time; diff --git a/common/src/path.rs b/common/src/path.rs index 0743191b0c..7de1e7a5fc 100644 --- a/common/src/path.rs +++ b/common/src/path.rs @@ -1,9 +1,9 @@ use crate::{ astar::{Astar, PathResult}, - span, terrain::Block, vol::{BaseVol, ReadVol}, }; +use common_base::span; use hashbrown::hash_map::DefaultHashBuilder; use rand::prelude::*; use std::iter::FromIterator; diff --git a/common/src/ray.rs b/common/src/ray.rs index 933251c2cd..60eef65a05 100644 --- a/common/src/ray.rs +++ b/common/src/ray.rs @@ -1,4 +1,5 @@ -use crate::{span, vol::ReadVol}; +use crate::vol::ReadVol; +use common_base::span; use vek::*; pub trait RayForEach = FnMut(&V, Vec3); diff --git a/common/src/region.rs b/common/src/region.rs index 23428ba63b..c2b5313491 100644 --- a/common/src/region.rs +++ b/common/src/region.rs @@ -1,7 +1,5 @@ -use crate::{ - comp::{Pos, Vel}, - span, -}; +use crate::comp::{Pos, Vel}; +use common_base::span; use hashbrown::{hash_map::DefaultHashBuilder, HashSet}; use indexmap::IndexMap; use specs::{hibitset::BitSetLike, BitSet, Entities, Join, ReadStorage}; diff --git a/common/src/util/mod.rs b/common/src/util/mod.rs index 8b0af5ac59..2dbbc44a4f 100644 --- a/common/src/util/mod.rs +++ b/common/src/util/mod.rs @@ -4,7 +4,6 @@ pub mod find_dist; mod option; pub mod plane; pub mod projection; -pub mod userdata_dir; pub const GIT_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/githash")); pub const GIT_TAG: &str = include_str!(concat!(env!("OUT_DIR"), "/gittag")); @@ -32,77 +31,3 @@ pub use dir::*; pub use option::*; pub use plane::*; pub use projection::*; - -#[cfg(feature = "tracy")] pub use tracy_client; - -// https://discordapp.com/channels/676678179678715904/676685797524766720/723358438943621151 -#[macro_export] -macro_rules! span { - ($guard_name:tt, $level:ident, $name:expr, $($fields:tt)*) => { - let span = tracing::span!(tracing::Level::$level, $name, $($fields)*); - let $guard_name = span.enter(); - }; - ($guard_name:tt, $level:ident, $name:expr) => { - let span = tracing::span!(tracing::Level::$level, $name); - let $guard_name = span.enter(); - }; - ($guard_name:tt, $name:expr) => { - #[cfg(not(feature = "tracy"))] - let span = tracing::span!(tracing::Level::TRACE, $name); - #[cfg(not(feature = "tracy"))] - let $guard_name = span.enter(); - // Directly use `tracy_client` to decrease overhead for better timing - #[cfg(feature = "tracy")] - let $guard_name = $crate::util::tracy_client::Span::new( - $name, - "", - module_path!(), - line!(), - // No callstack since this has significant overhead - 0, - ); - }; - ($guard_name:tt, $no_tracy_name:expr, $tracy_name:expr) => { - #[cfg(not(feature = "tracy"))] - $crate::span!($guard_name, $no_tracy_name); - #[cfg(feature = "tracy")] - $crate::span!($guard_name, $tracy_name); - }; -} - -/// There's no guard, but really this is actually the guard -pub struct GuardlessSpan { - span: tracing::Span, - subscriber: tracing::Dispatch, -} - -impl GuardlessSpan { - pub fn new(span: tracing::Span) -> Self { - let subscriber = tracing::dispatcher::get_default(|d| d.clone()); - span.id().map(|id| subscriber.enter(&id)); - Self { span, subscriber } - } -} - -impl Drop for GuardlessSpan { - fn drop(&mut self) { self.span.id().map(|id| self.subscriber.exit(&id)); } -} - -#[macro_export] -macro_rules! no_guard_span { - ($level:ident, $name:expr, $($fields:tt)*) => { - GuardlessSpan::new( - tracing::span!(tracing::Level::$level, $name, $($fields)*) - ) - }; - ($level:ident, $name:expr) => { - GuardlessSpan::new( - tracing::span!(tracing::Level::$level, $name) - ) - }; - ($name:expr) => { - GuardlessSpan::new( - tracing::span!(tracing::Level::TRACE, $name) - ) - }; -} diff --git a/common/sys/Cargo.toml b/common/sys/Cargo.toml index 62a3b693b1..1f8339de6e 100644 --- a/common/sys/Cargo.toml +++ b/common/sys/Cargo.toml @@ -14,6 +14,8 @@ default = ["simd"] [dependencies] common = { package = "veloren-common", path = ".." } common-net = { package = "veloren-common-net", path = "../net" } +common-ecs = { package = "veloren-common-ecs", path = "../ecs" } +common-base = { package = "veloren-common-base", path = "../base" } rand = "0.8" rayon = "1.5" diff --git a/common/sys/src/aura.rs b/common/sys/src/aura.rs index 90829a39e0..bf6c23875d 100644 --- a/common/sys/src/aura.rs +++ b/common/sys/src/aura.rs @@ -7,9 +7,9 @@ use common::{ }, event::{EventBus, ServerEvent}, resources::DeltaTime, - system::{Job, Origin, Phase, System}, uid::UidAllocator, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{ saveload::MarkerAllocator, shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage, diff --git a/common/sys/src/beam.rs b/common/sys/src/beam.rs index 60ebd77d07..ff008a05cd 100644 --- a/common/sys/src/beam.rs +++ b/common/sys/src/beam.rs @@ -6,10 +6,10 @@ use common::{ }, event::{EventBus, ServerEvent}, resources::{DeltaTime, Time}, - system::{Job, Origin, Phase, System}, uid::{Uid, UidAllocator}, GroupTarget, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{ saveload::MarkerAllocator, shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage, diff --git a/common/sys/src/buff.rs b/common/sys/src/buff.rs index 9453e64b4b..0e71d50533 100644 --- a/common/sys/src/buff.rs +++ b/common/sys/src/buff.rs @@ -5,9 +5,9 @@ use common::{ }, event::{EventBus, ServerEvent}, resources::DeltaTime, - system::{Job, Origin, Phase, System}, Damage, DamageSource, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{ shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage, }; diff --git a/common/sys/src/character_behavior.rs b/common/sys/src/character_behavior.rs index 8783f29955..1dcc7f6b9a 100644 --- a/common/sys/src/character_behavior.rs +++ b/common/sys/src/character_behavior.rs @@ -18,9 +18,9 @@ use common::{ self, behavior::{CharacterBehavior, JoinData, JoinStruct}, }, - system::{Job, Origin, Phase, System}, uid::Uid, }; +use common_ecs::{Job, Origin, Phase, System}; use std::time::Duration; fn incorporate_update(join: &mut JoinStruct, state_update: StateUpdate) { diff --git a/common/sys/src/controller.rs b/common/sys/src/controller.rs index 40c0a07ce9..e920445c37 100644 --- a/common/sys/src/controller.rs +++ b/common/sys/src/controller.rs @@ -1,9 +1,9 @@ use common::{ comp::{BuffChange, ControlEvent, Controller}, event::{EventBus, ServerEvent}, - system::{Job, Origin, Phase, System}, uid::UidAllocator, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{ saveload::{Marker, MarkerAllocator}, shred::ResourceId, diff --git a/common/sys/src/lib.rs b/common/sys/src/lib.rs index c0dc0e99bf..4077fd861b 100644 --- a/common/sys/src/lib.rs +++ b/common/sys/src/lib.rs @@ -15,7 +15,7 @@ pub mod state; mod stats; // External -use common::system::{dispatch, System}; +use common_ecs::{dispatch, System}; use specs::DispatcherBuilder; pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { diff --git a/common/sys/src/melee.rs b/common/sys/src/melee.rs index 7bf88d813a..5890bf5b68 100644 --- a/common/sys/src/melee.rs +++ b/common/sys/src/melee.rs @@ -2,11 +2,11 @@ use common::{ combat::{AttackerInfo, TargetInfo}, comp::{Body, CharacterState, Energy, Group, Health, Inventory, Melee, Ori, Pos, Scale, Stats}, event::{EventBus, ServerEvent}, - system::{Job, Origin, Phase, System}, uid::Uid, util::Dir, GroupTarget, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{ shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage, }; diff --git a/common/sys/src/mount.rs b/common/sys/src/mount.rs index 68f1bedb9c..db36b178e8 100644 --- a/common/sys/src/mount.rs +++ b/common/sys/src/mount.rs @@ -1,8 +1,8 @@ use common::{ comp::{Controller, MountState, Mounting, Ori, Pos, Vel}, - system::{Job, Origin, Phase, System}, uid::UidAllocator, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{ saveload::{Marker, MarkerAllocator}, Entities, Join, Read, WriteStorage, diff --git a/common/sys/src/phys.rs b/common/sys/src/phys.rs index c8277ec0db..e58197ed09 100644 --- a/common/sys/src/phys.rs +++ b/common/sys/src/phys.rs @@ -5,14 +5,13 @@ use common::{ }, consts::{FRIC_GROUND, GRAVITY}, event::{EventBus, ServerEvent}, - metrics::PhysicsMetrics, resources::DeltaTime, - span, - system::{Job, Origin, ParMode, Phase, System}, terrain::{Block, TerrainGrid}, uid::Uid, vol::ReadVol, }; +use common_base::span; +use common_ecs::{Job, Origin, ParMode, Phase, PhysicsMetrics, System}; use rayon::iter::ParallelIterator; use specs::{Entities, Join, ParJoin, Read, ReadExpect, ReadStorage, WriteExpect, WriteStorage}; use std::ops::Range; diff --git a/common/sys/src/projectile.rs b/common/sys/src/projectile.rs index b09c28d10d..0255a884ea 100644 --- a/common/sys/src/projectile.rs +++ b/common/sys/src/projectile.rs @@ -6,11 +6,11 @@ use common::{ }, event::{EventBus, ServerEvent}, resources::DeltaTime, - system::{Job, Origin, Phase, System}, uid::UidAllocator, util::Dir, GroupTarget, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{ saveload::MarkerAllocator, shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage, diff --git a/common/sys/src/shockwave.rs b/common/sys/src/shockwave.rs index 20b084e3df..d5b1c9846c 100644 --- a/common/sys/src/shockwave.rs +++ b/common/sys/src/shockwave.rs @@ -6,11 +6,11 @@ use common::{ }, event::{EventBus, ServerEvent}, resources::{DeltaTime, Time}, - system::{Job, Origin, Phase, System}, uid::{Uid, UidAllocator}, util::Dir, GroupTarget, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{ saveload::MarkerAllocator, shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage, diff --git a/common/sys/src/state.rs b/common/sys/src/state.rs index f62434eddf..99da5167e5 100644 --- a/common/sys/src/state.rs +++ b/common/sys/src/state.rs @@ -5,15 +5,15 @@ use crate::plugin::PluginMgr; use common::{ comp, event::{EventBus, LocalEvent, ServerEvent}, - metrics::{PhysicsMetrics, SysMetrics}, region::RegionMap, resources::{DeltaTime, GameMode, Time, TimeOfDay}, - span, terrain::{Block, TerrainChunk, TerrainGrid}, time::DayPeriod, trade::Trades, vol::{ReadVol, WriteVol}, }; +use common_base::span; +use common_ecs::{PhysicsMetrics, SysMetrics}; use common_net::sync::WorldSyncExt; use hashbrown::{HashMap, HashSet}; use rayon::{ThreadPool, ThreadPoolBuilder}; diff --git a/common/sys/src/stats.rs b/common/sys/src/stats.rs index caa403d9a9..bc7fbe02a8 100644 --- a/common/sys/src/stats.rs +++ b/common/sys/src/stats.rs @@ -7,9 +7,9 @@ use common::{ event::{EventBus, ServerEvent}, outcome::Outcome, resources::{DeltaTime, Time}, - system::{Job, Origin, Phase, System}, uid::Uid, }; +use common_ecs::{Job, Origin, Phase, System}; use hashbrown::HashSet; use specs::{ shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, Write, WriteStorage, diff --git a/server-cli/Cargo.toml b/server-cli/Cargo.toml index d75e1987ec..53e3340d86 100644 --- a/server-cli/Cargo.toml +++ b/server-cli/Cargo.toml @@ -13,6 +13,7 @@ plugins = ["server/plugins"] [dependencies] server = { package = "veloren-server", path = "../server", default-features = false } common = { package = "veloren-common", path = "../common" } +common-base = { package = "veloren-common-base", path = "../common/base" } common-net = { package = "veloren-common-net", path = "../common/net" } tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] } diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs index b930bd9de9..213dedc2f8 100644 --- a/server-cli/src/main.rs +++ b/server-cli/src/main.rs @@ -14,7 +14,8 @@ use crate::{ tui_runner::{Message, Tui}, }; use clap::{App, Arg, SubCommand}; -use common::{clock::Clock, span}; +use common::clock::Clock; +use common_base::span; use server::{Event, Input, Server}; use std::{ io, @@ -85,7 +86,7 @@ fn main() -> io::Result<()> { // Determine folder to save server data in let server_data_dir = { - let mut path = common::userdata_dir_workspace!(); + let mut path = common_base::userdata_dir_workspace!(); info!("Using userdata folder at {}", path.display()); path.push(server::DEFAULT_DATA_DIR_NAME); path @@ -207,7 +208,7 @@ fn main() -> io::Result<()> { // Wait for the next tick. clock.tick(); #[cfg(feature = "tracy")] - common::util::tracy_client::finish_continuous_frame!(); + common_base::finish_continuous_frame!(); } Ok(()) diff --git a/server-cli/src/settings.rs b/server-cli/src/settings.rs index 3cca9ec466..aa1ab10741 100644 --- a/server-cli/src/settings.rs +++ b/server-cli/src/settings.rs @@ -69,7 +69,7 @@ impl Settings { } pub fn data_dir() -> PathBuf { - let mut path = common::userdata_dir_workspace!(); + let mut path = common_base::userdata_dir_workspace!(); path.push("server-cli"); path } diff --git a/server/Cargo.toml b/server/Cargo.toml index 083596abdf..4797c48eb3 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -13,6 +13,8 @@ default = ["worldgen", "plugins", "simd"] [dependencies] common = { package = "veloren-common", path = "../common" } +common-base = { package = "veloren-common-base", path = "../common/base" } +common-ecs = { package = "veloren-common-ecs", path = "../common/ecs" } common-sys = { package = "veloren-common-sys", path = "../common/sys" } common-net = { package = "veloren-common-net", path = "../common/net" } world = { package = "veloren-world", path = "../world" } @@ -21,6 +23,7 @@ network = { package = "veloren-network", path = "../network", features = ["metri specs = { git = "https://github.com/amethyst/specs.git", features = ["shred-derive"], rev = "d4435bdf496cf322c74886ca09dd8795984919b4" } specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "9fab7b396acd6454585486e50ae4bfe2069858a9" } +num_cpus = "1.0" tracing = "0.1" vek = { version = "0.14.1", features = ["serde"] } futures-util = "0.3.7" diff --git a/server/src/events/mod.rs b/server/src/events/mod.rs index afedfbb3a5..ead348a5d4 100644 --- a/server/src/events/mod.rs +++ b/server/src/events/mod.rs @@ -1,8 +1,6 @@ use crate::{state_ext::StateExt, Server}; -use common::{ - event::{EventBus, ServerEvent}, - span, -}; +use common::event::{EventBus, ServerEvent}; +use common_base::span; use entity_creation::{ handle_beam, handle_create_npc, handle_create_waypoint, handle_initialize_character, handle_loaded_character_data, handle_shockwave, handle_shoot, diff --git a/server/src/events/player.rs b/server/src/events/player.rs index 978309d4ff..f167fdb547 100644 --- a/server/src/events/player.rs +++ b/server/src/events/player.rs @@ -6,9 +6,9 @@ use crate::{ use common::{ comp, comp::{group, Player}, - span, uid::{Uid, UidAllocator}, }; +use common_base::span; use common_net::msg::{PlayerListUpdate, PresenceKind, ServerGeneral}; use common_sys::state::State; use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, WorldExt}; diff --git a/server/src/lib.rs b/server/src/lib.rs index 4729a738ba..119d1d216a 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -64,10 +64,10 @@ use common::{ recipe::default_recipe_book, resources::TimeOfDay, rtsim::RtSimEntity, - system::run_now, terrain::TerrainChunkSize, vol::{ReadVol, RectVolSize}, }; +use common_ecs::run_now; use common_net::{ msg::{ CharacterInfo, ClientType, DisconnectReason, PlayerInfo, PlayerListUpdate, ServerGeneral, diff --git a/server/src/rtsim/load_chunks.rs b/server/src/rtsim/load_chunks.rs index 37ecb29dae..e370577676 100644 --- a/server/src/rtsim/load_chunks.rs +++ b/server/src/rtsim/load_chunks.rs @@ -1,8 +1,6 @@ use super::*; -use common::{ - event::{EventBus, ServerEvent}, - system::{Job, Origin, Phase, System}, -}; +use common::event::{EventBus, ServerEvent}; +use common_ecs::{Job, Origin, Phase, System}; use specs::{Read, WriteExpect}; #[derive(Default)] diff --git a/server/src/rtsim/mod.rs b/server/src/rtsim/mod.rs index dca14151c3..2b193cc645 100644 --- a/server/src/rtsim/mod.rs +++ b/server/src/rtsim/mod.rs @@ -10,10 +10,10 @@ use self::{chunks::Chunks, entity::Entity}; use common::{ comp, rtsim::{RtSimController, RtSimEntity, RtSimId}, - system::{dispatch, System}, terrain::TerrainChunk, vol::RectRasterableVol, }; +use common_ecs::{dispatch, System}; use common_sys::state::State; use rand::prelude::*; use slab::Slab; diff --git a/server/src/rtsim/tick.rs b/server/src/rtsim/tick.rs index 312c403661..0ae3503f11 100644 --- a/server/src/rtsim/tick.rs +++ b/server/src/rtsim/tick.rs @@ -6,9 +6,9 @@ use common::{ comp::inventory::loadout_builder::LoadoutBuilder, event::{EventBus, ServerEvent}, resources::DeltaTime, - system::{Job, Origin, Phase, System}, terrain::TerrainGrid, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{Join, Read, ReadExpect, ReadStorage, WriteExpect, WriteStorage}; use std::sync::Arc; diff --git a/server/src/rtsim/unload_chunks.rs b/server/src/rtsim/unload_chunks.rs index eb9c85f79f..3bc49931cd 100644 --- a/server/src/rtsim/unload_chunks.rs +++ b/server/src/rtsim/unload_chunks.rs @@ -2,9 +2,9 @@ use super::*; use common::{ comp::Pos, event::{EventBus, ServerEvent}, - system::{Job, Origin, Phase, System}, terrain::TerrainGrid, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{Entities, Read, ReadExpect, ReadStorage, WriteExpect}; #[derive(Default)] diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index d3dcfb6364..41262be87b 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -17,13 +17,13 @@ use common::{ event::{Emitter, EventBus, ServerEvent}, path::TraversalConfig, resources::{DeltaTime, TimeOfDay}, - system::{Job, Origin, Phase, System}, terrain::{Block, TerrainGrid}, time::DayPeriod, uid::{Uid, UidAllocator}, util::Dir, vol::ReadVol, }; +use common_ecs::{Job, Origin, Phase, System}; use rand::{thread_rng, Rng}; use rayon::iter::ParallelIterator; use specs::{ diff --git a/server/src/sys/entity_sync.rs b/server/src/sys/entity_sync.rs index 1684770436..25fa256b45 100644 --- a/server/src/sys/entity_sync.rs +++ b/server/src/sys/entity_sync.rs @@ -9,11 +9,11 @@ use common::{ outcome::Outcome, region::{Event as RegionEvent, RegionMap}, resources::TimeOfDay, - system::{Job, Origin, Phase, System}, terrain::TerrainChunkSize, uid::Uid, vol::RectVolSize, }; +use common_ecs::{Job, Origin, Phase, System}; use common_net::{msg::ServerGeneral, sync::CompSyncPackage}; use specs::{ Entities, Entity as EcsEntity, Join, Read, ReadExpect, ReadStorage, Write, WriteStorage, diff --git a/server/src/sys/invite_timeout.rs b/server/src/sys/invite_timeout.rs index d08f9e848e..a55690ceba 100644 --- a/server/src/sys/invite_timeout.rs +++ b/server/src/sys/invite_timeout.rs @@ -1,9 +1,9 @@ use crate::client::Client; use common::{ comp::invite::{Invite, PendingInvites}, - system::{Job, Origin, Phase, System}, uid::Uid, }; +use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::{InviteAnswer, ServerGeneral}; use specs::{Entities, Join, ReadStorage, WriteStorage}; diff --git a/server/src/sys/metrics.rs b/server/src/sys/metrics.rs index b991622538..0f648368fe 100644 --- a/server/src/sys/metrics.rs +++ b/server/src/sys/metrics.rs @@ -2,12 +2,8 @@ use crate::{ metrics::{EcsSystemMetrics, PhysicsMetrics, TickMetrics}, Tick, TickStart, }; -use common::{ - metrics::SysMetrics, - resources::TimeOfDay, - system::{Job, Origin, Phase, System}, - terrain::TerrainGrid, -}; +use common::{resources::TimeOfDay, terrain::TerrainGrid}; +use common_ecs::{Job, Origin, Phase, SysMetrics, System}; use specs::{Entities, Join, Read, ReadExpect}; use std::time::Instant; @@ -23,7 +19,7 @@ impl<'a> System<'a> for Sys { ReadExpect<'a, TickStart>, Option>, Read<'a, SysMetrics>, - Read<'a, common::metrics::PhysicsMetrics>, + Read<'a, common_ecs::PhysicsMetrics>, ReadExpect<'a, EcsSystemMetrics>, ReadExpect<'a, TickMetrics>, ReadExpect<'a, PhysicsMetrics>, @@ -56,7 +52,11 @@ impl<'a> System<'a> for Sys { //this system hasn't run yet state.remove(Self::NAME); - for (name, stat) in common::system::gen_stats(&state, tick_start.0, 8, 8) { + lazy_static::lazy_static! { + static ref THREADS: u16 = num_cpus::get() as u16; + } + + for (name, stat) in common_ecs::gen_stats(&state, tick_start.0, *THREADS, *THREADS) { export_ecs .system_start_time .with_label_values(&[&name]) @@ -65,11 +65,15 @@ impl<'a> System<'a> for Sys { .system_thread_avg .with_label_values(&[&name]) .set(stat.avg_threads() as f64); - let len = stat.length_ns() as i64; + let len = stat.length_ns(); export_ecs .system_length_time .with_label_values(&[&name]) - .set(len); + .set(len as i64); + export_ecs + .system_length_count + .with_label_values(&[&name]) + .inc_by(len); export_ecs .system_length_hist .with_label_values(&[&name]) @@ -115,11 +119,15 @@ impl<'a> System<'a> for Sys { .system_thread_avg .with_label_values(&["metrics"]) .set(1.0); - let len = start.elapsed().as_nanos() as i64; + let len = start.elapsed().as_nanos() as u64; export_ecs .system_length_time .with_label_values(&["metrics"]) - .set(len); + .set(len as i64); + export_ecs + .system_length_count + .with_label_values(&["metrics"]) + .inc_by(len); export_ecs .system_length_hist .with_label_values(&["metrics"]) diff --git a/server/src/sys/mod.rs b/server/src/sys/mod.rs index 0995c82859..a97adf84eb 100644 --- a/server/src/sys/mod.rs +++ b/server/src/sys/mod.rs @@ -11,7 +11,7 @@ pub mod terrain; pub mod terrain_sync; pub mod waypoint; -use common::system::{dispatch, run_now}; +use common_ecs::{dispatch, run_now}; use specs::DispatcherBuilder; use std::{ marker::PhantomData, diff --git a/server/src/sys/msg/character_screen.rs b/server/src/sys/msg/character_screen.rs index 6bd591ec74..8e5a4c51a0 100644 --- a/server/src/sys/msg/character_screen.rs +++ b/server/src/sys/msg/character_screen.rs @@ -5,9 +5,9 @@ use crate::{ use common::{ comp::{ChatType, Player, UnresolvedChatMsg}, event::{EventBus, ServerEvent}, - system::{Job, Origin, Phase, System}, uid::Uid, }; +use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::{ClientGeneral, ServerGeneral}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage}; use std::sync::atomic::Ordering; diff --git a/server/src/sys/msg/general.rs b/server/src/sys/msg/general.rs index 7928218efd..5e91e50e51 100644 --- a/server/src/sys/msg/general.rs +++ b/server/src/sys/msg/general.rs @@ -3,9 +3,9 @@ use common::{ comp::{ChatMode, Player, UnresolvedChatMsg}, event::{EventBus, ServerEvent}, resources::Time, - system::{Job, Origin, Phase, System}, uid::Uid, }; +use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::{ validate_chat_msg, ChatMsgValidationError, ClientGeneral, MAX_BYTES_CHAT_MSG, }; diff --git a/server/src/sys/msg/in_game.rs b/server/src/sys/msg/in_game.rs index af11dc1b20..e79436de1f 100644 --- a/server/src/sys/msg/in_game.rs +++ b/server/src/sys/msg/in_game.rs @@ -2,10 +2,10 @@ use crate::{client::Client, metrics::NetworkRequestMetrics, presence::Presence, use common::{ comp::{CanBuild, ControlEvent, Controller, ForceUpdate, Health, Ori, Pos, Stats, Vel}, event::{EventBus, ServerEvent}, - system::{Job, Origin, Phase, System}, terrain::{TerrainChunkSize, TerrainGrid}, vol::{ReadVol, RectVolSize}, }; +use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::{ClientGeneral, PresenceKind, ServerGeneral}; use common_sys::state::BlockChange; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, Write, WriteStorage}; diff --git a/server/src/sys/msg/ping.rs b/server/src/sys/msg/ping.rs index 2ec8b4e907..35cee8953e 100644 --- a/server/src/sys/msg/ping.rs +++ b/server/src/sys/msg/ping.rs @@ -2,8 +2,8 @@ use crate::{client::Client, metrics::PlayerMetrics, Settings}; use common::{ event::{EventBus, ServerEvent}, resources::Time, - system::{Job, Origin, Phase, System}, }; +use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::PingMsg; use specs::{Entities, Join, Read, ReadExpect, ReadStorage}; use std::sync::atomic::Ordering; diff --git a/server/src/sys/object.rs b/server/src/sys/object.rs index b24cc0224b..bf87673c78 100644 --- a/server/src/sys/object.rs +++ b/server/src/sys/object.rs @@ -3,9 +3,9 @@ use common::{ effect::Effect, event::{EventBus, ServerEvent}, resources::DeltaTime, - system::{Job, Origin, Phase, System}, Damage, DamageSource, Explosion, RadiusEffect, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{Entities, Join, Read, ReadStorage, WriteStorage}; /// This system is responsible for handling misc object behaviours diff --git a/server/src/sys/persistence.rs b/server/src/sys/persistence.rs index 12b2c07695..1f9e070bf6 100644 --- a/server/src/sys/persistence.rs +++ b/server/src/sys/persistence.rs @@ -1,8 +1,6 @@ use crate::{persistence::character_updater, presence::Presence, sys::SysScheduler}; -use common::{ - comp::{Inventory, Stats, Waypoint}, - system::{Job, Origin, Phase, System}, -}; +use common::comp::{Inventory, Stats, Waypoint}; +use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::PresenceKind; use specs::{Join, ReadExpect, ReadStorage, Write}; diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index 394f966fbb..105b417a6c 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -4,9 +4,9 @@ use common::{ Gravity, Group, Health, Inventory, Item, LightEmitter, Mass, MountState, Mounting, Ori, Player, Poise, Pos, Scale, Shockwave, Stats, Sticky, Vel, }, - system::{Job, Origin, Phase, System}, uid::Uid, }; +use common_ecs::{Job, Origin, Phase, System}; use common_net::{ msg::EcsCompPacket, sync::{CompSyncPackage, EntityPackage, EntitySyncPackage, UpdateTracker, WorldSyncExt}, diff --git a/server/src/sys/subscription.rs b/server/src/sys/subscription.rs index 51a242e1d8..3e132d86e6 100644 --- a/server/src/sys/subscription.rs +++ b/server/src/sys/subscription.rs @@ -6,11 +6,11 @@ use crate::{ use common::{ comp::{Ori, Pos, Vel}, region::{region_in_vd, regions_in_vd, Event as RegionEvent, RegionMap}, - system::{Job, Origin, Phase, System}, terrain::TerrainChunkSize, uid::Uid, vol::RectVolSize, }; +use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::ServerGeneral; use specs::{ Entities, Join, ReadExpect, ReadStorage, SystemData, World, WorldExt, Write, WriteStorage, diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 8f21a42324..e0e3bc5247 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -6,10 +6,10 @@ use common::{ event::{EventBus, ServerEvent}, generation::get_npc_name, npc::NPC_NAMES, - system::{Job, Origin, Phase, System}, terrain::TerrainGrid, LoadoutBuilder, SkillSetBuilder, }; +use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::ServerGeneral; use common_sys::state::TerrainChanges; use specs::{Join, Read, ReadStorage, Write, WriteExpect}; diff --git a/server/src/sys/terrain_sync.rs b/server/src/sys/terrain_sync.rs index 070bfa8880..f085e6a025 100644 --- a/server/src/sys/terrain_sync.rs +++ b/server/src/sys/terrain_sync.rs @@ -1,9 +1,6 @@ use crate::{client::Client, presence::Presence}; -use common::{ - comp::Pos, - system::{Job, Origin, Phase, System}, - terrain::TerrainGrid, -}; +use common::{comp::Pos, terrain::TerrainGrid}; +use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::ServerGeneral; use common_sys::state::TerrainChanges; use specs::{Join, Read, ReadExpect, ReadStorage}; diff --git a/server/src/sys/waypoint.rs b/server/src/sys/waypoint.rs index 7107fc79c5..c3e74c4cbf 100644 --- a/server/src/sys/waypoint.rs +++ b/server/src/sys/waypoint.rs @@ -2,8 +2,8 @@ use crate::client::Client; use common::{ comp::{Player, Pos, Waypoint, WaypointArea}, resources::Time, - system::{Job, Origin, Phase, System}, }; +use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::{Notification, ServerGeneral}; use specs::{Entities, Join, Read, ReadStorage, WriteStorage}; diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index 7002bac3f6..e3385d8318 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -21,6 +21,8 @@ default = ["gl", "singleplayer", "native-dialog", "plugins", "simd"] [dependencies] client = {package = "veloren-client", path = "../client"} common = {package = "veloren-common", path = "../common"} +common-base = {package = "veloren-common-base", path = "../common/base"} +common-ecs = {package = "veloren-common-ecs", path = "../common/ecs"} common-net = {package = "veloren-common-net", path = "../common/net"} common-sys = {package = "veloren-common-sys", path = "../common/sys"} diff --git a/voxygen/src/ecs/sys.rs b/voxygen/src/ecs/sys.rs index a9810a35b0..4aedaa4c95 100644 --- a/voxygen/src/ecs/sys.rs +++ b/voxygen/src/ecs/sys.rs @@ -1,7 +1,7 @@ pub mod floater; mod interpolation; -use common::system::{dispatch, System}; +use common_ecs::{dispatch, System}; use specs::DispatcherBuilder; pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { diff --git a/voxygen/src/ecs/sys/floater.rs b/voxygen/src/ecs/sys/floater.rs index 164ca568c4..8929d0a839 100644 --- a/voxygen/src/ecs/sys/floater.rs +++ b/voxygen/src/ecs/sys/floater.rs @@ -5,9 +5,9 @@ use crate::ecs::{ use common::{ comp::{Health, HealthSource, Pos}, resources::DeltaTime, - system::{Job, Origin, Phase, System}, uid::Uid, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, WriteStorage}; // How long floaters last (in seconds) diff --git a/voxygen/src/ecs/sys/interpolation.rs b/voxygen/src/ecs/sys/interpolation.rs index 2b96957150..44525f8e70 100644 --- a/voxygen/src/ecs/sys/interpolation.rs +++ b/voxygen/src/ecs/sys/interpolation.rs @@ -2,8 +2,8 @@ use crate::ecs::comp::Interpolated; use common::{ comp::{object, Body, Ori, Pos, Vel}, resources::DeltaTime, - system::{Job, Origin, Phase, System}, }; +use common_ecs::{Job, Origin, Phase, System}; use specs::{Entities, Join, Read, ReadStorage, WriteStorage}; use tracing::warn; use vek::*; diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 7efda93209..18fcac195e 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -71,13 +71,13 @@ use common::{ BuffKind, }, outcome::Outcome, - span, terrain::TerrainChunk, trade::TradeAction, uid::Uid, util::srgba_to_linear, vol::RectRasterableVol, }; +use common_base::span; use common_net::msg::{Notification, PresenceKind}; use conrod_core::{ text::cursor::Index, diff --git a/voxygen/src/lib.rs b/voxygen/src/lib.rs index c79d3cd8c6..b80024afa5 100644 --- a/voxygen/src/lib.rs +++ b/voxygen/src/lib.rs @@ -40,7 +40,8 @@ use crate::{ settings::Settings, window::{Event, Window}, }; -use common::{assets::AssetHandle, clock::Clock, span}; +use common::{assets::AssetHandle, clock::Clock}; +use common_base::span; /// A type used to store state that is shared between all play states. pub struct GlobalState { diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index 69b65def02..27f753fe0d 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -9,7 +9,8 @@ use crate::{ Direction, GlobalState, PlayState, PlayStateResult, }; use client::{self, Client}; -use common::{comp, resources::DeltaTime, span}; +use common::{comp, resources::DeltaTime}; +use common_base::span; use specs::WorldExt; use std::{cell::RefCell, mem, rc::Rc}; use tracing::error; diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 6f6b3c8f1c..23e894f4bb 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -16,7 +16,8 @@ use client::{ error::{InitProtocolError, NetworkConnectError, NetworkError}, }; use client_init::{ClientConnArgs, ClientInit, Error as InitError, Msg as InitMsg}; -use common::{assets::AssetExt, comp, span}; +use common::{assets::AssetExt, comp}; +use common_base::span; use std::sync::Arc; use tokio::runtime; use tracing::error; diff --git a/voxygen/src/mesh/greedy.rs b/voxygen/src/mesh/greedy.rs index 33ac107128..72b07968c2 100644 --- a/voxygen/src/mesh/greedy.rs +++ b/voxygen/src/mesh/greedy.rs @@ -1,5 +1,5 @@ use crate::render::{self, mesh::Quad, ColLightFmt, ColLightInfo, TerrainPipeline}; -use common::span; +use common_base::span; use vek::*; type TerrainVertex = ::Vertex; diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index d2ab578a6e..de9bed8cc3 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -7,12 +7,12 @@ use crate::{ scene::terrain::BlocksOfInterest, }; use common::{ - span, terrain::Block, util::either_with, vol::{ReadVol, RectRasterableVol}, volumes::vol_grid_2d::{CachedVolGrid2d, VolGrid2d}, }; +use common_base::span; use std::{collections::VecDeque, fmt::Debug}; use tracing::error; use vek::*; diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index f1ae11e340..6856dbbb4b 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -12,10 +12,8 @@ use super::{ AaMode, CloudMode, FilterMethod, FluidMode, LightingMode, Pipeline, RenderError, RenderMode, ShadowMapMode, ShadowMode, WrapMode, }; -use common::{ - assets::{self, AssetExt, AssetHandle}, - span, -}; +use common::assets::{self, AssetExt, AssetHandle}; +use common_base::span; use core::convert::TryFrom; use gfx::{ self, diff --git a/voxygen/src/run.rs b/voxygen/src/run.rs index de26f0c287..9a3819ee17 100644 --- a/voxygen/src/run.rs +++ b/voxygen/src/run.rs @@ -5,7 +5,7 @@ use crate::{ window::{Event, EventLoop}, Direction, GlobalState, PlayState, PlayStateResult, }; -use common::{no_guard_span, span, util::GuardlessSpan}; +use common_base::{no_guard_span, span, GuardlessSpan}; use std::{mem, time::Duration}; use tracing::debug; diff --git a/voxygen/src/scene/camera.rs b/voxygen/src/scene/camera.rs index b9ae5c97ac..ebd005a004 100644 --- a/voxygen/src/scene/camera.rs +++ b/voxygen/src/scene/camera.rs @@ -1,4 +1,5 @@ -use common::{span, terrain::TerrainGrid, vol::ReadVol}; +use common::{terrain::TerrainGrid, vol::ReadVol}; +use common_base::span; use std::f32::consts::PI; use treeculler::Frustum; use vek::*; diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index e8821425e2..e4d0a9af31 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -33,12 +33,12 @@ use common::{ LightEmitter, Ori, PhysicsState, PoiseState, Pos, Scale, Vel, }, resources::DeltaTime, - span, states::utils::StageSection, terrain::TerrainChunk, util::Dir, vol::RectRasterableVol, }; +use common_base::span; use common_sys::state::State; use core::{ borrow::Borrow, diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 43d0c9dd4e..cc3ffb706e 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -28,10 +28,10 @@ use common::{ comp, outcome::Outcome, resources::DeltaTime, - span, terrain::{BlockKind, TerrainChunk}, vol::ReadVol, }; +use common_base::span; use common_sys::state::State; use comp::item::Reagent; use num::traits::{Float, FloatConst}; diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index 95e5e348b6..7161bbf88b 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -13,11 +13,11 @@ use common::{ figure::Segment, outcome::Outcome, resources::DeltaTime, - span, spiral::Spiral2d, terrain::TerrainChunk, vol::{RectRasterableVol, SizedVol}, }; +use common_base::span; use hashbrown::HashMap; use rand::prelude::*; use specs::{Join, WorldExt}; diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 725141cb1a..6faf7aa42e 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -15,12 +15,12 @@ use super::{math, LodData, SceneData}; use common::{ assets::{self, AssetExt, DotVoxAsset}, figure::Segment, - span, spiral::Spiral2d, terrain::{sprite, Block, SpriteKind, TerrainChunk}, vol::{BaseVol, ReadVol, RectRasterableVol, SampleVol}, volumes::vol_grid_2d::{VolGrid2d, VolGrid2dError}, }; +use common_base::span; use core::{f32, fmt::Debug, i32, marker::PhantomData, time::Duration}; use crossbeam::channel; use enum_iterator::IntoEnumIterator; diff --git a/voxygen/src/scene/terrain/watcher.rs b/voxygen/src/scene/terrain/watcher.rs index 2d68b512d5..202d7f284a 100644 --- a/voxygen/src/scene/terrain/watcher.rs +++ b/voxygen/src/scene/terrain/watcher.rs @@ -1,8 +1,8 @@ use common::{ - span, terrain::{BlockKind, SpriteKind, TerrainChunk}, vol::{IntoVolIterator, RectRasterableVol}, }; +use common_base::span; use rand::prelude::*; use vek::*; diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 4344a54162..7ed8e0b427 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -15,7 +15,6 @@ use common::{ }, consts::{MAX_MOUNT_RANGE, MAX_PICKUP_RANGE}, outcome::Outcome, - span, terrain::{Block, BlockKind}, trade::TradeResult, util::{ @@ -24,6 +23,7 @@ use common::{ }, vol::ReadVol, }; +use common_base::span; use common_net::{ msg::{server::InviteAnswer, PresenceKind}, sync::WorldSyncExt, diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index fc33b4007d..7e1806f377 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -815,7 +815,7 @@ impl Settings { pub fn voxygen_data_dir() -> PathBuf { // Note: since voxygen is technically a lib we made need to lift this up to // run.rs - let mut path = common::userdata_dir_workspace!(); + let mut path = common_base::userdata_dir_workspace!(); path.push("voxygen"); path } diff --git a/voxygen/src/singleplayer.rs b/voxygen/src/singleplayer.rs index 78b20aa47c..3e994d1361 100644 --- a/voxygen/src/singleplayer.rs +++ b/voxygen/src/singleplayer.rs @@ -33,7 +33,7 @@ impl Singleplayer { // Determine folder to save server data in let server_data_dir = { - let mut path = common::userdata_dir_workspace!(); + let mut path = common_base::userdata_dir_workspace!(); path.push("singleplayer"); path }; diff --git a/voxygen/src/ui/graphic/pixel_art.rs b/voxygen/src/ui/graphic/pixel_art.rs index 104caafe14..26ce09a8de 100644 --- a/voxygen/src/ui/graphic/pixel_art.rs +++ b/voxygen/src/ui/graphic/pixel_art.rs @@ -1,7 +1,5 @@ -use common::{ - span, - util::{linear_to_srgba, srgba_to_linear}, -}; +use common::util::{linear_to_srgba, srgba_to_linear}; +use common_base::span; /// Pixel art scaling /// Note: The current ui is locked to the pixel grid with little animation, if /// we want smoothly moving pixel art this should be done in the shaders diff --git a/voxygen/src/ui/ice/mod.rs b/voxygen/src/ui/ice/mod.rs index f120d32e67..c605f37bc3 100644 --- a/voxygen/src/ui/ice/mod.rs +++ b/voxygen/src/ui/ice/mod.rs @@ -15,7 +15,7 @@ use super::{ scale::{Scale, ScaleMode}, }; use crate::{render::Renderer, window::Window, Error}; -use common::span; +use common_base::span; use iced::{mouse, Cache, Size, UserInterface}; use iced_winit::Clipboard; use vek::*; diff --git a/voxygen/src/ui/ice/renderer/mod.rs b/voxygen/src/ui/ice/renderer/mod.rs index 20396bb0ff..d6d819e767 100644 --- a/voxygen/src/ui/ice/renderer/mod.rs +++ b/voxygen/src/ui/ice/renderer/mod.rs @@ -20,7 +20,8 @@ use crate::{ }, Error, }; -use common::{span, util::srgba_to_linear}; +use common::util::srgba_to_linear; +use common_base::span; use std::{convert::TryInto, ops::Range}; use vek::*; diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index 9bb63506e2..aef6491f58 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -33,7 +33,8 @@ use crate::{ #[rustfmt::skip] use ::image::GenericImageView; use cache::Cache; -use common::{span, util::srgba_to_linear}; +use common::util::srgba_to_linear; +use common_base::span; use conrod_core::{ event::Input, graph::{self, Graph}, diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index b3753b957c..ab59174d32 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -4,7 +4,7 @@ use crate::{ settings::{ControlSettings, Settings}, ui, Error, }; -use common::span; +use common_base::span; use crossbeam::channel; use gilrs::{EventType, Gilrs}; use hashbrown::HashMap;