Skip to content

Commit 1027d60

Browse files
committed
refactor: replace Play component with PacketState enum
Replace standalone `Play` component with `PacketState::Play` enum variant for better state management. Changes include: - Remove `Play` component and update queries to use `PacketState::Play` - Update player join logic to use `add_enum(PacketState::Play)` - Add `#[meta]` attribute to `ChatCooldown` component This change consolidates player state handling into the `PacketState` enum rather than using separate marker components.
1 parent 9b30f14 commit 1027d60

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

crates/hyperion/src/egress/player_join/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use valence_registry::{BiomeRegistry, RegistryCodec};
2121
use valence_server::entity::EntityKind;
2222
use valence_text::IntoText;
2323

24-
use crate::simulation::Pitch;
24+
use crate::simulation::{PacketState, Pitch};
2525

2626
mod list;
2727
pub use list::*;
@@ -35,7 +35,7 @@ use crate::{
3535
command::{get_command_packet, Command, ROOT_COMMAND},
3636
skin::PlayerSkin,
3737
util::registry_codec_raw,
38-
Comms, InGameName, Play, Position, Uuid, Yaw,
38+
Comms, InGameName, Position, Uuid, Yaw,
3939
},
4040
system_registry::{SystemId, PLAYER_JOINS},
4141
util::{SendableQuery, SendableRef},
@@ -622,7 +622,7 @@ impl Module for PlayerJoinModule {
622622
let entity = world.entity_from_id(entity);
623623
entity.set(skin);
624624

625-
entity.add::<Play>();
625+
entity.add_enum(PacketState::Play);
626626
});
627627
});
628628
}

crates/hyperion/src/egress/stats.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use tracing::{error, trace_span};
33

44
use crate::{
55
net::Compose,
6-
simulation::{blocks::Blocks, Play},
6+
simulation::{blocks::Blocks, PacketState},
77
};
88

99
#[derive(Component)]
1010
pub struct StatsModule;
1111

1212
impl Module for StatsModule {
1313
fn module(world: &World) {
14-
let players = world.new_query::<&Play>();
14+
let players = world.query::<()>().with_enum(PacketState::Play).build();
1515

1616
// let last_frame_time_total = 0.0;
1717

crates/hyperion/src/egress/sync_chunks.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
net::{Compose, DataBundle, NetworkStreamRef},
1515
simulation::{
1616
blocks::{Blocks, GetChunk},
17-
ChunkPosition, Play, Position,
17+
ChunkPosition, PacketState, Position,
1818
},
1919
system_registry::{GENERATE_CHUNK_CHANGES, SEND_FULL_LOADED_CHUNKS},
2020
util::TracingExt,
@@ -49,7 +49,7 @@ impl Module for SyncChunksModule {
4949
&NetworkStreamRef,
5050
&mut ChunkSendQueue,
5151
)
52-
.with::<Play>()
52+
.with_enum(PacketState::Play)
5353
.kind::<flecs::pipeline::OnUpdate>()
5454
.multi_threaded()
5555
.tracing_each_entity(
@@ -168,7 +168,7 @@ impl Module for SyncChunksModule {
168168
let system_id = SEND_FULL_LOADED_CHUNKS;
169169

170170
system!("send_full_loaded_chunks", world, &Blocks($), &Compose($), &NetworkStreamRef, &mut ChunkSendQueue)
171-
.with::<Play>()
171+
.with_enum(PacketState::Play)
172172
.kind::<flecs::pipeline::OnUpdate>()
173173
.multi_threaded()
174174
.each_entity(

crates/hyperion/src/simulation/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ pub struct InGameName(Arc<str>);
124124
#[derive(Component, Deref, DerefMut, From, Debug, Default)]
125125
pub struct IgnMap(DeferredMap<Arc<str>, Entity>);
126126

127-
/// This component is added to all players once they reach the play state. See [`PacketState::Play`].
128-
#[derive(Component, Default)]
129-
pub struct Play;
130-
131127
/// A component that represents a Player. In the future, this should be broken up into multiple components.
132128
///
133129
/// Why should it be broken up? The more things are broken up, the more we can take advantage of Rust borrowing rules.
@@ -514,7 +510,6 @@ impl Module for SimModule {
514510
world.component::<Health>().meta();
515511
world.component::<ChunkPosition>().meta();
516512
world.component::<EntityReaction>().meta();
517-
world.component::<Play>();
518513
world.component::<ConfirmBlockSequences>();
519514
world.component::<metadata::Metadata>();
520515
world.component::<animation::ActiveAnimation>();

events/proof-of-concept/src/module/chat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const CHAT_COOLDOWN_SECONDS: i64 = 15; // 15 seconds
1515
const CHAT_COOLDOWN_TICKS: i64 = CHAT_COOLDOWN_SECONDS * 20; // Convert seconds to ticks
1616

1717
#[derive(Default, Component)]
18+
#[meta]
1819
pub struct ChatCooldown {
1920
pub expires: i64,
2021
}
@@ -26,7 +27,7 @@ impl Module for ChatModule {
2627
fn module(world: &World) {
2728
let system_id = SystemId(8);
2829

29-
world.component::<ChatCooldown>();
30+
world.component::<ChatCooldown>().meta();
3031

3132
world
3233
.component::<Player>()

0 commit comments

Comments
 (0)