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::color_u8;
|
||||||
use macroquad::rand;
|
use macroquad::rand;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Bar {
|
pub struct Bar {
|
||||||
pub position:i32,
|
pub position:i32,
|
||||||
pub color:Color
|
pub color:color::Color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Bar{
|
impl Bar{
|
||||||
pub fn new(position:i32) -> Self{
|
pub fn new(position:i32, hsl_color:f32) -> Self{
|
||||||
|
println!("{}", hsl_color);
|
||||||
Bar{
|
Bar{
|
||||||
position,
|
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 {
|
pub fn new(screen_width:f32, screen_height:f32,length:i32) -> Self {
|
||||||
let barWidth = (screen_width/((length) as f32)) - 1_f32;
|
let barWidth = (screen_width/((length) as f32)) - 1_f32;
|
||||||
let barHeightStep = (screen_height/((length) as f32));
|
let barHeightStep = (screen_height/((length) as f32));
|
||||||
|
let colorStep = 360./length as f32;
|
||||||
let mut list:Vec<Bar> = vec!();
|
let mut list:Vec<Bar> = vec!();
|
||||||
for i in 1..length+1 {
|
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}
|
GuiVec{list, initialSize:length as usize, lastTime: 0.0 , reads:0, writes:0, comps:0, screen_height, screen_width}
|
||||||
}
|
}
|
||||||
|
|
19
src/State.rs
19
src/State.rs
|
@ -4,6 +4,7 @@ use std::time::Instant;
|
||||||
use macroquad::color::{BLACK, WHITE};
|
use macroquad::color::{BLACK, WHITE};
|
||||||
use macroquad::math::Vec2;
|
use macroquad::math::Vec2;
|
||||||
use macroquad::prelude::{clear_background, draw_text, get_fps, get_time, next_frame, screen_width};
|
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::ui::root_ui;
|
||||||
use macroquad::window::screen_height;
|
use macroquad::window::screen_height;
|
||||||
use crate::Algorithm::Algorithm;
|
use crate::Algorithm::Algorithm;
|
||||||
|
@ -20,17 +21,14 @@ impl State{
|
||||||
let mut lasttime:f64 = 0.;
|
let mut lasttime:f64 = 0.;
|
||||||
let mut holder = GuiVec::new(screen_width(), screen_height(), length);
|
let mut holder = GuiVec::new(screen_width(), screen_height(), length);
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
|
let mut speed = 200;
|
||||||
loop{
|
loop{
|
||||||
clear_background(WHITE);
|
clear_background(WHITE);
|
||||||
|
for _ in 0..speed{
|
||||||
if get_time()-lasttime > timeout && !finished && !paused{
|
if get_time()-lasttime > timeout && !finished && !paused{
|
||||||
let now = Instant::now();
|
|
||||||
match Pin::new(& mut generator).resume(()){
|
match Pin::new(& mut generator).resume(()){
|
||||||
GeneratorState::Yielded(x) => {
|
GeneratorState::Yielded(x) => {
|
||||||
holder = x;
|
holder = x;
|
||||||
let elapsed = now.elapsed();
|
|
||||||
//println!("{}", elapsed.as_micros());
|
|
||||||
println!("{}", get_fps())
|
|
||||||
},
|
},
|
||||||
GeneratorState::Complete(x) => {
|
GeneratorState::Complete(x) => {
|
||||||
finished = true;
|
finished = true;
|
||||||
|
@ -39,6 +37,7 @@ impl State{
|
||||||
};
|
};
|
||||||
lasttime = get_time();
|
lasttime = get_time();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
holder.draw();
|
holder.draw();
|
||||||
draw_text(format!("Read: {}", holder.reads).as_str(), screen_width()*0.01, 20.0, 20.0, BLACK);
|
draw_text(format!("Read: {}", holder.reads).as_str(), screen_width()*0.01, 20.0, 20.0, BLACK);
|
||||||
draw_text(format!("Write: {}", holder.writes).as_str(), screen_width()*0.01, 40.0, 20.0, BLACK);
|
draw_text(format!("Write: {}", holder.writes).as_str(), screen_width()*0.01, 40.0, 20.0, BLACK);
|
||||||
|
@ -55,15 +54,9 @@ impl State{
|
||||||
if root_ui().button(Vec2::new(screen_width()*0.01, 110.), "Return"){
|
if root_ui().button(Vec2::new(screen_width()*0.01, 110.), "Return"){
|
||||||
ret = true;
|
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")]
|
#[macroquad::main("BeepSort")]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let mut length = 200;
|
let mut length = 100;
|
||||||
|
|
||||||
let mut delay = 0.0;
|
let mut delay = 0.;
|
||||||
|
|
||||||
loop{
|
loop{
|
||||||
clear_background(WHITE);
|
clear_background(WHITE);
|
||||||
|
|
Loading…
Reference in a new issue