From 05d0eb9db42abbb1ec808673bc35881f51051a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Tue, 6 Apr 2021 17:47:03 +0200 Subject: [PATCH 1/4] seperate sys/state --- Cargo.lock | 28 ++++++++++--- Cargo.toml | 1 + client/Cargo.toml | 3 +- client/src/lib.rs | 6 ++- common/state/Cargo.toml | 40 +++++++++++++++++++ common/{sys/src/state.rs => state/src/lib.rs} | 8 ++-- common/{sys => state}/src/plugin/errors.rs | 0 .../src/plugin/memory_manager.rs | 0 common/{sys => state}/src/plugin/mod.rs | 0 common/{sys => state}/src/plugin/module.rs | 0 common/{sys => state}/src/plugin/wasm_env.rs | 0 common/sys/Cargo.toml | 12 ------ common/sys/src/interpolation.rs | 24 ++++++----- common/sys/src/lib.rs | 8 ++-- server/Cargo.toml | 3 +- server/src/cmd.rs | 2 +- server/src/events/entity_manipulation.rs | 2 +- server/src/events/group_manip.rs | 2 +- server/src/events/inventory_manip.rs | 2 +- server/src/events/player.rs | 2 +- server/src/lib.rs | 8 ++-- server/src/login_provider.rs | 4 +- server/src/rtsim/mod.rs | 2 +- server/src/state_ext.rs | 2 +- server/src/sys/mod.rs | 4 +- server/src/sys/msg/in_game.rs | 2 +- server/src/sys/msg/register.rs | 4 +- server/src/sys/terrain.rs | 2 +- server/src/sys/terrain_sync.rs | 2 +- voxygen/Cargo.toml | 3 +- voxygen/src/audio/ambient.rs | 2 +- voxygen/src/audio/music.rs | 2 +- .../src/audio/sfx/event_mapper/block/mod.rs | 2 +- .../audio/sfx/event_mapper/campfire/mod.rs | 2 +- .../src/audio/sfx/event_mapper/combat/mod.rs | 2 +- voxygen/src/audio/sfx/event_mapper/mod.rs | 2 +- .../audio/sfx/event_mapper/movement/mod.rs | 2 +- voxygen/src/audio/sfx/mod.rs | 2 +- voxygen/src/scene/figure/mod.rs | 2 +- voxygen/src/scene/mod.rs | 2 +- 40 files changed, 127 insertions(+), 69 deletions(-) create mode 100644 common/state/Cargo.toml rename common/{sys/src/state.rs => state/src/lib.rs} (99%) rename common/{sys => state}/src/plugin/errors.rs (100%) rename common/{sys => state}/src/plugin/memory_manager.rs (100%) rename common/{sys => state}/src/plugin/mod.rs (100%) rename common/{sys => state}/src/plugin/module.rs (100%) rename common/{sys => state}/src/plugin/wasm_env.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index ce4db3af9d..2553e70952 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5442,6 +5442,7 @@ dependencies = [ "veloren-common-ecs", "veloren-common-frontend", "veloren-common-net", + "veloren-common-state", "veloren-common-sys", "veloren-network", ] @@ -5535,18 +5536,14 @@ dependencies = [ ] [[package]] -name = "veloren-common-sys" +name = "veloren-common-state" version = "0.9.0" dependencies = [ "bincode", "hashbrown", - "indexmap", - "ordered-float 2.1.1", - "rand 0.8.3", "rayon", "scopeguard", "serde", - "slab", "specs", "tar", "toml", @@ -5560,6 +5557,25 @@ dependencies = [ "wasmer", ] +[[package]] +name = "veloren-common-sys" +version = "0.9.0" +dependencies = [ + "hashbrown", + "indexmap", + "ordered-float 2.1.1", + "rand 0.8.3", + "rayon", + "slab", + "specs", + "tracing", + "vek", + "veloren-common", + "veloren-common-base", + "veloren-common-ecs", + "veloren-common-net", +] + [[package]] name = "veloren-network" version = "0.3.0" @@ -5666,6 +5682,7 @@ dependencies = [ "veloren-common-base", "veloren-common-ecs", "veloren-common-net", + "veloren-common-state", "veloren-common-sys", "veloren-network", "veloren-plugin-api", @@ -5753,6 +5770,7 @@ dependencies = [ "veloren-common-ecs", "veloren-common-frontend", "veloren-common-net", + "veloren-common-state", "veloren-common-sys", "veloren-server", "veloren-voxygen-anim", diff --git a/Cargo.toml b/Cargo.toml index 817eb35f37..2eb30662d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "common/base", "common/ecs", "common/net", + "common/state", "common/sys", "common/frontend", "client", diff --git a/client/Cargo.toml b/client/Cargo.toml index ff1d1237d9..8f7619c628 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [features] tracy = ["common/tracy", "common-base/tracy", "common-sys/tracy", "common-net/tracy", "common-frontend/tracy"] simd = ["vek/platform_intrinsics"] -plugins = ["common-sys/plugins"] +plugins = ["common-state/plugins"] bin_bot = ["common-ecs", "serde", "ron", "clap", "rustyline", "common-frontend", "async-channel"] default = ["simd"] @@ -15,6 +15,7 @@ default = ["simd"] [dependencies] common = { package = "veloren-common", path = "../common", features = ["no-assets"] } common-base = { package = "veloren-common-base", path = "../common/base" } +common-state = { package = "veloren-common-state", path = "../common/state", default-features = false } 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 4443e2638e..52f012b1df 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -54,7 +54,8 @@ use common_net::{ }, sync::WorldSyncExt, }; -use common_sys::state::State; +use common_state::State; +use common_sys::add_local_systems; use comp::BuffKind; use futures_util::FutureExt; use hashbrown::{HashMap, HashSet}; @@ -1418,7 +1419,8 @@ impl Client { } // 4) Tick the client's LocalState - self.state.tick(dt, add_foreign_systems, true); + self.state + .tick(dt, add_local_systems, add_foreign_systems, true); // TODO: avoid emitting these in the first place self.state .ecs() diff --git a/common/state/Cargo.toml b/common/state/Cargo.toml new file mode 100644 index 0000000000..26c2cec587 --- /dev/null +++ b/common/state/Cargo.toml @@ -0,0 +1,40 @@ +[package] +authors = ["Marcel Märtens "] +edition = "2018" +name = "veloren-common-state" +version = "0.9.0" + +[features] +tracy = ["common/tracy"] +simd = ["vek/platform_intrinsics"] +plugins = ["toml", "tar", "wasmer", "bincode", "plugin-api", "serde"] + +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" } + +rayon = "1.5" +tracing = { version = "0.1", default-features = false } +vek = { version = "=0.14.1", features = ["serde"] } + +# Data structures +hashbrown = { version = "0.9", features = ["rayon", "serde", "nightly"] } + +# ECS +specs = { git = "https://github.com/amethyst/specs.git", features = ["serde", "storage-event-control", "derive"], rev = "5a9b71035007be0e3574f35184acac1cd4530496" } + +# Plugins +scopeguard = "1.1.0" +serde = { version = "1.0.110", features = ["derive"], optional = true } +toml = { version = "0.5.7", optional = true } +tar = { version = "0.4.30", optional = true } +wasmer = { version = "1.0.0", optional = true, default-features = false, features = ["wat", "default-cranelift", "default-jit"] } +bincode = { version = "1.3.1", optional = true } +plugin-api = { package = "veloren-plugin-api", path = "../../plugin/api", optional = true } + +# Tweak running code +#inline_tweak = { version = "1.0.8", features = ["release_tweak"] } diff --git a/common/sys/src/state.rs b/common/state/src/lib.rs similarity index 99% rename from common/sys/src/state.rs rename to common/state/src/lib.rs index b839295879..a3707c983f 100644 --- a/common/sys/src/state.rs +++ b/common/state/src/lib.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "plugins")] pub mod plugin; + #[cfg(feature = "plugins")] use crate::plugin::memory_manager::EcsWorld; #[cfg(feature = "plugins")] @@ -18,7 +20,7 @@ use common::{ vol::{ReadVol, WriteVol}, }; use common_base::span; -use common_ecs::{run_now, PhysicsMetrics, SysMetrics}; +use common_ecs::{PhysicsMetrics, SysMetrics}; use common_net::sync::{interpolation as sync_interp, WorldSyncExt}; use core::{convert::identity, time::Duration}; use hashbrown::{hash_map, HashMap, HashSet}; @@ -506,6 +508,7 @@ impl State { pub fn tick( &mut self, dt: Duration, + add_local_systems: impl Fn(&mut DispatcherBuilder), add_foreign_systems: impl Fn(&mut DispatcherBuilder), update_terrain_and_regions: bool, ) { @@ -528,14 +531,13 @@ impl State { // Create and run a dispatcher for ecs systems. let mut dispatch_builder = DispatcherBuilder::new().with_pool(Arc::clone(&self.thread_pool)); - crate::add_local_systems(&mut dispatch_builder); // TODO: Consider alternative ways to do this + add_local_systems(&mut dispatch_builder); add_foreign_systems(&mut dispatch_builder); // This dispatches all the systems in parallel. let mut dispatcher = dispatch_builder.build(); drop(guard); span!(guard, "run systems"); - run_now::(&self.ecs); dispatcher.dispatch(&self.ecs); drop(guard); diff --git a/common/sys/src/plugin/errors.rs b/common/state/src/plugin/errors.rs similarity index 100% rename from common/sys/src/plugin/errors.rs rename to common/state/src/plugin/errors.rs diff --git a/common/sys/src/plugin/memory_manager.rs b/common/state/src/plugin/memory_manager.rs similarity index 100% rename from common/sys/src/plugin/memory_manager.rs rename to common/state/src/plugin/memory_manager.rs diff --git a/common/sys/src/plugin/mod.rs b/common/state/src/plugin/mod.rs similarity index 100% rename from common/sys/src/plugin/mod.rs rename to common/state/src/plugin/mod.rs diff --git a/common/sys/src/plugin/module.rs b/common/state/src/plugin/module.rs similarity index 100% rename from common/sys/src/plugin/module.rs rename to common/state/src/plugin/module.rs diff --git a/common/sys/src/plugin/wasm_env.rs b/common/state/src/plugin/wasm_env.rs similarity index 100% rename from common/sys/src/plugin/wasm_env.rs rename to common/state/src/plugin/wasm_env.rs diff --git a/common/sys/Cargo.toml b/common/sys/Cargo.toml index b2ac1ec354..348379a164 100644 --- a/common/sys/Cargo.toml +++ b/common/sys/Cargo.toml @@ -7,7 +7,6 @@ version = "0.9.0" [features] tracy = ["common/tracy"] simd = ["vek/platform_intrinsics"] -plugins = ["toml", "tar", "wasmer", "bincode", "plugin-api"] default = ["simd"] @@ -31,16 +30,5 @@ slab = "0.4.2" # ECS specs = { git = "https://github.com/amethyst/specs.git", features = ["serde", "storage-event-control", "derive"], rev = "5a9b71035007be0e3574f35184acac1cd4530496" } -# Serde -serde = { version = "1.0.110", features = ["derive"] } - -# Plugins -scopeguard = "1.1.0" -toml = { version = "0.5.7", optional = true } -tar = { version = "0.4.30", optional = true } -wasmer = { version = "1.0.0", optional = true, default-features = false, features = ["wat", "default-cranelift", "default-jit"] } -bincode = { version = "1.3.1", optional = true } -plugin-api = { package = "veloren-plugin-api", path = "../../plugin/api", optional = true } - # Tweak running code #inline_tweak = { version = "1.0.8", features = ["release_tweak"] } diff --git a/common/sys/src/interpolation.rs b/common/sys/src/interpolation.rs index 66a0f7778b..0f0fb13fa5 100644 --- a/common/sys/src/interpolation.rs +++ b/common/sys/src/interpolation.rs @@ -11,35 +11,37 @@ use specs::{ }; #[derive(SystemData)] -pub struct InterpolationSystemData<'a> { +pub struct ReadData<'a> { time: Read<'a, Time>, player: Read<'a, PlayerEntity>, entities: Entities<'a>, - pos: WriteStorage<'a, Pos>, pos_interpdata: ReadStorage<'a, ::InterpData>, - vel: WriteStorage<'a, Vel>, vel_interpdata: ReadStorage<'a, ::InterpData>, - ori: WriteStorage<'a, Ori>, ori_interpdata: ReadStorage<'a, ::InterpData>, } #[derive(Default)] -pub struct InterpolationSystem; +pub struct Sys; -impl<'a> System<'a> for InterpolationSystem { - type SystemData = InterpolationSystemData<'a>; +impl<'a> System<'a> for Sys { + type SystemData = ( + ReadData<'a>, + WriteStorage<'a, Pos>, + WriteStorage<'a, Vel>, + WriteStorage<'a, Ori>, + ); const NAME: &'static str = "interpolation"; const ORIGIN: Origin = Origin::Common; const PHASE: Phase = Phase::Apply; - fn run(_job: &mut Job, mut data: InterpolationSystemData<'a>) { + fn run(_job: &mut Job, (data, mut pos, mut vel, mut ori): Self::SystemData) { let time = data.time.0; let player = data.player.0; ( &data.entities, - &mut data.pos, + &mut pos, &data.pos_interpdata, &data.vel_interpdata, ) @@ -54,7 +56,7 @@ impl<'a> System<'a> for InterpolationSystem { *pos = pos.interpolate(interp, time, vel); }, ); - (&data.entities, &mut data.vel, &data.vel_interpdata) + (&data.entities, &mut vel, &data.vel_interpdata) .par_join() .filter(|(e, _, _)| Some(e) != player.as_ref()) .for_each_init( @@ -66,7 +68,7 @@ impl<'a> System<'a> for InterpolationSystem { *vel = vel.interpolate(interp, time, &()); }, ); - (&data.entities, &mut data.ori, &data.ori_interpdata) + (&data.entities, &mut ori, &data.ori_interpdata) .par_join() .filter(|(e, _, _)| Some(e) != player.as_ref()) .for_each_init( diff --git a/common/sys/src/lib.rs b/common/sys/src/lib.rs index 7f5e329c11..59bc47ff8b 100644 --- a/common/sys/src/lib.rs +++ b/common/sys/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(label_break_value, bool_to_option, option_unwrap_none, array_map)] +#![feature(bool_to_option, option_unwrap_none, array_map)] #![allow(clippy::option_map_unit_fn)] mod aura; @@ -6,14 +6,12 @@ mod beam; mod buff; pub mod character_behavior; pub mod controller; -mod interpolation; +pub mod interpolation; pub mod melee; mod mount; pub mod phys; -#[cfg(feature = "plugins")] pub mod plugin; pub mod projectile; mod shockwave; -pub mod state; mod stats; // External @@ -21,12 +19,14 @@ use common_ecs::{dispatch, System}; use specs::DispatcherBuilder; pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { + dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[&mount::Sys::sys_name()]); dispatch::(dispatch_builder, &[&controller::Sys::sys_name()]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[ + &interpolation::Sys::sys_name(), &controller::Sys::sys_name(), &mount::Sys::sys_name(), &stats::Sys::sys_name(), diff --git a/server/Cargo.toml b/server/Cargo.toml index 4d790b703f..31dd0eb517 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" worldgen = [] tracy = ["common/tracy", "common-base/tracy", "common-ecs/tracy", "common-sys/tracy", "common-net/tracy", "world/tracy"] simd = ["vek/platform_intrinsics"] -plugins = ["common-sys/plugins"] +plugins = ["common-state/plugins"] default = ["worldgen", "plugins", "simd"] @@ -16,6 +16,7 @@ default = ["worldgen", "plugins", "simd"] 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-state = { package = "veloren-common-state", path = "../common/state" } common-sys = { package = "veloren-common-sys", path = "../common/sys" } common-net = { package = "veloren-common-net", path = "../common/net" } world = { package = "veloren-world", path = "../world" } diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 313579730f..9c24866507 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -34,7 +34,7 @@ use common_net::{ msg::{DisconnectReason, Notification, PlayerListUpdate, ServerGeneral}, sync::WorldSyncExt, }; -use common_sys::state::{BuildAreaError, BuildAreas}; +use common_state::{BuildAreaError, BuildAreas}; use core::{convert::TryFrom, ops::Not, time::Duration}; use hashbrown::HashSet; use rand::Rng; diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 90b7f13b7d..bf314d75cc 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -29,7 +29,7 @@ use common::{ Damage, DamageSource, Explosion, GroupTarget, RadiusEffect, }; use common_net::{msg::ServerGeneral, sync::WorldSyncExt}; -use common_sys::state::BlockChange; +use common_state::BlockChange; use comp::chat::GenericChatMsg; use hashbrown::HashSet; use specs::{join::Join, saveload::MarkerAllocator, Entity as EcsEntity, WorldExt}; diff --git a/server/src/events/group_manip.rs b/server/src/events/group_manip.rs index e0d194dc2f..3d175fd26f 100644 --- a/server/src/events/group_manip.rs +++ b/server/src/events/group_manip.rs @@ -9,7 +9,7 @@ use common::{ uid::Uid, }; use common_net::{msg::ServerGeneral, sync::WorldSyncExt}; -use common_sys::state::State; +use common_state::State; use specs::{ world::{Entity, WorldExt}, ReadStorage, WriteStorage, diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index 7ff3a7ac1c..6e687077b6 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -17,7 +17,7 @@ use common::{ vol::ReadVol, }; use common_net::{msg::ServerGeneral, sync::WorldSyncExt}; -use common_sys::state::State; +use common_state::State; use comp::LightEmitter; use crate::{client::Client, Server, StateExt}; diff --git a/server/src/events/player.rs b/server/src/events/player.rs index 5f4d439c3a..a7c56d6b1d 100644 --- a/server/src/events/player.rs +++ b/server/src/events/player.rs @@ -10,7 +10,7 @@ use common::{ }; use common_base::span; use common_net::msg::{PlayerListUpdate, PresenceKind, ServerGeneral}; -use common_sys::state::State; +use common_state::State; use specs::{saveload::MarkerAllocator, Builder, Entity as EcsEntity, WorldExt}; use tracing::{debug, error, trace, warn, Instrument}; diff --git a/server/src/lib.rs b/server/src/lib.rs index 3cccef1e4f..49c98eef1e 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -77,10 +77,11 @@ use common_net::{ sync::WorldSyncExt, }; #[cfg(feature = "plugins")] -use common_sys::plugin::memory_manager::EcsWorld; +use common_state::plugin::memory_manager::EcsWorld; #[cfg(feature = "plugins")] -use common_sys::plugin::PluginMgr; -use common_sys::state::{BuildAreas, State}; +use common_state::plugin::PluginMgr; +use common_state::{BuildAreas, State}; +use common_sys::add_local_systems; use metrics::{EcsSystemMetrics, PhysicsMetrics, TickMetrics}; use network::{Network, Pid, ProtocolAddr}; use persistence::{ @@ -516,6 +517,7 @@ impl Server { // in sys/terrain.rs self.state.tick( dt, + add_local_systems, |dispatcher_builder| { sys::msg::add_server_systems(dispatcher_builder); sys::add_server_systems(dispatcher_builder); diff --git a/server/src/login_provider.rs b/server/src/login_provider.rs index c75bae7d10..2028bc545a 100644 --- a/server/src/login_provider.rs +++ b/server/src/login_provider.rs @@ -2,9 +2,9 @@ use crate::settings::BanRecord; use authc::{AuthClient, AuthClientError, AuthToken, Uuid}; use common_net::msg::RegisterError; #[cfg(feature = "plugins")] -use common_sys::plugin::memory_manager::EcsWorld; +use common_state::plugin::memory_manager::EcsWorld; #[cfg(feature = "plugins")] -use common_sys::plugin::PluginMgr; +use common_state::plugin::PluginMgr; use hashbrown::{HashMap, HashSet}; use plugin_api::event::{PlayerJoinEvent, PlayerJoinResult}; use specs::Component; diff --git a/server/src/rtsim/mod.rs b/server/src/rtsim/mod.rs index 3a08bb55ff..827bd81728 100644 --- a/server/src/rtsim/mod.rs +++ b/server/src/rtsim/mod.rs @@ -14,7 +14,7 @@ use common::{ vol::RectRasterableVol, }; use common_ecs::{dispatch, System}; -use common_sys::state::State; +use common_state::State; use rand::prelude::*; use slab::Slab; use specs::{DispatcherBuilder, WorldExt}; diff --git a/server/src/state_ext.rs b/server/src/state_ext.rs index a0f5294031..733d188a57 100644 --- a/server/src/state_ext.rs +++ b/server/src/state_ext.rs @@ -18,7 +18,7 @@ use common_net::{ msg::{CharacterInfo, PlayerListUpdate, PresenceKind, ServerGeneral}, sync::WorldSyncExt, }; -use common_sys::state::State; +use common_state::State; use rand::prelude::*; use specs::{ saveload::MarkerAllocator, Builder, Entity as EcsEntity, EntityBuilder as EcsEntityBuilder, diff --git a/server/src/sys/mod.rs b/server/src/sys/mod.rs index 8542ecabef..141a24b20f 100644 --- a/server/src/sys/mod.rs +++ b/server/src/sys/mod.rs @@ -12,7 +12,7 @@ pub mod terrain_sync; pub mod waypoint; use common_ecs::{dispatch, run_now, System}; -use common_sys::{melee, projectile}; +use common_sys::{interpolation, melee, projectile}; use specs::DispatcherBuilder; use std::{ marker::PhantomData, @@ -23,7 +23,7 @@ pub type PersistenceScheduler = SysScheduler; pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) { dispatch::(dispatch_builder, &[&projectile::Sys::sys_name()]); - dispatch::(dispatch_builder, &[]); + dispatch::(dispatch_builder, &[&interpolation::Sys::sys_name()]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); diff --git a/server/src/sys/msg/in_game.rs b/server/src/sys/msg/in_game.rs index 624cec0893..f3b1475469 100644 --- a/server/src/sys/msg/in_game.rs +++ b/server/src/sys/msg/in_game.rs @@ -10,7 +10,7 @@ use common::{ }; use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::{ClientGeneral, PresenceKind, ServerGeneral}; -use common_sys::state::{BlockChange, BuildAreas}; +use common_state::{BlockChange, BuildAreas}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, Write, WriteStorage}; use tracing::{debug, trace, warn}; diff --git a/server/src/sys/msg/register.rs b/server/src/sys/msg/register.rs index a6e5a084f3..1a3092cbe7 100644 --- a/server/src/sys/msg/register.rs +++ b/server/src/sys/msg/register.rs @@ -20,10 +20,10 @@ use specs::{Entities, Join, Read, ReadExpect, ReadStorage, WriteExpect, WriteSto use tracing::trace; #[cfg(feature = "plugins")] -use common_sys::plugin::memory_manager::EcsWorld; +use common_state::plugin::memory_manager::EcsWorld; #[cfg(feature = "plugins")] -use common_sys::plugin::PluginMgr; +use common_state::plugin::PluginMgr; #[cfg(feature = "plugins")] type ReadPlugin<'a> = Read<'a, PluginMgr>; diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 3b37976311..8c4b9d5aa3 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -15,7 +15,7 @@ use common::{ }; use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::ServerGeneral; -use common_sys::state::TerrainChanges; +use common_state::TerrainChanges; use comp::Behavior; use specs::{Join, Read, ReadStorage, Write, WriteExpect}; use std::sync::Arc; diff --git a/server/src/sys/terrain_sync.rs b/server/src/sys/terrain_sync.rs index f085e6a025..5bd5925277 100644 --- a/server/src/sys/terrain_sync.rs +++ b/server/src/sys/terrain_sync.rs @@ -2,7 +2,7 @@ use crate::{client::Client, presence::Presence}; use common::{comp::Pos, terrain::TerrainGrid}; use common_ecs::{Job, Origin, Phase, System}; use common_net::msg::ServerGeneral; -use common_sys::state::TerrainChanges; +use common_state::TerrainChanges; use specs::{Join, Read, ReadExpect, ReadStorage}; /// This systems sends new chunks to clients as well as changes to existing diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index abf119b046..1f8ddbd08a 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -24,7 +24,7 @@ gl = ["gfx_device_gl", "gfx_gl"] hot-anim = ["anim/use-dyn-lib"] singleplayer = ["server"] simd = ["vek/platform_intrinsics"] -tracy = ["common/tracy", "common-ecs/tracy", "common-frontend/tracy", "common-net/tracy", "common-sys/tracy", "client/tracy"] +tracy = ["common/tracy", "common-ecs/tracy", "common-frontend/tracy", "common-net/tracy", "common-state/tracy", "client/tracy"] plugins = ["client/plugins"] default = ["gl", "singleplayer", "native-dialog", "plugins", "simd"] @@ -36,6 +36,7 @@ common-base = {package = "veloren-common-base", path = "../common/base"} common-ecs = {package = "veloren-common-ecs", path = "../common/ecs"} common-frontend = {package = "veloren-common-frontend", path = "../common/frontend"} common-net = {package = "veloren-common-net", path = "../common/net"} +common-state = {package = "veloren-common-state", path = "../common/state"} common-sys = {package = "veloren-common-sys", path = "../common/sys"} anim = {package = "veloren-voxygen-anim", path = "anim"} diff --git a/voxygen/src/audio/ambient.rs b/voxygen/src/audio/ambient.rs index c8dfe4c907..3ffa8b331f 100644 --- a/voxygen/src/audio/ambient.rs +++ b/voxygen/src/audio/ambient.rs @@ -8,7 +8,7 @@ use common::{ assets::{self, AssetExt, AssetHandle}, vol::ReadVol, }; -use common_sys::state::State; +use common_state::State; use serde::Deserialize; use std::time::Instant; use tracing::warn; diff --git a/voxygen/src/audio/music.rs b/voxygen/src/audio/music.rs index cedb27e25a..75154ac3d1 100644 --- a/voxygen/src/audio/music.rs +++ b/voxygen/src/audio/music.rs @@ -49,7 +49,7 @@ use common::{ assets::{self, AssetExt, AssetHandle}, terrain::{BiomeKind, SitesKind}, }; -use common_sys::state::State; +use common_state::State; use hashbrown::HashMap; use rand::{prelude::SliceRandom, thread_rng, Rng}; use serde::Deserialize; diff --git a/voxygen/src/audio/sfx/event_mapper/block/mod.rs b/voxygen/src/audio/sfx/event_mapper/block/mod.rs index ea939febaf..33dce469c6 100644 --- a/voxygen/src/audio/sfx/event_mapper/block/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/block/mod.rs @@ -14,7 +14,7 @@ use common::{ terrain::TerrainChunk, vol::{ReadVol, RectRasterableVol}, }; -use common_sys::state::State; +use common_state::State; use hashbrown::HashMap; use rand::{thread_rng, Rng}; use std::time::{Duration, Instant}; diff --git a/voxygen/src/audio/sfx/event_mapper/campfire/mod.rs b/voxygen/src/audio/sfx/event_mapper/campfire/mod.rs index 6c6613db94..cdd6f9ea68 100644 --- a/voxygen/src/audio/sfx/event_mapper/campfire/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/campfire/mod.rs @@ -13,7 +13,7 @@ use common::{ terrain::TerrainChunk, vol::ReadVol, }; -use common_sys::state::State; +use common_state::State; use hashbrown::HashMap; use specs::{Entity as EcsEntity, Join, WorldExt}; use std::time::{Duration, Instant}; diff --git a/voxygen/src/audio/sfx/event_mapper/combat/mod.rs b/voxygen/src/audio/sfx/event_mapper/combat/mod.rs index 2f3a16cc7d..c63f378b1d 100644 --- a/voxygen/src/audio/sfx/event_mapper/combat/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/combat/mod.rs @@ -17,7 +17,7 @@ use common::{ terrain::TerrainChunk, vol::ReadVol, }; -use common_sys::state::State; +use common_state::State; use hashbrown::HashMap; use specs::{Entity as EcsEntity, Join, WorldExt}; use std::time::{Duration, Instant}; diff --git a/voxygen/src/audio/sfx/event_mapper/mod.rs b/voxygen/src/audio/sfx/event_mapper/mod.rs index a577e64e45..844c472ad9 100644 --- a/voxygen/src/audio/sfx/event_mapper/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/mod.rs @@ -5,7 +5,7 @@ mod movement; use client::Client; use common::terrain::TerrainChunk; -use common_sys::state::State; +use common_state::State; use block::BlockEventMapper; use campfire::CampfireEventMapper; diff --git a/voxygen/src/audio/sfx/event_mapper/movement/mod.rs b/voxygen/src/audio/sfx/event_mapper/movement/mod.rs index 3665b8d048..9db8168574 100644 --- a/voxygen/src/audio/sfx/event_mapper/movement/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/movement/mod.rs @@ -14,7 +14,7 @@ use common::{ terrain::{BlockKind, TerrainChunk}, vol::ReadVol, }; -use common_sys::state::State; +use common_state::State; use hashbrown::HashMap; use specs::{Entity as EcsEntity, Join, WorldExt}; use std::time::{Duration, Instant}; diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index 5c937c418f..96ea404ba2 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -98,7 +98,7 @@ use common::{ outcome::Outcome, terrain::{BlockKind, TerrainChunk}, }; -use common_sys::state::State; +use common_state::State; use event_mapper::SfxEventMapper; use hashbrown::HashMap; use rand::prelude::*; diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 4baf065e78..6ef7a08958 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -39,7 +39,7 @@ use common::{ vol::RectRasterableVol, }; use common_base::span; -use common_sys::state::State; +use common_state::State; use core::{ borrow::Borrow, convert::TryFrom, diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index b300b5ffeb..eccdbf5f90 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -32,7 +32,7 @@ use common::{ vol::ReadVol, }; use common_base::span; -use common_sys::state::State; +use common_state::State; use comp::item::Reagent; use num::traits::{Float, FloatConst}; use specs::{Entity as EcsEntity, Join, WorldExt}; From 302769d086e2140822ad0d1195f876c4203eb7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Tue, 6 Apr 2021 22:22:14 +0200 Subject: [PATCH 2/4] remove authc from common::net --- Cargo.lock | 1 - common/net/Cargo.toml | 3 --- common/net/src/msg/server.rs | 5 ----- server/src/login_provider.rs | 14 +++++++++++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2553e70952..b27aa7160e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5524,7 +5524,6 @@ dependencies = [ name = "veloren-common-net" version = "0.9.0" dependencies = [ - "authc", "hashbrown", "serde", "specs", diff --git a/common/net/Cargo.toml b/common/net/Cargo.toml index 083afece47..209c2d6a18 100644 --- a/common/net/Cargo.toml +++ b/common/net/Cargo.toml @@ -21,9 +21,6 @@ tracing = { version = "0.1", default-features = false } # Data structures hashbrown = { version = "0.9", features = ["rayon", "serde", "nightly"] } -# Auth -authc = { git = "https://gitlab.com/veloren/auth.git", rev = "fb3dcbc4962b367253f8f2f92760ef44d2679c9a" } - # ECS specs = { git = "https://github.com/amethyst/specs.git", features = ["serde", "storage-event-control"], rev = "5a9b71035007be0e3574f35184acac1cd4530496" } specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "b65fb220e94f5d3c9bc30074a076149763795556" } diff --git a/common/net/src/msg/server.rs b/common/net/src/msg/server.rs index b16a10dbfa..9eabad35ca 100644 --- a/common/net/src/msg/server.rs +++ b/common/net/src/msg/server.rs @@ -1,6 +1,5 @@ use super::{world_msg::EconomyInfo, ClientType, EcsCompPacket, PingMsg}; use crate::sync; -use authc::AuthClientError; use common::{ character::{self, CharacterItem}, comp::{self, invite::InviteKind, item::MaterialStatManifest}, @@ -259,10 +258,6 @@ impl ServerMsg { } } -impl From for RegisterError { - fn from(err: AuthClientError) -> Self { Self::AuthError(err.to_string()) } -} - impl From for ServerGeneral { fn from(v: comp::ChatMsg) -> Self { ServerGeneral::ChatMsg(v) } } diff --git a/server/src/login_provider.rs b/server/src/login_provider.rs index 2028bc545a..b0b149b76d 100644 --- a/server/src/login_provider.rs +++ b/server/src/login_provider.rs @@ -167,9 +167,17 @@ impl LoginProvider { let token = AuthToken::from_str(username_or_token) .map_err(|e| RegisterError::AuthError(e.to_string()))?; // Validate token - let uuid = srv.validate(token).await?; - let username = srv.uuid_to_username(uuid).await?; - Ok((username, uuid)) + match async { + let uuid = srv.validate(token).await?; + let username = srv.uuid_to_username(uuid).await?; + let r: Result<_, authc::AuthClientError> = Ok((username, uuid)); + r + } + .await + { + Err(e) => Err(RegisterError::AuthError(e.to_string())), + Ok((username, uuid)) => Ok((username, uuid)), + } } pub fn username_to_uuid(&self, username: &str) -> Result { From e742020f42be08ae2cf9578658420725e9931be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Wed, 7 Apr 2021 01:20:26 +0200 Subject: [PATCH 3/4] include origin into system name --- common/ecs/src/system.rs | 13 ++++++++++++- common/sys/src/lib.rs | 1 + server/src/sys/mod.rs | 5 +++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/common/ecs/src/system.rs b/common/ecs/src/system.rs index e061582260..73e9ce329a 100644 --- a/common/ecs/src/system.rs +++ b/common/ecs/src/system.rs @@ -30,6 +30,17 @@ pub enum Origin { Frontend(&'static str), } +impl Origin { + fn name(&self) -> &'static str { + match self { + Origin::Common => "Common", + Origin::Client => "Client", + Origin::Server => "Server", + Origin::Frontend(name) => name, + } + } +} + #[derive(Default, Debug, Clone)] pub struct CpuTimeline { /// measurements for a System @@ -234,7 +245,7 @@ pub trait System<'a> { type SystemData: specs::SystemData<'a>; fn run(job: &mut Job, data: Self::SystemData); - fn sys_name() -> String { format!("{}_sys", Self::NAME) } + fn sys_name() -> String { format!("{}_{}_sys", Self::ORIGIN.name(), Self::NAME) } } pub fn dispatch<'a, 'b, T>(builder: &mut specs::DispatcherBuilder<'a, 'b>, dep: &[&str]) diff --git a/common/sys/src/lib.rs b/common/sys/src/lib.rs index 59bc47ff8b..4287507a5a 100644 --- a/common/sys/src/lib.rs +++ b/common/sys/src/lib.rs @@ -19,6 +19,7 @@ use common_ecs::{dispatch, System}; use specs::DispatcherBuilder; pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { + //TODO: don't run interpolation on server dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[&mount::Sys::sys_name()]); diff --git a/server/src/sys/mod.rs b/server/src/sys/mod.rs index 141a24b20f..5f1463da08 100644 --- a/server/src/sys/mod.rs +++ b/server/src/sys/mod.rs @@ -12,7 +12,7 @@ pub mod terrain_sync; pub mod waypoint; use common_ecs::{dispatch, run_now, System}; -use common_sys::{interpolation, melee, projectile}; +use common_sys::{melee, projectile}; use specs::DispatcherBuilder; use std::{ marker::PhantomData, @@ -23,7 +23,8 @@ pub type PersistenceScheduler = SysScheduler; pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) { dispatch::(dispatch_builder, &[&projectile::Sys::sys_name()]); - dispatch::(dispatch_builder, &[&interpolation::Sys::sys_name()]); + //Note: server should not depend on interpolation system + dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); dispatch::(dispatch_builder, &[]); From c221209743c6caa6c8302e838d4fd1ea46e85c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Tue, 20 Apr 2021 01:49:45 +0200 Subject: [PATCH 4/4] only have 1 Fn passed to tick fn --- client/src/lib.rs | 10 ++++++++-- common/state/src/lib.rs | 6 ++---- server/src/lib.rs | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 52f012b1df..777292495d 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1419,8 +1419,14 @@ impl Client { } // 4) Tick the client's LocalState - self.state - .tick(dt, add_local_systems, add_foreign_systems, true); + self.state.tick( + dt, + |dispatch_builder| { + add_local_systems(dispatch_builder); + add_foreign_systems(dispatch_builder); + }, + true, + ); // TODO: avoid emitting these in the first place self.state .ecs() diff --git a/common/state/src/lib.rs b/common/state/src/lib.rs index a3707c983f..fca4e14f9e 100644 --- a/common/state/src/lib.rs +++ b/common/state/src/lib.rs @@ -508,8 +508,7 @@ impl State { pub fn tick( &mut self, dt: Duration, - add_local_systems: impl Fn(&mut DispatcherBuilder), - add_foreign_systems: impl Fn(&mut DispatcherBuilder), + add_systems: impl Fn(&mut DispatcherBuilder), update_terrain_and_regions: bool, ) { span!(_guard, "tick", "State::tick"); @@ -532,8 +531,7 @@ impl State { let mut dispatch_builder = DispatcherBuilder::new().with_pool(Arc::clone(&self.thread_pool)); // TODO: Consider alternative ways to do this - add_local_systems(&mut dispatch_builder); - add_foreign_systems(&mut dispatch_builder); + add_systems(&mut dispatch_builder); // This dispatches all the systems in parallel. let mut dispatcher = dispatch_builder.build(); drop(guard); diff --git a/server/src/lib.rs b/server/src/lib.rs index 49c98eef1e..80689cce14 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -517,8 +517,8 @@ impl Server { // in sys/terrain.rs self.state.tick( dt, - add_local_systems, |dispatcher_builder| { + add_local_systems(dispatcher_builder); sys::msg::add_server_systems(dispatcher_builder); sys::add_server_systems(dispatcher_builder); #[cfg(feature = "worldgen")]