feat: upgrade to bevy 0.4
This commit is contained in:
parent
1ce54d5b5a
commit
89d57ca5f6
File diff suppressed because it is too large
Load Diff
|
@ -7,6 +7,6 @@ edition = "2018"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.3"
|
||||
bevy = "0.4"
|
||||
num-complex = "0.3"
|
||||
rayon = "1.5"
|
||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -1,4 +1,5 @@
|
|||
use bevy::{prelude::*, render::texture::TextureFormat};
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::texture::{Extent3d, TextureDimension, TextureFormat};
|
||||
use mandelbrot::Mandelbrot;
|
||||
use std::time::Instant;
|
||||
|
||||
|
@ -33,11 +34,7 @@ impl Default for SpriteScale {
|
|||
}
|
||||
}
|
||||
|
||||
fn transform_mandelbrot_system(
|
||||
input: Res<Input<KeyCode>>,
|
||||
mut scale: ResMut<SpriteScale>,
|
||||
// camera: Res<Camera>,
|
||||
) {
|
||||
fn transform_mandelbrot_system(input: Res<Input<KeyCode>>, mut scale: ResMut<SpriteScale>) {
|
||||
let zoom = input.pressed(KeyCode::Q) as i8 - input.pressed(KeyCode::E) as i8;
|
||||
let horizontal = input.pressed(KeyCode::D) as i8 - input.pressed(KeyCode::A) as i8;
|
||||
let vertical = input.pressed(KeyCode::W) as i8 - input.pressed(KeyCode::S) as i8;
|
||||
|
@ -90,13 +87,13 @@ fn mandelbrot_render_system(
|
|||
let v = scale.verti;
|
||||
let iters = scale.iterations;
|
||||
|
||||
let start = Instant::now();
|
||||
texture.data.copy_from_slice(fractal.generate_scaled_image(
|
||||
let buf = fractal.generate_scaled_image(
|
||||
((-2.5 * z) + h, (1.0 * z) + h),
|
||||
((-1.0 * z) - v, (1.0 * z) - v),
|
||||
iters,
|
||||
));
|
||||
let _diff = Instant::now() - start;
|
||||
);
|
||||
|
||||
texture.data.copy_from_slice(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,22 +101,24 @@ fn mandelbrot_render_system(
|
|||
}
|
||||
|
||||
fn startup(
|
||||
mut commands: Commands,
|
||||
commands: &mut Commands,
|
||||
mut textures: ResMut<Assets<Texture>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
let img_size = Vec2::new(Mandelbrot::width() as f32, Mandelbrot::height() as f32);
|
||||
let img_size = Extent3d::new(Mandelbrot::width() as u32, Mandelbrot::height() as u32, 1);
|
||||
let dimension = TextureDimension::D2;
|
||||
let img_buf = Mandelbrot::new().generate_image().to_vec();
|
||||
|
||||
let texture_handle = textures.add(Texture::new(
|
||||
img_size,
|
||||
dimension,
|
||||
img_buf,
|
||||
TextureFormat::Rgba8UnormSrgb,
|
||||
));
|
||||
|
||||
commands
|
||||
.spawn(Camera2dComponents::default())
|
||||
.spawn(SpriteComponents {
|
||||
.spawn(Camera2dBundle::default())
|
||||
.spawn(SpriteBundle {
|
||||
material: materials.add(texture_handle.into()),
|
||||
..Default::default()
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue