GL - Updated LevelLoader. Added lights.
Added lights. Changed the return type to vector<SmartPointer<ObjectTypeHeader>> Hid the LevelParser from the outside.
This commit is contained in:
parent
8f234611d2
commit
e7fee8b2e7
BIN
Bin/Level.txt
BIN
Bin/Level.txt
Binary file not shown.
BIN
Bin/map.txt
BIN
Bin/map.txt
Binary file not shown.
|
@ -3,16 +3,30 @@
|
|||
//////////////////////////////////
|
||||
|
||||
#include "LevelLoader.h"
|
||||
#include "LevelParser.h"
|
||||
using namespace GameLogic;
|
||||
using namespace GameLogic::LevelFileLoader;
|
||||
|
||||
|
||||
std::vector<ObjectTypeHeader> LevelLoader::LoadLevel(std::string fileName)
|
||||
struct LevelLoader::PrivData
|
||||
{
|
||||
return parser.Parse(fileName);
|
||||
LevelParser parser;
|
||||
};
|
||||
|
||||
LevelLoader::LevelLoader()
|
||||
: pData(new PrivData)
|
||||
{
|
||||
}
|
||||
|
||||
LevelLoader::~LevelLoader()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LevelLoader::LoadLevel(std::string fileName)
|
||||
{
|
||||
return pData->parser.Parse(fileName);
|
||||
}
|
||||
|
||||
LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName)
|
||||
{
|
||||
return parser.ParseHeader(fileName);
|
||||
return pData->parser.ParseHeader(fileName);
|
||||
}
|
|
@ -7,9 +7,8 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <Vector.h>
|
||||
#include "../Misc/Utilities.h"
|
||||
#include "ObjectDefines.h"
|
||||
#include "LevelParser.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
@ -17,15 +16,15 @@ namespace GameLogic
|
|||
{
|
||||
|
||||
public:
|
||||
LevelLoader(){this->parser = GameLogic::LevelFileLoader::LevelParser(); }
|
||||
~LevelLoader(){}
|
||||
LevelLoader();
|
||||
~LevelLoader();
|
||||
|
||||
/********************************************************
|
||||
* Loads the level and objects from file.
|
||||
* @param fileName: Path to the level-file that you want to load.
|
||||
* @return: Returns all structs with objects and information about the level.
|
||||
********************************************************/
|
||||
std::vector<ObjectTypeHeader> LoadLevel(std::string fileName);
|
||||
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LoadLevel(std::string fileName);
|
||||
|
||||
/********************************************************
|
||||
* Just for fast access for the meta information about the level.
|
||||
|
@ -35,7 +34,8 @@ namespace GameLogic
|
|||
LevelMetaData LoadLevelHeader(std::string fileName); //.
|
||||
|
||||
private:
|
||||
GameLogic::LevelFileLoader::LevelParser parser;
|
||||
struct PrivData;
|
||||
Utility::DynamicMemory::SmartPointer<PrivData> pData;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
using namespace GameLogic;
|
||||
using namespace ::LevelFileLoader;
|
||||
using namespace Utility::DynamicMemory;
|
||||
|
||||
LevelParser::LevelParser()
|
||||
{
|
||||
|
@ -16,12 +17,12 @@ LevelParser::~LevelParser()
|
|||
{
|
||||
}
|
||||
|
||||
std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
|
||||
std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filename)
|
||||
{
|
||||
int bufferSize = 0;
|
||||
int counter = 0;
|
||||
|
||||
std::vector<ObjectTypeHeader> objects;
|
||||
std::vector<SmartPointer<ObjectTypeHeader>> objects;
|
||||
|
||||
//Read entire level file.
|
||||
Loader loader;
|
||||
|
@ -44,21 +45,61 @@ std::vector<ObjectTypeHeader> LevelParser::Parse(std::string filename)
|
|||
{
|
||||
case ObjectType_LevelMetaData:
|
||||
{
|
||||
LevelMetaData header;
|
||||
ParseLevelMetaData(&buffer[counter], header, counter);
|
||||
LevelMetaData* header = new LevelMetaData;
|
||||
ParseLevelMetaData(&buffer[counter], *header, counter);
|
||||
objects.push_back(header);
|
||||
break;
|
||||
}
|
||||
|
||||
case ObjectType_Dynamic:
|
||||
//This is by design, static and dynamic is using the same converter. Do not add anything inbetween them.
|
||||
case ObjectType_Static: case ObjectType_Dynamic:
|
||||
{
|
||||
ObjectHeader header;
|
||||
ParseObject(&buffer[counter], &header, sizeof(header));
|
||||
ObjectHeader* header = new ObjectHeader;
|
||||
ParseObject(&buffer[counter], header, sizeof(*header));
|
||||
objects.push_back(header);
|
||||
counter += sizeof(header);
|
||||
counter += sizeof(*header);
|
||||
break;
|
||||
}
|
||||
|
||||
case ObjectType_Light:
|
||||
{
|
||||
LightType lightType;
|
||||
|
||||
//Get Light type
|
||||
ParseObject(&buffer[counter+4], &lightType, sizeof(lightType));
|
||||
|
||||
switch(lightType)
|
||||
{
|
||||
case LightType_PointLight:
|
||||
{
|
||||
PointLight* header = new PointLight;
|
||||
ParseObject(&buffer[counter], header, sizeof(*header));
|
||||
counter += sizeof(*header);
|
||||
objects.push_back(header);
|
||||
break;
|
||||
}
|
||||
case LightType_DirectionalLight:
|
||||
{
|
||||
DirectionalLight* header = new DirectionalLight;
|
||||
ParseObject(&buffer[counter], header, sizeof(*header));
|
||||
counter += sizeof(*header);
|
||||
objects.push_back(header);
|
||||
break;
|
||||
}
|
||||
case LightType_SpotLight:
|
||||
{
|
||||
SpotLight* header = new SpotLight;
|
||||
ParseObject(&buffer[counter], header, sizeof(*header));
|
||||
counter += sizeof(*header);
|
||||
objects.push_back(header);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//Undefined LightType.
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//Couldn't find typeID. FAIL!!!!!!
|
||||
break;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include "ObjectDefines.h"
|
||||
#include "../Misc/Utilities.h"
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
@ -16,7 +17,7 @@ namespace GameLogic
|
|||
~LevelParser();
|
||||
|
||||
//
|
||||
std::vector<ObjectTypeHeader> Parse(std::string filename);
|
||||
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> Parse(std::string filename);
|
||||
|
||||
//
|
||||
LevelMetaData ParseHeader(std::string filename);
|
||||
|
|
|
@ -15,11 +15,12 @@ namespace GameLogic
|
|||
ObjectType_LevelMetaData,
|
||||
ObjectType_Static,
|
||||
ObjectType_Dynamic,
|
||||
ObjectType_Light,
|
||||
//Etc
|
||||
|
||||
ObjectType_NUM_OF_TYPES,
|
||||
|
||||
ObjectType_Unknown = -1,
|
||||
ObjectType_Unknown = -1
|
||||
};
|
||||
|
||||
enum UsePhysics
|
||||
|
@ -29,7 +30,17 @@ namespace GameLogic
|
|||
UsePhysics_IgnorePhysics,
|
||||
|
||||
UsePhysics_Count,
|
||||
UsePhysics_Unknown = -1,
|
||||
UsePhysics_Unknown = -1
|
||||
};
|
||||
|
||||
enum LightType
|
||||
{
|
||||
LightType_PointLight,
|
||||
LightType_DirectionalLight,
|
||||
LightType_SpotLight,
|
||||
|
||||
LightType_Count,
|
||||
LightType_Unknown = -1
|
||||
};
|
||||
|
||||
//Should this be moved somewhere else?
|
||||
|
@ -40,7 +51,7 @@ namespace GameLogic
|
|||
//Etc
|
||||
|
||||
GameMode_Count,
|
||||
GameMode_Unknown = -1,
|
||||
GameMode_Unknown = -1
|
||||
};
|
||||
|
||||
|
||||
|
@ -104,6 +115,36 @@ namespace GameLogic
|
|||
//Scale
|
||||
float scale[3];
|
||||
};
|
||||
|
||||
|
||||
/************************************
|
||||
Lights
|
||||
*************************************/
|
||||
|
||||
struct BasicLight : public ObjectTypeHeader
|
||||
{
|
||||
LightType lightType;
|
||||
float ambientColor[3];
|
||||
float diffuseColor[3];
|
||||
float specularColor[3];
|
||||
};
|
||||
|
||||
struct PointLight : public BasicLight
|
||||
{
|
||||
float position[3];
|
||||
};
|
||||
|
||||
struct DirectionalLight : public BasicLight
|
||||
{
|
||||
float direction[3];
|
||||
};
|
||||
|
||||
struct SpotLight : public BasicLight
|
||||
{
|
||||
float direction[3];
|
||||
float range;
|
||||
float attenuation[3];
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -10,6 +10,14 @@ namespace GameLogic
|
|||
{
|
||||
namespace LevelFileLoader
|
||||
{
|
||||
/*
|
||||
These functions will copy data from where the buffer pointer points.
|
||||
header is the destination where the data will be copied.
|
||||
size is either the size of the data to be copied (if it is NOT sent by reference).
|
||||
Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied.
|
||||
|
||||
*/
|
||||
|
||||
void ParseObject(char* buffer, void *header, int size);
|
||||
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue