Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy 0.10 #79

Merged
merged 10 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
delete azalea-ecs
  • Loading branch information
mat-1 committed Mar 7, 2023
commit 60e0feb10eb4a9d4a5067e7f2844860951ff1c73
33 changes: 9 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ members = [
"azalea-buf",
"azalea-physics",
"azalea-registry",
"azalea-ecs",
]

[profile.release]
Expand Down
3 changes: 2 additions & 1 deletion azalea-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ azalea-block = { path = "../azalea-block", version = "0.6.0" }
azalea-chat = { path = "../azalea-chat", version = "0.6.0" }
azalea-core = { path = "../azalea-core", version = "0.6.0" }
azalea-crypto = { path = "../azalea-crypto", version = "0.6.0" }
azalea-ecs = { path = "../azalea-ecs", version = "0.6.0" }
azalea-physics = { path = "../azalea-physics", version = "0.6.0" }
azalea-protocol = { path = "../azalea-protocol", version = "0.6.0" }
azalea-registry = { path = "../azalea-registry", version = "0.6.0" }
azalea-world = { path = "../azalea-world", version = "0.6.0" }
bevy_app = "0.10.0"
bevy_ecs = "0.10.0"
bevy_log = "0.10.0"
bevy_tasks = "0.10.0"
bevy_time = "0.10.0"
Expand Down
12 changes: 6 additions & 6 deletions azalea-client/src/chat.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//! Implementations of chat-related features.

