Danbias/Code/Network/NetworkDependencies/Protocols.h

85 lines
1.5 KiB
C
Raw Normal View History

2013-11-21 14:49:30 +01:00
#ifndef NETWORK_DEPENDENCIES_PROTOCOLS_H
#define NETWORK_DEPENDENCIES_PROTOCOLS_H
2013-11-29 09:18:58 +01:00
//////////////////////////////////////
// Created by Sam Svensson 2013
// Holder structs for our protocols
// with the use of union.
// each packagetyp
// is linked to a protocol
//////////////////////////////////////
2013-11-21 14:49:30 +01:00
#include <string>
namespace Oyster
{
namespace Network
{
namespace Protocols
{
enum PackageType
{
2013-11-28 08:40:08 +01:00
PackageType_header,
PackageType_test,
PackageType_input,
PackageType_update_position
};
struct ProtocolHeader
{
int size;
int packageType;
int clientID;
2013-11-28 08:51:21 +01:00
ProtocolHeader() { this->packageType = PackageType_header; }
virtual ~ProtocolHeader() { }
};
struct ProtocolTest : public ProtocolHeader
{
std::string textMessage;
unsigned int numOfFloats;
float *f;
2013-11-28 08:51:21 +01:00
ProtocolTest() { this->packageType = PackageType_test; }
virtual ~ProtocolTest() { delete[] f; }
};
//Holding every protocol in an union.
//Used because we now don't have to type case our protocol when we recieve them.
class ProtocolSet
2013-11-22 09:17:07 +01:00
{
public:
PackageType type;
union
{
ProtocolHeader* pHeader;
ProtocolTest *pTest;
}Protocol;
void Release()
2013-11-22 09:17:07 +01:00
{
switch(type)
{
2013-11-28 08:51:21 +01:00
case PackageType_header:
if(Protocol.pHeader)
{
delete Protocol.pHeader;
}
break;
2013-11-28 08:51:21 +01:00
case PackageType_test:
if(Protocol.pTest)
{
delete Protocol.pTest;
}
break;
}
}
};
}
}
2013-11-21 14:49:30 +01:00
}
#endif