working chunks
This commit is contained in:
parent
ab7756c3bc
commit
0699c5da2e
83
src/map.rs
83
src/map.rs
@ -39,13 +39,13 @@ impl bevy::prelude::Plugin for Plugin {
|
||||
/// Determined empirically
|
||||
pub const AVERAGE_NEIGHBORS_NUMBER: f64 = 6.;
|
||||
|
||||
pub const HEIGHT: f64 = 16.;
|
||||
pub const WIDTH: f64 = 16.;
|
||||
pub const HEIGHT: f64 = 4.;
|
||||
pub const WIDTH: f64 = 4.;
|
||||
pub const REAL_HEIGHT: f32 = 8000.;
|
||||
pub const REAL_WIDTH: f32 = 8000.;
|
||||
pub const CELL_AREA: f32 = REAL_HEIGHT * REAL_WIDTH / CELLS as f32;
|
||||
pub const CELLS_TARGET_NUMBER: usize = 100_000;
|
||||
pub const CHUNKS_RESOLUTION: usize = 2;
|
||||
pub const CELLS_TARGET_NUMBER: usize = 100000;
|
||||
pub const CHUNKS_RESOLUTION: usize = 4;
|
||||
pub const CHUNKS: usize = CHUNKS_RESOLUTION.pow(2);
|
||||
pub const CELLS_PER_CHUNK: usize = CELLS_TARGET_NUMBER / CHUNKS;
|
||||
pub const CELLS: usize = CELLS_PER_CHUNK * CHUNKS;
|
||||
@ -83,10 +83,6 @@ fn setup(
|
||||
for chunk_y in 0..CHUNKS_RESOLUTION {
|
||||
let min_y = HEIGHT / 2. * ((2. * (chunk_y as f64) / (CHUNKS_RESOLUTION as f64)) - 1.);
|
||||
let max_y = min_y + (HEIGHT as f64 / CHUNKS_RESOLUTION as f64);
|
||||
println!(
|
||||
"[{},{}] x:[{}, {}], y:[{}, {}]",
|
||||
chunk_x, chunk_y, min_x, max_x, min_y, max_y
|
||||
);
|
||||
for _ in 0..CELLS_PER_CHUNK {
|
||||
sites.push(Point {
|
||||
x: rng.gen_range(min_x..max_x),
|
||||
@ -163,53 +159,36 @@ fn setup(
|
||||
}
|
||||
let mut chs = t.iter().map(|c| Cell::chunk_from_id(*c));
|
||||
let chs: [usize; 3] = std::array::from_fn(|_| chs.next().unwrap());
|
||||
// Add vertex to chunk if it is from an external chunk but we need it for a triangle. Else, just make the triangle
|
||||
if chs[1] == chs[2] && chs[0] != chs[1] {
|
||||
poss[chs[1]].push(poss[chs[0]][t[0] % CELLS_PER_CHUNK]);
|
||||
// hybrid_cells.insert(chs[0], chs[1]);
|
||||
indices[chs[1]].push((poss[chs[1]].len() - 1) as u32);
|
||||
} else {
|
||||
indices[chs[0]].push((t[0] % CELLS_PER_CHUNK) as u32);
|
||||
}
|
||||
if chs[0] == chs[2] && chs[1] != chs[0] {
|
||||
poss[chs[0]].push(poss[chs[1]][t[1] % CELLS_PER_CHUNK]);
|
||||
// hybrid_cells.insert(chs[1], chs[0]);
|
||||
indices[chs[0]].push((poss[chs[0]].len() - 1) as u32);
|
||||
} else {
|
||||
indices[chs[1]].push((t[1] % CELLS_PER_CHUNK) as u32);
|
||||
}
|
||||
if chs[0] == chs[1] && chs[2] != chs[0] {
|
||||
poss[chs[0]].push(poss[chs[2]][t[2] % CELLS_PER_CHUNK]);
|
||||
// hybrid_cells.insert(chs[2], chs[0]);
|
||||
indices[chs[0]].push((poss[chs[0]].len() - 1) as u32);
|
||||
} else {
|
||||
indices[chs[2]].push((t[2] % CELLS_PER_CHUNK) as u32);
|
||||
for ch in 0..CHUNKS {
|
||||
if !chs.contains(&ch) {
|
||||
continue;
|
||||
}
|
||||
// let ch = if chs[1] == chs[2] { chs[1] } else { chs[0] };
|
||||
// Add vertex to chunk if it is from an external chunk but we need it for a triangle. Else, just make the triangle
|
||||
if chs[2] != ch {
|
||||
poss[ch].push(poss[chs[2]][t[2] % CELLS_PER_CHUNK]);
|
||||
// hybrid_cells.insert(chs[2], chs[0]);
|
||||
indices[ch].push((poss[ch].len() - 1) as u32);
|
||||
} else {
|
||||
indices[ch].push((t[2] % CELLS_PER_CHUNK) as u32);
|
||||
}
|
||||
if chs[1] != ch {
|
||||
poss[ch].push(poss[chs[1]][t[1] % CELLS_PER_CHUNK]);
|
||||
// hybrid_cells.insert(chs[1], chs[0]);
|
||||
indices[ch].push((poss[ch].len() - 1) as u32);
|
||||
} else {
|
||||
indices[ch].push((t[1] % CELLS_PER_CHUNK) as u32);
|
||||
}
|
||||
if chs[0] != ch {
|
||||
poss[ch].push(poss[chs[0]][t[0] % CELLS_PER_CHUNK]);
|
||||
// hybrid_cells.insert(chs[0], chs[1]);
|
||||
indices[ch].push((poss[ch].len() - 1) as u32);
|
||||
} else {
|
||||
indices[ch].push((t[0] % CELLS_PER_CHUNK) as u32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// indices.extend(voronoi.triangulation().triangles.iter().map(|t| *t as u32));
|
||||
|
||||
// for (c, cd) in voronoi.iter_cells().zip(cells.iter_mut()) {
|
||||
// let vs = c.iter_vertices().collect::<Vec<_>>();
|
||||
// let i = poss.len();
|
||||
// for v in vs.iter() {
|
||||
// let z = get_altitude(&z_noise, &[v.x as f32, v.y as f32]);
|
||||
// poss.push(Vec3::new(v.x as f32, v.y as f32, z));
|
||||
// // const EPSILON: f32 = 0.01;
|
||||
// // let dzx = get_altitude(&z_noise, &[v.x as f32 + EPSILON, v.y as f32]) - z;
|
||||
// // let nx = (f32::consts::FRAC_PI_2 - (dzx / EPSILON).atan()).cos();
|
||||
// // let dzy = get_altitude(&z_noise, &[v.x as f32, v.y as f32 + EPSILON]) - z;
|
||||
// // let ny = (f32::consts::FRAC_PI_2 - (dzy / EPSILON).atan()).cos();
|
||||
|
||||
// // let nz = (1. - (nx.powi(2) + ny.powi(2))).sqrt();
|
||||
|
||||
// // normals.push(Vec3::new(nx, ny, nz));
|
||||
// }
|
||||
// for v in 1..(vs.len() - 1) {
|
||||
// indices.extend_from_slice(&[(i + v + 1) as u32, (i + v) as u32, i as u32]);
|
||||
// cd.vertices.extend_from_slice(&[i, i + v, i + v + 1]);
|
||||
// }
|
||||
// }
|
||||
let mut cells_entities = Vec::with_capacity(cells.len());
|
||||
for ((poss, indices), ch_cells) in poss
|
||||
.into_iter()
|
||||
|
Loading…
Reference in New Issue
Block a user