mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:29:50 +00:00
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 and2e7e1c0b2b, all hacks around lag-timeouts (and bits of1a3fb29ff3). 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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user