use azalea_chat::FormattedText;
use azalea_ecs::{
app::{App, Plugin},
entity::Entity,
event::{EventReader, EventWriter},
schedule::{IntoSystemConfig, IntoSystemConfigs},
};
use azalea_protocol::packets::game::{
clientbound_player_chat_packet::ClientboundPlayerChatPacket,
clientbound_system_chat_packet::ClientboundSystemChatPacket,
serverbound_chat_command_packet::ServerboundChatCommandPacket,
serverbound_chat_packet::{LastSeenMessagesUpdate, ServerboundChatPacket},
};
use bevy_app::{App, Plugin};
use bevy_ecs::{
entity::Entity,
event::{EventReader, EventWriter},
schedule::{IntoSystemConfig, IntoSystemConfigs},
};
use std::{
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
Expand Down
43 changes: 20 additions & 23 deletions azalea-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ use crate::{

use azalea_auth::{game_profile::GameProfile, sessionserver::ClientSessionServerError};
use azalea_chat::FormattedText;
use azalea_ecs::{
app::CoreSchedule,
ecs::Ecs,
schedule::{LogLevel, ScheduleBuildSettings},
};
use azalea_ecs::{
app::{App, Plugin, PluginGroup, PluginGroupBuilder},
bundle::Bundle,
component::Component,
entity::Entity,
schedule::{IntoSystemConfig, ScheduleLabel},
};
use azalea_physics::{PhysicsPlugin, PhysicsSet};
use azalea_protocol::{
connect::{Connection, ConnectionError},
Expand All @@ -50,7 +38,16 @@ use azalea_protocol::{
};
use azalea_world::{
entity::{EntityPlugin, EntityUpdateSet, Local, WorldName},
PartialWorld, World, WorldContainer,
Instance, PartialWorld, WorldContainer,
};
use bevy_app::{App, CoreSchedule, Plugin, PluginGroup, PluginGroupBuilder};
use bevy_ecs::{
bundle::Bundle,
component::Component,
entity::Entity,
schedule::IntoSystemConfig,
schedule::{LogLevel, ScheduleBuildSettings, ScheduleLabel},
world::World,
};
use bevy_log::LogPlugin;
use bevy_time::{prelude::FixedTime, TimePlugin};
Expand Down Expand Up @@ -90,7 +87,7 @@ pub struct Client {
/// The entity component system. You probably don't need to access this
/// directly. Note that if you're using a shared world (i.e. a swarm), this
/// will contain all entities in all worlds.
pub ecs: Arc<Mutex<Ecs>>,
pub ecs: Arc<Mutex<World>>,

/// Use this to force the client to run the schedule outside of a tick.
pub run_schedule_sender: mpsc::UnboundedSender<()>,
Expand Down Expand Up @@ -124,7 +121,7 @@ impl Client {
pub fn new(
profile: GameProfile,
entity: Entity,
ecs: Arc<Mutex<Ecs>>,
ecs: Arc<Mutex<World>>,
run_schedule_sender: mpsc::UnboundedSender<()>,
) -> Self {
Self {
Expand Down Expand Up @@ -184,7 +181,7 @@ impl Client {
/// Create a [`Client`] when you already have the ECS made with
/// [`start_ecs`]. You'd usually want to use [`Self::join`] instead.
pub async fn start_client(
ecs_lock: Arc<Mutex<Ecs>>,
ecs_lock: Arc<Mutex<World>>,
account: &Account,
address: &ServerAddress,
resolved_address: &SocketAddr,
Expand Down Expand Up @@ -230,7 +227,7 @@ impl Client {
packet_writer_sender,
// default to an empty world, it'll be set correctly later when we
// get the login packet
Arc::new(RwLock::new(World::default())),
Arc::new(RwLock::new(Instance::default())),
read_packets_task,
write_packets_task,
);
Expand Down Expand Up @@ -386,13 +383,13 @@ impl Client {
});
}

pub fn local_player<'a>(&'a self, ecs: &'a mut Ecs) -> &'a LocalPlayer {
pub fn local_player<'a>(&'a self, ecs: &'a mut World) -> &'a LocalPlayer {
self.query::<&LocalPlayer>(ecs)
}
pub fn local_player_mut<'a>(
&'a self,
ecs: &'a mut Ecs,
) -> azalea_ecs::ecs::Mut<'a, LocalPlayer> {
ecs: &'a mut World,
) -> bevy_ecs::world::Mut<'a, LocalPlayer> {
self.query::<&mut LocalPlayer>(ecs)
}

Expand Down Expand Up @@ -420,7 +417,7 @@ impl Client {
/// client, then it'll be the same as the world the client has loaded.
/// If the client using a shared world, then the shared world will be a
/// superset of the client's world.
pub fn world(&self) -> Arc<RwLock<World>> {
pub fn world(&self) -> Arc<RwLock<Instance>> {
let world_name = self.component::<WorldName>();
let ecs = self.ecs.lock();
let world_container = ecs.resource::<WorldContainer>();
Expand Down Expand Up @@ -553,7 +550,7 @@ pub fn start_ecs(
mut app: App,
run_schedule_receiver: mpsc::UnboundedReceiver<()>,
run_schedule_sender: mpsc::UnboundedSender<()>,
) -> Arc<Mutex<Ecs>> {
) -> Arc<Mutex<World>> {
app.setup();

// all resources should have been added by now so we can take the ecs from the
Expand All @@ -571,7 +568,7 @@ pub fn start_ecs(
}

async fn run_schedule_loop(
ecs: Arc<Mutex<Ecs>>,
ecs: Arc<Mutex<World>>,
outer_schedule_label: Box<dyn ScheduleLabel>,
mut run_schedule_receiver: mpsc::UnboundedReceiver<()>,
) {
Expand Down
4 changes: 2 additions & 2 deletions azalea-client/src/disconnect.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Disconnect a client from the server.

use azalea_ecs::{
app::{App, CoreSet, Plugin},
use bevy_app::{App, Plugin, CoreSet};
use bevy_ecs::{
component::Component,
entity::Entity,
event::{EventReader, EventWriter},
Expand Down
12 changes: 6 additions & 6 deletions azalea-client/src/entity_query.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::sync::Arc;

use azalea_ecs::{
use bevy_ecs::{
component::Component,
ecs::Ecs,
entity::Entity,
query::{ROQueryItem, ReadOnlyWorldQuery, WorldQuery},
world::World,
};
use parking_lot::Mutex;

Expand All @@ -22,7 +22,7 @@ impl Client {
/// .is_some();
/// # }
/// ```
pub fn query<'w, Q: WorldQuery>(&self, ecs: &'w mut Ecs) -> <Q as WorldQuery>::Item<'w> {
pub fn query<'w, Q: WorldQuery>(&self, ecs: &'w mut World) -> <Q as WorldQuery>::Item<'w> {
ecs.query::<Q>()
.get_mut(ecs, self.entity)
.expect("Our client is missing a required component.")
Expand All @@ -38,7 +38,7 @@ impl Client {
/// Note that this will very likely change in the future.
/// ```
/// use azalea_client::{Client, GameProfileComponent};
/// use azalea_ecs::query::With;
/// use bevy_ecs::query::With;
/// use azalea_world::entity::{Position, metadata::Player};
///
/// # fn example(mut bot: Client, sender_name: String) {
Expand Down Expand Up @@ -74,15 +74,15 @@ impl Client {
}

pub trait EntityPredicate<Q: ReadOnlyWorldQuery, Filter: ReadOnlyWorldQuery> {
fn find(&self, ecs_lock: Arc<Mutex<Ecs>>) -> Option<Entity>;
fn find(&self, ecs_lock: Arc<Mutex<World>>) -> Option<Entity>;
}
impl<F, Q, Filter> EntityPredicate<(Q,), Filter> for F
where
F: Fn(&ROQueryItem<Q>) -> bool,
Q: ReadOnlyWorldQuery,
Filter: ReadOnlyWorldQuery,
{
fn find(&self, ecs_lock: Arc<Mutex<Ecs>>) -> Option<Entity> {
fn find(&self, ecs_lock: Arc<Mutex<World>>) -> Option<Entity> {
let mut ecs = ecs_lock.lock();
let mut query = ecs.query_filtered::<(Entity, Q), Filter>();
let entity = query.iter(&ecs).find(|(_, q)| (self)(q)).map(|(e, _)| e);
Expand Down
9 changes: 2 additions & 7 deletions azalea-client/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@

use std::sync::Arc;

use azalea_ecs::{
app::{App, CoreSchedule, IntoSystemAppConfig, Plugin},
component::Component,
event::EventReader,
query::Added,
system::Query,
};
use azalea_protocol::packets::game::{
clientbound_player_combat_kill_packet::ClientboundPlayerCombatKillPacket, ClientboundGamePacket,
};
use azalea_world::entity::MinecraftEntityId;
use bevy_app::{App, CoreSchedule, IntoSystemAppConfig, Plugin};
use bevy_ecs::{component::Component, event::EventReader, query::Added, system::Query};
use derive_more::{Deref, DerefMut};
use tokio::sync::mpsc;

Expand Down
1 change: 0 additions & 1 deletion azalea-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ mod player;
pub mod task_pool;

pub use account::Account;
pub use azalea_ecs as ecs;
pub use client::{init_ecs_app, start_ecs, Client, ClientInformation, JoinError};
pub use events::Event;
pub use local_player::{GameProfileComponent, LocalPlayer};
Expand Down
15 changes: 7 additions & 8 deletions azalea-client/src/local_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ use std::{collections::HashMap, io, sync::Arc};

use azalea_auth::game_profile::GameProfile;
use azalea_core::ChunkPos;
use azalea_ecs::component::Component;
use azalea_ecs::entity::Entity;
use azalea_ecs::event::EventReader;
use azalea_ecs::{query::Added, system::Query};
use azalea_protocol::packets::game::ServerboundGamePacket;
use azalea_world::{
entity::{self, Dead},
PartialWorld, World,
Instance, PartialWorld,
};
use bevy_ecs::{
component::Component, entity::Entity, event::EventReader, query::Added, system::Query,
};
use derive_more::{Deref, DerefMut};
use parking_lot::RwLock;
Expand Down Expand Up @@ -44,7 +43,7 @@ pub struct LocalPlayer {
pub partial_world: Arc<RwLock<PartialWorld>>,
/// The world is the combined [`PartialWorld`]s of all clients in the same
/// world. (Only relevant if you're using a shared world, i.e. a swarm)
pub world: Arc<RwLock<World>>,
pub world: Arc<RwLock<Instance>>,

/// A task that reads packets from the server. The client is disconnected
/// when this task ends.
Expand Down Expand Up @@ -88,7 +87,7 @@ impl LocalPlayer {
pub fn new(
entity: Entity,
packet_writer: mpsc::UnboundedSender<ServerboundGamePacket>,
world: Arc<RwLock<World>>,
world: Arc<RwLock<Instance>>,
read_packets_task: JoinHandle<()>,
write_packets_task: JoinHandle<()>,
) -> Self {
Expand Down Expand Up @@ -129,7 +128,7 @@ impl Drop for LocalPlayer {

/// Update the [`LocalPlayerInLoadedChunk`] component for all [`LocalPlayer`]s.
pub fn update_in_loaded_chunk(
mut commands: azalea_ecs::system::Commands,
mut commands: bevy_ecs::system::Commands,
query: Query<(Entity, &LocalPlayer, &entity::Position)>,
) {
for (entity, local_player, position) in &query {
Expand Down
Loading