Merge branch 'GameClient' of https://github.com/dean11/Danbias into GameServer
This commit is contained in:
commit
efe29b7a18
|
@ -33,184 +33,187 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
|
||||||
Loader loader;
|
Loader loader;
|
||||||
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
|
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
|
||||||
|
|
||||||
//Read format version
|
if(buffer)
|
||||||
LevelLoaderInternal::FormatVersion levelFormatVersion;
|
|
||||||
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion));
|
|
||||||
counter += sizeof(levelFormatVersion);
|
|
||||||
if(this->formatVersion != levelFormatVersion)
|
|
||||||
{
|
{
|
||||||
//Returns an empty vector, because it will most likely fail to read the level format.
|
//Read format version
|
||||||
return objects;
|
LevelLoaderInternal::FormatVersion levelFormatVersion;
|
||||||
}
|
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion));
|
||||||
|
counter += sizeof(levelFormatVersion);
|
||||||
while(counter < bufferSize)
|
if(this->formatVersion != levelFormatVersion)
|
||||||
{
|
|
||||||
loadCgf = true;
|
|
||||||
//Get typeID
|
|
||||||
ObjectType typeID;
|
|
||||||
ParseObject(&buffer[counter], &typeID, sizeof(typeID));
|
|
||||||
switch((int)typeID)
|
|
||||||
{
|
{
|
||||||
case ObjectType_LevelMetaData:
|
//Returns an empty vector, because it will most likely fail to read the level format.
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(counter < bufferSize)
|
||||||
|
{
|
||||||
|
loadCgf = true;
|
||||||
|
//Get typeID
|
||||||
|
ObjectType typeID;
|
||||||
|
ParseObject(&buffer[counter], &typeID, sizeof(typeID));
|
||||||
|
switch((int)typeID)
|
||||||
{
|
{
|
||||||
SmartPointer<ObjectTypeHeader> header = new LevelMetaData;
|
case ObjectType_LevelMetaData:
|
||||||
ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter);
|
|
||||||
objects.push_back(header);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ObjectType_SpawnPoint:
|
|
||||||
{
|
|
||||||
loadCgf = false;
|
|
||||||
ObjectHeader* header = new ObjectHeader;
|
|
||||||
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
|
||||||
|
|
||||||
SpawnPointAttributes* spawn = new SpawnPointAttributes;
|
|
||||||
|
|
||||||
spawn->typeID = header->typeID;
|
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++)
|
|
||||||
{
|
{
|
||||||
spawn->position[i] = header->position[i];
|
SmartPointer<ObjectTypeHeader> header = new LevelMetaData;
|
||||||
|
ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter);
|
||||||
|
objects.push_back(header);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete header;
|
case ObjectType_SpawnPoint:
|
||||||
//objects.push_back(header);
|
|
||||||
objects.push_back(spawn);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//This is by design, static and dynamic is using the same converter. Do not add anything inbetween them.
|
|
||||||
//Unless they are changed to not be the same.
|
|
||||||
case ObjectType_Static: case ObjectType_Dynamic:
|
|
||||||
{
|
|
||||||
//Get specialType.
|
|
||||||
ObjectSpecialType specialType;
|
|
||||||
ParseObject(&buffer[counter+4], &specialType, sizeof(typeID));
|
|
||||||
|
|
||||||
switch(specialType)
|
|
||||||
{
|
{
|
||||||
//there is no difference when parsing these specialTypes.
|
loadCgf = false;
|
||||||
case ObjectSpecialType_CrystalShard:
|
ObjectHeader* header = new ObjectHeader;
|
||||||
case ObjectSpecialType_CrystalFormation:
|
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
||||||
case ObjectSpecialType_Spike:
|
|
||||||
case ObjectSpecialType_SpikeBox:
|
|
||||||
case ObjectSpecialType_RedExplosiveBox:
|
|
||||||
case ObjectSpecialType_StandarsBox:
|
|
||||||
case ObjectSpecialType_Stone:
|
|
||||||
case ObjectSpecialType_Building:
|
|
||||||
{
|
|
||||||
ObjectHeader* header = new ObjectHeader;
|
|
||||||
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
|
||||||
objects.push_back(header);
|
|
||||||
|
|
||||||
break;
|
SpawnPointAttributes* spawn = new SpawnPointAttributes;
|
||||||
|
|
||||||
|
spawn->typeID = header->typeID;
|
||||||
|
|
||||||
|
for(int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
spawn->position[i] = header->position[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
case ObjectSpecialType_JumpPad:
|
delete header;
|
||||||
|
//objects.push_back(header);
|
||||||
|
objects.push_back(spawn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//This is by design, static and dynamic is using the same converter. Do not add anything inbetween them.
|
||||||
|
//Unless they are changed to not be the same.
|
||||||
|
case ObjectType_Static: case ObjectType_Dynamic:
|
||||||
|
{
|
||||||
|
//Get specialType.
|
||||||
|
ObjectSpecialType specialType;
|
||||||
|
ParseObject(&buffer[counter+4], &specialType, sizeof(typeID));
|
||||||
|
|
||||||
|
switch(specialType)
|
||||||
{
|
{
|
||||||
JumpPadAttributes* header = new JumpPadAttributes;
|
//there is no difference when parsing these specialTypes.
|
||||||
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
case ObjectSpecialType_CrystalShard:
|
||||||
|
case ObjectSpecialType_CrystalFormation:
|
||||||
|
case ObjectSpecialType_Spike:
|
||||||
|
case ObjectSpecialType_SpikeBox:
|
||||||
|
case ObjectSpecialType_RedExplosiveBox:
|
||||||
|
case ObjectSpecialType_StandarsBox:
|
||||||
|
case ObjectSpecialType_Stone:
|
||||||
|
case ObjectSpecialType_Building:
|
||||||
|
{
|
||||||
|
ObjectHeader* header = new ObjectHeader;
|
||||||
|
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
||||||
|
objects.push_back(header);
|
||||||
|
|
||||||
//Read the spec
|
break;
|
||||||
ParseObject(&buffer[counter], header->direction, 16);
|
}
|
||||||
counter += 16;
|
|
||||||
objects.push_back(header);
|
|
||||||
|
|
||||||
break;
|
case ObjectSpecialType_JumpPad:
|
||||||
|
{
|
||||||
|
JumpPadAttributes* header = new JumpPadAttributes;
|
||||||
|
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
||||||
|
|
||||||
|
//Read the spec
|
||||||
|
ParseObject(&buffer[counter], header->direction, 16);
|
||||||
|
counter += 16;
|
||||||
|
objects.push_back(header);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ObjectSpecialType_Portal:
|
||||||
|
{
|
||||||
|
PortalAttributes* header = new PortalAttributes;
|
||||||
|
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
||||||
|
|
||||||
|
ParseObject(&buffer[counter], header->destination, 12);
|
||||||
|
counter += 12;
|
||||||
|
objects.push_back(header);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ObjectSpecialType_World:
|
||||||
|
{
|
||||||
|
WorldAttributes* header = new WorldAttributes;
|
||||||
|
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
||||||
|
|
||||||
|
ParseObject(&buffer[counter], &header->worldSize, 8);
|
||||||
|
counter += 8;
|
||||||
|
objects.push_back(header);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ObjectSpecialType_Sky:
|
||||||
|
{
|
||||||
|
loadCgf = false;
|
||||||
|
SkyAttributes* header = new SkyAttributes;
|
||||||
|
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
||||||
|
|
||||||
|
ParseObject(&buffer[counter], &header->skySize, 4);
|
||||||
|
counter += 4;
|
||||||
|
objects.push_back(header);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//this is a hotfix, fix so you only load the relevant data when the file is updated
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
//Couldn't find specialType
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ObjectSpecialType_Portal:
|
case ObjectType_Light:
|
||||||
|
{
|
||||||
|
LightType lightType;
|
||||||
|
|
||||||
|
//Get Light type
|
||||||
|
ParseObject(&buffer[counter+4], &lightType, sizeof(lightType));
|
||||||
|
|
||||||
|
//We only support PointLight for now.
|
||||||
|
BasicLight* header = new BasicLight;
|
||||||
|
ParseObject(&buffer[counter], header, sizeof(*header));
|
||||||
|
counter += sizeof(*header);
|
||||||
|
objects.push_back(header);
|
||||||
|
/*switch(lightType)
|
||||||
{
|
{
|
||||||
PortalAttributes* header = new PortalAttributes;
|
case LightType_PointLight:
|
||||||
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
|
||||||
|
|
||||||
ParseObject(&buffer[counter], header->destination, 12);
|
|
||||||
counter += 12;
|
|
||||||
objects.push_back(header);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ObjectSpecialType_World:
|
|
||||||
{
|
{
|
||||||
WorldAttributes* header = new WorldAttributes;
|
PointLight* header = new PointLight;
|
||||||
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
ParseObject(&buffer[counter], header, sizeof(*header));
|
||||||
|
counter += sizeof(*header);
|
||||||
ParseObject(&buffer[counter], &header->worldSize, 8);
|
|
||||||
counter += 8;
|
|
||||||
objects.push_back(header);
|
objects.push_back(header);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case LightType_DirectionalLight:
|
||||||
case ObjectSpecialType_Sky:
|
|
||||||
{
|
{
|
||||||
loadCgf = false;
|
DirectionalLight* header = new DirectionalLight;
|
||||||
SkyAttributes* header = new SkyAttributes;
|
ParseObject(&buffer[counter], header, sizeof(*header));
|
||||||
ParseObject(&buffer[counter], *header, counter, loadCgf);
|
counter += sizeof(*header);
|
||||||
|
objects.push_back(header);
|
||||||
ParseObject(&buffer[counter], &header->skySize, 4);
|
break;
|
||||||
counter += 4;
|
}
|
||||||
|
case LightType_SpotLight:
|
||||||
|
{
|
||||||
|
SpotLight* header = new SpotLight;
|
||||||
|
ParseObject(&buffer[counter], header, sizeof(*header));
|
||||||
|
counter += sizeof(*header);
|
||||||
objects.push_back(header);
|
objects.push_back(header);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//this is a hotfix, fix so you only load the relevant data when the file is updated
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
//Couldn't find specialType
|
//Undefined LightType.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;*/
|
||||||
}
|
|
||||||
|
|
||||||
case ObjectType_Light:
|
|
||||||
{
|
|
||||||
LightType lightType;
|
|
||||||
|
|
||||||
//Get Light type
|
|
||||||
ParseObject(&buffer[counter+4], &lightType, sizeof(lightType));
|
|
||||||
|
|
||||||
//We only support PointLight for now.
|
|
||||||
BasicLight* header = new BasicLight;
|
|
||||||
ParseObject(&buffer[counter], header, sizeof(*header));
|
|
||||||
counter += sizeof(*header);
|
|
||||||
objects.push_back(header);
|
|
||||||
/*switch(lightType)
|
|
||||||
{
|
|
||||||
case LightType_PointLight:
|
|
||||||
{
|
|
||||||
PointLight* header = new PointLight;
|
|
||||||
ParseObject(&buffer[counter], header, sizeof(*header));
|
|
||||||
counter += sizeof(*header);
|
|
||||||
objects.push_back(header);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case LightType_DirectionalLight:
|
|
||||||
{
|
|
||||||
DirectionalLight* header = new DirectionalLight;
|
|
||||||
ParseObject(&buffer[counter], header, sizeof(*header));
|
|
||||||
counter += sizeof(*header);
|
|
||||||
objects.push_back(header);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case LightType_SpotLight:
|
|
||||||
{
|
|
||||||
SpotLight* header = new SpotLight;
|
|
||||||
ParseObject(&buffer[counter], header, sizeof(*header));
|
|
||||||
counter += sizeof(*header);
|
|
||||||
objects.push_back(header);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
//Undefined LightType.
|
//Couldn't find typeID. FAIL!!!!!!
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
break;*/
|
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
//Couldn't find typeID. FAIL!!!!!!
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -317,6 +317,11 @@ bool NetworkClient::Connect(unsigned short port, std::wstring serverIP)
|
||||||
return this->Connect(port, ip.c_str());
|
return this->Connect(port, ip.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NetworkClient::Reconnect()
|
||||||
|
{
|
||||||
|
return this->privateData->connection.Reconnect();
|
||||||
|
}
|
||||||
|
|
||||||
void NetworkClient::Disconnect()
|
void NetworkClient::Disconnect()
|
||||||
{
|
{
|
||||||
if(!privateData) return;
|
if(!privateData) return;
|
||||||
|
|
|
@ -93,6 +93,11 @@ namespace Oyster
|
||||||
*/
|
*/
|
||||||
bool Connect(unsigned short port, std::wstring serverIP);
|
bool Connect(unsigned short port, std::wstring serverIP);
|
||||||
|
|
||||||
|
/**Tries to connect with the same port and ip it earlier used for Connect.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool Reconnect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -58,6 +58,9 @@ int Connection::Connect(unsigned short port , const char serverName[], bool bloc
|
||||||
{
|
{
|
||||||
if(this->socket == -1 || this->socket == 0) InitiateSocket();
|
if(this->socket == -1 || this->socket == 0) InitiateSocket();
|
||||||
|
|
||||||
|
lastConnectPort = port;
|
||||||
|
lastConnectAddr = serverName;
|
||||||
|
|
||||||
struct hostent *hostEnt;
|
struct hostent *hostEnt;
|
||||||
if((hostEnt = gethostbyname(serverName)) == NULL)
|
if((hostEnt = gethostbyname(serverName)) == NULL)
|
||||||
{
|
{
|
||||||
|
@ -83,6 +86,37 @@ int Connection::Connect(unsigned short port , const char serverName[], bool bloc
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Connection::Reconnect()
|
||||||
|
{
|
||||||
|
if(this->socket == -1 || this->socket == 0) InitiateSocket();
|
||||||
|
|
||||||
|
struct hostent *hostEnt;
|
||||||
|
if((hostEnt = gethostbyname(lastConnectAddr.c_str())) == NULL)
|
||||||
|
{
|
||||||
|
return WSAGetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in server;
|
||||||
|
server.sin_family = AF_INET;
|
||||||
|
server.sin_port = htons(lastConnectPort);
|
||||||
|
server.sin_addr.s_addr = *(unsigned long*) hostEnt->h_addr;
|
||||||
|
|
||||||
|
SetBlockingMode(true);
|
||||||
|
|
||||||
|
if(connect(this->socket, (sockaddr*)&server, sizeof(server)) == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
return WSAGetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
|
closed = false;
|
||||||
|
stillSending = true;
|
||||||
|
|
||||||
|
SetBlockingMode(blocking);
|
||||||
|
|
||||||
|
//connection succesfull!
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int Connection::InitiateServer(unsigned short port)
|
int Connection::InitiateServer(unsigned short port)
|
||||||
{
|
{
|
||||||
int errorCode = 0;
|
int errorCode = 0;
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace Oyster
|
||||||
virtual int Disconnect();
|
virtual int Disconnect();
|
||||||
virtual int Connect(ConnectionInfo info, bool blocking = false);
|
virtual int Connect(ConnectionInfo info, bool blocking = false);
|
||||||
virtual int Connect(unsigned short port , const char serverName[], bool blocking = false);
|
virtual int Connect(unsigned short port , const char serverName[], bool blocking = false);
|
||||||
|
virtual int Reconnect();
|
||||||
|
|
||||||
virtual ConnectionInfo Listen();
|
virtual ConnectionInfo Listen();
|
||||||
|
|
||||||
|
@ -47,6 +48,11 @@ namespace Oyster
|
||||||
bool stillSending;
|
bool stillSending;
|
||||||
bool closed;
|
bool closed;
|
||||||
std::string addr;
|
std::string addr;
|
||||||
|
|
||||||
|
std::string lastConnectAddr;
|
||||||
|
unsigned short lastConnectPort;
|
||||||
|
|
||||||
|
bool blocking;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ namespace Oyster
|
||||||
//(servers uses Listen instead of connect)
|
//(servers uses Listen instead of connect)
|
||||||
virtual int Connect( unsigned short port, const char serverName[] ) { return false; };
|
virtual int Connect( unsigned short port, const char serverName[] ) { return false; };
|
||||||
|
|
||||||
|
//Tries to connect with the same port and ip used for Connect.
|
||||||
|
virtual int Reconnect() = 0;
|
||||||
|
|
||||||
//Disconnects the client or server TODO: optimize!
|
//Disconnects the client or server TODO: optimize!
|
||||||
virtual int Disconnect() = 0;
|
virtual int Disconnect() = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue