Skip to content

Commit

Permalink
ui: sim state monitoring, play/pause
Browse files Browse the repository at this point in the history
  • Loading branch information
philiplinden committed Nov 19, 2024
1 parent b087019 commit 88ce33b
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 130 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dev_native = [
"dev",
# Enable system information plugin for native dev builds.
"bevy/sysinfo_plugin",
"iyes_perf_ui/sysinfo",
]
config-files = ["ron", "bevy_common_assets", "serde"]
inspect = ["bevy-inspector-egui", "bevy_panorbit_camera/bevy_egui"]
Expand All @@ -35,7 +36,7 @@ avian3d = { version = "0.1.2", features = ["debug-plugin"] }
# ui dependencies
bevy_panorbit_camera = { version = "0.20.0" }
bevy-inspector-egui = { version = "0.27.0", features = ["highlight_changes"], optional = true }
iyes_perf_ui = { version = "0.3.0" }
iyes_perf_ui = "0.3.0"
# file io dependencies
bevy_common_assets = { version = "0.11.0", features = ["ron"], optional = true }
ron = { version = "0.8.1", optional = true }
Expand Down
18 changes: 18 additions & 0 deletions docs/devlog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# development log

## 2024-11-18 again

I think I was a bit naive to install `bevy-trait-query`. It works for now but in
the future we should really move away from it. It is currently a crutch.

For some reason when the balloon bounces, it accelerates upward to oblivion. I
added some errors to stop the simulation when the balloon goes out of bounds,
but right now it panics. Not great but better than nothing. Best I can do is
bring in the "out of bounds" level to be less than the true bounds.

The drag force is the one that is causing the bad acceleration. Weight and
buoyancy don't change with time since the balloon has constant size right now.

- Added pause/play controls. Default key is `Space`.
- Added a new ui that displays the simulation state.
- Added a new ui that displays forces in real time, assuming only one balloon.
- Added an `Anomaly` state to the sim that is supposed to freeze.

## 2024-11-18

Iterating with AI on the drag calculations. It is set up to perform a raycast
Expand Down
2 changes: 0 additions & 2 deletions src/app3d/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod scene;
mod ui;
mod controls;

// Re-export the plugins so they can be added to the app with `app.add_plugins`.
pub use scene::ScenePlugin;
pub use ui::InterfacePlugins;
pub use controls::{ControlsPlugin, KeyBindingsConfig};
2 changes: 1 addition & 1 deletion src/app3d/scene/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};
use avian3d::math::TAU;

use crate::app3d::KeyBindingsConfig;
use crate::controls::KeyBindingsConfig;

pub struct CameraPlugin;

Expand Down
56 changes: 56 additions & 0 deletions src/app3d/ui/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use bevy::{app::PluginGroupBuilder, prelude::*};
use iyes_perf_ui::prelude::*;

use crate::controls::KeyBindingsConfig;
use crate::simulator::SimState;

use super::*;

/// A plugin group that includes all interface-related plugins
pub struct InterfacePlugins;

impl PluginGroup for InterfacePlugins {
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>()
.add(CoreUiPlugin)
.add(PausePlayPlugin)
.add(monitors::MonitorsPlugin)
}
}

/// Base UI plugin. This sets up the base plugins that all other ui plugins
/// need. .Placeholder for now
pub struct CoreUiPlugin;

impl Plugin for CoreUiPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
PerfUiPlugin,
#[cfg(feature = "dev")]
dev_tools::plugin,
));
}
}

pub struct PausePlayPlugin;

impl Plugin for PausePlayPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, toggle_pause);
}
}

fn toggle_pause(
sim_state: Res<State<SimState>>,
mut next_state: ResMut<NextState<SimState>>,
key_input: Res<ButtonInput<KeyCode>>,
key_bindings: Res<KeyBindingsConfig>,
) {
if key_input.just_pressed(key_bindings.time_controls.toggle_pause) {
match sim_state.as_ref().get() {
SimState::Stopped => next_state.set(SimState::Running),
SimState::Running => next_state.set(SimState::Stopped),
_ => ()
}
}
}
2 changes: 1 addition & 1 deletion src/app3d/ui/dev_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bevy::pbr::wireframe::{WireframeConfig, WireframePlugin};

use avian3d::debug_render::PhysicsDebugPlugin;

use crate::app3d::KeyBindingsConfig;
use crate::controls::KeyBindingsConfig;

pub(super) fn plugin(app: &mut App) {
// Toggle the debug overlay for UI.
Expand Down
31 changes: 3 additions & 28 deletions src/app3d/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
// mod monitors;
mod core;
mod monitors;

#[cfg(feature = "dev")]
mod dev_tools;

use bevy::{app::PluginGroupBuilder, prelude::*};
use iyes_perf_ui::prelude::*;

/// A plugin group that includes all interface-related plugins
pub struct InterfacePlugins;

impl PluginGroup for InterfacePlugins {
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>()
.add(CoreUiPlugin)
.add(monitors::ForceMonitorPlugin)
}
}

/// Base UI plugin. This sets up the base plugins that all other ui plugins
/// need. .Placeholder for now
pub struct CoreUiPlugin;

impl Plugin for CoreUiPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
PerfUiPlugin,
#[cfg(feature = "dev")]
dev_tools::plugin,
));
}
}
pub use core::InterfacePlugins;
Loading

0 comments on commit 88ce33b

Please sign in to comment.