Remember to build for Release, literally 100x performance!
This commit is contained in:
parent
906dacf28b
commit
d57068af75
4 changed files with 27 additions and 33 deletions
|
@ -1,21 +1,21 @@
|
|||
use macroquad::color::Color;
|
||||
use macroquad::color;
|
||||
use macroquad::color_u8;
|
||||
use macroquad::rand;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Bar {
|
||||
pub position:i32,
|
||||
pub color:Color
|
||||
pub color:color::Color
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl Bar{
|
||||
pub fn new(position:i32) -> Self{
|
||||
|
||||
pub fn new(position:i32, hsl_color:f32) -> Self{
|
||||
println!("{}", hsl_color);
|
||||
Bar{
|
||||
position,
|
||||
color:Color::from_rgba(rand::gen_range(0, 255),rand::gen_range(0, 254),rand::gen_range(0, 255),255),
|
||||
color: color::hsl_to_rgb((hsl_color as f32) , 1.0, 0.5),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,10 @@ impl GuiVec{
|
|||
pub fn new(screen_width:f32, screen_height:f32,length:i32) -> Self {
|
||||
let barWidth = (screen_width/((length) as f32)) - 1_f32;
|
||||
let barHeightStep = (screen_height/((length) as f32));
|
||||
let colorStep = 360./length as f32;
|
||||
let mut list:Vec<Bar> = vec!();
|
||||
for i in 1..length+1 {
|
||||
list.push(Bar::new(i));
|
||||
list.push(Bar::new(i, (colorStep*i as f32)/360.));
|
||||
}
|
||||
GuiVec{list, initialSize:length as usize, lastTime: 0.0 , reads:0, writes:0, comps:0, screen_height, screen_width}
|
||||
}
|
||||
|
|
43
src/State.rs
43
src/State.rs
|
@ -4,6 +4,7 @@ use std::time::Instant;
|
|||
use macroquad::color::{BLACK, WHITE};
|
||||
use macroquad::math::Vec2;
|
||||
use macroquad::prelude::{clear_background, draw_text, get_fps, get_time, next_frame, screen_width};
|
||||
use macroquad::time::get_frame_time;
|
||||
use macroquad::ui::root_ui;
|
||||
use macroquad::window::screen_height;
|
||||
use crate::Algorithm::Algorithm;
|
||||
|
@ -20,24 +21,22 @@ impl State{
|
|||
let mut lasttime:f64 = 0.;
|
||||
let mut holder = GuiVec::new(screen_width(), screen_height(), length);
|
||||
let mut counter = 0;
|
||||
|
||||
let mut speed = 200;
|
||||
loop{
|
||||
clear_background(WHITE);
|
||||
if get_time()-lasttime > timeout && !finished && !paused{
|
||||
let now = Instant::now();
|
||||
match Pin::new(& mut generator).resume(()){
|
||||
GeneratorState::Yielded(x) => {
|
||||
holder = x;
|
||||
let elapsed = now.elapsed();
|
||||
//println!("{}", elapsed.as_micros());
|
||||
println!("{}", get_fps())
|
||||
},
|
||||
GeneratorState::Complete(x) => {
|
||||
finished = true;
|
||||
paused = true;
|
||||
}
|
||||
};
|
||||
lasttime = get_time();
|
||||
for _ in 0..speed{
|
||||
if get_time()-lasttime > timeout && !finished && !paused{
|
||||
match Pin::new(& mut generator).resume(()){
|
||||
GeneratorState::Yielded(x) => {
|
||||
holder = x;
|
||||
},
|
||||
GeneratorState::Complete(x) => {
|
||||
finished = true;
|
||||
paused = true;
|
||||
}
|
||||
};
|
||||
lasttime = get_time();
|
||||
}
|
||||
}
|
||||
holder.draw();
|
||||
draw_text(format!("Read: {}", holder.reads).as_str(), screen_width()*0.01, 20.0, 20.0, BLACK);
|
||||
|
@ -55,15 +54,9 @@ impl State{
|
|||
if root_ui().button(Vec2::new(screen_width()*0.01, 110.), "Return"){
|
||||
ret = true;
|
||||
}
|
||||
if (finished && ret) || ret {
|
||||
break;
|
||||
}
|
||||
if counter != 20{
|
||||
counter += 1;
|
||||
}else{
|
||||
counter = 0;
|
||||
next_frame().await
|
||||
}
|
||||
|
||||
next_frame().await
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,9 +19,9 @@ use crate::Algorithm::AlgoEnum;
|
|||
|
||||
#[macroquad::main("BeepSort")]
|
||||
async fn main() {
|
||||
let mut length = 200;
|
||||
let mut length = 100;
|
||||
|
||||
let mut delay = 0.0;
|
||||
let mut delay = 0.;
|
||||
|
||||
loop{
|
||||
clear_background(WHITE);
|
||||
|
|
Loading…
Reference in a new issue