mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Worked on improving networking and terrain
Former-commit-id: e5ce819036a01f274c1c114bcd3b50fa42858703
This commit is contained in:
parent
927f3a12ba
commit
fc8b7e9750
@ -194,9 +194,9 @@ impl Client {
|
||||
{
|
||||
let chunk_pos = self.state.terrain().pos_key(pos.0.map(|e| e as i32));
|
||||
|
||||
for i in chunk_pos.x - 3..chunk_pos.x + 3 {
|
||||
for j in chunk_pos.y - 3..chunk_pos.y + 3 {
|
||||
for k in 0..1 {
|
||||
for i in chunk_pos.x - 1..chunk_pos.x + 1 {
|
||||
for j in chunk_pos.y - 1..chunk_pos.y + 1 {
|
||||
for k in 0..2 {
|
||||
let key = Vec3::new(i, j, k);
|
||||
if self.state.terrain().get_key(key).is_none()
|
||||
&& !self.pending_chunks.contains(&key)
|
||||
|
@ -73,6 +73,7 @@ impl<S: PostMsg, R: PostMsg> PostOffice<S, R> {
|
||||
match self.listener.accept() {
|
||||
Ok((stream, sock)) => new.push(PostBox::from_stream(stream).unwrap()),
|
||||
Err(e) if e.kind() == io::ErrorKind::WouldBlock => break,
|
||||
Err(e) if e.kind() == io::ErrorKind::Interrupted => {},
|
||||
Err(e) => {
|
||||
self.error = Some(e.into());
|
||||
break;
|
||||
@ -179,7 +180,7 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
||||
}
|
||||
|
||||
// Try getting messages from the send channel
|
||||
for _ in 0..100 {
|
||||
for _ in 0..1000 {
|
||||
match send_rx.try_recv() {
|
||||
Ok(send_msg) => {
|
||||
// Serialize message
|
||||
@ -209,7 +210,7 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
||||
}
|
||||
|
||||
// Try sending bytes through the TCP stream
|
||||
for _ in 0..100 {
|
||||
for _ in 0..1000 {
|
||||
//println!("HERE! Outgoing len: {}", outgoing_chunks.len());
|
||||
match outgoing_chunks.pop_front() {
|
||||
Some(chunk) => match stream.write_all(&chunk) {
|
||||
@ -230,12 +231,13 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
||||
}
|
||||
|
||||
// Try receiving bytes from the TCP stream
|
||||
for _ in 0..100 {
|
||||
for _ in 0..1000 {
|
||||
let mut buf = [0; 1024];
|
||||
|
||||
match stream.read(&mut buf) {
|
||||
Ok(n) => incoming_buf.extend_from_slice(&buf[0..n]),
|
||||
Err(e) if e.kind() == io::ErrorKind::WouldBlock => break,
|
||||
Err(e) if e.kind() == io::ErrorKind::Interrupted => {},
|
||||
// Worker error
|
||||
Err(e) => {
|
||||
recv_tx.send(Err(e.into())).unwrap();
|
||||
@ -245,7 +247,7 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
||||
}
|
||||
|
||||
// Try turning bytes into messages
|
||||
for _ in 0..100 {
|
||||
for _ in 0..1000 {
|
||||
match incoming_buf.get(0..8) {
|
||||
Some(len_bytes) => {
|
||||
let len = usize::from_le_bytes(<[u8; 8]>::try_from(len_bytes).unwrap()); // Can't fail
|
||||
@ -254,13 +256,14 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
||||
recv_tx.send(Err(Error::InvalidMessage)).unwrap();
|
||||
break 'work;
|
||||
} else if incoming_buf.len() >= len + 8 {
|
||||
let deserialize_result = bincode::deserialize(&incoming_buf[8..len + 8]);
|
||||
|
||||
if let Err(e) = &deserialize_result {
|
||||
println!("DESERIALIZE ERROR: {:?}", e);
|
||||
match bincode::deserialize(&incoming_buf[8..len + 8]) {
|
||||
Ok(msg) => recv_tx.send(Ok(msg)).unwrap(),
|
||||
Err(err) => {
|
||||
println!("Invalid message: {:?}", err);
|
||||
recv_tx.send(Err(err.into())).unwrap()
|
||||
},
|
||||
}
|
||||
|
||||
recv_tx.send(deserialize_result.map_err(|e| e.into()));
|
||||
incoming_buf = incoming_buf.split_off(len + 8);
|
||||
} else {
|
||||
break;
|
||||
|
@ -40,10 +40,15 @@ impl World {
|
||||
let wpos = lpos + chunk_pos * chunk.get_size().map(|e| e as i32);
|
||||
let wposf = wpos.map(|e| e as f64);
|
||||
|
||||
let freq = 1.0 / 64.0;
|
||||
let ampl = 12.0;
|
||||
let offs = 16.0;
|
||||
let height = perlin_nz.get(Vec2::from(wposf * freq).into_array()) * ampl + offs;
|
||||
let freq = 1.0 / 128.0;
|
||||
let ampl = 32.0;
|
||||
let small_freq = 1.0 / 16.0;
|
||||
let small_ampl = 8.0;
|
||||
let offs = 32.0;
|
||||
let height =
|
||||
perlin_nz.get(Vec2::from(wposf * freq).into_array()) * ampl
|
||||
+ perlin_nz.get(Vec2::from(wposf * small_freq).into_array()) * small_ampl
|
||||
+ offs;
|
||||
|
||||
chunk.set(lpos, if wposf.z < height {
|
||||
if wposf.z < height - 1.0 {
|
||||
|
Loading…
Reference in New Issue
Block a user