From 6a8ea8035712e6fe127c4358f660fcbaa92715f3 Mon Sep 17 00:00:00 2001 From: Forest Anderson Date: Sat, 29 Jul 2023 13:31:00 -0400 Subject: [PATCH] Added feature flag for client/server is common-state --- client/Cargo.toml | 2 +- common/state/Cargo.toml | 2 ++ common/state/src/state.rs | 72 +++++++++++++++++++++------------------ common/systems/Cargo.toml | 2 +- server/Cargo.toml | 2 +- voxygen/Cargo.toml | 2 +- 6 files changed, 45 insertions(+), 37 deletions(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index 53c6720259..ab391c5ea1 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -16,7 +16,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-state = { package = "veloren-common-state", path = "../common/state", default-features = false, features = ["client"] } common-systems = { package = "veloren-common-systems", path = "../common/systems", default-features = false } common-net = { package = "veloren-common-net", path = "../common/net" } network = { package = "veloren-network", path = "../network", features = ["compression","quic"], default-features = false } diff --git a/common/state/Cargo.toml b/common/state/Cargo.toml index 2e71eb301d..7f9cffd625 100644 --- a/common/state/Cargo.toml +++ b/common/state/Cargo.toml @@ -7,6 +7,8 @@ version = "0.10.0" [features] simd = ["vek/platform_intrinsics"] plugins = ["toml", "tar", "wasmer", "wasmer-wasix-types", "bincode", "plugin-api", "serde"] +server = [] +client = [] default = ["simd"] diff --git a/common/state/src/state.rs b/common/state/src/state.rs index 7771d54f00..813de53d03 100644 --- a/common/state/src/state.rs +++ b/common/state/src/state.rs @@ -237,32 +237,36 @@ impl State { ecs.register::(); // Register client-local components - // TODO: only register on the client - ecs.register::(); - ecs.register::>(); - ecs.register::>(); - ecs.register::>(); + #[cfg(feature = "client")] + { + ecs.register::(); + ecs.register::>(); + ecs.register::>(); + ecs.register::>(); + } // Register server-local components - // TODO: only register on the server - ecs.register::>(); - ecs.register::>(); - ecs.register::>(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); - ecs.register::(); + #[cfg(feature = "server")] + { + ecs.register::>(); + ecs.register::>(); + ecs.register::>(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + ecs.register::(); + } // Register synced resources used by the ECS. ecs.insert(TimeOfDay(0.0)); @@ -291,15 +295,17 @@ impl State { tracing::trace!(?slow_limit, "Slow Thread limit"); ecs.insert(SlowJobPool::new(slow_limit, 10_000, thread_pool)); - // TODO: only register on the server - ecs.insert(EventBus::::default()); - ecs.insert(comp::group::GroupManager::default()); - ecs.insert(RegionMap::new()); - ecs.insert(SysMetrics::default()); - ecs.insert(PhysicsMetrics::default()); - ecs.insert(Trades::default()); - ecs.insert(PlayerPhysicsSettings::default()); - ecs.insert(VolumeRiders::default()); + #[cfg(feature = "server")] + { + ecs.insert(EventBus::::default()); + ecs.insert(comp::group::GroupManager::default()); + ecs.insert(RegionMap::new()); + ecs.insert(SysMetrics::default()); + ecs.insert(PhysicsMetrics::default()); + ecs.insert(Trades::default()); + ecs.insert(PlayerPhysicsSettings::default()); + ecs.insert(VolumeRiders::default()); + } // Load plugins from asset directory #[cfg(feature = "plugins")] diff --git a/common/systems/Cargo.toml b/common/systems/Cargo.toml index 8b0d6c1852..4c289c9aa3 100644 --- a/common/systems/Cargo.toml +++ b/common/systems/Cargo.toml @@ -35,4 +35,4 @@ specs = { workspace = true, features = ["serde", "storage-event-control", "deriv [dev-dependencies] # Setup a State -common-state = { package = "veloren-common-state", path = "../state" } +common-state = { package = "veloren-common-state", path = "../state", features = ["server"] } diff --git a/server/Cargo.toml b/server/Cargo.toml index 1e46c780b4..de6c0db92e 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -19,7 +19,7 @@ default = ["worldgen", "plugins", "persistent_world", "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-state = { package = "veloren-common-state", path = "../common/state", features = ["server"] } common-systems = { package = "veloren-common-systems", path = "../common/systems" } common-net = { package = "veloren-common-net", path = "../common/net" } world = { package = "veloren-world", path = "../world" } diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index 3467736b98..1f99a4bf6f 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -47,7 +47,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-state = {package = "veloren-common-state", path = "../common/state", features = ["client"]} common-systems = {package = "veloren-common-systems", path = "../common/systems"} anim = {package = "veloren-voxygen-anim", path = "anim"}