GL- la in memcpy för parsing i parseFunctions

This commit is contained in:
Sam Mario Svensson 2014-01-27 14:57:18 +01:00
parent 99fbef8a64
commit dd2b214122
4 changed files with 17 additions and 70 deletions

View File

@ -31,7 +31,8 @@ std::vector<ObjectTypeHeader> 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<ObjectTypeHeader> 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:

View File

@ -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;
}

View File

@ -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;
}
}
}

View File

@ -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.
}
}