2014-01-28 11:29:35 +01:00
|
|
|
|
//////////////////////////////////
|
|
|
|
|
// Created by Sam Svensson 2013 //
|
|
|
|
|
//////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "ParseFunctions.h"
|
2014-02-17 10:38:11 +01:00
|
|
|
|
#include "Packing/Packing.h"
|
2014-02-07 14:12:54 +01:00
|
|
|
|
#include "Loader.h"
|
2014-01-28 11:29:35 +01:00
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using namespace Oyster::Packing;
|
|
|
|
|
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-01-28 16:15:10 +01:00
|
|
|
|
void ParseObject(char* buffer, void *header, int size)
|
2014-01-28 11:29:35 +01:00
|
|
|
|
{
|
|
|
|
|
memcpy(header, buffer, size);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
|
void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf)
|
2014-02-04 11:36:10 +01:00
|
|
|
|
{
|
|
|
|
|
char tempName[128];
|
2014-02-05 15:46:45 +01:00
|
|
|
|
unsigned int tempSize = 0;
|
2014-02-04 11:36:10 +01:00
|
|
|
|
int start = 0;
|
|
|
|
|
|
|
|
|
|
memcpy(&header.typeID, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
2014-02-07 14:12:54 +01:00
|
|
|
|
memcpy(&header.specialTypeID, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
|
|
|
|
|
2014-02-04 11:36:10 +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-07 14:12:54 +01:00
|
|
|
|
//The reset of the object struct
|
2014-02-05 15:46:45 +01:00
|
|
|
|
//3 float[3], 1 float
|
|
|
|
|
memcpy(&header.position, &buffer[start], 40);
|
|
|
|
|
start += 40;
|
2014-02-07 14:12:54 +01:00
|
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
|
//if loadCgf : Read path for bounding volume
|
|
|
|
|
if(loadCgf)
|
|
|
|
|
{
|
|
|
|
|
ParseBoundingVolume(&buffer[start], header.boundingVolume, start);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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-04 11:36:10 +01:00
|
|
|
|
|
|
|
|
|
size += start;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 16:15:10 +01:00
|
|
|
|
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size)
|
2014-01-28 11:29:35 +01:00
|
|
|
|
{
|
|
|
|
|
int start = 0;
|
2014-02-05 15:46:45 +01:00
|
|
|
|
unsigned int tempSize;
|
2014-02-04 11:36:10 +01:00
|
|
|
|
char tempName[128];
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
2014-01-28 11:29:35 +01:00
|
|
|
|
memcpy(&header.typeID, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
2014-01-28 11:29:35 +01:00
|
|
|
|
memcpy(&tempSize , &buffer[start], 4);
|
|
|
|
|
start += 4;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
header.levelName.assign(&tempName[0], &tempName[tempSize]);
|
2014-01-28 11:29:35 +01:00
|
|
|
|
start += tempSize;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
2014-02-04 14:30:45 +01:00
|
|
|
|
memcpy(&header.levelVersion, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
2014-01-28 11:29:35 +01:00
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
|
|
|
|
start +=4;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
header.levelDescription.assign(&tempName[0], &tempName[tempSize]);
|
2014-01-28 11:29:35 +01:00
|
|
|
|
start += tempSize;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
2014-01-28 11:29:35 +01:00
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
header.levelAuthor.assign(&tempName[0], &tempName[tempSize]);
|
2014-01-28 11:29:35 +01:00
|
|
|
|
start += tempSize;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
|
|
|
|
memcpy(&header.maxNumberOfPlayer, &buffer[start], 4);
|
2014-01-28 11:29:35 +01:00
|
|
|
|
start += 4;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
2014-01-28 11:29:35 +01:00
|
|
|
|
memcpy(&header.worldSize, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
2014-02-04 11:36:10 +01:00
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
2014-01-28 11:29:35 +01:00
|
|
|
|
start += 4;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
2014-02-04 11:36:10 +01:00
|
|
|
|
memcpy(&tempName, &buffer[start], tempSize);
|
|
|
|
|
header.overviewPicturePath.assign(&tempName[0], &tempName[tempSize]);
|
|
|
|
|
start += tempSize;
|
|
|
|
|
|
2014-01-28 11:29:35 +01:00
|
|
|
|
memcpy(&tempSize, &buffer[start], 4);
|
|
|
|
|
start += 4;
|
2014-01-28 16:15:10 +01:00
|
|
|
|
|
|
|
|
|
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-01-28 11:29:35 +01:00
|
|
|
|
}
|
2014-02-07 14:12:54 +01:00
|
|
|
|
|
|
|
|
|
void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size)
|
|
|
|
|
{
|
|
|
|
|
int start = 0;
|
|
|
|
|
int tempSize = 0;
|
|
|
|
|
char tempName[128];
|
2014-02-10 14:58:39 +01:00
|
|
|
|
|
2014-02-07 14:12:54 +01:00
|
|
|
|
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:58:39 +01:00
|
|
|
|
size += start;
|
|
|
|
|
|
2014-02-07 14:12:54 +01:00
|
|
|
|
//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-10 14:58:39 +01:00
|
|
|
|
|
|
|
|
|
start = 0;
|
2014-02-07 14:12:54 +01:00
|
|
|
|
LevelLoaderInternal::FormatVersion version;
|
2014-02-10 14:58:39 +01:00
|
|
|
|
memcpy(&version, &buf[0], sizeof(version));
|
2014-02-12 14:48:58 +01:00
|
|
|
|
start += 8;
|
2014-02-07 14:12:54 +01:00
|
|
|
|
|
2014-02-10 14:58:39 +01:00
|
|
|
|
memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType));
|
2014-02-07 14:12:54 +01:00
|
|
|
|
|
|
|
|
|
switch(volume.geoType)
|
|
|
|
|
{
|
|
|
|
|
case CollisionGeometryType_Box:
|
2014-02-10 14:58:39 +01:00
|
|
|
|
memcpy(&volume.box, &buf[start], sizeof(volume.box));
|
|
|
|
|
start += sizeof(volume.box);
|
2014-02-07 14:12:54 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CollisionGeometryType_Sphere:
|
2014-02-10 14:58:39 +01:00
|
|
|
|
memcpy(&volume.sphere, &buf[start], sizeof(volume.sphere));
|
|
|
|
|
start += sizeof(volume.sphere);
|
2014-02-07 14:12:54 +01:00
|
|
|
|
break;
|
2014-02-07 15:20:34 +01:00
|
|
|
|
|
|
|
|
|
case CollisionGeometryType_Cylinder:
|
2014-02-10 14:58:39 +01:00
|
|
|
|
memcpy(&volume.cylinder, &buf[start], sizeof(volume.cylinder));
|
|
|
|
|
start += sizeof(volume.cylinder);
|
2014-02-07 15:20:34 +01:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2014-02-07 14:12:54 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-28 11:29:35 +01:00
|
|
|
|
}
|
|
|
|
|
}
|