pub fn init_cells() -> (GraphicsReceiver, Vec<LifeSender>) {
    // configure the core and get it running
    executor::set_default_channel_capacity(10);
    executor::set_machine_count_estimate(GRID_SIZE + 10);
    executor::start_server();

    let (graphics_sender, graphics_receiver) = machine_impl::channel::<GraphicsCmd>();
    let mut cells: Vec<LifeSender> = Vec::with_capacity(GRID_SIZE * GRID_SIZE);

    // create all of the machines
    for idx in 0 .. GRID_SIZE * GRID_SIZE {
        let row = (idx / GRID_SIZE) as u32;
        let col = (idx % GRID_SIZE) as u32;
        let rect = Rect::new(
            (BORDER_SIZE + (RECT_SIZE + 1) * col) as i32,
            (BORDER_SIZE + (RECT_SIZE + 1) * row) as i32,
            RECT_SIZE,
            RECT_SIZE,
        );
        let (_, s) = executor::connect_unbounded(LifeCell::new(idx, graphics_sender.clone(), rect));
        cells.push(s);
    }
    // wait for them to all get assigned
    let target = GRID_SIZE * GRID_SIZE;
    loop {
        if target == executor::get_machine_count() {
            break;
        }
        std::thread::sleep(std::time::Duration::from_nanos(50));
    }
    log::info!("created {} machines", executor::get_machine_count());

    // wire the neighbors together
    cells.iter().enumerate().for_each(|(idx, cell)| {
        // each cell has 8 neighbors, go find them
        let row = idx / GRID_SIZE;
        let col = idx % GRID_SIZE;
        for dr in [GRID_SIZE - 1, 0, 1].iter().cloned() {
            for dc in [GRID_SIZE - 1, 0, 1].iter().cloned() {
                sdl2::rect::Rect::new(0, 0, RECT_SIZE, RECT_SIZE);
                if dr == 0 && dc == 0 {
                    continue;
                }
                let nr = (row + dr) % GRID_SIZE;
                let nc = (col + dc) % GRID_SIZE;
                let n = nr * GRID_SIZE + nc;
                cell.send(LifeCmd::AddNeighbor(cells[n].clone())).unwrap();
            }
        }
    });
    (graphics_receiver, cells)
}
// initialize cells and start the server
initialize cells and start the server
initialize cells and start the server
pub fn init_cells() -> (GraphicsReceiver, Vec<LifeSender>) {
    // configure the core and get it running
    executor::set_default_channel_capacity(10);
    executor::set_machine_count_estimate(GRID_SIZE + 10);
    executor::start_server();
    let (graphics_sender, graphics_receiver) = machine_impl::channel::<GraphicsCmd>();
    let mut cells: Vec<LifeSender> = Vec::with_capacity(GRID_SIZE * GRID_SIZE);
    // create all of the machines
    for idx in 0 .. GRID_SIZE * GRID_SIZE {
        let row = (idx / GRID_SIZE) as u32;
        let col = (idx % GRID_SIZE) as u32;
        let rect = Rect::new(
            (BORDER_SIZE + (RECT_SIZE + 1) * col) as i32,
            (BORDER_SIZE + (RECT_SIZE + 1) * row) as i32,
            RECT_SIZE,
            RECT_SIZE,
        );
        let (_, s) = executor::connect_unbounded(LifeCell::new(idx, graphics_sender.clone(), rect));
        cells.push(s);
    }
    // wait for them to all get assigned
    let target = GRID_SIZE * GRID_SIZE;
    loop {
        if target == executor::get_machine_count() {
            break;
        }
        std::thread::sleep(std::time::Duration::from_nanos(50));
    }
    log::info!("created {} machines", executor::get_machine_count());
    // wire the neighbors together
    cells.iter().enumerate().for_each(|(idx, cell)| {
        // each cell has 8 neighbors, go find them
        let row = idx / GRID_SIZE;
        let col = idx % GRID_SIZE;
        for dr in [GRID_SIZE - 1, 0, 1].iter().cloned() {
            for dc in [GRID_SIZE - 1, 0, 1].iter().cloned() {
                sdl2::rect::Rect::new(0, 0, RECT_SIZE, RECT_SIZE);
                if dr == 0 && dc == 0 {
                    continue;
                }
                let nr = (row + dr) % GRID_SIZE;
                let nc = (col + dc) % GRID_SIZE;
                let n = nr * GRID_SIZE + nc;
                cell.send(LifeCmd::AddNeighbor(cells[n].clone())).unwrap();
            }
        }
    });
    (graphics_receiver, cells)
}
pub fn init_cells ( ) -> ( GraphicsReceiver , Vec < LifeSender > ) { // configure the core and get it running executor :: set_default_channel_capacity ( 10 ) ; executor :: set_machine_count_estimate ( GRID_SIZE + 10 ) ; executor :: start_server ( ) ; let ( graphics_sender , graphics_receiver ) = machine_impl :: channel :: < GraphicsCmd > ( ) ; let mut cells : Vec < LifeSender > = Vec :: with_capacity ( GRID_SIZE * GRID_SIZE ) ; // create all of the machines for idx in 0 .. GRID_SIZE * GRID_SIZE { let row = ( idx / GRID_SIZE ) as u32 ; let col = ( idx % GRID_SIZE ) as u32 ; let rect = Rect :: new ( ( BORDER_SIZE + ( RECT_SIZE + 1 ) * col ) as i32 , ( BORDER_SIZE + ( RECT_SIZE + 1 ) * row ) as i32 , RECT_SIZE , RECT_SIZE , ) ; let ( _ , s ) = executor :: connect_unbounded ( LifeCell :: new ( idx , graphics_sender . clone ( ) , rect ) ) ; cells . push ( s ) ; } // wait for them to all get assigned let target = GRID_SIZE * GRID_SIZE ; loop { if target == executor :: get_machine_count ( ) { break ; } std :: thread :: sleep ( std :: time :: Duration :: from_nanos ( 50 ) ) ; } log :: info ! ( " " executor get_machine_count ( ) ) ; // wire the neighbors together cells . iter ( ) . enumerate ( ) . for_each ( | ( idx , cell ) | { // each cell has 8 neighbors, go find them let row = idx / GRID_SIZE ; let col = idx % GRID_SIZE ; for dr in [ GRID_SIZE - 1 , 0 , 1 ] . iter ( ) . cloned ( ) { for dc in [ GRID_SIZE - 1 , 0 , 1 ] . iter ( ) . cloned ( ) { sdl2 :: rect :: Rect :: new ( 0 , 0 , RECT_SIZE , RECT_SIZE ) ; if dr == 0 && dc == 0 { continue ; } let nr = ( row + dr ) % GRID_SIZE ; let nc = ( col + dc ) % GRID_SIZE ; let n = nr * GRID_SIZE + nc ; cell . send ( LifeCmd :: AddNeighbor ( cells [ n ] . clone ( ) ) ) . unwrap ( ) ; } } } ) ; ( graphics_receiver , cells ) }
initialize cells and start the server
initialize cells and start the server