Skip to content

Commit

Permalink
feat: use tracy frame marks
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka committed Nov 12, 2024
1 parent 075999b commit a7c168e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 36 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/hyperion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ roaring = {workspace = true, features = ["simd"]}
serde = {workspace = true, features = ["derive"]}
tokio = {workspace = true, features = ["full", "tracing"]}
tracing = {workspace = true}
tracing-tracy.workspace = true
uuid = {workspace = true, features = ["v3"]}
anyhow.workspace = true
base64.workspace = true
Expand Down
12 changes: 1 addition & 11 deletions crates/hyperion/src/egress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use sync_chunks::SyncChunksModule;
use sync_entity_state::EntityStateSyncModule;

use crate::{
ingress::GametickSpan,
net::NetworkStreamRef,
simulation::{ChunkPosition, blocks::Blocks},
system_registry::SystemId,
Expand Down Expand Up @@ -168,24 +167,15 @@ impl Module for EgressModule {
"clear_bump",
world,
&mut Compose($),
&mut GametickSpan($)
)
.kind_id(pipeline)
.each(move |(compose, gametick_span)| {
.each(move |compose| {
let span = info_span!("clear_bump");
let _enter = span.enter();

for bump in &mut compose.bump {
bump.reset();
}

replace_with::replace_with_or_abort(gametick_span, |span| {
let GametickSpan::Entered(span) = span else {
panic!("gametick_span should be exited");
};

GametickSpan::Exited(span.exit())
});
});
}
}
28 changes: 5 additions & 23 deletions crates/hyperion/src/ingress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use flecs_ecs::prelude::*;
use hyperion_utils::EntityExt;
use serde_json::json;
use sha2::Digest;
use tracing::{error, info, info_span, span::EnteredSpan, trace, warn};
use tracing::{error, info, info_span, trace, warn};
use valence_protocol::{
Bounded, Packet, VarInt, packets,
packets::{
Expand Down Expand Up @@ -269,22 +269,9 @@ fn process_status(
#[derive(Component)]
pub struct IngressModule;

#[derive(Component)]
pub enum GametickSpan {
Entered(EnteredSpan),
Exited(tracing::Span),
}

#[allow(clippy::non_send_fields_in_send_ty)]
unsafe impl Send for GametickSpan {}
unsafe impl Sync for GametickSpan {}

impl Module for IngressModule {
#[expect(clippy::too_many_lines)]
fn module(world: &World) {
world.component::<GametickSpan>();
world.set(GametickSpan::Exited(tracing::info_span!("tick")));

system!(
"update_ign_map",
world,
Expand All @@ -301,19 +288,14 @@ impl Module for IngressModule {
world,
&mut StreamLookup($),
&ReceiveState($),
&mut GametickSpan($)
)
.immediate(true)
.kind::<flecs::pipeline::OnLoad>()
.term_at(0)
.each_iter(move |it, _, (lookup, receive, gametick_span)| {
replace_with::replace_with_or_abort(gametick_span, |span| {
let GametickSpan::Exited(span) = span else {
panic!("gametick_span should be exited");
};

GametickSpan::Entered(span.entered())
});
.each_iter(move |it, _, (lookup, receive)| {
tracing_tracy::client::Client::running()
.expect("Tracy client should be running")
.frame_mark();

let span = info_span!("generate_ingress_events");
let _enter = span.enter();
Expand Down
3 changes: 1 addition & 2 deletions crates/hyperion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub use valence_ident;

pub use crate::simulation::command::CommandScope;
use crate::{
ingress::{GametickSpan, PendingRemove},
ingress::PendingRemove,
net::{NetworkStreamRef, PacketDecoder, proxy::ReceiveState},
runtime::Tasks,
simulation::{
Expand Down Expand Up @@ -218,7 +218,6 @@ impl Hyperion {
.next()
.context("could not get first address")?;

world.component::<GametickSpan>();
world.component::<Pose>();
world.component::<Prev<Pose>>();

Expand Down

0 comments on commit a7c168e

Please sign in to comment.