2014-02-10 14:00:14 +01:00
|
|
|
|
//////////////////////////////////
|
|
|
|
|
// Created by Sam Svensson 2013 //
|
|
|
|
|
//////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "ParseFunctions.h"
|
2014-02-12 14:48:58 +01:00
|
|
|
|
#include "Loader.h"
|
2014-02-10 14:00:14 +01:00
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using namespace GameLogic::LevelFileLoader;
|
|
|
|
|
using namespace GameLogic;
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
namespace GameLogic
|
|
|
|
|
{
|
|
|
|
|
namespace LevelFileLoader
|
|
|
|
|
{
|
2014-02-12 14:48:58 +01:00
|
|
|
|
//can parse any struct if the struct doesnt contain strings or char[]
|
2014-02-10 14:00:14 +01:00
|
|
|
|
void ParseObject(char* buffer, void *header, int size)
|
|
|
|
|
{
|
|
|
|
|
memcpy(header, buffer, size);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
|
void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf)
|
2014-02-10 14:00:14 +01:00
|
|
|
|
{
|
|
|
|
|
char tempName[128];
|
|
|
|
|
unsigned int tempSize = 0;
|
|
|
|
|
int start = 0;
|
|
|
|
|
|
|
|
|
|
memcpy(&header.typeID, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
|
memcpy(&header.specialTypeID, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
header.ModelFile.assign(&tempName[0], &tempName[tempSize]);
|
|
|
|
|
start += tempSize;
|
|
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
|
//The reset of the object struct
|
2014-02-10 14:00:14 +01:00
|
|
|
|
//3 float[3], 1 float
|
|
|
|
|
memcpy(&header.position, &buffer[start], 40);
|
|
|
|
|
start += 40;
|
2014-02-12 14:48:58 +01:00
|
|
|
|
|
|
|
|
|
//if loadCgf : Read path for bounding volume
|
|
|
|
|
if(loadCgf)
|
|
|
|
|
{
|
|
|
|
|
ParseBoundingVolume(&buffer[start], header.boundingVolume, start);
|
|
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
|
//else make sure the counter counts the name so we can jump over the string in the buffer.
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
|
|
|
|
|
string fileName;
|
|
|
|
|
fileName.assign(&tempName[0], &tempName[tempSize]);
|
|
|
|
|
start += tempSize;
|
|
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
|
|
|
|
|
|
size += start;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size)
|
|
|
|
|
{
|
|
|
|
|
int start = 0;
|
|
|
|
|
unsigned int tempSize;
|
|
|
|
|
char tempName[128];
|
|
|
|
|
|
|
|
|
|
memcpy(&header.typeID, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempSize , &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
header.levelName.assign(&tempName[0], &tempName[tempSize]);
|
|
|
|
|
start += tempSize;
|
|
|
|
|
|
|
|
|
|
memcpy(&header.levelVersion, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
|
|
|
|
start +=4;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
header.levelDescription.assign(&tempName[0], &tempName[tempSize]);
|
|
|
|
|
start += tempSize;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
header.levelAuthor.assign(&tempName[0], &tempName[tempSize]);
|
|
|
|
|
start += tempSize;
|
|
|
|
|
|
|
|
|
|
memcpy(&header.maxNumberOfPlayer, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&header.worldSize, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
header.overviewPicturePath.assign(&tempName[0], &tempName[tempSize]);
|
|
|
|
|
start += tempSize;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
int temp;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < tempSize; i++)
|
|
|
|
|
{
|
|
|
|
|
memcpy(&temp, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
header.gameModesSupported.push_back((GameMode)temp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size += start;
|
|
|
|
|
}
|
2014-02-12 14:48:58 +01:00
|
|
|
|
|
|
|
|
|
void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size)
|
|
|
|
|
{
|
|
|
|
|
int start = 0;
|
|
|
|
|
int tempSize = 0;
|
|
|
|
|
char tempName[128];
|
|
|
|
|
|
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
|
|
|
|
|
string fileName;
|
|
|
|
|
fileName.assign(&tempName[0], &tempName[tempSize]);
|
|
|
|
|
start += tempSize;
|
|
|
|
|
|
|
|
|
|
size += start;
|
|
|
|
|
|
|
|
|
|
//L<>s in filen.
|
|
|
|
|
int fileLength = 0;
|
|
|
|
|
Loader loader;
|
2014-02-13 16:33:26 +01:00
|
|
|
|
char* buf = loader.LoadFile("../Content/Worlds/cgf/"+ fileName, fileLength);
|
2014-02-12 14:48:58 +01:00
|
|
|
|
|
|
|
|
|
start = 0;
|
|
|
|
|
LevelLoaderInternal::FormatVersion version;
|
|
|
|
|
memcpy(&version, &buf[0], sizeof(version));
|
|
|
|
|
start += 4;
|
|
|
|
|
|
|
|
|
|
memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType));
|
|
|
|
|
start += sizeof(volume.geoType);
|
|
|
|
|
|
|
|
|
|
switch(volume.geoType)
|
|
|
|
|
{
|
|
|
|
|
case CollisionGeometryType_Box:
|
|
|
|
|
memcpy(&volume.box, &buf[start], sizeof(volume.box));
|
|
|
|
|
start += sizeof(volume.box);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CollisionGeometryType_Sphere:
|
|
|
|
|
memcpy(&volume.sphere, &buf[start], sizeof(volume.sphere));
|
|
|
|
|
start += sizeof(volume.sphere);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CollisionGeometryType_Cylinder:
|
|
|
|
|
memcpy(&volume.cylinder, &buf[start], sizeof(volume.cylinder));
|
|
|
|
|
start += sizeof(volume.cylinder);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
|
}
|
|
|
|
|
}
|