mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Basic worldgen
Former-commit-id: 3ca0afa95dd1d868a84a41129e889a203e8a7cd9
This commit is contained in:
parent
2548c1c31f
commit
c13206d82d
@ -73,7 +73,7 @@ impl<'a> System<'a> for Sys {
|
||||
* 50.0
|
||||
* vel.0.map(|e| {
|
||||
(e.abs() * friction * (vel.0.magnitude() * 0.1 + 0.5))
|
||||
.min(e.abs())
|
||||
.min(e.abs() * dt.0 * 50.0)
|
||||
.copysign(e)
|
||||
})
|
||||
* Vec3::new(1.0, 1.0, 0.0);
|
||||
|
@ -9,12 +9,12 @@ use specs::DispatcherBuilder;
|
||||
// System names
|
||||
const AGENT_SYS: &str = "agent_sys";
|
||||
const CONTROL_SYS: &str = "control_sys";
|
||||
const MOVEMENT_SYS: &str = "movement_sys";
|
||||
const PHYS_SYS: &str = "phys_sys";
|
||||
const ANIM_SYS: &str = "anim_sys";
|
||||
|
||||
pub fn add_local_systems(dispatch_builder: &mut DispatcherBuilder) {
|
||||
dispatch_builder.add(agent::Sys, AGENT_SYS, &[]);
|
||||
dispatch_builder.add(control::Sys, CONTROL_SYS, &[]);
|
||||
dispatch_builder.add(phys::Sys, MOVEMENT_SYS, &[]);
|
||||
dispatch_builder.add(phys::Sys, PHYS_SYS, &[]);
|
||||
dispatch_builder.add(control::Sys, CONTROL_SYS, &["phys_sys"]);
|
||||
dispatch_builder.add(anim::Sys, ANIM_SYS, &[]);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ use specs::{
|
||||
join::Join, saveload::MarkedBuilder, world::EntityBuilder as EcsEntityBuilder, Builder,
|
||||
Entity as EcsEntity,
|
||||
};
|
||||
use std::{collections::HashSet, i32, net::SocketAddr, sync::mpsc, time::Duration};
|
||||
use std::{collections::HashSet, i32, net::SocketAddr, sync::{Arc, mpsc}, time::Duration};
|
||||
use threadpool::ThreadPool;
|
||||
use vek::*;
|
||||
use world::World;
|
||||
@ -40,7 +40,7 @@ pub enum Event {
|
||||
|
||||
pub struct Server {
|
||||
state: State,
|
||||
world: World,
|
||||
world: Arc<World>,
|
||||
|
||||
postoffice: PostOffice<ServerMsg, ClientMsg>,
|
||||
clients: Clients,
|
||||
@ -68,7 +68,7 @@ impl Server {
|
||||
|
||||
let mut this = Self {
|
||||
state,
|
||||
world: World::generate(DEFAULT_WORLD_SEED),
|
||||
world: Arc::new(World::generate(DEFAULT_WORLD_SEED)),
|
||||
|
||||
postoffice: PostOffice::bind(addrs.into())?,
|
||||
clients: Clients::empty(),
|
||||
@ -110,11 +110,6 @@ impl Server {
|
||||
pub fn world(&self) -> &World {
|
||||
&self.world
|
||||
}
|
||||
/// Get a mutable reference to the server's world.
|
||||
#[allow(dead_code)]
|
||||
pub fn world_mut(&mut self) -> &mut World {
|
||||
&mut self.world
|
||||
}
|
||||
|
||||
/// Build a non-player character.
|
||||
#[allow(dead_code)]
|
||||
@ -574,8 +569,9 @@ impl Server {
|
||||
pub fn generate_chunk(&mut self, key: Vec2<i32>) {
|
||||
if self.pending_chunks.insert(key) {
|
||||
let chunk_tx = self.chunk_tx.clone();
|
||||
let world = self.world.clone();
|
||||
self.thread_pool.execute(move || {
|
||||
let _ = chunk_tx.send((key, World::generate_chunk(key)));
|
||||
let _ = chunk_tx.send((key, world.generate_chunk(key))).unwrap()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ image_ids! {
|
||||
// Crosshair
|
||||
crosshair: "voxygen/element/misc_bg/crosshair.vox",
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
<VoxelMs9Graphic>
|
||||
|
||||
// Buttons
|
||||
@ -121,7 +121,7 @@ image_ids! {
|
||||
button_hover: "voxygen/element/buttons/button_hover.vox",
|
||||
button_press: "voxygen/element/buttons/button_press.vox",
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
<ImageGraphic>
|
||||
|
||||
charwindow_gradient:"voxygen/element/misc_bg/charwindow.png",
|
||||
|
@ -24,11 +24,11 @@ impl World {
|
||||
Self { sim: sim::WorldSim::generate(seed) }
|
||||
}
|
||||
|
||||
pub fn tick(&mut self, dt: Duration) {
|
||||
pub fn tick(&self, dt: Duration) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
pub fn generate_chunk(chunk_pos: Vec2<i32>) -> TerrainChunk {
|
||||
pub fn generate_chunk(&self, chunk_pos: Vec2<i32>) -> TerrainChunk {
|
||||
// TODO: This is all test code, remove/improve this later.
|
||||
|
||||
let air = Block::empty();
|
||||
@ -47,7 +47,11 @@ impl World {
|
||||
* 1000.0)
|
||||
};
|
||||
|
||||
let offset_z = get_offset(chunk_pos * Vec2::from(TerrainChunkSize::SIZE).map(|e: u32| e as i32));
|
||||
let offset_z = self.sim.get(chunk_pos.map(|e| e as u32))
|
||||
.map(|chunk| chunk.alt as i32)
|
||||
.unwrap_or(0);
|
||||
|
||||
//get_offset(chunk_pos * Vec2::from(TerrainChunkSize::SIZE).map(|e: u32| e as i32));
|
||||
|
||||
let mut chunk = TerrainChunk::new(offset_z as i32, stone, air, TerrainChunkMeta::void());
|
||||
|
||||
|
@ -1,4 +1,10 @@
|
||||
use std::ops::{Mul, Div};
|
||||
use noise::{NoiseFn, OpenSimplex, Seedable};
|
||||
use vek::*;
|
||||
use common::{
|
||||
terrain::TerrainChunkSize,
|
||||
vol::VolSize,
|
||||
};
|
||||
use crate::WORLD_SIZE;
|
||||
|
||||
pub struct WorldSim {
|
||||
@ -14,9 +20,9 @@ impl WorldSim {
|
||||
};
|
||||
|
||||
let mut chunks = Vec::new();
|
||||
for x in 0..WORLD_SIZE.x {
|
||||
for y in 0..WORLD_SIZE.y {
|
||||
chunks.push(SimChunk::generate(&mut gen_ctx));
|
||||
for x in 0..WORLD_SIZE.x as u32 {
|
||||
for y in 0..WORLD_SIZE.y as u32 {
|
||||
chunks.push(SimChunk::generate(Vec2::new(x, y), &mut gen_ctx));
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,20 +31,32 @@ impl WorldSim {
|
||||
chunks,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&self, chunk_pos: Vec2<u32>) -> Option<&SimChunk> {
|
||||
if chunk_pos.map2(WORLD_SIZE, |e, sz| e < sz as u32).reduce_and() {
|
||||
Some(&self.chunks[chunk_pos.y as usize * WORLD_SIZE.x + chunk_pos.x as usize])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct GenCtx {
|
||||
alt_nz: OpenSimplex,
|
||||
}
|
||||
|
||||
struct SimChunk {
|
||||
alt: f32,
|
||||
pub struct SimChunk {
|
||||
pub alt: f32,
|
||||
}
|
||||
|
||||
impl SimChunk {
|
||||
pub fn generate(gen_ctx: &mut GenCtx) -> Self {
|
||||
fn generate(pos: Vec2<u32>, gen_ctx: &mut GenCtx) -> Self {
|
||||
let wposf = (pos * Vec2::from(TerrainChunkSize::SIZE)).map(|e| e as f64);
|
||||
|
||||
Self {
|
||||
alt: 0.0
|
||||
alt: gen_ctx.alt_nz
|
||||
.get((wposf.div(2048.0)).into_array())
|
||||
.mul(512.0) as f32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user