From 609e0f23bfc8a5328b329f95741550059749f98d Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 3 Nov 2019 19:57:36 -0500 Subject: [PATCH 01/11] Stop global syncing of entity creation --- Cargo.lock | 244 ++++++++++++++------------ client/src/lib.rs | 13 +- common/Cargo.toml | 3 +- common/src/comp/projectile.rs | 1 + common/src/lib.rs | 3 + common/src/msg/ecs_packet.rs | 82 ++++++++- common/src/msg/server.rs | 4 +- common/src/state.rs | 122 ++++--------- common/src/sys/mod.rs | 11 +- common/src/sys/mount.rs | 76 ++++++++ common/src/sys/stats.rs | 1 + server/Cargo.toml | 2 + server/src/cmd.rs | 3 +- server/src/lib.rs | 39 +++-- server/src/sys/entity_sync.rs | 99 +++++++---- server/src/sys/mod.rs | 10 +- server/src/sys/sentinel.rs | 309 +++++++++++++++++++++++++++++++++ server/src/sys/subscription.rs | 11 +- 18 files changed, 771 insertions(+), 262 deletions(-) create mode 100644 common/src/sys/mount.rs create mode 100644 server/src/sys/sentinel.rs diff --git a/Cargo.lock b/Cargo.lock index 0cfd0c3b4f..040d359b08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,7 +79,7 @@ name = "approx" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -169,7 +169,7 @@ version = "0.3.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -217,7 +217,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aster 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "clang-sys 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -237,7 +237,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "clang-sys 0.28.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -368,8 +368,11 @@ dependencies = [ [[package]] name = "cast" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "cc" @@ -394,7 +397,7 @@ dependencies = [ [[package]] name = "cfg-if" -version = "0.1.10" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -417,12 +420,11 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -600,7 +602,7 @@ dependencies = [ "objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "objc_id 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "smithay-clipboard 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "smithay-clipboard 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "wayland-client 0.23.6 (registry+https://github.com/rust-lang/crates.io-index)", "x11-clipboard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -658,7 +660,7 @@ dependencies = [ "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "stdweb 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -668,7 +670,7 @@ name = "crc32fast" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -677,20 +679,20 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "criterion-plot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xoshiro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", "tinytemplate 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -700,8 +702,8 @@ name = "criterion-plot" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -720,7 +722,7 @@ name = "crossbeam" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -772,7 +774,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -785,7 +787,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -798,7 +800,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -811,7 +813,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -826,6 +828,14 @@ dependencies = [ "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-queue" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-utils" version = "0.5.0" @@ -836,7 +846,7 @@ name = "crossbeam-utils" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -846,7 +856,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -903,7 +913,7 @@ name = "directories" version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -922,7 +932,7 @@ name = "dirs-sys" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1009,7 +1019,7 @@ name = "euc" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "vek 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1018,7 +1028,7 @@ version = "0.19.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "euclid_macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1056,7 +1066,7 @@ name = "fern" version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1066,7 +1076,7 @@ name = "filetime" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1215,7 +1225,7 @@ name = "getrandom" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1532,7 +1542,7 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atom 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1560,7 +1570,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1573,8 +1583,8 @@ dependencies = [ "jpeg-decoder 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", "num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", - "png 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "png 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", "scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "tiff 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1628,7 +1638,7 @@ dependencies = [ [[package]] name = "itertools" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1645,7 +1655,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1716,7 +1726,7 @@ name = "line_drawing" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1754,7 +1764,7 @@ name = "log" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1859,7 +1869,7 @@ name = "minifb" version = "0.13.0" source = "git+https://github.com/emoon/rust_minifb.git#bac71b297920c1f7ab5d6e384673d3ae5cc7d46d" dependencies = [ - "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", "orbclient 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1886,9 +1896,10 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.19" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1908,7 +1919,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.20 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1961,7 +1972,7 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1973,7 +1984,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2028,7 +2039,7 @@ dependencies = [ "inotify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.20 (registry+https://github.com/rust-lang/crates.io-index)", "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2041,7 +2052,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2054,7 +2065,7 @@ dependencies = [ "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", "num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2064,7 +2075,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2073,7 +2084,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2092,7 +2103,7 @@ version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2102,7 +2113,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2113,7 +2124,7 @@ dependencies = [ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "num-bigint 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2121,12 +2132,12 @@ name = "num-traits" version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2189,7 +2200,7 @@ name = "ordered-float" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2297,7 +2308,7 @@ name = "parking_lot_core" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2395,7 +2406,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "png" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2422,7 +2433,7 @@ name = "pretty_env_logger" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2466,7 +2477,7 @@ name = "prometheus" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 2.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2723,22 +2734,22 @@ dependencies = [ [[package]] name = "rayon" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon-core 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rayon-core" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2854,7 +2865,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "brotli2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "deflate 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", "filetime 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "multipart 0.15.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2862,7 +2873,7 @@ dependencies = [ "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2912,23 +2923,23 @@ name = "rusttype" version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rusttype 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rusttype 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rusttype" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "stb_truetype 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "stb_truetype 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2990,7 +3001,7 @@ name = "sdl2-sys" version = "0.32.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3027,7 +3038,7 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.41" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3062,7 +3073,7 @@ dependencies = [ "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "mopa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3109,6 +3120,11 @@ dependencies = [ "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "smallvec" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "smithay-client-toolkit" version = "0.4.6" @@ -3142,7 +3158,7 @@ dependencies = [ [[package]] name = "smithay-clipboard" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3161,7 +3177,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "mopa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "nonzero_signed 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "shred 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "shred-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3181,7 +3197,6 @@ dependencies = [ [[package]] name = "sphynx" version = "0.1.0" -source = "git+https://gitlab.com/veloren/sphynx.git?rev=ac4adf54d181339a789907acd27f61fe81daa455#ac4adf54d181339a789907acd27f61fe81daa455" dependencies = [ "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3206,7 +3221,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "stb_truetype" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3383,7 +3398,7 @@ dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3402,7 +3417,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ascii 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "chunked_transfer 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3414,7 +3429,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3461,10 +3476,10 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.9" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3519,7 +3534,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "vek" -version = "0.9.10" +version = "0.9.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3551,7 +3566,7 @@ dependencies = [ "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", "uvth 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "vek 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "veloren-common 0.4.0", ] @@ -3571,27 +3586,27 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "lz4-compress 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.20 (registry+https://github.com/rust-lang/crates.io-index)", "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "notify 5.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git)", - "sphynx 0.1.0 (git+https://gitlab.com/veloren/sphynx.git?rev=ac4adf54d181339a789907acd27f61fe81daa455)", - "vek 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "sphynx 0.1.0", + "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "veloren-server" version = "0.4.0" dependencies = [ - "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "hibitset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3606,10 +3621,12 @@ dependencies = [ "scan_fmt 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "shred 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "shred-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git)", "uvth 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "vek 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "veloren-common 0.4.0", "veloren-world 0.4.0", ] @@ -3629,7 +3646,7 @@ name = "veloren-voxygen" version = "0.4.0" dependencies = [ "backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "conrod_core 0.63.0 (git+https://gitlab.com/veloren/conrod.git)", "conrod_winit 0.63.0 (git+https://gitlab.com/veloren/conrod.git)", "cpal 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3660,7 +3677,7 @@ dependencies = [ "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", - "vek 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "veloren-client 0.4.0", "veloren-common 0.4.0", "veloren-server 0.4.0", @@ -3683,11 +3700,11 @@ dependencies = [ "ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "roots 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", - "vek 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", + "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "veloren-common 0.4.0", ] @@ -3995,14 +4012,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum c_vec 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f8a318911dce53b5f1ca6539c44f5342c632269f0fa7ea3e35f32458c27a7c30" "checksum cairo-rs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a110f269c2fd382df5fe8bd46dfa5f1b83608aa717fecb6e7a28c08c202f0e13" "checksum cairo-sys-rs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0395175ecba60accac076a02c31d143b9dcd9d5eb5316d7163a3273803b765c7" -"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" +"checksum cast 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" "checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8" "checksum cexpr 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42aac45e9567d97474a834efdee3081b3c942b2205be932092f53354ce503d6c" "checksum cexpr 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fce5b5fb86b0c57c20c834c1b412fd09c77c8a59b9473f86272709e78874cd1d" -"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum cgl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "55e7ec0b74fe5897894cbc207092c577e87c52f8a59e8ca8d97ef37551f60a49" "checksum chashmap 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ff41a3c2c1e39921b9003de14bf0439c7b63a9039637c291e1a64925d8ddfa45" -"checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68" +"checksum chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01" "checksum chunked_transfer 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "498d20a7aaf62625b9bf26e637cf7736417cde1d0c99f1d04d1170229a85cf87" "checksum clang-sys 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "611ec2e3a7623afd8a8c0d027887b6b55759d894abbf5fe11b9dc11b50d5b49a" "checksum clang-sys 0.28.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81de550971c976f176130da4b2978d3b524eaa0fd9ac31f3ceb5ae1231fb4853" @@ -4042,6 +4059,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9" "checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" +"checksum crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfd6515864a82d2f877b42813d4553292c6659498c9a2aa31bab5a15243c2700" "checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015" "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" "checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" @@ -4127,7 +4145,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0" "checksum instant 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6c346c299e3fe8ef94dc10c2c0253d858a69aac1245157a3bf4125915d528caf" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -"checksum itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "87fa75c9dea7b07be3138c49abbb83fd4bea199b5cdc76f9804458edc5da0d6e" +"checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum jpeg-decoder 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "c1aae18ffeeae409c6622c3b6a7ee49792a7e5a062eea1b135fbb74e301792ba" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" @@ -4161,7 +4179,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum minifb 0.13.0 (git+https://github.com/emoon/rust_minifb.git)" = "" "checksum minimp3 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "542e9bed56860c5070a09939eee0e2df6f8f73f60304ddf56d620947e7017239" "checksum minimp3-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c109ae05c00ad6e3a53fab101e2f234545bdd010f0fffd399355efaf70817817" -"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" +"checksum mio 0.6.20 (registry+https://github.com/rust-lang/crates.io-index)" = "72f4261ee7ab03cd36dc99eea4db8be6e83e4164da470e0c84f6726d6c605855" "checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum mopa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a785740271256c230f57462d3b83e52f998433a7062fc18f96d5999474a9f915" @@ -4184,7 +4202,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-iter 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "76bd5272412d173d6bf9afdf98db8612bbabc9a7a830b7bfc9c188911716132e" "checksum num-rational 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2885278d5fe2adc2f75ced642d52d879bffaceb5a2e0b1d4309ffdfb239b454" "checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" -"checksum num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "443c53b3c3531dfcbfa499d8893944db78474ad7a1d87fa2d94d1a2231693ac6" +"checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4" "checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" "checksum objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" "checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" @@ -4215,7 +4233,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum piston-viewport 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d96dd995f7dabe6d57cda668ec0fda39d6fe6e1e0b23f772582f383f2013611" "checksum pistoncore-input 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c612ce242c7bac8e96426a0ca34275fd980af440f0cca7c6c0e840ef8a4052f" "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" -"checksum png 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8422b27bb2c013dd97b9aef69e161ce262236f49aaf46a0489011c8ff0264602" +"checksum png 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f00ec9242f8e01119e83117dbadf34c5228ac2f1c4ddcd92bffa340d52291de" "checksum portpicker 0.1.0 (git+https://github.com/wusyong/portpicker-rs?branch=fix_ipv6)" = "" "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" "checksum pretty_env_logger 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "717ee476b1690853d222af4634056d830b5197ffd747726a9a1eee6da9f49074" @@ -4251,8 +4269,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" "checksum rand_xoshiro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e18c91676f670f6f0312764c759405f13afb98d5d73819840cf72a518487bff" "checksum raw-window-handle 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9db80d08d3ed847ce4fb3def46de0af4bfb6155bd09bd6eaf28b5ac72541c1f1" -"checksum rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83a27732a533a1be0a0035a111fe76db89ad312f6f0347004c220c57f209a123" -"checksum rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "98dcf634205083b17d0861252431eb2acbfb698ab7478a2d20de07954f47ec7b" +"checksum rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43739f8831493b276363637423d3622d4bd6394ab6f0a9c4a552e208aeb7fddd" +"checksum rayon-core 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8bf17de6f23b05473c437eb958b9c850bfc8af0961fe17b4cc92d5a627b4791" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecedbca3bf205f8d8f5c2b44d83cd0690e39ee84b951ed649e9f1841132b66d" @@ -4272,7 +4290,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rusttype 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "310942406a39981bed7e12b09182a221a29e0990f3e7e0c971f131922ed135d5" -"checksum rusttype 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6fa38506b5cbf2fb67f915e2725cb5012f1b9a785b0ab55c4733acda5f6554ef" +"checksum rusttype 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "14a911032fb5791ccbeec9f28fdcb9bf0983b81f227bafdfd227c658d0731c8a" "checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" "checksum safemem 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" @@ -4286,7 +4304,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4b39bd9b0b087684013a792c59e3e07a46a01d2322518d8a1104641a0b1be0" "checksum serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "ca13fc1a832f793322228923fbb3aba9f3f44444898f835d31ad1b74fa0a2bf8" -"checksum serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2" +"checksum serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)" = "1a3351dcbc1f067e2c92ab7c3c1f288ad1a4cffc470b5aaddb4c2e0a3ae80043" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" "checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" "checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" @@ -4297,16 +4315,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum slice-deque 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ffddf594f5f597f63533d897427a570dbaa9feabaaa06595b74b71b7014507d7" "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" +"checksum smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecf3b85f68e8abaa7555aa5abdb1153079387e60b718283d732f03897fcfc86" "checksum smithay-client-toolkit 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2ccb8c57049b2a34d2cc2b203fa785020ba0129d31920ef0d317430adaf748fa" "checksum smithay-client-toolkit 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "93960e8975909fcb14cc755de93af2149d8b8f4eb368315537d40cfd0f324054" -"checksum smithay-clipboard 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "315c3f4417d365483dcbaed9ba6488d9f176e43d83f3e1d581050f1c93869e3d" +"checksum smithay-clipboard 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9667a262ef7a9ff1c55a7e665cd3d36f9bc2809f94167b1fb3fc31423a83f8c0" "checksum specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)" = "de65613ada4338aa7ba71eca60eca24c60483433eec0077bc4f33cfc31f4bdf0" "checksum specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git)" = "" -"checksum sphynx 0.1.0 (git+https://gitlab.com/veloren/sphynx.git?rev=ac4adf54d181339a789907acd27f61fe81daa455)" = "" "checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" -"checksum stb_truetype 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "824210d6fb52cbc3ad2545270ead6860c7311aa5450642b078da4515937b6f7a" +"checksum stb_truetype 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f77b6b07e862c66a9f3e62a07588fee67cd90a9135a2b942409f195507b4fb51" "checksum stdweb 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum sum_type 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "da5b4a0c9f3c7c8e891e445a7c776627e208e8bba23ab680798066dd283e6a15" @@ -4336,7 +4354,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ucd-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa9b3b49edd3468c0e6565d85783f51af95212b6fa3986a5500954f00b460874" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "09c8070a9942f5e7cfccd93f490fdebd230ee3c3c9f107cb25bad5351ef671cf" +"checksum unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf" "checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" @@ -4345,7 +4363,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum utf8-ranges 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba" "checksum uvth 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e59a167890d173eb0fcd7a1b99b84dc05c521ae8d76599130b8e19bef287abbf" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -"checksum vek 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2bb887880c4eb92359ae9abea055ddf60bfade4603bf9534f3c62c2707cb306b" +"checksum vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)" = "1eb3ca8ea588deba055424cc1a79a830428b2f6c270b8d8f91946f660fa4d8ee" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e" diff --git a/client/src/lib.rs b/client/src/lib.rs index ce8fb7182d..b97f7f31a8 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -14,6 +14,7 @@ use common::{ ServerError, ServerInfo, ServerMsg, MAX_BYTES_CHAT_MSG, }, net::PostBox, + sphynx::WorldSyncExt, state::{State, Uid}, terrain::{block::Block, TerrainChunk, TerrainChunkSize}, vol::RectVolSize, @@ -94,7 +95,8 @@ impl Client { ); } - let state = State::from_state_package(ecs_state); + let mut state = State::default(); + state.ecs_mut().apply_state_package(ecs_state); let entity = state .ecs() .entity_from_uid(entity_uid) @@ -550,7 +552,14 @@ impl Client { } } ServerMsg::EcsSync(sync_package) => { - self.state.ecs_mut().sync_with_package(sync_package) + self.state.ecs_mut().apply_sync_package(sync_package) + } + ServerMsg::EcsResSync(res_sync_package) => self + .state + .ecs_mut() + .apply_res_sync_package(res_sync_package), + ServerMsg::CreateEntity(entity_package) => { + self.state.ecs_mut().apply_entity_package(entity_package) } ServerMsg::DeleteEntity(entity) => { if let Some(entity) = self.state.ecs().entity_from_uid(entity) { diff --git a/common/Cargo.toml b/common/Cargo.toml index 5e4dcbc571..e8a7c0ed41 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -5,7 +5,8 @@ authors = ["Joshua Barretto ", "Maciej Ćwięka , pub hit_wall: Vec, pub hit_entity: Vec, diff --git a/common/src/lib.rs b/common/src/lib.rs index eab693848d..0fbe6c554d 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -7,6 +7,9 @@ extern crate serde_derive; #[macro_use] extern crate log; +// Re-export sphynx +pub use sphynx; + pub mod assets; pub mod astar; pub mod clock; diff --git a/common/src/msg/ecs_packet.rs b/common/src/msg/ecs_packet.rs index 70f24e228c..e6ad0b6149 100644 --- a/common/src/msg/ecs_packet.rs +++ b/common/src/msg/ecs_packet.rs @@ -1,20 +1,28 @@ use crate::{comp, state}; use serde_derive::{Deserialize, Serialize}; +use sphynx::sum_type; use std::marker::PhantomData; // Automatically derive From for EcsResPacket // for each variant EcsResPacket::T(T). -sphynx::sum_type! { +sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsResPacket { Time(state::Time), TimeOfDay(state::TimeOfDay), } } -impl sphynx::ResPacket for EcsResPacket {} +impl sphynx::ResPacket for EcsResPacket { + fn apply(self, world: &specs::World) { + match self { + EcsResPacket::Time(time) => sphynx::handle_res_update(time, world), + EcsResPacket::TimeOfDay(time_of_day) => sphynx::handle_res_update(time_of_day, world), + } + } +} // Automatically derive From for EcsCompPacket // for each variant EcsCompPacket::T(T.) -sphynx::sum_type! { +sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsCompPacket { Pos(comp::Pos), @@ -37,7 +45,7 @@ sphynx::sum_type! { } // Automatically derive From for EcsCompPhantom // for each variant EcsCompPhantom::T(PhantomData). -sphynx::sum_type! { +sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsCompPhantom { Pos(PhantomData), @@ -60,4 +68,70 @@ sphynx::sum_type! { } impl sphynx::CompPacket for EcsCompPacket { type Phantom = EcsCompPhantom; + fn apply_insert(self, entity: specs::Entity, world: &specs::World) { + match self { + EcsCompPacket::Pos(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Vel(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Ori(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Body(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Player(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::CanBuild(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Stats(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::LightEmitter(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Item(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Scale(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::MountState(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Mounting(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Mass(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Projectile(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Gravity(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Sticky(comp) => sphynx::handle_insert(comp, entity, world), + } + } + fn apply_modify(self, entity: specs::Entity, world: &specs::World) { + match self { + EcsCompPacket::Pos(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Vel(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Ori(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Body(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Player(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::CanBuild(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Stats(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::LightEmitter(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Item(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Scale(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::MountState(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Mounting(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Mass(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Projectile(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Gravity(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Sticky(comp) => sphynx::handle_modify(comp, entity, world), + } + } + fn apply_remove(phantom: Self::Phantom, entity: specs::Entity, world: &specs::World) { + match phantom { + EcsCompPhantom::Pos(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Vel(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Ori(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Body(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Player(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::CanBuild(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Stats(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::LightEmitter(_) => { + sphynx::handle_remove::(entity, world) + } + EcsCompPhantom::Item(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Scale(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::MountState(_) => { + sphynx::handle_remove::(entity, world) + } + EcsCompPhantom::Mounting(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Mass(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Projectile(_) => { + sphynx::handle_remove::(entity, world) + } + EcsCompPhantom::Gravity(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Sticky(_) => sphynx::handle_remove::(entity, world), + } + } } diff --git a/common/src/msg/server.rs b/common/src/msg/server.rs index cbf1d9ac8a..dc8ccd8c1c 100644 --- a/common/src/msg/server.rs +++ b/common/src/msg/server.rs @@ -40,7 +40,9 @@ pub enum ServerMsg { message: String, }, SetPlayerEntity(u64), - EcsSync(sphynx::SyncPackage), + EcsSync(sphynx::SyncPackage), + EcsResSync(sphynx::ResSyncPackage), + CreateEntity(sphynx::EntityPackage), DeleteEntity(u64), EntityPos { entity: u64, diff --git a/common/src/state.rs b/common/src/state.rs index 9a3b5cd9ee..1d62d3419b 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -4,7 +4,6 @@ pub use sphynx::Uid; use crate::{ comp, event::{EventBus, LocalEvent, ServerEvent, SfxEventItem}, - msg::{EcsCompPacket, EcsResPacket}, region::RegionMap, sys, terrain::{Block, TerrainChunk, TerrainGrid}, @@ -14,12 +13,11 @@ use hashbrown::{HashMap, HashSet}; use rayon::{ThreadPool, ThreadPoolBuilder}; use serde_derive::{Deserialize, Serialize}; use specs::{ - saveload::Marker, shred::{Fetch, FetchMut}, storage::{MaskedStorage as EcsMaskedStorage, Storage as EcsStorage}, - Component, DispatcherBuilder, Entity as EcsEntity, Join, + Component, DispatcherBuilder, Entity as EcsEntity, }; -use sphynx; +use sphynx::WorldSyncExt; use std::{sync::Arc, time::Duration}; use vek::*; @@ -89,7 +87,7 @@ impl TerrainChanges { /// A type used to represent game state stored on both the client and the server. This includes /// things like entity components, terrain data, and global states like weather, time of day, etc. pub struct State { - ecs: sphynx::World, + ecs: specs::World, // Avoid lifetime annotation by storing a thread pool instead of the whole dispatcher thread_pool: Arc, } @@ -98,15 +96,15 @@ impl Default for State { /// Create a new `State`. fn default() -> Self { Self { - ecs: sphynx::World::new(specs::World::new(), Self::setup_sphynx_world), + ecs: Self::setup_ecs_world(), thread_pool: Arc::new(ThreadPoolBuilder::new().build().unwrap()), } } } impl State { - /// Create a new `State` from an ECS state package. - pub fn from_state_package( + // Create a new `State` from an ECS state package. + /*pub fn from_state_package( state_package: sphynx::StatePackage, ) -> Self { Self { @@ -117,25 +115,28 @@ impl State { ), thread_pool: Arc::new(ThreadPoolBuilder::new().build().unwrap()), } - } + }*/ - // Create a new Sphynx ECS world. + /// Creates ecs world and registers all the common components and resources // TODO: Split up registering into server and client (e.g. move EventBus to the server) - fn setup_sphynx_world(ecs: &mut sphynx::World) { + fn setup_ecs_world() -> specs::World { + let mut ecs = specs::World::new(); + // Uids for sync + ecs.register_sync_marker(); // Register server -> all clients synced components. - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); - ecs.register_synced::(); + 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 components send from clients -> server ecs.register::(); @@ -151,6 +152,7 @@ impl State { ecs.register::(); // Register server-local components + // TODO: only register on the server ecs.register::>(); ecs.register::>(); ecs.register::>(); @@ -163,10 +165,10 @@ impl State { ecs.register::(); // Register synced resources used by the ECS. - ecs.insert_synced(TimeOfDay(0.0)); + ecs.add_resource(Time(0.0)); + ecs.add_resource(TimeOfDay(0.0)); // Register unsynced resources used by the ECS. - ecs.add_resource(Time(0.0)); ecs.add_resource(DeltaTime(0.0)); ecs.add_resource(TerrainGrid::new().unwrap()); ecs.add_resource(BlockChange::default()); @@ -175,6 +177,8 @@ impl State { ecs.add_resource(EventBus::::default()); ecs.add_resource(EventBus::::default()); ecs.add_resource(RegionMap::new()); + + ecs } /// Register a component with the state's ECS. @@ -207,12 +211,12 @@ impl State { } /// Get a reference to the internal ECS world. - pub fn ecs(&self) -> &sphynx::World { + pub fn ecs(&self) -> &specs::World { &self.ecs } /// Get a mutable reference to the internal ECS world. - pub fn ecs_mut(&mut self) -> &mut sphynx::World { + pub fn ecs_mut(&mut self) -> &mut specs::World { &mut self.ecs } @@ -319,68 +323,6 @@ impl State { // Beyond a delta time of MAX_DELTA_TIME, start lagging to avoid skipping important physics events. self.ecs.write_resource::().0 = dt.as_secs_f32().min(MAX_DELTA_TIME); - // Mounted entities. We handle this here because we need access to the Uid registry and I - // forgot how to access that within a system. Anyhow, here goes. - for (entity, mount_state) in ( - &self.ecs.entities(), - &mut self.ecs.write_storage::(), - ) - .join() - { - match mount_state { - comp::MountState::Unmounted => {} - comp::MountState::MountedBy(mounter) => { - if let Some((controller, mounter)) = - self.ecs.entity_from_uid(mounter.id()).and_then(|mounter| { - self.ecs - .read_storage::() - .get(mounter) - .cloned() - .map(|x| (x, mounter)) - }) - { - let pos = self.ecs.read_storage::().get(entity).copied(); - let ori = self.ecs.read_storage::().get(entity).copied(); - let vel = self.ecs.read_storage::().get(entity).copied(); - if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) { - let _ = self - .ecs - .write_storage() - .insert(mounter, comp::Pos(pos.0 + Vec3::unit_z() * 1.0)); - let _ = self.ecs.write_storage().insert(mounter, ori); - let _ = self.ecs.write_storage().insert(mounter, vel); - } - let _ = self - .ecs - .write_storage::() - .insert(entity, controller); - } else { - *mount_state = comp::MountState::Unmounted; - } - } - } - } - - let mut to_unmount = Vec::new(); - for (entity, comp::Mounting(mountee)) in ( - &self.ecs.entities(), - &self.ecs.read_storage::(), - ) - .join() - { - if self - .ecs - .entity_from_uid(mountee.id()) - .filter(|mountee| self.ecs.is_alive(*mountee)) - .is_none() - { - to_unmount.push(entity); - } - } - for entity in to_unmount { - self.ecs.write_storage::().remove(entity); - } - // Run RegionMap tick to update entity region occupancy self.ecs.write_resource::().tick( self.ecs.read_storage::(), diff --git a/common/src/sys/mod.rs b/common/src/sys/mod.rs index f9f154c82d..8006c20abc 100644 --- a/common/src/sys/mod.rs +++ b/common/src/sys/mod.rs @@ -2,6 +2,7 @@ pub mod agent; mod cleanup; pub mod combat; pub mod controller; +mod mount; pub mod movement; pub mod phys; mod projectile; @@ -13,6 +14,7 @@ use specs::DispatcherBuilder; // System names const AGENT_SYS: &str = "agent_sys"; const CONTROLLER_SYS: &str = "controller_sys"; +const MOUNT_SYS: &str = "mount_sys"; const PHYS_SYS: &str = "phys_sys"; const MOVEMENT_SYS: &str = "movement_sys"; const PROJECTILE_SYS: &str = "projectile_sys"; @@ -23,13 +25,20 @@ const CLEANUP_SYS: &str = "cleanup_sys"; pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) { dispatch_builder.add(agent::Sys, AGENT_SYS, &[]); dispatch_builder.add(controller::Sys, CONTROLLER_SYS, &[AGENT_SYS]); + dispatch_builder.add(mount::Sys, MOUNT_SYS, &[CONTROLLER_SYS]); dispatch_builder.add(movement::Sys, MOVEMENT_SYS, &[]); dispatch_builder.add(combat::Sys, COMBAT_SYS, &[CONTROLLER_SYS]); dispatch_builder.add(stats::Sys, STATS_SYS, &[COMBAT_SYS]); dispatch_builder.add( phys::Sys, PHYS_SYS, - &[CONTROLLER_SYS, MOVEMENT_SYS, COMBAT_SYS, STATS_SYS], + &[ + CONTROLLER_SYS, + MOUNT_SYS, + MOVEMENT_SYS, + COMBAT_SYS, + STATS_SYS, + ], ); dispatch_builder.add(projectile::Sys, PROJECTILE_SYS, &[PHYS_SYS]); dispatch_builder.add(cleanup::Sys, CLEANUP_SYS, &[PHYS_SYS]); diff --git a/common/src/sys/mount.rs b/common/src/sys/mount.rs new file mode 100644 index 0000000000..0d992f57b4 --- /dev/null +++ b/common/src/sys/mount.rs @@ -0,0 +1,76 @@ +use crate::comp::{Controller, MountState, Mounting, Ori, Pos, Vel}; +use specs::{ + saveload::{Marker, MarkerAllocator}, + Entities, Join, Read, System, WriteStorage, +}; +use sphynx::UidAllocator; +use vek::*; + +/// This system is responsible for controlling mounts +pub struct Sys; +impl<'a> System<'a> for Sys { + type SystemData = ( + Read<'a, UidAllocator>, + Entities<'a>, + WriteStorage<'a, Controller>, + WriteStorage<'a, MountState>, + WriteStorage<'a, Mounting>, + WriteStorage<'a, Pos>, + WriteStorage<'a, Vel>, + WriteStorage<'a, Ori>, + ); + + fn run( + &mut self, + ( + uid_allocator, + entities, + mut controllers, + mut mount_state, + mut mountings, + mut positions, + mut velocities, + mut orientations, + ): Self::SystemData, + ) { + // Mounted entities. + for (entity, mut mount_states) in (&entities, &mut mount_state.restrict_mut()).join() { + match mount_states.get_unchecked() { + MountState::Unmounted => {} + MountState::MountedBy(mounter_uid) => { + if let Some((controller, mounter)) = uid_allocator + .retrieve_entity_internal(mounter_uid.id()) + .and_then(|mounter| controllers.get(mounter).cloned().map(|x| (x, mounter))) + { + // TODO: consider joining on these? (remember we can use .maybe()) + let pos = positions.get(entity).copied(); + let ori = orientations.get(entity).copied(); + let vel = velocities.get(entity).copied(); + if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) { + let _ = positions.insert(mounter, Pos(pos.0 + Vec3::unit_z() * 1.0)); + let _ = orientations.insert(mounter, ori); + let _ = velocities.insert(mounter, vel); + } + let _ = controllers.insert(entity, controller); + } else { + *(mount_states.get_mut_unchecked()) = MountState::Unmounted; + } + } + } + } + + let mut to_unmount = Vec::new(); + for (entity, Mounting(mountee_uid)) in (&entities, &mountings).join() { + if uid_allocator + .retrieve_entity_internal(mountee_uid.id()) + .filter(|mountee| entities.is_alive(*mountee)) + .is_none() + { + to_unmount.push(entity); + } + } + for entity in to_unmount { + mountings.remove(entity); + } + } +} diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index 448bb375a0..5de672a84b 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -23,6 +23,7 @@ impl<'a> System<'a> for Sys { ) { let mut server_event_emitter = server_event_bus.emitter(); + // Mutates all stats every tick causing the server to resend this component for every entity every tick for (entity, mut stat) in (&entities, &mut stats).join() { if stat.should_die() && !stat.is_dead { server_event_emitter.emit(ServerEvent::Destroy { diff --git a/server/Cargo.toml b/server/Cargo.toml index c379db4c90..3bb82317f0 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -12,6 +12,8 @@ specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git" } log = "0.4.8" specs = "0.14.2" +shred-derive = "0.5.0" +shred = "0.7.0" vek = "0.9.9" uvth = "3.1.1" lazy_static = "1.4.0" diff --git a/server/src/cmd.rs b/server/src/cmd.rs index a38a1126fe..df4b46882e 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -10,6 +10,7 @@ use common::{ msg::ServerMsg, npc::{get_npc_name, NpcKind}, pathfinding::WorldPath, + sphynx::WorldSyncExt, state::TimeOfDay, terrain::{Block, BlockKind, TerrainChunkSize}, vol::RectVolSize, @@ -1117,7 +1118,7 @@ fn handle_remove_lights( let size = to_delete.len(); for entity in to_delete { - let _ = server.state.ecs_mut().delete_entity_synced(entity); + let _ = server.state.ecs_mut().delete_entity(entity); } server.notify_client( diff --git a/server/src/lib.rs b/server/src/lib.rs index 41eaeb78d6..1e0034b621 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -19,6 +19,7 @@ use crate::{ chunk_generator::ChunkGenerator, client::{Client, RegionSubscription}, cmd::CHAT_COMMANDS, + sys::sentinel::{TrackedComps, TrackedResources}, }; use common::{ assets, comp, @@ -26,6 +27,7 @@ use common::{ event::{EventBus, ServerEvent}, msg::{ClientMsg, ClientState, ServerError, ServerInfo, ServerMsg}, net::PostOffice, + sphynx::WorldSyncExt, state::{BlockChange, State, TimeOfDay, Uid}, terrain::{block::Block, TerrainChunkSize, TerrainGrid}, vol::{ReadVol, RectVolSize, Vox}, @@ -33,7 +35,9 @@ use common::{ use log::debug; use metrics::ServerMetrics; use rand::Rng; -use specs::{join::Join, world::EntityBuilder as EcsEntityBuilder, Builder, Entity as EcsEntity}; +use specs::{ + join::Join, world::EntityBuilder as EcsEntityBuilder, Builder, Entity as EcsEntity, SystemData, +}; use std::{ i32, sync::Arc, @@ -90,11 +94,12 @@ impl Server { state.ecs_mut().add_resource(AuthProvider::new()); state.ecs_mut().add_resource(Tick(0)); state.ecs_mut().add_resource(ChunkGenerator::new()); - // System timers + // System timers for performance monitoring state .ecs_mut() .add_resource(sys::EntitySyncTimer::default()); state.ecs_mut().add_resource(sys::MessageTimer::default()); + state.ecs_mut().add_resource(sys::SentinelTimer::default()); state .ecs_mut() .add_resource(sys::SubscriptionTimer::default()); @@ -158,6 +163,9 @@ impl Server { // Set starting time for the server. state.ecs_mut().write_resource::().0 = settings.start_time; + // Register trackers + sys::sentinel::register_trackers(&mut state.ecs_mut()); + let this = Self { state, world: Arc::new(world), @@ -449,7 +457,7 @@ impl Server { }; if let Some(item_entity) = item_entity { - let _ = state.ecs_mut().delete_entity_synced(item_entity); + let _ = state.ecs_mut().delete_entity(item_entity); } state.write_component(entity, comp::InventoryUpdate); @@ -605,8 +613,8 @@ impl Server { { let not_mounting_yet = if let Some(comp::MountState::Unmounted) = state .ecs() - .write_storage::() - .get_mut(mountee) + .read_storage::() + .get(mountee) .cloned() { true @@ -738,7 +746,7 @@ impl Server { } ServerEvent::ClientDisconnect(entity) => { - if let Err(err) = state.ecs_mut().delete_entity_synced(entity) { + if let Err(err) = state.ecs_mut().delete_entity(entity) { debug!("Failed to delete disconnected client: {:?}", err); } @@ -756,7 +764,7 @@ impl Server { // TODO: is this needed? if let Some(entity) = todo_remove { - let _ = state.ecs_mut().delete_entity_synced(entity); + let _ = state.ecs_mut().delete_entity(entity); } } @@ -832,11 +840,6 @@ impl Server { let before_tick_6 = Instant::now(); // 6) Synchronise clients with the new state of the world. - // TODO: Remove sphynx - // Sync 'logical' state using Sphynx. - let sync_package = self.state.ecs_mut().next_sync_package(); - self.state - .notify_registered_clients(ServerMsg::EcsSync(sync_package)); // Remove NPCs that are outside the view distances of all players // This is done by removing NPCs in unloaded chunks @@ -853,7 +856,7 @@ impl Server { .collect::>() }; for entity in to_delete { - let _ = self.state.ecs_mut().delete_entity_synced(entity); + let _ = self.state.ecs_mut().delete_entity(entity); } let before_tick_7 = Instant::now(); @@ -864,6 +867,7 @@ impl Server { .read_resource::() .nanos as i64; let message_nanos = self.state.ecs().read_resource::().nanos as i64; + let sentinel_nanos = self.state.ecs().read_resource::().nanos as i64; let subscription_nanos = self .state .ecs() @@ -877,6 +881,7 @@ impl Server { let terrain_nanos = self.state.ecs().read_resource::().nanos as i64; let total_sys_nanos = entity_sync_nanos + message_nanos + + sentinel_nanos + subscription_nanos + terrain_sync_nanos + terrain_nanos; @@ -979,7 +984,13 @@ impl Server { .get_mut(entity) .unwrap() .notify(ServerMsg::InitialSync { - ecs_state: self.state.ecs().gen_state_package(), + ecs_state: TrackedResources::fetch(&self.state.ecs().res) + .state_package() + // Send client their entity + .with_entity( + TrackedComps::fetch(&self.state.ecs().res) + .create_entity_package(entity), + ), entity_uid: self.state.ecs().uid_from_entity(entity).unwrap().into(), // Can't fail. server_info: self.server_info.clone(), // world_map: (WORLD_SIZE/*, self.world.sim().get_map()*/), diff --git a/server/src/sys/entity_sync.rs b/server/src/sys/entity_sync.rs index a0d79fcb91..7d9dc40307 100644 --- a/server/src/sys/entity_sync.rs +++ b/server/src/sys/entity_sync.rs @@ -1,4 +1,7 @@ -use super::SysTimer; +use super::{ + sentinel::{ReadTrackers, TrackedComps, TrackedResources}, + SysTimer, +}; use crate::{ client::{Client, RegionSubscription}, Tick, @@ -35,6 +38,9 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, Client>, WriteStorage<'a, ForceUpdate>, WriteStorage<'a, InventoryUpdate>, + TrackedComps<'a>, + ReadTrackers<'a>, + TrackedResources<'a>, ); fn run( @@ -58,6 +64,9 @@ impl<'a> System<'a> for Sys { mut clients, mut force_updates, mut inventory_updates, + tracked_comps, + read_trackers, + tracked_resources, ): Self::SystemData, ) { timer.start(); @@ -105,14 +114,18 @@ impl<'a> System<'a> for Sys { }) }) { + let create_msg = ServerMsg::CreateEntity( + tracked_comps.create_entity_package(entity), + ); for (client, regions, client_entity, _) in &mut subscribers { if maybe_key .as_ref() .map(|key| !regions.contains(key)) .unwrap_or(true) + // Client doesn't need to know about itself && *client_entity != entity - // Client doesn't need to know about itself { + client.notify(create_msg.clone()); send_initial_unsynced_components( client, uid, @@ -142,39 +155,52 @@ impl<'a> System<'a> for Sys { } } - let mut send_msg = - |msg: ServerMsg, entity: EcsEntity, pos: Pos, force_update, throttle: bool| { - for (client, _, client_entity, client_pos) in &mut subscribers { - match force_update { - None if client_entity == &entity => {} - _ => { - let distance_sq = client_pos.0.distance_squared(pos.0); + // Sync tracked components + let sync_msg = ServerMsg::EcsSync( + read_trackers.create_sync_package(&tracked_comps, region.entities()), + ); + for (client, _, _, _) in &mut subscribers { + client.notify(sync_msg.clone()); + } - // Throttle update rate based on distance to player - // TODO: more entities will be farther away so it could be more - // efficient to reverse the order of these checks - let update = if !throttle || distance_sq < 100.0f32.powi(2) { - true // Closer than 100.0 blocks - } else if distance_sq < 150.0f32.powi(2) { - (tick + entity.id() as u64) % 2 == 0 - } else if distance_sq < 200.0f32.powi(2) { - (tick + entity.id() as u64) % 4 == 0 - } else if distance_sq < 250.0f32.powi(2) { - (tick + entity.id() as u64) % 8 == 0 - } else if distance_sq < 300.0f32.powi(2) { - (tick + entity.id() as u64) % 16 == 0 - } else { - (tick + entity.id() as u64) % 32 == 0 - }; - - if update { - client.notify(msg.clone()); - } - } + let mut send_msg = |msg: ServerMsg, + entity: EcsEntity, + pos: Pos, + force_update: Option<&ForceUpdate>, + throttle: bool| { + for (client, _, client_entity, client_pos) in &mut subscribers { + let update = if client_entity == &entity && force_update.is_none() { + // Don't send client physics update about itself + false + } else if !throttle { + // Update rate not thottled by distance + true + } else { + // Throttle update rate based on distance to client + let distance_sq = client_pos.0.distance_squared(pos.0); + // More entities farther away so checks start there + if distance_sq > 300.0f32.powi(2) { + (tick + entity.id() as u64) % 32 == 0 + } else if distance_sq > 250.0f32.powi(2) { + (tick + entity.id() as u64) % 16 == 0 + } else if distance_sq > 200.0f32.powi(2) { + (tick + entity.id() as u64) % 8 == 0 + } else if distance_sq > 150.0f32.powi(2) { + (tick + entity.id() as u64) % 4 == 0 + } else if distance_sq > 100.0f32.powi(2) { + (tick + entity.id() as u64) % 2 == 0 + } else { + true // Closer than 100 blocks } - } - }; + }; + if update { + client.notify(msg.clone()); + } + } + }; + + // Sync physics components for (_, entity, &uid, &pos, maybe_vel, maybe_ori, character_state, force_update) in ( region.entities(), &entities, @@ -257,6 +283,8 @@ impl<'a> System<'a> for Sys { } } + // TODO: Sync clients that don't have a position? + // Sync inventories for (client, inventory, _) in (&mut clients, &inventories, &inventory_updates).join() { client.notify(ServerMsg::InventoryUpdate(inventory.clone())); @@ -266,6 +294,13 @@ impl<'a> System<'a> for Sys { force_updates.clear(); inventory_updates.clear(); + // Sync resources + // TODO: doesn't really belong in this system + let res_msg = ServerMsg::EcsResSync(tracked_resources.create_res_sync_package()); + for client in (&mut clients).join() { + client.notify(res_msg.clone()); + } + timer.end(); } } diff --git a/server/src/sys/mod.rs b/server/src/sys/mod.rs index bbdadac329..28b3ac5842 100644 --- a/server/src/sys/mod.rs +++ b/server/src/sys/mod.rs @@ -1,5 +1,6 @@ pub mod entity_sync; pub mod message; +pub mod sentinel; pub mod subscription; pub mod terrain; pub mod terrain_sync; @@ -9,20 +10,27 @@ use std::{marker::PhantomData, time::Instant}; pub type EntitySyncTimer = SysTimer; pub type MessageTimer = SysTimer; +pub type SentinelTimer = SysTimer; pub type SubscriptionTimer = SysTimer; pub type TerrainTimer = SysTimer; pub type TerrainSyncTimer = SysTimer; // System names const ENTITY_SYNC_SYS: &str = "server_entity_sync_sys"; +const SENTINEL_SYS: &str = "sentinel_sys"; const SUBSCRIPTION_SYS: &str = "server_subscription_sys"; const TERRAIN_SYNC_SYS: &str = "server_terrain_sync_sys"; const TERRAIN_SYS: &str = "server_terrain_sys"; const MESSAGE_SYS: &str = "server_message_sys"; pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) { + dispatch_builder.add(sentinel::Sys, SENTINEL_SYS, &[]); dispatch_builder.add(subscription::Sys, SUBSCRIPTION_SYS, &[]); - dispatch_builder.add(entity_sync::Sys, ENTITY_SYNC_SYS, &[SUBSCRIPTION_SYS]); + dispatch_builder.add( + entity_sync::Sys, + ENTITY_SYNC_SYS, + &[SUBSCRIPTION_SYS, SENTINEL_SYS], + ); dispatch_builder.add(terrain_sync::Sys, TERRAIN_SYS, &[]); dispatch_builder.add(terrain::Sys, TERRAIN_SYNC_SYS, &[TERRAIN_SYS]); dispatch_builder.add(message::Sys, MESSAGE_SYS, &[]); diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs new file mode 100644 index 0000000000..d9abdbabdf --- /dev/null +++ b/server/src/sys/sentinel.rs @@ -0,0 +1,309 @@ +use super::SysTimer; +use common::{ + comp::{ + Body, CanBuild, Gravity, Item, LightEmitter, Mass, MountState, Mounting, Player, + Projectile, Scale, Stats, Sticky, + }, + msg::{EcsCompPacket, EcsResPacket}, + sphynx::{ + self, EntityPackage, ResSyncPackage, StatePackage, SyncPackage, UpdateTracker, WorldSyncExt, + }, + state::{Time, TimeOfDay, Uid}, +}; +use shred_derive::SystemData; +use specs::{ + Entity as EcsEntity, Join, ReadExpect, ReadStorage, System, World, Write, WriteExpect, +}; +use std::ops::Deref; + +/// Always watching +/// This system will monitor specific components for insertion, removal, and modification +pub struct Sys; +impl<'a> System<'a> for Sys { + type SystemData = ( + Write<'a, SysTimer>, + TrackedComps<'a>, + WriteTrackers<'a>, + ); + + fn run(&mut self, (mut timer, comps, mut trackers): Self::SystemData) { + timer.start(); + + record_changes(&comps, &mut trackers); + + timer.end(); + } +} + +// Probably more difficult than it needs to be :p +#[derive(SystemData)] +pub struct TrackedComps<'a> { + uid: ReadStorage<'a, Uid>, + body: ReadStorage<'a, Body>, + player: ReadStorage<'a, Player>, + stats: ReadStorage<'a, Stats>, + can_build: ReadStorage<'a, CanBuild>, + light_emitter: ReadStorage<'a, LightEmitter>, + item: ReadStorage<'a, Item>, + scale: ReadStorage<'a, Scale>, + mounting: ReadStorage<'a, Mounting>, + mount_state: ReadStorage<'a, MountState>, + mass: ReadStorage<'a, Mass>, + sticky: ReadStorage<'a, Sticky>, + gravity: ReadStorage<'a, Gravity>, + projectile: ReadStorage<'a, Projectile>, +} +impl<'a> TrackedComps<'a> { + pub fn create_entity_package(&self, entity: EcsEntity) -> EntityPackage { + let uid = self + .uid + .get(entity) + .copied() + .expect("No uid to create an entity package") + .0; + let mut packets = Vec::new(); + self.body + .get(entity) + .copied() + .map(|c| packets.push(c.into())); + self.player + .get(entity) + .cloned() + .map(|c| packets.push(c.into())); + self.stats + .get(entity) + .cloned() + .map(|c| packets.push(c.into())); + self.can_build + .get(entity) + .cloned() + .map(|c| packets.push(c.into())); + self.light_emitter + .get(entity) + .copied() + .map(|c| packets.push(c.into())); + self.item + .get(entity) + .cloned() + .map(|c| packets.push(c.into())); + self.scale + .get(entity) + .copied() + .map(|c| packets.push(c.into())); + self.mounting + .get(entity) + .cloned() + .map(|c| packets.push(c.into())); + self.mount_state + .get(entity) + .cloned() + .map(|c| packets.push(c.into())); + self.mass + .get(entity) + .copied() + .map(|c| packets.push(c.into())); + self.sticky + .get(entity) + .copied() + .map(|c| packets.push(c.into())); + self.gravity + .get(entity) + .copied() + .map(|c| packets.push(c.into())); + self.projectile + .get(entity) + .cloned() + .map(|c| packets.push(c.into())); + + EntityPackage(uid, packets) + } +} +#[derive(SystemData)] +pub struct ReadTrackers<'a> { + uid: ReadExpect<'a, UpdateTracker>, + body: ReadExpect<'a, UpdateTracker>, + player: ReadExpect<'a, UpdateTracker>, + stats: ReadExpect<'a, UpdateTracker>, + can_build: ReadExpect<'a, UpdateTracker>, + light_emitter: ReadExpect<'a, UpdateTracker>, + item: ReadExpect<'a, UpdateTracker>, + scale: ReadExpect<'a, UpdateTracker>, + mounting: ReadExpect<'a, UpdateTracker>, + mount_state: ReadExpect<'a, UpdateTracker>, + mass: ReadExpect<'a, UpdateTracker>, + sticky: ReadExpect<'a, UpdateTracker>, + gravity: ReadExpect<'a, UpdateTracker>, + projectile: ReadExpect<'a, UpdateTracker>, +} +impl<'a> ReadTrackers<'a> { + pub fn create_sync_package( + &self, + comps: &TrackedComps, + filter: impl Join + Copy, + ) -> SyncPackage { + SyncPackage::new(&comps.uid, &self.uid, filter) + .with_component( + &comps.uid, + &self.uid, + self.body.deref(), + &comps.body, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.player.deref(), + &comps.player, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.stats.deref(), + &comps.stats, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.can_build.deref(), + &comps.can_build, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.light_emitter.deref(), + &comps.light_emitter, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.item.deref(), + &comps.item, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.scale.deref(), + &comps.scale, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.mounting.deref(), + &comps.mounting, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.mount_state.deref(), + &comps.mount_state, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.mass.deref(), + &comps.mass, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.sticky.deref(), + &comps.sticky, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.gravity.deref(), + &comps.gravity, + filter, + ) + .with_component( + &comps.uid, + &self.uid, + self.projectile.deref(), + &comps.projectile, + filter, + ) + } +} + +#[derive(SystemData)] +pub struct WriteTrackers<'a> { + uid: WriteExpect<'a, UpdateTracker>, + body: WriteExpect<'a, UpdateTracker>, + player: WriteExpect<'a, UpdateTracker>, + stats: WriteExpect<'a, UpdateTracker>, + can_build: WriteExpect<'a, UpdateTracker>, + light_emitter: WriteExpect<'a, UpdateTracker>, + item: WriteExpect<'a, UpdateTracker>, + scale: WriteExpect<'a, UpdateTracker>, + mounting: WriteExpect<'a, UpdateTracker>, + mount_state: WriteExpect<'a, UpdateTracker>, + mass: WriteExpect<'a, UpdateTracker>, + sticky: WriteExpect<'a, UpdateTracker>, + gravity: WriteExpect<'a, UpdateTracker>, + projectile: WriteExpect<'a, UpdateTracker>, +} + +fn record_changes(comps: &TrackedComps, trackers: &mut WriteTrackers) { + // Update trackers + trackers.uid.record_changes(&comps.uid); + trackers.body.record_changes(&comps.body); + trackers.player.record_changes(&comps.player); + trackers.stats.record_changes(&comps.stats); + trackers.can_build.record_changes(&comps.can_build); + trackers.light_emitter.record_changes(&comps.light_emitter); + trackers.item.record_changes(&comps.item); + trackers.scale.record_changes(&comps.scale); + trackers.mounting.record_changes(&comps.mounting); + trackers.mount_state.record_changes(&comps.mount_state); + trackers.mass.record_changes(&comps.mass); + trackers.sticky.record_changes(&comps.sticky); + trackers.gravity.record_changes(&comps.gravity); + trackers.projectile.record_changes(&comps.projectile); +} + +pub fn register_trackers(world: &mut World) { + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); + world.register_tracker::(); +} + +#[derive(SystemData)] +pub struct TrackedResources<'a> { + time: ReadExpect<'a, Time>, + time_of_day: ReadExpect<'a, TimeOfDay>, +} +impl<'a> TrackedResources<'a> { + pub fn create_res_sync_package(&self) -> ResSyncPackage { + ResSyncPackage::new() + .with_res(self.time.deref()) + .with_res(self.time_of_day.deref()) + } + /// Create state package with resources included + pub fn state_package(&self) -> StatePackage { + StatePackage::new() + .with_res(self.time.deref()) + .with_res(self.time_of_day.deref()) + } +} diff --git a/server/src/sys/subscription.rs b/server/src/sys/subscription.rs index 88e574959e..0a5f0891dd 100644 --- a/server/src/sys/subscription.rs +++ b/server/src/sys/subscription.rs @@ -1,4 +1,4 @@ -use super::SysTimer; +use super::{sentinel::TrackedComps, SysTimer}; use crate::client::{self, Client, RegionSubscription}; use common::{ comp::{CharacterState, Ori, Player, Pos, Vel}, @@ -26,6 +26,7 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Player>, WriteStorage<'a, Client>, WriteStorage<'a, RegionSubscription>, + TrackedComps<'a>, ); fn run( @@ -42,6 +43,7 @@ impl<'a> System<'a> for Sys { players, mut clients, mut subscriptions, + tracked_comps, ): Self::SystemData, ) { timer.start(); @@ -142,7 +144,7 @@ impl<'a> System<'a> for Sys { // Send client intial info about the entities in this region if subscription.regions.insert(key) { if let Some(region) = region_map.get(key) { - for (uid, pos, vel, ori, character_state, _, _) in ( + for (uid, pos, vel, ori, character_state, _, entity) in ( &uids, &positions, velocities.maybe(), @@ -154,6 +156,11 @@ impl<'a> System<'a> for Sys { .join() .filter(|(_, _, _, _, _, _, e)| *e != client_entity) { + // Send message to create entity and tracked components + client.notify(ServerMsg::CreateEntity( + tracked_comps.create_entity_package(entity), + )); + // Send message to create physics components super::entity_sync::send_initial_unsynced_components( client, uid, From 71cce03f293def79a0710d3b3501bb9962b0f3cd Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 24 Nov 2019 15:12:03 -0500 Subject: [PATCH 02/11] Move sync code into common submodule --- Cargo.lock | 12 +-- client/src/lib.rs | 4 +- common/Cargo.toml | 3 +- common/src/comp/controller.rs | 2 +- common/src/comp/phys.rs | 2 +- common/src/comp/projectile.rs | 3 +- common/src/comp/stats.rs | 2 +- common/src/event.rs | 3 +- common/src/lib.rs | 4 +- common/src/msg/ecs_packet.rs | 112 ++++++++++----------- common/src/msg/server.rs | 10 +- common/src/state.rs | 19 +--- common/src/sync/mod.rs | 14 +++ common/src/sync/packet.rs | 167 +++++++++++++++++++++++++++++++ common/src/sync/sync_ext.rs | 178 +++++++++++++++++++++++++++++++++ common/src/sync/track.rs | 144 ++++++++++++++++++++++++++ common/src/sync/uid.rs | 88 ++++++++++++++++ common/src/sys/combat.rs | 3 +- common/src/sys/controller.rs | 2 +- common/src/sys/mount.rs | 6 +- common/src/sys/movement.rs | 4 +- common/src/sys/phys.rs | 2 +- server/src/cmd.rs | 2 +- server/src/lib.rs | 6 +- server/src/sys/entity_sync.rs | 6 +- server/src/sys/sentinel.rs | 9 +- server/src/sys/subscription.rs | 2 +- 27 files changed, 684 insertions(+), 125 deletions(-) create mode 100644 common/src/sync/mod.rs create mode 100644 common/src/sync/packet.rs create mode 100644 common/src/sync/sync_ext.rs create mode 100644 common/src/sync/track.rs create mode 100644 common/src/sync/uid.rs diff --git a/Cargo.lock b/Cargo.lock index 040d359b08..a945449cd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3194,16 +3194,6 @@ dependencies = [ "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "sphynx" -version = "0.1.0" -dependencies = [ - "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", - "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", - "sum_type 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "spin" version = "0.5.2" @@ -3598,7 +3588,7 @@ dependencies = [ "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git)", - "sphynx 0.1.0", + "sum_type 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/client/src/lib.rs b/client/src/lib.rs index b97f7f31a8..b59571a1f0 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -14,8 +14,8 @@ use common::{ ServerError, ServerInfo, ServerMsg, MAX_BYTES_CHAT_MSG, }, net::PostBox, - sphynx::WorldSyncExt, - state::{State, Uid}, + state::State, + sync::{Uid, WorldSyncExt}, terrain::{block::Block, TerrainChunk, TerrainChunkSize}, vol::RectVolSize, ChatType, diff --git a/common/Cargo.toml b/common/Cargo.toml index e8a7c0ed41..08f6ca603c 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -5,8 +5,6 @@ authors = ["Joshua Barretto ", "Maciej Ćwięka for EcsResPacket // for each variant EcsResPacket::T(T). @@ -12,11 +12,11 @@ sum_type! { TimeOfDay(state::TimeOfDay), } } -impl sphynx::ResPacket for EcsResPacket { +impl sync::ResPacket for EcsResPacket { fn apply(self, world: &specs::World) { match self { - EcsResPacket::Time(time) => sphynx::handle_res_update(time, world), - EcsResPacket::TimeOfDay(time_of_day) => sphynx::handle_res_update(time_of_day, world), + EcsResPacket::Time(time) => sync::handle_res_update(time, world), + EcsResPacket::TimeOfDay(time_of_day) => sync::handle_res_update(time_of_day, world), } } } @@ -66,72 +66,68 @@ sum_type! { Sticky(PhantomData), } } -impl sphynx::CompPacket for EcsCompPacket { +impl sync::CompPacket for EcsCompPacket { type Phantom = EcsCompPhantom; fn apply_insert(self, entity: specs::Entity, world: &specs::World) { match self { - EcsCompPacket::Pos(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Vel(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Ori(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Body(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Player(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::CanBuild(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Stats(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::LightEmitter(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Item(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Scale(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::MountState(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Mounting(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Mass(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Projectile(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Gravity(comp) => sphynx::handle_insert(comp, entity, world), - EcsCompPacket::Sticky(comp) => sphynx::handle_insert(comp, entity, world), + EcsCompPacket::Pos(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Vel(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Ori(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Body(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Player(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::CanBuild(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Stats(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::LightEmitter(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Item(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Scale(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::MountState(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Mounting(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Mass(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Projectile(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Gravity(comp) => sync::handle_insert(comp, entity, world), + EcsCompPacket::Sticky(comp) => sync::handle_insert(comp, entity, world), } } fn apply_modify(self, entity: specs::Entity, world: &specs::World) { match self { - EcsCompPacket::Pos(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Vel(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Ori(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Body(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Player(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::CanBuild(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Stats(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::LightEmitter(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Item(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Scale(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::MountState(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Mounting(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Mass(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Projectile(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Gravity(comp) => sphynx::handle_modify(comp, entity, world), - EcsCompPacket::Sticky(comp) => sphynx::handle_modify(comp, entity, world), + EcsCompPacket::Pos(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Vel(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Ori(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Body(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Player(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::CanBuild(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Stats(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::LightEmitter(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Item(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Scale(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::MountState(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Mounting(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Mass(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Projectile(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Gravity(comp) => sync::handle_modify(comp, entity, world), + EcsCompPacket::Sticky(comp) => sync::handle_modify(comp, entity, world), } } fn apply_remove(phantom: Self::Phantom, entity: specs::Entity, world: &specs::World) { match phantom { - EcsCompPhantom::Pos(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::Vel(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::Ori(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::Body(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::Player(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::CanBuild(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::Stats(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Pos(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Vel(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Ori(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Body(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Player(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::CanBuild(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Stats(_) => sync::handle_remove::(entity, world), EcsCompPhantom::LightEmitter(_) => { - sphynx::handle_remove::(entity, world) + sync::handle_remove::(entity, world) } - EcsCompPhantom::Item(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::Scale(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::MountState(_) => { - sphynx::handle_remove::(entity, world) - } - EcsCompPhantom::Mounting(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::Mass(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::Projectile(_) => { - sphynx::handle_remove::(entity, world) - } - EcsCompPhantom::Gravity(_) => sphynx::handle_remove::(entity, world), - EcsCompPhantom::Sticky(_) => sphynx::handle_remove::(entity, world), + EcsCompPhantom::Item(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Scale(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::MountState(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Mounting(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Mass(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Projectile(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Gravity(_) => sync::handle_remove::(entity, world), + EcsCompPhantom::Sticky(_) => sync::handle_remove::(entity, world), } } } diff --git a/common/src/msg/server.rs b/common/src/msg/server.rs index dc8ccd8c1c..90bc785ddb 100644 --- a/common/src/msg/server.rs +++ b/common/src/msg/server.rs @@ -1,6 +1,6 @@ use super::{ClientState, EcsCompPacket, EcsResPacket}; use crate::{ - comp, + comp, sync, terrain::{Block, TerrainChunk}, ChatType, }; @@ -26,7 +26,7 @@ pub struct ServerInfo { #[derive(Debug, Clone, Serialize, Deserialize)] pub enum ServerMsg { InitialSync { - ecs_state: sphynx::StatePackage, + ecs_state: sync::StatePackage, entity_uid: u64, server_info: ServerInfo, // world_map: Vec2, /*, Vec)*/ @@ -40,9 +40,9 @@ pub enum ServerMsg { message: String, }, SetPlayerEntity(u64), - EcsSync(sphynx::SyncPackage), - EcsResSync(sphynx::ResSyncPackage), - CreateEntity(sphynx::EntityPackage), + EcsSync(sync::SyncPackage), + EcsResSync(sync::ResSyncPackage), + CreateEntity(sync::EntityPackage), DeleteEntity(u64), EntityPos { entity: u64, diff --git a/common/src/state.rs b/common/src/state.rs index 1d62d3419b..dbc9becad1 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -1,10 +1,8 @@ -// Reexports -pub use sphynx::Uid; - use crate::{ comp, event::{EventBus, LocalEvent, ServerEvent, SfxEventItem}, region::RegionMap, + sync::WorldSyncExt, sys, terrain::{Block, TerrainChunk, TerrainGrid}, vol::WriteVol, @@ -17,7 +15,6 @@ use specs::{ storage::{MaskedStorage as EcsMaskedStorage, Storage as EcsStorage}, Component, DispatcherBuilder, Entity as EcsEntity, }; -use sphynx::WorldSyncExt; use std::{sync::Arc, time::Duration}; use vek::*; @@ -103,20 +100,6 @@ impl Default for State { } impl State { - // Create a new `State` from an ECS state package. - /*pub fn from_state_package( - state_package: sphynx::StatePackage, - ) -> Self { - Self { - ecs: sphynx::World::from_state_package( - specs::World::new(), - Self::setup_sphynx_world, - state_package, - ), - thread_pool: Arc::new(ThreadPoolBuilder::new().build().unwrap()), - } - }*/ - /// Creates ecs world and registers all the common components and resources // TODO: Split up registering into server and client (e.g. move EventBus to the server) fn setup_ecs_world() -> specs::World { diff --git a/common/src/sync/mod.rs b/common/src/sync/mod.rs new file mode 100644 index 0000000000..d26ad789fd --- /dev/null +++ b/common/src/sync/mod.rs @@ -0,0 +1,14 @@ +// Note: Currently only one-way sync is supported until a usecase for two-way sync arises +mod packet; +mod sync_ext; +mod track; +mod uid; + +// Reexports +pub use packet::{ + handle_insert, handle_modify, handle_remove, handle_res_update, CompPacket, EntityPackage, + ResPacket, ResSyncPackage, StatePackage, SyncPackage, +}; +pub use sync_ext::WorldSyncExt; +pub use track::{Tracker, UpdateTracker}; +pub use uid::{Uid, UidAllocator}; diff --git a/common/src/sync/packet.rs b/common/src/sync/packet.rs new file mode 100644 index 0000000000..b3cf45bf3c --- /dev/null +++ b/common/src/sync/packet.rs @@ -0,0 +1,167 @@ +use super::{ + track::{Tracker, UpdateTracker}, + uid::Uid, +}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use specs::{shred::Resource, Component, Entity, Join, ReadStorage, World}; +use std::{ + convert::{TryFrom, TryInto}, + fmt::Debug, + marker::PhantomData, +}; + +pub trait CompPacket: Clone + Debug + Send + 'static { + type Phantom: Clone + Debug + Serialize + DeserializeOwned; + + fn apply_insert(self, entity: Entity, world: &World); + fn apply_modify(self, entity: Entity, world: &World); + fn apply_remove(phantom: Self::Phantom, entity: Entity, world: &World); +} + +pub trait ResPacket: Clone + Debug + Send + 'static { + fn apply(self, world: &World); +} + +/// Useful for implementing CompPacket trait +pub fn handle_insert(comp: C, entity: Entity, world: &World) { + let _ = world.write_storage::().insert(entity, comp); +} +/// Useful for implementing CompPacket trait +pub fn handle_modify(comp: C, entity: Entity, world: &World) { + let _ = world + .write_storage::() + .get_mut(entity) + .map(|c| *c = comp); +} +/// Useful for implementing CompPacket trait +pub fn handle_remove(entity: Entity, world: &World) { + let _ = world.write_storage::().remove(entity); +} +/// Useful for implementing ResPacket trait +pub fn handle_res_update(res: R, world: &World) { + *world.write_resource::() = res; +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] +pub enum CompUpdateKind { + Inserted(P), + Modified(P), + Removed(P::Phantom), +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct EntityPackage(pub u64, pub Vec

); + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct StatePackage { + pub entities: Vec>, + pub resources: Vec, +} + +impl Default for StatePackage { + fn default() -> Self { + Self { + entities: Vec::new(), + resources: Vec::new(), + } + } +} + +impl StatePackage { + pub fn new() -> Self { + Self::default() + } + pub fn with_entities( + mut self, + mut entities: Vec>, + ) -> Self { + self.entities.append(&mut entities); + self + } + pub fn with_entity(mut self, entry: EntityPackage

) -> Self { + self.entities.push(entry); + self + } + pub fn with_res(mut self, res: &C) -> Self + where + R: From, + { + self.resources.push(R::from(res.clone())); + self + } +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct SyncPackage { + pub comp_updates: Vec<(u64, CompUpdateKind

)>, + pub created_entities: Vec, + pub deleted_entities: Vec, +} +impl SyncPackage

{ + pub fn new<'a>( + uids: &ReadStorage<'a, Uid>, + uid_tracker: &UpdateTracker, + filter: impl Join + Copy, + ) -> Self { + // Add created and deleted entities + let created_entities = (uids, filter, uid_tracker.inserted()) + .join() + .map(|(uid, _, _)| (*uid).into()) + .collect(); + // TODO: handle modified uid? + //created_entities.append(&mut (uids, filter, uid_tracker.inserted()).join().map(|(uid, _, _)| uid).collect()); + let deleted_entities = (uids, filter, uid_tracker.removed()) + .join() + .map(|(uid, _, _)| (*uid).into()) + .collect(); + + Self { + comp_updates: Vec::new(), + created_entities, + deleted_entities, + } + } + pub fn with_component<'a, C: Component + Clone + Send + Sync>( + mut self, + uids: &ReadStorage<'a, Uid>, + uid_tracker: &UpdateTracker, + tracker: &impl Tracker, + storage: &ReadStorage<'a, C>, + filter: impl Join + Copy, + ) -> Self + where + P: From, + C: TryFrom

, + P::Phantom: From>, + P::Phantom: TryInto>, + C::Storage: specs::storage::Tracked, + { + tracker.get_updates_for( + uids, + storage, + // Don't include updates for deleted entities + (filter, &!uid_tracker.removed()), + &mut self.comp_updates, + ); + self + } +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct ResSyncPackage { + pub resources: Vec, +} +impl ResSyncPackage { + pub fn new() -> Self { + Self { + resources: Vec::new(), + } + } + pub fn with_res(mut self, res: &C) -> Self + where + R: From, + { + self.resources.push(R::from(res.clone())); + self + } +} diff --git a/common/src/sync/sync_ext.rs b/common/src/sync/sync_ext.rs new file mode 100644 index 0000000000..a375667111 --- /dev/null +++ b/common/src/sync/sync_ext.rs @@ -0,0 +1,178 @@ +use super::{ + packet::{ + CompPacket, CompUpdateKind, EntityPackage, ResPacket, ResSyncPackage, StatePackage, + SyncPackage, + }, + track::UpdateTracker, + uid::{Uid, UidAllocator}, +}; +use specs::{ + saveload::{MarkedBuilder, MarkerAllocator}, + world::Builder, +}; + +pub trait WorldSyncExt { + fn register_sync_marker(&mut self); + fn register_synced(&mut self) + where + C::Storage: Default + specs::storage::Tracked; + fn register_tracker(&mut self) + where + C::Storage: Default + specs::storage::Tracked; + fn create_entity_synced(&mut self) -> specs::EntityBuilder; + fn uid_from_entity(&self, entity: specs::Entity) -> Option; + fn entity_from_uid(&self, uid: u64) -> Option; + fn apply_entity_package(&mut self, entity_package: EntityPackage

); + fn apply_state_package( + &mut self, + state_package: StatePackage, + ); + fn apply_sync_package(&mut self, package: SyncPackage

); + fn apply_res_sync_package(&mut self, package: ResSyncPackage); +} + +impl WorldSyncExt for specs::World { + fn register_sync_marker(&mut self) { + self.register_synced::(); + + self.add_resource(UidAllocator::new()); + } + fn register_synced(&mut self) + where + // P: From, + // C: TryFrom, + // P::Phantom: From>, + // P::Phantom: TryInto>, + C::Storage: Default + specs::storage::Tracked, + { + self.register::(); + self.register_tracker::(); + } + fn register_tracker(&mut self) + where + // P: From, + // C: TryFrom, + // P::Phantom: From>, + // P::Phantom: TryInto>, + C::Storage: Default + specs::storage::Tracked, + { + let tracker = UpdateTracker::::new(self); + self.add_resource(tracker); + } + + /*fn insert_synced(&mut self, res: C) + //where + // R: From, + // C: TryFrom, + { + self.add_resource::(res); + + self.res_trackers.insert(ResUpdateTracker::::new()); + }*/ + + fn create_entity_synced(&mut self) -> specs::EntityBuilder { + self.create_entity().marked::() + } + + /// Get the UID of an entity + fn uid_from_entity(&self, entity: specs::Entity) -> Option { + self.read_storage::().get(entity).copied() + } + + /// Get the UID of an entity + fn entity_from_uid(&self, uid: u64) -> Option { + self.read_resource::() + .retrieve_entity_internal(uid) + } + + fn apply_entity_package(&mut self, entity_package: EntityPackage

) { + let EntityPackage(entity_uid, packets) = entity_package; + + let entity = create_entity_with_uid(self, entity_uid); + for packet in packets { + packet.apply_insert(entity, self) + } + } + + fn apply_state_package( + &mut self, + state_package: StatePackage, + ) { + let StatePackage { + entities, + resources, + } = state_package; + + // Apply state package resources + for res_packet in resources { + res_packet.apply(self); + } + + // Apply state package entities + for entity_package in entities { + self.apply_entity_package(entity_package); + } + + // Initialize entities + //specs_world.maintain(); + } + + fn apply_sync_package(&mut self, package: SyncPackage

) { + // Take ownership of the fields + let SyncPackage { + comp_updates, + created_entities, + deleted_entities, + } = package; + + // Attempt to create entities + for entity_uid in created_entities { + create_entity_with_uid(self, entity_uid); + } + + // Update components + for (entity_uid, update) in comp_updates { + if let Some(entity) = self + .read_resource::() + .retrieve_entity_internal(entity_uid) + { + match update { + CompUpdateKind::Inserted(packet) => { + packet.apply_insert(entity, self); + } + CompUpdateKind::Modified(packet) => { + packet.apply_modify(entity, self); + } + CompUpdateKind::Removed(phantom) => { + P::apply_remove(phantom, entity, self); + } + } + } + } + + // Attempt to delete entities that were marked for deletion + for entity_uid in deleted_entities { + let entity = self + .read_resource::() + .retrieve_entity_internal(entity_uid); + if let Some(entity) = entity { + let _ = self.delete_entity(entity); + } + } + } + fn apply_res_sync_package(&mut self, package: ResSyncPackage) { + // Update resources + for res_packet in package.resources { + res_packet.apply(self); + } + } +} + +// Private utilities +fn create_entity_with_uid(specs_world: &mut specs::World, entity_uid: u64) -> specs::Entity { + let existing_entity = specs_world + .read_resource::() + .retrieve_entity_internal(entity_uid); + + existing_entity.unwrap_or_else(|| specs_world.create_entity_synced().build()) +} diff --git a/common/src/sync/track.rs b/common/src/sync/track.rs new file mode 100644 index 0000000000..2f27551b83 --- /dev/null +++ b/common/src/sync/track.rs @@ -0,0 +1,144 @@ +use super::{ + packet::{CompPacket, CompUpdateKind}, + uid::Uid, +}; +use specs::{BitSet, Component, Entity, Join, ReadStorage, World}; +use std::{ + convert::{TryFrom, TryInto}, + marker::PhantomData, +}; + +pub trait Tracker: Send + 'static +where + P: From, + C: TryFrom

, + P::Phantom: From>, + P::Phantom: TryInto>, + C::Storage: specs::storage::Tracked, +{ + fn add_packet_for<'a>( + &self, + storage: &specs::ReadStorage<'a, C>, + entity: specs::Entity, + packets: &mut Vec

, + ); + fn get_updates_for<'a>( + &self, + uids: &specs::ReadStorage<'a, Uid>, + storage: &specs::ReadStorage<'a, C>, + filter: impl Join + Copy, + buf: &mut Vec<(u64, CompUpdateKind

)>, + ); +} + +pub struct UpdateTracker { + reader_id: specs::ReaderId, + inserted: BitSet, + modified: BitSet, + removed: BitSet, + phantom: PhantomData, +} +impl UpdateTracker +where + C::Storage: specs::storage::Tracked, +{ + pub fn new(specs_world: &mut World) -> Self { + Self { + reader_id: specs_world.write_storage::().register_reader(), + inserted: BitSet::new(), + modified: BitSet::new(), + removed: BitSet::new(), + phantom: PhantomData, + } + } + pub fn inserted(&self) -> &BitSet { + &self.inserted + } + pub fn modified(&self) -> &BitSet { + &self.modified + } + pub fn removed(&self) -> &BitSet { + &self.removed + } + pub fn record_changes<'a>(&mut self, storage: &specs::ReadStorage<'a, C>) { + self.inserted.clear(); + self.modified.clear(); + self.removed.clear(); + + for event in storage.channel().read(&mut self.reader_id) { + match event { + specs::storage::ComponentEvent::Inserted(id) => { + // If previously removed/modified we don't need to know that anymore + self.removed.remove(*id); + self.modified.remove(*id); + self.inserted.add(*id); + } + specs::storage::ComponentEvent::Modified(id) => { + // We don't care about modification if the component was just added or was + // removed + if !self.removed.contains(*id) && !self.inserted.contains(*id) { + self.modified.add(*id); + } + } + specs::storage::ComponentEvent::Removed(id) => { + // Don't need to know that it was inserted/modified if it was subsequently removed + self.inserted.remove(*id); + self.modified.remove(*id); + self.removed.add(*id); + } + }; + } + } +} + +impl Tracker for UpdateTracker +where + P: From, + C: TryFrom

, + P::Phantom: From>, + P::Phantom: TryInto>, + C::Storage: specs::storage::Tracked, +{ + fn add_packet_for<'a>( + &self, + storage: &ReadStorage<'a, C>, + entity: Entity, + packets: &mut Vec

, + ) { + if let Some(comp) = storage.get(entity) { + packets.push(P::from(comp.clone())); + } + } + + fn get_updates_for<'a>( + &self, + uids: &specs::ReadStorage<'a, Uid>, + storage: &specs::ReadStorage<'a, C>, + entity_filter: impl Join + Copy, + buf: &mut Vec<(u64, CompUpdateKind

)>, + ) { + // Generate inserted updates + for (uid, comp, _, _) in (uids, storage, &self.inserted, entity_filter).join() { + buf.push(( + (*uid).into(), + CompUpdateKind::Inserted(P::from(comp.clone())), + )); + } + + // Generate modified updates + for (uid, comp, _, _) in (uids, storage, &self.modified, entity_filter).join() { + buf.push(( + (*uid).into(), + CompUpdateKind::Modified(P::from(comp.clone())), + )); + } + + // Generate removed updates + for (uid, _, _) in (uids, &self.removed, entity_filter).join() { + buf.push(( + (*uid).into(), + CompUpdateKind::Removed(P::Phantom::from(PhantomData::)), + )); + } + } +} diff --git a/common/src/sync/uid.rs b/common/src/sync/uid.rs new file mode 100644 index 0000000000..e7dc31b241 --- /dev/null +++ b/common/src/sync/uid.rs @@ -0,0 +1,88 @@ +use serde_derive::{Deserialize, Serialize}; +use specs::{ + saveload::{Marker, MarkerAllocator}, + world::EntitiesRes, + Component, Entity, FlaggedStorage, Join, ReadStorage, VecStorage, +}; +use std::{collections::HashMap, fmt, u64}; + +#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] +pub struct Uid(pub u64); + +impl Into for Uid { + fn into(self) -> u64 { + self.0 + } +} + +impl From for Uid { + fn from(uid: u64) -> Self { + Self(uid) + } +} + +impl fmt::Display for Uid { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +impl Component for Uid { + type Storage = FlaggedStorage>; +} + +impl Marker for Uid { + type Identifier = u64; + type Allocator = UidAllocator; + + fn id(&self) -> u64 { + self.0 + } + + fn update(&mut self, update: Self) { + assert_eq!(self.0, update.0); + } +} + +pub struct UidAllocator { + index: u64, + mapping: HashMap, +} + +impl UidAllocator { + pub fn new() -> Self { + Self { + index: 0, + mapping: HashMap::new(), + } + } +} + +impl Default for UidAllocator { + fn default() -> Self { + Self::new() + } +} + +impl MarkerAllocator for UidAllocator { + fn allocate(&mut self, entity: Entity, id: Option) -> Uid { + let id = id.unwrap_or_else(|| { + let id = self.index; + self.index += 1; + self.mapping.insert(id, entity); + id + }); + Uid(id) + } + + fn retrieve_entity_internal(&self, id: u64) -> Option { + self.mapping.get(&id).cloned() + } + + fn maintain(&mut self, entities: &EntitiesRes, storage: &ReadStorage) { + self.mapping = (entities, storage) + .join() + .map(|(e, m)| (m.id(), e)) + .collect(); + } +} diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index 6a23de568f..7ee73e4bfa 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -4,7 +4,8 @@ use crate::{ Ori, Pos, Stats, }, event::{EventBus, LocalEvent, ServerEvent}, - state::{DeltaTime, Uid}, + state::DeltaTime, + sync::Uid, }; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; use std::time::Duration; diff --git a/common/src/sys/controller.rs b/common/src/sys/controller.rs index 3894d1b325..999ebbba4a 100644 --- a/common/src/sys/controller.rs +++ b/common/src/sys/controller.rs @@ -7,12 +7,12 @@ use crate::{ }, event::{Emitter, EventBus, LocalEvent, ServerEvent}, state::DeltaTime, + sync::{Uid, UidAllocator}, }; use specs::{ saveload::{Marker, MarkerAllocator}, Entities, Entity, Join, Read, ReadStorage, System, WriteStorage, }; -use sphynx::{Uid, UidAllocator}; use std::time::Duration; use vek::*; diff --git a/common/src/sys/mount.rs b/common/src/sys/mount.rs index 0d992f57b4..741ee9212d 100644 --- a/common/src/sys/mount.rs +++ b/common/src/sys/mount.rs @@ -1,9 +1,11 @@ -use crate::comp::{Controller, MountState, Mounting, Ori, Pos, Vel}; +use crate::{ + comp::{Controller, MountState, Mounting, Ori, Pos, Vel}, + sync::UidAllocator, +}; use specs::{ saveload::{Marker, MarkerAllocator}, Entities, Join, Read, System, WriteStorage, }; -use sphynx::UidAllocator; use vek::*; /// This system is responsible for controlling mounts diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs index 6bd3b797ee..dcec8bac24 100644 --- a/common/src/sys/movement.rs +++ b/common/src/sys/movement.rs @@ -5,10 +5,10 @@ use crate::{ }, event::{EventBus, ServerEvent}, state::DeltaTime, + sync::Uid, terrain::TerrainGrid, }; -use specs::prelude::*; -use sphynx::Uid; +use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage}; use std::time::Duration; use vek::*; diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 401d1631f1..d0a9f133a9 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -3,11 +3,11 @@ use { comp::{Body, Gravity, Mass, Mounting, Ori, PhysicsState, Pos, Scale, Sticky, Vel}, event::{EventBus, ServerEvent}, state::DeltaTime, + sync::Uid, terrain::{Block, TerrainGrid}, vol::ReadVol, }, specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage}, - sphynx::Uid, vek::*, }; diff --git a/server/src/cmd.rs b/server/src/cmd.rs index df4b46882e..b3303cac21 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -10,8 +10,8 @@ use common::{ msg::ServerMsg, npc::{get_npc_name, NpcKind}, pathfinding::WorldPath, - sphynx::WorldSyncExt, state::TimeOfDay, + sync::WorldSyncExt, terrain::{Block, BlockKind, TerrainChunkSize}, vol::RectVolSize, }; diff --git a/server/src/lib.rs b/server/src/lib.rs index 1e0034b621..7e2f5729d0 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -27,8 +27,8 @@ use common::{ event::{EventBus, ServerEvent}, msg::{ClientMsg, ClientState, ServerError, ServerInfo, ServerMsg}, net::PostOffice, - sphynx::WorldSyncExt, - state::{BlockChange, State, TimeOfDay, Uid}, + state::{BlockChange, State, TimeOfDay}, + sync::{Uid, WorldSyncExt}, terrain::{block::Block, TerrainChunkSize, TerrainGrid}, vol::{ReadVol, RectVolSize, Vox}, }; @@ -899,7 +899,7 @@ impl Server { .set((before_tick_6 - before_handle_events).as_nanos() as i64); self.metrics .tick_time - .with_label_values(&["sphynx sync"]) + .with_label_values(&["entity deletion"]) .set((before_tick_7 - before_tick_6).as_nanos() as i64); self.metrics .tick_time diff --git a/server/src/sys/entity_sync.rs b/server/src/sys/entity_sync.rs index 7d9dc40307..05611359b6 100644 --- a/server/src/sys/entity_sync.rs +++ b/server/src/sys/entity_sync.rs @@ -10,7 +10,7 @@ use common::{ comp::{CharacterState, ForceUpdate, Inventory, InventoryUpdate, Last, Ori, Pos, Vel}, msg::ServerMsg, region::{Event as RegionEvent, RegionMap}, - state::Uid, + sync::Uid, }; use specs::{ Entities, Entity as EcsEntity, Join, Read, ReadExpect, ReadStorage, System, Write, WriteStorage, @@ -77,8 +77,8 @@ impl<'a> System<'a> for Sys { // 2. Iterate through region subscribers (ie clients) // - Collect a list of entity ids for clients who are subscribed to this region (hash calc to check each) // 3. Iterate through events from that region - // - For each entity left event, iterate through the client list and check if they are subscribed to the destination (hash calc per subscribed client per entity left event) - // - Do something with entity entered events when sphynx is removed?? + // - For each entity entered event, iterate through the client list and check if they are subscribed to the source (hash calc per subscribed client per entity event), if not subscribed to the source send a entity creation message to that client + // - For each entity left event, iterate through the client list and check if they are subscribed to the destination (hash calc per subscribed client per entity event) // 4. Iterate through entities in that region // 5. Inform clients of the component changes for that entity // - Throttle update rate base on distance to each client diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index d9abdbabdf..a3a0f3ba33 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -5,10 +5,11 @@ use common::{ Projectile, Scale, Stats, Sticky, }, msg::{EcsCompPacket, EcsResPacket}, - sphynx::{ - self, EntityPackage, ResSyncPackage, StatePackage, SyncPackage, UpdateTracker, WorldSyncExt, + state::{Time, TimeOfDay}, + sync::{ + CompPacket, EntityPackage, ResSyncPackage, StatePackage, SyncPackage, Uid, UpdateTracker, + WorldSyncExt, }, - state::{Time, TimeOfDay, Uid}, }; use shred_derive::SystemData; use specs::{ @@ -301,7 +302,7 @@ impl<'a> TrackedResources<'a> { .with_res(self.time_of_day.deref()) } /// Create state package with resources included - pub fn state_package(&self) -> StatePackage { + pub fn state_package(&self) -> StatePackage { StatePackage::new() .with_res(self.time.deref()) .with_res(self.time_of_day.deref()) diff --git a/server/src/sys/subscription.rs b/server/src/sys/subscription.rs index 0a5f0891dd..d4617fd499 100644 --- a/server/src/sys/subscription.rs +++ b/server/src/sys/subscription.rs @@ -4,7 +4,7 @@ use common::{ comp::{CharacterState, Ori, Player, Pos, Vel}, msg::ServerMsg, region::{region_in_vd, regions_in_vd, Event as RegionEvent, RegionMap}, - state::Uid, + sync::Uid, terrain::TerrainChunkSize, vol::RectVolSize, }; From e49cafafbfb39078ed190049496eb2deb470edda Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 29 Nov 2019 01:04:37 -0500 Subject: [PATCH 03/11] Actually send deletion messages --- Cargo.toml | 2 +- client/src/lib.rs | 13 ++- common/src/msg/ecs_packet.rs | 15 --- common/src/region.rs | 59 ++++++++-- common/src/state.rs | 2 +- common/src/sync/packet.rs | 28 ++--- common/src/sync/sync_ext.rs | 52 ++++----- common/src/sync/track.rs | 1 + common/src/sync/uid.rs | 8 +- server/src/cmd.rs | 5 +- server/src/lib.rs | 199 ++++++++++++++------------------- server/src/sys/entity_sync.rs | 46 +++++++- server/src/sys/message.rs | 12 +- server/src/sys/sentinel.rs | 187 +++++++++++++------------------ server/src/sys/subscription.rs | 116 +++++++++++++++++-- voxygen/src/hud/mod.rs | 11 +- world/src/sim/mod.rs | 2 +- 17 files changed, 440 insertions(+), 318 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4c463c2db7..9abd786022 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ opt-level = 2 overflow-checks = true debug-assertions = true panic = "abort" -debug = false +# debug = false codegen-units = 8 lto = false incremental = true diff --git a/client/src/lib.rs b/client/src/lib.rs index b59571a1f0..c1e0a5c365 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -562,10 +562,15 @@ impl Client { self.state.ecs_mut().apply_entity_package(entity_package) } ServerMsg::DeleteEntity(entity) => { - if let Some(entity) = self.state.ecs().entity_from_uid(entity) { - if entity != self.entity { - let _ = self.state.ecs_mut().delete_entity(entity); - } + if self + .state + .read_component_cloned::(self.entity) + .map(|u| u.into()) + != Some(entity) + { + self.state + .ecs_mut() + .delete_entity_and_clear_from_uid_allocator(entity); } } ServerMsg::EntityPos { entity, pos } => { diff --git a/common/src/msg/ecs_packet.rs b/common/src/msg/ecs_packet.rs index 83f1adef10..28964041ab 100644 --- a/common/src/msg/ecs_packet.rs +++ b/common/src/msg/ecs_packet.rs @@ -25,9 +25,6 @@ impl sync::ResPacket for EcsResPacket { sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsCompPacket { - Pos(comp::Pos), - Vel(comp::Vel), - Ori(comp::Ori), Body(comp::Body), Player(comp::Player), CanBuild(comp::CanBuild), @@ -48,9 +45,6 @@ sum_type! { sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsCompPhantom { - Pos(PhantomData), - Vel(PhantomData), - Ori(PhantomData), Body(PhantomData), Player(PhantomData), CanBuild(PhantomData), @@ -70,9 +64,6 @@ impl sync::CompPacket for EcsCompPacket { type Phantom = EcsCompPhantom; fn apply_insert(self, entity: specs::Entity, world: &specs::World) { match self { - EcsCompPacket::Pos(comp) => sync::handle_insert(comp, entity, world), - EcsCompPacket::Vel(comp) => sync::handle_insert(comp, entity, world), - EcsCompPacket::Ori(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Body(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Player(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::CanBuild(comp) => sync::handle_insert(comp, entity, world), @@ -90,9 +81,6 @@ impl sync::CompPacket for EcsCompPacket { } fn apply_modify(self, entity: specs::Entity, world: &specs::World) { match self { - EcsCompPacket::Pos(comp) => sync::handle_modify(comp, entity, world), - EcsCompPacket::Vel(comp) => sync::handle_modify(comp, entity, world), - EcsCompPacket::Ori(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Body(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Player(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::CanBuild(comp) => sync::handle_modify(comp, entity, world), @@ -110,9 +98,6 @@ impl sync::CompPacket for EcsCompPacket { } fn apply_remove(phantom: Self::Phantom, entity: specs::Entity, world: &specs::World) { match phantom { - EcsCompPhantom::Pos(_) => sync::handle_remove::(entity, world), - EcsCompPhantom::Vel(_) => sync::handle_remove::(entity, world), - EcsCompPhantom::Ori(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Body(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Player(_) => sync::handle_remove::(entity, world), EcsCompPhantom::CanBuild(_) => sync::handle_remove::(entity, world), diff --git a/common/src/region.rs b/common/src/region.rs index de8e5a526d..acf4aa04fa 100644 --- a/common/src/region.rs +++ b/common/src/region.rs @@ -104,6 +104,16 @@ impl RegionMap { // TODO special case large entities pub fn tick(&mut self, pos: ReadStorage, vel: ReadStorage, entities: Entities) { self.tick += 1; + // Clear events within each region + for i in 0..self.regions.len() { + self.regions + .get_index_mut(i) + .map(|(_, v)| v) + .unwrap() + .events + .clear(); + } + // Add any untracked entites for (pos, id) in (&pos, &entities, !&self.tracked_entities) .join() @@ -118,14 +128,6 @@ impl RegionMap { let mut regions_to_remove = Vec::new(); for i in 0..self.regions.len() { - // Clear events within each region - self.regions - .get_index_mut(i) - .map(|(_, v)| v) - .unwrap() - .events - .clear(); - for (maybe_pos, _maybe_vel, id) in ( pos.maybe(), vel.maybe(), @@ -215,6 +217,47 @@ impl RegionMap { pub fn key_pos(key: Vec2) -> Vec2 { key.map(|e| e << REGION_LOG2) } + /// Finds the region where a given entity is located using a given position to speed up the search + pub fn find_region(&self, entity: specs::Entity, pos: Vec3) -> Option> { + let id = entity.id(); + // Compute key for most likely region + let key = Self::pos_key(pos.map(|e| e as i32)); + // Get region + if let Some(region) = self.regions.get(&key) { + if region.entities().contains(id) { + return Some(key); + } else { + // Check neighbors + for i in 0..8 { + if let Some(idx) = region.neighbors[i] { + let (key, region) = self.regions.get_index(idx).unwrap(); + if region.entities().contains(id) { + return Some(*key); + } + } + } + } + } else { + // Check neighbors + for i in 0..8 { + let key = key + NEIGHBOR_OFFSETS[i]; + if let Some(region) = self.regions.get(&key) { + if region.entities().contains(id) { + return Some(key); + } + } + } + } + + // Scan though all regions + for (key, region) in self.iter() { + if region.entities().contains(id) { + return Some(key); + } + } + + None + } fn key_index(&self, key: Vec2) -> Option { self.regions.get_full(&key).map(|(i, _, _)| i) } diff --git a/common/src/state.rs b/common/src/state.rs index dbc9becad1..a2120e60c6 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -148,10 +148,10 @@ impl State { ecs.register::(); // Register synced resources used by the ECS. - ecs.add_resource(Time(0.0)); ecs.add_resource(TimeOfDay(0.0)); // Register unsynced resources used by the ECS. + ecs.add_resource(Time(0.0)); ecs.add_resource(DeltaTime(0.0)); ecs.add_resource(TerrainGrid::new().unwrap()); ecs.add_resource(BlockChange::default()); diff --git a/common/src/sync/packet.rs b/common/src/sync/packet.rs index b3cf45bf3c..f12d409960 100644 --- a/common/src/sync/packet.rs +++ b/common/src/sync/packet.rs @@ -2,6 +2,7 @@ use super::{ track::{Tracker, UpdateTracker}, uid::Uid, }; +use log::error; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use specs::{shred::Resource, Component, Entity, Join, ReadStorage, World}; use std::{ @@ -24,7 +25,9 @@ pub trait ResPacket: Clone + Debug + Send + 'static { /// Useful for implementing CompPacket trait pub fn handle_insert(comp: C, entity: Entity, world: &World) { - let _ = world.write_storage::().insert(entity, comp); + if let Err(err) = world.write_storage::().insert(entity, comp) { + error!("Error inserting component: {:?}", err); + }; } /// Useful for implementing CompPacket trait pub fn handle_modify(comp: C, entity: Entity, world: &World) { @@ -102,6 +105,7 @@ impl SyncPackage

{ uids: &ReadStorage<'a, Uid>, uid_tracker: &UpdateTracker, filter: impl Join + Copy, + deleted_entities: Vec, ) -> Self { // Add created and deleted entities let created_entities = (uids, filter, uid_tracker.inserted()) @@ -110,10 +114,15 @@ impl SyncPackage

{ .collect(); // TODO: handle modified uid? //created_entities.append(&mut (uids, filter, uid_tracker.inserted()).join().map(|(uid, _, _)| uid).collect()); - let deleted_entities = (uids, filter, uid_tracker.removed()) - .join() - .map(|(uid, _, _)| (*uid).into()) - .collect(); + // let deleted_entities = (uids.maybe(), filter, uid_tracker.removed()) + // .join() + // Why doesn't this panic?? + // .map(|(uid, _, _)| Into::::into(*uid.unwrap())) + // .collect::>(); + //let len = deleted_entities.len(); + //if len > 0 { + // println!("deleted {} in sync message", len); + // } Self { comp_updates: Vec::new(), @@ -124,7 +133,6 @@ impl SyncPackage

{ pub fn with_component<'a, C: Component + Clone + Send + Sync>( mut self, uids: &ReadStorage<'a, Uid>, - uid_tracker: &UpdateTracker, tracker: &impl Tracker, storage: &ReadStorage<'a, C>, filter: impl Join + Copy, @@ -136,13 +144,7 @@ impl SyncPackage

{ P::Phantom: TryInto>, C::Storage: specs::storage::Tracked, { - tracker.get_updates_for( - uids, - storage, - // Don't include updates for deleted entities - (filter, &!uid_tracker.removed()), - &mut self.comp_updates, - ); + tracker.get_updates_for(uids, storage, filter, &mut self.comp_updates); self } } diff --git a/common/src/sync/sync_ext.rs b/common/src/sync/sync_ext.rs index a375667111..1033f666cb 100644 --- a/common/src/sync/sync_ext.rs +++ b/common/src/sync/sync_ext.rs @@ -6,6 +6,7 @@ use super::{ track::UpdateTracker, uid::{Uid, UidAllocator}, }; +use log::error; use specs::{ saveload::{MarkedBuilder, MarkerAllocator}, world::Builder, @@ -20,6 +21,7 @@ pub trait WorldSyncExt { where C::Storage: Default + specs::storage::Tracked; fn create_entity_synced(&mut self) -> specs::EntityBuilder; + fn delete_entity_and_clear_from_uid_allocator(&mut self, uid: u64); fn uid_from_entity(&self, entity: specs::Entity) -> Option; fn entity_from_uid(&self, uid: u64) -> Option; fn apply_entity_package(&mut self, entity_package: EntityPackage

); @@ -35,14 +37,11 @@ impl WorldSyncExt for specs::World { fn register_sync_marker(&mut self) { self.register_synced::(); + // TODO: Consider only having allocator server side for now self.add_resource(UidAllocator::new()); } fn register_synced(&mut self) where - // P: From, - // C: TryFrom, - // P::Phantom: From>, - // P::Phantom: TryInto>, C::Storage: Default + specs::storage::Tracked, { self.register::(); @@ -50,26 +49,12 @@ impl WorldSyncExt for specs::World { } fn register_tracker(&mut self) where - // P: From, - // C: TryFrom, - // P::Phantom: From>, - // P::Phantom: TryInto>, C::Storage: Default + specs::storage::Tracked, { let tracker = UpdateTracker::::new(self); self.add_resource(tracker); } - /*fn insert_synced(&mut self, res: C) - //where - // R: From, - // C: TryFrom, - { - self.add_resource::(res); - - self.res_trackers.insert(ResUpdateTracker::::new()); - }*/ - fn create_entity_synced(&mut self) -> specs::EntityBuilder { self.create_entity().marked::() } @@ -94,6 +79,16 @@ impl WorldSyncExt for specs::World { } } + fn delete_entity_and_clear_from_uid_allocator(&mut self, uid: u64) { + // Clear from uid allocator + let maybe_entity = self.write_resource::().remove_entity(uid); + if let Some(entity) = maybe_entity { + if let Err(err) = self.delete_entity(entity) { + error!("Failed to delete entity: {:?}", err); + } + } + } + fn apply_state_package( &mut self, state_package: StatePackage, @@ -114,7 +109,7 @@ impl WorldSyncExt for specs::World { } // Initialize entities - //specs_world.maintain(); + //self.maintain(); } fn apply_sync_package(&mut self, package: SyncPackage

) { @@ -152,12 +147,7 @@ impl WorldSyncExt for specs::World { // Attempt to delete entities that were marked for deletion for entity_uid in deleted_entities { - let entity = self - .read_resource::() - .retrieve_entity_internal(entity_uid); - if let Some(entity) = entity { - let _ = self.delete_entity(entity); - } + self.delete_entity_and_clear_from_uid_allocator(entity_uid); } } fn apply_res_sync_package(&mut self, package: ResSyncPackage) { @@ -174,5 +164,15 @@ fn create_entity_with_uid(specs_world: &mut specs::World, entity_uid: u64) -> sp .read_resource::() .retrieve_entity_internal(entity_uid); - existing_entity.unwrap_or_else(|| specs_world.create_entity_synced().build()) + match existing_entity { + Some(entity) => entity, + None => { + let entity_builder = specs_world.create_entity(); + let uid = entity_builder + .world + .write_resource::() + .allocate(entity_builder.entity, Some(entity_uid)); + entity_builder.with(uid).build() + } + } } diff --git a/common/src/sync/track.rs b/common/src/sync/track.rs index 2f27551b83..f1137f5d28 100644 --- a/common/src/sync/track.rs +++ b/common/src/sync/track.rs @@ -76,6 +76,7 @@ where specs::storage::ComponentEvent::Modified(id) => { // We don't care about modification if the component was just added or was // removed + // Could potentially remove since this should theoretically never occur... if !self.removed.contains(*id) && !self.inserted.contains(*id) { self.modified.add(*id); } diff --git a/common/src/sync/uid.rs b/common/src/sync/uid.rs index e7dc31b241..87f69e87ed 100644 --- a/common/src/sync/uid.rs +++ b/common/src/sync/uid.rs @@ -56,6 +56,10 @@ impl UidAllocator { mapping: HashMap::new(), } } + // Useful for when a single entity is deleted because it doesn't reconstruct the entire hashmap + pub fn remove_entity(&mut self, id: u64) -> Option { + self.mapping.remove(&id) + } } impl Default for UidAllocator { @@ -69,14 +73,14 @@ impl MarkerAllocator for UidAllocator { let id = id.unwrap_or_else(|| { let id = self.index; self.index += 1; - self.mapping.insert(id, entity); id }); + self.mapping.insert(id, entity); Uid(id) } fn retrieve_entity_internal(&self, id: u64) -> Option { - self.mapping.get(&id).cloned() + self.mapping.get(&id).copied() } fn maintain(&mut self, entities: &EntitiesRes, storage: &ReadStorage) { diff --git a/server/src/cmd.rs b/server/src/cmd.rs index b3303cac21..22606d8ee2 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -21,6 +21,7 @@ use vek::*; use world::util::Sampler; use lazy_static::lazy_static; +use log::error; use scan_fmt::{scan_fmt, scan_fmt_some}; /// Struct representing a command that a user can run from server chat. @@ -1118,7 +1119,9 @@ fn handle_remove_lights( let size = to_delete.len(); for entity in to_delete { - let _ = server.state.ecs_mut().delete_entity(entity); + if let Err(err) = server.state.delete_entity_recorded(entity) { + error!("Failed to delete light: {:?}", err); + } } server.notify_client( diff --git a/server/src/lib.rs b/server/src/lib.rs index 7e2f5729d0..d49d4345b3 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -19,7 +19,7 @@ use crate::{ chunk_generator::ChunkGenerator, client::{Client, RegionSubscription}, cmd::CHAT_COMMANDS, - sys::sentinel::{TrackedComps, TrackedResources}, + sys::sentinel::{DeletedEntities, TrackedComps, TrackedResources}, }; use common::{ assets, comp, @@ -32,7 +32,7 @@ use common::{ terrain::{block::Block, TerrainChunkSize, TerrainGrid}, vol::{ReadVol, RectVolSize, Vox}, }; -use log::debug; +use log::{debug, error}; use metrics::ServerMetrics; use rand::Rng; use specs::{ @@ -166,6 +166,8 @@ impl Server { // Register trackers sys::sentinel::register_trackers(&mut state.ecs_mut()); + state.ecs_mut().add_resource(DeletedEntities::default()); + let this = Self { state, world: Arc::new(world), @@ -309,8 +311,6 @@ impl Server { let server_settings = &self.server_settings; - let mut todo_remove = None; - match event { ServerEvent::Explosion { pos, radius } => { const RAYS: usize = 500; @@ -380,19 +380,20 @@ impl Server { } ServerEvent::Destroy { entity, cause } => { - let ecs = state.ecs(); // Chat message - if let Some(player) = ecs.read_storage::().get(entity) { + if let Some(player) = state.ecs().read_storage::().get(entity) { let msg = if let comp::HealthSource::Attack { by } = cause { - ecs.entity_from_uid(by.into()).and_then(|attacker| { - ecs.read_storage::().get(attacker).map( - |attacker_alias| { + state.ecs().entity_from_uid(by.into()).and_then(|attacker| { + state + .ecs() + .read_storage::() + .get(attacker) + .map(|attacker_alias| { format!( "{} was killed by {}", &player.alias, &attacker_alias.alias ) - }, - ) + }) }) } else { None @@ -402,28 +403,44 @@ impl Server { state.notify_registered_clients(ServerMsg::kill(msg)); } - // Give EXP to the killer if entity had stats - let mut stats = ecs.write_storage::(); - - if let Some(entity_stats) = stats.get(entity).cloned() { - if let comp::HealthSource::Attack { by } = cause { - ecs.entity_from_uid(by.into()).map(|attacker| { - if let Some(attacker_stats) = stats.get_mut(attacker) { - // TODO: Discuss whether we should give EXP by Player Killing or not. - attacker_stats - .exp - .change_by((entity_stats.level.level() * 10) as i64); - } - }); + { + // Give EXP to the killer if entity had stats + let mut stats = state.ecs().write_storage::(); + if let Some(entity_stats) = stats.get(entity).cloned() { + if let comp::HealthSource::Attack { by } = cause { + state.ecs().entity_from_uid(by.into()).map(|attacker| { + if let Some(attacker_stats) = stats.get_mut(attacker) { + // TODO: Discuss whether we should give EXP by Player Killing or not. + attacker_stats + .exp + .change_by((entity_stats.level.level() * 10) as i64); + } + }); + } } } - if let Some(client) = ecs.write_storage::().get_mut(entity) { - let _ = ecs.write_storage().insert(entity, comp::Vel(Vec3::zero())); - let _ = ecs.write_storage().insert(entity, comp::ForceUpdate); + // This sucks + let mut remove = false; + + if let Some(client) = state.ecs().write_storage::().get_mut(entity) { + let _ = state + .ecs() + .write_storage() + .insert(entity, comp::Vel(Vec3::zero())); + let _ = state + .ecs() + .write_storage() + .insert(entity, comp::ForceUpdate); client.force_state(ClientState::Dead); } else { - todo_remove = Some(entity.clone()); + remove = true; + } + + if remove { + if let Err(err) = state.delete_entity_recorded(entity) { + error!("Failed to delete destroyed entity: {:?}", err); + } } } @@ -457,7 +474,9 @@ impl Server { }; if let Some(item_entity) = item_entity { - let _ = state.ecs_mut().delete_entity(item_entity); + if let Err(err) = state.delete_entity_recorded(item_entity) { + error!("Failed to delete picked up item entity: {:?}", err); + } } state.write_component(entity, comp::InventoryUpdate); @@ -728,7 +747,7 @@ impl Server { main, &server_settings, ); - Self::initialize_region_subscription(state, entity); + sys::subscription::initialize_region_subscription(state.ecs(), entity); } ServerEvent::CreateNpc { @@ -746,8 +765,8 @@ impl Server { } ServerEvent::ClientDisconnect(entity) => { - if let Err(err) = state.ecs_mut().delete_entity(entity) { - debug!("Failed to delete disconnected client: {:?}", err); + if let Err(err) = state.delete_entity_recorded(entity) { + error!("Failed to delete disconnected client: {:?}", err); } frontend_events.push(Event::ClientDisconnected { entity }); @@ -761,11 +780,6 @@ impl Server { chat_commands.push((entity, cmd)); } } - - // TODO: is this needed? - if let Some(entity) = todo_remove { - let _ = state.ecs_mut().delete_entity(entity); - } } // Generate requested chunks. @@ -825,7 +839,7 @@ impl Server { frontend_events.append(&mut self.handle_new_connections()?); let before_tick_4 = Instant::now(); - // 4) Tick the client's LocalState. + // 4) Tick the server's LocalState. self.state.tick(dt, sys::add_server_systems); let before_handle_events = Instant::now(); @@ -856,7 +870,9 @@ impl Server { .collect::>() }; for entity in to_delete { - let _ = self.state.ecs_mut().delete_entity(entity); + if let Err(err) = self.state.delete_entity_recorded(entity) { + error!("Failed to delete agent outside the terrain: {:?}", err); + } } let before_tick_7 = Instant::now(); @@ -1004,83 +1020,6 @@ impl Server { Ok(frontend_events) } - /// Initialize region subscription - fn initialize_region_subscription(state: &mut State, entity: specs::Entity) { - let mut subscription = None; - - if let (Some(client_pos), Some(client_vd), Some(client)) = ( - state.ecs().read_storage::().get(entity), - state - .ecs() - .read_storage::() - .get(entity) - .map(|pl| pl.view_distance) - .and_then(|v| v), - state.ecs().write_storage::().get_mut(entity), - ) { - use common::region::RegionMap; - - let fuzzy_chunk = (Vec2::::from(client_pos.0)) - .map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32); - let chunk_size = TerrainChunkSize::RECT_SIZE.reduce_max() as f32; - let regions = common::region::regions_in_vd( - client_pos.0, - (client_vd as f32 * chunk_size) as f32 - + (client::CHUNK_FUZZ as f32 + chunk_size) * 2.0f32.sqrt(), - ); - - for (_, region) in state - .ecs() - .read_resource::() - .iter() - .filter(|(key, _)| regions.contains(key)) - { - // Sync physics of all entities in this region - for (&uid, &pos, vel, ori, character_state, _) in ( - &state.ecs().read_storage::(), - &state.ecs().read_storage::(), // We assume all these entities have a position - state.ecs().read_storage::().maybe(), - state.ecs().read_storage::().maybe(), - state.ecs().read_storage::().maybe(), - region.entities(), - ) - .join() - { - client.notify(ServerMsg::EntityPos { - entity: uid.into(), - pos, - }); - if let Some(vel) = vel.copied() { - client.notify(ServerMsg::EntityVel { - entity: uid.into(), - vel, - }); - } - if let Some(ori) = ori.copied() { - client.notify(ServerMsg::EntityOri { - entity: uid.into(), - ori, - }); - } - if let Some(character_state) = character_state.copied() { - client.notify(ServerMsg::EntityCharacterState { - entity: uid.into(), - character_state, - }); - } - } - } - - subscription = Some(RegionSubscription { - fuzzy_chunk, - regions, - }); - } - if let Some(subscription) = subscription { - state.write_component(entity, subscription); - } - } - pub fn notify_client(&self, entity: EcsEntity, msg: ServerMsg) { if let Some(client) = self.state.ecs().write_storage::().get_mut(entity) { client.notify(msg) @@ -1142,6 +1081,10 @@ trait StateExt { stats: comp::Stats, body: comp::Body, ) -> EcsEntityBuilder; + fn delete_entity_recorded( + &mut self, + entity: EcsEntity, + ) -> Result<(), specs::error::WrongGeneration>; } impl StateExt for State { @@ -1202,4 +1145,28 @@ impl StateExt for State { client.notify(msg.clone()) } } + + fn delete_entity_recorded( + &mut self, + entity: EcsEntity, + ) -> Result<(), specs::error::WrongGeneration> { + let (maybe_uid, maybe_pos) = ( + self.ecs().read_storage::().get(entity).copied(), + self.ecs().read_storage::().get(entity).copied(), + ); + let res = self.ecs_mut().delete_entity(entity); + if res.is_ok() { + if let (Some(uid), Some(pos)) = (maybe_uid, maybe_pos) { + let region_key = self + .ecs() + .read_resource::() + .find_region(entity, pos.0) + .expect("Failed to find region containing entity during entity deletion"); + self.ecs() + .write_resource::() + .record_deleted_entity(uid, region_key); + } + } + res + } } diff --git a/server/src/sys/entity_sync.rs b/server/src/sys/entity_sync.rs index 05611359b6..7bb94fb3a5 100644 --- a/server/src/sys/entity_sync.rs +++ b/server/src/sys/entity_sync.rs @@ -1,5 +1,5 @@ use super::{ - sentinel::{ReadTrackers, TrackedComps, TrackedResources}, + sentinel::{DeletedEntities, ReadTrackers, TrackedComps, TrackedResources}, SysTimer, }; use crate::{ @@ -38,6 +38,7 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, Client>, WriteStorage<'a, ForceUpdate>, WriteStorage<'a, InventoryUpdate>, + Write<'a, DeletedEntities>, TrackedComps<'a>, ReadTrackers<'a>, TrackedResources<'a>, @@ -64,8 +65,9 @@ impl<'a> System<'a> for Sys { mut clients, mut force_updates, mut inventory_updates, + mut deleted_entities, tracked_comps, - read_trackers, + trackers, tracked_resources, ): Self::SystemData, ) { @@ -86,6 +88,8 @@ impl<'a> System<'a> for Sys { // Sync physics // via iterating through regions for (key, region) in region_map.iter() { + // Assemble subscriber list for this region by iterating through clients and checking + // if they are subscribed to this region let mut subscribers = (&mut clients, &entities, &subscriptions, &positions) .join() .filter_map(|(client, entity, subscription, pos)| { @@ -100,6 +104,10 @@ impl<'a> System<'a> for Sys { for event in region.events() { match event { RegionEvent::Entered(id, maybe_key) => { + // Don't process newly created entities here (redundant network messages) + if trackers.uid.inserted().contains(*id) { + continue; + } let entity = entities.entity(*id); if let Some((uid, pos, vel, ori, character_state)) = uids.get(entity).and_then(|uid| { @@ -156,8 +164,15 @@ impl<'a> System<'a> for Sys { } // Sync tracked components + // Get deleted entities in this region from DeletedEntities let sync_msg = ServerMsg::EcsSync( - read_trackers.create_sync_package(&tracked_comps, region.entities()), + trackers.create_sync_package( + &tracked_comps, + region.entities(), + deleted_entities + .take_deleted_in_region(key) + .unwrap_or_else(|| Vec::new()), + ), ); for (client, _, _, _) in &mut subscribers { client.notify(sync_msg.clone()); @@ -169,9 +184,9 @@ impl<'a> System<'a> for Sys { force_update: Option<&ForceUpdate>, throttle: bool| { for (client, _, client_entity, client_pos) in &mut subscribers { - let update = if client_entity == &entity && force_update.is_none() { - // Don't send client physics update about itself - false + let update = if client_entity == &entity { + // Don't send client physics updates about itself unless force update is set + force_update.is_some() } else if !throttle { // Update rate not thottled by distance true @@ -283,6 +298,25 @@ impl<'a> System<'a> for Sys { } } + // Handle entity deletion in regions that don't exist in RegionMap (theoretically none) + for (region_key, deleted) in deleted_entities.take_remaining_deleted() { + for client in + (&mut clients, &subscriptions) + .join() + .filter_map(|(client, subscription)| { + if client.is_ingame() && subscription.regions.contains(®ion_key) { + Some(client) + } else { + None + } + }) + { + for uid in &deleted { + client.notify(ServerMsg::DeleteEntity(*uid)); + } + } + } + // TODO: Sync clients that don't have a position? // Sync inventories diff --git a/server/src/sys/message.rs b/server/src/sys/message.rs index e4cdde00b2..6537e4e01a 100644 --- a/server/src/sys/message.rs +++ b/server/src/sys/message.rs @@ -1,7 +1,7 @@ use super::SysTimer; use crate::{auth_provider::AuthProvider, client::Client, CLIENT_TIMEOUT}; use common::{ - comp::{Admin, Body, CanBuild, Controller, Ori, Player, Pos, Vel}, + comp::{Admin, Body, CanBuild, Controller, ForceUpdate, Ori, Player, Pos, Vel}, event::{EventBus, ServerEvent}, msg::{validate_chat_msg, ChatMsgValidationError, MAX_BYTES_CHAT_MSG}, msg::{ClientMsg, ClientState, RequestStateError, ServerMsg}, @@ -25,6 +25,7 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Body>, ReadStorage<'a, CanBuild>, ReadStorage<'a, Admin>, + ReadStorage<'a, ForceUpdate>, WriteExpect<'a, AuthProvider>, Write<'a, BlockChange>, WriteStorage<'a, Pos>, @@ -46,6 +47,7 @@ impl<'a> System<'a> for Sys { bodies, can_build, admins, + force_updates, mut accounts, mut block_changes, mut positions, @@ -218,9 +220,11 @@ impl<'a> System<'a> for Sys { }, ClientMsg::PlayerPhysics { pos, vel, ori } => match client.client_state { ClientState::Character => { - let _ = positions.insert(entity, pos); - let _ = velocities.insert(entity, vel); - let _ = orientations.insert(entity, ori); + if force_updates.get(entity).is_none() { + let _ = positions.insert(entity, pos); + let _ = velocities.insert(entity, vel); + let _ = orientations.insert(entity, ori); + } } // Only characters can send positions. _ => client.error_state(RequestStateError::Impossible), diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index a3a0f3ba33..381f567ea7 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -5,17 +5,19 @@ use common::{ Projectile, Scale, Stats, Sticky, }, msg::{EcsCompPacket, EcsResPacket}, - state::{Time, TimeOfDay}, + state::TimeOfDay, sync::{ CompPacket, EntityPackage, ResSyncPackage, StatePackage, SyncPackage, Uid, UpdateTracker, WorldSyncExt, }, }; +use hashbrown::HashMap; use shred_derive::SystemData; use specs::{ Entity as EcsEntity, Join, ReadExpect, ReadStorage, System, World, Write, WriteExpect, }; use std::ops::Deref; +use vek::*; /// Always watching /// This system will monitor specific components for insertion, removal, and modification @@ -39,20 +41,20 @@ impl<'a> System<'a> for Sys { // Probably more difficult than it needs to be :p #[derive(SystemData)] pub struct TrackedComps<'a> { - uid: ReadStorage<'a, Uid>, - body: ReadStorage<'a, Body>, - player: ReadStorage<'a, Player>, - stats: ReadStorage<'a, Stats>, - can_build: ReadStorage<'a, CanBuild>, - light_emitter: ReadStorage<'a, LightEmitter>, - item: ReadStorage<'a, Item>, - scale: ReadStorage<'a, Scale>, - mounting: ReadStorage<'a, Mounting>, - mount_state: ReadStorage<'a, MountState>, - mass: ReadStorage<'a, Mass>, - sticky: ReadStorage<'a, Sticky>, - gravity: ReadStorage<'a, Gravity>, - projectile: ReadStorage<'a, Projectile>, + pub uid: ReadStorage<'a, Uid>, + pub body: ReadStorage<'a, Body>, + pub player: ReadStorage<'a, Player>, + pub stats: ReadStorage<'a, Stats>, + pub can_build: ReadStorage<'a, CanBuild>, + pub light_emitter: ReadStorage<'a, LightEmitter>, + pub item: ReadStorage<'a, Item>, + pub scale: ReadStorage<'a, Scale>, + pub mounting: ReadStorage<'a, Mounting>, + pub mount_state: ReadStorage<'a, MountState>, + pub mass: ReadStorage<'a, Mass>, + pub sticky: ReadStorage<'a, Sticky>, + pub gravity: ReadStorage<'a, Gravity>, + pub projectile: ReadStorage<'a, Projectile>, } impl<'a> TrackedComps<'a> { pub fn create_entity_package(&self, entity: EcsEntity) -> EntityPackage { @@ -121,115 +123,53 @@ impl<'a> TrackedComps<'a> { } #[derive(SystemData)] pub struct ReadTrackers<'a> { - uid: ReadExpect<'a, UpdateTracker>, - body: ReadExpect<'a, UpdateTracker>, - player: ReadExpect<'a, UpdateTracker>, - stats: ReadExpect<'a, UpdateTracker>, - can_build: ReadExpect<'a, UpdateTracker>, - light_emitter: ReadExpect<'a, UpdateTracker>, - item: ReadExpect<'a, UpdateTracker>, - scale: ReadExpect<'a, UpdateTracker>, - mounting: ReadExpect<'a, UpdateTracker>, - mount_state: ReadExpect<'a, UpdateTracker>, - mass: ReadExpect<'a, UpdateTracker>, - sticky: ReadExpect<'a, UpdateTracker>, - gravity: ReadExpect<'a, UpdateTracker>, - projectile: ReadExpect<'a, UpdateTracker>, + pub uid: ReadExpect<'a, UpdateTracker>, + pub body: ReadExpect<'a, UpdateTracker>, + pub player: ReadExpect<'a, UpdateTracker>, + pub stats: ReadExpect<'a, UpdateTracker>, + pub can_build: ReadExpect<'a, UpdateTracker>, + pub light_emitter: ReadExpect<'a, UpdateTracker>, + pub item: ReadExpect<'a, UpdateTracker>, + pub scale: ReadExpect<'a, UpdateTracker>, + pub mounting: ReadExpect<'a, UpdateTracker>, + pub mount_state: ReadExpect<'a, UpdateTracker>, + pub mass: ReadExpect<'a, UpdateTracker>, + pub sticky: ReadExpect<'a, UpdateTracker>, + pub gravity: ReadExpect<'a, UpdateTracker>, + pub projectile: ReadExpect<'a, UpdateTracker>, } impl<'a> ReadTrackers<'a> { pub fn create_sync_package( &self, comps: &TrackedComps, filter: impl Join + Copy, + deleted_entities: Vec, ) -> SyncPackage { - SyncPackage::new(&comps.uid, &self.uid, filter) + SyncPackage::new(&comps.uid, &self.uid, filter, deleted_entities) + .with_component(&comps.uid, self.body.deref(), &comps.body, filter) + .with_component(&comps.uid, self.player.deref(), &comps.player, filter) + .with_component(&comps.uid, self.stats.deref(), &comps.stats, filter) + .with_component(&comps.uid, self.can_build.deref(), &comps.can_build, filter) .with_component( &comps.uid, - &self.uid, - self.body.deref(), - &comps.body, - filter, - ) - .with_component( - &comps.uid, - &self.uid, - self.player.deref(), - &comps.player, - filter, - ) - .with_component( - &comps.uid, - &self.uid, - self.stats.deref(), - &comps.stats, - filter, - ) - .with_component( - &comps.uid, - &self.uid, - self.can_build.deref(), - &comps.can_build, - filter, - ) - .with_component( - &comps.uid, - &self.uid, self.light_emitter.deref(), &comps.light_emitter, filter, ) + .with_component(&comps.uid, self.item.deref(), &comps.item, filter) + .with_component(&comps.uid, self.scale.deref(), &comps.scale, filter) + .with_component(&comps.uid, self.mounting.deref(), &comps.mounting, filter) .with_component( &comps.uid, - &self.uid, - self.item.deref(), - &comps.item, - filter, - ) - .with_component( - &comps.uid, - &self.uid, - self.scale.deref(), - &comps.scale, - filter, - ) - .with_component( - &comps.uid, - &self.uid, - self.mounting.deref(), - &comps.mounting, - filter, - ) - .with_component( - &comps.uid, - &self.uid, self.mount_state.deref(), &comps.mount_state, filter, ) + .with_component(&comps.uid, self.mass.deref(), &comps.mass, filter) + .with_component(&comps.uid, self.sticky.deref(), &comps.sticky, filter) + .with_component(&comps.uid, self.gravity.deref(), &comps.gravity, filter) .with_component( &comps.uid, - &self.uid, - self.mass.deref(), - &comps.mass, - filter, - ) - .with_component( - &comps.uid, - &self.uid, - self.sticky.deref(), - &comps.sticky, - filter, - ) - .with_component( - &comps.uid, - &self.uid, - self.gravity.deref(), - &comps.gravity, - filter, - ) - .with_component( - &comps.uid, - &self.uid, self.projectile.deref(), &comps.projectile, filter, @@ -292,19 +232,46 @@ pub fn register_trackers(world: &mut World) { #[derive(SystemData)] pub struct TrackedResources<'a> { - time: ReadExpect<'a, Time>, time_of_day: ReadExpect<'a, TimeOfDay>, } impl<'a> TrackedResources<'a> { pub fn create_res_sync_package(&self) -> ResSyncPackage { - ResSyncPackage::new() - .with_res(self.time.deref()) - .with_res(self.time_of_day.deref()) + ResSyncPackage::new().with_res(self.time_of_day.deref()) } /// Create state package with resources included pub fn state_package(&self) -> StatePackage { - StatePackage::new() - .with_res(self.time.deref()) - .with_res(self.time_of_day.deref()) + StatePackage::new().with_res(self.time_of_day.deref()) + } +} + +/// Deleted entities grouped by region +pub struct DeletedEntities { + map: HashMap, Vec>, +} + +impl Default for DeletedEntities { + fn default() -> Self { + Self { + map: HashMap::new(), + } + } +} + +impl DeletedEntities { + pub fn record_deleted_entity(&mut self, uid: Uid, region_key: Vec2) { + self.map + .entry(region_key) + .or_insert(Vec::new()) + .push(uid.into()); + } + pub fn take_deleted_in_region(&mut self, key: Vec2) -> Option> { + self.map.remove(&key) + } + pub fn get_deleted_in_region(&mut self, key: Vec2) -> Option<&Vec> { + self.map.get(&key) + } + pub fn take_remaining_deleted(&mut self) -> Vec<(Vec2, Vec)> { + // TODO: don't allocate + self.map.drain().collect() } } diff --git a/server/src/sys/subscription.rs b/server/src/sys/subscription.rs index d4617fd499..a37d4057b7 100644 --- a/server/src/sys/subscription.rs +++ b/server/src/sys/subscription.rs @@ -1,4 +1,7 @@ -use super::{sentinel::TrackedComps, SysTimer}; +use super::{ + sentinel::{DeletedEntities, TrackedComps}, + SysTimer, +}; use crate::client::{self, Client, RegionSubscription}; use common::{ comp::{CharacterState, Ori, Player, Pos, Vel}, @@ -8,7 +11,10 @@ use common::{ terrain::TerrainChunkSize, vol::RectVolSize, }; -use specs::{Entities, Join, ReadExpect, ReadStorage, System, Write, WriteStorage}; +use log::{debug, error}; +use specs::{ + Entities, Join, ReadExpect, ReadStorage, System, SystemData, World, Write, WriteStorage, +}; use vek::*; /// This system will update region subscriptions based on client positions @@ -26,6 +32,7 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Player>, WriteStorage<'a, Client>, WriteStorage<'a, RegionSubscription>, + Write<'a, DeletedEntities>, TrackedComps<'a>, ); @@ -43,6 +50,7 @@ impl<'a> System<'a> for Sys { players, mut clients, mut subscriptions, + mut deleted_entities, tracked_comps, ): Self::SystemData, ) { @@ -68,8 +76,15 @@ impl<'a> System<'a> for Sys { &entities, ) .join() - .filter_map(|(c, s, pos, player, e)| player.view_distance.map(|v| (c, s, pos, v, e))) + .filter_map(|(client, s, pos, player, e)| { + if client.is_ingame() { + player.view_distance.map(|v| (client, s, pos, v, e)) + } else { + None + } + }) { + // Calculate current chunk let chunk = (Vec2::::from(pos.0)) .map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32); // Only update regions when moving to a new chunk @@ -87,7 +102,7 @@ impl<'a> System<'a> for Sys { .reduce_or() { // Update current chunk - subscription.fuzzy_chunk = (Vec2::::from(pos.0)) + subscription.fuzzy_chunk = dbg!(Vec2::::from(pos.0)) .map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32); // Use the largest side length as our chunk size let chunk_size = TerrainChunkSize::RECT_SIZE.reduce_max() as f32; @@ -108,19 +123,24 @@ impl<'a> System<'a> for Sys { // Iterate through regions to remove for key in regions_to_remove.drain(..) { - // Remove region from this clients set of subscribed regions + // Remove region from this client's set of subscribed regions subscription.regions.remove(&key); // Tell the client to delete the entities in that region if it exists in the RegionMap if let Some(region) = region_map.get(key) { - // Process entity left events since they won't be processed during phsyics sync because this region is no longer subscribed to + // Process entity left events since they won't be processed during entity sync because this region is no longer subscribed to + // TODO: consider changing system ordering?? for event in region.events() { match event { RegionEvent::Entered(_, _) => {} // These don't need to be processed because this region is being thrown out anyway RegionEvent::Left(id, maybe_key) => { // Lookup UID for entity + // Doesn't overlap with entity deletion in sync packages + // because the uid would not be available if the entity was + // deleted if let Some(&uid) = uids.get(entities.entity(*id)) { if !maybe_key .as_ref() + // Don't need to check that this isn't also in the regions to remove since the entity will be removed when we get to that one .map(|key| subscription.regions.contains(key)) .unwrap_or(false) { @@ -130,10 +150,19 @@ impl<'a> System<'a> for Sys { } } } + // Tell client to delete entities in the region for (&uid, _) in (&uids, region.entities()).join() { - client.notify(ServerMsg::DeleteEntity(uid.into())) + client.notify(ServerMsg::DeleteEntity(uid.into())); } } + // Send deleted entities since they won't be processed for this client in entity sync + for uid in deleted_entities + .get_deleted_in_region(key) + .iter() + .flat_map(|v| v.iter()) + { + client.notify(ServerMsg::DeleteEntity(*uid)); + } } for key in regions_in_vd( @@ -141,8 +170,10 @@ impl<'a> System<'a> for Sys { (vd as f32 * chunk_size) + (client::CHUNK_FUZZ as f32 + chunk_size) * 2.0f32.sqrt(), ) { - // Send client intial info about the entities in this region - if subscription.regions.insert(key) { + // Send client intial info about the entities in this region if it was not + // already within the set of subscribed regions + if subscription.regions.insert(key.clone()) { + let mut counter = 0; if let Some(region) = region_map.get(key) { for (uid, pos, vel, ori, character_state, _, entity) in ( &uids, @@ -156,6 +187,7 @@ impl<'a> System<'a> for Sys { .join() .filter(|(_, _, _, _, _, _, e)| *e != client_entity) { + counter += 1; // Send message to create entity and tracked components client.notify(ServerMsg::CreateEntity( tracked_comps.create_entity_package(entity), @@ -179,3 +211,69 @@ impl<'a> System<'a> for Sys { timer.end(); } } + +/// Initialize region subscription +pub fn initialize_region_subscription(world: &World, entity: specs::Entity) { + if let (Some(client_pos), Some(client_vd), Some(client)) = ( + world.read_storage::().get(entity), + world + .read_storage::() + .get(entity) + .map(|pl| pl.view_distance) + .and_then(|v| v), + world.write_storage::().get_mut(entity), + ) { + let fuzzy_chunk = (Vec2::::from(client_pos.0)) + .map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32); + let chunk_size = TerrainChunkSize::RECT_SIZE.reduce_max() as f32; + let regions = common::region::regions_in_vd( + client_pos.0, + (client_vd as f32 * chunk_size) as f32 + + (client::CHUNK_FUZZ as f32 + chunk_size) * 2.0f32.sqrt(), + ); + + let region_map = world.read_resource::(); + let tracked_comps = TrackedComps::fetch(&world.res); + for key in ®ions { + if let Some(region) = region_map.get(*key) { + for (uid, pos, vel, ori, character_state, _, entity) in ( + &tracked_comps.uid, + &world.read_storage::(), // We assume all these entities have a position + world.read_storage::().maybe(), + world.read_storage::().maybe(), + world.read_storage::().maybe(), + region.entities(), + &world.entities(), + ) + .join() + { + // Send message to create entity and tracked components + client.notify(ServerMsg::CreateEntity( + tracked_comps.create_entity_package(entity), + )); + // Send message to create physics components + super::entity_sync::send_initial_unsynced_components( + client, + uid, + pos, + vel, + ori, + character_state, + ); + } + } + } + + if let Err(err) = world.write_storage().insert( + entity, + RegionSubscription { + fuzzy_chunk, + regions, + }, + ) { + error!("Failed to insert region subscription component: {:?}", err); + } + } else { + debug!("Failed to initialize region subcription. Couldn't retrieve all the neccesary components on the provided entity"); + } +} diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 3c4308356e..da4b978067 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -112,6 +112,7 @@ widget_ids! { velocity, loaded_distance, time, + entity_count, // Game Version version, @@ -872,11 +873,19 @@ impl Hud { .font_id(self.fonts.cyri) .font_size(14) .set(self.ids.time, ui_widgets); + // Number of entities + let entity_count = client.state().ecs().entities().join().count(); + Text::new(&format!("Entity count: {}", entity_count)) + .color(TEXT_COLOR) + .down_from(self.ids.time, 5.0) + .font_id(self.fonts.cyri) + .font_size(14) + .set(self.ids.entity_count, ui_widgets); // Help Window Text::new("Press 'F1' to show Keybindings") .color(TEXT_COLOR) - .down_from(self.ids.time, 5.0) + .down_from(self.ids.entity_count, 5.0) .font_id(self.fonts.cyri) .font_size(14) .set(self.ids.help_info, ui_widgets); diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index ce7a484676..2ade596ad0 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -324,7 +324,7 @@ impl WorldSim { let logistic_cdf = |x: f64| (x / logistic_2_base).tanh() * 0.5 + 0.5; let erosion_pow = 2.0; - let n_steps = 100; + let n_steps = 7; let erosion_factor = |x: f64| logistic_cdf(erosion_pow * logit(x)); let alt = do_erosion( 0.0, From c3ac251fa81fa384b012f51a425bbc1efb3497c4 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sat, 30 Nov 2019 00:33:17 -0500 Subject: [PATCH 04/11] Stop syncing Projectile component to the client --- common/src/msg/ecs_packet.rs | 20 ++++++---- common/src/state.rs | 4 +- common/src/sync/packet.rs | 11 ------ common/src/sys/phys.rs | 3 +- server/src/sys/sentinel.rs | 68 ++++++++++++++++------------------ server/src/sys/subscription.rs | 4 +- 6 files changed, 49 insertions(+), 61 deletions(-) diff --git a/common/src/msg/ecs_packet.rs b/common/src/msg/ecs_packet.rs index 28964041ab..4dd487de70 100644 --- a/common/src/msg/ecs_packet.rs +++ b/common/src/msg/ecs_packet.rs @@ -3,19 +3,25 @@ use serde_derive::{Deserialize, Serialize}; use std::marker::PhantomData; use sum_type::sum_type; +// TODO: remove me +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum MustHaveMoreThanOneVariant {} + // Automatically derive From for EcsResPacket // for each variant EcsResPacket::T(T). sum_type! { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum EcsResPacket { - Time(state::Time), + //Time(state::Time), + MustHaveMoreThanOneVariant(MustHaveMoreThanOneVariant), TimeOfDay(state::TimeOfDay), } } impl sync::ResPacket for EcsResPacket { fn apply(self, world: &specs::World) { match self { - EcsResPacket::Time(time) => sync::handle_res_update(time, world), + //EcsResPacket::Time(time) => sync::handle_res_update(time, world), + EcsResPacket::MustHaveMoreThanOneVariant(_) => unimplemented!(), EcsResPacket::TimeOfDay(time_of_day) => sync::handle_res_update(time_of_day, world), } } @@ -35,7 +41,7 @@ sum_type! { MountState(comp::MountState), Mounting(comp::Mounting), Mass(comp::Mass), - Projectile(comp::Projectile), + //Projectile(comp::Projectile), Gravity(comp::Gravity), Sticky(comp::Sticky), } @@ -55,7 +61,7 @@ sum_type! { MountState(PhantomData), Mounting(PhantomData), Mass(PhantomData), - Projectile(PhantomData), + //Projectile(PhantomData), Gravity(PhantomData), Sticky(PhantomData), } @@ -74,7 +80,7 @@ impl sync::CompPacket for EcsCompPacket { EcsCompPacket::MountState(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Mounting(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Mass(comp) => sync::handle_insert(comp, entity, world), - EcsCompPacket::Projectile(comp) => sync::handle_insert(comp, entity, world), + //EcsCompPacket::Projectile(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Gravity(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Sticky(comp) => sync::handle_insert(comp, entity, world), } @@ -91,7 +97,7 @@ impl sync::CompPacket for EcsCompPacket { EcsCompPacket::MountState(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Mounting(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Mass(comp) => sync::handle_modify(comp, entity, world), - EcsCompPacket::Projectile(comp) => sync::handle_modify(comp, entity, world), + //EcsCompPacket::Projectile(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Gravity(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Sticky(comp) => sync::handle_modify(comp, entity, world), } @@ -110,7 +116,7 @@ impl sync::CompPacket for EcsCompPacket { EcsCompPhantom::MountState(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Mounting(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Mass(_) => sync::handle_remove::(entity, world), - EcsCompPhantom::Projectile(_) => sync::handle_remove::(entity, world), + //EcsCompPhantom::Projectile(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Gravity(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Sticky(_) => sync::handle_remove::(entity, world), } diff --git a/common/src/state.rs b/common/src/state.rs index a2120e60c6..af8ac3841b 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -119,7 +119,6 @@ impl State { ecs.register::(); ecs.register::(); ecs.register::(); - ecs.register::(); // Register components send from clients -> server ecs.register::(); @@ -143,9 +142,9 @@ impl State { ecs.register::(); ecs.register::(); ecs.register::(); - ecs.register::(); ecs.register::(); ecs.register::(); + ecs.register::(); // Register synced resources used by the ECS. ecs.add_resource(TimeOfDay(0.0)); @@ -156,6 +155,7 @@ impl State { ecs.add_resource(TerrainGrid::new().unwrap()); ecs.add_resource(BlockChange::default()); ecs.add_resource(TerrainChanges::default()); + // TODO: only register on the server ecs.add_resource(EventBus::::default()); ecs.add_resource(EventBus::::default()); ecs.add_resource(EventBus::::default()); diff --git a/common/src/sync/packet.rs b/common/src/sync/packet.rs index f12d409960..08c1d339e8 100644 --- a/common/src/sync/packet.rs +++ b/common/src/sync/packet.rs @@ -112,17 +112,6 @@ impl SyncPackage

{ .join() .map(|(uid, _, _)| (*uid).into()) .collect(); - // TODO: handle modified uid? - //created_entities.append(&mut (uids, filter, uid_tracker.inserted()).join().map(|(uid, _, _)| uid).collect()); - // let deleted_entities = (uids.maybe(), filter, uid_tracker.removed()) - // .join() - // Why doesn't this panic?? - // .map(|(uid, _, _)| Into::::into(*uid.unwrap())) - // .collect::>(); - //let len = deleted_entities.len(); - //if len > 0 { - // println!("deleted {} in sync message", len); - // } Self { comp_updates: Vec::new(), diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index d0a9f133a9..4b1b89d62b 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -342,13 +342,14 @@ impl<'a> System<'a> for Sys { } // Apply pushback - for (pos, scale, mass, vel, _, _, physics) in ( + for (pos, scale, mass, vel, _, _, _, physics) in ( &positions, scales.maybe(), masses.maybe(), &mut velocities, &bodies, !&mountings, + !&stickies, // Can't push stickies around &mut physics_states, ) .join() diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index 381f567ea7..bb59f42edf 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -1,8 +1,8 @@ use super::SysTimer; use common::{ comp::{ - Body, CanBuild, Gravity, Item, LightEmitter, Mass, MountState, Mounting, Player, - Projectile, Scale, Stats, Sticky, + Body, CanBuild, Gravity, Item, LightEmitter, Mass, MountState, Mounting, Player, Scale, + Stats, Sticky, }, msg::{EcsCompPacket, EcsResPacket}, state::TimeOfDay, @@ -16,7 +16,6 @@ use shred_derive::SystemData; use specs::{ Entity as EcsEntity, Join, ReadExpect, ReadStorage, System, World, Write, WriteExpect, }; -use std::ops::Deref; use vek::*; /// Always watching @@ -54,7 +53,7 @@ pub struct TrackedComps<'a> { pub mass: ReadStorage<'a, Mass>, pub sticky: ReadStorage<'a, Sticky>, pub gravity: ReadStorage<'a, Gravity>, - pub projectile: ReadStorage<'a, Projectile>, + //pub projectile: ReadStorage<'a, Projectile>, } impl<'a> TrackedComps<'a> { pub fn create_entity_package(&self, entity: EcsEntity) -> EntityPackage { @@ -113,10 +112,10 @@ impl<'a> TrackedComps<'a> { .get(entity) .copied() .map(|c| packets.push(c.into())); - self.projectile - .get(entity) - .cloned() - .map(|c| packets.push(c.into())); + //self.projectile + // .get(entity) + // .cloned() + // .map(|c| packets.push(c.into())); EntityPackage(uid, packets) } @@ -136,7 +135,7 @@ pub struct ReadTrackers<'a> { pub mass: ReadExpect<'a, UpdateTracker>, pub sticky: ReadExpect<'a, UpdateTracker>, pub gravity: ReadExpect<'a, UpdateTracker>, - pub projectile: ReadExpect<'a, UpdateTracker>, + //pub projectile: ReadExpect<'a, UpdateTracker>, } impl<'a> ReadTrackers<'a> { pub fn create_sync_package( @@ -146,34 +145,29 @@ impl<'a> ReadTrackers<'a> { deleted_entities: Vec, ) -> SyncPackage { SyncPackage::new(&comps.uid, &self.uid, filter, deleted_entities) - .with_component(&comps.uid, self.body.deref(), &comps.body, filter) - .with_component(&comps.uid, self.player.deref(), &comps.player, filter) - .with_component(&comps.uid, self.stats.deref(), &comps.stats, filter) - .with_component(&comps.uid, self.can_build.deref(), &comps.can_build, filter) + .with_component(&comps.uid, &*self.body, &comps.body, filter) + .with_component(&comps.uid, &*self.player, &comps.player, filter) + .with_component(&comps.uid, &*self.stats, &comps.stats, filter) + .with_component(&comps.uid, &*self.can_build, &comps.can_build, filter) .with_component( &comps.uid, - self.light_emitter.deref(), + &*self.light_emitter, &comps.light_emitter, filter, ) - .with_component(&comps.uid, self.item.deref(), &comps.item, filter) - .with_component(&comps.uid, self.scale.deref(), &comps.scale, filter) - .with_component(&comps.uid, self.mounting.deref(), &comps.mounting, filter) - .with_component( - &comps.uid, - self.mount_state.deref(), - &comps.mount_state, - filter, - ) - .with_component(&comps.uid, self.mass.deref(), &comps.mass, filter) - .with_component(&comps.uid, self.sticky.deref(), &comps.sticky, filter) - .with_component(&comps.uid, self.gravity.deref(), &comps.gravity, filter) - .with_component( - &comps.uid, - self.projectile.deref(), - &comps.projectile, - filter, - ) + .with_component(&comps.uid, &*self.item, &comps.item, filter) + .with_component(&comps.uid, &*self.scale, &comps.scale, filter) + .with_component(&comps.uid, &*self.mounting, &comps.mounting, filter) + .with_component(&comps.uid, &*self.mount_state, &comps.mount_state, filter) + .with_component(&comps.uid, &*self.mass, &comps.mass, filter) + .with_component(&comps.uid, &*self.sticky, &comps.sticky, filter) + .with_component(&comps.uid, &*self.gravity, &comps.gravity, filter) + //.with_component( + // &comps.uid, + // self.projectile.deref(), + // &comps.projectile, + // filter, + //) } } @@ -192,7 +186,7 @@ pub struct WriteTrackers<'a> { mass: WriteExpect<'a, UpdateTracker>, sticky: WriteExpect<'a, UpdateTracker>, gravity: WriteExpect<'a, UpdateTracker>, - projectile: WriteExpect<'a, UpdateTracker>, + //projectile: WriteExpect<'a, UpdateTracker>, } fn record_changes(comps: &TrackedComps, trackers: &mut WriteTrackers) { @@ -210,7 +204,7 @@ fn record_changes(comps: &TrackedComps, trackers: &mut WriteTrackers) { trackers.mass.record_changes(&comps.mass); trackers.sticky.record_changes(&comps.sticky); trackers.gravity.record_changes(&comps.gravity); - trackers.projectile.record_changes(&comps.projectile); + //trackers.projectile.record_changes(&comps.projectile); } pub fn register_trackers(world: &mut World) { @@ -227,7 +221,7 @@ pub fn register_trackers(world: &mut World) { world.register_tracker::(); world.register_tracker::(); world.register_tracker::(); - world.register_tracker::(); + //world.register_tracker::(); } #[derive(SystemData)] @@ -236,11 +230,11 @@ pub struct TrackedResources<'a> { } impl<'a> TrackedResources<'a> { pub fn create_res_sync_package(&self) -> ResSyncPackage { - ResSyncPackage::new().with_res(self.time_of_day.deref()) + ResSyncPackage::new().with_res(&*self.time_of_day) } /// Create state package with resources included pub fn state_package(&self) -> StatePackage { - StatePackage::new().with_res(self.time_of_day.deref()) + StatePackage::new().with_res(&*self.time_of_day) } } diff --git a/server/src/sys/subscription.rs b/server/src/sys/subscription.rs index a37d4057b7..ef6cc59659 100644 --- a/server/src/sys/subscription.rs +++ b/server/src/sys/subscription.rs @@ -102,7 +102,7 @@ impl<'a> System<'a> for Sys { .reduce_or() { // Update current chunk - subscription.fuzzy_chunk = dbg!(Vec2::::from(pos.0)) + subscription.fuzzy_chunk = Vec2::::from(pos.0) .map2(TerrainChunkSize::RECT_SIZE, |e, sz| e as i32 / sz as i32); // Use the largest side length as our chunk size let chunk_size = TerrainChunkSize::RECT_SIZE.reduce_max() as f32; @@ -173,7 +173,6 @@ impl<'a> System<'a> for Sys { // Send client intial info about the entities in this region if it was not // already within the set of subscribed regions if subscription.regions.insert(key.clone()) { - let mut counter = 0; if let Some(region) = region_map.get(key) { for (uid, pos, vel, ori, character_state, _, entity) in ( &uids, @@ -187,7 +186,6 @@ impl<'a> System<'a> for Sys { .join() .filter(|(_, _, _, _, _, _, e)| *e != client_entity) { - counter += 1; // Send message to create entity and tracked components client.notify(ServerMsg::CreateEntity( tracked_comps.create_entity_package(entity), From d341073a44d0f89f6812328acf4540c65e539107 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sat, 30 Nov 2019 01:41:20 -0500 Subject: [PATCH 05/11] Upgrade to specs 0.15.1 --- Cargo.lock | 198 ++++------------------- client/Cargo.toml | 2 +- client/src/lib.rs | 2 +- common/Cargo.toml | 6 +- common/src/region.rs | 3 +- common/src/state.rs | 24 +-- common/src/sync/packet.rs | 2 +- common/src/sync/sync_ext.rs | 5 +- common/src/sync/track.rs | 2 +- server/Cargo.toml | 8 +- server/src/cmd.rs | 2 +- server/src/lib.rs | 37 ++--- server/src/sys/sentinel.rs | 4 +- server/src/sys/subscription.rs | 5 +- voxygen/Cargo.toml | 2 +- voxygen/src/audio/sfx/event_mapper.rs | 2 +- voxygen/src/audio/sfx/mod.rs | 1 + voxygen/src/hud/map.rs | 1 + voxygen/src/hud/minimap.rs | 1 + voxygen/src/hud/mod.rs | 2 +- voxygen/src/hud/social.rs | 2 +- voxygen/src/menu/char_selection/scene.rs | 1 + voxygen/src/scene/figure/mod.rs | 2 +- voxygen/src/scene/mod.rs | 2 +- voxygen/src/session.rs | 2 +- 25 files changed, 83 insertions(+), 235 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a945449cd7..ea89d274a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -706,17 +706,6 @@ dependencies = [ "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crossbeam" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-deque 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "crossbeam" version = "0.7.2" @@ -730,18 +719,6 @@ dependencies = [ "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crossbeam-channel" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crossbeam-epoch 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "crossbeam-channel" version = "0.3.9" @@ -750,15 +727,6 @@ dependencies = [ "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crossbeam-deque" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "crossbeam-deque" version = "0.7.2" @@ -768,32 +736,6 @@ dependencies = [ "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crossbeam-epoch" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "crossbeam-epoch" version = "0.7.2" @@ -836,11 +778,6 @@ dependencies = [ "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crossbeam-utils" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "crossbeam-utils" version = "0.6.6" @@ -1151,14 +1088,6 @@ name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "gdk" version = "0.8.0" @@ -1538,7 +1467,7 @@ dependencies = [ [[package]] name = "hibitset" -version = "0.5.4" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atom 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1734,15 +1663,6 @@ name = "linked-hash-map" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "lock_api" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "lock_api" version = "0.3.1" @@ -1832,11 +1752,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "memoffset" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "memoffset" version = "0.5.3" @@ -2019,11 +1934,6 @@ dependencies = [ "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "nonzero_signed" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "notify" version = "5.0.0-pre.1" @@ -2219,14 +2129,6 @@ dependencies = [ "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "owning_ref" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "pango" version = "0.4.0" @@ -2261,15 +2163,6 @@ dependencies = [ "parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "parking_lot" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "parking_lot" version = "0.9.0" @@ -2291,18 +2184,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "parking_lot_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "parking_lot_core" version = "0.6.2" @@ -2973,11 +2854,6 @@ name = "scoped_threadpool" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "scopeguard" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "scopeguard" version = "1.0.0" @@ -3067,19 +2943,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "shred" -version = "0.7.2" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hashbrown 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "mopa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "shred-derive 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "shred-derive" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3167,31 +3044,28 @@ dependencies = [ [[package]] name = "specs" -version = "0.14.3" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "derivative 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hibitset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hashbrown 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "hibitset 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "mopa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "nonzero_signed 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", - "shred 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "shred-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "shred 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)", "shrev 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tuple_utils 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tuple_utils 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "specs-idvs" version = "0.1.0" -source = "git+https://gitlab.com/veloren/specs-idvs.git#4ce792042f951a29874954582234836c0eccaed6" +source = "git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15#55547cdf1358c667ac8a7d4c79857143bde2843c" dependencies = [ - "hibitset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", + "hibitset 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3432,7 +3306,7 @@ dependencies = [ [[package]] name = "tuple_utils" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3554,7 +3428,7 @@ dependencies = [ "image 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", - "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", + "specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", "uvth 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "veloren-common 0.4.0", @@ -3570,7 +3444,6 @@ dependencies = [ "dot_vox 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "find_folder 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "hibitset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3586,8 +3459,8 @@ dependencies = [ "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", - "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", - "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git)", + "specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", + "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15)", "sum_type 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3599,7 +3472,6 @@ dependencies = [ "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "hashbrown 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "hibitset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "portpicker 0.1.0 (git+https://github.com/wusyong/portpicker-rs?branch=fix_ipv6)", @@ -3611,10 +3483,8 @@ dependencies = [ "scan_fmt 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", - "shred 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "shred-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", - "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git)", + "specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", + "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15)", "uvth 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "veloren-common 0.4.0", @@ -3666,7 +3536,7 @@ dependencies = [ "rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", - "specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)", + "specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "veloren-client 0.4.0", "veloren-common 0.4.0", @@ -4038,19 +3908,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "938703e165481c8d612ea3479ac8342e5615185db37765162e762ec3523e2fc6" "checksum criterion-plot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eccdc6ce8bbe352ca89025bee672aa6d24f4eb8c53e3a8b5d1bc58011da072a2" -"checksum crossbeam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d7408247b1b87f480890f28b670c5f8d9a8a4274833433fe74dc0dfd46d33650" "checksum crossbeam 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2d818a4990769aac0c7ff1360e233ef3a41adcb009ebb2036bf6915eb0f6b23c" -"checksum crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7b85741761b7f160bc5e7e0c14986ef685b7f8bf9b7ad081c60c604bb4649827" "checksum crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa" -"checksum crossbeam-deque 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7792c4a9b5a4222f654e3728a3dd945aacc24d2c3a1a096ed265d80e4929cb9a" "checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" -"checksum crossbeam-epoch 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30fecfcac6abfef8771151f8be4abc9e4edc112c2bcb233314cafde2680536e9" -"checksum crossbeam-epoch 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2449aaa4ec7ef96e5fb24db16024b935df718e9ae1cec0a1e68feeca2efca7b8" "checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9" "checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" "checksum crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfd6515864a82d2f877b42813d4553292c6659498c9a2aa31bab5a15243c2700" -"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015" "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" "checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" "checksum csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37519ccdfd73a75821cac9319d4fce15a81b9fcf75f951df5b9988aa3a0af87d" @@ -4088,7 +3952,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" "checksum gdk 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd30051ff3d908ff2fc7e5776ffe1c699821e043809f294c3a61004f11d6c3a9" "checksum gdk-pixbuf 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c2d2199eba47ebcb9977ce28179649bdd59305ef465c4e6f9b65aaa41c24e6b5" "checksum gdk-pixbuf-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df6a3b73e04fafc07f5ebc083f1096a773412e627828e1103a55e921f81187d8" @@ -4123,7 +3986,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum gzip-header 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0131feb3d3bb2a5a238d8a4d09f6353b7ebfdc52e77bccbf4ea6eaa751dde639" "checksum hashbrown 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8e6073d0ca812575946eb5f35ff68dbe519907b25c42530389ff946dc84c6ead" "checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" -"checksum hibitset 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6527bc88f32e0d3926c7572874b2bf17a19b36978aacd0aacf75f7d27a5992d0" +"checksum hibitset 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "47e7292fd9f7fe89fa35c98048f2d0a69b79ed243604234d18f6f8a1aa6f408d" "checksum hound 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" "checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" @@ -4149,7 +4012,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" "checksum line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5cc7ad3d82c845bdb5dde34ffdcc7a5fb4d2996e1e1ee0f19c33bc80e15196b9" "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" -"checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" @@ -4162,7 +4024,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" "checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" -"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum mime_guess 1.8.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0d977de9ee851a0b16e932979515c0f3da82403183879811bc97d50bd9cc50f7" @@ -4181,7 +4042,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum noise 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "337525774dd8a197b613a01ea88058ef0ed023e5ed1e4b7e93de478e1f2bf770" "checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" -"checksum nonzero_signed 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "02783a0482333b0d3f5f5411b8fb60454a596696da041da0470ac9ef3e6e37d8" "checksum notify 5.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d742ae493f34bd2e20ec2f3c1276fc1981343a8efd7ef12bca4368d0303bed50" "checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" "checksum num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf4825417e1e1406b3782a8ce92f4d53f26ec055e3622e1881ca8e9f5f9e08db" @@ -4202,14 +4062,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" "checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" -"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum pango 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45374801e224373c3c0393cd48073c81093494c8735721e81d1dbaa4096b2767" "checksum pango-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94039b3921a4af4058a3e4335e5d15099101f298a92f5afc40bab3a3027594a1" "checksum parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "149d8f5b97f3c1133e3cfcd8886449959e856b557ff281e292b733d7c69e005e" -"checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" "checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" -"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" "checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" @@ -4286,7 +4143,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" "checksum scan_fmt 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "faf737f37ca340201889b5f48ecde47f233e9da3cbf3d04be27883adac39b4da" "checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" -"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" "checksum sdl2 0.32.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d051a07231e303f5f719da78cb6f7394f6d5b54f733aef5b0b447804a83edd7b" "checksum sdl2-sys 0.32.6 (registry+https://github.com/rust-lang/crates.io-index)" = "34e71125077d297d57e4c1acfe8981b5bdfbf5a20e7b589abfdcb33bf1127f86" @@ -4298,8 +4154,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" "checksum shared_library 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" "checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" -"checksum shred 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6ea122e6133568144fcfb5888737d4ac776ebc959f989dd65b907136ac22bfed" -"checksum shred-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fcf34e5e5302d3024aba7afc291f6d1ca7573ed035d3c0796976ba3f10691a1" +"checksum shred 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)" = "92472b9bafafbcba21935c6444d924e5332742f6778c49504a49a97eaeff6ccc" +"checksum shred-derive 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c245c03fd923292ae18e01eadf65606fdc995c175433104ef3eee956db7c2d7" "checksum shrev 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5752e017e03af9d735b4b069f53b7a7fd90fefafa04d8bd0c25581b0bff437f" "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" @@ -4309,8 +4165,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum smithay-client-toolkit 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2ccb8c57049b2a34d2cc2b203fa785020ba0129d31920ef0d317430adaf748fa" "checksum smithay-client-toolkit 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "93960e8975909fcb14cc755de93af2149d8b8f4eb368315537d40cfd0f324054" "checksum smithay-clipboard 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9667a262ef7a9ff1c55a7e665cd3d36f9bc2809f94167b1fb3fc31423a83f8c0" -"checksum specs 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)" = "de65613ada4338aa7ba71eca60eca24c60483433eec0077bc4f33cfc31f4bdf0" -"checksum specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git)" = "" +"checksum specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4943fde8c5d3d14c3d19d2a4c7abbd7b626c270a19e6cd35252294a48feb698c" +"checksum specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15)" = "" "checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" @@ -4339,7 +4195,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tiny_http 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1661fa0a44c95d01604bd05c66732a446c657efb62b5164a7a083a3b552b4951" "checksum tinytemplate 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4574b75faccaacddb9b284faecdf0b544b80b6b294f3d062d325c5726a209c20" "checksum toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" -"checksum tuple_utils 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbfecd7bb8f0a3e96b3b31c46af2677a55a588767c0091f484601424fcb20e7e" +"checksum tuple_utils 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44834418e2c5b16f47bedf35c28e148db099187dd5feee6367fb2525863af4f1" "checksum twoway 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" "checksum ucd-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa9b3b49edd3468c0e6565d85783f51af95212b6fa3986a5500954f00b460874" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" diff --git a/client/Cargo.toml b/client/Cargo.toml index 2dcb26563e..4f9509c1ec 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -12,6 +12,6 @@ uvth = "3.1.1" image = "0.22.3" num_cpus = "1.10.1" log = "0.4.8" -specs = "0.14.2" +specs = "0.15.1" vek = { version = "0.9.9", features = ["serde"] } hashbrown = { version = "0.6.2", features = ["serde", "nightly"] } diff --git a/client/src/lib.rs b/client/src/lib.rs index c1e0a5c365..c6eab89d3b 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -5,7 +5,7 @@ pub mod error; // Reexports pub use crate::error::Error; -pub use specs::{join::Join, saveload::Marker, Entity as EcsEntity, ReadStorage}; +pub use specs::{join::Join, saveload::Marker, Entity as EcsEntity, ReadStorage, WorldExt}; use common::{ comp::{self, ControlEvent, Controller, ControllerInputs, InventoryManip}, diff --git a/common/Cargo.toml b/common/Cargo.toml index 08f6ca603c..ccd3b901ce 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -5,9 +5,9 @@ authors = ["Joshua Barretto ", "Maciej Ćwięka (); // Register synced resources used by the ECS. - ecs.add_resource(TimeOfDay(0.0)); + ecs.insert(TimeOfDay(0.0)); // Register unsynced resources used by the ECS. - ecs.add_resource(Time(0.0)); - ecs.add_resource(DeltaTime(0.0)); - ecs.add_resource(TerrainGrid::new().unwrap()); - ecs.add_resource(BlockChange::default()); - ecs.add_resource(TerrainChanges::default()); + ecs.insert(Time(0.0)); + ecs.insert(DeltaTime(0.0)); + ecs.insert(TerrainGrid::new().unwrap()); + ecs.insert(BlockChange::default()); + ecs.insert(TerrainChanges::default()); // TODO: only register on the server - ecs.add_resource(EventBus::::default()); - ecs.add_resource(EventBus::::default()); - ecs.add_resource(EventBus::::default()); - ecs.add_resource(RegionMap::new()); + ecs.insert(EventBus::::default()); + ecs.insert(EventBus::::default()); + ecs.insert(EventBus::::default()); + ecs.insert(RegionMap::new()); ecs } @@ -320,7 +320,7 @@ impl State { // TODO: Consider alternative ways to do this add_foreign_systems(&mut dispatch_builder); // This dispatches all the systems in parallel. - dispatch_builder.build().dispatch(&self.ecs.res); + dispatch_builder.build().dispatch(&self.ecs); self.ecs.maintain(); diff --git a/common/src/sync/packet.rs b/common/src/sync/packet.rs index 08c1d339e8..dbad6ea228 100644 --- a/common/src/sync/packet.rs +++ b/common/src/sync/packet.rs @@ -4,7 +4,7 @@ use super::{ }; use log::error; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use specs::{shred::Resource, Component, Entity, Join, ReadStorage, World}; +use specs::{shred::Resource, Component, Entity, Join, ReadStorage, World, WorldExt}; use std::{ convert::{TryFrom, TryInto}, fmt::Debug, diff --git a/common/src/sync/sync_ext.rs b/common/src/sync/sync_ext.rs index 1033f666cb..ac2da7675f 100644 --- a/common/src/sync/sync_ext.rs +++ b/common/src/sync/sync_ext.rs @@ -10,6 +10,7 @@ use log::error; use specs::{ saveload::{MarkedBuilder, MarkerAllocator}, world::Builder, + WorldExt, }; pub trait WorldSyncExt { @@ -38,7 +39,7 @@ impl WorldSyncExt for specs::World { self.register_synced::(); // TODO: Consider only having allocator server side for now - self.add_resource(UidAllocator::new()); + self.insert(UidAllocator::new()); } fn register_synced(&mut self) where @@ -52,7 +53,7 @@ impl WorldSyncExt for specs::World { C::Storage: Default + specs::storage::Tracked, { let tracker = UpdateTracker::::new(self); - self.add_resource(tracker); + self.insert(tracker); } fn create_entity_synced(&mut self) -> specs::EntityBuilder { diff --git a/common/src/sync/track.rs b/common/src/sync/track.rs index f1137f5d28..e5aaa65357 100644 --- a/common/src/sync/track.rs +++ b/common/src/sync/track.rs @@ -2,7 +2,7 @@ use super::{ packet::{CompPacket, CompUpdateKind}, uid::Uid, }; -use specs::{BitSet, Component, Entity, Join, ReadStorage, World}; +use specs::{BitSet, Component, Entity, Join, ReadStorage, World, WorldExt}; use std::{ convert::{TryFrom, TryInto}, marker::PhantomData, diff --git a/server/Cargo.toml b/server/Cargo.toml index 3bb82317f0..d5234f894c 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -8,12 +8,10 @@ edition = "2018" common = { package = "veloren-common", path = "../common" } world = { package = "veloren-world", path = "../world" } -specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git" } +specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", branch = "imbris/specs-15"} log = "0.4.8" -specs = "0.14.2" -shred-derive = "0.5.0" -shred = "0.7.0" +specs = { version = "0.15.1", features = ["shred-derive"] } vek = "0.9.9" uvth = "3.1.1" lazy_static = "1.4.0" @@ -29,5 +27,3 @@ prometheus = "0.7" prometheus-static-metric = "0.2" rouille = "3.0.0" portpicker = { git = "https://github.com/wusyong/portpicker-rs", branch = "fix_ipv6" } -# TODO: remove when upgrading to specs 0.15 -hibitset = "0.5.3" diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 22606d8ee2..cca446f1a9 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -16,7 +16,7 @@ use common::{ vol::RectVolSize, }; use rand::Rng; -use specs::{Builder, Entity as EcsEntity, Join}; +use specs::{Builder, Entity as EcsEntity, Join, WorldExt}; use vek::*; use world::util::Sampler; diff --git a/server/src/lib.rs b/server/src/lib.rs index d49d4345b3..8f4d79985f 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -37,6 +37,7 @@ use metrics::ServerMetrics; use rand::Rng; use specs::{ join::Join, world::EntityBuilder as EcsEntityBuilder, Builder, Entity as EcsEntity, SystemData, + WorldExt, }; use std::{ i32, @@ -87,26 +88,18 @@ impl Server { /// Create a new `Server` pub fn new(settings: ServerSettings) -> Result { let mut state = State::default(); - state - .ecs_mut() - .add_resource(EventBus::::default()); + state.ecs_mut().insert(EventBus::::default()); // TODO: anything but this - state.ecs_mut().add_resource(AuthProvider::new()); - state.ecs_mut().add_resource(Tick(0)); - state.ecs_mut().add_resource(ChunkGenerator::new()); + state.ecs_mut().insert(AuthProvider::new()); + state.ecs_mut().insert(Tick(0)); + state.ecs_mut().insert(ChunkGenerator::new()); // System timers for performance monitoring - state - .ecs_mut() - .add_resource(sys::EntitySyncTimer::default()); - state.ecs_mut().add_resource(sys::MessageTimer::default()); - state.ecs_mut().add_resource(sys::SentinelTimer::default()); - state - .ecs_mut() - .add_resource(sys::SubscriptionTimer::default()); - state - .ecs_mut() - .add_resource(sys::TerrainSyncTimer::default()); - state.ecs_mut().add_resource(sys::TerrainTimer::default()); + state.ecs_mut().insert(sys::EntitySyncTimer::default()); + state.ecs_mut().insert(sys::MessageTimer::default()); + state.ecs_mut().insert(sys::SentinelTimer::default()); + state.ecs_mut().insert(sys::SubscriptionTimer::default()); + state.ecs_mut().insert(sys::TerrainSyncTimer::default()); + state.ecs_mut().insert(sys::TerrainTimer::default()); // Server-only components state.ecs_mut().register::(); state.ecs_mut().register::(); @@ -158,7 +151,7 @@ impl Server { }; // set the spawn point we calculated above - state.ecs_mut().add_resource(SpawnPoint(spawn_point)); + state.ecs_mut().insert(SpawnPoint(spawn_point)); // Set starting time for the server. state.ecs_mut().write_resource::().0 = settings.start_time; @@ -166,7 +159,7 @@ impl Server { // Register trackers sys::sentinel::register_trackers(&mut state.ecs_mut()); - state.ecs_mut().add_resource(DeletedEntities::default()); + state.ecs_mut().insert(DeletedEntities::default()); let this = Self { state, @@ -1000,11 +993,11 @@ impl Server { .get_mut(entity) .unwrap() .notify(ServerMsg::InitialSync { - ecs_state: TrackedResources::fetch(&self.state.ecs().res) + ecs_state: TrackedResources::fetch(&self.state.ecs()) .state_package() // Send client their entity .with_entity( - TrackedComps::fetch(&self.state.ecs().res) + TrackedComps::fetch(&self.state.ecs()) .create_entity_package(entity), ), entity_uid: self.state.ecs().uid_from_entity(entity).unwrap().into(), // Can't fail. diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index bb59f42edf..31acac56b3 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -12,9 +12,9 @@ use common::{ }, }; use hashbrown::HashMap; -use shred_derive::SystemData; use specs::{ - Entity as EcsEntity, Join, ReadExpect, ReadStorage, System, World, Write, WriteExpect, + shred::ResourceId, Entity as EcsEntity, Join, ReadExpect, ReadStorage, System, SystemData, + World, Write, WriteExpect, }; use vek::*; diff --git a/server/src/sys/subscription.rs b/server/src/sys/subscription.rs index ef6cc59659..f11eaeeafb 100644 --- a/server/src/sys/subscription.rs +++ b/server/src/sys/subscription.rs @@ -13,7 +13,8 @@ use common::{ }; use log::{debug, error}; use specs::{ - Entities, Join, ReadExpect, ReadStorage, System, SystemData, World, Write, WriteStorage, + Entities, Join, ReadExpect, ReadStorage, System, SystemData, World, WorldExt, Write, + WriteStorage, }; use vek::*; @@ -231,7 +232,7 @@ pub fn initialize_region_subscription(world: &World, entity: specs::Entity) { ); let region_map = world.read_resource::(); - let tracked_comps = TrackedComps::fetch(&world.res); + let tracked_comps = TrackedComps::fetch(world); for key in ®ions { if let Some(region) = region_map.get(*key) { for (uid, pos, vel, ori, character_state, _, entity) in ( diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index 896b6b7283..daa6fbfd66 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -27,7 +27,7 @@ conrod_winit = { git = "https://gitlab.com/veloren/conrod.git" } euc = "0.3.0" # ECS -specs = "0.14.2" +specs = "0.15.1" # Mathematics vek = { version = "0.9.9", features = ["serde"] } diff --git a/voxygen/src/audio/sfx/event_mapper.rs b/voxygen/src/audio/sfx/event_mapper.rs index 69baaa6b93..9a6f7c3d92 100644 --- a/voxygen/src/audio/sfx/event_mapper.rs +++ b/voxygen/src/audio/sfx/event_mapper.rs @@ -8,7 +8,7 @@ use common::{ event::{EventBus, SfxEvent, SfxEventItem}, }; use hashbrown::HashMap; -use specs::{Entity as EcsEntity, Join}; +use specs::{Entity as EcsEntity, Join, WorldExt}; use std::time::{Duration, Instant}; use vek::*; diff --git a/voxygen/src/audio/sfx/mod.rs b/voxygen/src/audio/sfx/mod.rs index a4007ccfa0..52ab02614c 100644 --- a/voxygen/src/audio/sfx/mod.rs +++ b/voxygen/src/audio/sfx/mod.rs @@ -9,6 +9,7 @@ use common::{ event::{EventBus, SfxEvent, SfxEventItem}, }; use serde::Deserialize; +use specs::WorldExt; use vek::*; #[derive(Deserialize)] diff --git a/voxygen/src/hud/map.rs b/voxygen/src/hud/map.rs index 0af0330e8b..885a69f319 100644 --- a/voxygen/src/hud/map.rs +++ b/voxygen/src/hud/map.rs @@ -7,6 +7,7 @@ use conrod_core::{ widget::{self, Button, Image, Rectangle, Text}, widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon, }; +use specs::WorldExt; use vek::*; widget_ids! { diff --git a/voxygen/src/hud/minimap.rs b/voxygen/src/hud/minimap.rs index 09893c2eba..be1e34ad2c 100644 --- a/voxygen/src/hud/minimap.rs +++ b/voxygen/src/hud/minimap.rs @@ -7,6 +7,7 @@ use conrod_core::{ widget::{self, Button, Image, Rectangle, Text}, widget_ids, Color, Colorable, Positionable, Sizeable, Widget, WidgetCommon, }; +use specs::WorldExt; use std::time::{Duration, Instant}; use vek::*; diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index da4b978067..7da5038331 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -49,7 +49,7 @@ use conrod_core::{ widget::{self, Button, Image, Rectangle, Text}, widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, }; -use specs::Join; +use specs::{Join, WorldExt}; use std::collections::VecDeque; use vek::*; diff --git a/voxygen/src/hud/social.rs b/voxygen/src/hud/social.rs index 14be88343c..b57ab9226c 100644 --- a/voxygen/src/hud/social.rs +++ b/voxygen/src/hud/social.rs @@ -7,7 +7,7 @@ use conrod_core::{ widget_ids, /*, Color*/ Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, }; -use specs::Join; +use specs::{Join, WorldExt}; use client::{self, Client}; diff --git a/voxygen/src/menu/char_selection/scene.rs b/voxygen/src/menu/char_selection/scene.rs index 4b2c99bfcc..906e60c0a4 100644 --- a/voxygen/src/menu/char_selection/scene.rs +++ b/voxygen/src/menu/char_selection/scene.rs @@ -21,6 +21,7 @@ use common::{ terrain::BlockKind, }; use log::error; +use specs::WorldExt; use vek::*; struct Skybox { diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index ddecd67043..b5e33ee35d 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -26,7 +26,7 @@ use common::{ }; use hashbrown::HashMap; use log::trace; -use specs::{Entity as EcsEntity, Join}; +use specs::{Entity as EcsEntity, Join, WorldExt}; use vek::*; const DAMAGE_FADE_COEFFICIENT: f64 = 5.0; diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index a98e30c436..d43450806d 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -22,7 +22,7 @@ use common::{ terrain::{BlockKind, TerrainChunk}, vol::ReadVol, }; -use specs::Join; +use specs::{Join, WorldExt}; use vek::*; // TODO: Don't hard-code this. diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 6d7151d65f..2ff3286fd0 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -17,7 +17,7 @@ use common::{ ChatType, }; use log::error; -use specs::Join; +use specs::{Join, WorldExt}; use std::{cell::RefCell, rc::Rc, time::Duration}; use vek::*; From 8f7323f41b66fa93c0406771a4016062c17415cb Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 1 Dec 2019 16:54:21 -0500 Subject: [PATCH 06/11] Stop syncing health change timer updates --- Cargo.lock | 2 +- common/Cargo.toml | 2 +- common/src/sys/phys.rs | 5 ++++- common/src/sys/stats.rs | 25 ++++++++++++++++++++----- server/src/lib.rs | 15 +++++++++++---- server/src/sys/mod.rs | 4 ++-- 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea89d274a5..0b821910f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3062,7 +3062,7 @@ dependencies = [ [[package]] name = "specs-idvs" version = "0.1.0" -source = "git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15#55547cdf1358c667ac8a7d4c79857143bde2843c" +source = "git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15#f049bf725f2a690d01ea8a83da49c7ebf8d8ea2a" dependencies = [ "hibitset 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/common/Cargo.toml b/common/Cargo.toml index ccd3b901ce..8362c5ce84 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", branch = "imbris/specs-15" } -specs = { version = "0.15.1", features = ["serde", "nightly"] } +specs = { version = "0.15.1", features = ["serde", "nightly", "storage-event-control"] } vek = { version = "0.9.9", features = ["serde"] } dot_vox = "4.0.0" image = "0.22.3" diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 4b1b89d62b..ad9e5170ec 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -349,10 +349,13 @@ impl<'a> System<'a> for Sys { &mut velocities, &bodies, !&mountings, - !&stickies, // Can't push stickies around + stickies.maybe(), &mut physics_states, ) .join() + .filter(|(_, _, _, _, _, _, sticky, physics)| { + sticky.is_none() || (physics.on_wall.is_none() && !physics.on_ground) + }) { physics.touch_entity = None; diff --git a/common/src/sys/stats.rs b/common/src/sys/stats.rs index 5de672a84b..f8aa9e281b 100644 --- a/common/src/sys/stats.rs +++ b/common/src/sys/stats.rs @@ -23,9 +23,25 @@ impl<'a> System<'a> for Sys { ) { let mut server_event_emitter = server_event_bus.emitter(); + // Increment last change timer + stats.set_event_emission(false); // avoid unnecessary syncing + for stat in (&mut stats).join() { + stat.health.last_change.0 += f64::from(dt.0); + } + stats.set_event_emission(true); + // Mutates all stats every tick causing the server to resend this component for every entity every tick - for (entity, mut stat) in (&entities, &mut stats).join() { - if stat.should_die() && !stat.is_dead { + for (entity, mut stats) in (&entities, &mut stats.restrict_mut()).join() { + let (set_dead, level_up) = { + let stat = stats.get_unchecked(); + ( + stat.should_die() && !stat.is_dead, + stat.exp.current() >= stat.exp.maximum(), + ) + }; + + if set_dead { + let stat = stats.get_mut_unchecked(); server_event_emitter.emit(ServerEvent::Destroy { entity, cause: stat.health.last_change.1.cause, @@ -34,9 +50,8 @@ impl<'a> System<'a> for Sys { stat.is_dead = true; } - stat.health.last_change.0 += f64::from(dt.0); - - if stat.exp.current() >= stat.exp.maximum() { + if level_up { + let stat = stats.get_mut_unchecked(); while stat.exp.current() >= stat.exp.maximum() { stat.exp.change_by(-(stat.exp.maximum() as i64)); stat.exp.change_maximum_by(25); diff --git a/server/src/lib.rs b/server/src/lib.rs index 8f4d79985f..571866eb98 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -36,8 +36,8 @@ use log::{debug, error}; use metrics::ServerMetrics; use rand::Rng; use specs::{ - join::Join, world::EntityBuilder as EcsEntityBuilder, Builder, Entity as EcsEntity, SystemData, - WorldExt, + join::Join, world::EntityBuilder as EcsEntityBuilder, Builder, Entity as EcsEntity, RunNow, + SystemData, WorldExt, }; use std::{ i32, @@ -831,7 +831,11 @@ impl Server { // 3) Handle inputs from clients frontend_events.append(&mut self.handle_new_connections()?); + // Run message recieving sys before the systems in common for decreased latency (e.g. run before controller system) + sys::message::Sys.run_now(&self.state.ecs()); + let before_tick_4 = Instant::now(); + // 4) Tick the server's LocalState. self.state.tick(dt, sys::add_server_systems); @@ -897,11 +901,14 @@ impl Server { self.metrics .tick_time .with_label_values(&["input"]) - .set((before_tick_4 - before_tick_1).as_nanos() as i64); + .set((before_tick_4 - before_tick_1).as_nanos() as i64 - message_nanos); self.metrics .tick_time .with_label_values(&["state tick"]) - .set((before_handle_events - before_tick_4).as_nanos() as i64 - total_sys_nanos); + .set( + (before_handle_events - before_tick_4).as_nanos() as i64 + - (total_sys_nanos - message_nanos), + ); self.metrics .tick_time .with_label_values(&["handle server events"]) diff --git a/server/src/sys/mod.rs b/server/src/sys/mod.rs index 28b3ac5842..cfb30c7479 100644 --- a/server/src/sys/mod.rs +++ b/server/src/sys/mod.rs @@ -21,9 +21,10 @@ const SENTINEL_SYS: &str = "sentinel_sys"; const SUBSCRIPTION_SYS: &str = "server_subscription_sys"; const TERRAIN_SYNC_SYS: &str = "server_terrain_sync_sys"; const TERRAIN_SYS: &str = "server_terrain_sys"; -const MESSAGE_SYS: &str = "server_message_sys"; +//const MESSAGE_SYS: &str = "server_message_sys"; pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) { + // TODO: makes some of these dependent on systems in common like the phys system dispatch_builder.add(sentinel::Sys, SENTINEL_SYS, &[]); dispatch_builder.add(subscription::Sys, SUBSCRIPTION_SYS, &[]); dispatch_builder.add( @@ -33,7 +34,6 @@ pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) { ); dispatch_builder.add(terrain_sync::Sys, TERRAIN_SYS, &[]); dispatch_builder.add(terrain::Sys, TERRAIN_SYNC_SYS, &[TERRAIN_SYS]); - dispatch_builder.add(message::Sys, MESSAGE_SYS, &[]); } /// Used to keep track of how much time each system takes From bfaa18e010cd05ff056e9367841b7f9f6b031734 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 1 Dec 2019 18:40:05 -0500 Subject: [PATCH 07/11] Fix NaN in agent sys, stop pushback from turning player around, account for Scale in melee attack hit detection --- Cargo.toml | 2 +- common/src/sys/agent.rs | 16 ++++++++-------- common/src/sys/combat.rs | 29 ++++++++++++++++++++--------- common/src/sys/movement.rs | 4 ++-- common/src/sys/phys.rs | 1 + 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9abd786022..4c463c2db7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ opt-level = 2 overflow-checks = true debug-assertions = true panic = "abort" -# debug = false +debug = false codegen-units = 8 lto = false incremental = true diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index c2bcbe1c2a..ef768e2a9d 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -1,6 +1,5 @@ use crate::comp::{ - Agent, CharacterState, Controller, ControllerInputs, MountState, MovementState::Glide, Pos, - Stats, + Agent, CharacterState, Controller, MountState, MovementState::Glide, Pos, Stats, }; use crate::pathfinding::WorldPath; use crate::terrain::TerrainGrid; @@ -60,7 +59,7 @@ impl<'a> System<'a> for Sys { controller.reset(); - let mut inputs = ControllerInputs::default(); + let mut inputs = &mut controller.inputs; match agent { Agent::Traveler { path } => { @@ -147,10 +146,10 @@ impl<'a> System<'a> for Sys { let dist = Vec2::::from(target_pos.0 - pos.0).magnitude(); if target_stats.is_dead { choose_new = true; - } else if dist < MIN_ATTACK_DIST - && dist > 0.001 - && rand::random::() < 0.3 - { + } else if dist < 0.001 { + // TODO: move back? (probably can only happen when entities are at a + // different z-level due to repulsion) + } else if dist < MIN_ATTACK_DIST { // Fight (and slowly move closer) inputs.move_dir = Vec2::::from(target_pos.0 - pos.0).normalized() * 0.01; @@ -203,7 +202,8 @@ impl<'a> System<'a> for Sys { } } - controller.inputs = inputs; + debug_assert!(inputs.move_dir.map(|e| !e.is_nan()).reduce_and()); + debug_assert!(inputs.look_dir.map(|e| !e.is_nan()).reduce_and()); } } } diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index 7ee73e4bfa..807ca96945 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -1,7 +1,7 @@ use crate::{ comp::{ ActionState::*, CharacterState, Controller, HealthChange, HealthSource, Item, ItemKind, - Ori, Pos, Stats, + Ori, Pos, Scale, Stats, }, event::{EventBus, LocalEvent, ServerEvent}, state::DeltaTime, @@ -13,7 +13,8 @@ use vek::*; const BLOCK_EFFICIENCY: f32 = 0.9; -const ATTACK_RANGE: f32 = 4.0; +const ATTACK_RANGE: f32 = 3.5; +const ATTACK_ANGLE: f32 = 45.0; const BLOCK_ANGLE: f32 = 180.0; /// This system is responsible for handling accepted inputs like moving or attacking @@ -27,6 +28,7 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Uid>, ReadStorage<'a, Pos>, ReadStorage<'a, Ori>, + ReadStorage<'a, Scale>, ReadStorage<'a, Controller>, WriteStorage<'a, CharacterState>, WriteStorage<'a, Stats>, @@ -42,6 +44,7 @@ impl<'a> System<'a> for Sys { uids, positions, orientations, + scales, controllers, mut character_states, stats, @@ -51,11 +54,12 @@ impl<'a> System<'a> for Sys { let mut _local_emitter = local_bus.emitter(); // Attacks - for (entity, uid, pos, ori, _, stat) in ( + for (entity, uid, pos, ori, scale_maybe, _, stat) in ( &entities, &uids, &positions, &orientations, + scales.maybe(), &controllers, &stats, ) @@ -92,11 +96,12 @@ impl<'a> System<'a> for Sys { if deal_damage { if let Some(Attack { .. }) = &character_states.get(entity).map(|c| c.action) { // Go through all other entities - for (b, uid_b, pos_b, ori_b, character_b, stat_b) in ( + for (b, uid_b, pos_b, ori_b, scale_b_maybe, character_b, stat_b) in ( &entities, &uids, &positions, &orientations, + scales.maybe(), &character_states, &stats, ) @@ -107,12 +112,18 @@ impl<'a> System<'a> for Sys { let pos_b2: Vec2 = Vec2::from(pos_b.0); let ori2 = Vec2::from(ori.0); + // Scales + let scale = scale_maybe.map_or(1.0, |s| s.0); + let scale_b = scale_b_maybe.map_or(1.0, |s| s.0); + // TODO: don't do this here + let rad_b = 0.5 * scale_b; + // Check if it is a hit if entity != b && !stat_b.is_dead - && pos.0.distance_squared(pos_b.0) < ATTACK_RANGE.powi(2) - // TODO: Use size instead of 1.0 - && ori2.angle_between(pos_b2 - pos2) < (2.0 / pos2.distance(pos_b2)).atan() + // Spherical wedge shaped attack field + && pos.0.distance_squared(pos_b.0) < (rad_b + scale * ATTACK_RANGE).powi(2) + && ori2.angle_between(pos_b2 - pos2) < ATTACK_ANGLE.to_radians() / 2.0 + (rad_b / pos2.distance(pos_b2)).atan() { // Weapon gives base damage let mut dmg = if let Some(ItemKind::Tool { power, .. }) = @@ -125,8 +136,8 @@ impl<'a> System<'a> for Sys { // Block if character_b.action.is_block() - && ori_b.0.angle_between(pos.0 - pos_b.0).to_degrees() - < BLOCK_ANGLE / 2.0 + && ori_b.0.angle_between(pos.0 - pos_b.0) + < BLOCK_ANGLE.to_radians() / 2.0 { dmg = (dmg as f32 * (1.0 - BLOCK_EFFICIENCY)) as i32 } diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs index dcec8bac24..f0f157b9ce 100644 --- a/common/src/sys/movement.rs +++ b/common/src/sys/movement.rs @@ -173,10 +173,10 @@ impl<'a> System<'a> for Sys { if Vec2::::from(wall_dir).magnitude_squared() > 0.001 { Vec2::from(wall_dir).normalized() } else { - Vec2::from(vel.0) + Vec2::from(inputs.move_dir) } } else { - Vec2::from(vel.0) + Vec2::from(inputs.move_dir) }; if ori_dir.magnitude_squared() > 0.0001 diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index ad9e5170ec..67689495b4 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -102,6 +102,7 @@ impl<'a> System<'a> for Sys { let scale = scale.map(|s| s.0).unwrap_or(1.0); // Basic collision with terrain + // TODO: rename this, not just the player entity let player_rad = 0.3 * scale; // half-width of the player's AABB let player_height = 1.5 * scale; From 5813f626d1d136bb730ca5d3500b1eeb84a8c314 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 1 Dec 2019 20:26:31 -0500 Subject: [PATCH 08/11] cleanup --- Cargo.lock | 9 ++++----- common/Cargo.toml | 2 +- common/src/msg/ecs_packet.rs | 7 ------- server/Cargo.toml | 2 +- server/src/sys/mod.rs | 1 - server/src/sys/sentinel.rs | 15 --------------- voxygen/src/ui/mod.rs | 15 ++++++++++++--- world/src/sim/mod.rs | 2 +- 8 files changed, 19 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b821910f2..030eb943a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3062,9 +3062,8 @@ dependencies = [ [[package]] name = "specs-idvs" version = "0.1.0" -source = "git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15#f049bf725f2a690d01ea8a83da49c7ebf8d8ea2a" +source = "git+https://gitlab.com/veloren/specs-idvs.git#111548cf44e9bb4c43feb12aa3fc253953ac6e4a" dependencies = [ - "hibitset 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3460,7 +3459,7 @@ dependencies = [ "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", "specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", - "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15)", + "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git)", "sum_type 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3484,7 +3483,7 @@ dependencies = [ "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", - "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15)", + "specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git)", "uvth 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", "veloren-common 0.4.0", @@ -4166,7 +4165,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum smithay-client-toolkit 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "93960e8975909fcb14cc755de93af2149d8b8f4eb368315537d40cfd0f324054" "checksum smithay-clipboard 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9667a262ef7a9ff1c55a7e665cd3d36f9bc2809f94167b1fb3fc31423a83f8c0" "checksum specs 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4943fde8c5d3d14c3d19d2a4c7abbd7b626c270a19e6cd35252294a48feb698c" -"checksum specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git?branch=imbris/specs-15)" = "" +"checksum specs-idvs 0.1.0 (git+https://gitlab.com/veloren/specs-idvs.git)" = "" "checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" diff --git a/common/Cargo.toml b/common/Cargo.toml index 8362c5ce84..adcdd3f834 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Joshua Barretto ", "Maciej Ćwięka sync::handle_res_update(time, world), EcsResPacket::MustHaveMoreThanOneVariant(_) => unimplemented!(), EcsResPacket::TimeOfDay(time_of_day) => sync::handle_res_update(time_of_day, world), } @@ -41,7 +39,6 @@ sum_type! { MountState(comp::MountState), Mounting(comp::Mounting), Mass(comp::Mass), - //Projectile(comp::Projectile), Gravity(comp::Gravity), Sticky(comp::Sticky), } @@ -61,7 +58,6 @@ sum_type! { MountState(PhantomData), Mounting(PhantomData), Mass(PhantomData), - //Projectile(PhantomData), Gravity(PhantomData), Sticky(PhantomData), } @@ -80,7 +76,6 @@ impl sync::CompPacket for EcsCompPacket { EcsCompPacket::MountState(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Mounting(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Mass(comp) => sync::handle_insert(comp, entity, world), - //EcsCompPacket::Projectile(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Gravity(comp) => sync::handle_insert(comp, entity, world), EcsCompPacket::Sticky(comp) => sync::handle_insert(comp, entity, world), } @@ -97,7 +92,6 @@ impl sync::CompPacket for EcsCompPacket { EcsCompPacket::MountState(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Mounting(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Mass(comp) => sync::handle_modify(comp, entity, world), - //EcsCompPacket::Projectile(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Gravity(comp) => sync::handle_modify(comp, entity, world), EcsCompPacket::Sticky(comp) => sync::handle_modify(comp, entity, world), } @@ -116,7 +110,6 @@ impl sync::CompPacket for EcsCompPacket { EcsCompPhantom::MountState(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Mounting(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Mass(_) => sync::handle_remove::(entity, world), - //EcsCompPhantom::Projectile(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Gravity(_) => sync::handle_remove::(entity, world), EcsCompPhantom::Sticky(_) => sync::handle_remove::(entity, world), } diff --git a/server/Cargo.toml b/server/Cargo.toml index d5234f894c..009ff93252 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" common = { package = "veloren-common", path = "../common" } world = { package = "veloren-world", path = "../world" } -specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", branch = "imbris/specs-15"} +specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git" } log = "0.4.8" specs = { version = "0.15.1", features = ["shred-derive"] } diff --git a/server/src/sys/mod.rs b/server/src/sys/mod.rs index cfb30c7479..72860c92c8 100644 --- a/server/src/sys/mod.rs +++ b/server/src/sys/mod.rs @@ -21,7 +21,6 @@ const SENTINEL_SYS: &str = "sentinel_sys"; const SUBSCRIPTION_SYS: &str = "server_subscription_sys"; const TERRAIN_SYNC_SYS: &str = "server_terrain_sync_sys"; const TERRAIN_SYS: &str = "server_terrain_sys"; -//const MESSAGE_SYS: &str = "server_message_sys"; pub fn add_server_systems(dispatch_builder: &mut DispatcherBuilder) { // TODO: makes some of these dependent on systems in common like the phys system diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index 31acac56b3..081e5a7c55 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -53,7 +53,6 @@ pub struct TrackedComps<'a> { pub mass: ReadStorage<'a, Mass>, pub sticky: ReadStorage<'a, Sticky>, pub gravity: ReadStorage<'a, Gravity>, - //pub projectile: ReadStorage<'a, Projectile>, } impl<'a> TrackedComps<'a> { pub fn create_entity_package(&self, entity: EcsEntity) -> EntityPackage { @@ -112,10 +111,6 @@ impl<'a> TrackedComps<'a> { .get(entity) .copied() .map(|c| packets.push(c.into())); - //self.projectile - // .get(entity) - // .cloned() - // .map(|c| packets.push(c.into())); EntityPackage(uid, packets) } @@ -135,7 +130,6 @@ pub struct ReadTrackers<'a> { pub mass: ReadExpect<'a, UpdateTracker>, pub sticky: ReadExpect<'a, UpdateTracker>, pub gravity: ReadExpect<'a, UpdateTracker>, - //pub projectile: ReadExpect<'a, UpdateTracker>, } impl<'a> ReadTrackers<'a> { pub fn create_sync_package( @@ -162,12 +156,6 @@ impl<'a> ReadTrackers<'a> { .with_component(&comps.uid, &*self.mass, &comps.mass, filter) .with_component(&comps.uid, &*self.sticky, &comps.sticky, filter) .with_component(&comps.uid, &*self.gravity, &comps.gravity, filter) - //.with_component( - // &comps.uid, - // self.projectile.deref(), - // &comps.projectile, - // filter, - //) } } @@ -186,7 +174,6 @@ pub struct WriteTrackers<'a> { mass: WriteExpect<'a, UpdateTracker>, sticky: WriteExpect<'a, UpdateTracker>, gravity: WriteExpect<'a, UpdateTracker>, - //projectile: WriteExpect<'a, UpdateTracker>, } fn record_changes(comps: &TrackedComps, trackers: &mut WriteTrackers) { @@ -204,7 +191,6 @@ fn record_changes(comps: &TrackedComps, trackers: &mut WriteTrackers) { trackers.mass.record_changes(&comps.mass); trackers.sticky.record_changes(&comps.sticky); trackers.gravity.record_changes(&comps.gravity); - //trackers.projectile.record_changes(&comps.projectile); } pub fn register_trackers(world: &mut World) { @@ -221,7 +207,6 @@ pub fn register_trackers(world: &mut World) { world.register_tracker::(); world.register_tracker::(); world.register_tracker::(); - //world.register_tracker::(); } #[derive(SystemData)] diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index e5e581adf8..b9514a903b 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -342,7 +342,7 @@ impl Ui { // moving origin to top-left corner (from middle). let min_x = self.ui.win_w / 2.0 + l; let min_y = self.ui.win_h / 2.0 - b - h; - Aabr { + let intersection = Aabr { min: Vec2 { x: (min_x * scale_factor) as u16, y: (min_y * scale_factor) as u16, @@ -352,7 +352,13 @@ impl Ui { y: ((min_y + h) * scale_factor) as u16, }, } - .intersection(window_scissor) + .intersection(window_scissor); + + if intersection.is_valid() { + intersection + } else { + Aabr::new_empty(Vec2::zero()) + } }; if new_scissor != current_scissor { // Finish the current command. @@ -750,7 +756,10 @@ impl Ui { } fn default_scissor(renderer: &Renderer) -> Aabr { - let (screen_w, screen_h) = renderer.get_resolution().map(|e| e as u16).into_tuple(); + let (screen_w, screen_h) = renderer + .get_resolution() + .map(|e| (e as u16).max(1)) + .into_tuple(); Aabr { min: Vec2 { x: 0, y: 0 }, max: Vec2 { diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 2ade596ad0..ce7a484676 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -324,7 +324,7 @@ impl WorldSim { let logistic_cdf = |x: f64| (x / logistic_2_base).tanh() * 0.5 + 0.5; let erosion_pow = 2.0; - let n_steps = 7; + let n_steps = 100; let erosion_factor = |x: f64| logistic_cdf(erosion_pow * logit(x)); let alt = do_erosion( 0.0, From b2752d2419199535fc3525dd8bc6ac5ab22c4a35 Mon Sep 17 00:00:00 2001 From: Imbris Date: Wed, 18 Dec 2019 00:22:52 -0500 Subject: [PATCH 09/11] Cutout unnecessary Resource syncing machinery and Tracker trait --- client/src/lib.rs | 27 +++++++-------- common/src/msg/ecs_packet.rs | 23 +------------ common/src/msg/mod.rs | 2 +- common/src/msg/server.rs | 10 +++--- common/src/state.rs | 2 +- common/src/sync/mod.rs | 6 ++-- common/src/sync/packet.rs | 62 ++++++++--------------------------- common/src/sync/sync_ext.rs | 49 ++++++++++----------------- common/src/sync/track.rs | 54 +++++++++++------------------- server/src/lib.rs | 17 ++++------ server/src/sys/entity_sync.rs | 13 ++++---- server/src/sys/sentinel.rs | 59 +++++++++------------------------ 12 files changed, 102 insertions(+), 222 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index c6eab89d3b..6cb7658c64 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -79,9 +79,9 @@ impl Client { // Wait for initial sync let (state, entity, server_info, world_map) = match postbox.next_message() { Some(ServerMsg::InitialSync { - ecs_state, - entity_uid, + entity_package, server_info, + time_of_day, // world_map: /*(map_size, world_map)*/map_size, }) => { // TODO: Voxygen should display this. @@ -95,12 +95,10 @@ impl Client { ); } + // Initialize `State` let mut state = State::default(); - state.ecs_mut().apply_state_package(ecs_state); - let entity = state - .ecs() - .entity_from_uid(entity_uid) - .ok_or(Error::ServerWentMad)?; + let entity = state.ecs_mut().apply_entity_package(entity_package); + *state.ecs_mut().write_resource() = time_of_day; // assert_eq!(world_map.len(), map_size.x * map_size.y); let map_size = Vec2::new(1024, 1024); @@ -539,7 +537,7 @@ impl Client { self.last_ping_delta = Instant::now() .duration_since(self.last_server_ping) - .as_secs_f64() + .as_secs_f64(); } ServerMsg::ChatMsg { chat_type, message } => { frontend_events.push(Event::Chat { chat_type, message }) @@ -551,15 +549,14 @@ impl Client { return Err(Error::Other("Failed to find entity from uid.".to_owned())); } } - ServerMsg::EcsSync(sync_package) => { - self.state.ecs_mut().apply_sync_package(sync_package) + ServerMsg::TimeOfDay(time_of_day) => { + *self.state.ecs_mut().write_resource() = time_of_day; + } + ServerMsg::EcsSync(sync_package) => { + self.state.ecs_mut().apply_sync_package(sync_package); } - ServerMsg::EcsResSync(res_sync_package) => self - .state - .ecs_mut() - .apply_res_sync_package(res_sync_package), ServerMsg::CreateEntity(entity_package) => { - self.state.ecs_mut().apply_entity_package(entity_package) + self.state.ecs_mut().apply_entity_package(entity_package); } ServerMsg::DeleteEntity(entity) => { if self diff --git a/common/src/msg/ecs_packet.rs b/common/src/msg/ecs_packet.rs index 8f0ee66ad3..e714416ff9 100644 --- a/common/src/msg/ecs_packet.rs +++ b/common/src/msg/ecs_packet.rs @@ -1,29 +1,8 @@ -use crate::{comp, state, sync}; +use crate::{comp, sync}; use serde_derive::{Deserialize, Serialize}; use std::marker::PhantomData; use sum_type::sum_type; -// TODO: remove me -#[derive(Clone, Debug, Serialize, Deserialize)] -pub enum MustHaveMoreThanOneVariant {} - -// Automatically derive From for EcsResPacket -// for each variant EcsResPacket::T(T). -sum_type! { - #[derive(Clone, Debug, Serialize, Deserialize)] - pub enum EcsResPacket { - MustHaveMoreThanOneVariant(MustHaveMoreThanOneVariant), - TimeOfDay(state::TimeOfDay), - } -} -impl sync::ResPacket for EcsResPacket { - fn apply(self, world: &specs::World) { - match self { - EcsResPacket::MustHaveMoreThanOneVariant(_) => unimplemented!(), - EcsResPacket::TimeOfDay(time_of_day) => sync::handle_res_update(time_of_day, world), - } - } -} // Automatically derive From for EcsCompPacket // for each variant EcsCompPacket::T(T.) sum_type! { diff --git a/common/src/msg/mod.rs b/common/src/msg/mod.rs index 09bdae25bb..12f72addf5 100644 --- a/common/src/msg/mod.rs +++ b/common/src/msg/mod.rs @@ -4,7 +4,7 @@ pub mod server; // Reexports pub use self::client::ClientMsg; -pub use self::ecs_packet::{EcsCompPacket, EcsResPacket}; +pub use self::ecs_packet::EcsCompPacket; pub use self::server::{RequestStateError, ServerError, ServerInfo, ServerMsg}; #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] diff --git a/common/src/msg/server.rs b/common/src/msg/server.rs index 90bc785ddb..7b922527d4 100644 --- a/common/src/msg/server.rs +++ b/common/src/msg/server.rs @@ -1,6 +1,6 @@ -use super::{ClientState, EcsCompPacket, EcsResPacket}; +use super::{ClientState, EcsCompPacket}; use crate::{ - comp, sync, + comp, state, sync, terrain::{Block, TerrainChunk}, ChatType, }; @@ -26,9 +26,9 @@ pub struct ServerInfo { #[derive(Debug, Clone, Serialize, Deserialize)] pub enum ServerMsg { InitialSync { - ecs_state: sync::StatePackage, - entity_uid: u64, + entity_package: sync::EntityPackage, server_info: ServerInfo, + time_of_day: state::TimeOfDay, // world_map: Vec2, /*, Vec)*/ }, StateAnswer(Result), @@ -40,8 +40,8 @@ pub enum ServerMsg { message: String, }, SetPlayerEntity(u64), + TimeOfDay(state::TimeOfDay), EcsSync(sync::SyncPackage), - EcsResSync(sync::ResSyncPackage), CreateEntity(sync::EntityPackage), DeleteEntity(u64), EntityPos { diff --git a/common/src/state.rs b/common/src/state.rs index b3378eea75..5e19b25c43 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -23,7 +23,7 @@ use vek::*; const DAY_CYCLE_FACTOR: f64 = 24.0 * 2.0; /// A resource that stores the time of day. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Serialize, Deserialize)] pub struct TimeOfDay(pub f64); /// A resource that stores the tick (i.e: physics) time. diff --git a/common/src/sync/mod.rs b/common/src/sync/mod.rs index d26ad789fd..7a5cae6d18 100644 --- a/common/src/sync/mod.rs +++ b/common/src/sync/mod.rs @@ -6,9 +6,9 @@ mod uid; // Reexports pub use packet::{ - handle_insert, handle_modify, handle_remove, handle_res_update, CompPacket, EntityPackage, - ResPacket, ResSyncPackage, StatePackage, SyncPackage, + handle_insert, handle_modify, handle_remove, CompPacket, EntityPackage, StatePackage, + SyncPackage, }; pub use sync_ext::WorldSyncExt; -pub use track::{Tracker, UpdateTracker}; +pub use track::UpdateTracker; pub use uid::{Uid, UidAllocator}; diff --git a/common/src/sync/packet.rs b/common/src/sync/packet.rs index dbad6ea228..b3ea29985c 100644 --- a/common/src/sync/packet.rs +++ b/common/src/sync/packet.rs @@ -1,10 +1,7 @@ -use super::{ - track::{Tracker, UpdateTracker}, - uid::Uid, -}; +use super::{track::UpdateTracker, uid::Uid}; use log::error; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use specs::{shred::Resource, Component, Entity, Join, ReadStorage, World, WorldExt}; +use specs::{Component, Entity, Join, ReadStorage, World, WorldExt}; use std::{ convert::{TryFrom, TryInto}, fmt::Debug, @@ -19,10 +16,6 @@ pub trait CompPacket: Clone + Debug + Send + 'static { fn apply_remove(phantom: Self::Phantom, entity: Entity, world: &World); } -pub trait ResPacket: Clone + Debug + Send + 'static { - fn apply(self, world: &World); -} - /// Useful for implementing CompPacket trait pub fn handle_insert(comp: C, entity: Entity, world: &World) { if let Err(err) = world.write_storage::().insert(entity, comp) { @@ -40,10 +33,6 @@ pub fn handle_modify(comp: C, entity: Entity, world: &World) { pub fn handle_remove(entity: Entity, world: &World) { let _ = world.write_storage::().remove(entity); } -/// Useful for implementing ResPacket trait -pub fn handle_res_update(res: R, world: &World) { - *world.write_resource::() = res; -} #[derive(Copy, Clone, Debug, Serialize, Deserialize)] pub enum CompUpdateKind { @@ -53,24 +42,25 @@ pub enum CompUpdateKind { } #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct EntityPackage(pub u64, pub Vec

); - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct StatePackage { - pub entities: Vec>, - pub resources: Vec, +pub struct EntityPackage { + pub uid: u64, + pub comps: Vec

, } -impl Default for StatePackage { +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct StatePackage { + pub entities: Vec>, +} + +impl Default for StatePackage

{ fn default() -> Self { Self { entities: Vec::new(), - resources: Vec::new(), } } } -impl StatePackage { +impl StatePackage

{ pub fn new() -> Self { Self::default() } @@ -85,13 +75,6 @@ impl StatePackage { self.entities.push(entry); self } - pub fn with_res(mut self, res: &C) -> Self - where - R: From, - { - self.resources.push(R::from(res.clone())); - self - } } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -122,7 +105,7 @@ impl SyncPackage

{ pub fn with_component<'a, C: Component + Clone + Send + Sync>( mut self, uids: &ReadStorage<'a, Uid>, - tracker: &impl Tracker, + tracker: &UpdateTracker, storage: &ReadStorage<'a, C>, filter: impl Join + Copy, ) -> Self @@ -137,22 +120,3 @@ impl SyncPackage

{ self } } - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct ResSyncPackage { - pub resources: Vec, -} -impl ResSyncPackage { - pub fn new() -> Self { - Self { - resources: Vec::new(), - } - } - pub fn with_res(mut self, res: &C) -> Self - where - R: From, - { - self.resources.push(R::from(res.clone())); - self - } -} diff --git a/common/src/sync/sync_ext.rs b/common/src/sync/sync_ext.rs index ac2da7675f..b567b6f8d2 100644 --- a/common/src/sync/sync_ext.rs +++ b/common/src/sync/sync_ext.rs @@ -1,8 +1,5 @@ use super::{ - packet::{ - CompPacket, CompUpdateKind, EntityPackage, ResPacket, ResSyncPackage, StatePackage, - SyncPackage, - }, + packet::{CompPacket, CompUpdateKind, EntityPackage, StatePackage, SyncPackage}, track::UpdateTracker, uid::{Uid, UidAllocator}, }; @@ -25,13 +22,12 @@ pub trait WorldSyncExt { fn delete_entity_and_clear_from_uid_allocator(&mut self, uid: u64); fn uid_from_entity(&self, entity: specs::Entity) -> Option; fn entity_from_uid(&self, uid: u64) -> Option; - fn apply_entity_package(&mut self, entity_package: EntityPackage

); - fn apply_state_package( + fn apply_entity_package( &mut self, - state_package: StatePackage, - ); + entity_package: EntityPackage

, + ) -> specs::Entity; + fn apply_state_package(&mut self, state_package: StatePackage

); fn apply_sync_package(&mut self, package: SyncPackage

); - fn apply_res_sync_package(&mut self, package: ResSyncPackage); } impl WorldSyncExt for specs::World { @@ -71,13 +67,18 @@ impl WorldSyncExt for specs::World { .retrieve_entity_internal(uid) } - fn apply_entity_package(&mut self, entity_package: EntityPackage

) { - let EntityPackage(entity_uid, packets) = entity_package; + fn apply_entity_package( + &mut self, + entity_package: EntityPackage

, + ) -> specs::Entity { + let EntityPackage { uid, comps } = entity_package; - let entity = create_entity_with_uid(self, entity_uid); - for packet in packets { + let entity = create_entity_with_uid(self, uid); + for packet in comps { packet.apply_insert(entity, self) } + + entity } fn delete_entity_and_clear_from_uid_allocator(&mut self, uid: u64) { @@ -90,25 +91,15 @@ impl WorldSyncExt for specs::World { } } - fn apply_state_package( - &mut self, - state_package: StatePackage, - ) { - let StatePackage { - entities, - resources, - } = state_package; - - // Apply state package resources - for res_packet in resources { - res_packet.apply(self); - } + fn apply_state_package(&mut self, state_package: StatePackage

) { + let StatePackage { entities } = state_package; // Apply state package entities for entity_package in entities { self.apply_entity_package(entity_package); } + // TODO: determine if this is needed // Initialize entities //self.maintain(); } @@ -151,12 +142,6 @@ impl WorldSyncExt for specs::World { self.delete_entity_and_clear_from_uid_allocator(entity_uid); } } - fn apply_res_sync_package(&mut self, package: ResSyncPackage) { - // Update resources - for res_packet in package.resources { - res_packet.apply(self); - } - } } // Private utilities diff --git a/common/src/sync/track.rs b/common/src/sync/track.rs index e5aaa65357..8c57360e60 100644 --- a/common/src/sync/track.rs +++ b/common/src/sync/track.rs @@ -8,29 +8,6 @@ use std::{ marker::PhantomData, }; -pub trait Tracker: Send + 'static -where - P: From, - C: TryFrom

, - P::Phantom: From>, - P::Phantom: TryInto>, - C::Storage: specs::storage::Tracked, -{ - fn add_packet_for<'a>( - &self, - storage: &specs::ReadStorage<'a, C>, - entity: specs::Entity, - packets: &mut Vec

, - ); - fn get_updates_for<'a>( - &self, - uids: &specs::ReadStorage<'a, Uid>, - storage: &specs::ReadStorage<'a, C>, - filter: impl Join + Copy, - buf: &mut Vec<(u64, CompUpdateKind

)>, - ); -} - pub struct UpdateTracker { reader_id: specs::ReaderId, inserted: BitSet, @@ -92,32 +69,39 @@ where } } -impl Tracker for UpdateTracker -where - P: From, - C: TryFrom

, - P::Phantom: From>, - P::Phantom: TryInto>, - C::Storage: specs::storage::Tracked, -{ - fn add_packet_for<'a>( +impl UpdateTracker { + pub fn add_packet_for<'a, P>( &self, storage: &ReadStorage<'a, C>, entity: Entity, packets: &mut Vec

, - ) { + ) where + P: CompPacket, + P: From, + C: TryFrom

, + P::Phantom: From>, + P::Phantom: TryInto>, + C::Storage: specs::storage::Tracked, + { if let Some(comp) = storage.get(entity) { packets.push(P::from(comp.clone())); } } - fn get_updates_for<'a>( + pub fn get_updates_for<'a, P>( &self, uids: &specs::ReadStorage<'a, Uid>, storage: &specs::ReadStorage<'a, C>, entity_filter: impl Join + Copy, buf: &mut Vec<(u64, CompUpdateKind

)>, - ) { + ) where + P: CompPacket, + P: From, + C: TryFrom

, + P::Phantom: From>, + P::Phantom: TryInto>, + C::Storage: specs::storage::Tracked, + { // Generate inserted updates for (uid, comp, _, _) in (uids, storage, &self.inserted, entity_filter).join() { buf.push(( diff --git a/server/src/lib.rs b/server/src/lib.rs index 571866eb98..f8815ad6cf 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -19,7 +19,7 @@ use crate::{ chunk_generator::ChunkGenerator, client::{Client, RegionSubscription}, cmd::CHAT_COMMANDS, - sys::sentinel::{DeletedEntities, TrackedComps, TrackedResources}, + sys::sentinel::{DeletedEntities, TrackedComps}, }; use common::{ assets, comp, @@ -992,7 +992,8 @@ impl Server { .create_entity_synced() .with(client) .build(); - // Return the state of the current world (all of the components that Sphynx tracks). + // Send client all the tracked components currently attached to its entity as well + // as synced resources (currently only `TimeOfDay`) log::debug!("Starting initial sync with client."); self.state .ecs() @@ -1000,15 +1001,11 @@ impl Server { .get_mut(entity) .unwrap() .notify(ServerMsg::InitialSync { - ecs_state: TrackedResources::fetch(&self.state.ecs()) - .state_package() - // Send client their entity - .with_entity( - TrackedComps::fetch(&self.state.ecs()) - .create_entity_package(entity), - ), - entity_uid: self.state.ecs().uid_from_entity(entity).unwrap().into(), // Can't fail. + // Send client their entity + entity_package: TrackedComps::fetch(&self.state.ecs()) + .create_entity_package(entity), server_info: self.server_info.clone(), + time_of_day: *self.state.ecs().read_resource(), // world_map: (WORLD_SIZE/*, self.world.sim().get_map()*/), }); log::debug!("Done initial sync with client."); diff --git a/server/src/sys/entity_sync.rs b/server/src/sys/entity_sync.rs index 7bb94fb3a5..cb571b7c7c 100644 --- a/server/src/sys/entity_sync.rs +++ b/server/src/sys/entity_sync.rs @@ -1,5 +1,5 @@ use super::{ - sentinel::{DeletedEntities, ReadTrackers, TrackedComps, TrackedResources}, + sentinel::{DeletedEntities, ReadTrackers, TrackedComps}, SysTimer, }; use crate::{ @@ -10,6 +10,7 @@ use common::{ comp::{CharacterState, ForceUpdate, Inventory, InventoryUpdate, Last, Ori, Pos, Vel}, msg::ServerMsg, region::{Event as RegionEvent, RegionMap}, + state::TimeOfDay, sync::Uid, }; use specs::{ @@ -22,6 +23,7 @@ impl<'a> System<'a> for Sys { type SystemData = ( Entities<'a>, Read<'a, Tick>, + ReadExpect<'a, TimeOfDay>, ReadExpect<'a, RegionMap>, Write<'a, SysTimer>, ReadStorage<'a, Uid>, @@ -41,7 +43,6 @@ impl<'a> System<'a> for Sys { Write<'a, DeletedEntities>, TrackedComps<'a>, ReadTrackers<'a>, - TrackedResources<'a>, ); fn run( @@ -49,6 +50,7 @@ impl<'a> System<'a> for Sys { ( entities, tick, + time_of_day, region_map, mut timer, uids, @@ -68,7 +70,6 @@ impl<'a> System<'a> for Sys { mut deleted_entities, tracked_comps, trackers, - tracked_resources, ): Self::SystemData, ) { timer.start(); @@ -329,10 +330,10 @@ impl<'a> System<'a> for Sys { inventory_updates.clear(); // Sync resources - // TODO: doesn't really belong in this system - let res_msg = ServerMsg::EcsResSync(tracked_resources.create_res_sync_package()); + // TODO: doesn't really belong in this system (rename system or create another system?) + let tof_msg = ServerMsg::TimeOfDay(*time_of_day); for client in (&mut clients).join() { - client.notify(res_msg.clone()); + client.notify(tof_msg.clone()); } timer.end(); diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index 081e5a7c55..8fc04ea445 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -4,12 +4,8 @@ use common::{ Body, CanBuild, Gravity, Item, LightEmitter, Mass, MountState, Mounting, Player, Scale, Stats, Sticky, }, - msg::{EcsCompPacket, EcsResPacket}, - state::TimeOfDay, - sync::{ - CompPacket, EntityPackage, ResSyncPackage, StatePackage, SyncPackage, Uid, UpdateTracker, - WorldSyncExt, - }, + msg::EcsCompPacket, + sync::{EntityPackage, SyncPackage, Uid, UpdateTracker, WorldSyncExt}, }; use hashbrown::HashMap; use specs::{ @@ -62,57 +58,48 @@ impl<'a> TrackedComps<'a> { .copied() .expect("No uid to create an entity package") .0; - let mut packets = Vec::new(); - self.body - .get(entity) - .copied() - .map(|c| packets.push(c.into())); + let mut comps = Vec::new(); + self.body.get(entity).copied().map(|c| comps.push(c.into())); self.player .get(entity) .cloned() - .map(|c| packets.push(c.into())); + .map(|c| comps.push(c.into())); self.stats .get(entity) .cloned() - .map(|c| packets.push(c.into())); + .map(|c| comps.push(c.into())); self.can_build .get(entity) .cloned() - .map(|c| packets.push(c.into())); + .map(|c| comps.push(c.into())); self.light_emitter .get(entity) .copied() - .map(|c| packets.push(c.into())); - self.item - .get(entity) - .cloned() - .map(|c| packets.push(c.into())); + .map(|c| comps.push(c.into())); + self.item.get(entity).cloned().map(|c| comps.push(c.into())); self.scale .get(entity) .copied() - .map(|c| packets.push(c.into())); + .map(|c| comps.push(c.into())); self.mounting .get(entity) .cloned() - .map(|c| packets.push(c.into())); + .map(|c| comps.push(c.into())); self.mount_state .get(entity) .cloned() - .map(|c| packets.push(c.into())); - self.mass - .get(entity) - .copied() - .map(|c| packets.push(c.into())); + .map(|c| comps.push(c.into())); + self.mass.get(entity).copied().map(|c| comps.push(c.into())); self.sticky .get(entity) .copied() - .map(|c| packets.push(c.into())); + .map(|c| comps.push(c.into())); self.gravity .get(entity) .copied() - .map(|c| packets.push(c.into())); + .map(|c| comps.push(c.into())); - EntityPackage(uid, packets) + EntityPackage { uid, comps } } } #[derive(SystemData)] @@ -209,20 +196,6 @@ pub fn register_trackers(world: &mut World) { world.register_tracker::(); } -#[derive(SystemData)] -pub struct TrackedResources<'a> { - time_of_day: ReadExpect<'a, TimeOfDay>, -} -impl<'a> TrackedResources<'a> { - pub fn create_res_sync_package(&self) -> ResSyncPackage { - ResSyncPackage::new().with_res(&*self.time_of_day) - } - /// Create state package with resources included - pub fn state_package(&self) -> StatePackage { - StatePackage::new().with_res(&*self.time_of_day) - } -} - /// Deleted entities grouped by region pub struct DeletedEntities { map: HashMap, Vec>, From 934c5d684676610e87bcbfdf3122ffb3d2c75318 Mon Sep 17 00:00:00 2001 From: Imbris Date: Thu, 19 Dec 2019 22:31:41 -0500 Subject: [PATCH 10/11] Various tweaks: moved radius determination to function on , comments, simplified server Destroy event code, debug assert modified components aren't removed in change tracking, etc --- common/src/comp/body.rs | 17 +++++++++++++++++ common/src/sync/packet.rs | 3 +++ common/src/sync/track.rs | 7 +++---- common/src/sys/agent.rs | 7 +++++-- common/src/sys/combat.rs | 24 +++++++++++++----------- server/src/lib.rs | 20 ++++++++++++-------- voxygen/src/ui/mod.rs | 5 +---- 7 files changed, 54 insertions(+), 29 deletions(-) diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index b2ba589b24..6b63bb8f51 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -33,6 +33,23 @@ impl Body { _ => false, } } + // Note: this might need to be refined to something more complex for realistic + // behavior with less cylindrical bodies (e.g. wolfs) + pub fn radius(&self) -> f32 { + // TODO: Improve these values (some might be reliant on more info in inner type) + match self { + Body::Humanoid(_) => 0.5, + Body::QuadrupedSmall(_) => 0.6, + Body::QuadrupedMedium(_) => 0.9, + Body::BirdMedium(_) => 0.5, + Body::FishMedium(_) => 0.5, + Body::Dragon(_) => 2.5, + Body::BirdSmall(_) => 0.2, + Body::FishSmall(_) => 0.2, + Body::BipedLarge(_) => 1.0, + Body::Object(_) => 0.3, + } + } } impl Component for Body { diff --git a/common/src/sync/packet.rs b/common/src/sync/packet.rs index b3ea29985c..a9d3363eeb 100644 --- a/common/src/sync/packet.rs +++ b/common/src/sync/packet.rs @@ -8,6 +8,9 @@ use std::{ marker::PhantomData, }; +/// Implemented by type that carries component data for insertion and modification +/// The assocatied `Phantom` type only carries information about which component type is of +/// interest and is used to transmit deletion events pub trait CompPacket: Clone + Debug + Send + 'static { type Phantom: Clone + Debug + Serialize + DeserializeOwned; diff --git a/common/src/sync/track.rs b/common/src/sync/track.rs index 8c57360e60..3cccda6794 100644 --- a/common/src/sync/track.rs +++ b/common/src/sync/track.rs @@ -51,10 +51,9 @@ where self.inserted.add(*id); } specs::storage::ComponentEvent::Modified(id) => { - // We don't care about modification if the component was just added or was - // removed - // Could potentially remove since this should theoretically never occur... - if !self.removed.contains(*id) && !self.inserted.contains(*id) { + // We don't care about modification if the component was just added + if !self.inserted.contains(*id) { + debug_assert!(!self.removed.contains(*id)); // Theoretically impossible self.modified.add(*id); } } diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index ef768e2a9d..5ce18dacab 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -147,8 +147,11 @@ impl<'a> System<'a> for Sys { if target_stats.is_dead { choose_new = true; } else if dist < 0.001 { - // TODO: move back? (probably can only happen when entities are at a - // different z-level due to repulsion) + // Probably can only happen when entities are at a different z-level + // since at the same level repulsion would keep them apart. + // Distinct from the first if block since we may want to change the + // behavior for this case. + choose_new = true; } else if dist < MIN_ATTACK_DIST { // Fight (and slowly move closer) inputs.move_dir = diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index 807ca96945..78cba752c0 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -1,7 +1,7 @@ use crate::{ comp::{ - ActionState::*, CharacterState, Controller, HealthChange, HealthSource, Item, ItemKind, - Ori, Pos, Scale, Stats, + ActionState::*, Body, CharacterState, Controller, HealthChange, HealthSource, Item, + ItemKind, Ori, Pos, Scale, Stats, }, event::{EventBus, LocalEvent, ServerEvent}, state::DeltaTime, @@ -30,8 +30,9 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Ori>, ReadStorage<'a, Scale>, ReadStorage<'a, Controller>, + ReadStorage<'a, Body>, + ReadStorage<'a, Stats>, WriteStorage<'a, CharacterState>, - WriteStorage<'a, Stats>, ); fn run( @@ -46,15 +47,16 @@ impl<'a> System<'a> for Sys { orientations, scales, controllers, - mut character_states, + bodies, stats, + mut character_states, ): Self::SystemData, ) { let mut server_emitter = server_bus.emitter(); let mut _local_emitter = local_bus.emitter(); // Attacks - for (entity, uid, pos, ori, scale_maybe, _, stat) in ( + for (entity, uid, pos, ori, scale_maybe, _, attacker_stats) in ( &entities, &uids, &positions, @@ -68,7 +70,7 @@ impl<'a> System<'a> for Sys { let recover_duration = if let Some(Item { kind: ItemKind::Tool { kind, .. }, .. - }) = stat.equipment.main + }) = attacker_stats.equipment.main { kind.attack_recover_duration() } else { @@ -96,7 +98,7 @@ impl<'a> System<'a> for Sys { if deal_damage { if let Some(Attack { .. }) = &character_states.get(entity).map(|c| c.action) { // Go through all other entities - for (b, uid_b, pos_b, ori_b, scale_b_maybe, character_b, stat_b) in ( + for (b, uid_b, pos_b, ori_b, scale_b_maybe, character_b, stats_b, body_b) in ( &entities, &uids, &positions, @@ -104,6 +106,7 @@ impl<'a> System<'a> for Sys { scales.maybe(), &character_states, &stats, + &bodies, ) .join() { @@ -115,19 +118,18 @@ impl<'a> System<'a> for Sys { // Scales let scale = scale_maybe.map_or(1.0, |s| s.0); let scale_b = scale_b_maybe.map_or(1.0, |s| s.0); - // TODO: don't do this here - let rad_b = 0.5 * scale_b; + let rad_b = body_b.radius() * scale_b; // Check if it is a hit if entity != b - && !stat_b.is_dead + && !stats_b.is_dead // Spherical wedge shaped attack field && pos.0.distance_squared(pos_b.0) < (rad_b + scale * ATTACK_RANGE).powi(2) && ori2.angle_between(pos_b2 - pos2) < ATTACK_ANGLE.to_radians() / 2.0 + (rad_b / pos2.distance(pos_b2)).atan() { // Weapon gives base damage let mut dmg = if let Some(ItemKind::Tool { power, .. }) = - stat.equipment.main.as_ref().map(|i| &i.kind) + attacker_stats.equipment.main.as_ref().map(|i| &i.kind) { *power as i32 } else { diff --git a/server/src/lib.rs b/server/src/lib.rs index f8815ad6cf..8804efe33f 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -413,21 +413,25 @@ impl Server { } } - // This sucks - let mut remove = false; + let mut remove = true; if let Some(client) = state.ecs().write_storage::().get_mut(entity) { - let _ = state + remove = false; + state .ecs() .write_storage() - .insert(entity, comp::Vel(Vec3::zero())); - let _ = state + .insert(entity, comp::Vel(Vec3::zero())) + .err() + .map(|err| error!("Failed to set zero vel on dead client: {:?}", err)); + state .ecs() .write_storage() - .insert(entity, comp::ForceUpdate); + .insert(entity, comp::ForceUpdate) + .err() + .map(|err| { + error!("Failed to insert ForceUpdate on dead client: {:?}", err) + }); client.force_state(ClientState::Dead); - } else { - remove = true; } if remove { diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index b9514a903b..6a20dbfbf0 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -756,10 +756,7 @@ impl Ui { } fn default_scissor(renderer: &Renderer) -> Aabr { - let (screen_w, screen_h) = renderer - .get_resolution() - .map(|e| (e as u16).max(1)) - .into_tuple(); + let (screen_w, screen_h) = renderer.get_resolution().into_tuple(); Aabr { min: Vec2 { x: 0, y: 0 }, max: Vec2 { From 6524ea31d11ef5f99b562e0b9ab463cfd8b68ac1 Mon Sep 17 00:00:00 2001 From: Imbris Date: Thu, 19 Dec 2019 23:28:37 -0500 Subject: [PATCH 11/11] Fix flight turning --- common/src/sys/movement.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/src/sys/movement.rs b/common/src/sys/movement.rs index f0f157b9ce..4c85dfc8cc 100644 --- a/common/src/sys/movement.rs +++ b/common/src/sys/movement.rs @@ -175,6 +175,10 @@ impl<'a> System<'a> for Sys { } else { Vec2::from(inputs.move_dir) } + } else if let Glide = character.movement { + // Note: non-gliding forces will also affect velocity and thus orientation + // producing potentially unexpected changes in direction + Vec2::from(vel.0) } else { Vec2::from(inputs.move_dir) };