mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Move tracy frame markers to proper locations, add a few spans
This commit is contained in:
parent
82b95974f1
commit
1355c1e8f5
@ -32,6 +32,7 @@ use common::{
|
||||
},
|
||||
outcome::Outcome,
|
||||
recipe::RecipeBook,
|
||||
span,
|
||||
state::State,
|
||||
sync::{Uid, UidAllocator, WorldSyncExt},
|
||||
terrain::{block::Block, neighbors, BiomeKind, SitesKind, TerrainChunk, TerrainChunkSize},
|
||||
@ -935,6 +936,7 @@ impl Client {
|
||||
dt: Duration,
|
||||
add_foreign_systems: impl Fn(&mut DispatcherBuilder),
|
||||
) -> Result<Vec<Event>, Error> {
|
||||
span!(_guard, "tick", "Client::tick");
|
||||
// This tick function is the centre of the Veloren universe. Most client-side
|
||||
// things are managed from here, and as such it's important that it
|
||||
// stays organised. Please consult the core developers before making
|
||||
|
@ -3,6 +3,7 @@ use crate::{
|
||||
event::{EventBus, LocalEvent, ServerEvent},
|
||||
metrics::{PhysicsMetrics, SysMetrics},
|
||||
region::RegionMap,
|
||||
span,
|
||||
sync::WorldSyncExt,
|
||||
sys,
|
||||
terrain::{Block, TerrainChunk, TerrainGrid},
|
||||
@ -329,6 +330,7 @@ impl State {
|
||||
|
||||
// Run RegionMap tick to update entity region occupancy
|
||||
pub fn update_region_map(&self) {
|
||||
span!(_guard, "update_region_map", "State::update_region_map");
|
||||
self.ecs.write_resource::<RegionMap>().tick(
|
||||
self.ecs.read_storage::<comp::Pos>(),
|
||||
self.ecs.read_storage::<comp::Vel>(),
|
||||
@ -338,6 +340,11 @@ impl State {
|
||||
|
||||
// Apply terrain changes
|
||||
pub fn apply_terrain_changes(&self) {
|
||||
span!(
|
||||
_guard,
|
||||
"apply_terrain_changes",
|
||||
"State::apply_terrain_changes"
|
||||
);
|
||||
let mut terrain = self.ecs.write_resource::<TerrainGrid>();
|
||||
let mut modified_blocks =
|
||||
std::mem::take(&mut self.ecs.write_resource::<BlockChange>().blocks);
|
||||
@ -354,6 +361,7 @@ impl State {
|
||||
add_foreign_systems: impl Fn(&mut DispatcherBuilder),
|
||||
update_terrain_and_regions: bool,
|
||||
) {
|
||||
span!(_guard, "tick", "State::tick");
|
||||
// Change the time accordingly.
|
||||
self.ecs.write_resource::<TimeOfDay>().0 += dt.as_secs_f64() * DAY_CYCLE_FACTOR;
|
||||
self.ecs.write_resource::<Time>().0 += dt.as_secs_f64();
|
||||
@ -367,6 +375,7 @@ impl State {
|
||||
self.update_region_map();
|
||||
}
|
||||
|
||||
span!(guard, "create dispatcher");
|
||||
// Run systems to update the world.
|
||||
// Create and run a dispatcher for ecs systems.
|
||||
let mut dispatch_builder =
|
||||
@ -375,15 +384,22 @@ impl State {
|
||||
// TODO: Consider alternative ways to do this
|
||||
add_foreign_systems(&mut dispatch_builder);
|
||||
// This dispatches all the systems in parallel.
|
||||
dispatch_builder.build().dispatch(&self.ecs);
|
||||
let mut dispatcher = dispatch_builder.build();
|
||||
drop(guard);
|
||||
span!(guard, "run systems");
|
||||
dispatcher.dispatch(&self.ecs);
|
||||
drop(guard);
|
||||
|
||||
span!(guard, "maintain ecs");
|
||||
self.ecs.maintain();
|
||||
drop(guard);
|
||||
|
||||
if update_terrain_and_regions {
|
||||
self.apply_terrain_changes();
|
||||
}
|
||||
|
||||
// Process local events
|
||||
span!(guard, "process local events");
|
||||
let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all();
|
||||
for event in events {
|
||||
let mut velocities = self.ecs.write_storage::<comp::Vel>();
|
||||
@ -424,10 +440,12 @@ impl State {
|
||||
},
|
||||
}
|
||||
}
|
||||
drop(guard);
|
||||
}
|
||||
|
||||
/// Clean up the state after a tick.
|
||||
pub fn cleanup(&mut self) {
|
||||
span!(_guard, "cleanup", "State::cleanup");
|
||||
// Clean up data structures from the last tick.
|
||||
self.ecs.write_resource::<TerrainChanges>().clear();
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use crate::{
|
||||
tui_runner::{Message, Tui},
|
||||
};
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use common::clock::Clock;
|
||||
use common::{clock::Clock, span};
|
||||
use server::{Event, Input, Server};
|
||||
use std::{
|
||||
io,
|
||||
@ -144,11 +144,7 @@ fn main() -> io::Result<()> {
|
||||
// Wait for a tick so we don't start with a zero dt
|
||||
|
||||
loop {
|
||||
#[cfg(feature = "tracy")]
|
||||
common::util::tracy_client::finish_continuous_frame!();
|
||||
#[cfg(feature = "tracy")]
|
||||
let frame = common::util::tracy_client::start_noncontinuous_frame!("work");
|
||||
|
||||
span!(guard, "work");
|
||||
// Terminate the server if instructed to do so by the shutdown coordinator
|
||||
if shutdown_coordinator.check(&mut server, &settings) {
|
||||
break;
|
||||
@ -195,10 +191,11 @@ fn main() -> io::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tracy")]
|
||||
drop(frame);
|
||||
drop(guard);
|
||||
// Wait for the next tick.
|
||||
clock.tick();
|
||||
#[cfg(feature = "tracy")]
|
||||
common::util::tracy_client::finish_continuous_frame!();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -39,7 +39,7 @@ use crate::{
|
||||
settings::Settings,
|
||||
window::{Event, Window},
|
||||
};
|
||||
use common::{assets::watch, clock::Clock};
|
||||
use common::{assets::watch, clock::Clock, span};
|
||||
|
||||
/// A type used to store state that is shared between all play states.
|
||||
pub struct GlobalState {
|
||||
@ -63,7 +63,10 @@ impl GlobalState {
|
||||
self.window.needs_refresh_resize();
|
||||
}
|
||||
|
||||
pub fn maintain(&mut self, dt: std::time::Duration) { self.audio.maintain(dt); }
|
||||
pub fn maintain(&mut self, dt: std::time::Duration) {
|
||||
span!(_guard, "maintain", "GlobalState::maintain");
|
||||
self.audio.maintain(dt);
|
||||
}
|
||||
|
||||
#[cfg(feature = "singleplayer")]
|
||||
pub fn paused(&self) -> bool {
|
||||
|
@ -171,19 +171,19 @@ fn handle_main_events_cleared(
|
||||
.swap_buffers()
|
||||
.expect("Failed to swap window buffers!");
|
||||
drop(guard);
|
||||
#[cfg(feature = "tracy")]
|
||||
common::util::tracy_client::finish_continuous_frame!();
|
||||
}
|
||||
|
||||
if !exit {
|
||||
// Wait for the next tick.
|
||||
span!(_guard, "Main thread sleep");
|
||||
span!(guard, "Main thread sleep");
|
||||
global_state.clock.set_target_dt(Duration::from_secs_f64(
|
||||
1.0 / global_state.settings.graphics.max_fps as f64,
|
||||
));
|
||||
global_state.clock.tick();
|
||||
drop(guard);
|
||||
#[cfg(feature = "tracy")]
|
||||
common::util::tracy_client::finish_continuous_frame!();
|
||||
|
||||
span!(_guard, "Maintain global state");
|
||||
// Maintain global state.
|
||||
global_state.maintain(global_state.clock.dt());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user