From a14dcff8f975836afc01d351f16f8febc5e0d502 Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Tue, 1 Aug 2023 16:11:06 -0400 Subject: [PATCH] Adds a test line drawn --- Cargo.lock | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +- src/main.rs | 20 ++++++++++-- src/world.rs | 23 +++++++------- 4 files changed, 117 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86a1cde..2126eaa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -696,6 +696,18 @@ dependencies = [ "radsort", ] +[[package]] +name = "bevy_prototype_lyon" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e347c16caede05dc5f774ba388cefeef0ab558a5601fc6b5ffd6606bef77308" +dependencies = [ + "bevy", + "lyon_algorithms", + "lyon_tessellation", + "svgtypes", +] + [[package]] name = "bevy_ptr" version = "0.11.0" @@ -1499,6 +1511,15 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "float_next_after" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fc612c5837986b7104a87a0df74a5460931f1c5274be12f8d0f40aa2f30d632" +dependencies = [ + "num-traits", +] + [[package]] name = "fnv" version = "1.0.7" @@ -2033,6 +2054,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "libm" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" + [[package]] name = "libudev-sys" version = "0.1.4" @@ -2048,6 +2075,7 @@ name = "life_sim" version = "0.1.0" dependencies = [ "bevy", + "bevy_prototype_lyon", ] [[package]] @@ -2066,6 +2094,48 @@ version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +[[package]] +name = "lyon_algorithms" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00a0349cd8f0270781bb93a824b63df6178e3b4a27794e7be3ce3763f5a44d6e" +dependencies = [ + "lyon_path", + "num-traits", +] + +[[package]] +name = "lyon_geom" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74df1ff0a0147282eb10699537a03baa7d31972b58984a1d44ce0624043fe8ad" +dependencies = [ + "arrayvec", + "euclid", + "num-traits", +] + +[[package]] +name = "lyon_path" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca507745ba7ccbc76e5c44e7b63b1a29d2b0d6126f375806a5bbaf657c7d6c45" +dependencies = [ + "lyon_geom", + "num-traits", +] + +[[package]] +name = "lyon_tessellation" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d2124218d5428149f9e09520b9acc024334a607e671f032d06567b61008977c" +dependencies = [ + "float_next_after", + "lyon_path", + "thiserror", +] + [[package]] name = "mach2" version = "0.4.1" @@ -2326,6 +2396,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -2820,6 +2891,12 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "238abfbb77c1915110ad968465608b68e869e0772622c9656714e73e5a1a522f" +[[package]] +name = "siphasher" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" + [[package]] name = "slab" version = "0.4.8" @@ -2878,6 +2955,15 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fb1df15f412ee2e9dfc1c504260fa695c1c3f10fe9f4a6ee2d2184d7d6450e2" +[[package]] +name = "svgtypes" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22975e8a2bac6a76bb54f898a6b18764633b00e780330f0b689f65afb3975564" +dependencies = [ + "siphasher", +] + [[package]] name = "syn" version = "1.0.109" diff --git a/Cargo.toml b/Cargo.toml index bf7f52d..4498558 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,9 @@ edition = "2021" [dependencies] bevy = "0.11.0" +bevy_prototype_lyon = "0.9.0" # Enable high optimizations for dependencies (incl. Bevy), but not for our code: [profile.dev.package."*"] -opt-level = 3 \ No newline at end of file +opt-level = 3 diff --git a/src/main.rs b/src/main.rs index b402715..9651ed1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, DiagnosticsStore}, window::{PresentMode, WindowTheme}, sprite::MaterialMesh2dBundle}; +use bevy_prototype_lyon::prelude::*; use world::WorldPlugin; use std::time::Instant; @@ -43,7 +44,7 @@ fn main() DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "Life Sim".into(), - resolution: (1000., 1000.).into(), + resolution: (700., 700.).into(), present_mode: PresentMode::AutoVsync, // Tells wasm to resize the window according to the available canvas fit_canvas_to_parent: true, @@ -59,7 +60,8 @@ fn main() WorldPlugin { grid_width: 100., grid_height: 100. - } + }, + ShapePlugin )) .insert_resource(SimulationState::new(200)) .insert_resource(Time::new(Instant::now())) @@ -85,6 +87,17 @@ fn setup(mut commands: Commands, mut meshes: ResMut>, mut materials Agent )); + // Line test + let line = shapes::Line(Vec2::ZERO, Vec2::new(100.0, 100.0)); + commands.spawn(( + ShapeBundle { + path: GeometryBuilder::build_as(&line), + ..default() + }, + Stroke::new(Color::ORANGE_RED, 5.0), + //Fill::color(Color::ORANGE_RED), + )); + // UI // Text with multiple sections @@ -149,4 +162,5 @@ fn ui_update(mut state: Res, diagnostics: Res } } } -} \ No newline at end of file +} + diff --git a/src/world.rs b/src/world.rs index 53de95c..eea561d 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,5 +1,6 @@ -use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; +use bevy::prelude::*; +use bevy_prototype_lyon::prelude::*; #[derive(Resource)] struct WorldPluginState @@ -42,19 +43,19 @@ impl Plugin for WorldPlugin fn setup(mut commands: Commands, settings: Res, mut meshes: ResMut>, mut materials: ResMut>) { // Camera - commands.spawn(Camera2dBundle::default()); + //commands.spawn(Camera2dBundle::default()); // Add Grid - let cell_width = settings.window_width / settings.grid_width; - let cell_height = settings.window_height / settings.grid_height; - let line_size = 2; - for i in 0..settings.grid_width as i32 - { - for j in 0..settings.grid_height as i32 - { + // let cell_width = settings.window_width / settings.grid_width; + // let cell_height = settings.window_height / settings.grid_height; + // let line_size = 2; + // for i in 0..settings.grid_width as i32 + // { + // for j in 0..settings.grid_height as i32 + // { - } - } + // } + // } } // fn add_line(mut commands: Commands, point_a: Vec2, point_b: Vec2, line_size: i32)