mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-14 03:18:41 -06:00
use force for plr
This commit is contained in:
parent
f84fe5d022
commit
8d673ed82f
|
@ -1,334 +1,342 @@
|
||||||
use bracket_noise::prelude::*;
|
use bracket_noise::prelude::*;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use glam::{IVec3, ivec3, Vec3Swizzles, IVec2};
|
use glam::{IVec3, ivec3, Vec3Swizzles, IVec2};
|
||||||
use rand_xoshiro::Xoshiro256StarStar;
|
use rand_xoshiro::Xoshiro256StarStar;
|
||||||
use crate::{
|
use crate::{
|
||||||
chunk::{BlockData, CHUNK_SIZE},
|
chunk::{BlockData, CHUNK_SIZE},
|
||||||
block::Block,
|
block::Block,
|
||||||
queue::QueuedBlock,
|
queue::QueuedBlock,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn mountain_ramp(mut x: f32) -> f32 {
|
fn mountain_ramp(mut x: f32) -> f32 {
|
||||||
x *= 2.0;
|
x *= 2.0;
|
||||||
if x < 0.4 {
|
if x < 0.4 {
|
||||||
0.5 * x
|
0.5 * x
|
||||||
} else if x < 0.55 {
|
} else if x < 0.55 {
|
||||||
4. * (x - 0.4) + 0.2
|
4. * (x - 0.4) + 0.2
|
||||||
} else {
|
} else {
|
||||||
0.4444 * (x - 0.55) + 0.8
|
0.4444 * (x - 0.55) + 0.8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_height(height: i32, chunk_position: IVec3) -> usize {
|
fn local_height(height: i32, chunk_position: IVec3) -> usize {
|
||||||
let offset = chunk_position * CHUNK_SIZE as i32;
|
let offset = chunk_position * CHUNK_SIZE as i32;
|
||||||
(height - offset.y).clamp(0, CHUNK_SIZE as i32) as usize
|
(height - offset.y).clamp(0, CHUNK_SIZE as i32) as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
fn local_y_position(height: i32, chunk_position: IVec3) -> Option<usize> {
|
fn local_y_position(height: i32, chunk_position: IVec3) -> Option<usize> {
|
||||||
let offset = chunk_position * CHUNK_SIZE as i32;
|
let offset = chunk_position * CHUNK_SIZE as i32;
|
||||||
let position = height - offset.y;
|
let position = height - offset.y;
|
||||||
(0..CHUNK_SIZE as i32).contains(&position).then_some(position as usize)
|
(0..CHUNK_SIZE as i32).contains(&position).then_some(position as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn generate_world(chunk_position: IVec3, seed: u64) -> (BlockData, Vec<QueuedBlock>) {
|
pub fn generate_world(chunk_position: IVec3, seed: u64) -> (BlockData, Vec<QueuedBlock>) {
|
||||||
let offset = chunk_position * CHUNK_SIZE as i32;
|
let offset = chunk_position * CHUNK_SIZE as i32;
|
||||||
let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]);
|
let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]);
|
||||||
let mut queue = Vec::with_capacity(0);
|
let mut queue = Vec::with_capacity(0);
|
||||||
|
|
||||||
let mut smart_place = |blocks: &mut BlockData, position: IVec3, block: Block| {
|
let mut smart_place = |blocks: &mut BlockData, position: IVec3, block: Block| {
|
||||||
if position.to_array().iter().any(|&x| !(0..CHUNK_SIZE).contains(&(x as usize))) {
|
if position.to_array().iter().any(|&x| !(0..CHUNK_SIZE).contains(&(x as usize))) {
|
||||||
let event_pos = offset + position;
|
let event_pos = offset + position;
|
||||||
queue.retain(|block: &QueuedBlock| {
|
queue.retain(|block: &QueuedBlock| {
|
||||||
block.position != event_pos
|
block.position != event_pos
|
||||||
});
|
});
|
||||||
queue.push(QueuedBlock {
|
queue.push(QueuedBlock {
|
||||||
position: event_pos,
|
position: event_pos,
|
||||||
block_type: block,
|
block_type: block,
|
||||||
soft: true
|
soft: true
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
blocks[position.x as usize][position.y as usize][position.z as usize] = block;
|
blocks[position.x as usize][position.y as usize][position.z as usize] = block;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut height_noise = FastNoise::seeded(seed);
|
//STICK
|
||||||
height_noise.set_fractal_type(FractalType::FBM);
|
if chunk_position.x == 0 && chunk_position.y == 5 {
|
||||||
height_noise.set_fractal_octaves(4);
|
for z in 0..CHUNK_SIZE {
|
||||||
height_noise.set_frequency(0.003);
|
blocks[0][0][z] = Block::Stone;
|
||||||
|
}
|
||||||
let mut elevation_noise = FastNoise::seeded(seed.rotate_left(1));
|
}
|
||||||
elevation_noise.set_fractal_type(FractalType::FBM);
|
//
|
||||||
elevation_noise.set_fractal_octaves(1);
|
|
||||||
elevation_noise.set_frequency(0.001);
|
let mut height_noise = FastNoise::seeded(seed);
|
||||||
|
height_noise.set_fractal_type(FractalType::FBM);
|
||||||
let mut cave_noise_a = FastNoise::seeded(seed.rotate_left(2));
|
height_noise.set_fractal_octaves(4);
|
||||||
cave_noise_a.set_fractal_type(FractalType::FBM);
|
height_noise.set_frequency(0.003);
|
||||||
cave_noise_a.set_fractal_octaves(2);
|
|
||||||
cave_noise_a.set_frequency(0.01);
|
let mut elevation_noise = FastNoise::seeded(seed.rotate_left(1));
|
||||||
|
elevation_noise.set_fractal_type(FractalType::FBM);
|
||||||
let mut cave_noise_b = FastNoise::seeded(seed.rotate_left(3));
|
elevation_noise.set_fractal_octaves(1);
|
||||||
cave_noise_b.set_fractal_type(FractalType::FBM);
|
elevation_noise.set_frequency(0.001);
|
||||||
cave_noise_b.set_fractal_octaves(3);
|
|
||||||
cave_noise_b.set_frequency(0.015);
|
let mut cave_noise_a = FastNoise::seeded(seed.rotate_left(2));
|
||||||
|
cave_noise_a.set_fractal_type(FractalType::FBM);
|
||||||
let mut cave_noise_holes = FastNoise::seeded(seed.rotate_left(4));
|
cave_noise_a.set_fractal_octaves(2);
|
||||||
cave_noise_holes.set_fractal_type(FractalType::FBM);
|
cave_noise_a.set_frequency(0.01);
|
||||||
cave_noise_holes.set_fractal_octaves(2);
|
|
||||||
cave_noise_holes.set_frequency(0.005);
|
let mut cave_noise_b = FastNoise::seeded(seed.rotate_left(3));
|
||||||
|
cave_noise_b.set_fractal_type(FractalType::FBM);
|
||||||
let mut ravine_nose_line = FastNoise::seeded(seed.rotate_left(5));
|
cave_noise_b.set_fractal_octaves(3);
|
||||||
ravine_nose_line.set_fractal_type(FractalType::Billow);
|
cave_noise_b.set_frequency(0.015);
|
||||||
ravine_nose_line.set_fractal_octaves(2);
|
|
||||||
ravine_nose_line.set_frequency(0.005);
|
let mut cave_noise_holes = FastNoise::seeded(seed.rotate_left(4));
|
||||||
|
cave_noise_holes.set_fractal_type(FractalType::FBM);
|
||||||
let mut ravine_noise_location = FastNoise::seeded(seed.rotate_left(6));
|
cave_noise_holes.set_fractal_octaves(2);
|
||||||
ravine_noise_location.set_fractal_type(FractalType::FBM);
|
cave_noise_holes.set_frequency(0.005);
|
||||||
ravine_noise_location.set_fractal_octaves(1);
|
|
||||||
ravine_noise_location.set_frequency(0.005);
|
let mut ravine_nose_line = FastNoise::seeded(seed.rotate_left(5));
|
||||||
|
ravine_nose_line.set_fractal_type(FractalType::Billow);
|
||||||
let mut river_noise = FastNoise::seeded(seed.rotate_left(7));
|
ravine_nose_line.set_fractal_octaves(2);
|
||||||
river_noise.set_fractal_type(FractalType::Billow);
|
ravine_nose_line.set_frequency(0.005);
|
||||||
river_noise.set_fractal_octaves(2);
|
|
||||||
river_noise.set_frequency(0.5 * 0.005);
|
let mut ravine_noise_location = FastNoise::seeded(seed.rotate_left(6));
|
||||||
|
ravine_noise_location.set_fractal_type(FractalType::FBM);
|
||||||
let mut rng = Xoshiro256StarStar::seed_from_u64(
|
ravine_noise_location.set_fractal_octaves(1);
|
||||||
seed
|
ravine_noise_location.set_frequency(0.005);
|
||||||
^ (chunk_position.x as u32 as u64)
|
|
||||||
^ ((chunk_position.z as u32 as u64) << 32)
|
let mut river_noise = FastNoise::seeded(seed.rotate_left(7));
|
||||||
);
|
river_noise.set_fractal_type(FractalType::Billow);
|
||||||
let rng_map_a: [[f32; CHUNK_SIZE]; CHUNK_SIZE] = rng.gen();
|
river_noise.set_fractal_octaves(2);
|
||||||
let rng_map_b: [[f32; CHUNK_SIZE]; CHUNK_SIZE] = rng.gen();
|
river_noise.set_frequency(0.5 * 0.005);
|
||||||
|
|
||||||
//Generate height map
|
let mut rng = Xoshiro256StarStar::seed_from_u64(
|
||||||
let mut within_heightmap = false;
|
seed
|
||||||
let mut deco_heightmap = [[None; CHUNK_SIZE]; CHUNK_SIZE];
|
^ (chunk_position.x as u32 as u64)
|
||||||
|
^ ((chunk_position.z as u32 as u64) << 32)
|
||||||
for x in 0..CHUNK_SIZE {
|
);
|
||||||
for z in 0..CHUNK_SIZE {
|
let rng_map_a: [[f32; CHUNK_SIZE]; CHUNK_SIZE] = rng.gen();
|
||||||
let (noise_x, noise_y) = ((offset.x + x as i32) as f32, (offset.z + z as i32) as f32);
|
let rng_map_b: [[f32; CHUNK_SIZE]; CHUNK_SIZE] = rng.gen();
|
||||||
//sample noises (that are needed right now)
|
|
||||||
let raw_heightmap_value = height_noise.get_noise(noise_x, noise_y);
|
//Generate height map
|
||||||
let raw_elevation_value = elevation_noise.get_noise(noise_x, noise_y);
|
let mut within_heightmap = false;
|
||||||
let raw_ravine_location_value = ravine_noise_location.get_noise(noise_x, noise_y);
|
let mut deco_heightmap = [[None; CHUNK_SIZE]; CHUNK_SIZE];
|
||||||
//compute height
|
|
||||||
let mut is_surface = true;
|
for x in 0..CHUNK_SIZE {
|
||||||
let mut river_fill_height = None;
|
for z in 0..CHUNK_SIZE {
|
||||||
let height = {
|
let (noise_x, noise_y) = ((offset.x + x as i32) as f32, (offset.z + z as i32) as f32);
|
||||||
let local_elevation = raw_elevation_value.powi(4).sqrt();
|
//sample noises (that are needed right now)
|
||||||
let mut height = (mountain_ramp(raw_heightmap_value) * local_elevation * 100.) as i32;
|
let raw_heightmap_value = height_noise.get_noise(noise_x, noise_y);
|
||||||
//Flatten valleys
|
let raw_elevation_value = elevation_noise.get_noise(noise_x, noise_y);
|
||||||
if height < 0 {
|
let raw_ravine_location_value = ravine_noise_location.get_noise(noise_x, noise_y);
|
||||||
height /= 2;
|
//compute height
|
||||||
}
|
let mut is_surface = true;
|
||||||
//Generate rivers
|
let mut river_fill_height = None;
|
||||||
{
|
let height = {
|
||||||
let river_width = (height as f32 / -5.).clamp(0.5, 1.);
|
let local_elevation = raw_elevation_value.powi(4).sqrt();
|
||||||
let river_value = river_noise.get_noise(noise_x, noise_y);
|
let mut height = (mountain_ramp(raw_heightmap_value) * local_elevation * 100.) as i32;
|
||||||
if ((-0.00625 * river_width)..(0.00625 * river_width)).contains(&(river_value.powi(2))) {
|
//Flatten valleys
|
||||||
is_surface = false;
|
if height < 0 {
|
||||||
river_fill_height = Some(height - 1);
|
height /= 2;
|
||||||
//river_fill_height = Some(-3);
|
}
|
||||||
height -= (river_width * 15. * ((0.00625 * river_width) - river_value.powi(2)) * (1. / (0.00625 * river_width))).round() as i32;
|
//Generate rivers
|
||||||
}
|
{
|
||||||
}
|
let river_width = (height as f32 / -5.).clamp(0.5, 1.);
|
||||||
//Generate ravines
|
let river_value = river_noise.get_noise(noise_x, noise_y);
|
||||||
if height < 0 && raw_ravine_location_value > 0.4 {
|
if ((-0.00625 * river_width)..(0.00625 * river_width)).contains(&(river_value.powi(2))) {
|
||||||
let raw_ravine_value = ravine_nose_line.get_noise(noise_x, noise_y);
|
is_surface = false;
|
||||||
if (-0.0125..0.0125).contains(&(raw_ravine_value.powi(2))) {
|
river_fill_height = Some(height - 1);
|
||||||
is_surface = false;
|
//river_fill_height = Some(-3);
|
||||||
height -= (100. * (0.0125 - raw_ravine_value.powi(2)) * (1. / 0.0125)).round() as i32;
|
height -= (river_width * 15. * ((0.00625 * river_width) - river_value.powi(2)) * (1. / (0.00625 * river_width))).round() as i32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
height
|
//Generate ravines
|
||||||
};
|
if height < 0 && raw_ravine_location_value > 0.4 {
|
||||||
//add to heightmap
|
let raw_ravine_value = ravine_nose_line.get_noise(noise_x, noise_y);
|
||||||
if is_surface {
|
if (-0.0125..0.0125).contains(&(raw_ravine_value.powi(2))) {
|
||||||
deco_heightmap[x][z] = Some(height);
|
is_surface = false;
|
||||||
//place dirt
|
height -= (100. * (0.0125 - raw_ravine_value.powi(2)) * (1. / 0.0125)).round() as i32;
|
||||||
for y in 0..local_height(height, chunk_position) {
|
}
|
||||||
blocks[x][y][z] = Block::Dirt;
|
}
|
||||||
within_heightmap = true;
|
height
|
||||||
}
|
};
|
||||||
//place stone
|
//add to heightmap
|
||||||
for y in 0..local_height(height - 5 - (raw_heightmap_value * 5.) as i32, chunk_position) {
|
if is_surface {
|
||||||
blocks[x][y][z] = Block::Stone;
|
deco_heightmap[x][z] = Some(height);
|
||||||
within_heightmap = true;
|
//place dirt
|
||||||
}
|
for y in 0..local_height(height, chunk_position) {
|
||||||
//place grass
|
blocks[x][y][z] = Block::Dirt;
|
||||||
if let Some(y) = local_y_position(height, chunk_position) {
|
within_heightmap = true;
|
||||||
blocks[x][y][z] = Block::Grass;
|
}
|
||||||
within_heightmap = true;
|
//place stone
|
||||||
}
|
for y in 0..local_height(height - 5 - (raw_heightmap_value * 5.) as i32, chunk_position) {
|
||||||
} else if let Some(river_fill_height) = river_fill_height {
|
blocks[x][y][z] = Block::Stone;
|
||||||
//Place water
|
within_heightmap = true;
|
||||||
for y in 0..local_height(river_fill_height, chunk_position) {
|
}
|
||||||
blocks[x][y][z] = Block::Water;
|
//place grass
|
||||||
within_heightmap = true;
|
if let Some(y) = local_y_position(height, chunk_position) {
|
||||||
}
|
blocks[x][y][z] = Block::Grass;
|
||||||
//Place stone
|
within_heightmap = true;
|
||||||
for y in 0..local_height(height, chunk_position) {
|
}
|
||||||
blocks[x][y][z] = Block::Stone;
|
} else if let Some(river_fill_height) = river_fill_height {
|
||||||
within_heightmap = true;
|
//Place water
|
||||||
}
|
for y in 0..local_height(river_fill_height, chunk_position) {
|
||||||
//Place dirt
|
blocks[x][y][z] = Block::Water;
|
||||||
if let Some(y) = local_y_position(height, chunk_position) {
|
within_heightmap = true;
|
||||||
blocks[x][y][z] = Block::Dirt;
|
}
|
||||||
within_heightmap = true;
|
//Place stone
|
||||||
}
|
for y in 0..local_height(height, chunk_position) {
|
||||||
} else {
|
blocks[x][y][z] = Block::Stone;
|
||||||
//Place stone
|
within_heightmap = true;
|
||||||
for y in 0..local_height(height, chunk_position) {
|
}
|
||||||
blocks[x][y][z] = Block::Stone;
|
//Place dirt
|
||||||
within_heightmap = true;
|
if let Some(y) = local_y_position(height, chunk_position) {
|
||||||
}
|
blocks[x][y][z] = Block::Dirt;
|
||||||
}
|
within_heightmap = true;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
//Place stone
|
||||||
//Carve out caves
|
for y in 0..local_height(height, chunk_position) {
|
||||||
if within_heightmap {
|
blocks[x][y][z] = Block::Stone;
|
||||||
for z in 0..CHUNK_SIZE {
|
within_heightmap = true;
|
||||||
for y in 0..CHUNK_SIZE {
|
}
|
||||||
for x in 0..CHUNK_SIZE {
|
}
|
||||||
if blocks[x][y][z] != Block::Stone { continue }
|
}
|
||||||
|
}
|
||||||
let cave_size = ((offset.y + y as i32) as f32 / -100.).clamp(0., 1.);
|
|
||||||
let inv_cave_size = 1. - cave_size;
|
//Carve out caves
|
||||||
if cave_size < 0.1 { continue }
|
if within_heightmap {
|
||||||
|
for z in 0..CHUNK_SIZE {
|
||||||
let position = ivec3(x as i32, y as i32, z as i32) + offset;
|
for y in 0..CHUNK_SIZE {
|
||||||
|
for x in 0..CHUNK_SIZE {
|
||||||
let is_cave = || {
|
if blocks[x][y][z] != Block::Stone { continue }
|
||||||
let raw_cavemap_value_a = cave_noise_a.get_noise3d(position.x as f32, position.y as f32, position.z as f32);
|
|
||||||
let raw_cavemap_value_b = cave_noise_b.get_noise3d(position.x as f32, position.y as f32, position.z as f32);
|
let cave_size = ((offset.y + y as i32) as f32 / -100.).clamp(0., 1.);
|
||||||
((cave_size * -0.15)..=(cave_size * 0.15)).contains(&raw_cavemap_value_a) &&
|
let inv_cave_size = 1. - cave_size;
|
||||||
((cave_size * -0.15)..=(cave_size * 0.15)).contains(&raw_cavemap_value_b)
|
if cave_size < 0.1 { continue }
|
||||||
};
|
|
||||||
let is_hole_cave = || {
|
let position = ivec3(x as i32, y as i32, z as i32) + offset;
|
||||||
let raw_cavemap_value_holes = cave_noise_holes.get_noise3d(position.x as f32, position.y as f32, position.z as f32);
|
|
||||||
((0.9 + (0.1 * inv_cave_size))..=1.0).contains(&raw_cavemap_value_holes.abs())
|
let is_cave = || {
|
||||||
};
|
let raw_cavemap_value_a = cave_noise_a.get_noise3d(position.x as f32, position.y as f32, position.z as f32);
|
||||||
|
let raw_cavemap_value_b = cave_noise_b.get_noise3d(position.x as f32, position.y as f32, position.z as f32);
|
||||||
if is_cave() || is_hole_cave() {
|
((cave_size * -0.15)..=(cave_size * 0.15)).contains(&raw_cavemap_value_a) &&
|
||||||
blocks[x][y][z] = Block::Air;
|
((cave_size * -0.15)..=(cave_size * 0.15)).contains(&raw_cavemap_value_b)
|
||||||
if deco_heightmap[x][z] == Some(y as i32 + offset.y) {
|
};
|
||||||
deco_heightmap[x][z] = None
|
let is_hole_cave = || {
|
||||||
}
|
let raw_cavemap_value_holes = cave_noise_holes.get_noise3d(position.x as f32, position.y as f32, position.z as f32);
|
||||||
}
|
((0.9 + (0.1 * inv_cave_size))..=1.0).contains(&raw_cavemap_value_holes.abs())
|
||||||
}
|
};
|
||||||
}
|
|
||||||
}
|
if is_cave() || is_hole_cave() {
|
||||||
}
|
blocks[x][y][z] = Block::Air;
|
||||||
|
if deco_heightmap[x][z] == Some(y as i32 + offset.y) {
|
||||||
//Add decorations
|
deco_heightmap[x][z] = None
|
||||||
for x in 0..CHUNK_SIZE {
|
}
|
||||||
for z in 0..CHUNK_SIZE {
|
}
|
||||||
//get height
|
}
|
||||||
let Some(height) = deco_heightmap[x][z] else { continue };
|
}
|
||||||
//check for air
|
}
|
||||||
// if blocks[x][local_y][z] == Block::Air {
|
}
|
||||||
// continue
|
|
||||||
// }
|
//Add decorations
|
||||||
//place tall grass
|
for x in 0..CHUNK_SIZE {
|
||||||
if rng_map_a[x][z] < 0.03 {
|
for z in 0..CHUNK_SIZE {
|
||||||
if let Some(y) = local_y_position(height + 1, chunk_position) {
|
//get height
|
||||||
blocks[x][y][z] = Block::TallGrass;
|
let Some(height) = deco_heightmap[x][z] else { continue };
|
||||||
}
|
//check for air
|
||||||
}
|
// if blocks[x][local_y][z] == Block::Air {
|
||||||
//place trees!
|
// continue
|
||||||
if rng_map_a[x][z] < 0.001 {
|
// }
|
||||||
//Replace grass with dirt under the tree
|
//place tall grass
|
||||||
if let Some(y) = local_y_position(height, chunk_position) {
|
if rng_map_a[x][z] < 0.03 {
|
||||||
blocks[x][y][z] = Block::Dirt;
|
if let Some(y) = local_y_position(height + 1, chunk_position) {
|
||||||
}
|
blocks[x][y][z] = Block::TallGrass;
|
||||||
|
}
|
||||||
//Place wood (no smart_place needed here!)
|
}
|
||||||
let tree_height = 4 + (rng_map_b[x][z] * 3.).round() as i32;
|
//place trees!
|
||||||
for tree_y in 0..tree_height {
|
if rng_map_a[x][z] < 0.001 {
|
||||||
if let Some(y) = local_y_position(height + 1 + tree_y, chunk_position) {
|
//Replace grass with dirt under the tree
|
||||||
blocks[x][y][z] = Block::Wood;
|
if let Some(y) = local_y_position(height, chunk_position) {
|
||||||
}
|
blocks[x][y][z] = Block::Dirt;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tree_height = 4 + (rng_map_b[x][z] * 3.).round() as i32;
|
//Place wood (no smart_place needed here!)
|
||||||
|
let tree_height = 4 + (rng_map_b[x][z] * 3.).round() as i32;
|
||||||
//Place leaf blocks
|
for tree_y in 0..tree_height {
|
||||||
if let Some(y) = local_y_position(height + 1, chunk_position) {
|
if let Some(y) = local_y_position(height + 1 + tree_y, chunk_position) {
|
||||||
let tree_pos = ivec3(x as i32, y as i32, z as i32);
|
blocks[x][y][z] = Block::Wood;
|
||||||
// Place wood (smart_place)
|
}
|
||||||
// for tree_y in 0..tree_height {
|
}
|
||||||
// smart_place(&mut blocks, tree_pos + tree_y * IVec3::Y, Block::Wood);
|
|
||||||
// }
|
let tree_height = 4 + (rng_map_b[x][z] * 3.).round() as i32;
|
||||||
// Part that wraps around the tree
|
|
||||||
{
|
//Place leaf blocks
|
||||||
let tree_leaf_height = tree_height - 3;
|
if let Some(y) = local_y_position(height + 1, chunk_position) {
|
||||||
let leaf_width = 2;
|
let tree_pos = ivec3(x as i32, y as i32, z as i32);
|
||||||
for tree_y in tree_leaf_height..tree_height {
|
// Place wood (smart_place)
|
||||||
for tree_x in (-leaf_width)..=leaf_width {
|
// for tree_y in 0..tree_height {
|
||||||
for tree_z in (-leaf_width)..=leaf_width {
|
// smart_place(&mut blocks, tree_pos + tree_y * IVec3::Y, Block::Wood);
|
||||||
let tree_offset = ivec3(tree_x, tree_y, tree_z);
|
// }
|
||||||
if tree_offset.xz() == IVec2::ZERO { continue }
|
// Part that wraps around the tree
|
||||||
smart_place(&mut blocks, tree_pos + tree_offset, Block::Leaf);
|
{
|
||||||
}
|
let tree_leaf_height = tree_height - 3;
|
||||||
}
|
let leaf_width = 2;
|
||||||
}
|
for tree_y in tree_leaf_height..tree_height {
|
||||||
}
|
for tree_x in (-leaf_width)..=leaf_width {
|
||||||
//part above the tree
|
for tree_z in (-leaf_width)..=leaf_width {
|
||||||
{
|
let tree_offset = ivec3(tree_x, tree_y, tree_z);
|
||||||
let leaf_above_height = 2;
|
if tree_offset.xz() == IVec2::ZERO { continue }
|
||||||
let leaf_width = 1;
|
smart_place(&mut blocks, tree_pos + tree_offset, Block::Leaf);
|
||||||
for tree_y in tree_height..(tree_height + leaf_above_height) {
|
}
|
||||||
for tree_x in (-leaf_width)..=leaf_width {
|
}
|
||||||
for tree_z in (-leaf_width)..=leaf_width {
|
}
|
||||||
let tree_offset = ivec3(tree_x, tree_y, tree_z);
|
}
|
||||||
smart_place(&mut blocks, tree_pos + tree_offset, Block::Leaf);
|
//part above the tree
|
||||||
}
|
{
|
||||||
}
|
let leaf_above_height = 2;
|
||||||
}
|
let leaf_width = 1;
|
||||||
}
|
for tree_y in tree_height..(tree_height + leaf_above_height) {
|
||||||
}
|
for tree_x in (-leaf_width)..=leaf_width {
|
||||||
}
|
for tree_z in (-leaf_width)..=leaf_width {
|
||||||
}
|
let tree_offset = ivec3(tree_x, tree_y, tree_z);
|
||||||
}
|
smart_place(&mut blocks, tree_pos + tree_offset, Block::Leaf);
|
||||||
|
}
|
||||||
(blocks, queue)
|
}
|
||||||
|
}
|
||||||
// let mut cave_noise = FastNoise::seeded(seed);
|
}
|
||||||
// cave_noise.set_fractal_type(FractalType::FBM);
|
}
|
||||||
// cave_noise.set_frequency(0.1);
|
}
|
||||||
|
}
|
||||||
// let mut dirt_noise = FastNoise::seeded(seed.rotate_left(1));
|
}
|
||||||
// dirt_noise.set_fractal_type(FractalType::FBM);
|
|
||||||
// dirt_noise.set_frequency(0.1);
|
(blocks, queue)
|
||||||
|
|
||||||
//
|
// let mut cave_noise = FastNoise::seeded(seed);
|
||||||
|
// cave_noise.set_fractal_type(FractalType::FBM);
|
||||||
// if chunk_position.y >= 0 {
|
// cave_noise.set_frequency(0.1);
|
||||||
// if chunk_position.y == 0 {
|
|
||||||
// for x in 0..CHUNK_SIZE {
|
// let mut dirt_noise = FastNoise::seeded(seed.rotate_left(1));
|
||||||
// for z in 0..CHUNK_SIZE {
|
// dirt_noise.set_fractal_type(FractalType::FBM);
|
||||||
// blocks[x][0][z] = Block::Dirt;
|
// dirt_noise.set_frequency(0.1);
|
||||||
// blocks[x][1][z] = Block::Grass;
|
|
||||||
// }
|
//
|
||||||
// }
|
|
||||||
// }
|
// if chunk_position.y >= 0 {
|
||||||
// } else {
|
// if chunk_position.y == 0 {
|
||||||
// for x in 0..CHUNK_SIZE {
|
// for x in 0..CHUNK_SIZE {
|
||||||
// for y in 0..CHUNK_SIZE {
|
// for z in 0..CHUNK_SIZE {
|
||||||
// for z in 0..CHUNK_SIZE {
|
// blocks[x][0][z] = Block::Dirt;
|
||||||
// let position = ivec3(x as i32, y as i32, z as i32) + offset;
|
// blocks[x][1][z] = Block::Grass;
|
||||||
// let v_cave_noise = cave_noise.get_noise3d(position.x as f32, position.y as f32, position.z as f32) * (-position.y as f32 - 10.0).clamp(0., 1.);
|
// }
|
||||||
// let v_dirt_noise = dirt_noise.get_noise3d(position.x as f32, position.y as f32, position.z as f32) * (-position.y as f32).clamp(0., 1.);
|
// }
|
||||||
// if v_cave_noise > 0.5 {
|
// }
|
||||||
// blocks[x][y][z] = Block::Stone;
|
// } else {
|
||||||
// } else if v_dirt_noise > 0.5 {
|
// for x in 0..CHUNK_SIZE {
|
||||||
// blocks[x][y][z] = Block::Dirt;
|
// for y in 0..CHUNK_SIZE {
|
||||||
// }
|
// for z in 0..CHUNK_SIZE {
|
||||||
// }
|
// let position = ivec3(x as i32, y as i32, z as i32) + offset;
|
||||||
// }
|
// let v_cave_noise = cave_noise.get_noise3d(position.x as f32, position.y as f32, position.z as f32) * (-position.y as f32 - 10.0).clamp(0., 1.);
|
||||||
// }
|
// let v_dirt_noise = dirt_noise.get_noise3d(position.x as f32, position.y as f32, position.z as f32) * (-position.y as f32).clamp(0., 1.);
|
||||||
// }
|
// if v_cave_noise > 0.5 {
|
||||||
// blocks
|
// blocks[x][y][z] = Block::Stone;
|
||||||
|
// } else if v_dirt_noise > 0.5 {
|
||||||
}
|
// blocks[x][y][z] = Block::Dirt;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// blocks
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use glam::{EulerRot, Mat4, Quat, Vec2, Vec2Swizzles, Vec3, Vec3Swizzles};
|
use glam::{vec3, EulerRot, Mat4, Quat, Vec2, Vec2Swizzles, Vec3, Vec3Swizzles};
|
||||||
use shipyard::{track, Component, Get, IntoIter, IntoWithId, IntoWorkload, Unique, UniqueView, View, ViewMut, Workload};
|
use shipyard::{track, Component, Get, IntoIter, IntoWithId, IntoWorkload, Unique, UniqueView, View, ViewMut, Workload};
|
||||||
use winit::keyboard::KeyCode;
|
use winit::keyboard::KeyCode;
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
@ -77,17 +77,23 @@ fn update_movement(
|
||||||
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation_norm, translation);
|
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation_norm, translation);
|
||||||
},
|
},
|
||||||
PlayerControllerType::FpsCtl => {
|
PlayerControllerType::FpsCtl => {
|
||||||
let actor = (&mut actors).get(id).unwrap();
|
let mut actor = (&mut actors).get(id).unwrap();
|
||||||
|
|
||||||
let euler = rotation_norm.to_euler(EulerRot::YZX);
|
let euler = rotation_norm.to_euler(EulerRot::YZX);
|
||||||
let right = Vec2::from_angle(-euler.0).extend(0.).xzy();
|
let right = Vec2::from_angle(-euler.0).extend(0.).xzy();
|
||||||
let forward = Vec2::from_angle(-(euler.0 + PI/2.)).extend(0.).xzy();
|
let forward = Vec2::from_angle(-(euler.0 + PI/2.)).extend(0.).xzy();
|
||||||
|
|
||||||
translation += forward * movement.z * ctl.speed * dt.0.as_secs_f32();
|
actor.apply_force(ctl.speed * (
|
||||||
translation += right * movement.x * ctl.speed * dt.0.as_secs_f32();
|
(forward * movement.z) +
|
||||||
translation += Vec3::Y * movement.y * ctl.speed * dt.0.as_secs_f32();
|
(right * movement.x) +
|
||||||
|
(Vec3::Y * movement.y)
|
||||||
|
));
|
||||||
|
|
||||||
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation_norm, translation);
|
// translation += forward * movement.z * ctl.speed * dt.0.as_secs_f32();
|
||||||
|
// translation += right * movement.x * ctl.speed * dt.0.as_secs_f32();
|
||||||
|
// translation += Vec3::Y * movement.y * ctl.speed * dt.0.as_secs_f32();
|
||||||
|
|
||||||
|
// transform.0 = Mat4::from_scale_rotation_translation(scale, rotation_norm, translation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue