Thread the NetClient session.

This threads the netclient session, which avoids timeouts when the
main-thread is not polling (map creation, very long simulation frames).

Unlike the NetServer, which should be as independent as possible from
the main thread, the NetClient is fundamentally tied to the game thread.
Therefore, this only threads the session object.
To ensure good performance and ease-of-use, lock-free queues for
in/out-going messages are used.

This fixes artificial timeouts, while also improving actual ping reports
(since frame-time is no longer a factor).
It effectively reverts D1513/eda236522c and 2e7e1c0b2b, all hacks around
lag-timeouts (and bits of 1a3fb29ff3).

Based on a patch by: Stan
Comments by: Vladislavbelov
Fixes #3700, refs #3373

Differential Revision: https://code.wildfiregames.com/D2848
This was SVN commit r24518.
This commit is contained in:
wraitii
2021-01-06 15:26:11 +00:00
parent 8ae3c09dc0
commit 2d40068cd1
8 changed files with 166 additions and 189 deletions
+8 -6
View File
@@ -25,8 +25,10 @@
#include "ps/CStr.h"
#include <atomic>
#include <ctime>
#include <deque>
#include <thread>
class CGame;
class CNetClientSession;
@@ -128,12 +130,6 @@ public:
*/
void CheckServerConnection();
/**
* Flush any queued outgoing network messages.
* This should be called soon after sending a group of messages that may be batched together.
*/
void Flush();
/**
* Retrieves the next queued GUI message, and removes it from the queue.
* The returned value is in the GetScriptInterface() JS context.
@@ -232,6 +228,10 @@ public:
*/
void SendPausedMessage(bool pause);
/**
* @return Whether the NetClient is shutting down.
*/
bool ShouldShutdown() const;
private:
void SendAuthenticateMessage();
@@ -275,6 +275,8 @@ private:
/// Current network session (or NULL if not connected)
CNetClientSession* m_Session;
std::thread m_PollingThread;
/// Turn manager associated with the current game (or NULL if we haven't started the game yet)
CNetClientTurnManager* m_ClientTurnManager;