mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Adjusted terrain loading and meshing performance
Former-commit-id: b55800b559289bf925d56096f29c0cfbc22439d2
This commit is contained in:
parent
0b0c71592c
commit
f136a63f69
@ -170,6 +170,7 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
|||||||
let mut incoming_buf = Vec::new();
|
let mut incoming_buf = Vec::new();
|
||||||
|
|
||||||
'work: while running.load(Ordering::Relaxed) {
|
'work: while running.load(Ordering::Relaxed) {
|
||||||
|
for _ in 0..30 {
|
||||||
// Get stream errors
|
// Get stream errors
|
||||||
match stream.take_error() {
|
match stream.take_error() {
|
||||||
Ok(Some(e)) | Err(e) => {
|
Ok(Some(e)) | Err(e) => {
|
||||||
@ -180,7 +181,7 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try getting messages from the send channel
|
// Try getting messages from the send channel
|
||||||
for _ in 0..1000 {
|
for _ in 0..100 {
|
||||||
match send_rx.try_recv() {
|
match send_rx.try_recv() {
|
||||||
Ok(send_msg) => {
|
Ok(send_msg) => {
|
||||||
// Serialize message
|
// Serialize message
|
||||||
@ -210,11 +211,15 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try sending bytes through the TCP stream
|
// Try sending bytes through the TCP stream
|
||||||
for _ in 0..1000 {
|
for _ in 0..100 {
|
||||||
//println!("HERE! Outgoing len: {}", outgoing_chunks.len());
|
//println!("HERE! Outgoing len: {}", outgoing_chunks.len());
|
||||||
match outgoing_chunks.pop_front() {
|
match outgoing_chunks.pop_front() {
|
||||||
Some(chunk) => match stream.write_all(&chunk) {
|
Some(mut chunk) => match stream.write(&chunk) {
|
||||||
Ok(()) => {},
|
Ok(n) => if n == chunk.len() {},
|
||||||
|
Ok(n) => {
|
||||||
|
outgoing_chunks.push_front(chunk.split_off(n));
|
||||||
|
break;
|
||||||
|
},
|
||||||
Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
|
Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||||
// Return chunk to the queue to try again later
|
// Return chunk to the queue to try again later
|
||||||
outgoing_chunks.push_front(chunk);
|
outgoing_chunks.push_front(chunk);
|
||||||
@ -222,6 +227,7 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
|||||||
},
|
},
|
||||||
// Worker error
|
// Worker error
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
println!("SEND ERROR: {:?}", e);
|
||||||
recv_tx.send(Err(e.into())).unwrap();
|
recv_tx.send(Err(e.into())).unwrap();
|
||||||
break 'work;
|
break 'work;
|
||||||
},
|
},
|
||||||
@ -231,8 +237,8 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try receiving bytes from the TCP stream
|
// Try receiving bytes from the TCP stream
|
||||||
for _ in 0..1000 {
|
for _ in 0..100 {
|
||||||
let mut buf = [0; 1024];
|
let mut buf = [0; 4096];
|
||||||
|
|
||||||
match stream.read(&mut buf) {
|
match stream.read(&mut buf) {
|
||||||
Ok(n) => incoming_buf.extend_from_slice(&buf[0..n]),
|
Ok(n) => incoming_buf.extend_from_slice(&buf[0..n]),
|
||||||
@ -247,7 +253,7 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try turning bytes into messages
|
// Try turning bytes into messages
|
||||||
for _ in 0..1000 {
|
for _ in 0..100 {
|
||||||
match incoming_buf.get(0..8) {
|
match incoming_buf.get(0..8) {
|
||||||
Some(len_bytes) => {
|
Some(len_bytes) => {
|
||||||
let len = usize::from_le_bytes(<[u8; 8]>::try_from(len_bytes).unwrap()); // Can't fail
|
let len = usize::from_le_bytes(<[u8; 8]>::try_from(len_bytes).unwrap()); // Can't fail
|
||||||
@ -272,6 +278,7 @@ impl<S: PostMsg, R: PostMsg> PostBox<S, R> {
|
|||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
thread::sleep(Duration::from_millis(10));
|
thread::sleep(Duration::from_millis(10));
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ impl<S: Skeleton> FigureState<S> {
|
|||||||
let mat =
|
let mat =
|
||||||
Mat4::<f32>::identity() *
|
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();
|
||||||
|
@ -165,8 +165,10 @@ impl Terrain {
|
|||||||
todo.active_worker = true;
|
todo.active_worker = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Receive chunk meshes from worker threads, upload them to the GPU and then store them
|
// Receive a chunk mesh from a worker thread, upload it to the GPU and then store it
|
||||||
while let Ok(response) = self.mesh_recv.recv_timeout(Duration::new(0, 0)) {
|
// Only pull out one chunk per frame to avoid an unacceptable amount of blocking lag due
|
||||||
|
// to the GPU upload. That still gives us a 60 chunks / second budget to play with.
|
||||||
|
if let Ok(response) = self.mesh_recv.recv_timeout(Duration::new(0, 0)) {
|
||||||
match self.mesh_todo.iter().find(|todo| todo.pos == response.pos) {
|
match self.mesh_todo.iter().find(|todo| todo.pos == response.pos) {
|
||||||
// It's the mesh we want, insert the newly finished model into the terrain model
|
// It's the mesh we want, insert the newly finished model into the terrain model
|
||||||
// data structure (convert the mesh to a model first of course)
|
// data structure (convert the mesh to a model first of course)
|
||||||
@ -180,7 +182,7 @@ impl Terrain {
|
|||||||
},
|
},
|
||||||
// Chunk must have been removed, or it was spawned on an old tick. Drop the mesh
|
// Chunk must have been removed, or it was spawned on an old tick. Drop the mesh
|
||||||
// since it's either out of date or no longer needed
|
// since it's either out of date or no longer needed
|
||||||
_ => continue,
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user