| 251 | } |
| 252 | |
| 253 | void WorldServerThread::update(WorldServerFidelity fidelity) { |
| 254 | RecursiveMutexLocker locker(m_mutex); |
| 255 | auto unerroredClientIds = m_worldServer->clientIds(); |
| 256 | for (auto clientId : unerroredClientIds) { |
| 257 | RecursiveMutexLocker queueLocker(m_queueMutex); |
| 258 | auto incomingPackets = take(m_incomingPacketQueue[clientId]); |
| 259 | queueLocker.unlock(); |
| 260 | try { |
| 261 | m_worldServer->handleIncomingPackets(clientId, std::move(incomingPackets)); |
| 262 | } catch (std::exception const& e) { |
| 263 | Logger::error("WorldServerThread exception caught handling incoming packets for client {}: {}", |
| 264 | clientId, outputException(e, true)); |
| 265 | RecursiveMutexLocker queueLocker(m_queueMutex); |
| 266 | m_outgoingPacketQueue[clientId].appendAll(m_worldServer->removeClient(clientId)); |
| 267 | unerroredClientIds.remove(clientId); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | float dt = ServerGlobalTimestep * GlobalTimescale; |
| 272 | m_worldServer->setFidelity(fidelity); |
| 273 | if (dt > 0.0f && (!m_pause || *m_pause == false)) |
| 274 | m_worldServer->update(dt); |
| 275 | |
| 276 | List<Message> messages; |
| 277 | { |
| 278 | RecursiveMutexLocker locker(m_messageMutex); |
| 279 | messages = std::move(m_messages); |
| 280 | } |
| 281 | for (auto& message : messages) { |
| 282 | if (auto resp = m_worldServer->receiveMessage(ServerConnectionId, message.message, message.args)) |
| 283 | message.promise.fulfill(*resp); |
| 284 | else |
| 285 | message.promise.fail("Message not handled by world"); |
| 286 | } |
| 287 | |
| 288 | for (auto& clientId : unerroredClientIds) { |
| 289 | auto outgoingPackets = m_worldServer->getOutgoingPackets(clientId); |
| 290 | RecursiveMutexLocker queueLocker(m_queueMutex); |
| 291 | m_outgoingPacketQueue[clientId].appendAll(std::move(outgoingPackets)); |
| 292 | } |
| 293 | |
| 294 | m_shouldExpire = m_worldServer->shouldExpire(); |
| 295 | |
| 296 | if (m_updateAction) |
| 297 | m_updateAction(this, m_worldServer.get()); |
| 298 | } |
| 299 | |
| 300 | void WorldServerThread::sync() { |
| 301 | RecursiveMutexLocker locker(m_mutex); |
nothing calls this directly
no test coverage detected