Skip to content

refactor: update flecs #899

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

Merged
merged 2 commits into from
May 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions crates/hyperion-clap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::iter::zip;

use clap::{Arg as ClapArg, Parser, ValueEnum, ValueHint, error::ErrorKind};
use flecs_ecs::{
core::{Entity, EntityView, EntityViewGet, World, WorldGet, WorldProvider},
core::{Entity, EntityView, EntityViewGet, World, WorldGet, WorldProvider, id},
prelude::{Component, Module},
};
use hyperion::{
Expand Down Expand Up @@ -45,7 +45,7 @@ pub trait MinecraftCommand: Parser + CommandPermission {
let mut on = world
.entity()
.set(node_to_register)
.child_of_id(get_root_command_entity());
.child_of(get_root_command_entity());

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

on = world.entity().set(node_to_register).child_of_id(on);
on = world.entity().set(node_to_register).child_of(on);
}

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

caller.entity_view(world).get::<&ConnectionId>(|stream| {
Expand Down
8 changes: 4 additions & 4 deletions crates/hyperion-permission/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::ValueEnum;
use flecs_ecs::{
core::{EntityViewGet, QueryBuilderImpl, SystemAPI, TermBuilderImpl, World, WorldGet},
core::{EntityViewGet, QueryBuilderImpl, SystemAPI, TermBuilderImpl, World, WorldGet, id},
macros::{Component, observer},
prelude::{Module, flecs},
};
Expand Down Expand Up @@ -50,22 +50,22 @@ impl Module for PermissionModule {
});

observer!(world, flecs::OnSet, &Uuid, &storage::PermissionStorage($))
.with::<Player>()
.with(id::<Player>())
.each_entity(|entity, (uuid, permissions)| {
let group = permissions.get(**uuid);
entity.set(group);
});

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions crates/hyperion-respawn/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use hyperion::{
flecs_ecs::{
self,
core::{EntityViewGet, World, WorldGet},
core::{id, EntityViewGet, World, WorldGet},
macros::Component,
prelude::Module,
},
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Module for RespawnModule {
health.heal(20.);

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

let pkt_health = play::HealthUpdateS2c {
health: health.abs(),
Expand Down
10 changes: 5 additions & 5 deletions crates/hyperion/src/egress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl Module for EgressModule {

let pipeline = world
.entity()
.add::<flecs::pipeline::Phase>()
.depends_on::<flecs::pipeline::OnStore>();
.add(id::<flecs::pipeline::Phase>())
.depends_on(id::<flecs::pipeline::OnStore>());

world.import::<StatsModule>();
world.import::<PlayerJoinModule>();
Expand All @@ -60,7 +60,7 @@ impl Module for EgressModule {
&Compose($),
&mut Blocks($),
)
.kind::<flecs::pipeline::OnUpdate>()
.kind(id::<flecs::pipeline::OnUpdate>())
.each_iter(move |it: TableIter<'_, false>, _, (compose, mc)| {
let span = info_span!("broadcast_chunk_deltas");
let _enter = span.enter();
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Module for EgressModule {
&mut Compose($),
&mut EgressComm($),
)
.kind_id(pipeline)
.kind(pipeline)
.each(move |(compose, egress)| {
let span = info_span!("egress");
let _enter = span.enter();
Expand Down Expand Up @@ -166,7 +166,7 @@ impl Module for EgressModule {
world,
&mut Compose($),
)
.kind_id(pipeline)
.kind(pipeline)
.each(move |compose| {
let span = info_span!("clear_bump");
let _enter = span.enter();
Expand Down
4 changes: 2 additions & 2 deletions crates/hyperion/src/egress/player_join/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ pub fn player_join_world(
.iter_stage(world)
.each_iter(|it, idx, (uuid, _, position, yaw, pitch, _, flags)| {
let mut result = || {
let query_entity = it.entity(idx);
let query_entity = it.entity(idx).expect("idx must be in bounds");

if entity.id() == query_entity.id() {
return anyhow::Ok(());
Expand Down Expand Up @@ -545,7 +545,7 @@ impl Module for PlayerJoinModule {
&Config($),
&RayonWorldStages($),
)
.kind::<flecs::pipeline::PreUpdate>()
.kind(id::<flecs::pipeline::PreUpdate>())
.each_iter(
move |it, _, (comms, compose, crafting_registry, config, stages)| {
let span = tracing::info_span!("joins");
Expand Down
4 changes: 2 additions & 2 deletions crates/hyperion/src/egress/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Module for StatsModule {
// let system_id = GLOBAL_STATS;

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

Expand All @@ -41,7 +41,7 @@ impl Module for StatsModule {
world,
&mut Blocks($),
)
.kind::<flecs::pipeline::OnUpdate>()
.kind(id::<flecs::pipeline::OnUpdate>())
.each_iter(|_iter, _, blocks| {
let span = info_span!("load_pending");
let _enter = span.enter();
Expand Down
5 changes: 2 additions & 3 deletions crates/hyperion/src/egress/sync_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Module for SyncChunksModule {
&mut ChunkSendQueue,
)
.with_enum(PacketState::Play)
.kind::<flecs::pipeline::OnUpdate>()
.kind(id::<flecs::pipeline::OnUpdate>())
.each_iter(
move |it, _, (compose, last_sent, pose, &stream_id, chunk_changes)| {
let system = it.system();
Expand Down Expand Up @@ -159,8 +159,7 @@ impl Module for SyncChunksModule {

system!("send_full_loaded_chunks", world, &Blocks($), &Compose($), &ConnectionId, &mut ChunkSendQueue)
.with_enum(PacketState::Play)
.kind::<flecs::pipeline::OnUpdate>()

.kind(id::<flecs::pipeline::OnUpdate>())
.each_iter(
move |it, _, (chunks, compose, &stream_id, queue)| {
const MAX_CHUNKS_PER_TICK: usize = 16;
Expand Down
32 changes: 16 additions & 16 deletions crates/hyperion/src/egress/sync_entity_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub struct EntityStateSyncModule;
fn track_previous<T: ComponentId + Copy + Debug + PartialEq>(world: &World) {
let post_store = world
.entity_named("post_store")
.add::<flecs::pipeline::Phase>()
.depends_on::<flecs::pipeline::OnStore>();
.add(id::<flecs::pipeline::Phase>())
.depends_on(id::<flecs::pipeline::OnStore>());

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

world
.observer_named::<flecs::OnSet, &T>(&observer_name)
.without::<(Prev, T)>() // we have not set Prev yet
.without((id::<Prev>(), id::<T>())) // we have not set Prev yet
.each_entity(|entity, value| {
entity.set_pair::<Prev, T>(*value);
});

world
.system_named::<(&mut (Prev, T), &T)>(system_name.as_str())
.kind_id(post_store)
.kind(post_store)
.each(|(prev, value)| {
*prev = *value;
});
Expand All @@ -70,7 +70,7 @@ impl Module for EntityStateSyncModule {
)>("entity_xp_sync")
.term_at(0u32)
.singleton()
.kind::<flecs::pipeline::OnStore>()
.kind(id::<flecs::pipeline::OnStore>())
.each_iter(|table, idx, (compose, net, prev_xp, current)| {
const {
assert!(size_of::<Xp>() == size_of::<u16>());
Expand All @@ -87,8 +87,8 @@ impl Module for EntityStateSyncModule {
total_xp: VarInt::default(),
};

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

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

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

let metadata = get_and_clear_metadata(metadata_changes);
Expand All @@ -110,7 +110,7 @@ impl Module for EntityStateSyncModule {
entity_id,
tracked_values: RawBytes(&view),
};
if entity.has::<Position>() {
if entity.has(id::<Position>()) {
entity.get::<&Position>(|position| {
compose
.broadcast_local(&pkt, position.to_chunk(), system)
Expand All @@ -132,12 +132,12 @@ impl Module for EntityStateSyncModule {
?&ConnectionId,
&mut ActiveAnimation,
)
.kind::<flecs::pipeline::OnStore>()
.kind(id::<flecs::pipeline::OnStore>())
.each_iter(
move |it, row, (position, compose, connection_id, animation)| {
let io = connection_id.copied();

let entity = it.entity(row);
let entity = it.entity(row).expect("row must be in bounds");
let system = it.system();

let entity_id = VarInt(entity.minecraft_id());
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Module for EntityStateSyncModule {
&mut MovementTracking,
&Flight,
)
.kind::<flecs::pipeline::PreStore>()
.kind(id::<flecs::pipeline::PreStore>())
.each_iter(
|it,
row,
Expand All @@ -192,7 +192,7 @@ impl Module for EntityStateSyncModule {
)| {
let world = it.system().world();
let system = it.system();
let entity = it.entity(row);
let entity = it.entity(row).expect("row must be in bounds");
let entity_id = VarInt(entity.minecraft_id());

if let Some(pending_teleport) = pending_teleport {
Expand Down Expand Up @@ -363,7 +363,7 @@ impl Module for EntityStateSyncModule {
&Owner,
?&ConnectionId
)
.kind::<flecs::pipeline::OnUpdate>()
.kind(id::<flecs::pipeline::OnUpdate>())
.with_enum_wildcard::<EntityKind>()
.each_iter(|it, row, (position, velocity, owner, connection_id)| {
if let Some(_connection_id) = connection_id {
Expand All @@ -372,7 +372,7 @@ impl Module for EntityStateSyncModule {

let system = it.system();
let world = system.world();
let arrow_entity = it.entity(row);
let arrow_entity = it.entity(row).expect("row must be in bounds");

if velocity.0 != Vec3::ZERO {
let center = **position;
Expand Down
Loading
Loading