Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
philiplinden committed Dec 16, 2024
1 parent e206cdd commit 60bfc4e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 211 deletions.
32 changes: 15 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ path = "src/simulator/src/lib.rs"
name = "yahs"
path = "src/cli/src/main.rs"

# Include the GUI binary as "yahs-ui"
[[bin]]
name = "yahs-ui"
path = "src/ui/src/main.rs"

# These are the dependencies for the project when building it from the root
# These are the dependencies when building the CLI from the project root
[dependencies]
# Simulator dependencies
yahs-simulator = { path = "src/simulator" }
yahs-ui = { path = "src/ui" }
yahs-cli = { path = "src/cli" }
bevy = { workspace = true }
avian3d = { workspace = true }
bevy-trait-query = { workspace = true }

# CLI dependencies
yahs-cli = { path = "src/cli" }
bevy_ratatui = "0.7.0"
ratatui = "0.29"
color-eyre = "0.6.3"
crossterm = "0.28.1"

[features]
default = ["dev"]
dev = ["yahs-ui/dev", "yahs-cli/dev", "yahs-simulator/dev"]
inspect = ["yahs-ui/inspect"]
dev = ["yahs-cli/dev", "yahs-simulator/dev"]

[workspace.package]
authors = ["Philip Linden <[email protected]>"]
Expand All @@ -46,15 +46,15 @@ license = "MIT or Apache-2.0"
[workspace]
resolver = "2" # Important for Bevy
members = [
"src/yahs-simulator",
"src/yahs-ui",
"src/yahs-cli"
"src/simulator",
"src/cli",
"src/ui"
]

[workspace.dependencies]
# Shared dependencies with fixed versions
bevy = { version = "0.15.0", default-features = false, features = [
"bevy_asset", "bevy_state", "multi_threaded"
"bevy_state", "multi_threaded"
] }
avian3d = { git = "https://github.com/Jondolf/avian.git", branch = "main" }
bevy-trait-query = "0.7.0"
Expand Down Expand Up @@ -84,6 +84,7 @@ opt-level = 1
# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package."*"]
opt-level = 3
debug = false

# The default profile is optimized for Wasm builds because that's what [Trunk
# reads](https://github.com/trunk-rs/trunk/issues/605). Optimize for size in the
Expand All @@ -92,9 +93,6 @@ opt-level = 3
# Compile the entire crate as one unit. Slows compile times, marginal
# improvements.
codegen-units = 1
# Do a second optimization pass over the entire program, including
# dependencies. Slows compile times, marginal improvements.
lto = "thin"
# Optimize with size in mind (also try "z", sometimes it is better).
# Slightly slows compile times, great improvements to file size and runtime
# performance.
Expand Down
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,15 @@ Running this package as a standalone application compiles all of the crates
and runs the CLI by default:

```bash
cargo run --workspace
cargo run
```

Force the standalone application to run the GUI instead of the CLI:

```bash
cargo run --workspace --bin yahs-ui
cargo run --bin yahs-ui
```

Or install the standalone application to your system:

```bash
# as a CLI
$ cargo install --path "src/cli" --release
$ yahs --help

# as a GUI
$ cargo install --path "src/ui" --release
$ yahs-ui
```


## License

Except where noted (below and/or in individual files), all code in this
Expand Down
68 changes: 7 additions & 61 deletions src/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,22 @@ authors = { workspace = true }
license = { workspace = true }

[[bin]]
name = "yahs"
name = "yahs-cli"
path = "src/main.rs"

