LevelLoader reads lights and cgMesh correctly.

This commit is contained in:
Pontus Fransson 2014-02-22 12:58:43 +01:00
parent 1c71d7ef80
commit 6eb0a282c2
5 changed files with 60 additions and 7 deletions

View File

@ -231,7 +231,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName )
pointLight.Color = light->color;
pointLight.Pos = light->position;
pointLight.Bright = light->intensity;
pointLight.Radius = light->raduis;
pointLight.Radius = light->radius;
C_Light *newLight = new C_Light( pointLight, objectID );

View File

@ -166,16 +166,17 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
case ObjectType_Light:
{
LightType lightType;
//LightType lightType;
//Get Light type
ParseObject(&buffer[counter+4], &lightType, sizeof(lightType));
//ParseObject(&buffer[counter+4], &lightType, sizeof(lightType));
//We only support PointLight for now.
BasicLight* header = new BasicLight;
ParseObject(&buffer[counter], header, sizeof(*header));
counter += sizeof(*header);
ParseLight(&buffer[counter], *header, counter);
objects.push_back(header);
/*switch(lightType)
{
case LightType_PointLight:
@ -208,6 +209,7 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
}
break;*/
}
break;
default:
//Couldn't find typeID. FAIL!!!!!!
break;

View File

@ -52,6 +52,7 @@ namespace GameLogic
CollisionGeometryType_Box,
CollisionGeometryType_Sphere,
CollisionGeometryType_Cylinder,
CollisionGeometryType_CG_MESH,
CollisionGeometryType_Count,
CollisionGeometryType_Unknown = -1
@ -161,6 +162,11 @@ namespace GameLogic
float radius;
};
struct BoundingVolumeCGMesh : public BoundingVolumeBase
{
wchar_t filename[128];
};
struct BoundingVolume
{
CollisionGeometryType geoType;
@ -169,9 +175,9 @@ namespace GameLogic
LevelLoaderInternal::BoundingVolumeBox box;
LevelLoaderInternal::BoundingVolumeSphere sphere;
LevelLoaderInternal::BoundingVolumeCylinder cylinder;
LevelLoaderInternal::BoundingVolumeCGMesh cgMesh;
};
};
}
struct LevelMetaData : public ObjectTypeHeader
@ -253,8 +259,10 @@ namespace GameLogic
LightType lightType; //Is not used right now
float color[3];
float position[3];
float raduis;
float radius;
float intensity;
virtual ~BasicLight(){}
};
/* We only support pointlight right now.
struct PointLight : public BasicLight

View File

@ -20,6 +20,32 @@ namespace GameLogic
memcpy(header, buffer, size);
}
void ParseLight(char* buffer, BasicLight& header, int& size)
{
int start = 0;
memcpy(&header.typeID, &buffer[start], 40);
start += 40;
/*
memcpy(&header.lightType, &buffer[start], 4);
start += 4;
memcpy(&header.color, &buffer[start], 12);
start += 12;
memcpy(&header.position, &buffer[start], 12);
start += 12;
memcpy(&header.radius, &buffer[start], 4);
start += 4;
memcpy(&header.intensity, &buffer[start], 4);
start += 4;*/
size += start;
//memcpy(&header, buffer, size);
}
void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf)
{
char tempName[128];
@ -173,6 +199,22 @@ namespace GameLogic
start += sizeof(volume.cylinder);
break;
case CollisionGeometryType_CG_MESH:
{
memcpy(&volume.cgMesh, &buf[start], sizeof(float)*12);
start += sizeof(float)*12;
memcpy(&tempSize, &buf[start], sizeof(tempSize));
start += 4;
memcpy(&tempName, &buf[start], tempSize);
tempName[tempSize] = '\0';
//convert from char[] to wchar_t[]
mbstowcs_s(NULL, volume.cgMesh.filename, tempSize+1, tempName, _TRUNCATE);
start += tempSize;
}
break;
default:
break;
}

View File

@ -18,6 +18,7 @@ namespace GameLogic
*/
void ParseObject(char* buffer, void *header, int size);
void ParseLight(char* buffer, BasicLight& header, int& size);
void ParseObject(char* buffer, ObjectHeader& header, int& size , bool loadCgf);
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size);
void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size);