Debug visualisation of relative wind velocity

This commit is contained in:
Ludvig Böklin 2021-06-22 15:32:34 +02:00
parent 1960ddd62b
commit 1ea087a54d
2 changed files with 49 additions and 0 deletions

View File

@ -1181,4 +1181,43 @@ impl Scene {
keep
});
}
pub fn maintain_debug_relative_wind(
&mut self,
client: &Client,
settings: &Settings,
debug_shape_id: &mut Option<DebugShapeId>,
) {
if settings.interface.toggle_hitboxes {
let ecs = client.state().ecs();
let entity = client.entity();
let rel_flow = ecs
.read_storage::<comp::PhysicsState>()
.get(entity)
.and_then(|physics| physics.in_fluid)
.and_then(|fluid| {
ecs.read_storage::<comp::Vel>()
.get(entity)
.map(|vel| fluid.relative_flow(vel))
});
if let (Some(pos), Some(rel_flow)) = (
ecs.read_storage::<comp::Pos>().get(entity).copied(),
rel_flow,
) {
if let Some(shape_id) = debug_shape_id {
self.debug.remove_shape(*shape_id);
}
let shape_id = self
.debug
.add_shape(DebugShape::Line([Vec3::zero(), rel_flow.0 * 0.2]));
debug_shape_id.insert(shape_id);
let hb_pos = [pos.0.x, pos.0.y, pos.0.z + 2.0, 0.0];
let color = [0.0, 1.0, 1.0, 0.5];
self.debug.set_pos_and_color(shape_id, hb_pos, color);
}
}
}
}

View File

@ -75,6 +75,7 @@ pub struct SessionState {
interactable: Option<Interactable>,
saved_zoom_dist: Option<f32>,
hitboxes: HashMap<specs::Entity, DebugShapeId>,
debug_wind: Option<DebugShapeId>,
}
/// Represents an active game session (i.e., the one being played).
@ -123,6 +124,7 @@ impl SessionState {
interactable: None,
saved_zoom_dist: None,
hitboxes: HashMap::new(),
debug_wind: None,
}
}
@ -144,6 +146,8 @@ impl SessionState {
let mut client = self.client.borrow_mut();
self.scene
.maintain_debug_hitboxes(&client, &global_state.settings, &mut self.hitboxes);
self.scene
.maintain_debug_relative_wind(&client, &global_state.settings, &mut self.debug_wind);
for event in client.tick(self.inputs.clone(), dt, crate::ecs::sys::add_local_systems)? {
match event {
client::Event::Chat(m) => {
@ -1372,6 +1376,12 @@ impl PlayState for SessionState {
&scene_data,
&client,
);
self.scene.maintain(
global_state.window.renderer_mut(),
&mut global_state.audio,
&scene_data,
&client,
);
// Process outcomes from client
for outcome in outcomes {