#[cfg(feature = "flame_it")]
use flame;
use glium::{
self, glutin::{self, WindowEvent},
};
use gridsim::{GetNeighbors, Sim, SquareGrid, TakeMoveNeighbors};
#[cfg(feature = "flame_it")]
use std::fs::File;
use Renderer;
#[cfg_attr(feature = "flame_it", flame)]
pub fn basic_bool<'a, S: 'a>(grid: SquareGrid<'a, S>)
where
S: Sim<'a, Cell = bool>,
S::Cell: Sync + Send,
S::Move: Sync + Send,
S::Diff: Sync + Send,
S::Neighbors: Sync + Send,
S::MoveNeighbors: Sync + Send,
SquareGrid<'a, S>: TakeMoveNeighbors<usize, S::MoveNeighbors>,
SquareGrid<'a, S>: GetNeighbors<'a, usize, S::Neighbors>,
{
basic_filter(grid, |_| [1.0, 1.0, 1.0, 1.0], |&c| c);
}
#[cfg_attr(feature = "flame_it", flame)]
pub fn basic<'a, S: 'a, F>(grid: SquareGrid<'a, S>, coloration: F)
where
S: Sim<'a>,
F: Fn(&S::Cell) -> [f32; 4] + Sync,
S::Cell: Sync + Send,
S::Move: Sync + Send,
S::Diff: Sync + Send,
S::Neighbors: Sync + Send,
S::MoveNeighbors: Sync + Send,
SquareGrid<'a, S>: TakeMoveNeighbors<usize, S::MoveNeighbors>,
SquareGrid<'a, S>: GetNeighbors<'a, usize, S::Neighbors>,
{
basic_filter(grid, coloration, |_| true);
}
#[cfg_attr(feature = "flame_it", flame)]
pub fn basic_filter<'a, S: 'a, Color, Filter>(
mut grid: SquareGrid<'a, S>,
coloration: Color,
filter: Filter,
) where
S: Sim<'a>,
Color: Fn(&S::Cell) -> [f32; 4] + Sync,
Filter: Fn(&S::Cell) -> bool + Sync,
S::Cell: Sync + Send,
S::Move: Sync + Send,
S::Diff: Sync + Send,
S::Neighbors: Sync + Send,
S::MoveNeighbors: Sync + Send,
SquareGrid<'a, S>: TakeMoveNeighbors<usize, S::MoveNeighbors>,
SquareGrid<'a, S>: GetNeighbors<'a, usize, S::Neighbors>,
{
let mut events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new();
let context = glutin::ContextBuilder::new().with_vsync(true);
let display = glium::Display::new(window, context, &events_loop).unwrap();
let renderer = Renderer::new(&display);
loop {
use glium::Surface;
#[cfg_attr(feature = "flame_it", flame)]
grid.cycle();
let mut target = display.draw();
target.clear_color(0.0, 0.0, 0.0, 1.0);
renderer
.render(
&display,
&mut target,
&grid,
Default::default(),
&coloration,
&filter,
)
.unwrap();
target.finish().unwrap();
let mut finish = false;
events_loop.poll_events(|event| {
match event {
glutin::Event::WindowEvent { event, .. } => {
match event {
WindowEvent::Closed => {
#[cfg(feature = "flame_it")]
flame::dump_html(&mut File::create("flame-graph.html").unwrap())
.expect(
"gridsim-ui::run::basic_filter(): unable to write flamegraph",
);
finish = true;
}
_ => (),
}
}
_ => (),
}
});
if finish {
return;
}
}
}