mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
refactor(server_world): use thread pool for chunk request handling
This commit is contained in:
@@ -516,6 +516,8 @@ glm::vec3 ServerWorld::get_player_pos(const std::string& uuid) const {
|
|||||||
|
|
||||||
void ServerWorld::handle_chunk_req(const std::string& uuid, ChunkPos pos) {
|
void ServerWorld::handle_chunk_req(const std::string& uuid, ChunkPos pos) {
|
||||||
|
|
||||||
|
auto pool = m_gen_thread_pool.load();
|
||||||
|
pool->enqueue([uuid, pos, this]() {
|
||||||
Arena arean;
|
Arena arean;
|
||||||
ChunkDataRsp* rsp = Arena::Create<ChunkDataRsp>(&arean);
|
ChunkDataRsp* rsp = Arena::Create<ChunkDataRsp>(&arean);
|
||||||
auto* rsq_pos = rsp->mutable_pos();
|
auto* rsq_pos = rsp->mutable_pos();
|
||||||
@@ -533,7 +535,8 @@ void ServerWorld::handle_chunk_req(const std::string& uuid, ChunkPos pos) {
|
|||||||
auto& chunk_blocks = it->second.get_chunk_blocks();
|
auto& chunk_blocks = it->second.get_chunk_blocks();
|
||||||
blocks->Assign(chunk_blocks.begin(), chunk_blocks.end());
|
blocks->Assign(chunk_blocks.begin(), chunk_blocks.end());
|
||||||
auto& neighbor_blocks = it->second.get_neightbor_blocks();
|
auto& neighbor_blocks = it->second.get_neightbor_blocks();
|
||||||
auto assign = [](auto* nb,
|
auto assign =
|
||||||
|
[](auto* nb,
|
||||||
const std::optional<std::vector<BlockType>>& blocks) {
|
const std::optional<std::vector<BlockType>>& blocks) {
|
||||||
if (!blocks) {
|
if (!blocks) {
|
||||||
return;
|
return;
|
||||||
@@ -567,6 +570,7 @@ void ServerWorld::handle_chunk_req(const std::string& uuid, ChunkPos pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s->send(make_packet(*rsp));
|
s->send(make_packet(*rsp));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerWorld::handle_block_change(const BlockChangeReq& req) {
|
void ServerWorld::handle_block_change(const BlockChangeReq& req) {
|
||||||
|
|||||||
Reference in New Issue
Block a user