handmade/include/Server.h
Bubblegumdrop 60e282929f Add a "SafeUDPpacket" and "SafeUDPpacketV" class.
I'm trying to merge UDPpacketVBuffer and SafeUDPpacketV.

Seems pretty messy so far... hopefully this is fruitful.
2022-01-16 14:40:20 -05:00

56 lines
1.2 KiB
C++

#pragma once
#include <string>
#include <vector>
#include "lib_lua_common.h"
#include "UDPbase.h"
/*
* Used as mFetchPacketsCallbackTimerID timeout
*/
#define DEFAULT_SOCKET_TIMEOUT 10
class Server : public UDPbase
{
SDL_mutex* mProcessPacketMutex;
SDL_TimerID mFetchPacketsCallbackTimerID;
SDLNet_SocketSet SocketSet;
UDPpacket** packetV;
lua_State *mLuaState;
public:
Server (const char* host, const Uint16 port);
~Server (void);
/*
* error: invalid use of non-static member function Uint32 Server::FetchPacketsCallback(Uint32, void*)
* Don't understand this.
* static keyword fixes it.
*/
static Uint32 FetchPacketsCallback (Uint32 interval, void* param);
void ProcessPacketHelper (UDPpacket* packet);
void RunLua (const std::string& buf);
int AllocateApproximateResources (const int nclients);
int Start (void);
int Stop (void);
int Lock (void)
{
return SDL_LockMutex (mProcessPacketMutex);
}
int Unlock (void)
{
return SDL_UnlockMutex (mProcessPacketMutex);
}
lua_State* getLuaState(void) { return mLuaState; }
UDPsocket getUDPsock (size_t idx) { return UDPsocks.at (idx); }
UDPpacket** getPacketV (void) { return packetV; }
SDLNet_SocketSet getSocketSet (void) { return SocketSet; }
};