Skip to content

Commit

Permalink
Update to bevy 0.11-dev (#392)
Browse files Browse the repository at this point in the history
## Description

- Update to a recent development version of bevy 0.11 in an effort to
solve #323.
- Resolve footgun with event loop by moving it to a dedicated schedule
that runs after `PreUpdate`.
- Miscellaneous code quality improvements.
- Disable `dump_schedule` tool because it's stuck on bevy 0.10.
  • Loading branch information
rj00a authored Jun 21, 2023
1 parent 0f3e6f2 commit 85526b5
Show file tree
Hide file tree
Showing 63 changed files with 506 additions and 506 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ opt-level = 1

[workspace]
members = ["crates/*", "tools/*"]
exclude = ["tools/dump_schedule"]
resolver = "2"

[workspace.package]
Expand All @@ -95,11 +96,10 @@ arrayvec = "0.7.2"
async-trait = "0.1.60"
atty = "0.2.14"
base64 = "0.21.0"
bevy_app = { version = "0.10.1", default-features = false }
bevy_ecs = { version = "0.10.1", default-features = false, features = [
"trace",
] }
bevy_hierarchy = { version = "0.10.1", default-features = false }
bevy_app = { git = "https://github.com/bevyengine/bevy", rev = "910f984709fb58cddbb7393c948634a2540e8d72", default-features = false }
bevy_ecs = { git = "https://github.com/bevyengine/bevy", rev = "910f984709fb58cddbb7393c948634a2540e8d72", default-features = false }
bevy_hierarchy = { git = "https://github.com/bevyengine/bevy", rev = "910f984709fb58cddbb7393c948634a2540e8d72", default-features = false }
bevy_utils = { git = "https://github.com/bevyengine/bevy", rev = "910f984709fb58cddbb7393c948634a2540e8d72" }
bevy_mod_debugdump = "0.7.0"
bitfield-struct = "0.3.1"
byteorder = "1.4.3"
Expand Down
2 changes: 1 addition & 1 deletion benches/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn idle_update(c: &mut Criterion) {
let mut app = App::new();

app.add_plugins(DefaultPlugins);
app.add_startup_system(setup);
app.add_systems(Startup, setup);

// Run startup schedule.
app.update();
Expand Down
10 changes: 5 additions & 5 deletions crates/valence_advancement/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use bevy_ecs::prelude::{Entity, EventReader, EventWriter};
use bevy_ecs::prelude::*;
use valence_client::event_loop::PacketEvent;
use valence_core::ident::Ident;

use crate::packet::AdvancementTabC2s;

/// This event sends when the client changes or closes advancement's tab.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct AdvancementTabChange {
#[derive(Event, Clone, PartialEq, Eq, Debug)]
pub struct AdvancementTabChangeEvent {
pub client: Entity,
/// If None then the client has closed advancement's tabs.
pub opened_tab: Option<Ident<String>>,
}

pub(crate) fn handle_advancement_tab_change(
mut packets: EventReader<PacketEvent>,
mut advancement_tab_change_events: EventWriter<AdvancementTabChange>,
mut advancement_tab_change_events: EventWriter<AdvancementTabChangeEvent>,
) {
for packet in packets.iter() {
if let Some(pkt) = packet.decode::<AdvancementTabC2s>() {
advancement_tab_change_events.send(AdvancementTabChange {
advancement_tab_change_events.send(AdvancementTabChangeEvent {
client: packet.client,
opened_tab: match pkt {
AdvancementTabC2s::ClosedScreen => None,
Expand Down
47 changes: 25 additions & 22 deletions crates/valence_advancement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ use std::borrow::Cow;
use std::io::Write;
use std::time::{SystemTime, UNIX_EPOCH};

use bevy_app::{CoreSet, Plugin};
use bevy_ecs::prelude::{Bundle, Component, Entity};
use bevy_ecs::query::{Added, Changed, Or, With};
use bevy_ecs::schedule::{IntoSystemConfig, IntoSystemSetConfig, SystemSet};
use bevy_ecs::system::{Commands, Query, SystemParam};
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use bevy_ecs::system::SystemParam;
pub use bevy_hierarchy;
use bevy_hierarchy::{Children, Parent};
use event::{handle_advancement_tab_change, AdvancementTabChange};
use event::{handle_advancement_tab_change, AdvancementTabChangeEvent};
use packet::SelectAdvancementTabS2c;
use rustc_hash::FxHashMap;
use valence_client::{Client, FlushPacketsSet, SpawnClientsSet};
Expand All @@ -37,23 +35,28 @@ pub struct WriteAdvancementToCacheSet;

impl Plugin for AdvancementPlugin {
fn build(&self, app: &mut bevy_app::App) {
app.configure_sets((
WriteAdvancementPacketToClientsSet
.in_base_set(CoreSet::PostUpdate)
.before(FlushPacketsSet),
WriteAdvancementToCacheSet
.in_base_set(CoreSet::PostUpdate)
.before(WriteAdvancementPacketToClientsSet),
))
.add_event::<AdvancementTabChange>()
.add_system(
add_advancement_update_component_to_new_clients
.after(SpawnClientsSet)
.in_base_set(CoreSet::PreUpdate),
app.configure_sets(
PostUpdate,
(
WriteAdvancementPacketToClientsSet.before(FlushPacketsSet),
WriteAdvancementToCacheSet.before(WriteAdvancementPacketToClientsSet),
),
)
.add_event::<AdvancementTabChangeEvent>()
.add_systems(
PreUpdate,
(
add_advancement_update_component_to_new_clients.after(SpawnClientsSet),
handle_advancement_tab_change,
),
)
.add_system(handle_advancement_tab_change.in_base_set(CoreSet::PreUpdate))
.add_system(update_advancement_cached_bytes.in_set(WriteAdvancementToCacheSet))
.add_system(send_advancement_update_packet.in_set(WriteAdvancementPacketToClientsSet));
.add_systems(
PostUpdate,
(
update_advancement_cached_bytes,
send_advancement_update_packet,
),
);
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/valence_anvil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ impl Plugin for AnvilPlugin {
fn build(&self, app: &mut App) {
app.add_event::<ChunkLoadEvent>()
.add_event::<ChunkUnloadEvent>()
.add_system(remove_unviewed_chunks.in_base_set(CoreSet::PreUpdate))
.add_systems(PreUpdate, remove_unviewed_chunks)
.add_systems(
PostUpdate,
(init_anvil, update_client_views, send_recv_chunks)
.chain()
.in_base_set(CoreSet::PostUpdate)
.before(UpdateClientsSet),
);
}
Expand Down Expand Up @@ -433,7 +433,7 @@ fn anvil_worker(mut state: ChunkWorkerState) {
}

/// An event sent by `valence_anvil` after an attempt to load a chunk is made.
#[derive(Debug)]
#[derive(Event, Debug)]
pub struct ChunkLoadEvent {
/// The [`Instance`] where the chunk is located.
pub instance: Entity,
Expand All @@ -460,7 +460,7 @@ pub enum ChunkLoadStatus {
}

/// An event sent by `valence_anvil` when a chunk is unloaded from an instance.
#[derive(Debug)]
#[derive(Event, Debug)]
pub struct ChunkUnloadEvent {
/// The [`Instance`] where the chunk was unloaded.
pub instance: Entity,
Expand Down
8 changes: 2 additions & 6 deletions crates/valence_biome/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ pub struct BiomePlugin;
impl Plugin for BiomePlugin {
fn build(&self, app: &mut App) {
app.init_resource::<BiomeRegistry>()
.add_startup_system(load_default_biomes.in_base_set(CoreSet::PreUpdate))
.add_system(
update_biome_registry
.in_base_set(CoreSet::PostUpdate)
.before(RegistrySet),
);
.add_systems(PreStartup, load_default_biomes)
.add_systems(PostUpdate, update_biome_registry.before(RegistrySet));
}
}

Expand Down
12 changes: 4 additions & 8 deletions crates/valence_boss_bar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@

use std::borrow::Cow;

use bevy_app::CoreSet::PostUpdate;
use bevy_app::Plugin;
use bevy_ecs::prelude::Entity;
use bevy_ecs::query::{Added, Changed, With};
use bevy_ecs::schedule::{IntoSystemConfig, IntoSystemConfigs};
use bevy_ecs::system::Query;
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use packet::{BossBarAction, BossBarS2c};
use valence_client::{Client, FlushPacketsSet};
use valence_core::despawn::Despawned;
Expand All @@ -42,6 +38,7 @@ pub struct BossBarPlugin;
impl Plugin for BossBarPlugin {
fn build(&self, app: &mut bevy_app::App) {
app.add_systems(
PostUpdate,
(
boss_bar_title_update,
boss_bar_health_update,
Expand All @@ -51,8 +48,7 @@ impl Plugin for BossBarPlugin {
boss_bar_despawn,
client_disconnection.before(boss_bar_viewers_update),
)
.before(FlushPacketsSet)
.in_base_set(PostUpdate),
.before(FlushPacketsSet),
);
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/valence_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition.workspace = true
anyhow.workspace = true
bevy_app.workspace = true
bevy_ecs.workspace = true
bevy_utils.workspace = true # Needed for `ScheduleLabel` derive macro.
bitfield-struct.workspace = true
bytes.workspace = true
glam.workspace = true
Expand Down
15 changes: 7 additions & 8 deletions crates/valence_client/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ use valence_core::protocol::var_int::VarInt;
use valence_core::protocol::{packet_id, Decode, Encode, Packet};

use super::*;
use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent};
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};
use crate::packet::{PlayerAction, PlayerActionC2s};

pub(super) fn build(app: &mut App) {
app.add_event::<DiggingEvent>()
.add_system(
handle_player_action
.in_schedule(EventLoopSchedule)
.in_base_set(EventLoopSet::PreUpdate),
)
.add_system(acknowledge_player_actions.in_set(UpdateClientsSet));
.add_systems(EventLoopPreUpdate, handle_player_action)
.add_systems(
PostUpdate,
acknowledge_player_actions.in_set(UpdateClientsSet),
);
}

#[derive(Copy, Clone, Debug)]
#[derive(Event, Copy, Clone, Debug)]
pub struct DiggingEvent {
pub client: Entity,
pub position: BlockPos,
Expand Down
16 changes: 6 additions & 10 deletions crates/valence_client/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@ use valence_core::protocol::{packet_id, Decode, Encode, Packet};
use valence_entity::entity::Flags;
use valence_entity::{entity, Pose};

use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent};
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};

pub(super) fn build(app: &mut App) {
app.add_event::<SprintEvent>()
.add_event::<SneakEvent>()
.add_event::<JumpWithHorseEvent>()
.add_event::<LeaveBedEvent>()
.add_system(
handle_client_command
.in_schedule(EventLoopSchedule)
.in_base_set(EventLoopSet::PreUpdate),
);
.add_systems(EventLoopPreUpdate, handle_client_command);
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)]
pub struct SprintEvent {
pub client: Entity,
pub state: SprintState,
Expand All @@ -31,7 +27,7 @@ pub enum SprintState {
Stop,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)]
pub struct SneakEvent {
pub client: Entity,
pub state: SneakState,
Expand All @@ -43,7 +39,7 @@ pub enum SneakState {
Stop,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)]
pub struct JumpWithHorseEvent {
pub client: Entity,
pub state: JumpWithHorseState,
Expand All @@ -58,7 +54,7 @@ pub enum JumpWithHorseState {
Stop,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)]
pub struct LeaveBedEvent {
pub client: Entity,
}
Expand Down
11 changes: 4 additions & 7 deletions crates/valence_client/src/custom_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ use valence_core::protocol::raw::RawBytes;
use valence_core::protocol::{packet_id, Decode, Encode};

use super::*;
use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent};
use crate::event_loop::{EventLoopPreUpdate, PacketEvent};

pub(super) fn build(app: &mut App) {
app.add_event::<CustomPayloadEvent>().add_system(
handle_custom_payload
.in_schedule(EventLoopSchedule)
.in_base_set(EventLoopSet::PreUpdate),
);
app.add_event::<CustomPayloadEvent>()
.add_systems(EventLoopPreUpdate, handle_custom_payload);
}

#[derive(Clone, Debug)]
#[derive(Event, Clone, Debug)]
pub struct CustomPayloadEvent {
pub client: Entity,
pub channel: Ident<String>,
Expand Down
Loading

0 comments on commit 85526b5

Please sign in to comment.