GL - Updated level loader.
This commit is contained in:
parent
1f28c05983
commit
1261ed734f
|
@ -30,7 +30,8 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
|
|||
|
||||
//Read format version
|
||||
FormatVersion levelFormatVersion;
|
||||
//ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion));
|
||||
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion));
|
||||
counter += sizeof(levelFormatVersion);
|
||||
if(this->formatVersion != levelFormatVersion)
|
||||
{
|
||||
//Do something if it's not the same version
|
||||
|
@ -55,9 +56,8 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
|
|||
case ObjectType_Static: case ObjectType_Dynamic:
|
||||
{
|
||||
ObjectHeader* header = new ObjectHeader;
|
||||
ParseObject(&buffer[counter], header, sizeof(*header));
|
||||
ParseObject(&buffer[counter], *header, counter);
|
||||
objects.push_back(header);
|
||||
counter += sizeof(*header);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,8 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
|
|||
|
||||
//Read format version
|
||||
FormatVersion levelFormatVersion;
|
||||
//ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion));
|
||||
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion));
|
||||
counter += sizeof(levelFormatVersion);
|
||||
if(this->formatVersion != levelFormatVersion)
|
||||
{
|
||||
//Do something if it's not the same version
|
||||
|
@ -142,11 +143,42 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
|
|||
ParseLevelMetaData(&buffer[counter], levelHeader, counter);
|
||||
return levelHeader;
|
||||
break;
|
||||
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);
|
||||
|
||||
//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, counter);
|
||||
break;
|
||||
}
|
||||
|
||||
case ObjectType_Light:
|
||||
{
|
||||
LightType lightType;
|
||||
ParseObject(&buffer[counter+4], &lightType, sizeof(lightType));
|
||||
|
||||
switch(lightType)
|
||||
{
|
||||
case LightType_PointLight:
|
||||
{
|
||||
counter += sizeof(PointLight);
|
||||
break;
|
||||
}
|
||||
case LightType_DirectionalLight:
|
||||
{
|
||||
counter += sizeof(DirectionalLight);
|
||||
break;
|
||||
}
|
||||
case LightType_SpotLight:
|
||||
{
|
||||
counter += sizeof(SpotLight);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//Undefined LightType.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
//Couldn't find typeID. FAIL!!!!!!
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace GameLogic
|
|||
UsePhysics_UseFullPhysics,
|
||||
UsePhysics_IgnoreGravity,
|
||||
UsePhysics_IgnorePhysics,
|
||||
UsePhysics_IgnoreCollision,
|
||||
|
||||
UsePhysics_Count,
|
||||
UsePhysics_Unknown = -1
|
||||
|
@ -82,12 +83,13 @@ namespace GameLogic
|
|||
|
||||
struct PhysicsObject
|
||||
{
|
||||
UsePhysics usePhysics;
|
||||
float mass;
|
||||
float elasticity;
|
||||
float inertiaMagnitude[3];
|
||||
float inertiaRotation[3];
|
||||
float frictionCoeffStatic;
|
||||
float frictionCoeffDynamic;
|
||||
float inertiaTensor[16];
|
||||
UsePhysics usePhysics;
|
||||
|
||||
};
|
||||
|
||||
struct LevelMetaData : ObjectTypeHeader
|
||||
|
@ -97,17 +99,15 @@ namespace GameLogic
|
|||
std::string levelDescription;
|
||||
std::string levelAuthor;
|
||||
int maxNumberOfPlayer;
|
||||
float worldSize;
|
||||
int overviewPictureID;
|
||||
int worldSize;
|
||||
std::string overviewPicturePath;
|
||||
std::vector<GameMode> gameModesSupported;
|
||||
};
|
||||
|
||||
struct ObjectHeader : public ObjectTypeHeader
|
||||
{
|
||||
//Model,
|
||||
int ModelID;
|
||||
//Texture
|
||||
int TextureID;
|
||||
std::string ModelFile;
|
||||
//Position
|
||||
float position[3];
|
||||
//Rotation
|
||||
|
|
|
@ -20,11 +20,33 @@ namespace GameLogic
|
|||
memcpy(header, buffer, size);
|
||||
}
|
||||
|
||||
void ParseObject(char* buffer, ObjectHeader& header, int& size)
|
||||
{
|
||||
char tempName[128];
|
||||
int tempSize = 0;
|
||||
int start = 0;
|
||||
|
||||
memcpy(&header.typeID, &buffer[start], 4);
|
||||
start += 4;
|
||||
|
||||
memcpy(&tempSize, &buffer[start], 4);
|
||||
start += 4;
|
||||
|
||||
memcpy(&tempName, &buffer[start], tempSize);
|
||||
header.ModelFile.assign(&tempName[0], &tempName[tempSize]);
|
||||
start += tempSize;
|
||||
|
||||
memcpy(&header.position, &buffer[start], 36);
|
||||
start += 36;
|
||||
|
||||
size += start;
|
||||
}
|
||||
|
||||
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size)
|
||||
{
|
||||
int start = 0;
|
||||
int tempSize;
|
||||
char tempName[100];
|
||||
char tempName[128];
|
||||
|
||||
memcpy(&header.typeID, &buffer[start], 4);
|
||||
start += 4;
|
||||
|
@ -59,9 +81,13 @@ namespace GameLogic
|
|||
memcpy(&header.worldSize, &buffer[start], 4);
|
||||
start += 4;
|
||||
|
||||
memcpy(&header.overviewPictureID, &buffer[start], 4);
|
||||
memcpy(&tempSize, &buffer[start], 4);
|
||||
start += 4;
|
||||
|
||||
memcpy(&tempName, &buffer[start], tempSize);
|
||||
header.overviewPicturePath.assign(&tempName[0], &tempName[tempSize]);
|
||||
start += tempSize;
|
||||
|
||||
memcpy(&tempSize, &buffer[start], 4);
|
||||
start += 4;
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace GameLogic
|
|||
*/
|
||||
|
||||
void ParseObject(char* buffer, void *header, int size);
|
||||
void ParseObject(char* buffer, ObjectHeader& header, int& size);
|
||||
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue