This repository has been archived on 2026-04-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Tortuga/libs/common/network_queue.cpp
T
Kayne Ruse 009e7b845b Fixed network error, leaving try block in place for the time being
It seems that the union type Packet didn't initialize Packet::type to
PacketType::NONE using in class initialization. I've fixed this by moving
the initialization of Packet::type to Packet::Packet().

This might actually be a compiler error, I might need to let someone know.
2013-06-17 09:09:04 +10:00

37 lines
686 B
C++

#include "network_queue.hpp"
#include "service_locator.hpp"
#include "udp_network_utility.hpp"
#include "SDL/SDL_thread.h"
#include <deque>
static SDL_sem* lock = SDL_CreateSemaphore(1);
static std::deque<Packet> queue;
int networkQueue(void*) {
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
for(;;) {
SDL_SemWait(lock);
while(netUtil->Receive()) {
Packet p;
memcpy(&p, netUtil->GetInData(), sizeof(Packet));
queue.push_back(p);
}
SDL_SemPost(lock);
SDL_Delay(10);
}
}
Packet popNetworkPacket() {
SDL_SemWait(lock);
Packet p;
if (queue.size() > 0) {
Packet p = queue[0];
queue.pop_front();
}
SDL_SemPost(lock);
return p;
}