From e7fee8b2e7161d2768e914d398a424da151edb6a Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Mon, 3 Feb 2014 14:50:15 +0100 Subject: [PATCH] GL - Updated LevelLoader. Added lights. Added lights. Changed the return type to vector> Hid the LevelParser from the outside. --- Bin/Level.txt | Bin 156 -> 0 bytes Bin/map | Bin 156 -> 0 bytes Bin/map.txt | Bin 60 -> 0 bytes .../GameLogic/LevelLoader/LevelLoader.cpp | 22 ++++- Code/Game/GameLogic/LevelLoader/LevelLoader.h | 44 +++++----- .../GameLogic/LevelLoader/LevelParser.cpp | 81 +++++++++++++----- Code/Game/GameLogic/LevelLoader/LevelParser.h | 3 +- .../GameLogic/LevelLoader/ObjectDefines.h | 47 +++++++++- .../GameLogic/LevelLoader/ParseFunctions.h | 10 ++- 9 files changed, 156 insertions(+), 51 deletions(-) delete mode 100644 Bin/Level.txt delete mode 100644 Bin/map delete mode 100644 Bin/map.txt diff --git a/Bin/Level.txt b/Bin/Level.txt deleted file mode 100644 index d86dd3db4f89e0c84adfa01d7b0ec5a42dd61adb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 156 zcmZQzU|?VYV!y=PR7M~T0wBIiYH>0$&A`y$pam3X0x19jkXjHMgqeXjYRNaJ8F^XG hjYrow<6?ux*}DpzTmbMiDYF0o diff --git a/Bin/map b/Bin/map deleted file mode 100644 index a578cc3216cf4c730d47a3cae791ddccf2b29610..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 156 zcmZQ#U|?VZVrC$YTJp_lMqZY47AJ$m6N^*QIDs?+LxY1BkYob085kIWGyuTm1-1YH diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp index d60aac66..5bb916ab 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp @@ -3,16 +3,30 @@ ////////////////////////////////// #include "LevelLoader.h" +#include "LevelParser.h" using namespace GameLogic; using namespace GameLogic::LevelFileLoader; - -std::vector LevelLoader::LoadLevel(std::string fileName) +struct LevelLoader::PrivData { - return parser.Parse(fileName); + LevelParser parser; +}; + +LevelLoader::LevelLoader() + : pData(new PrivData) +{ +} + +LevelLoader::~LevelLoader() +{ +} + +std::vector> LevelLoader::LoadLevel(std::string fileName) +{ + return pData->parser.Parse(fileName); } LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) { - return parser.ParseHeader(fileName); + return pData->parser.ParseHeader(fileName); } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.h b/Code/Game/GameLogic/LevelLoader/LevelLoader.h index 4ac7a950..bcd6e587 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.h +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.h @@ -7,36 +7,36 @@ #include #include -#include +#include "../Misc/Utilities.h" #include "ObjectDefines.h" -#include "LevelParser.h" namespace GameLogic { - class LevelLoader - { + class LevelLoader + { - public: - LevelLoader(){this->parser = GameLogic::LevelFileLoader::LevelParser(); } - ~LevelLoader(){} + public: + LevelLoader(); + ~LevelLoader(); - /******************************************************** - * Loads the level and objects from file. - * @param fileName: Path to the level-file that you want to load. - * @return: Returns all structs with objects and information about the level. - ********************************************************/ - std::vector LoadLevel(std::string fileName); + /******************************************************** + * Loads the level and objects from file. + * @param fileName: Path to the level-file that you want to load. + * @return: Returns all structs with objects and information about the level. + ********************************************************/ + std::vector> LoadLevel(std::string fileName); - /******************************************************** - * Just for fast access for the meta information about the level. - * @param fileName: Path to the level-file that you want to load. - * @return: Returns the meta information about the level. - ********************************************************/ - LevelMetaData LoadLevelHeader(std::string fileName); //. + /******************************************************** + * Just for fast access for the meta information about the level. + * @param fileName: Path to the level-file that you want to load. + * @return: Returns the meta information about the level. + ********************************************************/ + LevelMetaData LoadLevelHeader(std::string fileName); //. - private: - GameLogic::LevelFileLoader::LevelParser parser; - }; + private: + struct PrivData; + Utility::DynamicMemory::SmartPointer pData; + }; } #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 3ab3c203..3a20f192 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -5,6 +5,7 @@ using namespace GameLogic; using namespace ::LevelFileLoader; +using namespace Utility::DynamicMemory; LevelParser::LevelParser() { @@ -16,12 +17,12 @@ LevelParser::~LevelParser() { } -std::vector LevelParser::Parse(std::string filename) +std::vector> LevelParser::Parse(std::string filename) { int bufferSize = 0; int counter = 0; - std::vector objects; + std::vector> objects; //Read entire level file. Loader loader; @@ -42,26 +43,66 @@ std::vector LevelParser::Parse(std::string filename) ParseObject(&buffer[counter], &typeID, sizeof(typeID)); switch((int)typeID.typeID) { - case ObjectType_LevelMetaData: - { - LevelMetaData header; - ParseLevelMetaData(&buffer[counter], header, counter); - objects.push_back(header); - break; - } + case ObjectType_LevelMetaData: + { + LevelMetaData* header = new LevelMetaData; + ParseLevelMetaData(&buffer[counter], *header, counter); + objects.push_back(header); + break; + } - case ObjectType_Dynamic: - { - ObjectHeader header; - ParseObject(&buffer[counter], &header, sizeof(header)); - objects.push_back(header); - counter += sizeof(header); - break; - } + //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. + case ObjectType_Static: case ObjectType_Dynamic: + { + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], header, sizeof(*header)); + objects.push_back(header); + counter += sizeof(*header); + break; + } - default: - //Couldn't find typeID. FAIL!!!!!! - break; + case ObjectType_Light: + { + LightType lightType; + + //Get Light type + ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); + + switch(lightType) + { + case LightType_PointLight: + { + PointLight* header = new PointLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + case LightType_DirectionalLight: + { + DirectionalLight* header = new DirectionalLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + case LightType_SpotLight: + { + SpotLight* header = new SpotLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + default: + //Undefined LightType. + break; + } + break; + } + default: + //Couldn't find typeID. FAIL!!!!!! + break; } } diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.h b/Code/Game/GameLogic/LevelLoader/LevelParser.h index 6dce25f8..9ad30642 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.h +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.h @@ -4,6 +4,7 @@ #include #include #include "ObjectDefines.h" +#include "../Misc/Utilities.h" namespace GameLogic { @@ -16,7 +17,7 @@ namespace GameLogic ~LevelParser(); // - std::vector Parse(std::string filename); + std::vector> Parse(std::string filename); // LevelMetaData ParseHeader(std::string filename); diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index dcf960a5..21e3a7e3 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -15,11 +15,12 @@ namespace GameLogic ObjectType_LevelMetaData, ObjectType_Static, ObjectType_Dynamic, + ObjectType_Light, //Etc ObjectType_NUM_OF_TYPES, - ObjectType_Unknown = -1, + ObjectType_Unknown = -1 }; enum UsePhysics @@ -29,7 +30,17 @@ namespace GameLogic UsePhysics_IgnorePhysics, UsePhysics_Count, - UsePhysics_Unknown = -1, + UsePhysics_Unknown = -1 + }; + + enum LightType + { + LightType_PointLight, + LightType_DirectionalLight, + LightType_SpotLight, + + LightType_Count, + LightType_Unknown = -1 }; //Should this be moved somewhere else? @@ -40,7 +51,7 @@ namespace GameLogic //Etc GameMode_Count, - GameMode_Unknown = -1, + GameMode_Unknown = -1 }; @@ -104,6 +115,36 @@ namespace GameLogic //Scale float scale[3]; }; + + + /************************************ + Lights + *************************************/ + + struct BasicLight : public ObjectTypeHeader + { + LightType lightType; + float ambientColor[3]; + float diffuseColor[3]; + float specularColor[3]; + }; + + struct PointLight : public BasicLight + { + float position[3]; + }; + + struct DirectionalLight : public BasicLight + { + float direction[3]; + }; + + struct SpotLight : public BasicLight + { + float direction[3]; + float range; + float attenuation[3]; + }; } #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h index 08962b4a..554b95db 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h @@ -10,8 +10,16 @@ namespace GameLogic { namespace LevelFileLoader { + /* + These functions will copy data from where the buffer pointer points. + header is the destination where the data will be copied. + size is either the size of the data to be copied (if it is NOT sent by reference). + Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied. + + */ + void ParseObject(char* buffer, void *header, int size); - void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); + void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); } }