mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
fmt
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
|
use rand::thread_rng;
|
||||||
use std::ops::{Add, Mul, Sub};
|
use std::ops::{Add, Mul, Sub};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
use veloren_world::sim::Settlement;
|
use veloren_world::sim::Settlement;
|
||||||
use rand::thread_rng;
|
|
||||||
|
|
||||||
const W: usize = 640;
|
const W: usize = 640;
|
||||||
const H: usize = 480;
|
const H: usize = 480;
|
||||||
@ -21,7 +21,12 @@ fn main() {
|
|||||||
|
|
||||||
let seed = settlement.get_at(pos).map(|b| b.seed).unwrap_or(0);
|
let seed = settlement.get_at(pos).map(|b| b.seed).unwrap_or(0);
|
||||||
|
|
||||||
buf[j * W + i] = u32::from_le_bytes([(seed >> 0) as u8, (seed >> 8) as u8, (seed >> 16) as u8, (seed >> 24) as u8]);
|
buf[j * W + i] = u32::from_le_bytes([
|
||||||
|
(seed >> 0) as u8,
|
||||||
|
(seed >> 8) as u8,
|
||||||
|
(seed >> 16) as u8,
|
||||||
|
(seed >> 24) as u8,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
|
use noise::{NoiseFn, Seedable, SuperSimplex};
|
||||||
|
use rand::thread_rng;
|
||||||
use std::ops::{Add, Mul, Sub};
|
use std::ops::{Add, Mul, Sub};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
use veloren_world::sim::Settlement;
|
use veloren_world::sim::Settlement;
|
||||||
use rand::thread_rng;
|
|
||||||
use noise::{Seedable, NoiseFn, SuperSimplex};
|
|
||||||
|
|
||||||
const W: usize = 640;
|
const W: usize = 640;
|
||||||
const H: usize = 640;
|
const H: usize = 640;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut win =
|
let mut win = minifb::Window::new("Turb", W, H, minifb::WindowOptions::default()).unwrap();
|
||||||
minifb::Window::new("Turb", W, H, minifb::WindowOptions::default()).unwrap();
|
|
||||||
|
|
||||||
let nz_x = SuperSimplex::new().set_seed(0);
|
let nz_x = SuperSimplex::new().set_seed(0);
|
||||||
let nz_y = SuperSimplex::new().set_seed(1);
|
let nz_y = SuperSimplex::new().set_seed(1);
|
||||||
@ -24,13 +23,9 @@ fn main() {
|
|||||||
|
|
||||||
let pos = pos * 10.0;
|
let pos = pos * 10.0;
|
||||||
|
|
||||||
let pos = (0..10)
|
let pos = (0..10).fold(pos, |pos, _| pos.map(|e| e.powf(3.0) - 1.0));
|
||||||
.fold(pos, |pos, _| pos.map(|e| e.powf(3.0) - 1.0));
|
|
||||||
|
|
||||||
let val = if pos
|
let val = if pos.map(|e| e.abs() < 0.5).reduce_and() {
|
||||||
.map(|e| e.abs() < 0.5)
|
|
||||||
.reduce_and()
|
|
||||||
{
|
|
||||||
1.0f32
|
1.0f32
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
|
@ -139,7 +139,8 @@ impl<'a> Sampler for ColumnGen<'a> {
|
|||||||
let dist_to_path = match &sim_chunk.location {
|
let dist_to_path = match &sim_chunk.location {
|
||||||
Some(loc) => {
|
Some(loc) => {
|
||||||
let this_loc = &sim.locations[loc.loc_idx];
|
let this_loc = &sim.locations[loc.loc_idx];
|
||||||
this_loc.neighbours
|
this_loc
|
||||||
|
.neighbours
|
||||||
.iter()
|
.iter()
|
||||||
.map(|j| {
|
.map(|j| {
|
||||||
let other_loc = &sim.locations[*j];
|
let other_loc = &sim.locations[*j];
|
||||||
@ -159,7 +160,7 @@ impl<'a> Sampler for ColumnGen<'a> {
|
|||||||
.filter(|x| x.is_finite())
|
.filter(|x| x.is_finite())
|
||||||
.min_by(|a, b| a.partial_cmp(b).unwrap())
|
.min_by(|a, b| a.partial_cmp(b).unwrap())
|
||||||
.unwrap_or(f32::INFINITY)
|
.unwrap_or(f32::INFINITY)
|
||||||
},
|
}
|
||||||
None => f32::INFINITY,
|
None => f32::INFINITY,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -178,11 +179,14 @@ impl<'a> Sampler for ColumnGen<'a> {
|
|||||||
let rpos = wposf.map2(loc.center, |a, b| a as f32 - b as f32) / 256.0 + 0.5;
|
let rpos = wposf.map2(loc.center, |a, b| a as f32 - b as f32) / 256.0 + 0.5;
|
||||||
|
|
||||||
if rpos.map(|e| e >= 0.0 && e < 1.0).reduce_and() {
|
if rpos.map(|e| e >= 0.0 && e < 1.0).reduce_and() {
|
||||||
(loc.settlement.get_at(rpos).map(|b| b.seed % 20 + 10).unwrap_or(0)) as f32
|
(loc.settlement
|
||||||
|
.get_at(rpos)
|
||||||
|
.map(|b| b.seed % 20 + 10)
|
||||||
|
.unwrap_or(0)) as f32
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
None => 0.0,
|
None => 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
use super::Settlement;
|
||||||
|
use fxhash::FxHashSet;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
use fxhash::FxHashSet;
|
|
||||||
use super::Settlement;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Location {
|
pub struct Location {
|
||||||
|
@ -160,11 +160,7 @@ impl WorldSim {
|
|||||||
|
|
||||||
loc_clone.sort_by_key(|(_, l)| l.distance_squared(pos));
|
loc_clone.sort_by_key(|(_, l)| l.distance_squared(pos));
|
||||||
|
|
||||||
loc_clone
|
loc_clone.iter().skip(1).take(2).for_each(|(j, _)| {
|
||||||
.iter()
|
|
||||||
.skip(1)
|
|
||||||
.take(2)
|
|
||||||
.for_each(|(j, _)| {
|
|
||||||
locations[i].neighbours.insert(*j);
|
locations[i].neighbours.insert(*j);
|
||||||
locations[*j].neighbours.insert(i);
|
locations[*j].neighbours.insert(i);
|
||||||
});
|
});
|
||||||
@ -181,10 +177,8 @@ impl WorldSim {
|
|||||||
let loc = Vec2::new(i as i32 + R_COORDS[idx], j as i32 + R_COORDS[idx + 1])
|
let loc = Vec2::new(i as i32 + R_COORDS[idx], j as i32 + R_COORDS[idx + 1])
|
||||||
.map(|e| e as usize);
|
.map(|e| e as usize);
|
||||||
|
|
||||||
loc_grid[j * grid_size.x + i] = loc_grid
|
loc_grid[j * grid_size.x + i] =
|
||||||
.get(loc.y * grid_size.x + loc.x)
|
loc_grid.get(loc.y * grid_size.x + loc.x).cloned().flatten();
|
||||||
.cloned()
|
|
||||||
.flatten();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,7 +189,10 @@ impl WorldSim {
|
|||||||
for i in 0..WORLD_SIZE.x {
|
for i in 0..WORLD_SIZE.x {
|
||||||
for j in 0..WORLD_SIZE.y {
|
for j in 0..WORLD_SIZE.y {
|
||||||
let chunk_pos = Vec2::new(i as i32, j as i32);
|
let chunk_pos = Vec2::new(i as i32, j as i32);
|
||||||
let block_pos = Vec2::new(chunk_pos.x * TerrainChunkSize::SIZE.x as i32, chunk_pos.y * TerrainChunkSize::SIZE.y as i32);
|
let block_pos = Vec2::new(
|
||||||
|
chunk_pos.x * TerrainChunkSize::SIZE.x as i32,
|
||||||
|
chunk_pos.y * TerrainChunkSize::SIZE.y as i32,
|
||||||
|
);
|
||||||
let cell_pos = Vec2::new(i / cell_size, j / cell_size);
|
let cell_pos = Vec2::new(i / cell_size, j / cell_size);
|
||||||
|
|
||||||
// Find the distance to each region
|
// Find the distance to each region
|
||||||
@ -228,7 +225,10 @@ impl WorldSim {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.location
|
.location
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|l| locations[l.loc_idx].center.distance_squared(block_pos) < town_size * town_size)
|
.map(|l| {
|
||||||
|
locations[l.loc_idx].center.distance_squared(block_pos)
|
||||||
|
< town_size * town_size
|
||||||
|
})
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
if in_town {
|
if in_town {
|
||||||
self.get_mut(chunk_pos).unwrap().spawn_rate = 0.0;
|
self.get_mut(chunk_pos).unwrap().spawn_rate = 0.0;
|
||||||
@ -471,9 +471,7 @@ impl SimChunk {
|
|||||||
|
|
||||||
pub fn get_name(&self, world: &WorldSim) -> Option<String> {
|
pub fn get_name(&self, world: &WorldSim) -> Option<String> {
|
||||||
if let Some(loc) = &self.location {
|
if let Some(loc) = &self.location {
|
||||||
Some(world.locations[loc.loc_idx]
|
Some(world.locations[loc.loc_idx].name().to_string())
|
||||||
.name()
|
|
||||||
.to_string())
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -27,25 +27,16 @@ pub struct Building {
|
|||||||
enum Lot {
|
enum Lot {
|
||||||
None,
|
None,
|
||||||
One(Building),
|
One(Building),
|
||||||
Many {
|
Many { split_x: bool, lots: Vec<Lot> },
|
||||||
split_x: bool,
|
|
||||||
lots: Vec<Lot>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Lot {
|
impl Lot {
|
||||||
pub fn generate(deep: usize, depth: f32, aspect: f32, rng: &mut impl Rng) -> Self {
|
pub fn generate(deep: usize, depth: f32, aspect: f32, rng: &mut impl Rng) -> Self {
|
||||||
let depth = if deep < 3 {
|
let depth = if deep < 3 { 8.0 } else { depth };
|
||||||
8.0
|
|
||||||
} else {
|
|
||||||
depth
|
|
||||||
};
|
|
||||||
|
|
||||||
if (depth < 1.0 || deep > 6) && !(deep < 3 || deep % 2 == 1) {
|
if (depth < 1.0 || deep > 6) && !(deep < 3 || deep % 2 == 1) {
|
||||||
if rng.gen::<f32>() < 0.5 {
|
if rng.gen::<f32>() < 0.5 {
|
||||||
Lot::One(Building {
|
Lot::One(Building { seed: rng.gen() })
|
||||||
seed: rng.gen(),
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
Lot::None
|
Lot::None
|
||||||
}
|
}
|
||||||
@ -76,11 +67,13 @@ impl Lot {
|
|||||||
pub fn get_at(&self, pos: Vec2<f32>) -> Option<&Building> {
|
pub fn get_at(&self, pos: Vec2<f32>) -> Option<&Building> {
|
||||||
match self {
|
match self {
|
||||||
Lot::None => None,
|
Lot::None => None,
|
||||||
Lot::One(building) => if pos.map(|e| e > 0.1 && e < 0.9).reduce_and() {
|
Lot::One(building) => {
|
||||||
|
if pos.map(|e| e > 0.1 && e < 0.9).reduce_and() {
|
||||||
Some(building)
|
Some(building)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
}
|
||||||
|
}
|
||||||
Lot::Many { split_x, lots } => {
|
Lot::Many { split_x, lots } => {
|
||||||
let split_dim = if *split_x { pos.x } else { pos.y };
|
let split_dim = if *split_x { pos.x } else { pos.y };
|
||||||
let idx = (split_dim * lots.len() as f32).floor() as usize;
|
let idx = (split_dim * lots.len() as f32).floor() as usize;
|
||||||
@ -89,7 +82,7 @@ impl Lot {
|
|||||||
} else {
|
} else {
|
||||||
Vec2::new(pos.x, (pos.y * lots.len() as f32).fract())
|
Vec2::new(pos.x, (pos.y * lots.len() as f32).fract())
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user