Skip to content

Instantly share code, notes, and snippets.

@zesterer
Created August 2, 2018 21:59
Show Gist options
  • Save zesterer/a52af72a2469861ef31bf09fc0b81b03 to your computer and use it in GitHub Desktop.
Save zesterer/a52af72a2469861ef31bf09fc0b81b03 to your computer and use it in GitHub Desktop.
fn start_networking (remote: &str) {
let mut threadpool = ThreadPool::new(10);
let mut postoffice = PostOffice::new(remote);
while let Ok(req) = postoffice.await_new() {
threadpool.exec(move || {
match req {
Req::Chunk(postbox) => handle_chunk_req(postbox),
Req::Entity(postbox) => handle_entity_req(postbox),
Req::Inventory(postbox) => handle_inventory_req(postbox),
}
});
}
}
fn handle_chunk_req(postbox: PostBox<ChunkMsg>) {
while let Ok(reply) = postbox.await() {
match reply {
ChunkMsg::GetVolumeData(pos) => postbox.send(self.chunk_mgr.get_volume_data(pos)),
}
}
}
fn handle_entity_req(postbox: PostBox<EntityMsg>) {
while let Ok(reply) = postbox.await() {
match reply {
EntityMsg::PlayerUpdate { pos, vel } => self.entity(postbox.client.entity_id).update(pos, vel),
EntityMsg::WhoIs(entity_id) => postbox.send(EntityMsg::EntityDetails { name: self.entity(entity_id).get_name() }),
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment