From 0f5517398dbb4b72c5395d13b918fcc8d5acdf11 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 24 Jan 2014 09:00:59 +0100 Subject: [PATCH 01/12] GL - Update uml, LevelParser.h.cpp ObjectDefines.h --- Code/Dokumentation/LevelLoader.uxf | 46 +++++++++++++-------------- Code/Game/GameLogic/GameLogic.vcxproj | 3 ++ Code/Game/GameLogic/LevelParser.cpp | 2 ++ Code/Game/GameLogic/LevelParser.h | 28 ++++++++++++++++ Code/Game/GameLogic/ObjectDefines.h | 38 ++++++++++++++++++++++ 5 files changed, 94 insertions(+), 23 deletions(-) create mode 100644 Code/Game/GameLogic/LevelParser.cpp create mode 100644 Code/Game/GameLogic/LevelParser.h create mode 100644 Code/Game/GameLogic/ObjectDefines.h diff --git a/Code/Dokumentation/LevelLoader.uxf b/Code/Dokumentation/LevelLoader.uxf index 723857bb..fd3e9c79 100644 --- a/Code/Dokumentation/LevelLoader.uxf +++ b/Code/Dokumentation/LevelLoader.uxf @@ -1,11 +1,11 @@ - + 8 com.umlet.element.Package 552 - 320 + 360 584 368 @@ -16,7 +16,7 @@ com.umlet.element.Class 440 - 88 + 128 128 40 @@ -28,7 +28,7 @@ com.umlet.element.Relation 768 - 472 + 512 136 104 @@ -39,12 +39,12 @@ com.umlet.element.Class 560 - 544 + 584 232 136 <<Interface>> -Parser +LevelParser -- Functions: vector<struct> Parse(); @@ -60,7 +60,7 @@ const int FileVersion; com.umlet.element.Class 624 - 208 + 248 80 24 @@ -72,7 +72,7 @@ const int FileVersion; com.umlet.element.Relation 640 - 208 + 248 40 168 @@ -83,7 +83,7 @@ const int FileVersion; com.umlet.element.Relation 384 - 176 + 216 256 56 @@ -97,7 +97,7 @@ m2=1..1 com.umlet.element.Package 248 - 320 + 360 248 160 @@ -108,7 +108,7 @@ m2=1..1 com.umlet.element.Class 800 - 360 + 400 208 136 @@ -127,7 +127,7 @@ Privates: com.umlet.element.Class 328 - 208 + 248 80 24 @@ -138,11 +138,11 @@ Privates: com.umlet.element.Class 256 - 360 + 400 232 104 - Defines.h + ObjectDefines.h <<Header file>> -- Enum ObjectType(static, dynamic, specials); @@ -156,7 +156,7 @@ Struct specials com.umlet.element.Relation 680 - 176 + 216 152 56 @@ -170,7 +170,7 @@ Uses> com.umlet.element.Class 816 - 192 + 232 128 40 @@ -182,7 +182,7 @@ Uses> com.umlet.element.Class 928 - 560 + 600 200 120 @@ -196,7 +196,7 @@ functions for creating the right structs com.umlet.element.Relation 768 - 576 + 616 176 56 @@ -210,7 +210,7 @@ Uses> com.umlet.element.Class 560 - 360 + 400 232 136 @@ -230,7 +230,7 @@ Privates: com.umlet.element.Relation 344 - 208 + 248 40 168 @@ -241,7 +241,7 @@ Privates: com.umlet.element.Relation 840 - 208 + 248 88 168 @@ -253,7 +253,7 @@ Privates: com.umlet.element.Relation 656 - 472 + 512 40 88 @@ -264,7 +264,7 @@ Privates: com.umlet.element.Relation 544 - 64 + 104 136 160 diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 6b66a9d5..da052b70 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -185,6 +185,8 @@ + + @@ -202,6 +204,7 @@ + diff --git a/Code/Game/GameLogic/LevelParser.cpp b/Code/Game/GameLogic/LevelParser.cpp new file mode 100644 index 00000000..65b63aef --- /dev/null +++ b/Code/Game/GameLogic/LevelParser.cpp @@ -0,0 +1,2 @@ +#include "LevelParser.h" + diff --git a/Code/Game/GameLogic/LevelParser.h b/Code/Game/GameLogic/LevelParser.h new file mode 100644 index 00000000..f1904d9c --- /dev/null +++ b/Code/Game/GameLogic/LevelParser.h @@ -0,0 +1,28 @@ +#ifndef LEVEL_PARSER_H +#define LEVEL_PARSER_H + +#include +#include "ObjectDefines.h" + +namespace GameLogic +{ + namespace LevelLoader + { + class LevelParser + { + public: + LevelParser(); + ~LevelParser(); + + // + std::vector Parse(); + + // + ObjectTypeHeader ParseHeader(); + + private: + + }; + } +} +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/ObjectDefines.h b/Code/Game/GameLogic/ObjectDefines.h new file mode 100644 index 00000000..74bca42c --- /dev/null +++ b/Code/Game/GameLogic/ObjectDefines.h @@ -0,0 +1,38 @@ +#ifndef OBJECT_DEFINES_H +#define OBJECT_DEFINES_H + +namespace GameLogic +{ + enum ObjectType + { + ObjectType_Static, + ObjectType_Dynamic, + + + ObjectType_NUM_OF_TYPES, + + ObjectType_Unknow = -1, + }; + + struct ObjectTypeHeader + { + ObjectType typeID; + + }; + + struct ObjectHeader : public ObjectTypeHeader + { + //Model, + + //Texture + + //Position + float position[3]; + //Rotation + float rotation[3]; + //Scale + float scale[3]; + }; +} + +#endif \ No newline at end of file From aaf3bf30f9a19644dc6480cbcc3d0097dec073fd Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 24 Jan 2014 10:01:58 +0100 Subject: [PATCH 02/12] GL - LevelParser half way implemented. --- Code/Game/GameLogic/LevelParser.cpp | 80 +++++++++++++++++++++++++++++ Code/Game/GameLogic/LevelParser.h | 27 +++++++++- Code/Game/GameLogic/ObjectDefines.h | 3 +- 3 files changed, 107 insertions(+), 3 deletions(-) diff --git a/Code/Game/GameLogic/LevelParser.cpp b/Code/Game/GameLogic/LevelParser.cpp index 65b63aef..21e6c020 100644 --- a/Code/Game/GameLogic/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelParser.cpp @@ -1,2 +1,82 @@ #include "LevelParser.h" +using namespace GameLogic; +using namespace ::LevelLoader; + +LevelParser::LevelParser() +{ +} + +LevelParser::~LevelParser() +{ +} + +// +std::vector LevelParser::Parse(std::string filename) +{ + //Read entire level file. + + std::vector objects; + + unsigned int counter = 0; + unsigned int stringSize = 0; + while(counter < stringSize) + { + //Get typeID + int typeID = 0; + + + switch(typeID) + { + case TypeID_LevelHeader: + //Call function + counter += LevelHeaderSize; + break; + + case TypeID_Object: + //Call function + counter += ObjectHeaderSize; + break; + default: + //Couldn't find typeID. FAIL!!!!!! + break; + } + } + + return objects; +} + +// +ObjectTypeHeader LevelParser::ParseHeader(std::string filename) +{ + //Read entire level file. + + //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) + { + case TypeID_LevelHeader: + //Call function + + break; + case TypeID_Object: + //Call function + counter += ObjectHeaderSize; + break; + + default: + //Couldn't find typeID. FAIL!!!!!! + break; + } + } + + return header; +} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelParser.h b/Code/Game/GameLogic/LevelParser.h index f1904d9c..f261004b 100644 --- a/Code/Game/GameLogic/LevelParser.h +++ b/Code/Game/GameLogic/LevelParser.h @@ -1,6 +1,7 @@ #ifndef LEVEL_PARSER_H #define LEVEL_PARSER_H +#include #include #include "ObjectDefines.h" @@ -15,12 +16,34 @@ namespace GameLogic ~LevelParser(); // - std::vector Parse(); + std::vector Parse(std::string filename); // - ObjectTypeHeader ParseHeader(); + ObjectTypeHeader ParseHeader(std::string filename); private: + static const int TypeHeaderSize = 4; //Including the TypeID + static const int ObjectHeaderSize = 10; //Including modelID, textureID, position, rotation, scale. + static const int LevelHeaderSize = 10; //Including Format version, Name, Map version etc. + + static const int FormatVersionMajor = 1; + static const int FormatVersionMinor = 0; + + /************************************* + Question + *************************************/ + //Could we use the IDs in "ObjectDefines.h" or do we have to use our own??? + enum TypeID + { + TypeID_LevelHeader, + TypeID_Player, + TypeID_Object, + + + TypeID_NUM_OF_TYPES, + + ObjectType_Unknown = -1, + }; }; } diff --git a/Code/Game/GameLogic/ObjectDefines.h b/Code/Game/GameLogic/ObjectDefines.h index 74bca42c..eae1b0c9 100644 --- a/Code/Game/GameLogic/ObjectDefines.h +++ b/Code/Game/GameLogic/ObjectDefines.h @@ -5,13 +5,14 @@ namespace GameLogic { enum ObjectType { + ObjectType_Level, ObjectType_Static, ObjectType_Dynamic, ObjectType_NUM_OF_TYPES, - ObjectType_Unknow = -1, + ObjectType_Unknown = -1, }; struct ObjectTypeHeader From c84ed645f00d0b256599462e093b9b3f29e64710 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Fri, 24 Jan 2014 10:22:18 +0100 Subject: [PATCH 03/12] GameLogic - implementation of LevelLoader --- Code/Dokumentation/LevelLoader.uxf | 300 +++++++++++++------------- Code/Game/GameLogic/GameLogic.vcxproj | 4 + Code/Game/GameLogic/LevelLoader.cpp | 17 ++ Code/Game/GameLogic/LevelLoader.h | 29 +++ Code/Game/GameLogic/Loader.cpp | 18 ++ Code/Game/GameLogic/Loader.h | 28 +++ 6 files changed, 246 insertions(+), 150 deletions(-) create mode 100644 Code/Game/GameLogic/LevelLoader.cpp create mode 100644 Code/Game/GameLogic/LevelLoader.h create mode 100644 Code/Game/GameLogic/Loader.cpp create mode 100644 Code/Game/GameLogic/Loader.h diff --git a/Code/Dokumentation/LevelLoader.uxf b/Code/Dokumentation/LevelLoader.uxf index 723857bb..6cfb9c29 100644 --- a/Code/Dokumentation/LevelLoader.uxf +++ b/Code/Dokumentation/LevelLoader.uxf @@ -1,61 +1,6 @@ 8 - - com.umlet.element.Package - - 552 - 320 - 584 - 368 - - LevelLoader - - - - com.umlet.element.Class - - 440 - 88 - 128 - 40 - - GameLogic -<<Erik>> - - - - com.umlet.element.Relation - - 768 - 472 - 136 - 104 - - lt=<<<<- - 120;24;120;88;24;88 - - - com.umlet.element.Class - - 560 - 544 - 232 - 136 - - <<Interface>> -Parser --- -Functions: -vector<struct> Parse(); -- -Privates: -enum headerType; -const int FileHeaderSize; -const int FileVersion; - - - com.umlet.element.Class @@ -71,85 +16,39 @@ const int FileVersion; com.umlet.element.Relation - 640 + 840 208 - 40 + 88 168 - lt=<<. - 24;24;24;152 - - - com.umlet.element.Relation - - 384 - 176 - 256 - 56 - - lt=->>>> -m1=1..1 -m2=1..1 -<Knows about - 240;40;24;40 - - - com.umlet.element.Package - - 248 - 320 - 248 - 160 - - Defines - + lt=. +<Uses + 24;24;24;64;72;64;72;152 com.umlet.element.Class - 800 - 360 - 208 - 136 + 928 + 560 + 200 + 120 - <<Interface>> -Loader + Collection of functions +<<lots of functions>> -- -Functions: -wchar* LoadFile(string fileName); -Model* LoadModel(string modelName); -Model* LoadModel(int modelID); -- -Privates: +functions for creating the right structs com.umlet.element.Class - 328 - 208 - 80 - 24 + 440 + 88 + 128 + 40 - Defines - - - - com.umlet.element.Class - - 256 - 360 - 232 - 104 - - Defines.h -<<Header file>> --- -Enum ObjectType(static, dynamic, specials); -. -Struct static; -Struct dynamic; -Struct specials + GameLogic +<<Erik>> @@ -169,28 +68,32 @@ Uses> com.umlet.element.Class - 816 - 192 - 128 - 40 + 800 + 360 + 208 + 136 - Resource Loader -<<Dennis>><<Singleton> + <<Interface>> +Loader +-- +Functions: +wchar* LoadFile(string fileName); +//Model* LoadHitBoxes(string modelName); +//Model* LoadHitBoxes(int modelID); +- +Privates: - com.umlet.element.Class + com.umlet.element.Relation - 928 - 560 - 200 - 120 + 344 + 208 + 40 + 168 - Collection of functions -<<lots of functions>> --- -functions for creating the right structs - + lt=<<. + 24;24;24;152 com.umlet.element.Relation @@ -206,6 +109,61 @@ m2=1..1 Uses> 24;40;160;40 + + com.umlet.element.Class + + 816 + 192 + 128 + 40 + + Resource Loader +<<Dennis>><<Singleton> + + + + com.umlet.element.Relation + + 768 + 472 + 136 + 104 + + lt=<<<<- + 120;24;120;88;24;88 + + + com.umlet.element.Relation + + 384 + 176 + 256 + 56 + + lt=->>>> +m1=1..1 +m2=1..1 +<Knows about + 240;40;24;40 + + + com.umlet.element.Class + + 256 + 360 + 232 + 104 + + Defines.h +<<Header file>> +-- +Enum ObjectType(static, dynamic, specials); +. +Struct static; +Struct dynamic; +Struct specials + + com.umlet.element.Class @@ -229,7 +187,7 @@ Privates: com.umlet.element.Relation - 344 + 640 208 40 168 @@ -238,27 +196,26 @@ Privates: 24;24;24;152 - com.umlet.element.Relation + com.umlet.element.Class - 840 + 328 208 - 88 - 168 + 80 + 24 - lt=. -<Uses - 24;24;24;64;72;64;72;152 + Defines + - com.umlet.element.Relation + com.umlet.element.Package - 656 - 472 - 40 - 88 + 248 + 320 + 248 + 160 - lt=<<<<- - 24;72;24;24 + Defines + com.umlet.element.Relation @@ -274,4 +231,47 @@ m2=1..1 Uses> 24;40;80;40;120;40;120;144 + + com.umlet.element.Relation + + 656 + 472 + 40 + 88 + + lt=<<<<- + 24;72;24;24 + + + com.umlet.element.Class + + 560 + 544 + 232 + 136 + + <<Interface>> +Parser +-- +Functions: +vector<struct> Parse(); +- +Privates: +enum headerType; +const int FileHeaderSize; +const int FileVersion; + + + + + com.umlet.element.Package + + 552 + 320 + 584 + 368 + + LevelLoader + + diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 6b66a9d5..bfa96d35 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -184,6 +184,8 @@ + + @@ -202,6 +204,8 @@ + + diff --git a/Code/Game/GameLogic/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader.cpp new file mode 100644 index 00000000..0e302d37 --- /dev/null +++ b/Code/Game/GameLogic/LevelLoader.cpp @@ -0,0 +1,17 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "LevelLoader.h" +using namespace GameLogic; +using namespace GameLogic::LevelLoader; + +std::vector LevelLoader::LoadLevel(std::string fileName) +{ + Parser->parse(fileName); +} + +std::vector LevelLoader::LoadLevelHeader(std::string fileName) +{ + parser->parseHeader(fileName); +} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader.h b/Code/Game/GameLogic/LevelLoader.h new file mode 100644 index 00000000..c33cd09b --- /dev/null +++ b/Code/Game/GameLogic/LevelLoader.h @@ -0,0 +1,29 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#ifndef LEVELLOADER_H +#define LEVELLOADER_H + +#include +#include +#include "ObjectDefines.h" +#include "LevelParser.h" + +namespace GameLogic +{ + class LevelLoader + { + + public: + LevelLoader(){this->parser = new Parser()}; + ~LevelLoader(){}; + std::vector LoadLevel(std::string fileName); //loads the level and objects from file + std::vector LoadLevelHeader(std::string fileName); //just for fast access for the meta information about the level. + + private: + LevelParser parser; + }; +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/Loader.cpp b/Code/Game/GameLogic/Loader.cpp new file mode 100644 index 00000000..3cc68c50 --- /dev/null +++ b/Code/Game/GameLogic/Loader.cpp @@ -0,0 +1,18 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "Loader.h" + +using namespace GameLogic::LevelLoader; +using namespace Oyster::Resource; +using namespace std; + +char* Loader::LoadFile(std::string fileName) +{ + //convert from string to wstring + std::wstring temp(fileName.begin(), fileName.end()); + + //convert from wstring to wchar then loads the file + return OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Loader.h b/Code/Game/GameLogic/Loader.h new file mode 100644 index 00000000..0d0a662f --- /dev/null +++ b/Code/Game/GameLogic/Loader.h @@ -0,0 +1,28 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#ifndef LOADER_H +#define LOADER_H + +#include "Resource\OysterResource.h" +#include + +namespace GameLogic +{ + namespace LevelLoader + { + class Loader + { + public: + Loader(){}; + ~Loader(){}; + char* LoadFile(std::string fileName); + + //TODO: + //Add functionality to load physicsObjects (hitboxes) + }; + } +} + +#endif; \ No newline at end of file From e188794aa3f5c8572517662d1e8cacf8c884de05 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Mon, 27 Jan 2014 10:14:02 +0100 Subject: [PATCH 04/12] GL - Load level in LevelParser --- Code/Game/GameLogic/LevelParser.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/LevelParser.cpp b/Code/Game/GameLogic/LevelParser.cpp index 1f6a9398..5a709316 100644 --- a/Code/Game/GameLogic/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelParser.cpp @@ -1,5 +1,7 @@ #include "LevelParser.h" +#include "Loader.h" + using namespace GameLogic; using namespace ::LevelFileLoader; @@ -15,6 +17,8 @@ LevelParser::~LevelParser() std::vector LevelParser::Parse(std::string filename) { //Read entire level file. + Loader loader; + unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str()); std::vector objects; @@ -25,6 +29,7 @@ std::vector LevelParser::Parse(std::string filename) //Get typeID int typeID = 0; + //Unpack ID switch(typeID) { @@ -50,6 +55,8 @@ std::vector LevelParser::Parse(std::string filename) ObjectTypeHeader LevelParser::ParseHeader(std::string filename) { //Read entire level file. + Loader loader; + unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str()); //Find the header in the returned string. unsigned int counter = 0; @@ -65,7 +72,8 @@ ObjectTypeHeader LevelParser::ParseHeader(std::string filename) { case TypeID_LevelHeader: //Call function - + + counter += LevelHeaderSize; break; case TypeID_Object: //Call function From 1748fe323a5d531ed73a3651f24110260475e2ef Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Mon, 27 Jan 2014 10:15:39 +0100 Subject: [PATCH 05/12] GL - Added Parsing functions for levelLoader and moved Packing classes to misc --- Code/Game/GameLogic/GameLogic.vcxproj | 2 + Code/Game/GameLogic/Loader.cpp | 5 +- Code/Game/GameLogic/Loader.h | 4 +- Code/Game/GameLogic/ObjectDefines.h | 4 +- Code/Game/GameLogic/ParseFunctions.cpp | 83 +++ Code/Game/GameLogic/ParserFunctions.h | 22 + Code/Misc/Misc.vcxproj | 2 + Code/Misc/Misc.vcxproj.filters | 6 + Code/Misc/Packing/Packing.cpp | 346 +++++++++++++ Code/Misc/Packing/Packing.h | 81 +++ .../Messages/MessageHeader.cpp | 3 +- .../NetworkDependencies.vcxproj | 2 - .../NetworkDependencies.vcxproj.filters | 2 - Code/Network/NetworkDependencies/Packing.cpp | 486 ------------------ Code/Network/NetworkDependencies/Packing.h | 107 ---- 15 files changed, 551 insertions(+), 604 deletions(-) create mode 100644 Code/Game/GameLogic/ParseFunctions.cpp create mode 100644 Code/Game/GameLogic/ParserFunctions.h create mode 100644 Code/Misc/Packing/Packing.cpp create mode 100644 Code/Misc/Packing/Packing.h delete mode 100644 Code/Network/NetworkDependencies/Packing.cpp delete mode 100644 Code/Network/NetworkDependencies/Packing.h diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index ba7603a7..54ec2d7e 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -189,6 +189,7 @@ + @@ -210,6 +211,7 @@ + diff --git a/Code/Game/GameLogic/Loader.cpp b/Code/Game/GameLogic/Loader.cpp index ec537765..01047b2f 100644 --- a/Code/Game/GameLogic/Loader.cpp +++ b/Code/Game/GameLogic/Loader.cpp @@ -8,11 +8,12 @@ using namespace GameLogic::LevelFileLoader; using namespace Oyster::Resource; using namespace std; -char* Loader::LoadFile(std::string fileName) +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 (char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); + return (unsigned char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Loader.h b/Code/Game/GameLogic/Loader.h index 72d53854..d77921c5 100644 --- a/Code/Game/GameLogic/Loader.h +++ b/Code/Game/GameLogic/Loader.h @@ -15,9 +15,9 @@ namespace GameLogic class Loader { public: - Loader(){}; + Loader (){}; ~Loader(){}; - char* LoadFile(std::string fileName); + unsigned char* LoadFile(std::string fileName, int &size); //TODO: //Add functionality to load physicsObjects (hitboxes) diff --git a/Code/Game/GameLogic/ObjectDefines.h b/Code/Game/GameLogic/ObjectDefines.h index eae1b0c9..7f2307d1 100644 --- a/Code/Game/GameLogic/ObjectDefines.h +++ b/Code/Game/GameLogic/ObjectDefines.h @@ -24,9 +24,9 @@ namespace GameLogic struct ObjectHeader : public ObjectTypeHeader { //Model, - + int ModelID; //Texture - + int TextureID; //Position float position[3]; //Rotation diff --git a/Code/Game/GameLogic/ParseFunctions.cpp b/Code/Game/GameLogic/ParseFunctions.cpp new file mode 100644 index 00000000..28199e6b --- /dev/null +++ b/Code/Game/GameLogic/ParseFunctions.cpp @@ -0,0 +1,83 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "ParserFunctions.h" +#include "../../Misc/Packing/Packing.h" +#include + +using namespace Oyster::Packing; +using namespace GameLogic; +using namespace std; + +ObjectTypeHeader parseObjectTypeHeader(unsigned char* buffer) +{ + int i = Unpacki(buffer); + + 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; + + + //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; +} \ No newline at end of file diff --git a/Code/Game/GameLogic/ParserFunctions.h b/Code/Game/GameLogic/ParserFunctions.h new file mode 100644 index 00000000..0608e77a --- /dev/null +++ b/Code/Game/GameLogic/ParserFunctions.h @@ -0,0 +1,22 @@ +////////////////////////////////// +// 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 diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index 0b7bf576..6c3db1ec 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -146,6 +146,7 @@ + @@ -164,6 +165,7 @@ + diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index 44348332..8413642a 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -48,6 +48,9 @@ Source Files + + Source Files + @@ -110,5 +113,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Code/Misc/Packing/Packing.cpp b/Code/Misc/Packing/Packing.cpp new file mode 100644 index 00000000..30064b0a --- /dev/null +++ b/Code/Misc/Packing/Packing.cpp @@ -0,0 +1,346 @@ +#include "Packing.h" + +/*************************** + Packing +***************************/ + +#include + +namespace Oyster +{ + namespace Packing + { + //bool (1-bit) + void Pack(unsigned char buffer[], bool i) + { + *buffer++ = i; + } + + //char (8-bit) + void Pack(unsigned char buffer[], char i) + { + *buffer++ = i; + } + + void Pack(unsigned char buffer[], unsigned char i) + { + *buffer++ = i; + } + + //short (16-bit) + void Pack(unsigned char buffer[], short i) + { + *buffer++ = i >> 8; + *buffer++ = (char)i; + } + + void Pack(unsigned char buffer[], unsigned short i) + { + *buffer++ = i >> 8; + *buffer++ = (char)i; + } + + //int (32-bit) + void Pack(unsigned char buffer[], int i) + { + *buffer++ = i >> 24; + *buffer++ = i >> 16; + *buffer++ = i >> 8; + *buffer++ = i; + } + + void Pack(unsigned char buffer[], unsigned int i) + { + *buffer++ = i >> 24; + *buffer++ = i >> 16; + *buffer++ = i >> 8; + *buffer++ = i; + } + + //__int64 (64-bit) + void Pack(unsigned char buffer[], __int64 i) + { + *buffer++ = (char)(i >> 56); + *buffer++ = (char)(i >> 48); + *buffer++ = (char)(i >> 40); + *buffer++ = (char)(i >> 32); + *buffer++ = (char)(i >> 24); + *buffer++ = (char)(i >> 16); + *buffer++ = (char)(i >> 8); + *buffer++ = (char)i; + } + + void Pack(unsigned char buffer[], unsigned __int64 i) + { + *buffer++ = (char)(i >> 56); + *buffer++ = (char)(i >> 48); + *buffer++ = (char)(i >> 40); + *buffer++ = (char)(i >> 32); + *buffer++ = (char)(i >> 24); + *buffer++ = (char)(i >> 16); + *buffer++ = (char)(i >> 8); + *buffer++ = (char)i; + } + + //floating point (32, 64-bit) + void Pack(unsigned char buffer[], float i) + { + int tempFloat = (int)Pack754(i, 32, 8); + Pack(buffer, tempFloat); + } + + void Pack(unsigned char buffer[], double i) + { + __int64 tempDouble = Pack754(i, 64, 11); + Pack(buffer, tempDouble); + } + + //string + void Pack(unsigned char buffer[], char str[]) + { + short len = (short)strlen(str); + Pack(buffer, len); + buffer += 2; + memcpy(buffer, str, len); + } + + void Pack(unsigned char buffer[], std::string& str) + { + short len = (short)str.length(); + Pack(buffer, len); + buffer += 2; + memcpy(buffer, str.c_str(), len); + } + + unsigned __int64 Pack754(long double f, unsigned bits, unsigned expbits) + { + long double fnorm; + int shift; + long long sign, exp, significand; + unsigned significandbits = bits - expbits - 1; // -1 for sign bit + + if (f == 0.0) + return 0; // get this special case out of the way + + // check sign and begin normalization + if (f < 0) + { + sign = 1; + fnorm = -f; + } + else + { + sign = 0; + fnorm = f; + } + + // get the normalized form of f and track the exponent + shift = 0; + while(fnorm >= 2.0) + { + fnorm /= 2.0; + shift++; + } + + while(fnorm < 1.0) + { + fnorm *= 2.0; + shift--; + } + + fnorm = fnorm - 1.0; + + // calculate the binary form (non-float) of the significand data + significand = (long long)(fnorm * ((1LL << significandbits) + 0.5f)); + + // get the biased exponent + exp = shift + ((1 << (expbits - 1)) - 1); // shift + bias + + // return the final answer + return (sign << (bits - 1)) | (exp << (bits - expbits - 1)) | significand; + } + + /****************************** + Unpacking + ******************************/ + + //bool (1-bit) + bool Unpackb(unsigned char buffer[]) + { + return *buffer; + } + + //char (8-bit) + char Unpackc(unsigned char buffer[]) + { + if(*buffer <= 0x7f) + { + return *buffer; + } + else + { + return (-1 - (unsigned char)(0xffu - *buffer)); + } + } + + unsigned char UnpackC(unsigned char buffer[]) + { + return *buffer; + } + + //short (16-bit) + short Unpacks(unsigned char buffer[]) + { + short i = ((short)buffer[0] << 8) | buffer[1]; + + if(i > 0x7fffu) + { + i = -1 - (unsigned short)(0xffffu - i); + } + + return i; + } + + unsigned short UnpackS(unsigned char buffer[]) + { + return ((unsigned int)buffer[0] << 8) | buffer[1]; + } + + //int (32-bit) + int Unpacki(unsigned char buffer[]) + { + int i = ((int)buffer[0] << 24) | + ((int)buffer[1] << 16) | + ((int)buffer[2] << 8) | + ((int)buffer[3]); + + if(i > 0x7fffffffu) + { + i = -1 - (int)(0xffffffffu - i); + } + + return i; + } + + unsigned int UnpackI(unsigned char buffer[]) + { + return ((unsigned int)buffer[0] << 24) | + ((unsigned int)buffer[1] << 16) | + ((unsigned int)buffer[2] << 8) | + ((unsigned int)buffer[3]); + } + + //__int64 (64-bit) + __int64 Unpacki64(unsigned char buffer[]) + { + __int64 i = ((__int64)buffer[0] << 56) | + ((__int64)buffer[1] << 48) | + ((__int64)buffer[2] << 40) | + ((__int64)buffer[3] << 32) | + ((__int64)buffer[4] << 24) | + ((__int64)buffer[5] << 16) | + ((__int64)buffer[6] << 8) | + (buffer[7]); + + if(i > 0x7fffffffffffffffu) + { + i = -1 - (__int64)(0xffffffffffffffffu - i); + } + + return i; + } + + unsigned __int64 UnpackI64(unsigned char buffer[]) + { + + return ((__int64)buffer[0] << 56) | + ((__int64)buffer[1] << 48) | + ((__int64)buffer[2] << 40) | + ((__int64)buffer[3] << 32) | + ((__int64)buffer[4] << 24) | + ((__int64)buffer[5] << 16) | + ((__int64)buffer[6] << 8) | + ((__int64)buffer[7]); + } + + //floating point (32, 64-bit) + float Unpackf(unsigned char buffer[]) + { + int tempFloat = Unpacki(buffer); + return (float)Unpack754(tempFloat, 32, 8); + } + + double Unpackd(unsigned char buffer[]) + { + __int64 tempDouble = Unpacki64(buffer); + return Unpack754(tempDouble, 64, 11); + } + + //string + char* UnpackCStr(unsigned char buffer[]) + { + short len = UnpackS(buffer); + char* str = new char[len+1]; + + buffer += 2; + for(int i = 0; i < len; i++) + { + str[i] = buffer[i]; + } + + str[len] = '\0'; + + return str; + } + + std::string UnpackStr(unsigned char buffer[]) + { + short len = UnpackS(buffer); + std::string temp; + temp.resize(len); + + buffer += 2; + for(int i = 0; i < len; i++) + { + temp[i] = buffer[i]; + } + + return temp; + } + + long double Unpack754(unsigned __int64 i, unsigned bits, unsigned expbits) + { + long double result; + long long shift; + unsigned bias; + unsigned significandbits = bits - expbits - 1; // -1 for sign bit + + if (i == 0) + return 0.0; + + // pull the significand + result = (long double)(i&((1LL << significandbits) - 1)); // mask + result /= (1LL << significandbits); // convert back to float + result += 1.0f; // add the one back on + + // deal with the exponent + bias = (1 << (expbits - 1)) - 1; + shift = ((i >> significandbits) & ((1LL << expbits) - 1)) - bias; + while(shift > 0) + { + result *= 2.0; + shift--; + } + while(shift < 0) + { + result /= 2.0; + shift++; + } + + // sign it + result *= (i >> (bits - 1)) & 1 ? -1.0 : 1.0; + + return result; + } + } +} diff --git a/Code/Misc/Packing/Packing.h b/Code/Misc/Packing/Packing.h new file mode 100644 index 00000000..47a65c51 --- /dev/null +++ b/Code/Misc/Packing/Packing.h @@ -0,0 +1,81 @@ +#ifndef PACKING_H +#define PACKING_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#include + +/****************************** + Packing +******************************/ +namespace Oyster +{ + namespace Packing + { + //bool (1-bit) + void Pack(unsigned char buffer[], bool i); + + //char (8-bit) + void Pack(unsigned char buffer[], char i); + void Pack(unsigned char buffer[], unsigned char i); // unsigned + + //short (16-bit) + void Pack(unsigned char buffer[], short i); + void Pack(unsigned char buffer[], unsigned short i); // unsigned + + //int (32-bit) + void Pack(unsigned char buffer[], int i); + void Pack(unsigned char buffer[], unsigned int i); // unsigned + + //__int64 (64-bit) + void Pack(unsigned char buffer[], __int64 i); + void Pack(unsigned char buffer[], unsigned __int64 i); // unsigned + + //floating point (32, 64-bit) + void Pack(unsigned char buffer[], float i); + void Pack(unsigned char buffer[], double i); + + //string + void Pack(unsigned char buffer[], char str[]); + void Pack(unsigned char buffer[], std::string& str); + + unsigned __int64 Pack754(long double f, unsigned bits, unsigned expbits); + + /****************************** + Unpacking + ******************************/ + + //bool (1-bit) + bool Unpackb(unsigned char buffer[]); + + //char (8-bit) + char Unpackc(unsigned char buffer[]); + unsigned char UnpackC(unsigned char buffer[]); // unsigned + + //short (16-bit) + short Unpacks(unsigned char buffer[]); + unsigned short UnpackS(unsigned char buffer[]); // unsigned + + //int (32-bit) + int Unpacki(unsigned char buffer[]); + unsigned int UnpackI(unsigned char buffer[]); // unsigned + + //__int64 (64-bit) + __int64 Unpacki64(unsigned char buffer[]); + unsigned __int64 UnpackI64(unsigned char buffer[]); // unsigned + + //floating point (32, 64-bit) + float Unpackf(unsigned char buffer[]); + double Unpackd(unsigned char buffer[]); + + //string + char* UnpackCStr(unsigned char buffer[]); + std::string UnpackStr(unsigned char buffer[]); + + long double Unpack754(unsigned __int64 i, unsigned bits, unsigned expbits); + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp index d2823b62..8f315797 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp @@ -1,8 +1,9 @@ #include "MessageHeader.h" -#include "../Packing.h" +#include "../../../Misc/Packing/Packing.h" #include using namespace std; +using namespace Oyster::Packing; using namespace Oyster::Network; using namespace Oyster::Network::Messages; using namespace Oyster::Network::Protocols; diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj index 4d2ad291..c0048016 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj @@ -157,7 +157,6 @@ - @@ -172,7 +171,6 @@ - diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index eadbbeb3..cce2fe94 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -7,7 +7,6 @@ - @@ -22,7 +21,6 @@ - diff --git a/Code/Network/NetworkDependencies/Packing.cpp b/Code/Network/NetworkDependencies/Packing.cpp deleted file mode 100644 index 41d059a3..00000000 --- a/Code/Network/NetworkDependencies/Packing.cpp +++ /dev/null @@ -1,486 +0,0 @@ -#include "Packing.h" - -/*************************** - Packing -***************************/ - -#include - -namespace Oyster -{ - namespace Network - { - namespace Packing - { - //bool (1-bit) - void Pack(unsigned char buffer[], bool i) - { - *buffer++ = i; - } - - //char (8-bit) - void Pack(unsigned char buffer[], char i) - { - *buffer++ = i; - } - - void Pack(unsigned char buffer[], unsigned char i) - { - *buffer++ = i; - } - - //short (16-bit) - void Pack(unsigned char buffer[], short i) - { - *buffer++ = i >> 8; - *buffer++ = (char)i; - } - - void Pack(unsigned char buffer[], unsigned short i) - { - *buffer++ = i >> 8; - *buffer++ = (char)i; - } - - //int (32-bit) - void Pack(unsigned char buffer[], int i) - { - *buffer++ = i >> 24; - *buffer++ = i >> 16; - *buffer++ = i >> 8; - *buffer++ = i; - } - - void Pack(unsigned char buffer[], unsigned int i) - { - *buffer++ = i >> 24; - *buffer++ = i >> 16; - *buffer++ = i >> 8; - *buffer++ = i; - } - - //__int64 (64-bit) - void Pack(unsigned char buffer[], __int64 i) - { - *buffer++ = (char)(i >> 56); - *buffer++ = (char)(i >> 48); - *buffer++ = (char)(i >> 40); - *buffer++ = (char)(i >> 32); - *buffer++ = (char)(i >> 24); - *buffer++ = (char)(i >> 16); - *buffer++ = (char)(i >> 8); - *buffer++ = (char)i; - } - - void Pack(unsigned char buffer[], unsigned __int64 i) - { - *buffer++ = (char)(i >> 56); - *buffer++ = (char)(i >> 48); - *buffer++ = (char)(i >> 40); - *buffer++ = (char)(i >> 32); - *buffer++ = (char)(i >> 24); - *buffer++ = (char)(i >> 16); - *buffer++ = (char)(i >> 8); - *buffer++ = (char)i; - } - - //floating point (32, 64-bit) - void Pack(unsigned char buffer[], float i) - { - int tempFloat = (int)Pack754(i, 32, 8); - Pack(buffer, tempFloat); - } - - void Pack(unsigned char buffer[], double i) - { - __int64 tempDouble = Pack754(i, 64, 11); - Pack(buffer, tempDouble); - } - - //string - void Pack(unsigned char buffer[], char str[]) - { - short len = (short)strlen(str); - Pack(buffer, len); - buffer += 2; - memcpy(buffer, str, len); - } - - void Pack(unsigned char buffer[], std::string& str) - { - short len = (short)str.length(); - Pack(buffer, len); - buffer += 2; - memcpy(buffer, str.c_str(), len); - } - - unsigned __int64 Pack754(long double f, unsigned bits, unsigned expbits) - { - long double fnorm; - int shift; - long long sign, exp, significand; - unsigned significandbits = bits - expbits - 1; // -1 for sign bit - - if (f == 0.0) - return 0; // get this special case out of the way - - // check sign and begin normalization - if (f < 0) - { - sign = 1; - fnorm = -f; - } - else - { - sign = 0; - fnorm = f; - } - - // get the normalized form of f and track the exponent - shift = 0; - while(fnorm >= 2.0) - { - fnorm /= 2.0; - shift++; - } - - while(fnorm < 1.0) - { - fnorm *= 2.0; - shift--; - } - - fnorm = fnorm - 1.0; - - // calculate the binary form (non-float) of the significand data - significand = (long long)(fnorm * ((1LL << significandbits) + 0.5f)); - - // get the biased exponent - exp = shift + ((1 << (expbits - 1)) - 1); // shift + bias - - // return the final answer - return (sign << (bits - 1)) | (exp << (bits - expbits - 1)) | significand; - } - - /****************************** - Unpacking - ******************************/ - - //bool (1-bit) - bool Unpackb(unsigned char buffer[]) - { - return *buffer; - } - - //char (8-bit) - char Unpackc(unsigned char buffer[]) - { - if(*buffer <= 0x7f) - { - return *buffer; - } - else - { - return (-1 - (unsigned char)(0xffu - *buffer)); - } - } - - unsigned char UnpackC(unsigned char buffer[]) - { - return *buffer; - } - - //short (16-bit) - short Unpacks(unsigned char buffer[]) - { - short i = ((short)buffer[0] << 8) | buffer[1]; - - if(i > 0x7fffu) - { - i = -1 - (unsigned short)(0xffffu - i); - } - - return i; - } - - unsigned short UnpackS(unsigned char buffer[]) - { - return ((unsigned int)buffer[0] << 8) | buffer[1]; - } - - //int (32-bit) - int Unpacki(unsigned char buffer[]) - { - int i = ((int)buffer[0] << 24) | - ((int)buffer[1] << 16) | - ((int)buffer[2] << 8) | - ((int)buffer[3]); - - if(i > 0x7fffffffu) - { - i = -1 - (int)(0xffffffffu - i); - } - - return i; - } - - unsigned int UnpackI(unsigned char buffer[]) - { - return ((unsigned int)buffer[0] << 24) | - ((unsigned int)buffer[1] << 16) | - ((unsigned int)buffer[2] << 8) | - ((unsigned int)buffer[3]); - } - - //__int64 (64-bit) - __int64 Unpacki64(unsigned char buffer[]) - { - __int64 i = ((__int64)buffer[0] << 56) | - ((__int64)buffer[1] << 48) | - ((__int64)buffer[2] << 40) | - ((__int64)buffer[3] << 32) | - ((__int64)buffer[4] << 24) | - ((__int64)buffer[5] << 16) | - ((__int64)buffer[6] << 8) | - (buffer[7]); - - if(i > 0x7fffffffffffffffu) - { - i = -1 - (__int64)(0xffffffffffffffffu - i); - } - - return i; - } - - unsigned __int64 UnpackI64(unsigned char buffer[]) - { - - return ((__int64)buffer[0] << 56) | - ((__int64)buffer[1] << 48) | - ((__int64)buffer[2] << 40) | - ((__int64)buffer[3] << 32) | - ((__int64)buffer[4] << 24) | - ((__int64)buffer[5] << 16) | - ((__int64)buffer[6] << 8) | - ((__int64)buffer[7]); - } - - //floating point (32, 64-bit) - float Unpackf(unsigned char buffer[]) - { - int tempFloat = Unpacki(buffer); - return (float)Unpack754(tempFloat, 32, 8); - } - - double Unpackd(unsigned char buffer[]) - { - __int64 tempDouble = Unpacki64(buffer); - return Unpack754(tempDouble, 64, 11); - } - - //string - char* UnpackCStr(unsigned char buffer[]) - { - short len = UnpackS(buffer); - char* str = new char[len+1]; - - buffer += 2; - for(int i = 0; i < len; i++) - { - str[i] = buffer[i]; - } - - str[len] = '\0'; - - return str; - } - - std::string UnpackStr(unsigned char buffer[]) - { - short len = UnpackS(buffer); - std::string temp; - temp.resize(len); - - buffer += 2; - for(int i = 0; i < len; i++) - { - temp[i] = buffer[i]; - } - - return temp; - } - - long double Unpack754(unsigned __int64 i, unsigned bits, unsigned expbits) - { - long double result; - long long shift; - unsigned bias; - unsigned significandbits = bits - expbits - 1; // -1 for sign bit - - if (i == 0) - return 0.0; - - // pull the significand - result = (long double)(i&((1LL << significandbits) - 1)); // mask - result /= (1LL << significandbits); // convert back to float - result += 1.0f; // add the one back on - - // deal with the exponent - bias = (1 << (expbits - 1)) - 1; - shift = ((i >> significandbits) & ((1LL << expbits) - 1)) - bias; - while(shift > 0) - { - result *= 2.0; - shift--; - } - while(shift < 0) - { - result /= 2.0; - shift++; - } - - // sign it - result *= (i >> (bits - 1)) & 1 ? -1.0 : 1.0; - - return result; - } - } - } -} - -/* -int32_t pack(unsigned char* buffer, char* format, ...) -{ - va_list ap; - int16_t h; - int32_t l; - int8_t c; - float f; - double d; - char* s; - int32_t size = 0, len; - - va_start(ap, format); - - for(; *format != '\0'; format++) - { - switch(*format) - { - case 'h': // 16-bit - size += 2; - h = (int16_t)va_arg(ap, int); - packi16(buffer, h); - buffer += 2; - break; - case 'l': // 32-bit - size += 4; - l = va_arg(ap, int32_t); - packi32(buffer, l); - buffer += 4; - break; - case 'c': // 8-bit - size += 1; - c = (int8_t)va_arg(ap, int); - *buffer++ = (c >> 0)&0xff; - break; - case 'f': // float (32-bit) - size += 4; - f = (float)va_arg(ap, double); - //l = pack754(f, 32, 8); - packi32(buffer, l); - buffer += 4; - break; - case 'd': // double (64-bit) - size += 8; - d = (float)va_arg(ap, double); - //l = pack754(f, 64, 11); - packi32(buffer, l); - buffer += 4; - break; - case 's': // string - s = va_arg(ap, char*); - len = strlen(s); - size += len + 2; - packi16(buffer, len); - buffer += 2; - memcpy(buffer, s, len); - buffer += len; - break; - } - } - - va_end(ap); - - return size; -} -*/ - -/* -void unpack(unsigned char* buffer, char* format, ...) -{ - va_list ap; - int16_t* h; - int32_t* l; - int32_t pf; - int64_t pd; - int8_t* c; - float* f; - double* d; - char* s; - int32_t len, count, maxstrlen = 0; - - va_start(ap, format); - - for(; *format != '\0'; format++) - { - switch(*format) - { - case 'h': // 16-bit - h = va_arg(ap, int16_t*); - *h = unpacki16(buffer); - buffer += 2; - break; - case 'l': // 32-bit - l = va_arg(ap, int32_t*); - *l = unpacki32(buffer); - buffer += 4; - break; - case 'c': // 8-bit - c = va_arg(ap, int8_t*); - *c = *buffer++; - break; - case 'f': // float - f = va_arg(ap, float*); - pf = unpacki32(buffer); - buffer += 4; - //*f = unpack754(pf, 32, 8); - break; - case 'd': // double (64-bit) - d = va_arg(ap, double*); - pd = unpacki64(buffer); - buffer += 8; - //*d = unpack754(pf, 64, 11); - break; - case 's': // string - s = va_arg(ap, char*); - len = unpacki16(buffer); - buffer += 2; - if (maxstrlen > 0 && len > maxstrlen) count = maxstrlen - 1; - else count = len; - memcpy(s, buffer, count); - s[count] = '\0'; - buffer += len; - break; - default: - if (isdigit(*format)) // track max str len - { - maxstrlen = maxstrlen * 10 + (*format-'0'); - } - } - - if(!isdigit(*format)) - maxstrlen = 0; - } - - va_end(ap); -}*/ \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Packing.h b/Code/Network/NetworkDependencies/Packing.h deleted file mode 100644 index aaf3a1b8..00000000 --- a/Code/Network/NetworkDependencies/Packing.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef PACKING_H -#define PACKING_H - -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include - -/****************************** - Packing -******************************/ -namespace Oyster -{ - namespace Network - { - namespace Packing - { - //bool (1-bit) - void Pack(unsigned char buffer[], bool i); - - //char (8-bit) - void Pack(unsigned char buffer[], char i); - void Pack(unsigned char buffer[], unsigned char i); // unsigned - - //short (16-bit) - void Pack(unsigned char buffer[], short i); - void Pack(unsigned char buffer[], unsigned short i); // unsigned - - //int (32-bit) - void Pack(unsigned char buffer[], int i); - void Pack(unsigned char buffer[], unsigned int i); // unsigned - - //__int64 (64-bit) - void Pack(unsigned char buffer[], __int64 i); - void Pack(unsigned char buffer[], unsigned __int64 i); // unsigned - - //floating point (32, 64-bit) - void Pack(unsigned char buffer[], float i); - void Pack(unsigned char buffer[], double i); - - //string - void Pack(unsigned char buffer[], char str[]); - void Pack(unsigned char buffer[], std::string& str); - - unsigned __int64 Pack754(long double f, unsigned bits, unsigned expbits); - - /****************************** - Unpacking - ******************************/ - - //bool (1-bit) - bool Unpackb(unsigned char buffer[]); - - //char (8-bit) - char Unpackc(unsigned char buffer[]); - unsigned char UnpackC(unsigned char buffer[]); // unsigned - - //short (16-bit) - short Unpacks(unsigned char buffer[]); - unsigned short UnpackS(unsigned char buffer[]); // unsigned - - //int (32-bit) - int Unpacki(unsigned char buffer[]); - unsigned int UnpackI(unsigned char buffer[]); // unsigned - - //__int64 (64-bit) - __int64 Unpacki64(unsigned char buffer[]); - unsigned __int64 UnpackI64(unsigned char buffer[]); // unsigned - - //floating point (32, 64-bit) - float Unpackf(unsigned char buffer[]); - double Unpackd(unsigned char buffer[]); - - //string - char* UnpackCStr(unsigned char buffer[]); - std::string UnpackStr(unsigned char buffer[]); - - long double Unpack754(unsigned __int64 i, unsigned bits, unsigned expbits); - } - } -} - - -//int32_t pack(unsigned char* buffer, char* format, ...); - -//void unpack(unsigned char* buffer, char* format, ...); - - -/*********************************************** -* This table is used for naming pack/unpack functions. -* It's also used to identify types in the 'format' string in function pack()/unpack() -* -* bits |signed unsigned float string -* -----+---------------------------------- -* 1 | b -* 8 | c C -* 16 | s S f -* 32 | i I d -* 64 | q Q g -* - | str -* -* (16-bit unsigned length is automatically added in front of strings) -* -*/ - -#endif \ No newline at end of file From 51a1b3ecff054787361f4021826a5c6b0de97f4b Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Mon, 27 Jan 2014 13:54:56 +0100 Subject: [PATCH 06/12] GL - Resource get size --- Code/Misc/Resource/OResourceHandler.cpp | 7 +++++++ Code/Misc/Resource/OysterResource.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/Code/Misc/Resource/OResourceHandler.cpp b/Code/Misc/Resource/OResourceHandler.cpp index 918ecd1d..52d93af0 100644 --- a/Code/Misc/Resource/OResourceHandler.cpp +++ b/Code/Misc/Resource/OResourceHandler.cpp @@ -214,7 +214,14 @@ int OysterResource::GetResourceId(const wchar_t c[]) return -1; } +int OysterResource::GetResourceSize(const OHRESOURCE& resource) +{ + OResource* t = resourcePrivate.FindResource(resource); + if(t) return t->GetResourceSize(); + + return -1; +} OResource* ResourcePrivate::FindResource(const OHRESOURCE& h) const { diff --git a/Code/Misc/Resource/OysterResource.h b/Code/Misc/Resource/OysterResource.h index d6509b54..8adce704 100644 --- a/Code/Misc/Resource/OysterResource.h +++ b/Code/Misc/Resource/OysterResource.h @@ -150,6 +150,11 @@ namespace Oyster * @return Returns the accociated ID */ static int GetResourceId(const wchar_t filename[]); + + + static int GetResourceSize(const OHRESOURCE& resource); + + }; } From 91bf6ce901e4b56d1e7ac3fba9a23541be924c30 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Mon, 27 Jan 2014 13:57:18 +0100 Subject: [PATCH 07/12] 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 From dd2b214122186dd1797ccd2d7af1b6388e14c8ab Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Mon, 27 Jan 2014 14:57:18 +0100 Subject: [PATCH 08/12] =?UTF-8?q?GL-=20la=20in=20memcpy=20f=C3=B6r=20parsi?= =?UTF-8?q?ng=20i=20parseFunctions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/Game/GameLogic/LevelParser.cpp | 8 +-- Code/Game/GameLogic/Loader.cpp | 5 +- Code/Game/GameLogic/ParseFunctions.cpp | 70 +++----------------------- Code/Game/GameLogic/ParseFunctions.h | 4 +- 4 files changed, 17 insertions(+), 70 deletions(-) diff --git a/Code/Game/GameLogic/LevelParser.cpp b/Code/Game/GameLogic/LevelParser.cpp index a03da6eb..a957b88a 100644 --- a/Code/Game/GameLogic/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelParser.cpp @@ -31,7 +31,8 @@ std::vector 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 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: diff --git a/Code/Game/GameLogic/Loader.cpp b/Code/Game/GameLogic/Loader.cpp index 01047b2f..0afb48de 100644 --- a/Code/Game/GameLogic/Loader.cpp +++ b/Code/Game/GameLogic/Loader.cpp @@ -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; } \ No newline at end of file diff --git a/Code/Game/GameLogic/ParseFunctions.cpp b/Code/Game/GameLogic/ParseFunctions.cpp index 11e7b0ab..64405ff5 100644 --- a/Code/Game/GameLogic/ParseFunctions.cpp +++ b/Code/Game/GameLogic/ParseFunctions.cpp @@ -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; } } } \ No newline at end of file diff --git a/Code/Game/GameLogic/ParseFunctions.h b/Code/Game/GameLogic/ParseFunctions.h index 180f82c3..5638f419 100644 --- a/Code/Game/GameLogic/ParseFunctions.h +++ b/Code/Game/GameLogic/ParseFunctions.h @@ -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. } } From 4de1c1aafd438efcd3080de77a7ebd9e5d28ee71 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 28 Jan 2014 11:27:29 +0100 Subject: [PATCH 09/12] GL - More Object structs, LevelLoader api comments. Changed the LevelParser to use the new functions from ParserFunctions. Might need to cast something to (void*). --- Code/Game/GameLogic/LevelLoader.cpp | 2 +- Code/Game/GameLogic/LevelLoader.h | 16 ++++- Code/Game/GameLogic/LevelParser.cpp | 97 +++++++++++++++++------------ Code/Game/GameLogic/LevelParser.h | 25 +------- Code/Game/GameLogic/ObjectDefines.h | 78 +++++++++++++++++++++-- 5 files changed, 148 insertions(+), 70 deletions(-) diff --git a/Code/Game/GameLogic/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader.cpp index 3827251a..a6f8bb98 100644 --- a/Code/Game/GameLogic/LevelLoader.cpp +++ b/Code/Game/GameLogic/LevelLoader.cpp @@ -12,7 +12,7 @@ std::vector LevelLoader::LoadLevel(std::string fileName) return parser->Parse(fileName); } -ObjectTypeHeader LevelLoader::LoadLevelHeader(std::string fileName) +LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) { return parser->ParseHeader(fileName); } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader.h b/Code/Game/GameLogic/LevelLoader.h index ed7aab4d..8f87d141 100644 --- a/Code/Game/GameLogic/LevelLoader.h +++ b/Code/Game/GameLogic/LevelLoader.h @@ -19,8 +19,20 @@ namespace GameLogic public: LevelLoader(){this->parser = new GameLogic::LevelFileLoader::LevelParser(); } ~LevelLoader(){} - std::vector LoadLevel(std::string fileName); //loads the level and objects from file - ObjectTypeHeader LoadLevelHeader(std::string fileName); //just for fast access for the meta information about the level. + + /******************************************************** + * 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); //. private: GameLogic::LevelFileLoader::LevelParser *parser; diff --git a/Code/Game/GameLogic/LevelParser.cpp b/Code/Game/GameLogic/LevelParser.cpp index a957b88a..acc52c69 100644 --- a/Code/Game/GameLogic/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelParser.cpp @@ -6,9 +6,10 @@ using namespace GameLogic; using namespace ::LevelFileLoader; - LevelParser::LevelParser() { + formatVersion.formatVersionMajor = 1; + formatVersion.formatVersionMinor = 0; } LevelParser::~LevelParser() @@ -18,35 +19,43 @@ 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(), stringSize); + int bufferSize = 0; + unsigned int counter = 0; std::vector objects; - unsigned int counter = 0; - - while(counter < stringSize) + //Read entire level file. + Loader loader; + unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), bufferSize); + + //Read format version + FormatVersion levelFormatVersion; + ParseObject(&buffer[counter], formatVersion, sizeof(formatVersion)); + if(this->formatVersion != levelFormatVersion) + { + //Do something if it's not the same version + } + + while(counter < bufferSize) { //Get typeID ObjectTypeHeader typeID; - typeID = ParseObjectTypeHeader(&buffer[counter]); - //counter += 4; - //Unpack ID + ParseObject(&buffer[counter], typeID, sizeof(typeID)); switch((int)typeID.typeID) { - case TypeID_LevelHeader: - //Call function - counter += LevelHeaderSize; + case ObjectType_LevelMetaData: + LevelMetaData header; + //ParseObject(&buffer[counter], header, sizeof(header)); + objects.push_back(header); + counter += sizeof(header); break; - case TypeID_Object: - //Call function - objects.push_back(ParseObjectHeader(&buffer[counter])); - counter += sizeof(ObjectHeader); - break; + case ObjectType_Dynamic: + ObjectHeader header; + ParseObject(&buffer[counter], header, sizeof(header)); + objects.push_back(header); + counter += sizeof(header); default: //Couldn't find typeID. FAIL!!!!!! break; @@ -56,36 +65,44 @@ 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) +//för meta information om leveln. +LevelMetaData LevelParser::ParseHeader(std::string filename) { - int stringSize = 0; + int bufferSize = 0; + unsigned int counter = 0; + + LevelMetaData levelHeader; + levelHeader.typeID = ObjectType::ObjectType_Unknown; + //Read entire level file. Loader loader; - unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), stringSize); + unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), bufferSize); + + //Read format version + FormatVersion levelFormatVersion; + ParseObject(&buffer[counter], formatVersion, sizeof(formatVersion)); + if(this->formatVersion != levelFormatVersion) + { + //Do something if it's not the same version + } //Find the header in the returned string. - unsigned int counter = 0; - - - ObjectTypeHeader header; - header.typeID = ObjectType_Level; - - while(counter < stringSize) + while(counter < bufferSize) { ObjectTypeHeader typeID; - typeID = ParseObjectTypeHeader(buffer); + ParseObject(&buffer[counter], typeID, sizeof(typeID)); + switch(typeID.typeID) { - case TypeID_LevelHeader: - //Call function - - counter += LevelHeaderSize; + case ObjectType_LevelMetaData: + //ParseObject(&buffer[counter], levelHeader, sizeof(levelHeader)); + return levelHeader; + counter += sizeof(LevelMetaData); break; - case TypeID_Object: - //Call function - counter += ObjectHeaderSize; + case ObjectType_Dynamic: + //Do not call parse this object, since we are only interested in the LevelMetaData + //Only increase the counter size + counter += sizeof(ObjectHeader); break; default: @@ -94,5 +111,5 @@ ObjectTypeHeader LevelParser::ParseHeader(std::string filename) } } - return header; + return levelHeader; } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelParser.h b/Code/Game/GameLogic/LevelParser.h index bcb9cb31..6dce25f8 100644 --- a/Code/Game/GameLogic/LevelParser.h +++ b/Code/Game/GameLogic/LevelParser.h @@ -19,31 +19,10 @@ namespace GameLogic std::vector Parse(std::string filename); // - ObjectTypeHeader ParseHeader(std::string filename); + LevelMetaData ParseHeader(std::string filename); private: - static const int TypeHeaderSize = 4; //Including the TypeID - static const int ObjectHeaderSize = 10; //Including modelID, textureID, position, rotation, scale. - static const int LevelHeaderSize = 10; //Including Format version, Name, Map version etc. - - static const int FormatVersionMajor = 1; - static const int FormatVersionMinor = 0; - - /************************************* - Question - *************************************/ - //Could we use the IDs in "ObjectDefines.h" or do we have to use our own??? - enum TypeID - { - TypeID_LevelHeader, - TypeID_Player, - TypeID_Object, - - - TypeID_NUM_OF_TYPES, - - ObjectType_Unknown = -1, - }; + FormatVersion formatVersion; }; } diff --git a/Code/Game/GameLogic/ObjectDefines.h b/Code/Game/GameLogic/ObjectDefines.h index 7f2307d1..2d3e09f0 100644 --- a/Code/Game/GameLogic/ObjectDefines.h +++ b/Code/Game/GameLogic/ObjectDefines.h @@ -1,27 +1,97 @@ #ifndef OBJECT_DEFINES_H #define OBJECT_DEFINES_H +#include +#include + namespace GameLogic { + /************************************ + Enums + *************************************/ + enum ObjectType { - ObjectType_Level, + ObjectType_LevelMetaData, ObjectType_Static, ObjectType_Dynamic, - + //Etc ObjectType_NUM_OF_TYPES, ObjectType_Unknown = -1, }; + enum UsePhysics + { + UsePhysics_UseFullPhysics, + UsePhysics_IgnoreGravity, + UsePhysics_IgnorePhysics, + + UsePhysics_Count, + UsePhysics_Unknown = -1, + }; + + //Should this be moved somewhere else? + enum GameMode + { + GameMode_FreeForAll, + GameMode_TeamDeathMatch, + //Etc + + GameMode_Count, + GameMode_Unknown = -1, + }; + + + /************************************ + Structs + *************************************/ + + struct FormatVersion + { + int formatVersionMajor; + int formatVersionMinor; + + bool operator ==(const FormatVersion& obj) + { + return (this->formatVersionMajor != obj.formatVersionMajor && this->formatVersionMinor != obj.formatVersionMinor); + } + + bool operator !=(const FormatVersion& obj) + { + return !(*this == obj); + } + }; + struct ObjectTypeHeader { ObjectType typeID; - }; - struct ObjectHeader : public ObjectTypeHeader + struct PhysicsObject + { + float mass; + float elasticity; + float frictionCoeffStatic; + float frictionCoeffDynamic; + float inertiaTensor[16]; + UsePhysics usePhysics; + }; + + struct LevelMetaData : ObjectTypeHeader + { + std::string levelName; + FormatVersion levelVersion; + std::string levelDescription; + std::string levelAuthor; + int maxNumberOfPlayer; + float worldSize; + int overviewPictureID; + std::vector gameModesSupported; + }; + + struct ObjectHeader : public PhysicsObject, public ObjectTypeHeader { //Model, int ModelID; From d2ebad74452c02865ada3104056bc6959c3dde00 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Tue, 28 Jan 2014 11:29:35 +0100 Subject: [PATCH 10/12] GL - Fixed ParseFunction so now we only have 1 + specialcases functions instead of 1 function for every case --- Code/Dokumentation/LevelLoader.uxf | 350 +++++++++--------- Code/Game/GameLogic/GameLogic.vcxproj | 18 +- .../{ => LevelLoader}/LevelLoader.cpp | 0 .../GameLogic/{ => LevelLoader}/LevelLoader.h | 0 .../{ => LevelLoader}/LevelParser.cpp | 1 - .../GameLogic/{ => LevelLoader}/LevelParser.h | 0 .../GameLogic/{ => LevelLoader}/Loader.cpp | 2 + .../Game/GameLogic/{ => LevelLoader}/Loader.h | 2 +- .../{ => LevelLoader}/ObjectDefines.h | 0 .../GameLogic/LevelLoader/ParseFunctions.cpp | 55 +++ .../GameLogic/LevelLoader/ParseFunctions.h | 19 + Code/Game/GameLogic/ParseFunctions.cpp | 33 -- Code/Game/GameLogic/ParseFunctions.h | 19 - 13 files changed, 261 insertions(+), 238 deletions(-) rename Code/Game/GameLogic/{ => LevelLoader}/LevelLoader.cpp (100%) rename Code/Game/GameLogic/{ => LevelLoader}/LevelLoader.h (100%) rename Code/Game/GameLogic/{ => LevelLoader}/LevelParser.cpp (99%) rename Code/Game/GameLogic/{ => LevelLoader}/LevelParser.h (100%) rename Code/Game/GameLogic/{ => LevelLoader}/Loader.cpp (94%) rename Code/Game/GameLogic/{ => LevelLoader}/Loader.h (88%) rename Code/Game/GameLogic/{ => LevelLoader}/ObjectDefines.h (100%) create mode 100644 Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp create mode 100644 Code/Game/GameLogic/LevelLoader/ParseFunctions.h delete mode 100644 Code/Game/GameLogic/ParseFunctions.cpp delete mode 100644 Code/Game/GameLogic/ParseFunctions.h diff --git a/Code/Dokumentation/LevelLoader.uxf b/Code/Dokumentation/LevelLoader.uxf index 90dcb0f7..b5cef8f0 100644 --- a/Code/Dokumentation/LevelLoader.uxf +++ b/Code/Dokumentation/LevelLoader.uxf @@ -4,8 +4,20 @@ com.umlet.element.Relation - 640 - 256 + 632 + 232 + 88 + 176 + + lt=. +<Uses + 24;24;24;64;72;64;72;160 + + + com.umlet.element.Relation + + 136 + 232 40 168 @@ -15,20 +27,111 @@ com.umlet.element.Relation - 840 - 256 - 88 + 448 + 496 + 40 + 88 + + lt=<<<<- + 24;72;24;24 + + + com.umlet.element.Relation + + 432 + 232 + 40 168 - lt=. -<Uses - 24;24;24;64;72;64;72;152 + lt=<<. + 24;24;24;152 com.umlet.element.Class + + 608 + 216 + 128 + 40 + + Resource Loader +<<Dennis>><<Singleton> + + + + com.umlet.element.Class + + 232 + 112 + 128 + 40 + + GameLogic +<<Erik>> + + + + com.umlet.element.Class + + 120 + 232 + 80 + 24 + + Defines + + + + com.umlet.element.Class + + 352 + 568 + 232 + 136 + + <<Interface>> +LevelParser +-- +Functions: +vector<struct> Parse(); +- +Privates: +enum headerType; +const int FileHeaderSize; +const int FileVersion; + + + + + com.umlet.element.Relation + + 336 + 88 + 136 + 160 + + lt=lt=->>>> +m1=1..1 +m2=1..1 +Uses> + 24;40;80;40;120;40;120;144 + + + com.umlet.element.Relation 560 - 408 + 496 + 136 + 104 + + lt=<<<<- + 120;24;120;88;24;88 + + + com.umlet.element.Class + + 352 + 384 232 136 @@ -45,54 +148,79 @@ Privates: - com.umlet.element.Class + com.umlet.element.Relation - 440 - 136 - 128 - 40 + 560 + 600 + 176 + 56 - GameLogic -<<Erik>> - + lt=- +m1=1..1 +m2=1..1 +Uses> + 24;40;160;40 com.umlet.element.Package - 552 - 368 + 344 + 344 584 368 LevelLoader + + com.umlet.element.Relation + + 472 + 200 + 152 + 56 + + lt=- +m1=1..1 +m2=1..1 +Uses> + 24;40;136;40 + com.umlet.element.Class - 560 - 592 - 232 - 136 + 416 + 232 + 80 + 24 - <<Interface>> -Parser --- -Functions: -vector<struct> Parse(); -- -Privates: -enum headerType; -const int FileHeaderSize; -const int FileVersion; + LevelLoader com.umlet.element.Class - 928 - 608 + 48 + 384 + 232 + 104 + + ObjectDefines.h +<<Header file>> +-- +Enum ObjectType(static, dynamic, specials); +. +Struct static; +Struct dynamic; +Struct specials + + + + com.umlet.element.Class + + 720 + 584 200 120 @@ -103,23 +231,23 @@ functions for creating the right structs - com.umlet.element.Relation + com.umlet.element.Package - 768 - 520 - 136 - 104 + 40 + 344 + 248 + 160 - lt=<<<<- - 120;24;120;88;24;88 + Defines + com.umlet.element.Class - 800 - 408 + 592 + 392 208 - 136 + 128 <<Interface>> Loader @@ -135,67 +263,8 @@ Privates: com.umlet.element.Relation - 656 - 520 - 40 - 88 - - lt=<<<<- - 24;72;24;24 - - - com.umlet.element.Class - - 328 - 256 - 80 - 24 - - Defines - - - - com.umlet.element.Relation - - 680 - 224 - 152 - 56 - - lt=- -m1=1..1 -m2=1..1 -Uses> - 24;40;136;40 - - - com.umlet.element.Class - - 624 - 256 - 80 - 24 - - LevelLoader - - - - - com.umlet.element.Relation - - 344 - 256 - 40 - 168 - - lt=<<. - 24;24;24;152 - - - com.umlet.element.Relation - - 384 - 224 + 176 + 200 256 56 @@ -205,73 +274,4 @@ m2=1..1 <Knows about 240;40;24;40 - - com.umlet.element.Relation - - 544 - 112 - 136 - 160 - - lt=lt=->>>> -m1=1..1 -m2=1..1 -Uses> - 24;40;80;40;120;40;120;144 - - - com.umlet.element.Relation - - 768 - 624 - 176 - 56 - - lt=- -m1=1..1 -m2=1..1 -Uses> - 24;40;160;40 - - - com.umlet.element.Package - - 248 - 368 - 248 - 160 - - Defines - - - - com.umlet.element.Class - - 256 - 408 - 232 - 104 - - Defines.h -<<Header file>> --- -Enum ObjectType(static, dynamic, specials); -. -Struct static; -Struct dynamic; -Struct specials - - - - com.umlet.element.Class - - 816 - 240 - 128 - 40 - - Resource Loader -<<Dennis>><<Singleton> - - diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index df1d09aa..809c82b5 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -184,12 +184,12 @@ - - + + - - - + + + @@ -207,11 +207,11 @@ - - - + + + - + diff --git a/Code/Game/GameLogic/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp similarity index 100% rename from Code/Game/GameLogic/LevelLoader.cpp rename to Code/Game/GameLogic/LevelLoader/LevelLoader.cpp diff --git a/Code/Game/GameLogic/LevelLoader.h b/Code/Game/GameLogic/LevelLoader/LevelLoader.h similarity index 100% rename from Code/Game/GameLogic/LevelLoader.h rename to Code/Game/GameLogic/LevelLoader/LevelLoader.h diff --git a/Code/Game/GameLogic/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp similarity index 99% rename from Code/Game/GameLogic/LevelParser.cpp rename to Code/Game/GameLogic/LevelLoader/LevelParser.cpp index a957b88a..08c4da7e 100644 --- a/Code/Game/GameLogic/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -15,7 +15,6 @@ LevelParser::~LevelParser() { } -// std::vector LevelParser::Parse(std::string filename) { int stringSize = 0; diff --git a/Code/Game/GameLogic/LevelParser.h b/Code/Game/GameLogic/LevelLoader/LevelParser.h similarity index 100% rename from Code/Game/GameLogic/LevelParser.h rename to Code/Game/GameLogic/LevelLoader/LevelParser.h diff --git a/Code/Game/GameLogic/Loader.cpp b/Code/Game/GameLogic/LevelLoader/Loader.cpp similarity index 94% rename from Code/Game/GameLogic/Loader.cpp rename to Code/Game/GameLogic/LevelLoader/Loader.cpp index 0afb48de..26818202 100644 --- a/Code/Game/GameLogic/Loader.cpp +++ b/Code/Game/GameLogic/LevelLoader/Loader.cpp @@ -15,6 +15,8 @@ unsigned char* Loader::LoadFile(std::string fileName, int &size) //convert from wstring to wchar then loads the file unsigned char* buffer = (unsigned char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); + + //gets the size of the char buffer. size = OysterResource::GetResourceSize(buffer); return buffer; } \ No newline at end of file diff --git a/Code/Game/GameLogic/Loader.h b/Code/Game/GameLogic/LevelLoader/Loader.h similarity index 88% rename from Code/Game/GameLogic/Loader.h rename to Code/Game/GameLogic/LevelLoader/Loader.h index d77921c5..2d605169 100644 --- a/Code/Game/GameLogic/Loader.h +++ b/Code/Game/GameLogic/LevelLoader/Loader.h @@ -5,7 +5,7 @@ #ifndef LOADER_H #define LOADER_H -#include "Resource\OysterResource.h" +#include "..\Misc\Resource\OysterResource.h" #include namespace GameLogic diff --git a/Code/Game/GameLogic/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h similarity index 100% rename from Code/Game/GameLogic/ObjectDefines.h rename to Code/Game/GameLogic/LevelLoader/ObjectDefines.h diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp new file mode 100644 index 00000000..abca143c --- /dev/null +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -0,0 +1,55 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "ParseFunctions.h" +#include "../../../Misc/Packing/Packing.h" +#include + +using namespace Oyster::Packing; +using namespace GameLogic::LevelFileLoader; +using namespace GameLogic; +using namespace std; + +namespace GameLogic +{ + namespace LevelFileLoader + { + void ParseObject(unsigned char* buffer, void* header, int size) + { + memcpy(header, buffer, size); + } + + void ParseLevelMetaData(unsigned char* buffer, struct LevelMetaData &header) + { + int start = 0; + int tempSize; + memcpy(&header.typeID, &buffer[start], 4); + start += 4; + memcpy(&tempSize , &buffer[start], 4); + start += 4; + memcpy(&header.levelName, &buffer[start], tempSize); + start += tempSize; + memcpy(&header.levelVersion, &buffer[start], 8) + start += 8; + memcpy(&tempSize, &buffer[start], 4); + start +=4; + memcpy(&header.description, &buffer[start], tempSize); + start += tempSize; + memcpy(&tempSize, &buffer[start], 4); + start += 4; + memcpy(&header.author, &buffer[start], tempSize); + start += tempSize; + memcpy(&header.nrOfPlayers, &buffer[start], 4); + start += 4; + memcpy(&header.worldSize, &buffer[start], 4); + start += 4; + memcpy(&header.map, &buffer[start], 4); + start += 4; + memcpy(&tempSize, &buffer[start], 4); + start += 4; + memcpy(&header.gameModes, &buffer[start], 4 * tempSize); + start += tempSize; + } + } +} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h new file mode 100644 index 00000000..7a6ab93a --- /dev/null +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h @@ -0,0 +1,19 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#ifndef PARSERFUNCTIONS_H +#define PARSERFUNCTIONS_H +#include "ObjectDefines.h" + +namespace GameLogic +{ + namespace LevelFileLoader + { + void ParseObject(unsigned char* buffer, void* header, int size); + void ParseLevelMetaData(unsigned char* buffer, struct ObjectTypeHeader &header); + } +} + + +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/ParseFunctions.cpp b/Code/Game/GameLogic/ParseFunctions.cpp deleted file mode 100644 index 64405ff5..00000000 --- a/Code/Game/GameLogic/ParseFunctions.cpp +++ /dev/null @@ -1,33 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "ParseFunctions.h" -#include "../../Misc/Packing/Packing.h" -#include - -using namespace Oyster::Packing; -using namespace GameLogic::LevelFileLoader; -using namespace GameLogic; -using namespace std; - -namespace GameLogic -{ - namespace LevelFileLoader - { - ObjectTypeHeader ParseObjectTypeHeader(unsigned char* buffer) - { - struct ObjectTypeHeader header; - memcpy(&header, buffer, sizeof(ObjectTypeHeader)); - return header; - } - - ObjectHeader ParseObjectHeader (unsigned char* buffer) - { - struct ObjectHeader header; - memcpy(&header, buffer, sizeof(ObjectHeader)); - - return header; - } - } -} \ No newline at end of file diff --git a/Code/Game/GameLogic/ParseFunctions.h b/Code/Game/GameLogic/ParseFunctions.h deleted file mode 100644 index 5638f419..00000000 --- a/Code/Game/GameLogic/ParseFunctions.h +++ /dev/null @@ -1,19 +0,0 @@ -////////////////////////////////// -// 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 From f968adebebdede3eb1f49c082c5fd2ece2608f5b Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Tue, 28 Jan 2014 16:15:10 +0100 Subject: [PATCH 11/12] GL - LevelLoader = done and done --- Bin/Level.txt | Bin 0 -> 156 bytes Bin/map | Bin 0 -> 156 bytes Bin/map.txt | Bin 48 -> 60 bytes .../GameLogic/LevelLoader/LevelLoader.cpp | 4 +- Code/Game/GameLogic/LevelLoader/LevelLoader.h | 4 +- .../GameLogic/LevelLoader/LevelParser.cpp | 39 ++++++++------- Code/Game/GameLogic/LevelLoader/Loader.cpp | 16 ++++++- Code/Game/GameLogic/LevelLoader/Loader.h | 2 +- .../GameLogic/LevelLoader/ObjectDefines.h | 2 +- .../GameLogic/LevelLoader/ParseFunctions.cpp | 45 ++++++++++++++---- .../GameLogic/LevelLoader/ParseFunctions.h | 4 +- 11 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 Bin/Level.txt create mode 100644 Bin/map diff --git a/Bin/Level.txt b/Bin/Level.txt new file mode 100644 index 0000000000000000000000000000000000000000..d86dd3db4f89e0c84adfa01d7b0ec5a42dd61adb GIT binary patch literal 156 zcmZQzU|?VYV!y=PR7M~T0wBIiYH>0$&A`y$pam3X0x19jkXjHMgqeXjYRNaJ8F^XG hjYrow<6?ux*}DpzTmbMiDYF0o literal 0 HcmV?d00001 diff --git a/Bin/map b/Bin/map new file mode 100644 index 0000000000000000000000000000000000000000..a578cc3216cf4c730d47a3cae791ddccf2b29610 GIT binary patch literal 156 zcmZQ#U|?VZVrC$YTJp_lMqZY47AJ$m6N^*QIDs?+LxY1BkYob085kIWGyuTm1-1YH literal 48 gcmZQzU|?imU|<4bW~XmUqMWnxW;m}o+K7t{08$7NVE_OC diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp index a6f8bb98..d60aac66 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp @@ -9,10 +9,10 @@ using namespace GameLogic::LevelFileLoader; std::vector LevelLoader::LoadLevel(std::string fileName) { - return parser->Parse(fileName); + return parser.Parse(fileName); } LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) { - return parser->ParseHeader(fileName); + return 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 8f87d141..4ac7a950 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.h +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.h @@ -17,7 +17,7 @@ namespace GameLogic { public: - LevelLoader(){this->parser = new GameLogic::LevelFileLoader::LevelParser(); } + LevelLoader(){this->parser = GameLogic::LevelFileLoader::LevelParser(); } ~LevelLoader(){} /******************************************************** @@ -35,7 +35,7 @@ namespace GameLogic LevelMetaData LoadLevelHeader(std::string fileName); //. private: - GameLogic::LevelFileLoader::LevelParser *parser; + GameLogic::LevelFileLoader::LevelParser parser; }; } diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 72d68d97..3ab3c203 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -19,17 +19,17 @@ LevelParser::~LevelParser() std::vector LevelParser::Parse(std::string filename) { int bufferSize = 0; - unsigned int counter = 0; + int counter = 0; std::vector objects; //Read entire level file. Loader loader; - unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), bufferSize); + char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); //Read format version FormatVersion levelFormatVersion; - ParseObject(&buffer[counter], formatVersion, sizeof(formatVersion)); + //ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); if(this->formatVersion != levelFormatVersion) { //Do something if it's not the same version @@ -39,22 +39,26 @@ std::vector LevelParser::Parse(std::string filename) { //Get typeID ObjectTypeHeader typeID; - ParseObject(&buffer[counter], typeID, sizeof(typeID)); - + ParseObject(&buffer[counter], &typeID, sizeof(typeID)); switch((int)typeID.typeID) { case ObjectType_LevelMetaData: + { LevelMetaData header; - //ParseObject(&buffer[counter], header, sizeof(header)); + 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; - - case ObjectType_Dynamic: - ObjectHeader header; - ParseObject(&buffer[counter], header, sizeof(header)); - objects.push_back(header); - counter += sizeof(header); + } + default: //Couldn't find typeID. FAIL!!!!!! break; @@ -68,18 +72,18 @@ std::vector LevelParser::Parse(std::string filename) LevelMetaData LevelParser::ParseHeader(std::string filename) { int bufferSize = 0; - unsigned int counter = 0; + int counter = 0; LevelMetaData levelHeader; levelHeader.typeID = ObjectType::ObjectType_Unknown; //Read entire level file. Loader loader; - unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), bufferSize); + char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); //Read format version FormatVersion levelFormatVersion; - ParseObject(&buffer[counter], formatVersion, sizeof(formatVersion)); + //ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); if(this->formatVersion != levelFormatVersion) { //Do something if it's not the same version @@ -89,14 +93,13 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) while(counter < bufferSize) { ObjectTypeHeader typeID; - ParseObject(&buffer[counter], typeID, sizeof(typeID)); + ParseObject(&buffer[counter], &typeID, sizeof(typeID)); switch(typeID.typeID) { case ObjectType_LevelMetaData: - //ParseObject(&buffer[counter], levelHeader, sizeof(levelHeader)); + ParseLevelMetaData(&buffer[counter], levelHeader, counter); return levelHeader; - counter += sizeof(LevelMetaData); break; case ObjectType_Dynamic: //Do not call parse this object, since we are only interested in the LevelMetaData diff --git a/Code/Game/GameLogic/LevelLoader/Loader.cpp b/Code/Game/GameLogic/LevelLoader/Loader.cpp index 26818202..a0206d89 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.cpp +++ b/Code/Game/GameLogic/LevelLoader/Loader.cpp @@ -3,19 +3,31 @@ ////////////////////////////////// #include "Loader.h" +#include using namespace GameLogic::LevelFileLoader; using namespace Oyster::Resource; using namespace std; -unsigned char* Loader::LoadFile(std::string fileName, int &size) +char* Loader::LoadFile(std::string fileName, int &size) { //convert from string to wstring std::wstring temp(fileName.begin(), fileName.end()); //convert from wstring to wchar then loads the file - unsigned char* buffer = (unsigned char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); + char* buffer = (char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); + //std::ifstream f; + //f.open(fileName, std::ios::binary); + //if (!f.is_open()) + // return 0; + //f.seekg(0, std::ifstream::end); + //size = f.tellg(); + //f.seekg(0); + //char* buffer = new char[size]; + //f.read(buffer, size); + // + //f.close(); //gets the size of the char buffer. size = OysterResource::GetResourceSize(buffer); return buffer; diff --git a/Code/Game/GameLogic/LevelLoader/Loader.h b/Code/Game/GameLogic/LevelLoader/Loader.h index 2d605169..198c2a87 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.h +++ b/Code/Game/GameLogic/LevelLoader/Loader.h @@ -17,7 +17,7 @@ namespace GameLogic public: Loader (){}; ~Loader(){}; - unsigned char* LoadFile(std::string fileName, int &size); + char* LoadFile(std::string fileName, int &size); //TODO: //Add functionality to load physicsObjects (hitboxes) diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 2d3e09f0..dcf960a5 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -91,7 +91,7 @@ namespace GameLogic std::vector gameModesSupported; }; - struct ObjectHeader : public PhysicsObject, public ObjectTypeHeader + struct ObjectHeader : public ObjectTypeHeader { //Model, int ModelID; diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index abca143c..f456b2d7 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -15,41 +15,66 @@ namespace GameLogic { namespace LevelFileLoader { - void ParseObject(unsigned char* buffer, void* header, int size) + void ParseObject(char* buffer, void *header, int size) { memcpy(header, buffer, size); } - void ParseLevelMetaData(unsigned char* buffer, struct LevelMetaData &header) + void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size) { int start = 0; int tempSize; + char tempName[100]; + memcpy(&header.typeID, &buffer[start], 4); start += 4; + memcpy(&tempSize , &buffer[start], 4); start += 4; - memcpy(&header.levelName, &buffer[start], tempSize); + + memcpy(&tempName, &buffer[start], tempSize); + header.levelName.assign(&tempName[0], &tempName[tempSize]); start += tempSize; - memcpy(&header.levelVersion, &buffer[start], 8) + + memcpy(&header.levelVersion, &buffer[start], 8); start += 8; + memcpy(&tempSize, &buffer[start], 4); start +=4; - memcpy(&header.description, &buffer[start], tempSize); + + memcpy(&tempName, &buffer[start], tempSize); + header.levelDescription.assign(&tempName[0], &tempName[tempSize]); start += tempSize; + memcpy(&tempSize, &buffer[start], 4); start += 4; - memcpy(&header.author, &buffer[start], tempSize); + + memcpy(&tempName, &buffer[start], tempSize); + header.levelAuthor.assign(&tempName[0], &tempName[tempSize]); start += tempSize; - memcpy(&header.nrOfPlayers, &buffer[start], 4); + + memcpy(&header.maxNumberOfPlayer, &buffer[start], 4); start += 4; + memcpy(&header.worldSize, &buffer[start], 4); start += 4; - memcpy(&header.map, &buffer[start], 4); + + memcpy(&header.overviewPictureID, &buffer[start], 4); start += 4; + memcpy(&tempSize, &buffer[start], 4); start += 4; - memcpy(&header.gameModes, &buffer[start], 4 * tempSize); - start += tempSize; + + int temp; + + for(int i = 0; i < tempSize; i++) + { + memcpy(&temp, &buffer[start], 4); + start += 4; + header.gameModesSupported.push_back((GameMode)temp); + } + + size += start; } } } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h index 7a6ab93a..08962b4a 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h @@ -10,8 +10,8 @@ namespace GameLogic { namespace LevelFileLoader { - void ParseObject(unsigned char* buffer, void* header, int size); - void ParseLevelMetaData(unsigned char* buffer, struct ObjectTypeHeader &header); + void ParseObject(char* buffer, void *header, int size); + void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); } } From c78bbba3eb17f848c6eb32c4b44a86ca9ccb0e5a Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Thu, 30 Jan 2014 13:33:59 +0100 Subject: [PATCH 12/12] GL- Removed commentet unnecessary code --- Code/Game/GameLogic/LevelLoader/Loader.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Code/Game/GameLogic/LevelLoader/Loader.cpp b/Code/Game/GameLogic/LevelLoader/Loader.cpp index a0206d89..3e15315c 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.cpp +++ b/Code/Game/GameLogic/LevelLoader/Loader.cpp @@ -17,18 +17,6 @@ char* Loader::LoadFile(std::string fileName, int &size) //convert from wstring to wchar then loads the file char* buffer = (char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); - //std::ifstream f; - //f.open(fileName, std::ios::binary); - //if (!f.is_open()) - // return 0; - //f.seekg(0, std::ifstream::end); - //size = f.tellg(); - //f.seekg(0); - //char* buffer = new char[size]; - //f.read(buffer, size); - // - //f.close(); - //gets the size of the char buffer. size = OysterResource::GetResourceSize(buffer); return buffer; } \ No newline at end of file