networking i guess
This commit is contained in:
118
game/shared/netmap.h
Normal file
118
game/shared/netmap.h
Normal file
@@ -0,0 +1,118 @@
|
||||
#ifndef NETMAP_H
|
||||
#define NETMAP_H
|
||||
#include "stddef.h"
|
||||
#include "stdint.h"
|
||||
#include "datamap.h"
|
||||
|
||||
struct netfield_t
|
||||
{
|
||||
const char *m_szName;
|
||||
fieldtype_t m_eType;
|
||||
size_t m_uOffset;
|
||||
size_t m_uSize;
|
||||
};
|
||||
|
||||
struct netmap_t
|
||||
{
|
||||
struct netmap_t *m_pBase;
|
||||
netfield_t *m_pFields;
|
||||
uint32_t m_uFieldCount;
|
||||
};
|
||||
|
||||
#define NetPropInt(name) { #name, FIELD_INT, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||
#define NetPropFloat(name) { #name, FIELD_FLOAT, _class_offsetof(ThisClass, name), sizeof(name)}
|
||||
#define NetPropFloat3(name) \
|
||||
NetPropFloat(name.x), \
|
||||
NetPropFloat(name.y), \
|
||||
NetPropFloat(name.z)
|
||||
#define NetPropQuaternion(name) \
|
||||
NetPropFloat(name.x), \
|
||||
NetPropFloat(name.y), \
|
||||
NetPropFloat(name.z), \
|
||||
NetPropFloat(name.w) \
|
||||
|
||||
#define __DECLARE_NETCLASS_NOBASE() \
|
||||
netmap_t *GetBaseSendMap(); \
|
||||
virtual netmap_t *GetSendMap(); \
|
||||
virtual netmap_t SendMapInit(); \
|
||||
netmap_t *GetBaseRecvMap(); \
|
||||
virtual netmap_t *GetRecvMap(); \
|
||||
virtual netmap_t RecvMapInit(); \
|
||||
|
||||
#define __DECLARE_NETCLASS() \
|
||||
netmap_t *GetBaseSendMap(); \
|
||||
virtual netmap_t *GetSendMap() override; \
|
||||
virtual netmap_t SendMapInit() override; \
|
||||
netmap_t *GetBaseRecvMap(); \
|
||||
virtual netmap_t *GetRecvMap() override; \
|
||||
virtual netmap_t RecvMapInit() override; \
|
||||
|
||||
#define DECLARE_SERVERCLASS_NOBASE() \
|
||||
__DECLARE_NETCLASS_NOBASE() \
|
||||
|
||||
#define DECLARE_CLIENTCLASS_NOBASE() \
|
||||
__DECLARE_NETCLASS_NOBASE() \
|
||||
|
||||
#define DECLARE_SERVERCLASS() \
|
||||
__DECLARE_NETCLASS() \
|
||||
|
||||
#define DECLARE_CLIENTCLASS() \
|
||||
__DECLARE_NETCLASS() \
|
||||
|
||||
#define IMPLEMENT_SEND_DT_INTERNAL(className) \
|
||||
netmap_t *className::GetSendMap() { static netmap_t s_DataMap = ThisClass::SendMapInit(); return &s_DataMap; } \
|
||||
netmap_t className::SendMapInit() { \
|
||||
netmap_t map; \
|
||||
map.m_pBase = ThisClass::GetBaseSendMap(); \
|
||||
static netfield_t dataDesc[] \
|
||||
{\
|
||||
|
||||
#define IMPLEMENT_SEND_DT_NOBASE(className) \
|
||||
netmap_t *className::GetBaseSendMap() { return NULL; } \
|
||||
IMPLEMENT_SEND_DT_INTERNAL(className)
|
||||
#define IMPLEMENT_SEND_DT(className) \
|
||||
netmap_t *className::GetBaseSendMap() { return BaseClass::GetSendMap(); } \
|
||||
IMPLEMENT_SEND_DT_INTERNAL(className)
|
||||
|
||||
#define IMPLEMENT_RECV_DT_INTERNAL(className) \
|
||||
netmap_t *className::GetRecvMap() { static netmap_t s_DataMap = ThisClass::RecvMapInit(); return &s_DataMap; } \
|
||||
netmap_t className::RecvMapInit() { \
|
||||
netmap_t map; \
|
||||
map.m_pBase = ThisClass::GetBaseRecvMap(); \
|
||||
static netfield_t dataDesc[] \
|
||||
{\
|
||||
|
||||
#define IMPLEMENT_RECV_DT_NOBASE(className) \
|
||||
netmap_t *className::GetBaseRecvMap() { return NULL; } \
|
||||
IMPLEMENT_RECV_DT_INTERNAL(className)
|
||||
#define IMPLEMENT_RECV_DT(className) \
|
||||
netmap_t *className::GetBaseRecvMap() { return BaseClass::GetRecvMap(); } \
|
||||
IMPLEMENT_RECV_DT_INTERNAL(className)
|
||||
|
||||
#define END_NET_DT_INTERNAL() \
|
||||
}; \
|
||||
map.m_uFieldCount = sizeof(dataDesc)/sizeof(netfield_t); \
|
||||
map.m_pFields = dataDesc; \
|
||||
return map; \
|
||||
}
|
||||
|
||||
#define END_SEND_DT() \
|
||||
END_NET_DT_INTERNAL()
|
||||
#define END_RECV_DT() \
|
||||
END_NET_DT_INTERNAL()
|
||||
|
||||
#define IMPLEMENT_EMPTY_SEND_DT_NOBASE(className) \
|
||||
IMPLEMENT_SEND_DT_NOBASE(className) \
|
||||
END_RECV_DT()
|
||||
#define IMPLEMENT_EMPTY_SEND_DT(className) \
|
||||
IMPLEMENT_SEND_DT(className) \
|
||||
END_RECV_DT()
|
||||
#define IMPLEMENT_EMPTY_RECV_DT_NOBASE(className) \
|
||||
IMPLEMENT_RECV_DT_NOBASE(className) \
|
||||
END_RECV_DT()
|
||||
#define IMPLEMENT_EMPTY_RECV_DT(className) \
|
||||
IMPLEMENT_RECV_DT(className) \
|
||||
END_RECV_DT()
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user