Update WaveformColapse builder to use the proper tileset

This commit is contained in:
Timothy Warren 2022-01-28 14:01:24 -05:00
parent a40f43b839
commit 6d57020327
3 changed files with 23 additions and 6 deletions

View File

@ -7,7 +7,7 @@ use common::*;
use constraints::*; use constraints::*;
use solver::*; use solver::*;
use crate::map_builders::{BuilderMap, MetaMapBuilder}; use super::{BuilderMap, MetaMapBuilder};
use crate::Map; use crate::Map;
pub struct WaveformCollapseBuilder {} pub struct WaveformCollapseBuilder {}
@ -33,12 +33,18 @@ impl WaveformCollapseBuilder {
let constraints = patterns_to_constraints(patterns, CHUNK_SIZE); let constraints = patterns_to_constraints(patterns, CHUNK_SIZE);
self.render_tile_gallery(&constraints, CHUNK_SIZE, build_data); self.render_tile_gallery(&constraints, CHUNK_SIZE, build_data);
let old_map = build_data.map.clone();
build_data.map = Map::new( build_data.map = Map::new(
build_data.map.depth, build_data.map.depth,
build_data.width, build_data.width,
build_data.height, build_data.height,
&build_data.map.name, &build_data.map.name,
); );
build_data.spawn_list.clear();
build_data.rooms = None;
build_data.corridors = None;
let mut tries = 0;
loop { loop {
let mut solver = Solver::new(constraints.clone(), CHUNK_SIZE, &build_data.map); let mut solver = Solver::new(constraints.clone(), CHUNK_SIZE, &build_data.map);
while !solver.iteration(&mut build_data.map, rng) { while !solver.iteration(&mut build_data.map, rng) {
@ -48,9 +54,16 @@ impl WaveformCollapseBuilder {
if solver.possible { if solver.possible {
break; break;
} // If it has hit an impossible condition, try again } // If it has hit an impossible condition, try again
tries += 1;
if tries > 10 {
break;
}
} }
build_data.spawn_list.clear(); if tries > 10 {
// Restore the old one
build_data.map = old_map;
}
} }
fn render_tile_gallery( fn render_tile_gallery(
@ -59,7 +72,12 @@ impl WaveformCollapseBuilder {
chunk_size: i32, chunk_size: i32,
build_data: &mut BuilderMap, build_data: &mut BuilderMap,
) { ) {
build_data.map = Map::new(0, build_data.width, build_data.height, &build_data.map.name); build_data.map = Map::new(
build_data.map.depth,
build_data.width,
build_data.height,
&build_data.map.name,
);
let mut counter = 0; let mut counter = 0;
let mut x = 1; let mut x = 1;
let mut y = 1; let mut y = 1;

View File

@ -1,7 +1,6 @@
use std::collections::HashSet; use std::collections::HashSet;
use super::MapChunk; use super::{tile_idx_in_chunk, MapChunk};
use crate::map_builders::waveform_collapse::common::tile_idx_in_chunk;
use crate::{Map, TileType}; use crate::{Map, TileType};
pub fn build_patterns( pub fn build_patterns(

View File

@ -1,6 +1,6 @@
use std::collections::HashSet; use std::collections::HashSet;
use super::common::MapChunk; use super::MapChunk;
use crate::Map; use crate::Map;
pub struct Solver { pub struct Solver {