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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.3"
|
bevy = "0.4"
|
||||||
num-complex = "0.3"
|
num-complex = "0.3"
|
||||||
rayon = "1.5"
|
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 mandelbrot::Mandelbrot;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
@ -33,11 +34,7 @@ impl Default for SpriteScale {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transform_mandelbrot_system(
|
fn transform_mandelbrot_system(input: Res<Input<KeyCode>>, mut scale: ResMut<SpriteScale>) {
|
||||||
input: Res<Input<KeyCode>>,
|
|
||||||
mut scale: ResMut<SpriteScale>,
|
|
||||||
// camera: Res<Camera>,
|
|
||||||
) {
|
|
||||||
let zoom = input.pressed(KeyCode::Q) as i8 - input.pressed(KeyCode::E) as i8;
|
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 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;
|
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 v = scale.verti;
|
||||||
let iters = scale.iterations;
|
let iters = scale.iterations;
|
||||||
|
|
||||||
let start = Instant::now();
|
let buf = fractal.generate_scaled_image(
|
||||||
texture.data.copy_from_slice(fractal.generate_scaled_image(
|
|
||||||
((-2.5 * z) + h, (1.0 * z) + h),
|
((-2.5 * z) + h, (1.0 * z) + h),
|
||||||
((-1.0 * z) - v, (1.0 * z) - v),
|
((-1.0 * z) - v, (1.0 * z) - v),
|
||||||
iters,
|
iters,
|
||||||
));
|
);
|
||||||
let _diff = Instant::now() - start;
|
|
||||||
|
texture.data.copy_from_slice(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,22 +101,24 @@ fn mandelbrot_render_system(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn startup(
|
fn startup(
|
||||||
mut commands: Commands,
|
commands: &mut Commands,
|
||||||
mut textures: ResMut<Assets<Texture>>,
|
mut textures: ResMut<Assets<Texture>>,
|
||||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
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 img_buf = Mandelbrot::new().generate_image().to_vec();
|
||||||
|
|
||||||
let texture_handle = textures.add(Texture::new(
|
let texture_handle = textures.add(Texture::new(
|
||||||
img_size,
|
img_size,
|
||||||
|
dimension,
|
||||||
img_buf,
|
img_buf,
|
||||||
TextureFormat::Rgba8UnormSrgb,
|
TextureFormat::Rgba8UnormSrgb,
|
||||||
));
|
));
|
||||||
|
|
||||||
commands
|
commands
|
||||||
.spawn(Camera2dComponents::default())
|
.spawn(Camera2dBundle::default())
|
||||||
.spawn(SpriteComponents {
|
.spawn(SpriteBundle {
|
||||||
material: materials.add(texture_handle.into()),
|
material: materials.add(texture_handle.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue