GL - LevelLoader = done and done
This commit is contained in:
parent
2b63563a9b
commit
f968adebeb
Binary file not shown.
BIN
Bin/map.txt
BIN
Bin/map.txt
Binary file not shown.
|
@ -9,10 +9,10 @@ using namespace GameLogic::LevelFileLoader;
|
||||||
|
|
||||||
std::vector<ObjectTypeHeader> LevelLoader::LoadLevel(std::string fileName)
|
std::vector<ObjectTypeHeader> LevelLoader::LoadLevel(std::string fileName)
|
||||||
{
|
{
|
||||||
return parser->Parse(fileName);
|
return parser.Parse(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName)
|
LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName)
|
||||||
{
|
{
|
||||||
return parser->ParseHeader(fileName);
|
return parser.ParseHeader(fileName);
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@ namespace GameLogic
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LevelLoader(){this->parser = new GameLogic::LevelFileLoader::LevelParser(); }
|
LevelLoader(){this->parser = GameLogic::LevelFileLoader::LevelParser(); }
|
||||||
~LevelLoader(){}
|
~LevelLoader(){}
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
|
@ -35,7 +35,7 @@ namespace GameLogic
|
||||||
LevelMetaData LoadLevelHeader(std::string fileName); //.
|
LevelMetaData LoadLevelHeader(std::string fileName); //.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GameLogic::LevelFileLoader::LevelParser *parser;
|
GameLogic::LevelFileLoader::LevelParser parser;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,17 +19,17 @@ LevelParser::~LevelParser()
|
||||||
std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
|
std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
|
||||||
{
|
{
|
||||||
int bufferSize = 0;
|
int bufferSize = 0;
|
||||||
unsigned int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
std::vector<ObjectTypeHeader> objects;
|
std::vector<ObjectTypeHeader> objects;
|
||||||
|
|
||||||
//Read entire level file.
|
//Read entire level file.
|
||||||
Loader loader;
|
Loader loader;
|
||||||
unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), bufferSize);
|
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
|
||||||
|
|
||||||
//Read format version
|
//Read format version
|
||||||
FormatVersion levelFormatVersion;
|
FormatVersion levelFormatVersion;
|
||||||
ParseObject(&buffer[counter], formatVersion, sizeof(formatVersion));
|
//ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion));
|
||||||
if(this->formatVersion != levelFormatVersion)
|
if(this->formatVersion != levelFormatVersion)
|
||||||
{
|
{
|
||||||
//Do something if it's not the same version
|
//Do something if it's not the same version
|
||||||
|
@ -39,22 +39,26 @@ std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
|
||||||
{
|
{
|
||||||
//Get typeID
|
//Get typeID
|
||||||
ObjectTypeHeader typeID;
|
ObjectTypeHeader typeID;
|
||||||
ParseObject(&buffer[counter], typeID, sizeof(typeID));
|
ParseObject(&buffer[counter], &typeID, sizeof(typeID));
|
||||||
|
|
||||||
switch((int)typeID.typeID)
|
switch((int)typeID.typeID)
|
||||||
{
|
{
|
||||||
case ObjectType_LevelMetaData:
|
case ObjectType_LevelMetaData:
|
||||||
|
{
|
||||||
LevelMetaData header;
|
LevelMetaData header;
|
||||||
//ParseObject(&buffer[counter], header, sizeof(header));
|
ParseLevelMetaData(&buffer[counter], header, counter);
|
||||||
|
objects.push_back(header);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ObjectType_Dynamic:
|
||||||
|
{
|
||||||
|
ObjectHeader header;
|
||||||
|
ParseObject(&buffer[counter], &header, sizeof(header));
|
||||||
objects.push_back(header);
|
objects.push_back(header);
|
||||||
counter += sizeof(header);
|
counter += sizeof(header);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case ObjectType_Dynamic:
|
|
||||||
ObjectHeader header;
|
|
||||||
ParseObject(&buffer[counter], header, sizeof(header));
|
|
||||||
objects.push_back(header);
|
|
||||||
counter += sizeof(header);
|
|
||||||
default:
|
default:
|
||||||
//Couldn't find typeID. FAIL!!!!!!
|
//Couldn't find typeID. FAIL!!!!!!
|
||||||
break;
|
break;
|
||||||
|
@ -68,18 +72,18 @@ std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
|
||||||
LevelMetaData LevelParser::ParseHeader(std::string filename)
|
LevelMetaData LevelParser::ParseHeader(std::string filename)
|
||||||
{
|
{
|
||||||
int bufferSize = 0;
|
int bufferSize = 0;
|
||||||
unsigned int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
LevelMetaData levelHeader;
|
LevelMetaData levelHeader;
|
||||||
levelHeader.typeID = ObjectType::ObjectType_Unknown;
|
levelHeader.typeID = ObjectType::ObjectType_Unknown;
|
||||||
|
|
||||||
//Read entire level file.
|
//Read entire level file.
|
||||||
Loader loader;
|
Loader loader;
|
||||||
unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), bufferSize);
|
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
|
||||||
|
|
||||||
//Read format version
|
//Read format version
|
||||||
FormatVersion levelFormatVersion;
|
FormatVersion levelFormatVersion;
|
||||||
ParseObject(&buffer[counter], formatVersion, sizeof(formatVersion));
|
//ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion));
|
||||||
if(this->formatVersion != levelFormatVersion)
|
if(this->formatVersion != levelFormatVersion)
|
||||||
{
|
{
|
||||||
//Do something if it's not the same version
|
//Do something if it's not the same version
|
||||||
|
@ -89,14 +93,13 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
|
||||||
while(counter < bufferSize)
|
while(counter < bufferSize)
|
||||||
{
|
{
|
||||||
ObjectTypeHeader typeID;
|
ObjectTypeHeader typeID;
|
||||||
ParseObject(&buffer[counter], typeID, sizeof(typeID));
|
ParseObject(&buffer[counter], &typeID, sizeof(typeID));
|
||||||
|
|
||||||
switch(typeID.typeID)
|
switch(typeID.typeID)
|
||||||
{
|
{
|
||||||
case ObjectType_LevelMetaData:
|
case ObjectType_LevelMetaData:
|
||||||
//ParseObject(&buffer[counter], levelHeader, sizeof(levelHeader));
|
ParseLevelMetaData(&buffer[counter], levelHeader, counter);
|
||||||
return levelHeader;
|
return levelHeader;
|
||||||
counter += sizeof(LevelMetaData);
|
|
||||||
break;
|
break;
|
||||||
case ObjectType_Dynamic:
|
case ObjectType_Dynamic:
|
||||||
//Do not call parse this object, since we are only interested in the LevelMetaData
|
//Do not call parse this object, since we are only interested in the LevelMetaData
|
||||||
|
|
|
@ -3,19 +3,31 @@
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|
||||||
#include "Loader.h"
|
#include "Loader.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
using namespace GameLogic::LevelFileLoader;
|
using namespace GameLogic::LevelFileLoader;
|
||||||
using namespace Oyster::Resource;
|
using namespace Oyster::Resource;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
unsigned char* Loader::LoadFile(std::string fileName, int &size)
|
char* Loader::LoadFile(std::string fileName, int &size)
|
||||||
{
|
{
|
||||||
//convert from string to wstring
|
//convert from string to wstring
|
||||||
std::wstring temp(fileName.begin(), fileName.end());
|
std::wstring temp(fileName.begin(), fileName.end());
|
||||||
|
|
||||||
//convert from wstring to wchar then loads the file
|
//convert from wstring to wchar then loads the file
|
||||||
unsigned char* buffer = (unsigned char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false);
|
char* buffer = (char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false);
|
||||||
|
|
||||||
|
//std::ifstream f;
|
||||||
|
//f.open(fileName, std::ios::binary);
|
||||||
|
//if (!f.is_open())
|
||||||
|
// return 0;
|
||||||
|
//f.seekg(0, std::ifstream::end);
|
||||||
|
//size = f.tellg();
|
||||||
|
//f.seekg(0);
|
||||||
|
//char* buffer = new char[size];
|
||||||
|
//f.read(buffer, size);
|
||||||
|
//
|
||||||
|
//f.close();
|
||||||
//gets the size of the char buffer.
|
//gets the size of the char buffer.
|
||||||
size = OysterResource::GetResourceSize(buffer);
|
size = OysterResource::GetResourceSize(buffer);
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace GameLogic
|
||||||
public:
|
public:
|
||||||
Loader (){};
|
Loader (){};
|
||||||
~Loader(){};
|
~Loader(){};
|
||||||
unsigned char* LoadFile(std::string fileName, int &size);
|
char* LoadFile(std::string fileName, int &size);
|
||||||
|
|
||||||
//TODO:
|
//TODO:
|
||||||
//Add functionality to load physicsObjects (hitboxes)
|
//Add functionality to load physicsObjects (hitboxes)
|
||||||
|
|
|
@ -91,7 +91,7 @@ namespace GameLogic
|
||||||
std::vector<GameMode> gameModesSupported;
|
std::vector<GameMode> gameModesSupported;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ObjectHeader : public PhysicsObject, public ObjectTypeHeader
|
struct ObjectHeader : public ObjectTypeHeader
|
||||||
{
|
{
|
||||||
//Model,
|
//Model,
|
||||||
int ModelID;
|
int ModelID;
|
||||||
|
|
|
@ -15,41 +15,66 @@ namespace GameLogic
|
||||||
{
|
{
|
||||||
namespace LevelFileLoader
|
namespace LevelFileLoader
|
||||||
{
|
{
|
||||||
void ParseObject(unsigned char* buffer, void* header, int size)
|
void ParseObject(char* buffer, void *header, int size)
|
||||||
{
|
{
|
||||||
memcpy(header, buffer, size);
|
memcpy(header, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParseLevelMetaData(unsigned char* buffer, struct LevelMetaData &header)
|
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size)
|
||||||
{
|
{
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int tempSize;
|
int tempSize;
|
||||||
|
char tempName[100];
|
||||||
|
|
||||||
memcpy(&header.typeID, &buffer[start], 4);
|
memcpy(&header.typeID, &buffer[start], 4);
|
||||||
start += 4;
|
start += 4;
|
||||||
|
|
||||||
memcpy(&tempSize , &buffer[start], 4);
|
memcpy(&tempSize , &buffer[start], 4);
|
||||||
start += 4;
|
start += 4;
|
||||||
memcpy(&header.levelName, &buffer[start], tempSize);
|
|
||||||
|
memcpy(&tempName, &buffer[start], tempSize);
|
||||||
|
header.levelName.assign(&tempName[0], &tempName[tempSize]);
|
||||||
start += tempSize;
|
start += tempSize;
|
||||||
memcpy(&header.levelVersion, &buffer[start], 8)
|
|
||||||
|
memcpy(&header.levelVersion, &buffer[start], 8);
|
||||||
start += 8;
|
start += 8;
|
||||||
|
|
||||||
memcpy(&tempSize, &buffer[start], 4);
|
memcpy(&tempSize, &buffer[start], 4);
|
||||||
start +=4;
|
start +=4;
|
||||||
memcpy(&header.description, &buffer[start], tempSize);
|
|
||||||
|
memcpy(&tempName, &buffer[start], tempSize);
|
||||||
|
header.levelDescription.assign(&tempName[0], &tempName[tempSize]);
|
||||||
start += tempSize;
|
start += tempSize;
|
||||||
|
|
||||||
memcpy(&tempSize, &buffer[start], 4);
|
memcpy(&tempSize, &buffer[start], 4);
|
||||||
start += 4;
|
start += 4;
|
||||||
memcpy(&header.author, &buffer[start], tempSize);
|
|
||||||
|
memcpy(&tempName, &buffer[start], tempSize);
|
||||||
|
header.levelAuthor.assign(&tempName[0], &tempName[tempSize]);
|
||||||
start += tempSize;
|
start += tempSize;
|
||||||
memcpy(&header.nrOfPlayers, &buffer[start], 4);
|
|
||||||
|
memcpy(&header.maxNumberOfPlayer, &buffer[start], 4);
|
||||||
start += 4;
|
start += 4;
|
||||||
|
|
||||||
memcpy(&header.worldSize, &buffer[start], 4);
|
memcpy(&header.worldSize, &buffer[start], 4);
|
||||||
start += 4;
|
start += 4;
|
||||||
memcpy(&header.map, &buffer[start], 4);
|
|
||||||
|
memcpy(&header.overviewPictureID, &buffer[start], 4);
|
||||||
start += 4;
|
start += 4;
|
||||||
|
|
||||||
memcpy(&tempSize, &buffer[start], 4);
|
memcpy(&tempSize, &buffer[start], 4);
|
||||||
start += 4;
|
start += 4;
|
||||||
memcpy(&header.gameModes, &buffer[start], 4 * tempSize);
|
|
||||||
start += tempSize;
|
int temp;
|
||||||
|
|
||||||
|
for(int i = 0; i < tempSize; i++)
|
||||||
|
{
|
||||||
|
memcpy(&temp, &buffer[start], 4);
|
||||||
|
start += 4;
|
||||||
|
header.gameModesSupported.push_back((GameMode)temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
size += start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,8 +10,8 @@ namespace GameLogic
|
||||||
{
|
{
|
||||||
namespace LevelFileLoader
|
namespace LevelFileLoader
|
||||||
{
|
{
|
||||||
void ParseObject(unsigned char* buffer, void* header, int size);
|
void ParseObject(char* buffer, void *header, int size);
|
||||||
void ParseLevelMetaData(unsigned char* buffer, struct ObjectTypeHeader &header);
|
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue