Former-commit-id: b43b7192f7a2dd71da26182ca0c74449867381f3
This commit is contained in:
Joshua Barretto 2019-05-09 18:58:16 +01:00
parent 3b44bda43c
commit 54cc9e137a
17 changed files with 144 additions and 117 deletions

View File

@ -4,7 +4,10 @@ pub mod error;
pub mod input; pub mod input;
// Reexports // Reexports
pub use crate::{error::Error, input::{Input, InputEvent}}; pub use crate::{
error::Error,
input::{Input, InputEvent},
};
pub use specs::join::Join; pub use specs::join::Join;
pub use specs::Entity as EcsEntity; pub use specs::Entity as EcsEntity;
@ -196,7 +199,11 @@ impl Client {
// Remove chunks that are too far from the player // Remove chunks that are too far from the player
let mut chunks_to_remove = Vec::new(); let mut chunks_to_remove = Vec::new();
self.state.terrain().iter().for_each(|(key, _)| { self.state.terrain().iter().for_each(|(key, _)| {
if (Vec2::from(chunk_pos) - Vec2::from(key)).map(|e: i32| e.abs()).reduce_max() > 6 { if (Vec2::from(chunk_pos) - Vec2::from(key))
.map(|e: i32| e.abs())
.reduce_max()
> 6
{
chunks_to_remove.push(key); chunks_to_remove.push(key);
} }
}); });

View File

@ -203,11 +203,7 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
*/ */
// Assemble into packet // Assemble into packet
let mut packet_bytes = msg_bytes let mut packet_bytes = msg_bytes.len().to_le_bytes().as_ref().to_vec();
.len()
.to_le_bytes()
.as_ref()
.to_vec();
packet_bytes.push(msg_bytes.iter().fold(0, |a, x| a ^ *x)); packet_bytes.push(msg_bytes.iter().fold(0, |a, x| a ^ *x));
packet_bytes.append(&mut msg_bytes); packet_bytes.append(&mut msg_bytes);
@ -270,25 +266,32 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
for _ in 0..100 { for _ in 0..100 {
match incoming_buf.get(0..9) { match incoming_buf.get(0..9) {
Some(len_bytes) => { Some(len_bytes) => {
let len = usize::from_le_bytes(<[u8; 8]>::try_from(&len_bytes[0..8]).unwrap()); // Can't fail let len = usize::from_le_bytes(
<[u8; 8]>::try_from(&len_bytes[0..8]).unwrap(),
); // Can't fail
if len > MAX_MSG_SIZE { if len > MAX_MSG_SIZE {
recv_tx.send(Err(Error::InvalidMessage)).unwrap(); recv_tx.send(Err(Error::InvalidMessage)).unwrap();
break 'work; break 'work;
} else if incoming_buf.len() >= len + 9 { } else if incoming_buf.len() >= len + 9 {
let checksum_found = incoming_buf[9..len + 9].iter().fold(0, |a, x| a ^ *x); let checksum_found =
incoming_buf[9..len + 9].iter().fold(0, |a, x| a ^ *x);
let checksum_expected = len_bytes[8]; let checksum_expected = len_bytes[8];
assert_eq!(checksum_found, checksum_expected, "Message checksum failed!"); assert_eq!(
checksum_found, checksum_expected,
"Message checksum failed!"
);
let msg_bytes = lz4_compress::decompress(&incoming_buf[9..len + 9]).unwrap(); let msg_bytes =
lz4_compress::decompress(&incoming_buf[9..len + 9]).unwrap();
match bincode::deserialize(&msg_bytes) { match bincode::deserialize(&msg_bytes) {
Ok(msg) => recv_tx.send(Ok(msg)).unwrap(), Ok(msg) => recv_tx.send(Ok(msg)).unwrap(),
Err(err) => { Err(err) => {
println!("BINCODE ERROR: {:?}", err); println!("BINCODE ERROR: {:?}", err);
recv_tx.send(Err(err.into())).unwrap() recv_tx.send(Err(err.into())).unwrap()
}, }
} }
incoming_buf = incoming_buf.split_off(len + 9); incoming_buf = incoming_buf.split_off(len + 9);

View File

@ -1,5 +1,5 @@
// Library // Library
use specs::{Entities, Join, Read, ReadStorage, ReadExpect, System, WriteStorage}; use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage};
use vek::*; use vek::*;
// Crate // Crate
@ -8,9 +8,9 @@ use crate::{
phys::{Dir, Pos, Vel}, phys::{Dir, Pos, Vel},
Animation, AnimationHistory, Control, Animation, AnimationHistory, Control,
}, },
state::DeltaTime,
terrain::TerrainMap, terrain::TerrainMap,
vol::{ReadVol, Vox}, vol::{ReadVol, Vox},
state::DeltaTime,
}; };
// Basic ECS AI agent system // Basic ECS AI agent system
@ -28,14 +28,18 @@ impl<'a> System<'a> for Sys {
ReadStorage<'a, Control>, ReadStorage<'a, Control>,
); );
fn run(&mut self, (terrain, dt, entities, pos, mut vels, mut dirs, mut anims, controls): Self::SystemData) { fn run(
&mut self,
(terrain, dt, entities, pos, mut vels, mut dirs, mut anims, controls): Self::SystemData,
) {
for (entity, pos, mut vel, mut dir, control) in for (entity, pos, mut vel, mut dir, control) in
(&entities, &pos, &mut vels, &mut dirs, &controls).join() (&entities, &pos, &mut vels, &mut dirs, &controls).join()
{ {
let on_ground = terrain let on_ground = terrain
.get((pos.0 - Vec3::unit_z() * 0.1).map(|e| e.floor() as i32)) .get((pos.0 - Vec3::unit_z() * 0.1).map(|e| e.floor() as i32))
.map(|vox| !vox.is_empty()) .map(|vox| !vox.is_empty())
.unwrap_or(false) && vel.0.z <= 0.0; .unwrap_or(false)
&& vel.0.z <= 0.0;
if on_ground { if on_ground {
// TODO: Don't hard-code this // TODO: Don't hard-code this
@ -64,8 +68,8 @@ impl<'a> System<'a> for Sys {
let last_history = anims.get_mut(entity).cloned(); let last_history = anims.get_mut(entity).cloned();
let time = if let Some((true, time)) = last_history let time = if let Some((true, time)) =
.map(|last| (last.current == animation, last.time)) last_history.map(|last| (last.current == animation, last.time))
{ {
time + dt.0 as f64 time + dt.0 as f64
} else { } else {

View File

@ -8,19 +8,10 @@ pub mod input;
// Reexports // Reexports
pub use crate::{error::Error, input::Input}; pub use crate::{error::Error, input::Input};
use std::{ use crate::{
collections::HashSet, client::{Client, Clients},
net::SocketAddr, cmd::CHAT_COMMANDS,
sync::mpsc,
time::Duration,
i32,
}; };
use specs::{
join::Join, saveload::MarkedBuilder, world::EntityBuilder as EcsEntityBuilder, Builder,
Entity as EcsEntity,
};
use threadpool::ThreadPool;
use vek::*;
use common::{ use common::{
comp, comp,
comp::character::Animation, comp::character::Animation,
@ -29,11 +20,14 @@ use common::{
state::{State, Uid}, state::{State, Uid},
terrain::TerrainChunk, terrain::TerrainChunk,
}; };
use world::World; use specs::{
use crate::{ join::Join, saveload::MarkedBuilder, world::EntityBuilder as EcsEntityBuilder, Builder,
client::{Client, Clients}, Entity as EcsEntity,
cmd::CHAT_COMMANDS,
}; };
use std::{collections::HashSet, i32, net::SocketAddr, sync::mpsc, time::Duration};
use threadpool::ThreadPool;
use vek::*;
use world::World;
const CLIENT_TIMEOUT: f64 = 20.0; // Seconds const CLIENT_TIMEOUT: f64 = 20.0; // Seconds
@ -204,7 +198,9 @@ impl Server {
.join() .join()
{ {
let chunk_pos = self.state.terrain().pos_key(pos.0.map(|e| e as i32)); let chunk_pos = self.state.terrain().pos_key(pos.0.map(|e| e as i32));
let dist = (Vec2::from(chunk_pos) - Vec2::from(key)).map(|e: i32| e.abs()).reduce_max(); let dist = (Vec2::from(chunk_pos) - Vec2::from(key))
.map(|e: i32| e.abs())
.reduce_max();
if dist < 5 { if dist < 5 {
self.clients.notify( self.clients.notify(

View File

@ -1,8 +1,5 @@
// Standard // Standard
use std::{ use std::{f32::consts::PI, ops::Mul};
f32::consts::PI,
ops::Mul,
};
// Library // Library
use vek::*; use vek::*;
@ -16,7 +13,11 @@ impl Animation for IdleAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = f64;
fn update_skeleton(skeleton: &Self::Skeleton, global_time: f64, anim_time: f64) -> Self::Skeleton { fn update_skeleton(
skeleton: &Self::Skeleton,
global_time: f64,
anim_time: f64,
) -> Self::Skeleton {
let mut next = (*skeleton).clone(); let mut next = (*skeleton).clone();
let wave = (anim_time as f32 * 12.0).sin(); let wave = (anim_time as f32 * 12.0).sin();
@ -48,16 +49,16 @@ impl Animation for IdleAnimation {
next.shorts.scale = Vec3::one(); next.shorts.scale = Vec3::one();
next.l_hand.offset = Vec3::new( next.l_hand.offset = Vec3::new(
-7.5, -2.0 + waveultracos_slow * 0.3, -7.5,
-2.0 + waveultracos_slow * 0.3,
12.0 + waveultra_slow * 1.1, 12.0 + waveultra_slow * 1.1,
); );
next.l_hand.ori = Quaternion::rotation_x(0.0 + waveultra_slow * 0.06); next.l_hand.ori = Quaternion::rotation_x(0.0 + waveultra_slow * 0.06);
next.l_hand.scale = Vec3::one(); next.l_hand.scale = Vec3::one();
next.r_hand.offset = Vec3::new( next.r_hand.offset = Vec3::new(
7.5, -2.0 + waveultracos_slow * 0.3, 7.5,
-2.0 + waveultracos_slow * 0.3,
12.0 + waveultra_slow * 1.1, 12.0 + waveultra_slow * 1.1,
); );
next.r_hand.ori = Quaternion::rotation_x(0.0 + waveultra_slow * 0.06); next.r_hand.ori = Quaternion::rotation_x(0.0 + waveultra_slow * 0.06);

View File

@ -14,7 +14,11 @@ impl Animation for JumpAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = f64;
fn update_skeleton(skeleton: &Self::Skeleton, global_time: f64, anim_time: f64) -> Self::Skeleton { fn update_skeleton(
skeleton: &Self::Skeleton,
global_time: f64,
anim_time: f64,
) -> Self::Skeleton {
let mut next = (*skeleton).clone(); let mut next = (*skeleton).clone();
let wave = (anim_time as f32 * 14.0).sin(); let wave = (anim_time as f32 * 14.0).sin();
let arcwave = (1.0f32.ln_1p() - 1.0).abs(); let arcwave = (1.0f32.ln_1p() - 1.0).abs();
@ -22,7 +26,7 @@ impl Animation for JumpAnimation {
let fuzzwave = (anim_time as f32 * 12.0).sin(); let fuzzwave = (anim_time as f32 * 12.0).sin();
let wavecos = (anim_time as f32 * 14.0).cos(); let wavecos = (anim_time as f32 * 14.0).cos();
let wave_slow = (anim_time as f32 * 5.0 + PI).min(PI / 2.0).sin(); let wave_slow = (anim_time as f32 * 5.0 + PI).min(PI / 2.0).sin();
let wave_slowtest = (anim_time as f32).min(PI/2.0).sin(); let wave_slowtest = (anim_time as f32).min(PI / 2.0).sin();
let wavecos_slow = (anim_time as f32 * 8.0 + PI).cos(); let wavecos_slow = (anim_time as f32 * 8.0 + PI).cos();
let wave_dip = (wave_slow.abs() - 0.5).abs(); let wave_dip = (wave_slow.abs() - 0.5).abs();
let mult = wave_slow / (wave_slow.abs()); let mult = wave_slow / (wave_slow.abs());

View File

@ -1,11 +1,11 @@
pub mod idle; pub mod idle;
pub mod run;
pub mod jump; pub mod jump;
pub mod run;
// Reexports // Reexports
pub use self::idle::IdleAnimation; pub use self::idle::IdleAnimation;
pub use self::run::RunAnimation;
pub use self::jump::JumpAnimation; pub use self::jump::JumpAnimation;
pub use self::run::RunAnimation;
// Crate // Crate
use crate::render::FigureBoneData; use crate::render::FigureBoneData;

View File

@ -13,7 +13,11 @@ impl Animation for RunAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = (f32, f64); type Dependency = (f32, f64);
fn update_skeleton(skeleton: &Self::Skeleton, (velocity, global_time): Self::Dependency, anim_time: f64) -> Self::Skeleton { fn update_skeleton(
skeleton: &Self::Skeleton,
(velocity, global_time): Self::Dependency,
anim_time: f64,
) -> Self::Skeleton {
let mut next = (*skeleton).clone(); let mut next = (*skeleton).clone();
let wave = (anim_time as f32 * 14.0).sin(); let wave = (anim_time as f32 * 14.0).sin();
@ -61,7 +65,7 @@ impl Animation for RunAnimation {
next.weapon.scale = Vec3::one(); next.weapon.scale = Vec3::one();
next.torso.offset = Vec3::new(-0.5, -0.2, 0.2); next.torso.offset = Vec3::new(-0.5, -0.2, 0.2);
next.torso.ori = Quaternion::rotation_x( - velocity * 0.05 - wavecos * 0.1); next.torso.ori = Quaternion::rotation_x(-velocity * 0.05 - wavecos * 0.1);
next.torso.scale = Vec3::one() / 11.0; next.torso.scale = Vec3::one() / 11.0;
next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0); next.l_shoulder.offset = Vec3::new(3.0, 6.0, 18.0);

View File

@ -50,5 +50,9 @@ pub trait Animation {
type Dependency; type Dependency;
/// Returns a new skeleton that is generated by the animation /// Returns a new skeleton that is generated by the animation
fn update_skeleton(skeleton: &Self::Skeleton, dependency: Self::Dependency, anim_time: f64) -> Self::Skeleton; fn update_skeleton(
skeleton: &Self::Skeleton,
dependency: Self::Dependency,
anim_time: f64,
) -> Self::Skeleton;
} }

View File

@ -1,9 +1,9 @@
use client::{error::Error as ClientError, Client}; use client::{error::Error as ClientError, Client};
use common::comp; use common::comp;
use std::{ use std::{
net::ToSocketAddrs,
sync::mpsc::{channel, Receiver, TryRecvError}, sync::mpsc::{channel, Receiver, TryRecvError},
thread::{self, JoinHandle}, thread::{self, JoinHandle},
net::ToSocketAddrs,
time::Duration, time::Duration,
}; };
@ -23,7 +23,11 @@ pub struct ClientInit {
rx: Receiver<Result<Client, Error>>, rx: Receiver<Result<Client, Error>>,
} }
impl ClientInit { impl ClientInit {
pub fn new(connection_args: (String, u16, bool), client_args: (comp::Player, u64), wait: bool) -> Self { pub fn new(
connection_args: (String, u16, bool),
client_args: (comp::Player, u64),
wait: bool,
) -> Self {
let (server_address, default_port, prefer_ipv6) = connection_args; let (server_address, default_port, prefer_ipv6) = connection_args;
let (player, view_distance) = client_args; let (player, view_distance) = client_args;

View File

@ -1,11 +1,11 @@
use std::net::SocketAddr; use super::{client_init::ClientInit, DEFAULT_PORT};
use log::warn;
use common::comp;
use crate::{ use crate::{
menu::char_selection::CharSelectionState, singleplayer::Singleplayer, Direction, GlobalState, menu::char_selection::CharSelectionState, singleplayer::Singleplayer, Direction, GlobalState,
PlayState, PlayStateResult, PlayState, PlayStateResult,
}; };
use super::{client_init::ClientInit, DEFAULT_PORT}; use common::comp;
use log::warn;
use std::net::SocketAddr;
pub struct StartSingleplayerState { pub struct StartSingleplayerState {
singleplayer: Singleplayer, singleplayer: Singleplayer,
@ -17,10 +17,7 @@ impl StartSingleplayerState {
pub fn new() -> Self { pub fn new() -> Self {
let (singleplayer, sock) = Singleplayer::new(); let (singleplayer, sock) = Singleplayer::new();
Self { Self { singleplayer, sock }
singleplayer,
sock,
}
} }
} }
@ -45,7 +42,7 @@ impl PlayState for StartSingleplayerState {
Some(Err(err)) => { Some(Err(err)) => {
warn!("Failed to start singleplayer server: {:?}", err); warn!("Failed to start singleplayer server: {:?}", err);
return PlayStateResult::Pop; return PlayStateResult::Pop;
}, }
_ => {} _ => {}
} }
}; };

View File

@ -12,7 +12,7 @@ use gfx::{
// Local // Local
use super::{ use super::{
super::{Mesh, Pipeline, WinColorFmt, WinDepthFmt, Tri}, super::{Mesh, Pipeline, Tri, WinColorFmt, WinDepthFmt},
Globals, Globals,
}; };

View File

@ -1,4 +1,4 @@
use super::super::{Pipeline, Quad, WinColorFmt, WinDepthFmt, Tri}; use super::super::{Pipeline, Quad, Tri, WinColorFmt, WinDepthFmt};
use gfx::{ use gfx::{
self, self,
// Macros // Macros

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
anim::{ anim::{
character::{CharacterSkeleton, IdleAnimation, RunAnimation, JumpAnimation}, character::{CharacterSkeleton, IdleAnimation, JumpAnimation, RunAnimation},
Animation, Skeleton, Animation, Skeleton,
}, },
mesh::Meshable, mesh::Meshable,
@ -207,15 +207,21 @@ impl FigureCache {
.or_insert_with(|| FigureState::new(renderer, CharacterSkeleton::new())); .or_insert_with(|| FigureState::new(renderer, CharacterSkeleton::new()));
let target_skeleton = match animation_history.current { let target_skeleton = match animation_history.current {
comp::character::Animation::Idle => { comp::character::Animation::Idle => IdleAnimation::update_skeleton(
IdleAnimation::update_skeleton(&mut state.skeleton, time, animation_history.time) &mut state.skeleton,
}, time,
comp::character::Animation::Run => { animation_history.time,
RunAnimation::update_skeleton(&mut state.skeleton, (vel.0.magnitude(), time), animation_history.time) ),
}, comp::character::Animation::Run => RunAnimation::update_skeleton(
comp::character::Animation::Jump => { &mut state.skeleton,
JumpAnimation::update_skeleton(&mut state.skeleton, time, animation_history.time) (vel.0.magnitude(), time),
}, animation_history.time,
),
comp::character::Animation::Jump => JumpAnimation::update_skeleton(
&mut state.skeleton,
time,
animation_history.time,
),
}; };
state.skeleton.interpolate(&target_skeleton); state.skeleton.interpolate(&target_skeleton);
@ -266,7 +272,7 @@ impl<S: Skeleton> FigureState<S> {
fn update(&mut self, renderer: &mut Renderer, pos: Vec3<f32>, dir: Vec3<f32>) { fn update(&mut self, renderer: &mut Renderer, pos: Vec3<f32>, dir: Vec3<f32>) {
let mat = Mat4::<f32>::identity() let mat = Mat4::<f32>::identity()
* Mat4::translation_3d(pos) * Mat4::translation_3d(pos)
* Mat4::rotation_z(-dir.x.atan2(dir.y));// + f32::consts::PI / 2.0); * Mat4::rotation_z(-dir.x.atan2(dir.y)); // + f32::consts::PI / 2.0);
let locals = FigureLocals::new(mat); let locals = FigureLocals::new(mat);
renderer.update_consts(&mut self.locals, &[locals]).unwrap(); renderer.update_consts(&mut self.locals, &[locals]).unwrap();

View File

@ -1,17 +1,3 @@
use std::{
cell::RefCell,
rc::Rc,
time::Duration,
mem,
};
use vek::*;
use common::clock::Clock;
use client::{
self,
Client,
Input,
InputEvent,
};
use crate::{ use crate::{
hud::{Event as HudEvent, Hud}, hud::{Event as HudEvent, Hud},
key_state::KeyState, key_state::KeyState,
@ -21,6 +7,10 @@ use crate::{
window::{Event, Key, Window}, window::{Event, Key, Window},
Direction, Error, GlobalState, PlayState, PlayStateResult, Direction, Error, GlobalState, PlayState, PlayStateResult,
}; };
use client::{self, Client, Input, InputEvent};
use common::clock::Clock;
use std::{cell::RefCell, mem, rc::Rc, time::Duration};
use vek::*;
const FPS: u64 = 60; const FPS: u64 = 60;
@ -72,15 +62,14 @@ impl SessionState {
let mut input_events = Vec::new(); let mut input_events = Vec::new();
mem::swap(&mut self.input_events, &mut input_events); mem::swap(&mut self.input_events, &mut input_events);
for event in self for event in self.client.borrow_mut().tick(
.client Input {
.borrow_mut()
.tick(Input {
move_dir, move_dir,
jumping: self.key_state.jump, jumping: self.key_state.jump,
events: input_events, events: input_events,
}, dt)? },
{ dt,
)? {
match event { match event {
client::Event::Chat(msg) => { client::Event::Chat(msg) => {
self.hud.new_message(msg); self.hud.new_message(msg);
@ -155,7 +144,7 @@ impl PlayState for SessionState {
Event::KeyDown(Key::Jump) => { Event::KeyDown(Key::Jump) => {
self.input_events.push(InputEvent::Jump); self.input_events.push(InputEvent::Jump);
self.key_state.jump = true; self.key_state.jump = true;
}, }
// Movement Key Released // Movement Key Released
Event::KeyUp(Key::MoveForward) => self.key_state.up = false, Event::KeyUp(Key::MoveForward) => self.key_state.up = false,
Event::KeyUp(Key::MoveBack) => self.key_state.down = false, Event::KeyUp(Key::MoveBack) => self.key_state.down = false,

View File

@ -1,13 +1,13 @@
use std::{ use common::clock::Clock;
sync::mpsc::{channel, Receiver, Sender, TryRecvError},
time::Duration,
thread::{self, JoinHandle},
net::SocketAddr,
};
use log::info; use log::info;
use portpicker::pick_unused_port; use portpicker::pick_unused_port;
use common::clock::Clock;
use server::{Event, Input, Server}; use server::{Event, Input, Server};
use std::{
net::SocketAddr,
sync::mpsc::{channel, Receiver, Sender, TryRecvError},
thread::{self, JoinHandle},
time::Duration,
};
const TPS: u64 = 30; const TPS: u64 = 30;
@ -26,18 +26,23 @@ impl Singleplayer {
pub fn new() -> (Self, SocketAddr) { pub fn new() -> (Self, SocketAddr) {
let (sender, reciever) = channel(); let (sender, reciever) = channel();
let sock = SocketAddr::from(([127,0,0,1], pick_unused_port() let sock = SocketAddr::from((
.expect("Failed to find unused port"))); [127, 0, 0, 1],
pick_unused_port().expect("Failed to find unused port"),
));
let sock2 = sock.clone(); let sock2 = sock.clone();
let thread = thread::spawn(move || { let thread = thread::spawn(move || {
run_server(sock2, reciever); run_server(sock2, reciever);
}); });
(Singleplayer { (
Singleplayer {
server_thread: thread, server_thread: thread,
sender, sender,
}, sock) },
sock,
)
} }
} }

View File

@ -32,12 +32,9 @@ impl World {
let dirt = Block::new(3, Rgb::new(128, 90, 0)); let dirt = Block::new(3, Rgb::new(128, 90, 0));
let sand = Block::new(4, Rgb::new(180, 150, 50)); let sand = Block::new(4, Rgb::new(180, 150, 50));
let perlin_nz = Perlin::new() let perlin_nz = Perlin::new().set_seed(1);
.set_seed(1); let temp_nz = Perlin::new().set_seed(2);
let temp_nz = Perlin::new() let chaos_nz = Perlin::new().set_seed(3);
.set_seed(2);
let chaos_nz = Perlin::new()
.set_seed(3);
for lpos in chunk.iter_positions() { for lpos in chunk.iter_positions() {
let wpos = lpos + chunk_pos * chunk.get_size().map(|e| e as i32); let wpos = lpos + chunk_pos * chunk.get_size().map(|e| e as i32);
@ -50,10 +47,16 @@ impl World {
let small_ampl = 6.0; let small_ampl = 6.0;
let offs = 32.0; let offs = 32.0;
let chaos = chaos_nz.get(Vec2::from(wposf * chaos_freq).into_array()).max(0.0) + 0.5; let chaos = chaos_nz
.get(Vec2::from(wposf * chaos_freq).into_array())
.max(0.0)
+ 0.5;
let height = perlin_nz.get(Vec2::from(wposf * freq).into_array()) * ampl * chaos let height = perlin_nz.get(Vec2::from(wposf * freq).into_array()) * ampl * chaos
+ perlin_nz.get((wposf * small_freq).into_array()) * small_ampl * 2.0 * chaos.powf(2.0) + perlin_nz.get((wposf * small_freq).into_array())
* small_ampl
* 2.0
* chaos.powf(2.0)
+ offs; + offs;
let temp = (temp_nz.get(Vec2::from(wposf * (1.0 / 64.0)).into_array()) + 1.0) * 0.5; let temp = (temp_nz.get(Vec2::from(wposf * (1.0 / 64.0)).into_array()) + 1.0) * 0.5;