[ServerWorld] Added a timeout to chunk request queue loop.
Also added a 10 sec timeout on individual chunk requests.master
parent
a43c24b3de
commit
03a932c2c4
|
@ -80,7 +80,7 @@ void ServerWorld::updatePlayerChunks(ServerPlayer &player, s32 cx, s32 cy, s32 c
|
|||
player.z()
|
||||
};
|
||||
|
||||
if (glm::length(playerPos - chunkWorldPos) >= (ServerConfig::renderDistance + 1) * CHUNK_WIDTH) {
|
||||
if (glm::length(playerPos - chunkWorldPos) >= (ServerConfig::renderDistance + 3) * CHUNK_WIDTH) {
|
||||
m_server->sendChunkUnload(chunkPos.x, chunkPos.y, chunkPos.z, player.client());
|
||||
chunksToRemove.emplace_back(chunkPos);
|
||||
|
||||
|
@ -171,22 +171,20 @@ bool ServerWorld::generateChunk(ServerChunk &chunk) {
|
|||
|
||||
void ServerWorld::processSendRequests() {
|
||||
// Debug variables
|
||||
u64 chunksGenerated = 0;
|
||||
u64 chunksSent = 0;
|
||||
// u64 chunksBackToQueue = 0;
|
||||
// u64 chunksGenerated = 0;
|
||||
// u64 chunksSent = 0;
|
||||
// u64 chunksTooOld = 0;
|
||||
// u64 startQueueSize = m_chunkSendRequestQueue.size();
|
||||
|
||||
if (!m_chunkSendRequestQueue.empty())
|
||||
gkDebug() << "Processing send requests...";
|
||||
// if (!m_chunkSendRequestQueue.empty())
|
||||
// gkDebug() << "Processing send requests...";
|
||||
|
||||
u64 start = gk::GameClock::getInstance().getTicks(true);
|
||||
u64 now = start;
|
||||
while (/* now - start < 100 && */!m_chunkSendRequestQueue.empty()) {
|
||||
while (now - start < 500 && !m_chunkSendRequestQueue.empty()) {
|
||||
auto &[chunkPos, player, timestamp] = m_chunkSendRequestQueue.front();
|
||||
|
||||
// bool isTooOld = now - timestamp >= 1000;
|
||||
if (/* !isTooOld && */player.sentChunks.find(chunkPos) == player.sentChunks.end()) {
|
||||
bool isTooOld = now - timestamp >= 10000;
|
||||
if (!isTooOld && player.sentChunks.find(chunkPos) == player.sentChunks.end()) {
|
||||
glm::dvec3 chunkWorldPos{
|
||||
chunkPos.x * CHUNK_WIDTH + CHUNK_WIDTH / 2.f,
|
||||
chunkPos.y * CHUNK_DEPTH + CHUNK_DEPTH / 2.f,
|
||||
|
@ -200,17 +198,18 @@ void ServerWorld::processSendRequests() {
|
|||
};
|
||||
|
||||
// bool addChunkBackToQueue = false;
|
||||
if (glm::length(playerPos - chunkWorldPos) < (ServerConfig::renderDistance + 1) * CHUNK_WIDTH) {
|
||||
if (glm::length(playerPos - chunkWorldPos) < (ServerConfig::renderDistance + 2) * CHUNK_WIDTH) {
|
||||
if (player.isOnline() && !player.isChunkLoaded(chunkPos)) {
|
||||
ServerChunk &chunk = getOrCreateChunk(chunkPos.x, chunkPos.y, chunkPos.z);
|
||||
|
||||
chunksGenerated += generateChunk(chunk)
|
||||
+ generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::West))
|
||||
+ generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::East))
|
||||
+ generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::South))
|
||||
+ generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::North))
|
||||
+ generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::Bottom))
|
||||
+ generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::Top));
|
||||
// chunksGenerated +=
|
||||
generateChunk(chunk);
|
||||
generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::West));
|
||||
generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::East));
|
||||
generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::South));
|
||||
generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::North));
|
||||
generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::Bottom));
|
||||
generateChunk((ServerChunk &)*chunk.getSurroundingChunk(Chunk::Top));
|
||||
|
||||
if (!chunk.areAllNeighboursInitialized())
|
||||
gkWarning() << "All neighbours of chunk" << chunkPos << "aren't initialized when they should be";
|
||||
|
@ -221,7 +220,7 @@ void ServerWorld::processSendRequests() {
|
|||
addChunkToProcess(&chunk);
|
||||
player.addLoadedChunk(chunkPos);
|
||||
|
||||
++chunksSent;
|
||||
// ++chunksSent;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,14 +253,14 @@ void ServerWorld::processSendRequests() {
|
|||
now = gk::GameClock::getInstance().getTicks(true);
|
||||
}
|
||||
|
||||
if (now - start > 0) {
|
||||
gkDebug() << "Done in" << now - start << "ms for dim" << m_dimension.id()
|
||||
<< "| Gen:" << chunksGenerated
|
||||
<< "| Sent:" << chunksSent;
|
||||
// << "| BTQ:" << chunksBackToQueue
|
||||
// << "| Old:" << chunksTooOld
|
||||
// << "| QLen:" << startQueueSize << "->" << m_chunkSendRequestQueue.size();
|
||||
}
|
||||
// if (now - start > 0) {
|
||||
// gkDebug() << "Done in" << now - start << "ms for dim" << m_dimension.id()
|
||||
// << "| Gen:" << chunksGenerated
|
||||
// << "| Sent:" << chunksSent
|
||||
// // << "| BTQ:" << chunksBackToQueue
|
||||
// << "| Old:" << chunksTooOld;
|
||||
// // << "| QLen:" << startQueueSize << "->" << m_chunkSendRequestQueue.size();
|
||||
// }
|
||||
}
|
||||
|
||||
// Please update 'docs/lua-api-cpp.md' if you change this
|
||||
|
|
Loading…
Reference in New Issue