MKB2A5XCWBZO2E6QFE6PD36LF3IGMJCGJB5TGMRAPSKCKHS75ISAC
ZH7HF4FYTYVE5NQFULKSDXIE3LHMFVQGI3FKF366QRY7NJLPADRQC
XL7JSPPGAN3SWJHNKJYWLZSPCWYBA4XP6EJOI5QQE7PPVUW7DFIQC
EV477LPQ57FEHMFO6E3LL5MFWZC6NTGER42SKP5CJN73SWXGB5AQC
7SXAXY6J4QHPDUUHCKZDEZOZ2IUMSBWODICOMIZH2KA2BGV3F54QC
ASIORORAPGGVNLR42J6PZRTG7JKK34GYXBYSKSTJFXSFW6YXBJJQC
7FTW5AQKOO4W5AIHYZSAKLQR6LGVTXH7SKMSTA4ER4C4HP54VE4QC
ZJ2DSL63RVPSNXIGTAZNPV6HLHOKLWC5RSK5EAAM3HIYUJ5Y3ISQC
RSP5XTRHUKKJOBWS2377O7L3ZEQF6JSYPJDMNSINKAO63FHZFZOQC
5Y32O2B2GTH2UHFA3NO4ZY673XNHT3W4DQADFMK4LMKLSXMZKHGQC
DBHCCY3W2DG4WYMXBZ2UCNYVGZ5PS5UUUNWCXVYJ4TMXQDIZT6GAC
7VC7N62AXEYFKNG2CDAGQK7N3AMVRVM4ECBSHOLMCVHANU52ILXQC
OQCI44VL3IROGBJ52MUI3AICPKEPAJVFL45PGQNNQRK4TKIK7HAAC
YT2GB32PAGZCSNZGKTQH7MCJ675TK2G5OHS7SY4R2FDCNBKQHXYAC
ZW67OU7OPHAITCJS3GHQYFBRY5YGOIGRD7B4CKULAXAEXHM42KYQC
66PNECCRWS2BPZS555P2355EY2PAHZWHJJEXTDU2WUBOHANRNXFQC
}
#[allow(clippy::too_many_arguments)]
fn debug_view_window(
query: Query<(&ActionState<PlayerAction>, &DashState), With<Player>>,
mut contexts: EguiContexts,
you: Option<Res<You>>,
mut fundsp_output: NonSendMut<fundsp_kira::FundspAudioOutput>,
mut track: ResMut<fundsp_kira::MainTrack>,
mut sample_pairs: Local<VecDeque<(f32, f32)>>,
) {
const SAMPLES_TO_KEEP: usize = 512;
// Update main track data
let samples_stored = sample_pairs.len();
// Remove old samples
if samples_stored >= SAMPLES_TO_KEEP {
// Remove old sampels
sample_pairs.pop_front();
}
sample_pairs.push_back(track.sample());
egui::Window::new("Action State").show(contexts.ctx_mut(), |ui| {
if ui.button("Noisy").clicked() {
use fundsp::hacker32::*;
fundsp_output.play(
&fundsp_kira::Machine::new(
pink() * envelope(|t| exp(-5.0 * t)),
// pink() * 0.2,
),
&mut track,
);
}
ui.collapsing("Audio Details", |ui| {
// TODO Abstract this away into an egui widget for an *oscilloscope*
use egui_plot::{Line, Plot, PlotPoints};
let left_wave: PlotPoints = sample_pairs
.iter()
.enumerate()
.map(|(t, (s, _))| [t as f64, *s as f64])
.chain((samples_stored..SAMPLES_TO_KEEP).map(|i| [i as f64, 0.0]))
.collect();
let left_line = Line::new(left_wave).color(egui::Color32::BLUE);
let right_wave: PlotPoints = sample_pairs
.iter()
.enumerate()
.map(|(t, (_, s))| [t as f64, *s as f64])
.chain((samples_stored..SAMPLES_TO_KEEP).map(|i| [i as f64, 0.0]))
.collect();
let right_line = Line::new(right_wave).color(egui::Color32::RED);
ui.label("Main Track Oscilloscope");
Plot::new("waveform")
.view_aspect(4.0)
.auto_bounds(egui::Vec2b::new(false, false))
.show_grid(egui::Vec2b::new(false, true))
.include_y(-1.0)
.include_y(1.0)
.include_x(0.0)
.include_x(SAMPLES_TO_KEEP as f64)
.show_axes(false)
.show(ui, |plot_ui| {
plot_ui.line(left_line);
plot_ui.line(right_line);
});
ui.label(format!("MainTrack RMS: {:?}", track.rms()));
});
if let Some(you) = you.and_then(|you| you.0) {
ui.label(format!("You are {}.", you));
} else {
ui.label("There is no You.");
}
let Ok((action_state, dash_state)) = query.get_single() else {
return;
};
ui.label(if dash_state.0 {
"Dashing"
} else {
"Not Dashing"
});
if let Some(dad) = action_state.clamped_axis_pair(&PlayerAction::Move) {
ui.label(format!("X movement: {}", dad.x()));
ui.label(format!("Y movement: {}", dad.y()));
} else {
ui.label("!! Move action not (properly) bound !!");
}
if let Some(hand_dad) = action_state.clamped_axis_pair(&PlayerAction::Hand) {
_ = hand_dad;
ui.label("Hand action connected!");
ui.label(format!(
"Hand actions: [{}]",
[
(hand_dad.x() > 0.5).then_some("HandMoveRight"),
(hand_dad.x() < -0.5).then_some("HandMoveLeft"),
(hand_dad.y() > 0.5).then_some("HandUse"),
]
.into_iter()
.flatten()
.collect::<Vec<_>>()
.join(", ")
));
} else {
ui.label("!! Hand action not (properly) bound !!");
}
});
use std::collections::VecDeque;
use crate::{fundsp_kira, PlayerAction, You};
use crate::{DashState, Player};
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts};
use leafwing_input_manager::prelude::*;
#[allow(clippy::too_many_arguments)]
pub fn debug_view_window(
query: Query<(&ActionState<PlayerAction>, &DashState), With<Player>>,
mut contexts: EguiContexts,
you: Option<Res<You>>,
mut fundsp_output: NonSendMut<fundsp_kira::FundspAudioOutput>,
mut track: ResMut<fundsp_kira::MainTrack>,
mut sample_pairs: Local<VecDeque<(f32, f32)>>,
) {
const SAMPLES_TO_KEEP: usize = 512;
// Update main track data
let samples_stored = sample_pairs.len();
// Remove old samples
if samples_stored >= SAMPLES_TO_KEEP {
// Remove old sampels
sample_pairs.pop_front();
}
sample_pairs.push_back(track.sample());
egui::Window::new("Action State").show(contexts.ctx_mut(), |ui| {
if ui.button("Noisy").clicked() {
use fundsp::hacker32::*;
fundsp_output.play(
&fundsp_kira::Machine::new(
pink() * envelope(|t| exp(-5.0 * t)),
// pink() * 0.2,
),
&mut track,
);
}
ui.collapsing("Audio Details", |ui| {
// TODO Abstract this away into an egui widget for an *oscilloscope*
use egui_plot::{Line, Plot, PlotPoints};
let left_wave: PlotPoints = sample_pairs
.iter()
.enumerate()
.map(|(t, (s, _))| [t as f64, *s as f64])
.chain((samples_stored..SAMPLES_TO_KEEP).map(|i| [i as f64, 0.0]))
.collect();
let left_line = Line::new(left_wave).color(egui::Color32::BLUE);
let right_wave: PlotPoints = sample_pairs
.iter()
.enumerate()
.map(|(t, (_, s))| [t as f64, *s as f64])
.chain((samples_stored..SAMPLES_TO_KEEP).map(|i| [i as f64, 0.0]))
.collect();
let right_line = Line::new(right_wave).color(egui::Color32::RED);
ui.label("Main Track Oscilloscope");
Plot::new("waveform")
.view_aspect(4.0)
.auto_bounds(egui::Vec2b::new(false, false))
.show_grid(egui::Vec2b::new(false, true))
.include_y(-1.0)
.include_y(1.0)
.include_x(0.0)
.include_x(SAMPLES_TO_KEEP as f64)
.show_axes(false)
.show(ui, |plot_ui| {
plot_ui.line(left_line);
plot_ui.line(right_line);
});
ui.label(format!("MainTrack RMS: {:?}", track.rms()));
});
if let Some(you) = you.and_then(|you| you.0) {
ui.label(format!("You are {}.", you));
} else {
ui.label("There is no You.");
}
let Ok((action_state, dash_state)) = query.get_single() else {
return;
};
ui.label(if dash_state.0 {
"Dashing"
} else {
"Not Dashing"
});
if let Some(dad) = action_state.clamped_axis_pair(&PlayerAction::Move) {
ui.label(format!("X movement: {}", dad.x()));
ui.label(format!("Y movement: {}", dad.y()));
} else {
ui.label("!! Move action not (properly) bound !!");
}
if let Some(hand_dad) = action_state.clamped_axis_pair(&PlayerAction::Hand) {
_ = hand_dad;
ui.label("Hand action connected!");
ui.label(format!(
"Hand actions: [{}]",
[
(hand_dad.x() > 0.5).then_some("HandMoveRight"),
(hand_dad.x() < -0.5).then_some("HandMoveLeft"),
(hand_dad.y() > 0.5).then_some("HandUse"),
]
.into_iter()
.flatten()
.collect::<Vec<_>>()
.join(", ")
));
} else {
ui.label("!! Hand action not (properly) bound !!");
}
});
}