[dependencies]
yahs-simulator = { path = "../simulator" }
bevy = { workspace = true, default-features = false, features = [
bevy = { workspace = true, features = [
"bevy_state",
"multi_threaded",
] }
clap = { version = "4.5.23", features = [ "env"] }
thiserror = "2.0.7"
bevy_ratatui = "0.7"
ratatui = "0.29"
crossterm = "0.28.1"
color-eyre = "0.6.3"

[features]
default = ["dev"]
default = []
dev = [
"yahs-simulator/dev",
"bevy/dynamic_linking",
"bevy/bevy_dev_tools",
"clap/debug",
]

# -----------------------------------------------------------------------------
# Some Bevy optimizations
# -----------------------------------------------------------------------------

# Idiomatic Bevy code often triggers these lints, and the CI workflow treats
# them as errors. In some cases they may still signal poor code quality however,
# so consider commenting out these lines.
[lints.clippy]
# Bevy supplies arguments to systems via dependency injection, so it's
# natural for systems to request more than 7 arguments -- which triggers
# this lint.
too_many_arguments = "allow"
# Queries that access many components may trigger this lint.
type_complexity = "allow"

# Compile with Performance Optimizations:
# https://bevyengine.org/learn/quick-start/getting-started/setup/#compile-with-performance-optimizations

# Enable a small amount of optimization in the dev profile for our code.
[profile.dev]
opt-level = 1

# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package."*"]
opt-level = 3

# The default profile is optimized for Wasm builds because that's what [Trunk
# reads](https://github.com/trunk-rs/trunk/issues/605). Optimize for size in the
# wasm-release profile to reduce load times and bandwidth usage on web.
[profile.release]
# Compile the entire crate as one unit. Slows compile times, marginal
# improvements.
codegen-units = 1
# Do a second optimization pass over the entire program, including
# dependencies. Slows compile times, marginal improvements.
lto = "thin"
# Optimize with size in mind (also try "z", sometimes it is better).
# Slightly slows compile times, great improvements to file size and runtime
# performance.
opt-level = "s"
# Strip all debugging information from the binary to slightly reduce file
# size.
strip = "debuginfo"

# Override some settings for native builds.
[profile.release-native]
# Default to release profile values.
inherits = "release"
# Optimize with performance in mind.
opt-level = 3
# Keep debug information in the binary.
strip = "none"
7 changes: 7 additions & 0 deletions src/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# yahs-cli

This is the CLI for the yahs project.

```bash
cargo run --bin yahs-cli
```
42 changes: 33 additions & 9 deletions src/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
use bevy::{prelude::*, state::app::StatesPlugin};
use yahs_simulator::prelude::SimulatorPlugins;

use bevy::{
app::{AppExit, ScheduleRunnerPlugin},
prelude::*,
};
use bevy_ratatui::{
error::exit_on_error, event::KeyEvent, terminal::RatatuiContext, RatatuiPlugins,
};
fn main() {
let wait_duration = std::time::Duration::from_secs_f64(1. / 60.); // 60 FPS
App::new()
.add_plugins((
MinimalPlugins,
StatesPlugin,
SimulatorPlugins,
))
.add_plugins(RatatuiPlugins::default())
.add_plugins(ScheduleRunnerPlugin::run_loop(wait_duration))
.add_systems(PreUpdate, keyboard_input_system)
.add_systems(Update, hello_world.pipe(exit_on_error))
.run();
}
}

fn hello_world(mut context: ResMut<RatatuiContext>) -> color_eyre::Result<()> {
context.draw(|frame| {
let text = ratatui::text::Text::raw("hello world\nPress 'q' to Quit");
frame.render_widget(text, frame.area())
})?;
Ok(())
}

fn keyboard_input_system(mut events: EventReader<KeyEvent>, mut exit: EventWriter<AppExit>) {
use crossterm::event::KeyCode;
for event in events.read() {
match event.code {
KeyCode::Char('q') | KeyCode::Esc => {
exit.send_default();
}
_ => {}
}
}
}
54 changes: 0 additions & 54 deletions src/simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,4 @@ bevy-trait-query = { workspace = true }
default = []
dev = [
"bevy/dynamic_linking",
"bevy/bevy_dev_tools",
]

# -----------------------------------------------------------------------------
# Some Bevy optimizations
# -----------------------------------------------------------------------------

# Idiomatic Bevy code often triggers these lints, and the CI workflow treats
# them as errors. In some cases they may still signal poor code quality however,
# so consider commenting out these lines.
[lints.clippy]
# Bevy supplies arguments to systems via dependency injection, so it's
# natural for systems to request more than 7 arguments -- which triggers
# this lint.
too_many_arguments = "allow"
# Queries that access many components may trigger this lint.
type_complexity = "allow"

# Compile with Performance Optimizations:
# https://bevyengine.org/learn/quick-start/getting-started/setup/#compile-with-performance-optimizations

# Enable a small amount of optimization in the dev profile for our code.
[profile.dev]
opt-level = 1

# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package."*"]
opt-level = 3

# The default profile is optimized for Wasm builds because that's what [Trunk
# reads](https://github.com/trunk-rs/trunk/issues/605). Optimize for size in the
# wasm-release profile to reduce load times and bandwidth usage on web.
[profile.release]
# Compile the entire crate as one unit. Slows compile times, marginal
# improvements.
codegen-units = 1
# Do a second optimization pass over the entire program, including
# dependencies. Slows compile times, marginal improvements.
lto = "thin"
# Optimize with size in mind (also try "z", sometimes it is better).
# Slightly slows compile times, great improvements to file size and runtime
# performance.
opt-level = "s"
# Strip all debugging information from the binary to slightly reduce file
# size.
strip = "debuginfo"

# Override some settings for native builds.
[profile.release-native]
# Default to release profile values.
inherits = "release"
# Optimize with performance in mind.
opt-level = 3
# Keep debug information in the binary.
strip = "none"
55 changes: 1 addition & 54 deletions src/ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,64 +33,11 @@ bevy-inspector-egui = { version = "0.28", optional = true, features = [
] }

[features]
default = ["dev"]
default = []
dev = [
"avian3d/debug-plugin",
"bevy/bevy_dev_tools",
"bevy/dynamic_linking",
"yahs-simulator/dev",
]
inspect = ["bevy-inspector-egui"]

# -----------------------------------------------------------------------------
# Some Bevy optimizations
# -----------------------------------------------------------------------------

# Idiomatic Bevy code often triggers these lints, and the CI workflow treats
# them as errors. In some cases they may still signal poor code quality however,
# so consider commenting out these lines.
[lints.clippy]
# Bevy supplies arguments to systems via dependency injection, so it's
# natural for systems to request more than 7 arguments -- which triggers
# this lint.
too_many_arguments = "allow"
# Queries that access many components may trigger this lint.
type_complexity = "allow"

# Compile with Performance Optimizations:
# https://bevyengine.org/learn/quick-start/getting-started/setup/#compile-with-performance-optimizations

# Enable a small amount of optimization in the dev profile for our code.
[profile.dev]
opt-level = 1

# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package."*"]
opt-level = 3

# The default profile is optimized for Wasm builds because that's what [Trunk
# reads](https://github.com/trunk-rs/trunk/issues/605). Optimize for size in the
# wasm-release profile to reduce load times and bandwidth usage on web.
[profile.release]
# Compile the entire crate as one unit. Slows compile times, marginal
# improvements.
codegen-units = 1
# Do a second optimization pass over the entire program, including
# dependencies. Slows compile times, marginal improvements.
lto = "thin"
# Optimize with size in mind (also try "z", sometimes it is better).
# Slightly slows compile times, great improvements to file size and runtime
# performance.
opt-level = "s"
# Strip all debugging information from the binary to slightly reduce file
# size.
strip = "debuginfo"

# Override some settings for native builds.
[profile.release-native]
# Default to release profile values.
inherits = "release"
# Optimize with performance in mind.
opt-level = 3
# Keep debug information in the binary.
strip = "none"
3 changes: 2 additions & 1 deletion src/ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

mod camera;
pub mod controls;
mod dev_tools;
mod scene;
#[cfg(feature = "dev")]
mod dev_tools;

use camera::CameraPlugin;
use controls::ControlsPlugin;
Expand Down

0 comments on commit 60bfc4e

Please sign in to comment.