Commit 6a1cafc0 authored by hybrid's avatar hybrid

Fixed some texture problems and speed up string reading. Release memory after mesh is loaded.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1211 dfc29bdd-3216-0410-991c-e03cc46cb475
parent f9d4bc02
...@@ -12,7 +12,7 @@ namespace irr ...@@ -12,7 +12,7 @@ namespace irr
namespace scene namespace scene
{ {
//#define LWO_READER_DEBUG #define LWO_READER_DEBUG
#define charsToUIntD(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d) #define charsToUIntD(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
inline unsigned int charsToUInt(const char *str) inline unsigned int charsToUInt(const char *str)
...@@ -140,8 +140,6 @@ bool CLWOMeshFileLoader::isALoadableFileExtension(const c8* filename) const ...@@ -140,8 +140,6 @@ bool CLWOMeshFileLoader::isALoadableFileExtension(const c8* filename) const
IAnimatedMesh* CLWOMeshFileLoader::createMesh(io::IReadFile* file) IAnimatedMesh* CLWOMeshFileLoader::createMesh(io::IReadFile* file)
{ {
File = file; File = file;
Points.clear();
Materials.clear();
if (Mesh) if (Mesh)
Mesh->drop(); Mesh->drop();
...@@ -172,8 +170,12 @@ IAnimatedMesh* CLWOMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -172,8 +170,12 @@ IAnimatedMesh* CLWOMeshFileLoader::createMesh(io::IReadFile* file)
am->recalculateBoundingBox(); am->recalculateBoundingBox();
Mesh->drop(); Mesh->drop();
Mesh = 0; Mesh = 0;
Points.clear(); Points.clear();
Polygons.clear();
TCoords.clear();
Materials.clear(); Materials.clear();
Images.clear();
return am; return am;
} }
...@@ -301,21 +303,29 @@ bool CLWOMeshFileLoader::readChunks() ...@@ -301,21 +303,29 @@ bool CLWOMeshFileLoader::readChunks()
#ifndef __BIG_ENDIAN__ #ifndef __BIG_ENDIAN__
index=os::Byteswap::byteswap(index); index=os::Byteswap::byteswap(index);
#endif #endif
size -= 4;
while (size != 0)
{
File->read(&type, 4); File->read(&type, 4);
File->read(&subsize, 2); File->read(&subsize, 2);
#ifndef __BIG_ENDIAN__ #ifndef __BIG_ENDIAN__
subsize=os::Byteswap::byteswap(subsize); subsize=os::Byteswap::byteswap(subsize);
#endif #endif
size -= 10; size -= 6;
if (strncmp(type, "STIL", 4)) if (strncmp(type, "STIL", 4))
{ {
File->seek(size, true); File->seek(subsize, true);
break; size -= subsize;
continue;
} }
core::stringc path; core::stringc path;
size -= readString(path); size -= readString(path, subsize);
#ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loaded clip", path.c_str());
#endif
Images.push_back(path); Images.push_back(path);
} }
}
break; break;
case charsToUIntD('S','U','R','F'): case charsToUIntD('S','U','R','F'):
#ifdef LWO_READER_DEBUG #ifdef LWO_READER_DEBUG
...@@ -342,7 +352,7 @@ bool CLWOMeshFileLoader::readChunks() ...@@ -342,7 +352,7 @@ bool CLWOMeshFileLoader::readChunks()
os::Printer::log("LWO loader: loading text."); os::Printer::log("LWO loader: loading text.");
#endif #endif
core::stringc text; core::stringc text;
size -= readString(text); size -= readString(text, size);
} }
break; break;
// not needed // not needed
...@@ -924,7 +934,7 @@ void CLWOMeshFileLoader::readMat(u32 size) ...@@ -924,7 +934,7 @@ void CLWOMeshFileLoader::readMat(u32 size)
mat->ReflMap=Images[tmp32-1]; mat->ReflMap=Images[tmp32-1];
} }
else else
size -= readString(mat->ReflMap); size -= readString(mat->ReflMap, size);
} }
break; break;
case charsToUIntD('R','S','A','N'): case charsToUIntD('R','S','A','N'):
...@@ -997,7 +1007,7 @@ void CLWOMeshFileLoader::readMat(u32 size) ...@@ -997,7 +1007,7 @@ void CLWOMeshFileLoader::readMat(u32 size)
mat->Texture[currTexture].Map=Images[tmp32-1]; mat->Texture[currTexture].Map=Images[tmp32-1];
} }
else else
size -= readString(mat->Texture[currTexture].Map); size -= readString(mat->Texture[currTexture].Map, size);
} }
break; break;
case charsToUIntD('T','B','L','R'): case charsToUIntD('T','B','L','R'):
...@@ -1159,7 +1169,7 @@ void CLWOMeshFileLoader::readMat(u32 size) ...@@ -1159,7 +1169,7 @@ void CLWOMeshFileLoader::readMat(u32 size)
File->read(&tmp32, 4); // skip type File->read(&tmp32, 4); // skip type
size -= 4; size -= 4;
core::stringc name; core::stringc name;
size -= readString(name); size -= readString(name, size);
// mat->VertexColor = getColorVMAP(name); // mat->VertexColor = getColorVMAP(name);
} }
break; break;
...@@ -1196,55 +1206,55 @@ void CLWOMeshFileLoader::readMat(u32 size) ...@@ -1196,55 +1206,55 @@ void CLWOMeshFileLoader::readMat(u32 size)
os::Printer::log("LWO loader: loading ctex."); os::Printer::log("LWO loader: loading ctex.");
#endif #endif
currTexture=0; currTexture=0;
size -= readString(mat->Texture[currTexture].Type); size -= readString(mat->Texture[currTexture].Type, size);
break; break;
case charsToUIntD('D','T','E','X'): case charsToUIntD('D','T','E','X'):
#ifdef LWO_READER_DEBUG #ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading dtex."); os::Printer::log("LWO loader: loading dtex.");
#endif #endif
currTexture=1; currTexture=1;
size -= readString(mat->Texture[currTexture].Type); size -= readString(mat->Texture[currTexture].Type, size);
break; break;
case charsToUIntD('S','T','E','X'): case charsToUIntD('S','T','E','X'):
#ifdef LWO_READER_DEBUG #ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading stex."); os::Printer::log("LWO loader: loading stex.");
#endif #endif
currTexture=2; currTexture=2;
size -= readString(mat->Texture[currTexture].Type); size -= readString(mat->Texture[currTexture].Type, size);
break; break;
case charsToUIntD('R','T','E','X'): case charsToUIntD('R','T','E','X'):
#ifdef LWO_READER_DEBUG #ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading rtex."); os::Printer::log("LWO loader: loading rtex.");
#endif #endif
currTexture=3; currTexture=3;
size -= readString(mat->Texture[currTexture].Type); size -= readString(mat->Texture[currTexture].Type, size);
break; break;
case charsToUIntD('T','T','E','X'): case charsToUIntD('T','T','E','X'):
#ifdef LWO_READER_DEBUG #ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading ttex."); os::Printer::log("LWO loader: loading ttex.");
#endif #endif
currTexture=4; currTexture=4;
size -= readString(mat->Texture[currTexture].Type); size -= readString(mat->Texture[currTexture].Type, size);
break; break;
case charsToUIntD('L','T','E','X'): case charsToUIntD('L','T','E','X'):
#ifdef LWO_READER_DEBUG #ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading ltex."); os::Printer::log("LWO loader: loading ltex.");
#endif #endif
currTexture=5; currTexture=5;
size -= readString(mat->Texture[currTexture].Type); size -= readString(mat->Texture[currTexture].Type, size);
break; break;
case charsToUIntD('B','T','E','X'): case charsToUIntD('B','T','E','X'):
#ifdef LWO_READER_DEBUG #ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading btex."); os::Printer::log("LWO loader: loading btex.");
#endif #endif
currTexture=6; currTexture=6;
size -= readString(mat->Texture[currTexture].Type); size -= readString(mat->Texture[currTexture].Type, size);
break; break;
case charsToUIntD('T','A','L','P'): case charsToUIntD('T','A','L','P'):
#ifdef LWO_READER_DEBUG #ifdef LWO_READER_DEBUG
os::Printer::log("LWO loader: loading alpha map."); os::Printer::log("LWO loader: loading alpha map.");
#endif #endif
size -= readString(mat->Texture[currTexture].AlphaMap); size -= readString(mat->Texture[currTexture].AlphaMap, size);
break; break;
case charsToUIntD('T','F','L','G'): case charsToUIntD('T','F','L','G'):
#ifdef LWO_READER_DEBUG #ifdef LWO_READER_DEBUG
...@@ -1484,7 +1494,7 @@ void CLWOMeshFileLoader::readMat(u32 size) ...@@ -1484,7 +1494,7 @@ void CLWOMeshFileLoader::readMat(u32 size)
subsize=os::Byteswap::byteswap(subsize); subsize=os::Byteswap::byteswap(subsize);
#endif #endif
size -= 6; size -= 6;
size -= readString(ordinal); size -= readString(ordinal, size);
} }
break; break;
case charsToUIntD('C','H','A','N'): case charsToUIntD('C','H','A','N'):
...@@ -1637,11 +1647,13 @@ u32 CLWOMeshFileLoader::readColor(video::SColor& color) ...@@ -1637,11 +1647,13 @@ u32 CLWOMeshFileLoader::readColor(video::SColor& color)
} }
} }
u32 CLWOMeshFileLoader::readString(core::stringc& name) u32 CLWOMeshFileLoader::readString(core::stringc& name, u32 size)
{ {
c8 c; c8 c;
name=""; name="";
if (size)
name.reserve(size);
File->read(&c, 1); File->read(&c, 1);
while (c) while (c)
{ {
......
...@@ -49,7 +49,7 @@ private: ...@@ -49,7 +49,7 @@ private:
void readVertexMapping(u32 size); void readVertexMapping(u32 size);
void readObj2(u32 size); void readObj2(u32 size);
void readMat(u32 size); void readMat(u32 size);
u32 readString(core::stringc& name); u32 readString(core::stringc& name, u32 size=0);
u32 readVec(core::vector3df& vec); u32 readVec(core::vector3df& vec);
u32 readVX(u32& num); u32 readVX(u32& num);
u32 readColor(video::SColor& color); u32 readColor(video::SColor& color);
......
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