Sprinkle instrumentation in common crate,in particular in the ecs systems

This commit is contained in:
Imbris 2020-08-26 04:11:31 -04:00
parent 50ceb1c93e
commit e37a01be9d
12 changed files with 35 additions and 4 deletions

View File

@ -1,5 +1,6 @@
use crate::{
astar::{Astar, PathResult},
span,
terrain::Block,
vol::{BaseVol, ReadVol},
};
@ -327,6 +328,7 @@ impl Chaser {
where
V: BaseVol<Vox = Block> + ReadVol,
{
span!(_guard, "Chaser::chase");
let pos_to_tgt = pos.distance(tgt);
// If we're already close to the target then there's nothing to do

View File

@ -1,4 +1,7 @@
use crate::vol::{ReadVol, Vox};
use crate::{
span,
vol::{ReadVol, Vox},
};
use vek::*;
pub trait RayUntil<V: Vox> = FnMut(&V) -> bool;
@ -52,6 +55,7 @@ impl<'a, V: ReadVol, F: RayUntil<V::Vox>, G: RayForEach<V::Vox>> Ray<'a, V, F, G
}
pub fn cast(mut self) -> (f32, Result<Option<&'a V::Vox>, V::Error>) {
span!(_guard, "Ray::cast");
// TODO: Fully test this!
const PLANCK: f32 = 0.001;

View File

@ -1,4 +1,7 @@
use crate::comp::{Pos, Vel};
use crate::{
comp::{Pos, Vel},
span,
};
use hashbrown::{hash_map::DefaultHashBuilder, HashSet};
use indexmap::IndexMap;
use specs::{hibitset::BitSetLike, BitSet, Entities, Join, ReadStorage};
@ -104,6 +107,7 @@ impl RegionMap {
// TODO maintain within a system?
// TODO special case large entities
pub fn tick(&mut self, pos: ReadStorage<Pos>, vel: ReadStorage<Vel>, entities: Entities) {
span!(_guard, "Region::tick");
self.tick += 1;
// Clear events within each region
for i in 0..self.regions.len() {

View File

@ -11,6 +11,7 @@ use crate::{
},
event::{EventBus, ServerEvent},
path::{Chaser, TraversalConfig},
span,
state::{DeltaTime, Time},
sync::{Uid, UidAllocator},
terrain::TerrainGrid,
@ -116,6 +117,7 @@ impl<'a> System<'a> for Sys {
)
.join()
{
span!(_guard, "agent::Sys::run");
// Hack, replace with better system when groups are more sophisticated
// Override alignment if in a group unless entity is owned already
let alignment = if !matches!(alignment, Some(Alignment::Owned(_))) {

View File

@ -4,6 +4,7 @@ use crate::{
Loadout, Mounting, Ori, PhysicsState, Pos, StateUpdate, Stats, Vel,
},
event::{EventBus, LocalEvent, ServerEvent},
span,
state::DeltaTime,
states,
sync::{Uid, UidAllocator},
@ -183,6 +184,7 @@ impl<'a> System<'a> for Sys {
mountings,
): Self::SystemData,
) {
span!(_guard, "character_behavior::Sys::run");
let mut server_emitter = server_bus.emitter();
let mut local_emitter = local_bus.emitter();

View File

@ -4,6 +4,7 @@ use crate::{
Loadout, Ori, Pos, Scale, Stats,
},
event::{EventBus, LocalEvent, ServerEvent},
span,
sync::Uid,
util::Dir,
};
@ -52,6 +53,7 @@ impl<'a> System<'a> for Sys {
character_states,
): Self::SystemData,
) {
span!(_guard, "combat::Sys::run");
let mut server_emitter = server_bus.emitter();
let mut local_emitter = local_bus.emitter();
// Attacks

View File

@ -4,6 +4,7 @@ use crate::{
CharacterState, ControlEvent, Controller, InventoryManip,
},
event::{EventBus, LocalEvent, ServerEvent},
span,
state::DeltaTime,
sync::{Uid, UidAllocator},
};
@ -43,6 +44,7 @@ impl<'a> System<'a> for Sys {
uids,
): Self::SystemData,
) {
span!(_guard, "controller::Sys::run");
let mut server_emitter = server_bus.emitter();
for (entity, _uid, controller, character_state) in

View File

@ -1,5 +1,6 @@
use crate::{
comp::{Controller, MountState, Mounting, Ori, Pos, Vel},
span,
sync::UidAllocator,
};
use specs::{
@ -36,6 +37,7 @@ impl<'a> System<'a> for Sys {
mut orientations,
): Self::SystemData,
) {
span!(_guard, "mount::Sys::run");
// Mounted entities.
for (entity, mut mount_states) in (&entities, &mut mount_state.restrict_mut()).join() {
match mount_states.get_unchecked() {

View File

@ -95,10 +95,11 @@ impl<'a> System<'a> for Sys {
projectiles,
): Self::SystemData,
) {
span!(_guard, "<phys::Sys as System>::run");
span!(_guard, "phys::Sys::run");
let mut event_emitter = event_bus.emitter();
// Add/reset physics state components
span!(guard, "Add/reset physics state components");
for (entity, _, _, _, _) in (
&entities,
&colliders,
@ -112,6 +113,7 @@ impl<'a> System<'a> for Sys {
.entry(entity)
.map(|e| e.or_insert_with(Default::default));
}
drop(guard);
// Apply pushback
//
@ -126,6 +128,7 @@ impl<'a> System<'a> for Sys {
// terrain collision code below, although that's not trivial to do since
// it means the step needs to take into account the speeds of both
// entities.
span!(guard, "Apply pushback");
for (entity, pos, scale, mass, collider, _, _, physics, projectile) in (
&entities,
&positions,
@ -246,8 +249,10 @@ impl<'a> System<'a> for Sys {
.get_mut(entity)
.map(|vel| vel.0 += vel_delta * dt.0);
}
drop(guard);
// Apply movement inputs
span!(guard, "Apply movement and terrain collision");
let land_on_grounds = (
&entities,
scales.maybe(),
@ -349,6 +354,7 @@ impl<'a> System<'a> for Sys {
radius: f32,
z_range: Range<f32>,
) -> impl Iterator<Item = Aabb<f32>> + 'a {
span!(_guard, "collision_iter");
near_iter.filter_map(move |(i, j, k)| {
let block_pos = pos.map(|e| e.floor() as i32) + Vec3::new(i, j, k);
@ -648,6 +654,7 @@ impl<'a> System<'a> for Sys {
land_on_grounds_a.append(&mut land_on_grounds_b);
land_on_grounds_a
});
drop(guard);
land_on_grounds.into_iter().for_each(|(entity, vel)| {
event_emitter.emit(ServerEvent::LandOnGround { entity, vel: vel.0 });

View File

@ -4,6 +4,7 @@ use crate::{
Loadout, Ori, PhysicsState, Pos, Projectile, Vel,
},
event::{EventBus, LocalEvent, ServerEvent},
span,
state::DeltaTime,
sync::UidAllocator,
util::Dir,
@ -48,6 +49,7 @@ impl<'a> System<'a> for Sys {
loadouts,
): Self::SystemData,
) {
span!(_guard, "projectile::Sys::run");
let mut local_emitter = local_bus.emitter();
let mut server_emitter = server_bus.emitter();

View File

@ -1,6 +1,7 @@
use crate::{
comp::{CharacterState, Energy, EnergySource, HealthSource, Stats},
event::{EventBus, ServerEvent},
span,
state::DeltaTime,
};
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
@ -24,6 +25,7 @@ impl<'a> System<'a> for Sys {
&mut self,
(entities, dt, server_event_bus, character_states, mut stats, mut energies): Self::SystemData,
) {
span!(_guard, "stats::Sys::run");
let mut server_event_emitter = server_event_bus.emitter();
// Increment last change timer

View File

@ -242,7 +242,7 @@ impl<'a, V: RectRasterableVol<Vox = Block> + ReadVol + Debug>
self,
(range, max_texture_size): Self::Supplement,
) -> MeshGen<TerrainPipeline, FluidPipeline, Self> {
span!(_guard, "<&VolGrid2d as Meshable<_, _>::generate_mesh");
span!(_guard, "<&VolGrid2d as Meshable<_, _>>::generate_mesh");
// Find blocks that should glow
// FIXME: Replace with real lit blocks when we actually have blocks that glow.
let lit_blocks = core::iter::empty();