1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

add bevy_ecs to deps

This commit is contained in:
Ubuntu 2022-12-13 22:58:20 +00:00
parent 1b99803b21
commit 129e2adf0a
4 changed files with 271 additions and 57 deletions

258
Cargo.lock generated
View file

@ -67,6 +67,17 @@ version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
[[package]]
name = "async-channel"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833"
dependencies = [
"concurrent-queue 2.0.0",
"event-listener",
"futures-core",
]
[[package]]
name = "async-compression"
version = "0.3.15"
@ -80,6 +91,30 @@ dependencies = [
"tokio",
]
[[package]]
name = "async-executor"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b"
dependencies = [
"async-lock",
"async-task",
"concurrent-queue 2.0.0",
"fastrand",
"futures-lite",
"slab",
]
[[package]]
name = "async-lock"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8101efe8695a6c17e02911402145357e718ac92d3ff88ae8419e84b1707b685"
dependencies = [
"event-listener",
"futures-lite",
]
[[package]]
name = "async-recursion"
version = "1.0.0"
@ -91,6 +126,12 @@ dependencies = [
"syn",
]
[[package]]
name = "async-task"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524"
[[package]]
name = "async-trait"
version = "0.1.59"
@ -377,8 +418,8 @@ dependencies = [
"azalea-core",
"azalea-nbt",
"azalea-registry",
"bevy_ecs",
"enum-as-inner",
"hecs",
"log",
"nohash-hasher",
"parking_lot",
@ -407,6 +448,83 @@ version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]]
name = "bevy_ecs"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c071d7c6bc9801253485e05d0c257284150de755391902746837ba21c0cf74"
dependencies = [
"async-channel",
"bevy_ecs_macros",
"bevy_ptr",
"bevy_tasks",
"bevy_utils",
"downcast-rs",
"event-listener",
"fixedbitset",
"fxhash",
"serde",
"thread_local",
]
[[package]]
name = "bevy_ecs_macros"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c15bd45438eeb681ad74f2d205bb07a5699f98f9524462a30ec764afab2742ce"
dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "bevy_macro_utils"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "022bb69196deeea691b6997414af85bbd7f2b34a8914c4aa7a7ff4dfa44f7677"
dependencies = [
"quote",
"syn",
"toml",
]
[[package]]
name = "bevy_ptr"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ec44f7655039546bc5d34d98de877083473f3e9b2b81d560c528d6d74d3eff4"
[[package]]
name = "bevy_tasks"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "680b16b53df9c9f24681dd95f4d772d83760bd19adf8bca00f358a3aad997853"
dependencies = [
"async-channel",
"async-executor",
"async-task",
"concurrent-queue 1.2.4",
"futures-lite",
"once_cell",
"wasm-bindgen-futures",
]
[[package]]
name = "bevy_utils"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16750aae52cd35bd7b60eb61cee883420b250e11b4a290b8d44b2b2941795739"
dependencies = [
"ahash 0.7.6",
"getrandom",
"hashbrown",
"instant",
"tracing",
"uuid",
]
[[package]]
name = "bitflags"
version = "1.3.2"
@ -466,6 +584,12 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
[[package]]
name = "cache-padded"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c"
[[package]]
name = "cast"
version = "0.3.0"
@ -524,6 +648,24 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "concurrent-queue"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af4780a44ab5696ea9e28294517f1fffb421a83a25af521333c838635509db9c"
dependencies = [
"cache-padded",
]
[[package]]
name = "concurrent-queue"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "core-foundation"
version = "0.9.3"
@ -685,6 +827,12 @@ dependencies = [
"crypto-common",
]
[[package]]
name = "downcast-rs"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "either"
version = "1.8.0"
@ -725,6 +873,12 @@ dependencies = [
"termcolor",
]
[[package]]
name = "event-listener"
version = "2.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
[[package]]
name = "fastrand"
version = "1.8.0"
@ -828,6 +982,21 @@ version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb"
[[package]]
name = "futures-lite"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48"
dependencies = [
"fastrand",
"futures-core",
"futures-io",
"memchr",
"parking",
"pin-project-lite",
"waker-fn",
]
[[package]]
name = "futures-macro"
version = "0.3.25"
@ -869,6 +1038,15 @@ dependencies = [
"slab",
]
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "generic-array"
version = "0.14.6"
@ -886,8 +1064,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"wasi",
"wasm-bindgen",
]
[[package]]
@ -928,6 +1108,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
dependencies = [
"ahash 0.7.6",
"serde",
]
[[package]]
@ -936,29 +1117,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hecs"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6530b5d25416ece146739e6130f7f7e39f9ee3435236be32b6774f548d76aac"
dependencies = [
"hashbrown",
"hecs-macros",
"lazy_static",
"spin 0.9.4",
]
[[package]]
name = "hecs-macros"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14883fb70dcf2363b5dd2321b9473117d91ebadf211959df748cec6927fd3765"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
@ -1092,6 +1250,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
@ -1135,9 +1296,6 @@ name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
dependencies = [
"spin 0.5.2",
]
[[package]]
name = "libc"
@ -1423,6 +1581,12 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "parking"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
[[package]]
name = "parking_lot"
version = "0.12.1"
@ -1857,18 +2021,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "spin"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09"
[[package]]
name = "syn"
version = "1.0.105"
@ -1943,6 +2095,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "thread_local"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
dependencies = [
"once_cell",
]
[[package]]
name = "tinytemplate"
version = "1.2.1"
@ -2023,6 +2184,15 @@ dependencies = [
"tracing",
]
[[package]]
name = "toml"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
dependencies = [
"serde",
]
[[package]]
name = "tower-service"
version = "0.3.2"
@ -2165,6 +2335,10 @@ name = "uuid"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c"
dependencies = [
"getrandom",
"serde",
]
[[package]]
name = "vcpkg"
@ -2178,6 +2352,12 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "waker-fn"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
[[package]]
name = "walkdir"
version = "2.3.2"

