Commit 2a7f88fc authored by hybrid's avatar hybrid

Reindentation.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1092 dfc29bdd-3216-0410-991c-e03cc46cb475
parent fbb1d585
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
//
//
// This file was originally written by Salvatore Russo.
// I (Nikolaus Gebhardt) did some minor modifications changes to it and integrated
// I (Nikolaus Gebhardt) did some minor modifications changes to it and integrated
// it into Irrlicht:
// - removed STL dependency
// - removed log file and replaced it with irrlicht logging
// - adapted code formatting a bit to Irrlicht style
// - removed memory leaks
// Thanks a lot to Salvatore for his work on this and that he gave me
// his permission to add it into Irrlicht.
// his permission to add it into Irrlicht.
// This support library has been made by Salvatore Russo and is released under GNU public license for general uses.
// For uses in Irrlicht core and only for Irrlicht related uses I release this library under zlib license.
......@@ -25,10 +25,10 @@ using namespace video;
#include "irrString.h"
/** A structure representing some DeleD infos.
This structure contains data about DeleD level file like: version, ambient colour, number of objects etc...*/
struct dmfHeader
{
/** A structure representing some DeleD infos.
This structure contains data about DeleD level file like: version, ambient colour, number of objects etc...*/
struct dmfHeader
{
//main file header
f32 dmfVersion; //!<File version
char dmfName[128]; //!<Scene name
......@@ -48,18 +48,18 @@ struct dmfHeader
This structure contains texture names, an ID and some flags.*/
struct dmfMaterial
{
u32 materialID;//!<This material unique ID.
u32 textureFlag;//!<First texture Flag (0=Normal, 1=Color).
u32 lightmapFlag;//!<Lightmap Flag (0=Normal, others not considered).
u32 textureBlend;//!<Texture Blend mode used to support alpha maps (4=Alpha map, others not implemented yet).
char textureName[64];//!<Name of first texture (only file name, no path).
char lightmapName[64];//!<Name of lightmap (only file name, no path).
u32 materialID;//!<This material unique ID.
u32 textureFlag;//!<First texture Flag (0=Normal, 1=Color).
u32 lightmapFlag;//!<Lightmap Flag (0=Normal, others not considered).
u32 textureBlend;//!<Texture Blend mode used to support alpha maps (4=Alpha map, others not implemented yet).
char textureName[64];//!<Name of first texture (only file name, no path).
char lightmapName[64];//!<Name of lightmap (only file name, no path).
};
/** A structure rapresenting a single face.
This structure contains first vertice index, number of vertices and the material used.*/
struct dmfFace
struct dmfFace
{
u32 firstVert;//!<First vertice index.
u32 numVerts;//!<Number of vertices for this face.
......@@ -69,7 +69,7 @@ struct dmfFace
/** A structure rapresenting a single vertice.
This structure contains vertice position coordinates and texture an lightmap UV.*/
struct dmfVert
struct dmfVert
{
f32 tc[2];//!<Texture UV coords.
f32 lc[2];//!<Lightmap UV coords.
......@@ -79,14 +79,14 @@ struct dmfVert
/** A structure rapresenting a single dynamic light.
This structure contains light position coordinates, diffuse colour, specular colour and maximum radius of light.*/
struct dmfLight
struct dmfLight
{
f32 pos[3];//!<Position of this light.
SColorf diffuseColor;//!<Diffuse color.
SColorf specularColor;//!<Specular color.
f32 radius;//!<Maximum radius of light.
};
/** A structure rapresenting a single water plane.
This structure contains light position coordinates, diffuse colour, specular colour and maximum radius of light.*/
struct dmfWaterPlain
......@@ -97,7 +97,7 @@ struct dmfWaterPlain
core::dimension2d<s32> tileNum;//!<number of tiles of this water plain.
f32 waveHeight;//!<height of waves.
f32 waveSpeed;//!<waves speed.
f32 waveLength;//!<waves length.
f32 waveLength;//!<waves length.
};
......@@ -106,58 +106,56 @@ This function converts an hex string (i.e. FF) to its int value (i.e. 255).
\return An int representing the hex input value.*/
int axtoi(const char *hexStg)
{
unsigned int intValue = 0; // integer value of hex string
sscanf(hexStg, "%x", &intValue);
return (intValue);
unsigned int intValue = 0; // integer value of hex string
sscanf(hexStg, "%x", &intValue);
return (intValue);
}
/** A standard string.
A standard string created with standard template libraries.*/
typedef core::stringc stdstring;
typedef core::stringc String;
//Define a class StringList based on core::array and the defined class String
/** A simple stringlist class based on core::array.
This StringList class is based on core::array and the defined String class.
*/
class StringList : public core::array<String>
class StringList : public core::array<String>
{
public:
/**Basic Constructor*/
StringList()
/**Basic Constructor*/
StringList()
{
}
/**Constructor based on file loading.
Look at LoadFromFile specifications.*/
/**Constructor based on file loading.
Look at LoadFromFile specifications.*/
StringList(io::IReadFile* file)
{
LoadFromFile(file);
}
/**Basic destructor.*/
~StringList()
/**Basic destructor.*/
~StringList()
{
clear();
}
//Adds a String to StringList
/** Add a string to this StringList.*/
void Add(String str/*<String to add to the current StringList*/)
//Adds a String to StringList
/** Add a string to this StringList.*/
void Add(String str/*<String to add to the current StringList*/)
{
push_back(str);
}
//Loads a stringlist from a file
//note that each String added to StringList
//is separed by a \\n character and it's present
//at the end of line.
/** Loads a StringList from a file.
This function loads a StringList from a file where each string is divided by a \\n char.*/
void LoadFromFile(io::IReadFile* file)
//Loads a stringlist from a file
//note that each String added to StringList
//is separated by a \\n character and it's present
//at the end of line.
/** Loads a StringList from a file.
This function loads a StringList from a file where each string is divided by a \\n char.*/
void LoadFromFile(io::IReadFile* file)
{
const long sz = file->getSize();
char* buf = new char[sz+1];
......@@ -174,7 +172,7 @@ public:
str.trim();
Add(str);
start = p+1;
}
}
++p;
}
......@@ -187,39 +185,39 @@ public:
}
delete [] buf;
}
}
};
//This function subdivides a string in a list of strings
//This function subdivides a string in a list of strings
/** This function subdivides strings divided by divider in a list of strings.
\return A StringList made of all strings divided by divider.*/
StringList SubdivideString(String str, String divider)
{
StringList strings; //returned StringList
strings.clear(); //clear returned stringlist
int c=0;
StringList strings; //returned StringList
strings.clear(); //clear returned stringlist
int c=0;
int l=str.size();
//process entire string
while(c<l)
//process entire string
while(c<l)
{
String resultstr;
resultstr = "";
//read characters until divider is encountered
while((str[c]!=divider[0]) && c<l)
String resultstr;
resultstr = "";
//read characters until divider is encountered
while((str[c]!=divider[0]) && c<l)
{
resultstr += str[c];
c++;
}
//Remove spaces \t and \n from string in my implementation...
//pay attention or change it in dll.h if you don't want to remove
//a particular char.
resultstr.trim();//trims string resultstr
strings.Add(resultstr);//add trimmed string
c++;
}
resultstr += str[c];
++c;
}
//Remove spaces \t and \n from string in my implementation...
//pay attention or change it in dll.h if you don't want to remove
//a particular char.
resultstr.trim();//trims string resultstr
strings.Add(resultstr);//add trimmed string
++c;
}
return strings;
}
......@@ -240,109 +238,111 @@ bool GetDMFHeader (StringList RawFile, dmfHeader & header)
temp = SubdivideString(RawFile[1],String(" "));//get version
StringList temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
header.dmfVersion = (float)atof(temp1[0].c_str());//save version
temp.clear();
temp = SubdivideString(RawFile[2],String(";"));//get name,ambient color and shadow opacity
sprintf(header.dmfName,"%s",temp[0].c_str());//save name
String red=String(""), green=String(""), blue=String("");
//get color value in hex
blue.append((char*)&temp[1][2]);
blue.append((char*)&temp[1][3]);
green.append((char*)&temp[1][4]);
green.append((char*)&temp[1][5]);
red.append((char*)&temp[1][6]);
red.append((char*)&temp[1][7]);
//set ambient color
header.dmfAmbient.set(0, axtoi(red.c_str()),
axtoi(green.c_str()), axtoi(blue.c_str()));
//set Shadow intensity
header.dmfShadow = (float)atof(temp[2].c_str());
//set current position
int offs=3;
//set Materials Number
header.numMaterials=atoi(RawFile[offs].c_str());
offs=offs + header.numMaterials;
offs++;
//set Object Number
header.numObjects=atoi(RawFile[offs].c_str());
//retrieve face and vertices number
header.numVertices=0;
header.numFaces=0;
header.numWatFaces=0;
header.numWatVertices=0;
offs++;
s32 fac;
int i;
for(i=0; i < (int)header.numObjects; i++)
{
StringList wat=SubdivideString(RawFile[offs],String(";"));
StringList wat1=SubdivideString(wat[0],String("_"));
offs++;
offs = offs + atoi(RawFile[offs].c_str());
offs++;
fac=atoi(RawFile[offs].c_str());
if(!(wat1[0]==String("water") && wat[2]==String("0")))
header.numFaces = header.numFaces + fac;
else
header.numWatFaces = header.numWatFaces + fac;
offs++;
for(int j=0; j<fac; j++)
if(!(wat1[0] == String("water") && wat[2] == String("0")))
header.numVertices=header.numVertices + atoi(RawFile[offs+j].c_str());
else
header.numWatVertices=header.numWatVertices + atoi(RawFile[offs + j].c_str());
offs = offs + fac;
}
//retrieve number of dynamic lights
header.numLights=0;
temp.clear();
temp1.clear();
s32 lit = atoi(RawFile[offs].c_str());
for (i=0; i<lit; i++)
temp.clear();
temp = SubdivideString(RawFile[2],String(";"));//get name,ambient color and shadow opacity
sprintf(header.dmfName,"%s",temp[0].c_str());//save name
String red=String(""), green=String(""), blue=String("");
//get color value in hex
blue.append((char*)&temp[1][2]);
blue.append((char*)&temp[1][3]);
green.append((char*)&temp[1][4]);
green.append((char*)&temp[1][5]);
red.append((char*)&temp[1][6]);
red.append((char*)&temp[1][7]);
//set ambient color
header.dmfAmbient.set(0, axtoi(red.c_str()),
axtoi(green.c_str()), axtoi(blue.c_str()));
//set Shadow intensity
header.dmfShadow = (float)atof(temp[2].c_str());
//set current position
int offs=3;
//set Materials Number
header.numMaterials=atoi(RawFile[offs].c_str());
offs+=header.numMaterials;
++offs;
//set Object Number
header.numObjects=atoi(RawFile[offs].c_str());
//retrieve face and vertices number
header.numVertices=0;
header.numFaces=0;
header.numWatFaces=0;
header.numWatVertices=0;
offs++;
s32 fac;
int i;
for(i=0; i < (int)header.numObjects; i++)
{
offs++;
temp=SubdivideString(RawFile[offs],String(";"));
StringList wat=SubdivideString(RawFile[offs],String(";"));
StringList wat1=SubdivideString(wat[0],String("_"));
++offs;
offs += atoi(RawFile[offs].c_str());
++offs;
fac=atoi(RawFile[offs].c_str());
if(atoi(temp[0].c_str())==1)
if(!(wat1[0]==String("water") && wat[2]==String("0")))
header.numFaces = header.numFaces + fac;
else
header.numWatFaces = header.numWatFaces + fac;
offs++;
for(int j=0; j<fac; j++)
{
temp1=SubdivideString(temp[18],String("_"));
if(!(wat1[0] == String("water") && wat[2] == String("0")))
header.numVertices=header.numVertices + atoi(RawFile[offs+j].c_str());
else
header.numWatVertices=header.numWatVertices + atoi(RawFile[offs + j].c_str());
}
offs = offs + fac;
}
//retrieve number of dynamic lights
header.numLights=0;
temp.clear();
temp1.clear();
s32 lit = atoi(RawFile[offs].c_str());
for (i=0; i<lit; i++)
{
offs++;
temp=SubdivideString(RawFile[offs],String(";"));
if(temp1[0]==String("dynamic"))
header.numLights++;
if(atoi(temp[0].c_str())==1)
{
temp1=SubdivideString(temp[18],String("_"));
if(temp1[0]==String("dynamic"))
header.numLights++;
}
temp.clear();
temp1.clear();
temp.clear();
temp1.clear();
}
return true; //everything is OK so loading is correct
return true; //everything is OK so loading is correct
}
/**This function extract an array of dmfMaterial from a DMF file.
You must give in input a StringList representing a DMF file loaded with LoadFromFile.
\return true if function succeed or false on fail.*/
\return true if function succeed or false on fail.*/
bool GetDMFMaterials(StringList RawFile /**<StringList representing a DMF file.*/,
dmfMaterial materials[]/**<Materials returned.*/,
int num_material/**<Number of materials contained in DMF file.*/,
......@@ -356,20 +356,20 @@ bool GetDMFMaterials(StringList RawFile /**<StringList representing a DMF file.*
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
//end checking
temp.clear();
temp1.clear();
for(int i=0;i<num_material; ++i)
{
temp=SubdivideString(RawFile[offs+i],";");
......@@ -401,7 +401,7 @@ bool GetDMFMaterials(StringList RawFile /**<StringList representing a DMF file.*
else
sprintf(materials[i].lightmapName,"%s",temp1[1].c_str());
}
else
else
{
materials[i].lightmapFlag=1;
materials[i].lightmapName[0]=0;
......@@ -415,282 +415,292 @@ bool GetDMFMaterials(StringList RawFile /**<StringList representing a DMF file.*
/**This function extract an array of dmfMaterial from a DMF file considering 1st an 2nd layer for water plains.
You must give in input a StringList representing a DMF file loaded with LoadFromFile.
\return true if function succeed or false on fail.*/
\return true if function succeed or false on fail.*/
bool GetDMFWaterMaterials(StringList RawFile /**<StringList representing a DMF file.*/,
dmfMaterial materials[]/**<Materials returned.*/,
int num_material/**<Number of materials contained in DMF file.*/){
int offs=4;
StringList temp;
StringList temp1;
StringList temp2;
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
//end checking
temp.clear();
temp1.clear();
for(int i=0;i<num_material;i++)
{
temp = SubdivideString(RawFile[offs+i],";");
materials[i].materialID=i;
temp1 = SubdivideString(temp[5],",");
materials[i].textureFlag=atoi(temp1[0].c_str());
temp2 = SubdivideString(temp1[1],"\\");
sprintf(materials[i].textureName,"%s",temp2[temp2.size()-1].c_str());
temp1.clear();
temp2.clear();
int a=temp.size();
if(a==7)
{
temp1=SubdivideString(temp[6],",");
materials[i].lightmapFlag=atoi(temp1[0].c_str());
temp2=SubdivideString(temp1[1],"\\");
sprintf(materials[i].lightmapName,"%s",temp2[temp2.size() - 1].c_str());
}
else
{
materials[i].lightmapFlag=1;
sprintf(materials[i].lightmapName,"FFFFFFFF");
}
temp1.clear();
temp2.clear();
}
return true;
dmfMaterial materials[]/**<Materials returned.*/,
int num_material/**<Number of materials contained in DMF file.*/
)
{
int offs=4;
StringList temp;
StringList temp1;
StringList temp2;
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
//end checking
temp.clear();
temp1.clear();
for(int i=0;i<num_material;i++)
{
temp = SubdivideString(RawFile[offs+i],";");
materials[i].materialID=i;
temp1 = SubdivideString(temp[5],",");
materials[i].textureFlag=atoi(temp1[0].c_str());
temp2 = SubdivideString(temp1[1],"\\");
sprintf(materials[i].textureName,"%s",temp2[temp2.size()-1].c_str());
temp1.clear();
temp2.clear();
int a=temp.size();
if(a==7)
{
temp1=SubdivideString(temp[6],",");
materials[i].lightmapFlag=atoi(temp1[0].c_str());
temp2=SubdivideString(temp1[1],"\\");
sprintf(materials[i].lightmapName,"%s",temp2[temp2.size() - 1].c_str());
}
else
{
materials[i].lightmapFlag=1;
sprintf(materials[i].lightmapName,"FFFFFFFF");
}
temp1.clear();
temp2.clear();
}
return true;
}
/**This function extract an array of dmfVert and dmfFace from a DMF file.
You must give in input a StringList representing a DMF file loaded with LoadFromFile and two arrays long enough.
Please use GetDMFHeader() before this function to know number of vertices and faces.
\return true if function succeed or false on fail.*/
\return true if function succeed or false on fail.*/
bool GetDMFVerticesFaces(StringList RawFile/**<StringList representing a DMF file.*/,
dmfVert vertices[]/**<Vertices returned*/,
dmfFace faces[]/**Faces returned*/){
int offs=3;
int offs1=0;
StringList temp,temp1;
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
//end checking
temp.clear();
temp1.clear();
offs=offs + atoi(RawFile[offs].c_str());
offs++;
s32 objs = atoi(RawFile[offs].c_str());
s32 fac=0, vert=0, tmp_sz=0, vert_cnt=0, face_cnt=0;
offs++;
for (int i=0; i<objs; i++)
{
StringList wat=SubdivideString(RawFile[offs],";");
StringList wat1=SubdivideString(wat[0],"_");
offs++;
offs1=offs;
offs=offs + atoi(RawFile[offs].c_str());
offs++;
offs1++;
fac=atoi(RawFile[offs].c_str());
offs++;
if(!(wat1[0]==String("water") && wat[2]==String("0")))
{
for(int j=0;j<fac;j++)
{
temp=SubdivideString(RawFile[offs+j],";");
//first value is vertices number for this face
faces[face_cnt].numVerts=atoi(temp[0].c_str());
vert=faces[face_cnt].numVerts;
//second is material ID
faces[face_cnt].materialID=atoi(temp[1].c_str());
//vertices are ordined
faces[face_cnt].firstVert=vert_cnt;
//now we'll create vertices structure
for(int k=0;k<vert;k++)
{
//get vertex position
temp1=SubdivideString(RawFile[offs1+atoi(temp[2+k].c_str())],";");
//copy x,y,z values
vertices[vert_cnt].pos[0] = (float)atof(temp1[0].c_str());
vertices[vert_cnt].pos[1] = (float)atof(temp1[1].c_str());
vertices[vert_cnt].pos[2] = (float)-atof(temp1[2].c_str());
//get uv coords for tex and light if any
vertices[vert_cnt].tc[0] = (float)atof(temp[2+vert+(2*k)].c_str());
vertices[vert_cnt].tc[1] = (float)atof(temp[2+vert+(2*k)+1].c_str());
tmp_sz=temp.size();
vertices[vert_cnt].lc[0] = (float)atof(temp[tmp_sz-(2*vert)+(2*k)].c_str());
vertices[vert_cnt].lc[1] = (float)atof(temp[tmp_sz-(2*vert)+(2*k)+1].c_str());
vert_cnt++;
temp1.clear();
}
face_cnt++;
temp.clear();
}
}
offs=offs+fac;
}
return true;
dmfVert vertices[]/**<Vertices returned*/,
dmfFace faces[]/**Faces returned*/
)
{
int offs=3;
int offs1=0;
StringList temp,temp1;
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
//end checking
temp.clear();
temp1.clear();
offs=offs + atoi(RawFile[offs].c_str());
offs++;
s32 objs = atoi(RawFile[offs].c_str());
s32 fac=0, vert=0, tmp_sz=0, vert_cnt=0, face_cnt=0;
offs++;
for (int i=0; i<objs; i++)
{
StringList wat=SubdivideString(RawFile[offs],";");
StringList wat1=SubdivideString(wat[0],"_");
offs++;
offs1=offs;
offs=offs + atoi(RawFile[offs].c_str());
offs++;
offs1++;
fac=atoi(RawFile[offs].c_str());
offs++;
if(!(wat1[0]==String("water") && wat[2]==String("0")))
{
for(int j=0;j<fac;j++)
{
temp=SubdivideString(RawFile[offs+j],";");
//first value is vertices number for this face
faces[face_cnt].numVerts=atoi(temp[0].c_str());
vert=faces[face_cnt].numVerts;
//second is material ID
faces[face_cnt].materialID=atoi(temp[1].c_str());
//vertices are ordined
faces[face_cnt].firstVert=vert_cnt;
//now we'll create vertices structure
for(int k=0;k<vert;k++)
{
//get vertex position
temp1=SubdivideString(RawFile[offs1+atoi(temp[2+k].c_str())],";");
//copy x,y,z values
vertices[vert_cnt].pos[0] = (float)atof(temp1[0].c_str());
vertices[vert_cnt].pos[1] = (float)atof(temp1[1].c_str());
vertices[vert_cnt].pos[2] = (float)-atof(temp1[2].c_str());
//get uv coords for tex and light if any
vertices[vert_cnt].tc[0] = (float)atof(temp[2+vert+(2*k)].c_str());
vertices[vert_cnt].tc[1] = (float)atof(temp[2+vert+(2*k)+1].c_str());
tmp_sz=temp.size();
vertices[vert_cnt].lc[0] = (float)atof(temp[tmp_sz-(2*vert)+(2*k)].c_str());
vertices[vert_cnt].lc[1] = (float)atof(temp[tmp_sz-(2*vert)+(2*k)+1].c_str());
vert_cnt++;
temp1.clear();
}
face_cnt++;
temp.clear();
}
}
offs=offs+fac;
}
return true;
}
/**This function extract an array of dmfLights from a DMF file.
You must give in input a StringList representing a DMF file loaded with LoadFromFile
and one array long enough.
Please use GetDMFHeader() before this function to know number of dynamic lights.
\return true if function succeed or false on fail.*/
You must give in input a StringList representing a DMF file loaded with
LoadFromFile and one array long enough. Please use GetDMFHeader() before this
function to know number of dynamic lights.
\return true if function succeed or false on fail.*/
bool GetDMFLights(StringList RawFile/**<StringList representing a DMF file.*/,
dmfLight lights[]/**<Lights returned.*/){
int offs=3;
StringList temp,temp1;
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
//end checking
temp.clear();
temp1.clear();
offs=offs + atoi(RawFile[offs].c_str());
offs++;
s32 objs = atoi(RawFile[offs].c_str());
s32 lit=0;
s32 d_lit=0;
offs++;
//let's get position of lights in file
int i;
for(i=0;i<objs;i++)
{
offs++;
offs = offs + atoi(RawFile[offs].c_str());
offs++;
offs = offs + atoi(RawFile[offs].c_str());
offs++;
}
//let's find dynamic lights
lit = atoi(RawFile[offs].c_str());
for(i=0;i<lit;i++)
{
offs++;
temp=SubdivideString(RawFile[offs],String(";"));
if(atoi(temp[0].c_str())==1){
temp1=SubdivideString(temp[18],String("_"));
if(temp1[0]==String("dynamic"))
{
lights[d_lit].radius = (float)atof(temp[4].c_str());
lights[d_lit].pos[0] = (float)atof(temp[5].c_str());
lights[d_lit].pos[1] = (float)atof(temp[6].c_str());
lights[d_lit].pos[2] = (float)-atof(temp[7].c_str());
lights[d_lit].diffuseColor = SColorf(
SColor(255, atoi(temp[10].c_str()), atoi(temp[11].c_str()),
atoi(temp[12].c_str())));
lights[d_lit].specularColor = SColorf(
SColor(255, atoi(temp[13].c_str()), atoi(temp[14].c_str()),
atoi(temp[15].c_str())));
d_lit++;
}
}
temp.clear();
temp1.clear();
}
return true;
dmfLight lights[]/**<Lights returned.*/
)
{
int offs=3;
StringList temp,temp1;
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
//end checking
temp.clear();
temp1.clear();
offs=offs + atoi(RawFile[offs].c_str());
offs++;
s32 objs = atoi(RawFile[offs].c_str());
s32 lit=0;
s32 d_lit=0;
offs++;
//let's get position of lights in file
int i;
for(i=0;i<objs;i++)
{
offs++;
offs = offs + atoi(RawFile[offs].c_str());
offs++;
offs = offs + atoi(RawFile[offs].c_str());
offs++;
}
//let's find dynamic lights
lit = atoi(RawFile[offs].c_str());
for(i=0;i<lit;i++)
{
offs++;
temp=SubdivideString(RawFile[offs],String(";"));
if(atoi(temp[0].c_str())==1)
{
temp1=SubdivideString(temp[18],String("_"));
if(temp1[0]==String("dynamic"))
{
lights[d_lit].radius = (float)atof(temp[4].c_str());
lights[d_lit].pos[0] = (float)atof(temp[5].c_str());
lights[d_lit].pos[1] = (float)atof(temp[6].c_str());
lights[d_lit].pos[2] = (float)-atof(temp[7].c_str());
lights[d_lit].diffuseColor = SColorf(
SColor(255, atoi(temp[10].c_str()), atoi(temp[11].c_str()),
atoi(temp[12].c_str())));
lights[d_lit].specularColor = SColorf(
SColor(255, atoi(temp[13].c_str()), atoi(temp[14].c_str()),
atoi(temp[15].c_str())));
d_lit++;
}
}
temp.clear();
temp1.clear();
}
return true;
}
/**This function extract an array of dmfWaterPlain,dmfVert and dmfFace from a DMF file.
You must give in input a StringList representing a DMF file loaded with LoadFromFile and three arrays long enough.
Please use GetDMFHeader() before this function to know number of water plains and water faces as well as water vertices.
\return true if function succeed or false on fail.*/
\return true if function succeed or false on fail.*/
bool GetDMFWaterPlains(StringList RawFile/**<StringList representing a DMF file.*/,
dmfWaterPlain wat_planes[]/**<Water planes returned.*/,
dmfVert vertices[]/**<Vertices returned*/,
dmfFace faces[]/**Faces returned*/){
int offs=3;
int offs1=0;
StringList temp,temp1;
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
//end checking
temp.clear();
temp1.clear();
offs=offs+atoi(RawFile[offs].c_str());
offs++;
s32 objs=atoi(RawFile[offs].c_str());
s32 fac=0,vert=0,tmp_sz=0,vert_cnt=0,face_cnt=0,wat_id=0;
core::dimension2d<s32> tilenum(40,40);
f32 waveheight=3.0f;
f32 wavespeed=300.0f;
f32 wavelength=80.0f;
offs++;
dmfWaterPlain wat_planes[]/**<Water planes returned.*/,
dmfVert vertices[]/**<Vertices returned*/,
dmfFace faces[]/**Faces returned*/
)
{
int offs=3;
int offs1=0;
StringList temp,temp1;
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
//end checking
temp.clear();
temp1.clear();
offs=offs+atoi(RawFile[offs].c_str());
offs++;
s32 objs=atoi(RawFile[offs].c_str());
s32 fac=0,vert=0,tmp_sz=0,vert_cnt=0,face_cnt=0,wat_id=0;
core::dimension2d<s32> tilenum(40,40);
f32 waveheight=3.0f;
f32 wavespeed=300.0f;
f32 wavelength=80.0f;
offs++;
for(int i=0;i<objs;i++)
{
StringList wat=SubdivideString(RawFile[offs],";");
StringList wat1=SubdivideString(wat[0],"_");
offs++;
offs1=offs;
offs=offs+atoi(RawFile[offs].c_str());
offs++;
offs1++;
fac=atoi(RawFile[offs].c_str());
offs++;
StringList wat=SubdivideString(RawFile[offs],";");
StringList wat1=SubdivideString(wat[0],"_");
offs++;
offs1=offs;
offs=offs+atoi(RawFile[offs].c_str());
offs++;
offs1++;
fac=atoi(RawFile[offs].c_str());
offs++;
if(wat1[0]==String("water") && wat[2]==String("0"))
{
......@@ -702,80 +712,79 @@ bool GetDMFWaterPlains(StringList RawFile/**<StringList representing a DMF file.
{
switch(j)
{
case 0:
if(atoi(userinfo[0].c_str()))
tilenum.Width = atoi(userinfo[0].c_str());
break;
case 1:
if(atoi(userinfo[1].c_str()))
tilenum.Height = atoi(userinfo[1].c_str());
break;
case 2:
if(atof(userinfo[2].c_str()))
waveheight = (float)atof(userinfo[2].c_str());
break;
case 3:
if(atof(userinfo[3].c_str()))
wavespeed = (float)atof(userinfo[3].c_str());
break;
case 4:
if(atof(userinfo[4].c_str()))
wavelength = (float)atof(userinfo[4].c_str());
break;
case 0:
if(atoi(userinfo[0].c_str()))
tilenum.Width = atoi(userinfo[0].c_str());
break;
case 1:
if(atoi(userinfo[1].c_str()))
tilenum.Height = atoi(userinfo[1].c_str());
break;
case 2:
if(atof(userinfo[2].c_str()))
waveheight = (float)atof(userinfo[2].c_str());
break;
case 3:
if(atof(userinfo[3].c_str()))
wavespeed = (float)atof(userinfo[3].c_str());
break;
case 4:
if(atof(userinfo[4].c_str()))
wavelength = (float)atof(userinfo[4].c_str());
break;
}
}
wat_planes[wat_id].waterID=wat_id;
wat_planes[wat_id].numFaces=fac;
wat_planes[wat_id].firstFace=face_cnt;
wat_planes[wat_id].tileNum=tilenum;
wat_planes[wat_id].waveHeight=waveheight;
wat_planes[wat_id].waveSpeed=wavespeed;
wat_planes[wat_id].waveLength=wavelength;
}
wat_planes[wat_id].waterID=wat_id;
wat_planes[wat_id].numFaces=fac;
wat_planes[wat_id].firstFace=face_cnt;
wat_planes[wat_id].tileNum=tilenum;
wat_planes[wat_id].waveHeight=waveheight;
wat_planes[wat_id].waveSpeed=wavespeed;
wat_planes[wat_id].waveLength=wavelength;
for(j=0;j<fac;j++)
{
temp=SubdivideString(RawFile[offs+j],";");
//first value is vertices number for this face
faces[face_cnt].numVerts=atoi(temp[0].c_str());
vert=faces[face_cnt].numVerts;
//second is material ID
faces[face_cnt].materialID=atoi(temp[1].c_str());
//vertices are ordined
faces[face_cnt].firstVert=vert_cnt;
//now we'll create vertices structure
for(int k=0;k<vert;k++)
{
//get vertex position
temp1=SubdivideString(RawFile[offs1+atoi(temp[2+k].c_str())], ";");
//copy x,y,z values
vertices[vert_cnt].pos[0]=(float)atof(temp1[0].c_str());
vertices[vert_cnt].pos[1]=(float)atof(temp1[1].c_str());
vertices[vert_cnt].pos[2]=(float)-atof(temp1[2].c_str());
//get uv coords for tex and light if any
vertices[vert_cnt].tc[0]=(float)atof(temp[2+vert+(2*k)].c_str());
vertices[vert_cnt].tc[1]=(float)atof(temp[2+vert+(2*k)+1].c_str());
tmp_sz=temp.size();
vertices[vert_cnt].lc[0]=(float)atof(temp[tmp_sz-(2*vert)+(2*k)].c_str());
vertices[vert_cnt].lc[1]=(float)atof(temp[tmp_sz-(2*vert)+(2*k)+1].c_str());
vert_cnt++;
temp1.clear();
}
face_cnt++;
temp.clear();
};
}
offs=offs+fac;
}
return true;
}
temp=SubdivideString(RawFile[offs+j],";");
//first value is vertices number for this face
faces[face_cnt].numVerts=atoi(temp[0].c_str());
vert=faces[face_cnt].numVerts;
//second is material ID
faces[face_cnt].materialID=atoi(temp[1].c_str());
//vertices are ordined
faces[face_cnt].firstVert=vert_cnt;
//now we'll create vertices structure
for(int k=0;k<vert;k++)
{
//get vertex position
temp1=SubdivideString(RawFile[offs1+atoi(temp[2+k].c_str())], ";");
//copy x,y,z values
vertices[vert_cnt].pos[0]=(float)atof(temp1[0].c_str());
vertices[vert_cnt].pos[1]=(float)atof(temp1[1].c_str());
vertices[vert_cnt].pos[2]=(float)-atof(temp1[2].c_str());
//get uv coords for tex and light if any
vertices[vert_cnt].tc[0]=(float)atof(temp[2+vert+(2*k)].c_str());
vertices[vert_cnt].tc[1]=(float)atof(temp[2+vert+(2*k)+1].c_str());
tmp_sz=temp.size();
vertices[vert_cnt].lc[0]=(float)atof(temp[tmp_sz-(2*vert)+(2*k)].c_str());
vertices[vert_cnt].lc[1]=(float)atof(temp[tmp_sz-(2*vert)+(2*k)+1].c_str());
vert_cnt++;
temp1.clear();
}
face_cnt++;
temp.clear();
}
}
offs=offs+fac;
}
return true;
}
#endif /* __DMF_SUPPORT_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment