From e7573a55b5345384ca747cd3ca4cc879b19458ab Mon Sep 17 00:00:00 2001 From: Zerve0 Date: Fri, 21 Aug 2020 21:23:52 +0900 Subject: [PATCH 1/6] add bevymark example --- Cargo.toml | 4 + examples/tools/bevymark.rs | 162 +++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 examples/tools/bevymark.rs diff --git a/Cargo.toml b/Cargo.toml index cfea9ac0e56fa..1d3a856190853 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -266,6 +266,10 @@ path = "examples/shader/shader_custom_material.rs" name = "shader_defs" path = "examples/shader/shader_defs.rs" +[[example]] +name = "bevymark" +path = "examples/tools/bevymark.rs" + [[example]] name = "button" path = "examples/ui/button.rs" diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs new file mode 100644 index 0000000000000..f00e9db539572 --- /dev/null +++ b/examples/tools/bevymark.rs @@ -0,0 +1,162 @@ +use bevy::{ + diagnostic::{FrameTimeDiagnosticsPlugin, PrintDiagnosticsPlugin}, + prelude::*, +}; + +const BIRDS_PER_SECOND: u32 = 1000; +const GRAVITY: f32 = -9.8; +const MAX_VELOCITY: f32 = 750.; +const BIRD_SCALE: f32 = 0.15; +const HALF_BIRD_SIZE: f32 = 256. * BIRD_SCALE * 0.5; +struct BevyCounter { + pub count: u128, +} + +struct Bird { + velocity: Vec3, +} + +fn main() { + App::build() + .add_resource(WindowDescriptor { + title: "BevyMark".to_string(), + width: 1000, + height: 800, + vsync: true, + resizable: false, + ..Default::default() + }) + .add_default_plugins() + .add_plugin(FrameTimeDiagnosticsPlugin::default()) + .add_plugin(PrintDiagnosticsPlugin::default()) + .add_resource(BevyCounter { count: 0 }) + .add_resource(Option::>::None) + .add_resource(Option::::None) + .add_startup_system(setup.system()) + .add_system(mouse_handler.system()) + .add_system(movement_system.system()) + .add_system(collision_system.system()) + .add_system(counter_system.system()) + .run(); +} + +fn setup( + mut commands: Commands, + asset_server: Res, + mut materials: ResMut>, + mut out_material_handle: ResMut>>, +) { + *out_material_handle = Some( + materials.add( + asset_server + .load("assets/branding/icon.png") + .unwrap() + .into(), + ), + ); + + commands + .spawn(Camera2dComponents::default()) + .spawn(UiCameraComponents::default()) + .spawn(TextComponents { + text: Text { + font: asset_server + .load("assets/fonts/FiraMono-Medium.ttf") + .unwrap(), + value: "Bird Count:".to_string(), + style: TextStyle { + color: Color::rgb(0.0, 0.9, 0.0), + font_size: 40.0, + }, + }, + style: Style { + position_type: PositionType::Absolute, + position: Rect { + top: Val::Px(5.0), + left: Val::Px(5.0), + ..Default::default() + }, + ..Default::default() + }, + ..Default::default() + }); +} + +fn mouse_handler( + mut commands: Commands, + time: Res