From c75493b6ce00d13f9102ef951476f21d27c4470b Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Mon, 10 Feb 2014 14:58:39 +0100 Subject: [PATCH] GL - Levelformat updated 3.0 with new format! --- .../GameLogic/LevelLoader/LevelParser.cpp | 1 + .../GameLogic/LevelLoader/ObjectDefines.h | 30 ++++++---------- .../GameLogic/LevelLoader/ParseFunctions.cpp | 35 +++++++++---------- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 33567cc9..a6f806e8 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -123,6 +123,7 @@ std::vector> LevelParser::Parse(std::string filen break; } + default: //Couldn't find specialType break; diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index d87e42b2..46cb2465 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -138,14 +138,18 @@ namespace GameLogic struct BoundingVolumeBase { + CollisionGeometryType geoType; float position[3]; + float rotation[4]; + float frictionCoeffStatic; + float frictionCoeffDynamic; + float restitutionCoeff; + float mass; }; struct BoundingVolumeBox : public BoundingVolumeBase { float size[3]; - float angularAxis[3]; - float angle; }; struct BoundingVolumeSphere : public BoundingVolumeBase @@ -156,8 +160,6 @@ namespace GameLogic struct BoundingVolumeCylinder : public BoundingVolumeBase { float length; - float angularAxis[3]; - float angle; 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 @@ -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. ObjectSpecialType specialTypeID; @@ -208,12 +199,13 @@ namespace GameLogic std::string ModelFile; //Position float position[3]; - //Rotation - float rotation[3]; - float angle; + //Rotation Quaternion + float rotation[4]; //Scale float scale[3]; + ::GameLogic::LevelLoaderInternal::BoundingVolume boundingVolume; + virtual ~ObjectHeader(){} }; diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index e8c055b3..722bd609 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -44,11 +44,6 @@ namespace GameLogic //3 float[3], 1 float memcpy(&header.position, &buffer[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 ParseBoundingVolume(&buffer[start], header.boundingVolume, start); @@ -122,7 +117,7 @@ namespace GameLogic int start = 0; int tempSize = 0; char tempName[128]; - + memcpy(&tempSize, &buffer[start], 4); start += 4; @@ -132,39 +127,41 @@ namespace GameLogic fileName.assign(&tempName[0], &tempName[tempSize]); start += tempSize; + size += start; + //Läs in filen. int fileLength = 0; Loader loader; 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 += sizeof(volume.geoType); + start = 0; + 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) { case CollisionGeometryType_Box: - memcpy(&volume.box, &buf[12], sizeof(volume.box)); - //start += sizeof(volume.box); + memcpy(&volume.box, &buf[start], sizeof(volume.box)); + start += sizeof(volume.box); break; case CollisionGeometryType_Sphere: - memcpy(&volume.sphere, &buf[12], sizeof(volume.sphere)); - //start += sizeof(volume.sphere); + memcpy(&volume.sphere, &buf[start], sizeof(volume.sphere)); + start += sizeof(volume.sphere); break; case CollisionGeometryType_Cylinder: - memcpy(&volume.cylinder, &buf[12], sizeof(volume.cylinder)); - //start += sizeof(volume.cylinder); + memcpy(&volume.cylinder, &buf[start], sizeof(volume.cylinder)); + start += sizeof(volume.cylinder); break; default: break; } - - size += start; } } } \ No newline at end of file