From 91bf6ce901e4b56d1e7ac3fba9a23541be924c30 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Mon, 27 Jan 2014 13:57:18 +0100 Subject: [PATCH] GL- LevelFormat fix --- Bin/map.txt | Bin 0 -> 48 bytes Code/Game/GameLogic/GameLogic.vcxproj | 2 +- Code/Game/GameLogic/LevelParser.cpp | 26 +++--- Code/Game/GameLogic/ParseFunctions.cpp | 110 +++++++++++++------------ Code/Game/GameLogic/ParseFunctions.h | 19 +++++ Code/Game/GameLogic/ParserFunctions.h | 22 ----- 6 files changed, 94 insertions(+), 85 deletions(-) create mode 100644 Bin/map.txt create mode 100644 Code/Game/GameLogic/ParseFunctions.h delete mode 100644 Code/Game/GameLogic/ParserFunctions.h diff --git a/Bin/map.txt b/Bin/map.txt new file mode 100644 index 0000000000000000000000000000000000000000..c9d1861205c2960ed93f42a764db732d9c326d2e GIT binary patch literal 48 gcmZQzU|?imU|<4bW~XmUqMWnxW;m}o+K7t{08$7NVE_OC literal 0 HcmV?d00001 diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 54ec2d7e..df1d09aa 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -189,7 +189,7 @@ - + diff --git a/Code/Game/GameLogic/LevelParser.cpp b/Code/Game/GameLogic/LevelParser.cpp index 5a709316..a03da6eb 100644 --- a/Code/Game/GameLogic/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelParser.cpp @@ -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 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 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 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 diff --git a/Code/Game/GameLogic/ParseFunctions.cpp b/Code/Game/GameLogic/ParseFunctions.cpp index 28199e6b..11e7b0ab 100644 --- a/Code/Game/GameLogic/ParseFunctions.cpp +++ b/Code/Game/GameLogic/ParseFunctions.cpp @@ -2,82 +2,88 @@ // Created by Sam Svensson 2013 // ////////////////////////////////// -#include "ParserFunctions.h" +#include "ParseFunctions.h" #include "../../Misc/Packing/Packing.h" #include 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; + } + } } \ No newline at end of file diff --git a/Code/Game/GameLogic/ParseFunctions.h b/Code/Game/GameLogic/ParseFunctions.h new file mode 100644 index 00000000..180f82c3 --- /dev/null +++ b/Code/Game/GameLogic/ParseFunctions.h @@ -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 \ No newline at end of file diff --git a/Code/Game/GameLogic/ParserFunctions.h b/Code/Game/GameLogic/ParserFunctions.h deleted file mode 100644 index 0608e77a..00000000 --- a/Code/Game/GameLogic/ParserFunctions.h +++ /dev/null @@ -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 \ No newline at end of file