View file

@ -9,14 +9,14 @@ version = "0.5.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
azalea-block = {path = "../azalea-block", default-features = false, version = "^0.5.0"}
azalea-buf = {path = "../azalea-buf", version = "^0.5.0"}
azalea-chat = {path = "../azalea-chat", version = "^0.5.0"}
azalea-core = {path = "../azalea-core", version = "^0.5.0"}
azalea-nbt = {path = "../azalea-nbt", version = "^0.5.0"}
azalea-registry = {path = "../azalea-registry", version = "^0.5.0"}
azalea-block = { path = "../azalea-block", default-features = false, version = "^0.5.0" }
azalea-buf = { path = "../azalea-buf", version = "^0.5.0" }
azalea-chat = { path = "../azalea-chat", version = "^0.5.0" }
azalea-core = { path = "../azalea-core", version = "^0.5.0" }
azalea-nbt = { path = "../azalea-nbt", version = "^0.5.0" }
azalea-registry = { path = "../azalea-registry", version = "^0.5.0" }
bevy_ecs = { version = "0.9.1", default-features = false }
enum-as-inner = "0.5.1"
hecs = {version = "0.9.1", features = ["macros"]}
log = "0.4.17"
nohash-hasher = "0.2.0"
parking_lot = "^0.12.1"

View file

@ -15,6 +15,10 @@ use std::ops::{Deref, DerefMut};
use std::ptr::NonNull;
use uuid::Uuid;
/// NOTE: EntityId internally uses twice the memory as just a u32, so if a u32
/// would work just as well then use that.
pub type EntityId = hecs::Entity;
/// A reference to an entity in a world.
#[derive(Debug)]
pub struct Entity<'d, D = &'d WeakWorld> {

View file

@ -1,10 +1,12 @@
use crate::entity::EntityData;
use crate::entity::{EntityData, EntityId};
use azalea_core::ChunkPos;
use hecs::EntityBuilder;
use log::warn;
use nohash_hasher::{IntMap, IntSet};
use parking_lot::RwLock;
use std::{
collections::HashMap,
fmt::Debug,
sync::{Arc, Weak},
};
use uuid::Uuid;
@ -42,21 +44,32 @@ pub struct PartialEntityStorage {
///
/// [`PartialWorld::entity_mut`]: crate::PartialWorld::entity_mut
pub owner_entity_id: Option<u32>,
/// A counter for each entity that tracks how many updates we've observed
/// for it.
///
/// This is used for shared worlds (i.e. swarms), to make sure we don't
/// update entities twice on accident.
pub updates_received: IntMap<u32, u32>,
/// Strong references to the entities we have loaded.
data_by_id: IntMap<u32, Arc<EntityData>>,
/// A set of all the entity ids in render distance.
loaded_entity_ids: IntSet<u32>,
}
/// Weakly store entities in a world. If the entities aren't being referenced
/// by anything else (like an [`PartialEntityStorage`]), they'll be forgotten.
#[derive(Debug, Default)]
#[derive(Default)]
pub struct WeakEntityStorage {
data_by_id: IntMap<u32, Weak<EntityData>>,
/// The ECS that actually contains the entities.
ecs: hecs::World,
/// The number of `PartialWorld`s that have this entity loaded.
/// (this is reference counting)
entity_reference_count: IntMap<EntityId, usize>,
/// An index of all the entity ids we know are in a chunk
ids_by_chunk: HashMap<ChunkPos, IntSet<u32>>,
ids_by_chunk: HashMap<ChunkPos, IntSet<EntityId>>,
/// An index of entity ids by their UUIDs
id_by_uuid: HashMap<Uuid, u32>,
/// The canonical number of updates we've gotten for every entity.
pub updates_received: IntMap<u32, u32>,
}
@ -69,19 +82,24 @@ impl PartialEntityStorage {
shared,
owner_entity_id,
updates_received: IntMap::default(),
data_by_id: IntMap::default(),
loaded_entity_ids: IntSet::default(),
}
}
/// Add an entity to the storage.
#[inline]
pub fn insert(&mut self, id: u32, entity: EntityData) {
// if the entity is already in the shared world, we don't need to do anything
if self.shared.read().data_by_id.contains_key(&id) {
pub fn insert(&mut self, id: u32, bundle: impl bevy_ecs::prelude::Bundle) {
// if you're trying to optimize this, see if checking if the id is in
// self.loaded_entity_ids would help with performance
// i didn't put the check here just in case it doesn't actually help
// if the entity is already in the shared world, we don't need to do
// anything
if self.shared.read().contains_id(&id) {
return;
}
// add the entity to the "indexes"
// add the entity to the indexes
let mut shared = self.shared.write();
shared
.ids_by_chunk
@ -384,6 +402,18 @@ impl WeakEntityStorage {
}
}
impl Debug for WeakEntityStorage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("WeakEntityStorage")
// .field("ecs", &self.ecs)
.field("entity_reference_count", &self.entity_reference_count)
.field("ids_by_chunk", &self.ids_by_chunk)
.field("id_by_uuid", &self.id_by_uuid)
.field("updates_received", &self.updates_received)
.finish()
}
}
#[cfg(test)]
mod tests {
use crate::entity::{metadata, EntityMetadata};