mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Started work on worldgen
Former-commit-id: 277a4b2a0a5a393c590a710aebaf62e5cce2ad1d
This commit is contained in:
parent
837ba99d2a
commit
f9f434a1c2
@ -147,7 +147,7 @@ impl Client {
|
|||||||
frontend_events.append(&mut self.handle_new_messages()?);
|
frontend_events.append(&mut self.handle_new_messages()?);
|
||||||
|
|
||||||
self.state.terrain().iter().for_each(|(k, _)| {
|
self.state.terrain().iter().for_each(|(k, _)| {
|
||||||
println!("Chunk at {:?}", k);
|
//println!("Chunk at {:?}", k);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.state.write_component(
|
self.state.write_component(
|
||||||
@ -194,9 +194,9 @@ impl Client {
|
|||||||
{
|
{
|
||||||
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));
|
||||||
|
|
||||||
for i in chunk_pos.x - 1..chunk_pos.x + 1 {
|
for i in chunk_pos.x - 2..chunk_pos.x + 2 {
|
||||||
for j in chunk_pos.y - 1..chunk_pos.y + 1 {
|
for j in chunk_pos.y - 2..chunk_pos.y + 2 {
|
||||||
for k in -1..3 {
|
for k in 0..1 {
|
||||||
let key = chunk_pos + Vec3::new(i, j, k);
|
let key = chunk_pos + Vec3::new(i, j, k);
|
||||||
if self.state.terrain().get_key(key).is_none()
|
if self.state.terrain().get_key(key).is_none()
|
||||||
&& !self.pending_chunks.contains(&key)
|
&& !self.pending_chunks.contains(&key)
|
||||||
|
@ -73,6 +73,7 @@ impl<V: Vox + Clone, S: VolSize, M> SampleVol for VolMap<V, S, M> {
|
|||||||
/// Note that the resultant volume does not carry forward metadata from the original chunks.
|
/// Note that the resultant volume does not carry forward metadata from the original chunks.
|
||||||
fn sample(&self, range: Aabb<i32>) -> Result<Self::Sample, VolMapErr> {
|
fn sample(&self, range: Aabb<i32>) -> Result<Self::Sample, VolMapErr> {
|
||||||
// Return early if we don't have all the needed chunks that we need!
|
// Return early if we don't have all the needed chunks that we need!
|
||||||
|
/*
|
||||||
let min_chunk = Self::chunk_key(range.min);
|
let min_chunk = Self::chunk_key(range.min);
|
||||||
let max_chunk = Self::chunk_key(range.max - Vec3::one());
|
let max_chunk = Self::chunk_key(range.max - Vec3::one());
|
||||||
for x in min_chunk.x..=max_chunk.x {
|
for x in min_chunk.x..=max_chunk.x {
|
||||||
@ -84,6 +85,7 @@ impl<V: Vox + Clone, S: VolSize, M> SampleVol for VolMap<V, S, M> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
let mut sample = Dyna::filled(
|
let mut sample = Dyna::filled(
|
||||||
range.size().map(|e| e as u32).into(),
|
range.size().map(|e| e as u32).into(),
|
||||||
@ -92,7 +94,7 @@ impl<V: Vox + Clone, S: VolSize, M> SampleVol for VolMap<V, S, M> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for pos in sample.iter_positions() {
|
for pos in sample.iter_positions() {
|
||||||
sample.set(pos, self.get(range.min + pos)?.clone())
|
sample.set(pos, self.get(range.min + pos).map(|v| v.clone()).unwrap_or(V::empty()))
|
||||||
.map_err(|err| VolMapErr::DynaErr(err))?;
|
.map_err(|err| VolMapErr::DynaErr(err))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,6 +182,7 @@ impl Server {
|
|||||||
// Fetch any generated `TerrainChunk`s and insert them into the terrain
|
// Fetch any generated `TerrainChunk`s and insert them into the terrain
|
||||||
// Also, send the chunk data to anybody that is close by
|
// Also, send the chunk data to anybody that is close by
|
||||||
for (key, chunk) in self.chunk_rx.try_iter() {
|
for (key, chunk) in self.chunk_rx.try_iter() {
|
||||||
|
println!("Generation finished {:?}", key);
|
||||||
// Send the chunk to all nearby players
|
// Send the chunk to all nearby players
|
||||||
for (entity, player, pos) in (
|
for (entity, player, pos) in (
|
||||||
&self.state.ecs().entities(),
|
&self.state.ecs().entities(),
|
||||||
@ -193,12 +194,11 @@ impl Server {
|
|||||||
// TODO: Distance check
|
// TODO: Distance check
|
||||||
// if self.state.terrain().key_pos(key)
|
// if self.state.terrain().key_pos(key)
|
||||||
|
|
||||||
/*
|
println!("Send to player {:?}", key);
|
||||||
self.clients.notify(entity, ServerMsg::TerrainChunkUpdate {
|
self.clients.notify(entity, ServerMsg::TerrainChunkUpdate {
|
||||||
key,
|
key,
|
||||||
chunk: Box::new(chunk.clone()),
|
chunk: Box::new(chunk.clone()),
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.state.insert_chunk(key, chunk);
|
self.state.insert_chunk(key, chunk);
|
||||||
@ -322,10 +322,10 @@ impl Server {
|
|||||||
}
|
}
|
||||||
ClientState::Spectator | ClientState::Character => {
|
ClientState::Spectator | ClientState::Character => {
|
||||||
match state.terrain().get_key(key) {
|
match state.terrain().get_key(key) {
|
||||||
Some(chunk) => {} /*client.postbox.send_message(ServerMsg::TerrainChunkUpdate {
|
Some(chunk) => client.postbox.send_message(ServerMsg::TerrainChunkUpdate {
|
||||||
key,
|
key,
|
||||||
chunk: Box::new(chunk.clone()),
|
chunk: Box::new(chunk.clone()),
|
||||||
}),*/
|
}),
|
||||||
None => requested_chunks.push(key),
|
None => requested_chunks.push(key),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,14 +99,22 @@ impl Terrain {
|
|||||||
// What happens if the block on the edge of a chunk gets modified? We need to spawn
|
// What happens if the block on the edge of a chunk gets modified? We need to spawn
|
||||||
// a mesh worker to remesh its neighbour(s) too since their ambient occlusion and face
|
// a mesh worker to remesh its neighbour(s) too since their ambient occlusion and face
|
||||||
// elision information changes too!
|
// elision information changes too!
|
||||||
match self.mesh_todo.iter_mut().find(|todo| todo.pos == *pos) {
|
for i in -1..2 {
|
||||||
Some(todo) => todo.started_tick = current_tick,
|
for j in -1..2 {
|
||||||
// The chunk it's queued yet, add it to the queue
|
for k in -1..2 {
|
||||||
None => self.mesh_todo.push_back(ChunkMeshState {
|
let pos = pos + Vec3::new(i, j, k);
|
||||||
pos: *pos,
|
|
||||||
started_tick: current_tick,
|
match self.mesh_todo.iter_mut().find(|todo| todo.pos == pos) {
|
||||||
active_worker: false,
|
Some(todo) => todo.started_tick = current_tick,
|
||||||
}),
|
// The chunk it's queued yet, add it to the queue
|
||||||
|
None => self.mesh_todo.push_back(ChunkMeshState {
|
||||||
|
pos,
|
||||||
|
started_tick: current_tick,
|
||||||
|
active_worker: false,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user