diff --git a/src/main.rs b/src/main.rs index 5aec832..bc52f1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,10 @@ -use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; +use bevy::{ + prelude::*, + diagnostic::{FrameTimeDiagnosticsPlugin, DiagnosticsStore}, + window::{PresentMode, WindowTheme}, + sprite::MaterialMesh2dBundle}; + use std::time::Instant; mod neural_net; @@ -7,6 +12,9 @@ mod neural_net; #[derive(Component)] struct Agent; +#[derive(Component)] +struct FpsText; + #[derive(Resource)] struct SimulationState { @@ -29,11 +37,27 @@ impl SimulationState fn main() { App::new() - .add_plugins(DefaultPlugins) + .add_plugins(( + DefaultPlugins.set(WindowPlugin { + primary_window: Some(Window { + title: "Life Sim".into(), + resolution: (1280., 720.).into(), + present_mode: PresentMode::AutoVsync, + // Tells wasm to resize the window according to the available canvas + fit_canvas_to_parent: true, + // Tells wasm not to override default event handling, like F5, Ctrl+R etc. + prevent_default_event_handling: false, + window_theme: Some(WindowTheme::Dark), + ..default() + }), + ..default() + }), + FrameTimeDiagnosticsPlugin + )) .insert_resource(SimulationState::new(200)) .insert_resource(Time::new(Instant::now())) .add_systems(Startup, setup) - .add_systems(Update, tick_simulation) + .add_systems(Update, (tick_simulation, ui_update)) .run(); } @@ -53,6 +77,29 @@ fn setup(mut commands: Commands, mut meshes: ResMut>, mut materials }, Agent )); + + + // UI + // Text with multiple sections + commands.spawn(( + // Create a TextBundle that has a Text with a list of sections. + TextBundle::from_sections([ + TextSection::new( + "FPS: ", + TextStyle { + font_size: 60.0, + color: Color::WHITE, + ..default() + }, + ), + TextSection::from_style(TextStyle { + font_size: 60.0, + color: Color::GOLD, + ..default() + }), + ]), + FpsText, + )); } fn tick_simulation(mut state: ResMut, delta_time: Res