GL- LevelFormat fix

This commit is contained in:
Sam Mario Svensson 2014-01-27 13:57:18 +01:00
parent d6432b2c73
commit 91bf6ce901
6 changed files with 94 additions and 85 deletions

BIN
Bin/map.txt Normal file

Binary file not shown.

View File

@ -189,7 +189,7 @@
<ClInclude Include="Object.h" />
<ClInclude Include="ObjectDefines.h" />
<ClInclude Include="LevelParser.h" />
<ClInclude Include="ParserFunctions.h" />
<ClInclude Include="ParseFunctions.h" />
<ClInclude Include="Player.h" />
<ClInclude Include="StaticObject.h" />
<ClInclude Include="Team.h" />

View File

@ -1,10 +1,12 @@
#include "LevelParser.h"
#include "Loader.h"
#include "ParseFunctions.h"
using namespace GameLogic;
using namespace ::LevelFileLoader;
LevelParser::LevelParser()
{
}
@ -16,22 +18,23 @@ LevelParser::~LevelParser()
//
std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
{
int stringSize = 0;
//Read entire level file.
Loader loader;
unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str());
unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), stringSize);
std::vector<ObjectTypeHeader> objects;
unsigned int counter = 0;
unsigned int stringSize = 0;
while(counter < stringSize)
{
//Get typeID
int typeID = 0;
ObjectTypeHeader typeID;
typeID = parseObjectTypeHeader(buffer);
//Unpack ID
switch(typeID)
switch((int)typeID.typeID)
{
case TypeID_LevelHeader:
//Call function
@ -51,24 +54,27 @@ std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
return objects;
}
//
//för meta information om leveln. Måste göra så den returnerar rätt strukt så fort vi
//vi definierat en!
ObjectTypeHeader LevelParser::ParseHeader(std::string filename)
{
int stringSize = 0;
//Read entire level file.
Loader loader;
unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str());
unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), stringSize);
//Find the header in the returned string.
unsigned int counter = 0;
unsigned int stringSize = 0;
ObjectTypeHeader header;
header.typeID = ObjectType_Level;
while(counter < stringSize)
{
int typeID = 0;
switch(typeID)
ObjectTypeHeader typeID;
typeID = parseObjectTypeHeader(buffer);
switch(typeID.typeID)
{
case TypeID_LevelHeader:
//Call function

View File

@ -2,82 +2,88 @@
// Created by Sam Svensson 2013 //
//////////////////////////////////
#include "ParserFunctions.h"
#include "ParseFunctions.h"
#include "../../Misc/Packing/Packing.h"
#include <string>
using namespace Oyster::Packing;
using namespace GameLogic::LevelFileLoader;
using namespace GameLogic;
using namespace std;
ObjectTypeHeader parseObjectTypeHeader(unsigned char* buffer)
namespace GameLogic
{
int i = Unpacki(buffer);
namespace LevelFileLoader
{
ObjectTypeHeader parseObjectTypeHeader(unsigned char* buffer)
{
struct ObjectTypeHeader header;
int i = Unpacki(buffer);
header.typeID = (ObjectType)i;
return header;
}
struct ObjectTypeHeader header;
header.typeID = (ObjectType)i;
return header;
}
ObjectHeader parseObjectHeader (unsigned char* buffer)
{
struct ObjectHeader header;
int x, y,z;
string s;
int start = 0;
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;
//ModelID
x = Unpacki(buffer);
header.ModelID = (ObjectType)x;
//TextureID
start += 4;
x = Unpacki(&buffer[start]);
header.TextureID = x;
//TextureID
start += 4;
x = Unpacki(&buffer[start]);
header.TextureID = x;
//Position
start += 4;
x = Unpacki(&buffer[start]);
//Position
start += 4;
x = Unpacki(&buffer[start]);
start += 4;
y = Unpacki(&buffer[start]);
start += 4;
y = Unpacki(&buffer[start]);
start += 4;
z = Unpacki(&buffer[start]);
start += 4;
z = Unpacki(&buffer[start]);
header.position[0] = x;
header.position[1] = y;
header.position[2] = z;
header.position[0] = x;
header.position[1] = y;
header.position[2] = z;
//Rotation
start += 4;
x = Unpacki(&buffer[start]);
//Rotation
start += 4;
x = Unpacki(&buffer[start]);
start += 4;
y = Unpacki(&buffer[start]);
start += 4;
y = Unpacki(&buffer[start]);
start += 4;
z = Unpacki(&buffer[start]);
start += 4;
z = Unpacki(&buffer[start]);
header.rotation[0] = x;
header.rotation[1] = y;
header.rotation[2] = z;
header.rotation[0] = x;
header.rotation[1] = y;
header.rotation[2] = z;
//Scale
start += 4;
x = Unpacki(&buffer[start]);
//Scale
start += 4;
x = Unpacki(&buffer[start]);
start += 4;
y = Unpacki(&buffer[start]);
start += 4;
y = Unpacki(&buffer[start]);
start += 4;
z = Unpacki(&buffer[start]);
start += 4;
z = Unpacki(&buffer[start]);
header.scale[0] = x;
header.scale[1] = y;
header.scale[2] = z;
header.scale[0] = x;
header.scale[1] = y;
header.scale[2] = z;
return header;
return header;
}
}
}

View File

@ -0,0 +1,19 @@
//////////////////////////////////
// Created by Sam Svensson 2013 //
//////////////////////////////////
#ifndef PARSERFUNCTIONS_H
#define PARSERFUNCTIONS_H
#include "ObjectDefines.h"
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.
}
}
#endif

View File

@ -1,22 +0,0 @@
//////////////////////////////////
// Created by Sam Svensson 2013 //
//////////////////////////////////
#ifndef PARSERFUNCTIONS_H
#define PARSERFUNCTIONS_H
#include "ObjectDefines.h"
namespace GameLogic
{
namespace LevelFileLoader
{
namespace parseFunctions
{
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.
}
}
}
#endif