From dd2b214122186dd1797ccd2d7af1b6388e14c8ab Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Mon, 27 Jan 2014 14:57:18 +0100 Subject: [PATCH] =?UTF-8?q?GL-=20la=20in=20memcpy=20f=C3=B6r=20parsing=20i?= =?UTF-8?q?=20parseFunctions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/Game/GameLogic/LevelParser.cpp | 8 +-- Code/Game/GameLogic/Loader.cpp | 5 +- Code/Game/GameLogic/ParseFunctions.cpp | 70 +++----------------------- Code/Game/GameLogic/ParseFunctions.h | 4 +- 4 files changed, 17 insertions(+), 70 deletions(-) diff --git a/Code/Game/GameLogic/LevelParser.cpp b/Code/Game/GameLogic/LevelParser.cpp index a03da6eb..a957b88a 100644 --- a/Code/Game/GameLogic/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelParser.cpp @@ -31,7 +31,8 @@ std::vector LevelParser::Parse(std::string filename) { //Get typeID ObjectTypeHeader typeID; - typeID = parseObjectTypeHeader(buffer); + typeID = ParseObjectTypeHeader(&buffer[counter]); + //counter += 4; //Unpack ID switch((int)typeID.typeID) @@ -43,7 +44,8 @@ std::vector LevelParser::Parse(std::string filename) case TypeID_Object: //Call function - counter += ObjectHeaderSize; + objects.push_back(ParseObjectHeader(&buffer[counter])); + counter += sizeof(ObjectHeader); break; default: //Couldn't find typeID. FAIL!!!!!! @@ -73,7 +75,7 @@ ObjectTypeHeader LevelParser::ParseHeader(std::string filename) while(counter < stringSize) { ObjectTypeHeader typeID; - typeID = parseObjectTypeHeader(buffer); + typeID = ParseObjectTypeHeader(buffer); switch(typeID.typeID) { case TypeID_LevelHeader: diff --git a/Code/Game/GameLogic/Loader.cpp b/Code/Game/GameLogic/Loader.cpp index 01047b2f..0afb48de 100644 --- a/Code/Game/GameLogic/Loader.cpp +++ b/Code/Game/GameLogic/Loader.cpp @@ -13,7 +13,8 @@ unsigned char* Loader::LoadFile(std::string fileName, int &size) //convert from string to wstring std::wstring temp(fileName.begin(), fileName.end()); - size = temp.size(); //convert from wstring to wchar then loads the file - return (unsigned char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); + unsigned char* buffer = (unsigned char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); + size = OysterResource::GetResourceSize(buffer); + return buffer; } \ No newline at end of file diff --git a/Code/Game/GameLogic/ParseFunctions.cpp b/Code/Game/GameLogic/ParseFunctions.cpp index 11e7b0ab..64405ff5 100644 --- a/Code/Game/GameLogic/ParseFunctions.cpp +++ b/Code/Game/GameLogic/ParseFunctions.cpp @@ -15,75 +15,19 @@ namespace GameLogic { namespace LevelFileLoader { - ObjectTypeHeader parseObjectTypeHeader(unsigned char* buffer) + ObjectTypeHeader ParseObjectTypeHeader(unsigned char* buffer) { struct ObjectTypeHeader header; - int i = Unpacki(buffer); - header.typeID = (ObjectType)i; + memcpy(&header, buffer, sizeof(ObjectTypeHeader)); return header; } - ObjectHeader parseObjectHeader (unsigned char* buffer) + ObjectHeader ParseObjectHeader (unsigned char* buffer) { - struct ObjectHeader header; - int x, y,z; - string s; - int start = 0; - - - //ModelID - x = Unpacki(buffer); - header.ModelID = (ObjectType)x; - - //TextureID - start += 4; - x = Unpacki(&buffer[start]); - header.TextureID = x; - - //Position - start += 4; - x = Unpacki(&buffer[start]); - - start += 4; - y = Unpacki(&buffer[start]); - - start += 4; - z = Unpacki(&buffer[start]); - - header.position[0] = x; - header.position[1] = y; - header.position[2] = z; - - //Rotation - start += 4; - x = Unpacki(&buffer[start]); - - start += 4; - y = Unpacki(&buffer[start]); - - start += 4; - z = Unpacki(&buffer[start]); - - header.rotation[0] = x; - header.rotation[1] = y; - header.rotation[2] = z; - - //Scale - start += 4; - x = Unpacki(&buffer[start]); - - start += 4; - y = Unpacki(&buffer[start]); - - start += 4; - z = Unpacki(&buffer[start]); - - header.scale[0] = x; - header.scale[1] = y; - header.scale[2] = z; - - - return header; + struct ObjectHeader header; + memcpy(&header, buffer, sizeof(ObjectHeader)); + + return header; } } } \ No newline at end of file diff --git a/Code/Game/GameLogic/ParseFunctions.h b/Code/Game/GameLogic/ParseFunctions.h index 180f82c3..5638f419 100644 --- a/Code/Game/GameLogic/ParseFunctions.h +++ b/Code/Game/GameLogic/ParseFunctions.h @@ -10,8 +10,8 @@ namespace GameLogic { namespace LevelFileLoader { - ObjectTypeHeader parseObjectTypeHeader(unsigned char* buffer); //send in a char buffer, this function will seperate it and then return the right struct with the values. - ObjectHeader parseObjectHeader (unsigned char* buffer); //send in a char buffer, this function will seperate it and then return the right struct with the values. + ObjectTypeHeader ParseObjectTypeHeader(unsigned char* buffer); //send in a char buffer, this function will seperate it and then return the right struct with the values. + ObjectHeader ParseObjectHeader (unsigned char* buffer); //send in a char buffer, this function will seperate it and then return the right struct with the values. } }