rust/landgen/src/wavefront_collapse/generator.rs
changeset 16073 5d302b12d837
parent 16064 07cb6dbc8444
child 16075 2c2b094e6bbe
equal deleted inserted replaced
16072:a4cbc6926439 16073:5d302b12d837
    89         )?;
    89         )?;
    90         let decoder = Decoder::new(BufReader::new(file));
    90         let decoder = Decoder::new(BufReader::new(file));
    91         let mut reader = decoder.read_info()?;
    91         let mut reader = decoder.read_info()?;
    92 
    92 
    93         let info = reader.info();
    93         let info = reader.info();
    94         let mut tiles_image = vec2d::Vec2D::new(
    94         let mut tiles_image =
    95             &Size::new(info.width as usize, info.height as usize),
    95             vec2d::Vec2D::new(&Size::new(info.width, info.height), parameters.zero);
    96             parameters.zero,
       
    97         );
       
    98 
    96 
    99         let mut buf = vec![0; reader.output_buffer_size()];
    97         let mut buf = vec![0; reader.output_buffer_size()];
   100         let info = reader.next_frame(&mut buf)?;
    98         let info = reader.next_frame(&mut buf)?;
   101         let bytes = &buf[..info.buffer_size()];
    99         let bytes = &buf[..info.buffer_size()];
   102 
   100 
   323 
   321 
   324         wfc.generate_map(&wfc_size, |_| {}, random_numbers);
   322         wfc.generate_map(&wfc_size, |_| {}, random_numbers);
   325 
   323 
   326         // render tiles into resulting land array
   324         // render tiles into resulting land array
   327         let mut result = land2d::Land2D::new(&self.template.size, parameters.zero);
   325         let mut result = land2d::Land2D::new(&self.template.size, parameters.zero);
   328         let offset_y = result.height() - result.play_height();
   326         let offset_y = result.height() - result.play_height() as usize;
   329         let offset_x = (result.width() - result.play_width()) / 2;
   327         let offset_x = (result.width() - result.play_width() as usize) / 2;
   330 
   328 
   331         for row in 0..wfc_size.height {
   329         for row in 0..wfc_size.height as usize {
   332             for column in 0..wfc_size.width {
   330             for column in 0..wfc_size.width as usize {
   333                 if let Some(Tile::Numbered(tile_index)) = wfc.grid().get(row, column) {
   331                 if let Some(Tile::Numbered(tile_index)) = wfc.grid().get(row, column) {
   334                     let tile = &tiles[*tile_index];
   332                     let tile = &tiles[*tile_index];
   335 
   333 
   336                     for tile_row in 0..tile.size().height {
   334                     for tile_row in 0..tile.size().height as usize {
   337                         for tile_column in 0..tile.size().width {
   335                         for tile_column in 0..tile.size().width as usize {
   338                             result.map(
   336                             result.map(
   339                                 (row * tile.size().height + tile_row + offset_y) as i32,
   337                                 (row * tile.size().height as usize + tile_row + offset_y) as i32,
   340                                 (column * tile.size().width + tile_column + offset_x) as i32,
   338                                 (column * tile.size().width as usize + tile_column + offset_x)
       
   339                                     as i32,
   341                                 |p| {
   340                                 |p| {
   342                                     *p =
   341                                     *p =
   343                                         *tile.get(tile_row, tile_column).unwrap_or(&parameters.zero)
   342                                         *tile.get(tile_row, tile_column).unwrap_or(&parameters.zero)
   344                                 },
   343                                 },
   345                             );
   344                             );