Commit 35fe8766 authored by hybrid's avatar hybrid

Some dmf simplifications.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2875 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 06379558
...@@ -57,7 +57,8 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -57,7 +57,8 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
video::IVideoDriver* driver = SceneMgr->getVideoDriver(); video::IVideoDriver* driver = SceneMgr->getVideoDriver();
//Load stringlist //Load stringlist
StringList dmfRawFile(file); StringList dmfRawFile;
LoadFromFile(file, dmfRawFile);
if (dmfRawFile.size()==0) if (dmfRawFile.size()==0)
return 0; return 0;
...@@ -69,13 +70,13 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -69,13 +70,13 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
dmfHeader header; dmfHeader header;
//load header //load header
core::array<dmfMaterial> materiali;
if (GetDMFHeader(dmfRawFile, header)) if (GetDMFHeader(dmfRawFile, header))
{ {
//let's set ambient light //let's set ambient light
SceneMgr->setAmbientLight(header.dmfAmbient); SceneMgr->setAmbientLight(header.dmfAmbient);
//let's create the correct number of materials, vertices and faces //let's create the correct number of materials, vertices and faces
core::array<dmfMaterial> materiali;
dmfVert *verts=new dmfVert[header.numVertices]; dmfVert *verts=new dmfVert[header.numVertices];
dmfFace *faces=new dmfFace[header.numFaces]; dmfFace *faces=new dmfFace[header.numFaces];
...@@ -113,7 +114,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -113,7 +114,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
for (i = 0; i < header.numFaces; i++) for (i = 0; i < header.numFaces; i++)
{ {
#ifdef _IRR_DMF_DEBUG_ #ifdef _IRR_DMF_DEBUG_
// os::Printer::log("Polygon with #vertices", core::stringc(faces[i].numVerts).c_str()); os::Printer::log("Polygon with #vertices", core::stringc(faces[i].numVerts).c_str());
#endif #endif
if (faces[i].numVerts < 3) if (faces[i].numVerts < 3)
continue; continue;
...@@ -187,6 +188,33 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -187,6 +188,33 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
} }
} }
delete verts;
delete faces;
}
// delete all buffers without geometry in it.
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Cleaning meshbuffers.");
#endif
i = 0;
while(i < mesh->MeshBuffers.size())
{
if (mesh->MeshBuffers[i]->getVertexCount() == 0 ||
mesh->MeshBuffers[i]->getIndexCount() == 0)
{
// Meshbuffer is empty -- drop it
mesh->MeshBuffers[i]->drop();
mesh->MeshBuffers.erase(i);
materiali.erase(i);
}
else
{
i++;
}
}
{
//load textures and lightmaps in materials. //load textures and lightmaps in materials.
//don't worry if you receive a could not load texture, cause if you don't need //don't worry if you receive a could not load texture, cause if you don't need
//a particular material in your scene it will be loaded and then destroyed. //a particular material in your scene it will be loaded and then destroyed.
...@@ -202,7 +230,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -202,7 +230,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
path = FileSystem->getFileDir(file->getFileName()); path = FileSystem->getFileDir(file->getFileName());
path += ('/'); path += ('/');
for (i=0; i<header.numMaterials; i++) for (i=0; i<mesh->getMeshBufferCount(); i++)
{ {
//texture and lightmap //texture and lightmap
video::ITexture *tex = 0; video::ITexture *tex = 0;
...@@ -368,29 +396,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -368,29 +396,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
mat.setTexture(0, tex); mat.setTexture(0, tex);
mat.setTexture(1, lig); mat.setTexture(1, lig);
} }
delete verts;
delete faces;
}
// delete all buffers without geometry in it.
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Cleaning meshbuffers.");
#endif
i = 0;
while(i < mesh->MeshBuffers.size())
{
if (mesh->MeshBuffers[i]->getVertexCount() == 0 ||
mesh->MeshBuffers[i]->getIndexCount() == 0)
{
// Meshbuffer is empty -- drop it
mesh->MeshBuffers[i]->drop();
mesh->MeshBuffers.erase(i);
}
else
{
i++;
}
} }
// create bounding box // create bounding box
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
// This support library has been made by Salvatore Russo and is released under GNU public license for general uses. // 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. // For uses in Irrlicht core and only for Irrlicht related uses I release this library under zlib license.
// It uses standard template libraries to create String class and StringList class used in DeleD
// plugins made by me.
#ifndef __DMF_SUPPORT_H_INCLUDED__ #ifndef __DMF_SUPPORT_H_INCLUDED__
#define __DMF_SUPPORT_H_INCLUDED__ #define __DMF_SUPPORT_H_INCLUDED__
...@@ -27,6 +25,8 @@ namespace irr ...@@ -27,6 +25,8 @@ namespace irr
{ {
namespace scene namespace scene
{ {
namespace
{
/** A structure representing some DeleD infos. /** A structure representing some DeleD infos.
This structure contains data about DeleD level file like: version, ambient colour, number of objects etc...*/ This structure contains data about DeleD level file like: version, ambient colour, number of objects etc...*/
...@@ -73,7 +73,7 @@ struct dmfFace ...@@ -73,7 +73,7 @@ struct dmfFace
}; };
/** A structure rapresenting a single vertice. /** A structure representing a single vertice.
This structure contains vertice position coordinates and texture an lightmap UV.*/ This structure contains vertice position coordinates and texture an lightmap UV.*/
struct dmfVert struct dmfVert
{ {
...@@ -93,7 +93,7 @@ struct dmfLight ...@@ -93,7 +93,7 @@ struct dmfLight
f32 radius;//!<Maximum radius of light. f32 radius;//!<Maximum radius of light.
}; };
/** A structure rapresenting a single water plane. /** A structure representing a single water plane.
This structure contains light position coordinates, diffuse colour, specular colour and maximum radius of light.*/ This structure contains light position coordinates, diffuse colour, specular colour and maximum radius of light.*/
struct dmfWaterPlane struct dmfWaterPlane
{ {
...@@ -117,52 +117,16 @@ int axtoi(const char *hexStg) ...@@ -117,52 +117,16 @@ int axtoi(const char *hexStg)
return (intValue); return (intValue);
} }
typedef core::array<core::stringc> StringList;
/** A standard string. //Loads a stringlist from a file
A standard string created with standard template libraries.*/ //note that each String added to StringList
typedef core::stringc String; //is separated by a \\n character and it's present
//at the end of line.
//Define a class StringList based on core::array and the defined class String /** Loads a StringList from a file.
/** A simple stringlist class based on core::array. This function loads a StringList from a file where each string is divided by a \\n char.*/
This StringList class is based on core::array and the defined String class. void LoadFromFile(io::IReadFile* file, StringList& strlist)
*/
class StringList : public core::array<String>
{ {
public:
/**Basic Constructor*/
StringList()
{
}
/**Constructor based on file loading.
Look at LoadFromFile specifications.*/
StringList(io::IReadFile* file)
{
LoadFromFile(file);
}
/**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*/)
{
push_back(str);
}
//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(); const long sz = file->getSize();
char* buf = new char[sz+1]; char* buf = new char[sz+1];
file->read(buf, sz); file->read(buf, sz);
...@@ -176,7 +140,7 @@ public: ...@@ -176,7 +140,7 @@ public:
{ {
core::stringc str(start, (u32)(p - start - 1)); core::stringc str(start, (u32)(p - start - 1));
str.trim(); str.trim();
Add(str); strlist.push_back(str);
start = p+1; start = p+1;
} }
...@@ -187,17 +151,16 @@ public: ...@@ -187,17 +151,16 @@ public:
{ {
core::stringc str(start, (u32)(p - start - 1)); core::stringc str(start, (u32)(p - start - 1));
str.trim(); str.trim();
Add(str); strlist.push_back(str);
} }
delete [] buf; 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. /** This function subdivides strings divided by divider in a list of strings.
\return A StringList made of all strings divided by divider.*/ \return A StringList made of all strings divided by divider.*/
StringList SubdivideString(const String& str, const String& divider) StringList SubdivideString(const core::stringc& str, const core::stringc& divider)
{ {
StringList strings; //returned StringList StringList strings; //returned StringList
strings.clear(); //clear returned stringlist strings.clear(); //clear returned stringlist
...@@ -208,7 +171,7 @@ StringList SubdivideString(const String& str, const String& divider) ...@@ -208,7 +171,7 @@ StringList SubdivideString(const String& str, const String& divider)
//process entire string //process entire string
while(c<l) while(c<l)
{ {
String resultstr; core::stringc resultstr;
resultstr = ""; resultstr = "";
//read characters until divider is encountered //read characters until divider is encountered
while((str[c]!=divider[0]) && c<l) while((str[c]!=divider[0]) && c<l)
...@@ -221,7 +184,7 @@ StringList SubdivideString(const String& str, const String& divider) ...@@ -221,7 +184,7 @@ StringList SubdivideString(const String& str, const String& divider)
//pay attention or change it in dll.h if you don't want to remove //pay attention or change it in dll.h if you don't want to remove
//a particular char. //a particular char.
resultstr.trim();//trims string resultstr resultstr.trim();//trims string resultstr
strings.Add(resultstr);//add trimmed string strings.push_back(resultstr);//add trimmed string
++c; ++c;
} }
...@@ -235,21 +198,23 @@ You must give in input a StringList representing a DMF file loaded with LoadFrom ...@@ -235,21 +198,23 @@ You must give in input a StringList representing a DMF file loaded with LoadFrom
\return true if function succeed or false on fail.*/ \return true if function succeed or false on fail.*/
bool GetDMFHeader(const StringList& RawFile, dmfHeader& header) bool GetDMFHeader(const StringList& RawFile, dmfHeader& header)
{ {
StringList temp=SubdivideString(RawFile[0],String(";")); //file info StringList temp;
RawFile[0].split(temp, ";"); //file info
// StringList temp=SubdivideString(RawFile[0],";"); //file info
if ( temp[0] != String("DeleD Map File") ) if ( temp[0] != "DeleD Map File" )
return false; //not a deled file return false; //not a deled file
temp.clear(); temp.clear();
temp = SubdivideString(RawFile[1],String(" "));//get version temp = SubdivideString(RawFile[1]," ");//get version
StringList temp1=SubdivideString(temp[1],String(";")); StringList temp1=SubdivideString(temp[1],";");
header.dmfVersion = (float)atof(temp1[0].c_str());//save version header.dmfVersion = (float)atof(temp1[0].c_str());//save version
if (header.dmfVersion < 0.91) if (header.dmfVersion < 0.91)
return false;//not correct version return false;//not correct version
temp.clear(); temp.clear();
temp = SubdivideString(RawFile[2],String(";"));//get name,ambient color and shadow opacity temp = SubdivideString(RawFile[2],";");//get name,ambient color and shadow opacity
header.dmfName=temp[0];//save name header.dmfName=temp[0];//save name
//set ambient color //set ambient color
...@@ -281,8 +246,8 @@ bool GetDMFHeader(const StringList& RawFile, dmfHeader& header) ...@@ -281,8 +246,8 @@ bool GetDMFHeader(const StringList& RawFile, dmfHeader& header)
for(i=0; i < (int)header.numObjects; i++) for(i=0; i < (int)header.numObjects; i++)
{ {
StringList wat=SubdivideString(RawFile[offs],String(";")); StringList wat=SubdivideString(RawFile[offs],";");
StringList wat1=SubdivideString(wat[0],String("_")); StringList wat1=SubdivideString(wat[0],"_");
++offs; ++offs;
offs += atoi(RawFile[offs].c_str()); offs += atoi(RawFile[offs].c_str());
...@@ -290,7 +255,7 @@ bool GetDMFHeader(const StringList& RawFile, dmfHeader& header) ...@@ -290,7 +255,7 @@ bool GetDMFHeader(const StringList& RawFile, dmfHeader& header)
fac=atoi(RawFile[offs].c_str()); fac=atoi(RawFile[offs].c_str());
if(!(wat1[0]==String("water") && wat[2]==String("0"))) if(!(wat1[0]=="water" && wat[2]=="0"))
header.numFaces = header.numFaces + fac; header.numFaces = header.numFaces + fac;
else else
header.numWatFaces = header.numWatFaces + fac; header.numWatFaces = header.numWatFaces + fac;
...@@ -299,7 +264,7 @@ bool GetDMFHeader(const StringList& RawFile, dmfHeader& header) ...@@ -299,7 +264,7 @@ bool GetDMFHeader(const StringList& RawFile, dmfHeader& header)
for(int j=0; j<fac; j++) for(int j=0; j<fac; j++)
{ {
if(!(wat1[0] == String("water") && wat[2] == String("0"))) if(!(wat1[0] == "water" && wat[2] == "0"))
header.numVertices=header.numVertices + atoi(RawFile[offs+j].c_str()); header.numVertices=header.numVertices + atoi(RawFile[offs+j].c_str());
else else
header.numWatVertices=header.numWatVertices + atoi(RawFile[offs + j].c_str()); header.numWatVertices=header.numWatVertices + atoi(RawFile[offs + j].c_str());
...@@ -317,13 +282,13 @@ bool GetDMFHeader(const StringList& RawFile, dmfHeader& header) ...@@ -317,13 +282,13 @@ bool GetDMFHeader(const StringList& RawFile, dmfHeader& header)
for (i=0; i<lit; i++) for (i=0; i<lit; i++)
{ {
offs++; offs++;
temp=SubdivideString(RawFile[offs],String(";")); temp=SubdivideString(RawFile[offs],";");
if(atoi(temp[0].c_str())==1) if(atoi(temp[0].c_str())==1)
{ {
temp1=SubdivideString(temp[18],String("_")); temp1=SubdivideString(temp[18],"_");
if(temp1[0]==String("dynamic")) if(temp1[0]=="dynamic")
header.numLights++; header.numLights++;
} }
temp.clear(); temp.clear();
...@@ -404,14 +369,14 @@ bool GetDMFWaterMaterials(const StringList& RawFile /**<StringList representing ...@@ -404,14 +369,14 @@ bool GetDMFWaterMaterials(const StringList& RawFile /**<StringList representing
StringList temp1; StringList temp1;
StringList temp2; StringList temp2;
//Checking if this is a DeleD map File of version >= 0.91 //Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info temp=SubdivideString(RawFile[0],";");//file info
if ( temp[0] != String("DeleD Map File") ) if ( temp[0] != "DeleD Map File" )
return false;//not a deled file return false;//not a deled file
temp.clear(); temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version temp=SubdivideString(RawFile[1]," ");//get version
temp1=SubdivideString(temp[1],String(";")); temp1=SubdivideString(temp[1],";");
if (atof(temp1[0].c_str()) < 0.91) if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version return false;//not correct version
...@@ -498,7 +463,7 @@ bool GetDMFVerticesFaces(const StringList& RawFile/**<StringList representing a ...@@ -498,7 +463,7 @@ bool GetDMFVerticesFaces(const StringList& RawFile/**<StringList representing a
const s32 numFaces=atoi(RawFile[offs].c_str()); const s32 numFaces=atoi(RawFile[offs].c_str());
offs++; offs++;
if(!(wat1[0]==String("water") && wat[2]==String("0"))) if(!(wat1[0]=="water" && wat[2]=="0"))
{ {
for(s32 j=0; j<numFaces; ++j) for(s32 j=0; j<numFaces; ++j)
{ {
...@@ -550,14 +515,14 @@ bool GetDMFLights(const StringList& RawFile/**<StringList representing a DMF fil ...@@ -550,14 +515,14 @@ bool GetDMFLights(const StringList& RawFile/**<StringList representing a DMF fil
StringList temp,temp1; StringList temp,temp1;
//Checking if this is a DeleD map File of version >= 0.91 //Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info temp=SubdivideString(RawFile[0],";");//file info
if ( temp[0] != String("DeleD Map File") ) if ( temp[0] != "DeleD Map File" )
return false;//not a deled file return false;//not a deled file
temp.clear(); temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version temp=SubdivideString(RawFile[1]," ");//get version
temp1=SubdivideString(temp[1],String(";")); temp1=SubdivideString(temp[1],";");
if (atof(temp1[0].c_str()) < 0.91) if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version return false;//not correct version
...@@ -592,11 +557,11 @@ bool GetDMFLights(const StringList& RawFile/**<StringList representing a DMF fil ...@@ -592,11 +557,11 @@ bool GetDMFLights(const StringList& RawFile/**<StringList representing a DMF fil
for(i=0;i<lit;i++) for(i=0;i<lit;i++)
{ {
offs++; offs++;
temp=SubdivideString(RawFile[offs],String(";")); temp=SubdivideString(RawFile[offs],";");
if(atoi(temp[0].c_str())==1) if(atoi(temp[0].c_str())==1)
{ {
temp1=SubdivideString(temp[18],String("_")); temp1=SubdivideString(temp[18],"_");
if(temp1[0]==String("dynamic")) if(temp1[0]=="dynamic")
{ {
lights[d_lit].radius = (float)atof(temp[4].c_str()); lights[d_lit].radius = (float)atof(temp[4].c_str());
lights[d_lit].pos.set((float)atof(temp[5].c_str()), lights[d_lit].pos.set((float)atof(temp[5].c_str()),
...@@ -637,14 +602,14 @@ bool GetDMFWaterPlanes(const StringList& RawFile/**<StringList representing a DM ...@@ -637,14 +602,14 @@ bool GetDMFWaterPlanes(const StringList& RawFile/**<StringList representing a DM
StringList temp,temp1; StringList temp,temp1;
//Checking if this is a DeleD map File of version >= 0.91 //Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info temp=SubdivideString(RawFile[0],";");//file info
if ( temp[0] != String("DeleD Map File") ) if ( temp[0] != "DeleD Map File" )
return false;//not a deled file return false;//not a deled file
temp.clear(); temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version temp=SubdivideString(RawFile[1]," ");//get version
temp1=SubdivideString(temp[1],String(";")); temp1=SubdivideString(temp[1],";");
if (atof(temp1[0].c_str()) < 0.91) if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version return false;//not correct version
...@@ -675,7 +640,7 @@ bool GetDMFWaterPlanes(const StringList& RawFile/**<StringList representing a DM ...@@ -675,7 +640,7 @@ bool GetDMFWaterPlanes(const StringList& RawFile/**<StringList representing a DM
fac=atoi(RawFile[offs].c_str()); fac=atoi(RawFile[offs].c_str());
offs++; offs++;
if(wat1[0]==String("water") && wat[2]==String("0")) if(wat1[0]=="water" && wat[2]=="0")
{ {
StringList userinfo=SubdivideString(wat[7],","); StringList userinfo=SubdivideString(wat[7],",");
...@@ -760,6 +725,8 @@ bool GetDMFWaterPlanes(const StringList& RawFile/**<StringList representing a DM ...@@ -760,6 +725,8 @@ bool GetDMFWaterPlanes(const StringList& RawFile/**<StringList representing a DM
} }
} // end namespace } // end namespace
} // end namespace } // end namespace scene
} // end namespace irr
#endif /* __DMF_SUPPORT_H__ */ #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