Created
August 2, 2018 21:59
-
-
Save zesterer/a52af72a2469861ef31bf09fc0b81b03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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