diff --git a/Bin/Level.txt b/Bin/Level.txt new file mode 100644 index 00000000..d86dd3db Binary files /dev/null and b/Bin/Level.txt differ diff --git a/Bin/map b/Bin/map new file mode 100644 index 00000000..a578cc32 Binary files /dev/null and b/Bin/map differ diff --git a/Bin/map.txt b/Bin/map.txt index c9d18612..e5c751fb 100644 Binary files a/Bin/map.txt and b/Bin/map.txt differ diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp index a6f8bb98..d60aac66 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp @@ -9,10 +9,10 @@ using namespace GameLogic::LevelFileLoader; std::vector LevelLoader::LoadLevel(std::string fileName) { - return parser->Parse(fileName); + return parser.Parse(fileName); } LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) { - return parser->ParseHeader(fileName); + return parser.ParseHeader(fileName); } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.h b/Code/Game/GameLogic/LevelLoader/LevelLoader.h index 8f87d141..4ac7a950 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.h +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.h @@ -17,7 +17,7 @@ namespace GameLogic { public: - LevelLoader(){this->parser = new GameLogic::LevelFileLoader::LevelParser(); } + LevelLoader(){this->parser = GameLogic::LevelFileLoader::LevelParser(); } ~LevelLoader(){} /******************************************************** @@ -35,7 +35,7 @@ namespace GameLogic LevelMetaData LoadLevelHeader(std::string fileName); //. private: - GameLogic::LevelFileLoader::LevelParser *parser; + GameLogic::LevelFileLoader::LevelParser parser; }; } diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 72d68d97..3ab3c203 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -19,17 +19,17 @@ LevelParser::~LevelParser() std::vector LevelParser::Parse(std::string filename) { int bufferSize = 0; - unsigned int counter = 0; + int counter = 0; std::vector objects; //Read entire level file. 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 FormatVersion levelFormatVersion; - ParseObject(&buffer[counter], formatVersion, sizeof(formatVersion)); + //ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); if(this->formatVersion != levelFormatVersion) { //Do something if it's not the same version @@ -39,22 +39,26 @@ std::vector LevelParser::Parse(std::string filename) { //Get typeID ObjectTypeHeader typeID; - ParseObject(&buffer[counter], typeID, sizeof(typeID)); - + ParseObject(&buffer[counter], &typeID, sizeof(typeID)); switch((int)typeID.typeID) { case ObjectType_LevelMetaData: + { 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); counter += sizeof(header); break; - - case ObjectType_Dynamic: - ObjectHeader header; - ParseObject(&buffer[counter], header, sizeof(header)); - objects.push_back(header); - counter += sizeof(header); + } + default: //Couldn't find typeID. FAIL!!!!!! break; @@ -68,18 +72,18 @@ std::vector LevelParser::Parse(std::string filename) LevelMetaData LevelParser::ParseHeader(std::string filename) { int bufferSize = 0; - unsigned int counter = 0; + int counter = 0; LevelMetaData levelHeader; levelHeader.typeID = ObjectType::ObjectType_Unknown; //Read entire level file. 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 FormatVersion levelFormatVersion; - ParseObject(&buffer[counter], formatVersion, sizeof(formatVersion)); + //ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); if(this->formatVersion != levelFormatVersion) { //Do something if it's not the same version @@ -89,14 +93,13 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) while(counter < bufferSize) { ObjectTypeHeader typeID; - ParseObject(&buffer[counter], typeID, sizeof(typeID)); + ParseObject(&buffer[counter], &typeID, sizeof(typeID)); switch(typeID.typeID) { case ObjectType_LevelMetaData: - //ParseObject(&buffer[counter], levelHeader, sizeof(levelHeader)); + ParseLevelMetaData(&buffer[counter], levelHeader, counter); return levelHeader; - counter += sizeof(LevelMetaData); break; case ObjectType_Dynamic: //Do not call parse this object, since we are only interested in the LevelMetaData diff --git a/Code/Game/GameLogic/LevelLoader/Loader.cpp b/Code/Game/GameLogic/LevelLoader/Loader.cpp index 26818202..a0206d89 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.cpp +++ b/Code/Game/GameLogic/LevelLoader/Loader.cpp @@ -3,19 +3,31 @@ ////////////////////////////////// #include "Loader.h" +#include using namespace GameLogic::LevelFileLoader; using namespace Oyster::Resource; 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 std::wstring temp(fileName.begin(), fileName.end()); //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. size = OysterResource::GetResourceSize(buffer); return buffer; diff --git a/Code/Game/GameLogic/LevelLoader/Loader.h b/Code/Game/GameLogic/LevelLoader/Loader.h index 2d605169..198c2a87 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.h +++ b/Code/Game/GameLogic/LevelLoader/Loader.h @@ -17,7 +17,7 @@ namespace GameLogic public: Loader (){}; ~Loader(){}; - unsigned char* LoadFile(std::string fileName, int &size); + char* LoadFile(std::string fileName, int &size); //TODO: //Add functionality to load physicsObjects (hitboxes) diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 2d3e09f0..dcf960a5 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -91,7 +91,7 @@ namespace GameLogic std::vector gameModesSupported; }; - struct ObjectHeader : public PhysicsObject, public ObjectTypeHeader + struct ObjectHeader : public ObjectTypeHeader { //Model, int ModelID; diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index abca143c..f456b2d7 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -15,41 +15,66 @@ namespace GameLogic { namespace LevelFileLoader { - void ParseObject(unsigned char* buffer, void* header, int size) + void ParseObject(char* buffer, void *header, int 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 tempSize; + char tempName[100]; + memcpy(&header.typeID, &buffer[start], 4); start += 4; + memcpy(&tempSize , &buffer[start], 4); start += 4; - memcpy(&header.levelName, &buffer[start], tempSize); + + memcpy(&tempName, &buffer[start], tempSize); + header.levelName.assign(&tempName[0], &tempName[tempSize]); start += tempSize; - memcpy(&header.levelVersion, &buffer[start], 8) + + memcpy(&header.levelVersion, &buffer[start], 8); start += 8; + memcpy(&tempSize, &buffer[start], 4); start +=4; - memcpy(&header.description, &buffer[start], tempSize); + + memcpy(&tempName, &buffer[start], tempSize); + header.levelDescription.assign(&tempName[0], &tempName[tempSize]); start += tempSize; + memcpy(&tempSize, &buffer[start], 4); start += 4; - memcpy(&header.author, &buffer[start], tempSize); + + memcpy(&tempName, &buffer[start], tempSize); + header.levelAuthor.assign(&tempName[0], &tempName[tempSize]); start += tempSize; - memcpy(&header.nrOfPlayers, &buffer[start], 4); + + memcpy(&header.maxNumberOfPlayer, &buffer[start], 4); start += 4; + memcpy(&header.worldSize, &buffer[start], 4); start += 4; - memcpy(&header.map, &buffer[start], 4); + + memcpy(&header.overviewPictureID, &buffer[start], 4); start += 4; + memcpy(&tempSize, &buffer[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; } } } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h index 7a6ab93a..08962b4a 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h @@ -10,8 +10,8 @@ namespace GameLogic { namespace LevelFileLoader { - void ParseObject(unsigned char* buffer, void* header, int size); - void ParseLevelMetaData(unsigned char* buffer, struct ObjectTypeHeader &header); + void ParseObject(char* buffer, void *header, int size); + void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); } }