feat(gameplay): add packet to clear all chunks on server rebuild

Add new packet S2C_ClearAllChunks (ID 3005) to notify clients when the server rebuilds its world. Clients respond by clearing their chunk cache and requesting fresh chunks. Shift UPDATE_TIME packet ID to 3006 to accommodate.
This commit is contained in:
2026-06-27 11:20:51 +08:00
parent aace0b4888
commit 7b6c11e904
6 changed files with 53 additions and 4 deletions

View File

@@ -104,6 +104,25 @@ bool ClientWorld::can_pass_block(const glm::ivec3& block_pos) const {
auto id = chunk_blocks[ClientChunk::index(x, y, z)];
return BlockManager::is_passable(id);
}
void ClientWorld::rebuild_world() {
if (m_is_rebuilding.exchange(true)) {
return;
}
stop_thread_pool();
{
std::lock_guard lk(m_chunks_mutex);
m_chunks.clear();
}
{
std::lock_guard lock(m_pending_upload_queue_mutex);
m_pending_upload_queue.clear();
}
start_thread_pool();
request_chunk();
m_is_rebuilding = false;
}
BlockType ClientWorld::get_block_tpye(const glm::ivec3& block_pos) const {
auto [chunk_x, chunk_z] = get_chunk_pos(block_pos.x, block_pos.z);
std::shared_lock lk(m_chunks_mutex);