f01463bab3
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.
36 lines
608 B
C++
36 lines
608 B
C++
#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
|