Skip to content

Instantly share code, notes, and snippets.

@SizzlingCalamari
Created October 23, 2015 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SizzlingCalamari/bfa89787d54283d56d72 to your computer and use it in GitHub Desktop.
Save SizzlingCalamari/bfa89787d54283d56d72 to your computer and use it in GitHub Desktop.
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
template<typename BufType, typename FnType, typename ContextType>
bool NetMsgFuncRunner(const FnType* netHandlers, uint32_t type, BufType& buf, ContextType& context, void* data)
{
if (type >= ARRAY_SIZE(netHandlers))
{
return false;
}
return netHandlers[type](buf, context, data);
}
bool NetHandlers::NetMsg_BitRead(uint32_t type, BitRead& bitbuf, SourceGameContext& context, void* data)
{
static const NetMsgBitReadFn netHandlers[] = DECLARE_NET_HANDLER_ARRAY(BitRead);
return NetMsgFuncRunner(netHandlers, type, bitbuf, context, data);
}
bool NetHandlers::NetMsg_BitWrite(uint32_t type, BitWrite& bitbuf, const SourceGameContext& context, void* data)
{
static const NetMsgBitWriteFn netHandlers[] = DECLARE_NET_HANDLER_ARRAY(BitWrite);
return NetMsgFuncRunner(netHandlers, type, bitbuf, context, data);
}
bool NetHandlers::NetMsg_JsonRead(uint32_t type, JsonRead& jsonbuf, SourceGameContext& context, void* data)
{
static const NetMsgJsonReadFn netHandlers[] = DECLARE_NET_HANDLER_ARRAY(JsonRead);
return NetMsgFuncRunner(netHandlers, type, jsonbuf, context, data);
}
bool NetHandlers::NetMsg_JsonWrite(uint32_t type, JsonWrite& jsonbuf, const SourceGameContext& context, void* data)
{
static const NetMsgJsonWriteFn netHandlers[] = DECLARE_NET_HANDLER_ARRAY(JsonWrite);
return NetMsgFuncRunner(netHandlers, type, jsonbuf, context, data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment