mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Restarted worldgen
Former-commit-id: e1526ec5f865904f11ab6a1507ecdc1a52acb28d
This commit is contained in:
parent
5118da0e0e
commit
feece604be
71
Cargo.lock
generated
71
Cargo.lock
generated
@ -173,6 +173,11 @@ name = "bitflags"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "0.8.2"
|
||||
@ -234,6 +239,11 @@ dependencies = [
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cast"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.37"
|
||||
@ -1393,6 +1403,19 @@ name = "memoffset"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "minifb"
|
||||
version = "0.11.2"
|
||||
source = "git+https://github.com/emoon/rust_minifb.git#2b8094cc6ce7fefeb322a8b4df09e0c978efd5e2"
|
||||
dependencies = [
|
||||
"cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"orbclient 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"x11-dl 2.18.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "minimp3"
|
||||
version = "0.3.3"
|
||||
@ -1524,6 +1547,16 @@ name = "nonzero_signed"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.2.0"
|
||||
@ -1642,6 +1675,15 @@ dependencies = [
|
||||
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "orbclient"
|
||||
version = "0.3.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ordered-float"
|
||||
version = "1.0.2"
|
||||
@ -2164,6 +2206,27 @@ name = "scopeguard"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "sdl2"
|
||||
version = "0.31.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sdl2-sys 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sdl2-sys"
|
||||
version = "0.31.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
@ -2645,6 +2708,7 @@ dependencies = [
|
||||
name = "veloren-world"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"minifb 0.11.2 (git+https://github.com/emoon/rust_minifb.git)",
|
||||
"noise 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"vek 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"veloren-common 0.2.0",
|
||||
@ -2867,6 +2931,7 @@ dependencies = [
|
||||
"checksum bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9f04a5e50dc80b3d5d35320889053637d15011aed5e66b66b37ae798c65da6f7"
|
||||
"checksum bindgen 0.32.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b242e11a8f446f5fc7b76b37e81d737cabca562a927bd33766dac55b5f1177f"
|
||||
"checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23"
|
||||
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
|
||||
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
|
||||
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
|
||||
"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
|
||||
@ -2876,6 +2941,7 @@ dependencies = [
|
||||
"checksum c_vec 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6237ac5a4b1e81c213c24c6437964c61e646df910a914b4ab1487b46df20bd13"
|
||||
"checksum cairo-rs 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0180a8b65dc13e78479c6a47c4d5f094d64dc34465a9433c6daef9ae2fbfb3ee"
|
||||
"checksum cairo-sys-rs 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a2414b86c20c40dfb56a98b1dbca05bde56411f488d268c4289a86df1b648c61"
|
||||
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
|
||||
"checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d"
|
||||
"checksum cexpr 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42aac45e9567d97474a834efdee3081b3c942b2205be932092f53354ce503d6c"
|
||||
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
|
||||
@ -3002,6 +3068,7 @@ dependencies = [
|
||||
"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
|
||||
"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
|
||||
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
|
||||
"checksum minifb 0.11.2 (git+https://github.com/emoon/rust_minifb.git)" = "<none>"
|
||||
"checksum minimp3 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "542e9bed56860c5070a09939eee0e2df6f8f73f60304ddf56d620947e7017239"
|
||||
"checksum minimp3-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c109ae05c00ad6e3a53fab101e2f234545bdd010f0fffd399355efaf70817817"
|
||||
"checksum mio 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "049ba5ca2b63e837adeee724aa9e36b408ed593529dcc802aa96ca14bd329bdf"
|
||||
@ -3016,6 +3083,7 @@ dependencies = [
|
||||
"checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b"
|
||||
"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
|
||||
"checksum nonzero_signed 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "02783a0482333b0d3f5f5411b8fb60454a596696da041da0470ac9ef3e6e37d8"
|
||||
"checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e"
|
||||
"checksum num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf4825417e1e1406b3782a8ce92f4d53f26ec055e3622e1881ca8e9f5f9e08db"
|
||||
"checksum num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "57450397855d951f1a41305e54851b1a7b8f5d2e349543a02a2effe25459f718"
|
||||
"checksum num-complex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "107b9be86cd2481930688277b675b0114578227f034674726605b8a482d8baf8"
|
||||
@ -3030,6 +3098,7 @@ dependencies = [
|
||||
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
||||
"checksum objc 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "31d20fd2b37e07cf5125be68357b588672e8cefe9a96f8c17a9d46053b3e590d"
|
||||
"checksum ogg 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d79f1db9148be9d0e174bb3ac890f6030fcb1ed947267c5a91ee4c91b5a91e15"
|
||||
"checksum orbclient 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0e398a001ca5f52b252d1cf5679d52ddd347d3130ac9ded98549f16537c546"
|
||||
"checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518"
|
||||
"checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b"
|
||||
"checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13"
|
||||
@ -3089,6 +3158,8 @@ dependencies = [
|
||||
"checksum scan_fmt 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b87497427f9fbe539ee6b9626f5a5e899331fdf1c1d62f14c637a462969db30"
|
||||
"checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
|
||||
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
|
||||
"checksum sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a74c2a98a354b20713b90cce70aef9e927e46110d1bc4ef728fd74e0d53eba60"
|
||||
"checksum sdl2-sys 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c543ce8a6e33a30cb909612eeeb22e693848211a84558d5a00bb11e791b7ab7"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
|
||||
|
@ -12,7 +12,7 @@ pub enum ChonkError {
|
||||
OutOfBounds,
|
||||
}
|
||||
|
||||
const SUB_CHUNK_HEIGHT: u32 = 16;
|
||||
const SUB_CHUNK_HEIGHT: u32 = 32;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Chonk {
|
||||
|
@ -52,4 +52,4 @@ directories = "1.0"
|
||||
portpicker = "0.1"
|
||||
num = "0.2"
|
||||
backtrace = "0.3"
|
||||
rand = "0.5"
|
||||
rand = "0.5"
|
||||
|
@ -8,3 +8,6 @@ edition = "2018"
|
||||
common = { package = "veloren-common", path = "../common" }
|
||||
vek = "0.9"
|
||||
noise = "0.5"
|
||||
|
||||
[dev-dependencies]
|
||||
minifb = { git = "https://github.com/emoon/rust_minifb.git" }
|
||||
|
65
world/examples/view.rs
Normal file
65
world/examples/view.rs
Normal file
@ -0,0 +1,65 @@
|
||||
use std::ops::{Add, Sub, Mul};
|
||||
use vek::*;
|
||||
use veloren_world::World;
|
||||
|
||||
const W: usize = 640;
|
||||
const H: usize = 480;
|
||||
|
||||
fn main() {
|
||||
let world = World::generate(0);
|
||||
|
||||
let mut win = minifb::Window::new(
|
||||
"World Viewer",
|
||||
W, H,
|
||||
minifb::WindowOptions::default(),
|
||||
).unwrap();
|
||||
|
||||
let mut focus = Vec2::zero();
|
||||
let mut gain = 1.0;
|
||||
|
||||
while win.is_open() {
|
||||
let mut buf = [0; W * H];
|
||||
|
||||
for i in 0..W {
|
||||
for j in 0..H {
|
||||
let pos = focus + Vec2::new(i as i32, j as i32) * 4;
|
||||
|
||||
let alt = world
|
||||
.sim()
|
||||
.sample(pos)
|
||||
.map(|sample| sample
|
||||
.alt
|
||||
.sub(64.0)
|
||||
.add(gain)
|
||||
.mul(0.7)
|
||||
.max(0.0)
|
||||
.min(255.0) as u8)
|
||||
.unwrap_or(0);
|
||||
|
||||
buf[j * W + i] = u32::from_le_bytes([alt; 4]);
|
||||
}
|
||||
}
|
||||
|
||||
let spd = 32;
|
||||
if win.is_key_down(minifb::Key::W) {
|
||||
focus.y -= spd;
|
||||
}
|
||||
if win.is_key_down(minifb::Key::A) {
|
||||
focus.x -= spd;
|
||||
}
|
||||
if win.is_key_down(minifb::Key::S) {
|
||||
focus.y += spd;
|
||||
}
|
||||
if win.is_key_down(minifb::Key::D) {
|
||||
focus.x += spd;
|
||||
}
|
||||
if win.is_key_down(minifb::Key::Q) {
|
||||
gain += 10.0;
|
||||
}
|
||||
if win.is_key_down(minifb::Key::E) {
|
||||
gain -= 10.0;
|
||||
}
|
||||
|
||||
win.update_with_buffer(&buf).unwrap();
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
mod sim;
|
||||
|
||||
use std::{
|
||||
ops::{Add, Mul, Neg},
|
||||
ops::{Add, Mul, Div, Neg},
|
||||
time::Duration,
|
||||
};
|
||||
use noise::{NoiseFn, Perlin, Seedable};
|
||||
@ -25,6 +25,10 @@ impl World {
|
||||
Self { sim: sim::WorldSim::generate(seed) }
|
||||
}
|
||||
|
||||
pub fn sim(&self) -> &sim::WorldSim {
|
||||
&self.sim
|
||||
}
|
||||
|
||||
pub fn tick(&self, dt: Duration) {
|
||||
// TODO
|
||||
}
|
||||
@ -37,6 +41,7 @@ impl World {
|
||||
let grass = Block::new(2, Rgb::new(75, 150, 0));
|
||||
let dirt = Block::new(3, Rgb::new(128, 90, 0));
|
||||
let sand = Block::new(4, Rgb::new(180, 150, 50));
|
||||
let water = Block::new(5, Rgb::new(100, 150, 255));
|
||||
|
||||
let warp_nz = Perlin::new().set_seed(self.sim.seed + 0);
|
||||
let temp_nz = Perlin::new().set_seed(self.sim.seed + 1);
|
||||
@ -54,56 +59,37 @@ impl World {
|
||||
let wpos2d = Vec2::new(x, y) + Vec3::from(chunk_pos) * TerrainChunkSize::SIZE.map(|e| e as i32);
|
||||
let wposf2d = wpos2d.map(|e| e as f64);
|
||||
|
||||
let sim::Sample {
|
||||
alt,
|
||||
surface_color
|
||||
} = if let Some(sample) = self.sim.sample(wpos2d) {
|
||||
sample
|
||||
} else {
|
||||
continue
|
||||
};
|
||||
|
||||
let max_z = self.sim
|
||||
.get_interpolated(wpos2d, |chunk| chunk.get_max_z())
|
||||
.unwrap_or(0.0) as i32;
|
||||
|
||||
let chaos = self.sim
|
||||
.get_interpolated(wpos2d, |chunk| chunk.chaos)
|
||||
.unwrap_or(0.0);
|
||||
|
||||
let damp = self.sim
|
||||
.get_interpolated(wpos2d, |chunk| chunk.damp)
|
||||
.unwrap_or(0.0)
|
||||
.abs().neg().add(1.0)
|
||||
.mul(1.0 - chaos);
|
||||
|
||||
let ridge_freq = 1.0 / 125.0;
|
||||
let ridge_ampl = 125.0;
|
||||
|
||||
let ridge = ridge_nz
|
||||
.get((wposf2d * ridge_freq).into_array()).abs().neg().add(1.0) as f32 * ridge_ampl * chaos.powf(8.0);
|
||||
|
||||
let height_z = self.sim
|
||||
.get_interpolated(wpos2d, |chunk| chunk.alt)
|
||||
.unwrap_or(0.0)
|
||||
+ ridge
|
||||
- damp.powf(20.0) * 32.0;
|
||||
|
||||
for z in base_z..max_z {
|
||||
let lpos = Vec3::new(x, y, z);
|
||||
let wpos = lpos
|
||||
+ Vec3::from(chunk_pos) * TerrainChunkSize::SIZE.map(|e| e as i32);
|
||||
let wposf = wpos.map(|e| e as f64);
|
||||
|
||||
let warp_freq = 1.0 / 40.0;
|
||||
let warp_ampl = 45.0;
|
||||
|
||||
let height = height_z
|
||||
+ warp_nz.get((wposf * warp_freq).into_array()) as f32 * warp_ampl * (chaos + 0.05).min(0.85);
|
||||
|
||||
let temp =
|
||||
(temp_nz.get(Vec2::from(wposf * (1.0 / 64.0)).into_array()) as f32 + 1.0) * 0.5;
|
||||
let height = alt;
|
||||
let temp = 0.0;
|
||||
|
||||
let z = wposf.z as f32;
|
||||
let _ = chunk.set(
|
||||
lpos,
|
||||
if z < height - 4.0 {
|
||||
if z < height - 6.0 {
|
||||
stone
|
||||
} else if z < height - 2.0 {
|
||||
dirt
|
||||
} else if z < height {
|
||||
Block::new(2, Rgb::new(10 + (75.0 * temp) as u8, 180, 50 - (50.0 * temp) as u8))
|
||||
Block::new(1, surface_color.map(|e| (e * 255.0) as u8))
|
||||
} else {
|
||||
air
|
||||
},
|
||||
@ -113,5 +99,7 @@ impl World {
|
||||
}
|
||||
|
||||
chunk
|
||||
|
||||
// */
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::{
|
||||
ops::{Add, Mul, Div, Neg},
|
||||
ops::{Add, Sub, Mul, Div, Neg},
|
||||
f32,
|
||||
};
|
||||
use noise::{NoiseFn, SuperSimplex, OpenSimplex, Seedable};
|
||||
use noise::{NoiseFn, BasicMulti, HybridMulti, RidgedMulti, SuperSimplex, OpenSimplex, Seedable, MultiFractal};
|
||||
use vek::*;
|
||||
use common::{
|
||||
terrain::TerrainChunkSize,
|
||||
@ -14,19 +14,26 @@ pub const WORLD_SIZE: Vec2<usize> = Vec2 { x: 1024, y: 1024 };
|
||||
pub struct WorldSim {
|
||||
pub seed: u32,
|
||||
chunks: Vec<SimChunk>,
|
||||
gen_ctx: GenCtx,
|
||||
}
|
||||
|
||||
impl WorldSim {
|
||||
pub fn generate(seed: u32) -> Self {
|
||||
let mut gen_ctx = GenCtx {
|
||||
base_nz: OpenSimplex::new()
|
||||
turb_x_nz: BasicMulti::new()
|
||||
.set_seed(seed + 0),
|
||||
damp_nz: SuperSimplex::new()
|
||||
turb_y_nz: BasicMulti::new()
|
||||
.set_seed(seed + 1),
|
||||
chaos_nz: SuperSimplex::new()
|
||||
chaos_nz: RidgedMulti::new()
|
||||
.set_octaves(7)
|
||||
.set_seed(seed + 2),
|
||||
alt_nz: OpenSimplex::new()
|
||||
alt_nz: HybridMulti::new()
|
||||
.set_octaves(7)
|
||||
.set_persistence(0.1)
|
||||
.set_seed(seed + 3),
|
||||
small_nz: BasicMulti::new()
|
||||
.set_octaves(1)
|
||||
.set_seed(seed + 4),
|
||||
};
|
||||
|
||||
let mut chunks = Vec::new();
|
||||
@ -39,6 +46,7 @@ impl WorldSim {
|
||||
Self {
|
||||
seed,
|
||||
chunks,
|
||||
gen_ctx,
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,28 +102,50 @@ impl WorldSim {
|
||||
y[y_idx] = cubic(x0, x1, x2, x3, pos.x.fract() as f32);
|
||||
}
|
||||
|
||||
/*
|
||||
fn cosine_interp (a: f32, b: f32, x: f32) -> f32 {
|
||||
let x2 = x;//(1.0 - (x * f32::consts::PI).cos()) / 2.0;
|
||||
a * (1.0 - x2) + b * x2
|
||||
}
|
||||
*/
|
||||
|
||||
Some(cubic(y[0], y[1], y[2], y[3], pos.y.fract() as f32))
|
||||
}
|
||||
|
||||
pub fn sample(&self, pos: Vec2<i32>) -> Option<Sample> {
|
||||
let wposf = pos.map(|e| e as f64);
|
||||
|
||||
/*let wposf = wposf + Vec2::new(
|
||||
self.gen_ctx.turb_x_nz.get((wposf.div(200.0)).into_array()) * 250.0,
|
||||
self.gen_ctx.turb_y_nz.get((wposf.div(200.0)).into_array()) * 250.0,
|
||||
);*/
|
||||
|
||||
let chaos = self.get_interpolated(pos, |chunk| chunk.chaos)?;
|
||||
|
||||
let alt = self.get_interpolated(pos, |chunk| chunk.alt)?
|
||||
+ self.gen_ctx.small_nz.get((wposf.div(128.0)).into_array()) as f32 * chaos.max(0.2) * 32.0;
|
||||
|
||||
// Colours
|
||||
let grass = Rgb::new(0.0, 0.765, 0.05);
|
||||
let stone = Rgb::new(0.695, 0.66, 0.551);
|
||||
|
||||
Some(Sample {
|
||||
alt,
|
||||
surface_color: Lerp::lerp(grass, stone, (alt - SEA_LEVEL) / 300.0),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Sample {
|
||||
pub alt: f32,
|
||||
pub surface_color: Rgb<f32>,
|
||||
}
|
||||
|
||||
struct GenCtx {
|
||||
base_nz: OpenSimplex,
|
||||
damp_nz: SuperSimplex,
|
||||
chaos_nz: SuperSimplex,
|
||||
alt_nz: OpenSimplex,
|
||||
turb_x_nz: BasicMulti,
|
||||
turb_y_nz: BasicMulti,
|
||||
chaos_nz: RidgedMulti,
|
||||
alt_nz: HybridMulti,
|
||||
small_nz: BasicMulti,
|
||||
}
|
||||
|
||||
const Z_TOLERANCE: f32 = 32.0;
|
||||
const SEA_LEVEL: f32 = 64.0;
|
||||
|
||||
pub struct SimChunk {
|
||||
pub damp: f32,
|
||||
pub chaos: f32,
|
||||
pub alt: f32,
|
||||
}
|
||||
@ -124,34 +154,20 @@ impl SimChunk {
|
||||
fn generate(pos: Vec2<u32>, gen_ctx: &mut GenCtx) -> Self {
|
||||
let wposf = (pos * Vec2::from(TerrainChunkSize::SIZE)).map(|e| e as f64);
|
||||
|
||||
let base = (gen_ctx.base_nz.get((wposf.div(6000.0)).into_array()) as f32)
|
||||
.add(1.0).mul(0.5)
|
||||
.mul(100.0)
|
||||
.add(32.0);
|
||||
|
||||
let damp = (0.0
|
||||
+ gen_ctx.damp_nz.get((wposf.div(2000.0)).into_array())
|
||||
+ gen_ctx.damp_nz.get((wposf.div(250.0)).into_array()) * 0.25
|
||||
) as f32;
|
||||
|
||||
let chaos = (gen_ctx.chaos_nz
|
||||
.get((wposf.div(1000.0)).into_array()) as f32)
|
||||
.get((wposf.div(3500.0)).into_array()) as f32)
|
||||
.add(1.0).mul(0.5)
|
||||
.mul(damp.max(0.0))
|
||||
.add(0.15)
|
||||
.powf(2.0)
|
||||
.min(1.0);
|
||||
.powf(1.85);
|
||||
|
||||
let chaos = chaos + chaos.mul(20.0).sin().mul(0.05);
|
||||
|
||||
Self {
|
||||
damp,
|
||||
chaos,
|
||||
alt: base + ((0.0
|
||||
+ gen_ctx.alt_nz.get((wposf.div(650.0)).into_array()) * 0.7
|
||||
+ gen_ctx.alt_nz.get((wposf.div(100.0)).into_array()) * 0.3
|
||||
) as f32)
|
||||
alt: SEA_LEVEL + (gen_ctx.alt_nz
|
||||
.get((wposf.div(750.0)).into_array()) as f32)
|
||||
.add(1.0).mul(0.5)
|
||||
.mul(750.0)
|
||||
.mul(chaos.max(0.05)),
|
||||
.mul(chaos)
|
||||
.mul(650.0),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user