Skip to content

Commit 3a440bb

Browse files
committed
refactor: update flecs
1 parent ec282f5 commit 3a440bb

File tree

31 files changed

+143
-137
lines changed

31 files changed

+143
-137
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hyperion-clap/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::iter::zip;
22

33
use clap::{Arg as ClapArg, Parser, ValueEnum, ValueHint, error::ErrorKind};
44
use flecs_ecs::{
5-
core::{Entity, EntityView, EntityViewGet, World, WorldGet, WorldProvider},
5+
core::{Entity, EntityView, EntityViewGet, World, WorldGet, WorldProvider, id},
66
prelude::{Component, Module},
77
};
88
use hyperion::{
@@ -45,7 +45,7 @@ pub trait MinecraftCommand: Parser + CommandPermission {
4545
let mut on = world
4646
.entity()
4747
.set(node_to_register)
48-
.child_of_id(get_root_command_entity());
48+
.child_of(get_root_command_entity());
4949

5050
for arg in cmd.get_arguments() {
5151
use valence_protocol::packets::play::command_tree_s2c::Parser as ValenceParser;
@@ -56,7 +56,7 @@ pub trait MinecraftCommand: Parser + CommandPermission {
5656
ValenceParser::String(StringArg::SingleWord),
5757
);
5858

59-
on = world.entity().set(node_to_register).child_of_id(on);
59+
on = world.entity().set(node_to_register).child_of(on);
6060
}
6161

6262
let on_execute = |input: &str, system: EntityView<'_>, caller: Entity| {
@@ -315,7 +315,7 @@ impl MinecraftCommand for PermissionCommand {
315315
entity.entity_view(world).get::<&mut Group>(|group| {
316316
if *group != cmd.group {
317317
*group = cmd.group;
318-
entity.entity_view(world).modified::<Group>();
318+
entity.entity_view(world).modified(id::<Group>());
319319
}
320320

321321
caller.entity_view(world).get::<&ConnectionId>(|stream| {

crates/hyperion-permission/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clap::ValueEnum;
22
use flecs_ecs::{
3-
core::{EntityViewGet, QueryBuilderImpl, SystemAPI, TermBuilderImpl, World, WorldGet},
3+
core::{EntityViewGet, QueryBuilderImpl, SystemAPI, TermBuilderImpl, World, WorldGet, id},
44
macros::{Component, observer},
55
prelude::{Module, flecs},
66
};
@@ -50,22 +50,22 @@ impl Module for PermissionModule {
5050
});
5151

5252
observer!(world, flecs::OnSet, &Uuid, &storage::PermissionStorage($))
53-
.with::<Player>()
53+
.with(id::<Player>())
5454
.each_entity(|entity, (uuid, permissions)| {
5555
let group = permissions.get(**uuid);
5656
entity.set(group);
5757
});
5858

5959
observer!(world, flecs::OnRemove, &Uuid, &Group, &storage::PermissionStorage($))
60-
.with::<Player>()
60+
.with(id::<Player>())
6161
.each(|(uuid, group, permissions)| {
6262
permissions.set(**uuid, *group).unwrap();
6363
});
6464

6565
observer!(world, flecs::OnSet, &Group).each_iter(|it, row, _group| {
6666
let system = it.system();
6767
let world = it.world();
68-
let entity = it.entity(row);
68+
let entity = it.entity(row).expect("row must be in bounds");
6969

7070
let root_command = hyperion::simulation::command::get_root_command_entity();
7171

crates/hyperion-respawn/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use hyperion::{
22
flecs_ecs::{
33
self,
4-
core::{EntityViewGet, World, WorldGet},
4+
core::{id, EntityViewGet, World, WorldGet},
55
macros::Component,
66
prelude::Module,
77
},
@@ -65,7 +65,7 @@ impl Module for RespawnModule {
6565
health.heal(20.);
6666

6767
*pose = Pose::Standing;
68-
client.modified::<Pose>(); // this is so observers detect the change
68+
client.modified(id::<Pose>()); // this is so observers detect the change
6969

7070
let pkt_health = play::HealthUpdateS2c {
7171
health: health.abs(),

crates/hyperion/src/egress/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ impl Module for EgressModule {
4646

4747
let pipeline = world
4848
.entity()
49-
.add::<flecs::pipeline::Phase>()
50-
.depends_on::<flecs::pipeline::OnStore>();
49+
.add(id::<flecs::pipeline::Phase>())
50+
.depends_on(id::<flecs::pipeline::OnStore>());
5151

5252
world.import::<StatsModule>();
5353
world.import::<PlayerJoinModule>();
@@ -60,7 +60,7 @@ impl Module for EgressModule {
6060
&Compose($),
6161
&mut Blocks($),
6262
)
63-
.kind::<flecs::pipeline::OnUpdate>()
63+
.kind(id::<flecs::pipeline::OnUpdate>())
6464
.each_iter(move |it: TableIter<'_, false>, _, (compose, mc)| {
6565
let span = info_span!("broadcast_chunk_deltas");
6666
let _enter = span.enter();
@@ -101,7 +101,7 @@ impl Module for EgressModule {
101101
&mut Compose($),
102102
&mut EgressComm($),
103103
)
104-
.kind_id(pipeline)
104+
.kind(pipeline)
105105
.each(move |(compose, egress)| {
106106
let span = info_span!("egress");
107107
let _enter = span.enter();
@@ -166,7 +166,7 @@ impl Module for EgressModule {
166166
world,
167167
&mut Compose($),
168168
)
169-
.kind_id(pipeline)
169+
.kind(pipeline)
170170
.each(move |compose| {
171171
let span = info_span!("clear_bump");
172172
let _enter = span.enter();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ pub fn player_join_world(
244244
.iter_stage(world)
245245
.each_iter(|it, idx, (uuid, _, position, yaw, pitch, _, flags)| {
246246
let mut result = || {
247-
let query_entity = it.entity(idx);
247+
let query_entity = it.entity(idx).expect("idx must be in bounds");
248248

249249
if entity.id() == query_entity.id() {
250250
return anyhow::Ok(());
@@ -545,7 +545,7 @@ impl Module for PlayerJoinModule {
545545
&Config($),
546546
&RayonWorldStages($),
547547
)
548-
.kind::<flecs::pipeline::PreUpdate>()
548+
.kind(id::<flecs::pipeline::PreUpdate>())
549549
.each_iter(
550550
move |it, _, (comms, compose, crafting_registry, config, stages)| {
551551
let span = tracing::info_span!("joins");

crates/hyperion/src/egress/stats.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Module for StatsModule {
1818
// let system_id = GLOBAL_STATS;
1919

2020
system!("global_update", world, &mut Compose($))
21-
.kind::<flecs::pipeline::OnUpdate>() // ? OnUpdate
21+
.kind(id::<flecs::pipeline::OnUpdate>()) // ? OnUpdate
2222
.each_iter(move |_, _, compose| {
2323
let global = compose.global_mut();
2424

@@ -41,7 +41,7 @@ impl Module for StatsModule {
4141
world,
4242
&mut Blocks($),
4343
)
44-
.kind::<flecs::pipeline::OnUpdate>()
44+
.kind(id::<flecs::pipeline::OnUpdate>())
4545
.each_iter(|_iter, _, blocks| {
4646
let span = info_span!("load_pending");
4747
let _enter = span.enter();

crates/hyperion/src/egress/sync_chunks.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Module for SyncChunksModule {
4444
&mut ChunkSendQueue,
4545
)
4646
.with_enum(PacketState::Play)
47-
.kind::<flecs::pipeline::OnUpdate>()
47+
.kind(id::<flecs::pipeline::OnUpdate>())
4848
.each_iter(
4949
move |it, _, (compose, last_sent, pose, &stream_id, chunk_changes)| {
5050
let system = it.system();
@@ -159,8 +159,7 @@ impl Module for SyncChunksModule {
159159

160160
system!("send_full_loaded_chunks", world, &Blocks($), &Compose($), &ConnectionId, &mut ChunkSendQueue)
161161
.with_enum(PacketState::Play)
162-
.kind::<flecs::pipeline::OnUpdate>()
163-
162+
.kind(id::<flecs::pipeline::OnUpdate>())
164163
.each_iter(
165164
move |it, _, (chunks, compose, &stream_id, queue)| {
166165
const MAX_CHUNKS_PER_TICK: usize = 16;

crates/hyperion/src/egress/sync_entity_state.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ pub struct EntityStateSyncModule;
3131
fn track_previous<T: ComponentId + Copy + Debug + PartialEq>(world: &World) {
3232
let post_store = world
3333
.entity_named("post_store")
34-
.add::<flecs::pipeline::Phase>()
35-
.depends_on::<flecs::pipeline::OnStore>();
34+
.add(id::<flecs::pipeline::Phase>())
35+
.depends_on(id::<flecs::pipeline::OnStore>());
3636

3737
// we include names so that if we call this multiple times, we don't get multiple observers/systems
3838
let component_name = std::any::type_name::<T>();
@@ -46,14 +46,14 @@ fn track_previous<T: ComponentId + Copy + Debug + PartialEq>(world: &World) {
4646

4747
world
4848
.observer_named::<flecs::OnSet, &T>(&observer_name)
49-
.without::<(Prev, T)>() // we have not set Prev yet
49+
.without((id::<Prev>(), id::<T>())) // we have not set Prev yet
5050
.each_entity(|entity, value| {
5151
entity.set_pair::<Prev, T>(*value);
5252
});
5353

5454
world
5555
.system_named::<(&mut (Prev, T), &T)>(system_name.as_str())
56-
.kind_id(post_store)
56+
.kind(post_store)
5757
.each(|(prev, value)| {
5858
*prev = *value;
5959
});
@@ -70,7 +70,7 @@ impl Module for EntityStateSyncModule {
7070
)>("entity_xp_sync")
7171
.term_at(0u32)
7272
.singleton()
73-
.kind::<flecs::pipeline::OnStore>()
73+
.kind(id::<flecs::pipeline::OnStore>())
7474
.each_iter(|table, idx, (compose, net, prev_xp, current)| {
7575
const {
7676
assert!(size_of::<Xp>() == size_of::<u16>());
@@ -87,8 +87,8 @@ impl Module for EntityStateSyncModule {
8787
total_xp: VarInt::default(),
8888
};
8989

90-
let entity = table.entity(idx);
91-
entity.modified::<Xp>();
90+
let entity = table.entity(idx).expect("idx must be in bounds");
91+
entity.modified(id::<Xp>());
9292

9393
compose.unicast(&packet, *net, system).unwrap();
9494
}
@@ -97,10 +97,10 @@ impl Module for EntityStateSyncModule {
9797
});
9898

9999
system!("entity_metadata_sync", world, &Compose($), &mut MetadataChanges)
100-
.kind::<flecs::pipeline::OnStore>()
100+
.kind(id::<flecs::pipeline::OnStore>())
101101
.each_iter(move |it, row, (compose, metadata_changes)| {
102102
let system = it.system();
103-
let entity = it.entity(row);
103+
let entity = it.entity(row).expect("row must be in bounds");
104104
let entity_id = VarInt(entity.minecraft_id());
105105

106106
let metadata = get_and_clear_metadata(metadata_changes);
@@ -110,7 +110,7 @@ impl Module for EntityStateSyncModule {
110110
entity_id,
111111
tracked_values: RawBytes(&view),
112112
};
113-
if entity.has::<Position>() {
113+
if entity.has(id::<Position>()) {
114114
entity.get::<&Position>(|position| {
115115
compose
116116
.broadcast_local(&pkt, position.to_chunk(), system)
@@ -132,12 +132,12 @@ impl Module for EntityStateSyncModule {
132132
?&ConnectionId,
133133
&mut ActiveAnimation,
134134
)
135-
.kind::<flecs::pipeline::OnStore>()
135+
.kind(id::<flecs::pipeline::OnStore>())
136136
.each_iter(
137137
move |it, row, (position, compose, connection_id, animation)| {
138138
let io = connection_id.copied();
139139

140-
let entity = it.entity(row);
140+
let entity = it.entity(row).expect("row must be in bounds");
141141
let system = it.system();
142142

143143
let entity_id = VarInt(entity.minecraft_id());
@@ -173,7 +173,7 @@ impl Module for EntityStateSyncModule {
173173
&mut MovementTracking,
174174
&Flight,
175175
)
176-
.kind::<flecs::pipeline::PreStore>()
176+
.kind(id::<flecs::pipeline::PreStore>())
177177
.each_iter(
178178
|it,
179179
row,
@@ -192,7 +192,7 @@ impl Module for EntityStateSyncModule {
192192
)| {
193193
let world = it.system().world();
194194
let system = it.system();
195-
let entity = it.entity(row);
195+
let entity = it.entity(row).expect("row must be in bounds");
196196
let entity_id = VarInt(entity.minecraft_id());
197197

198198
if let Some(pending_teleport) = pending_teleport {
@@ -363,7 +363,7 @@ impl Module for EntityStateSyncModule {
363363
&Owner,
364364
?&ConnectionId
365365
)
366-
.kind::<flecs::pipeline::OnUpdate>()
366+
.kind(id::<flecs::pipeline::OnUpdate>())
367367
.with_enum_wildcard::<EntityKind>()
368368
.each_iter(|it, row, (position, velocity, owner, connection_id)| {
369369
if let Some(_connection_id) = connection_id {
@@ -372,7 +372,7 @@ impl Module for EntityStateSyncModule {
372372

373373
let system = it.system();
374374
let world = system.world();
375-
let arrow_entity = it.entity(row);
375+
let arrow_entity = it.entity(row).expect("row must be in bounds");
376376

377377
if velocity.0 != Vec3::ZERO {
378378
let center = **position;

0 commit comments

Comments
 (0)