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="Object.h" />
<ClInclude Include="ObjectDefines.h" /> <ClInclude Include="ObjectDefines.h" />
<ClInclude Include="LevelParser.h" /> <ClInclude Include="LevelParser.h" />
<ClInclude Include="ParserFunctions.h" /> <ClInclude Include="ParseFunctions.h" />
<ClInclude Include="Player.h" /> <ClInclude Include="Player.h" />
<ClInclude Include="StaticObject.h" /> <ClInclude Include="StaticObject.h" />
<ClInclude Include="Team.h" /> <ClInclude Include="Team.h" />

View File

@ -1,10 +1,12 @@
#include "LevelParser.h" #include "LevelParser.h"
#include "Loader.h" #include "Loader.h"
#include "ParseFunctions.h"
using namespace GameLogic; using namespace GameLogic;
using namespace ::LevelFileLoader; using namespace ::LevelFileLoader;
LevelParser::LevelParser() LevelParser::LevelParser()
{ {
} }
@ -16,22 +18,23 @@ LevelParser::~LevelParser()
// //
std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename) std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
{ {
int stringSize = 0;
//Read entire level file. //Read entire level file.
Loader loader; 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; std::vector<ObjectTypeHeader> objects;
unsigned int counter = 0; unsigned int counter = 0;
unsigned int stringSize = 0;
while(counter < stringSize) while(counter < stringSize)
{ {
//Get typeID //Get typeID
int typeID = 0; ObjectTypeHeader typeID;
typeID = parseObjectTypeHeader(buffer);
//Unpack ID //Unpack ID
switch(typeID) switch((int)typeID.typeID)
{ {
case TypeID_LevelHeader: case TypeID_LevelHeader:
//Call function //Call function
@ -51,24 +54,27 @@ std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
return objects; 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) ObjectTypeHeader LevelParser::ParseHeader(std::string filename)
{ {
int stringSize = 0;
//Read entire level file. //Read entire level file.
Loader loader; 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. //Find the header in the returned string.
unsigned int counter = 0; unsigned int counter = 0;
unsigned int stringSize = 0;
ObjectTypeHeader header; ObjectTypeHeader header;
header.typeID = ObjectType_Level; header.typeID = ObjectType_Level;
while(counter < stringSize) while(counter < stringSize)
{ {
int typeID = 0; ObjectTypeHeader typeID;
switch(typeID) typeID = parseObjectTypeHeader(buffer);
switch(typeID.typeID)
{ {
case TypeID_LevelHeader: case TypeID_LevelHeader:
//Call function //Call function

View File

@ -2,23 +2,27 @@
// Created by Sam Svensson 2013 // // Created by Sam Svensson 2013 //
////////////////////////////////// //////////////////////////////////
#include "ParserFunctions.h" #include "ParseFunctions.h"
#include "../../Misc/Packing/Packing.h" #include "../../Misc/Packing/Packing.h"
#include <string> #include <string>
using namespace Oyster::Packing; using namespace Oyster::Packing;
using namespace GameLogic::LevelFileLoader;
using namespace GameLogic; using namespace GameLogic;
using namespace std; using namespace std;
namespace GameLogic
{
namespace LevelFileLoader
{
ObjectTypeHeader parseObjectTypeHeader(unsigned char* buffer) ObjectTypeHeader parseObjectTypeHeader(unsigned char* buffer)
{ {
int i = Unpacki(buffer);
struct ObjectTypeHeader header; struct ObjectTypeHeader header;
int i = Unpacki(buffer);
header.typeID = (ObjectType)i; header.typeID = (ObjectType)i;
return header; return header;
} }
ObjectHeader parseObjectHeader (unsigned char* buffer) ObjectHeader parseObjectHeader (unsigned char* buffer)
{ {
struct ObjectHeader header; struct ObjectHeader header;
@ -81,3 +85,5 @@ ObjectHeader parseObjectHeader (unsigned char* buffer)
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