Merge branch 'GameLogic-LevelFormat' of https://github.com/dean11/Danbias into GameLogic-LevelFormat
This commit is contained in:
commit
2b63563a9b
|
@ -12,7 +12,7 @@ std::vector<ObjectTypeHeader> 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);
|
||||
}
|
|
@ -19,8 +19,20 @@ namespace GameLogic
|
|||
public:
|
||||
LevelLoader(){this->parser = new GameLogic::LevelFileLoader::LevelParser(); }
|
||||
~LevelLoader(){}
|
||||
std::vector<ObjectTypeHeader> 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<ObjectTypeHeader> 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;
|
||||
|
|
|
@ -6,9 +6,10 @@
|
|||
using namespace GameLogic;
|
||||
using namespace ::LevelFileLoader;
|
||||
|
||||
|
||||
LevelParser::LevelParser()
|
||||
{
|
||||
formatVersion.formatVersionMajor = 1;
|
||||
formatVersion.formatVersionMinor = 0;
|
||||
}
|
||||
|
||||
LevelParser::~LevelParser()
|
||||
|
@ -17,35 +18,43 @@ LevelParser::~LevelParser()
|
|||
|
||||
std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
|
||||
{
|
||||
int stringSize = 0;
|
||||
//Read entire level file.
|
||||
Loader loader;
|
||||
unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), stringSize);
|
||||
int bufferSize = 0;
|
||||
unsigned int counter = 0;
|
||||
|
||||
std::vector<ObjectTypeHeader> objects;
|
||||
|
||||
unsigned int counter = 0;
|
||||
//Read entire level file.
|
||||
Loader loader;
|
||||
unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), bufferSize);
|
||||
|
||||
while(counter < stringSize)
|
||||
//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;
|
||||
|
@ -55,36 +64,44 @@ std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
|
|||
return objects;
|
||||
}
|
||||
|
||||
//för meta information om leveln. Måste göra så den returnerar rätt strukt så fort vi
|
||||
//vi definierat en!
|
||||
ObjectTypeHeader LevelParser::ParseHeader(std::string filename)
|
||||
//för meta information om leveln.
|
||||
LevelMetaData LevelParser::ParseHeader(std::string filename)
|
||||
{
|
||||
int stringSize = 0;
|
||||
//Read entire level file.
|
||||
Loader loader;
|
||||
unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), stringSize);
|
||||
|
||||
//Find the header in the returned string.
|
||||
int bufferSize = 0;
|
||||
unsigned int counter = 0;
|
||||
|
||||
LevelMetaData levelHeader;
|
||||
levelHeader.typeID = ObjectType::ObjectType_Unknown;
|
||||
|
||||
ObjectTypeHeader header;
|
||||
header.typeID = ObjectType_Level;
|
||||
//Read entire level file.
|
||||
Loader loader;
|
||||
unsigned char* buffer = (unsigned char*)loader.LoadFile(filename.c_str(), bufferSize);
|
||||
|
||||
while(counter < stringSize)
|
||||
//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.
|
||||
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:
|
||||
|
@ -93,5 +110,5 @@ ObjectTypeHeader LevelParser::ParseHeader(std::string filename)
|
|||
}
|
||||
}
|
||||
|
||||
return header;
|
||||
return levelHeader;
|
||||
}
|
|
@ -19,31 +19,10 @@ namespace GameLogic
|
|||
std::vector<ObjectTypeHeader> 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;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,27 +1,97 @@
|
|||
#ifndef OBJECT_DEFINES_H
|
||||
#define OBJECT_DEFINES_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<GameMode> gameModesSupported;
|
||||
};
|
||||
|
||||
struct ObjectHeader : public PhysicsObject, public ObjectTypeHeader
|
||||
{
|
||||
//Model,
|
||||
int ModelID;
|
||||
|
|
Loading…
Reference in New Issue