GL - Levelformat updated 3.0 with new format!

This commit is contained in:
Sam Mario Svensson 2014-02-10 14:58:39 +01:00
parent 49d29d87a5
commit c75493b6ce
3 changed files with 28 additions and 38 deletions

View File

@ -123,6 +123,7 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
break; break;
} }
default: default:
//Couldn't find specialType //Couldn't find specialType
break; break;

View File

@ -138,14 +138,18 @@ namespace GameLogic
struct BoundingVolumeBase struct BoundingVolumeBase
{ {
CollisionGeometryType geoType;
float position[3]; float position[3];
float rotation[4];
float frictionCoeffStatic;
float frictionCoeffDynamic;
float restitutionCoeff;
float mass;
}; };
struct BoundingVolumeBox : public BoundingVolumeBase struct BoundingVolumeBox : public BoundingVolumeBase
{ {
float size[3]; float size[3];
float angularAxis[3];
float angle;
}; };
struct BoundingVolumeSphere : public BoundingVolumeBase struct BoundingVolumeSphere : public BoundingVolumeBase
@ -156,8 +160,6 @@ namespace GameLogic
struct BoundingVolumeCylinder : public BoundingVolumeBase struct BoundingVolumeCylinder : public BoundingVolumeBase
{ {
float length; float length;
float angularAxis[3];
float angle;
float radius; float radius;
}; };
@ -172,17 +174,6 @@ namespace GameLogic
}; };
}; };
struct PhysicsObject
{
UsePhysics usePhysics;
float mass;
float inertiaMagnitude[3];
float inertiaRotation[3];
float frictionCoeffStatic;
float frictionCoeffDynamic;
float restitutionCoeff;
BoundingVolume boundingVolume;
};
} }
struct LevelMetaData : public ObjectTypeHeader struct LevelMetaData : public ObjectTypeHeader
@ -200,7 +191,7 @@ namespace GameLogic
}; };
struct ObjectHeader : public ObjectTypeHeader, public LevelLoaderInternal::PhysicsObject struct ObjectHeader : public ObjectTypeHeader
{ {
//Special type id for special objects: portal, jumppad, exploding objects, etc. //Special type id for special objects: portal, jumppad, exploding objects, etc.
ObjectSpecialType specialTypeID; ObjectSpecialType specialTypeID;
@ -208,12 +199,13 @@ namespace GameLogic
std::string ModelFile; std::string ModelFile;
//Position //Position
float position[3]; float position[3];
//Rotation //Rotation Quaternion
float rotation[3]; float rotation[4];
float angle;
//Scale //Scale
float scale[3]; float scale[3];
::GameLogic::LevelLoaderInternal::BoundingVolume boundingVolume;
virtual ~ObjectHeader(){} virtual ~ObjectHeader(){}
}; };

View File

@ -44,11 +44,6 @@ namespace GameLogic
//3 float[3], 1 float //3 float[3], 1 float
memcpy(&header.position, &buffer[start], 40); memcpy(&header.position, &buffer[start], 40);
start += 40; start += 40;
//Physics struct
//2 float[3], 4 float, 1 uint
memcpy(&header.usePhysics, &buffer[start], 44);
start += 44;
//Read path for bounding volume //Read path for bounding volume
ParseBoundingVolume(&buffer[start], header.boundingVolume, start); ParseBoundingVolume(&buffer[start], header.boundingVolume, start);
@ -122,7 +117,7 @@ namespace GameLogic
int start = 0; int start = 0;
int tempSize = 0; int tempSize = 0;
char tempName[128]; char tempName[128];
memcpy(&tempSize, &buffer[start], 4); memcpy(&tempSize, &buffer[start], 4);
start += 4; start += 4;
@ -132,39 +127,41 @@ namespace GameLogic
fileName.assign(&tempName[0], &tempName[tempSize]); fileName.assign(&tempName[0], &tempName[tempSize]);
start += tempSize; start += tempSize;
size += start;
//Läs in filen. //Läs in filen.
int fileLength = 0; int fileLength = 0;
Loader loader; Loader loader;
char* buf = loader.LoadFile("E:\\Dropbox\\Programming\\Github\\Danbias\\Bin\\Content\\Worlds\\cgf\\"+ fileName, fileLength); char* buf = loader.LoadFile("E:\\Dropbox\\Programming\\Github\\Danbias\\Bin\\Content\\Worlds\\cgf\\"+ fileName, fileLength);
LevelLoaderInternal::FormatVersion version;
memcpy(&version, &buffer[0], sizeof(version));
memcpy(&volume.geoType, &buf[8], sizeof(volume.geoType)); start = 0;
//start += sizeof(volume.geoType); LevelLoaderInternal::FormatVersion version;
memcpy(&version, &buf[0], sizeof(version));
start += 4;
memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType));
start += sizeof(volume.geoType);
switch(volume.geoType) switch(volume.geoType)
{ {
case CollisionGeometryType_Box: case CollisionGeometryType_Box:
memcpy(&volume.box, &buf[12], sizeof(volume.box)); memcpy(&volume.box, &buf[start], sizeof(volume.box));
//start += sizeof(volume.box); start += sizeof(volume.box);
break; break;
case CollisionGeometryType_Sphere: case CollisionGeometryType_Sphere:
memcpy(&volume.sphere, &buf[12], sizeof(volume.sphere)); memcpy(&volume.sphere, &buf[start], sizeof(volume.sphere));
//start += sizeof(volume.sphere); start += sizeof(volume.sphere);
break; break;
case CollisionGeometryType_Cylinder: case CollisionGeometryType_Cylinder:
memcpy(&volume.cylinder, &buf[12], sizeof(volume.cylinder)); memcpy(&volume.cylinder, &buf[start], sizeof(volume.cylinder));
//start += sizeof(volume.cylinder); start += sizeof(volume.cylinder);
break; break;
default: default:
break; break;
} }
size += start;
} }
} }
} }