Added and tested the network queue in the server
This is a reimplementation of the old network queue, but using a class. This still uses a separate thread, so that packets can wait if there's any lag. Really, thinking about it, I wonder how necessary this was. On the upside, no singletons this time. Which means that you can have several instances of UDPNetworkManager. That's unintentional, but good to know.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#ifndef NETWORKQUEUE_HPP_
|
||||
#define NETWORKQUEUE_HPP_
|
||||
|
||||
#include "udp_network_utility.hpp"
|
||||
#include "network_packet.hpp"
|
||||
|
||||
#include "SDL/SDL_thread.h"
|
||||
|
||||
#include <deque>
|
||||
|
||||
class NetworkQueue {
|
||||
public:
|
||||
NetworkQueue() = default;
|
||||
~NetworkQueue() = default;
|
||||
|
||||
void Init(UDPNetworkUtility*);
|
||||
void Quit();
|
||||
void Kill();
|
||||
|
||||
NetworkPacket Peek();
|
||||
NetworkPacket Pop();
|
||||
void Flush();
|
||||
private:
|
||||
friend int networkQueueThread(void*);
|
||||
void ResetMembers();
|
||||
|
||||
bool running = false;
|
||||
|
||||
UDPNetworkUtility* netUtil = nullptr;
|
||||
SDL_sem* lock = nullptr;
|
||||
SDL_Thread* thread = nullptr;
|
||||
std::deque<NetworkPacket> queue;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user