Commit 58764ce8 authored by cutealien's avatar cutealien

- Keep filenames additionally to internally used names for meshes, fonts,...

- Keep filenames additionally to internally used names for meshes, fonts, textures and sprites to fix problems with uppercase-filenames on Linux.
- Adapt MeshCache interface to make the difference between names and filenames more clear. Old functions behave the same, but are deprecated.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3004 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 65e7a3bd
Changes in 1.7
- Irrlicht keeps now filenames additionaly to the internally used names, thereby fixing some problems with uppercase-filenames on Linux.
- Bugfix: Mousewheel no longer sends EMIE_MOUSE_WHEEL messages twice on Linux.
- refactoring: E_ATTRIBUTE_TYPE and IAttribute have now own headers
......
......@@ -42,12 +42,12 @@ namespace scene
with one call. They can add additional meshes with this method
to the scene manager. The COLLADA loader for example uses this
method.
\param filename Filename of the mesh. When calling
\param name Name of the mesh. When calling
ISceneManager::getMesh() with this name it will return the mesh
set by this method.
\param mesh Pointer to a mesh which will now be referenced by
this name. */
virtual void addMesh(const io::path& filename, IAnimatedMesh* mesh) = 0;
virtual void addMesh(const io::path& name, IAnimatedMesh* mesh) = 0;
//! Removes a mesh from the cache.
/** After loading a mesh with getMesh(), the mesh can be
......@@ -67,7 +67,7 @@ namespace scene
/** You can load new meshes into the cache using getMesh() and
addMesh(). If you ever need to access the internal mesh cache,
you can do this using removeMesh(), getMeshNumber(),
getMeshByIndex() and getMeshFilename().
getMeshByIndex() and getMeshName().
\return Number of meshes in cache. */
virtual u32 getMeshCount() const = 0;
......@@ -90,60 +90,85 @@ namespace scene
number. */
virtual IAnimatedMesh* getMeshByIndex(u32 index) = 0;
//! Returns a mesh based on its filename.
/** \param filename Name of the mesh.
//! Returns a mesh based on its name (often a filename).
/** \deprecated Use getMeshByName() instead. */
_IRR_DEPRECATED_ virtual IAnimatedMesh* getMeshByFilename(const io::path& filename) = 0;
//! Get the name of a loaded mesh, based on its index. (Name is often identical to the filename).
/** \deprecated Use getMeshName() instead. */
_IRR_DEPRECATED_ virtual const io::path& getMeshFilename(u32 index) const = 0;
//! Get the name of a loaded mesh, if there is any. (Name is often identical to the filename).
/** \deprecated Use getMeshName() instead. */
_IRR_DEPRECATED_ virtual const io::path& getMeshFilename(const IAnimatedMesh* const mesh) const = 0;
//! Get the name of a loaded mesh, if there is any. (Name is often identical to the filename).
/** \deprecated Use getMeshName() instead. */
_IRR_DEPRECATED_ virtual const io::path& getMeshFilename(const IMesh* const mesh) const = 0;
//! Renames a loaded mesh.
/** \deprecated Use renameMesh() instead. */
_IRR_DEPRECATED_ virtual bool setMeshFilename(u32 index, const io::path& filename) = 0;
//! Renames a loaded mesh.
/** \deprecated Use renameMesh() instead. */
_IRR_DEPRECATED_ virtual bool setMeshFilename(const IAnimatedMesh* const mesh, const io::path& filename) = 0;
//! Renames a loaded mesh.
/** \deprecated Use renameMesh() instead. */
_IRR_DEPRECATED_ virtual bool setMeshFilename(const IMesh* const mesh, const io::path& filename) = 0;
//! Returns a mesh based on its name.
/** \param name Name of the mesh. Usually a filename.
\return Pointer to the mesh or 0 if there is none with this number. */
virtual IAnimatedMesh* getMeshByFilename(const io::path& filename) = 0;
virtual IAnimatedMesh* getMeshByName(const io::path& name) = 0;
//! Get the filename of a loaded mesh, based on its index.
//! Get the name of a loaded mesh, based on its index.
/** \param index: Index of the mesh, number between 0 and getMeshCount()-1.
\return String with name if mesh was found and has a name, else
0. */
virtual const io::path& getMeshFilename(u32 index) const = 0;
\return The name if mesh was found and has a name, else the path is empty. */
virtual const io::SNamedPath& getMeshName(u32 index) const = 0;
//! Get the filename of a loaded mesh, if there is any.
//! Get the name of a loaded mesh, if there is any.
/** \param mesh Pointer to mesh to query.
\return String with name if mesh was found and has a name, else
0. */
virtual const io::path& getMeshFilename(const IAnimatedMesh* const mesh) const = 0;
\return The name if mesh was found and has a name, else the path is empty. */
virtual const io::SNamedPath& getMeshName(const IAnimatedMesh* const mesh) const = 0;
//! Get the filename of a loaded mesh, if there is any.
//! Get the name of a loaded mesh, if there is any.
/** \param mesh Pointer to mesh to query.
\return String with name if mesh was found and has a name, else
0. */
virtual const io::path& getMeshFilename(const IMesh* const mesh) const = 0;
\return The name if mesh was found and has a name, else the path is empty. */
virtual const io::SNamedPath& getMeshName(const IMesh* const mesh) const = 0;
//! Renames a loaded mesh.
/** Note that renaming meshes might change the ordering of the
meshes, and so the index of the meshes as returned by
getMeshIndex() or taken by some methods will change.
\param index The index of the mesh in the cache.
\param filename New name for the mesh.
\param name New name for the mesh.
\return True if mesh was renamed. */
virtual bool setMeshFilename(u32 index, const io::path& filename) = 0;
virtual bool renameMesh(u32 index, const io::path& name) = 0;
//! Renames a loaded mesh.
/** Note that renaming meshes might change the ordering of the
meshes, and so the index of the meshes as returned by
getMeshIndex() or taken by some methods will change.
\param mesh Mesh to be renamed.
\param filename New name for the mesh.
\param name New name for the mesh.
\return True if mesh was renamed. */
virtual bool setMeshFilename(const IAnimatedMesh* const mesh, const io::path& filename) = 0;
virtual bool renameMesh(const IAnimatedMesh* const mesh, const io::path& name) = 0;
//! Renames a loaded mesh.
/** Note that renaming meshes might change the ordering of the
meshes, and so the index of the meshes as returned by
getMeshIndex() or taken by some methods will change.
\param mesh Mesh to be renamed.
\param filename New name for the mesh.
\param name New name for the mesh.
\return True if mesh was renamed. */
virtual bool setMeshFilename(const IMesh* const mesh, const io::path& filename) = 0;
virtual bool renameMesh(const IMesh* const mesh, const io::path& name) = 0;
//! Check if a mesh was already loaded.
/** \param filename Name of the mesh.
/** \param name Name of the mesh. Usually a filename.
\return True if the mesh has been loaded, else false. */
virtual bool isMeshLoaded(const io::path& filename) = 0;
virtual bool isMeshLoaded(const io::path& name) = 0;
//! Clears the whole mesh cache, removing all meshes.
/** All meshes will be reloaded completely when using ISceneManager::getMesh()
......
......@@ -85,9 +85,8 @@ class ITexture : public virtual IReferenceCounted
public:
//! constructor
ITexture(const io::path& name) : Name(name)
ITexture(const io::path& name) : NamedPath(name)
{
Name.make_lower();
}
//! Lock function.
......@@ -156,7 +155,7 @@ public:
virtual bool isRenderTarget() const { return false; }
//! Get name of texture (in most cases this is the filename)
const io::path& getName() const { return Name; }
const io::SNamedPath& getName() const { return NamedPath; }
protected:
......@@ -176,7 +175,7 @@ protected:
return ETCF_OPTIMIZED_FOR_SPEED;
}
io::path Name;
io::SNamedPath NamedPath;
};
......
......@@ -16,6 +16,76 @@ namespace io
/** This type will transparently handle different file system encodings. */
typedef core::string<fschar_t> path;
//! Used in places where we identify objects by a filename, but don't actually work with the real filename
/** Irrlicht is internally not case-sensitive when it comes to names.
Also this class is a first step towards support for correctly serializing renamed objects.
*/
struct SNamedPath
{
//! Constructor
SNamedPath() {}
//! Constructor
SNamedPath(const path& p) : Path(p), Name(p)
{
Name.replace( '\\', '/' );
Name.make_lower();
}
//! Is smaller comparator
bool operator <(const SNamedPath& other) const
{
return Name < other.Name;
}
//! Set the path. As the name depends on the path it will also be changed.
void setPath(const path& p)
{
Path = p;
Name = p;
Name.make_lower();
}
//! Get the path
const path& getPath() const
{
return Path;
};
//! Give the file a new name which is used for identification.
void rename(const path& name)
{
Name = name;
};
//! Has the file been given a new name?
bool isRenamed() const
{
return !Path.equals_ignore_case(Name);
}
//! Get the name which is used to identify the file. By default a lower-case version of the filename.
const path& getName() const
{
return Name;
}
//! Returns the name used in serialization
/** When the name wasn't renamed the path is used otherwise the name is used.
TODO: This is a workaround, as both strings should be serialized in the long run.
*/
const path& getSerializationName() const
{
if ( isRenamed() )
return getName();
return Path;
}
private:
path Path;
path Name;
};
} // io
} // irr
......
......@@ -770,7 +770,7 @@ void CAnimatedMeshSceneNode::serializeAttributes(io::IAttributes* out, io::SAttr
{
IAnimatedMeshSceneNode::serializeAttributes(out, options);
out->addString("Mesh", SceneManager->getMeshCache()->getMeshFilename(Mesh).c_str());
out->addString("Mesh", SceneManager->getMeshCache()->getMeshName(Mesh).getSerializationName().c_str());
out->addBool("Looping", Looping);
out->addBool("ReadOnlyMaterials", ReadOnlyMaterials);
out->addFloat("FramesPerSecond", FramesPerSecond);
......@@ -784,7 +784,7 @@ void CAnimatedMeshSceneNode::deserializeAttributes(io::IAttributes* in, io::SAtt
{
IAnimatedMeshSceneNode::deserializeAttributes(in, options);
io::path oldMeshStr = SceneManager->getMeshCache()->getMeshFilename(Mesh);
io::path oldMeshStr = SceneManager->getMeshCache()->getMeshName(Mesh).getSerializationName();
io::path newMeshStr = in->getAttributeAsString("Mesh");
Looping = in->getAttributeAsBool("Looping");
......
......@@ -1828,13 +1828,13 @@ public:
virtual core::stringw getStringW()
{
return core::stringw(Value ? Value->getName().c_str() : 0);
return core::stringw(Value ? Value->getName().getSerializationName().c_str() : 0);
}
virtual core::stringc getString()
{
// since texture names can be stringw we are careful with the types
return core::stringc(Value ? Value->getName().c_str() : 0);
return core::stringc(Value ? Value->getName().getSerializationName().c_str() : 0);
}
virtual void setString(const char* text)
......@@ -1852,7 +1852,7 @@ public:
{
if ( value == Value )
return;
if (Value)
Value->drop();
......
......@@ -172,7 +172,7 @@ void CGUIEnvironment::loadBuiltInFont()
}
SFont f;
f.Filename = filename;
f.NamedPath.setPath(filename);
f.Font = font;
Fonts.push_back(f);
......@@ -1309,8 +1309,7 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename)
// search existing font
SFont f;
f.Filename = filename;
f.Filename.make_lower();
f.NamedPath.setPath(filename);
s32 index = Fonts.binary_search(f);
if (index != -1)
......@@ -1322,7 +1321,7 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename)
if (!FileSystem->existFile(filename))
{
os::Printer::log("Could not load font because the file does not exist", f.Filename, ELL_ERROR);
os::Printer::log("Could not load font because the file does not exist", f.NamedPath.getPath(), ELL_ERROR);
return 0;
}
......@@ -1361,7 +1360,7 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename)
ifont = (IGUIFont*)font;
// change working directory, for loading textures
io::path workingDir = FileSystem->getWorkingDirectory();
FileSystem->changeWorkingDirectoryTo(FileSystem->getFileDir(f.Filename));
FileSystem->changeWorkingDirectoryTo(FileSystem->getFileDir(f.NamedPath.getPath()));
// load the font
if (!font->load(xml))
......@@ -1376,7 +1375,7 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename)
else if (t==EGFT_VECTOR)
{
// todo: vector fonts
os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.Filename.c_str(), ELL_ERROR);
os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.NamedPath.getName().c_str(), ELL_ERROR);
//CGUIFontVector* font = new CGUIFontVector(Driver);
//ifont = (IGUIFont*)font;
......@@ -1389,9 +1388,9 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename)
if (!ifont)
{
CGUIFont* font = new CGUIFont(this, f.Filename );
CGUIFont* font = new CGUIFont(this, f.NamedPath.getPath() );
ifont = (IGUIFont*)font;
if (!font->load(f.Filename))
if (!font->load(f.NamedPath.getPath()))
{
font->drop();
return 0;
......@@ -1413,7 +1412,7 @@ IGUIFont* CGUIEnvironment::addFont(const io::path& name, IGUIFont* font)
if (font)
{
SFont f;
f.Filename = name;
f.NamedPath.setPath(name);
s32 index = Fonts.binary_search(f);
if (index != -1)
return Fonts[index].Font;
......@@ -1440,8 +1439,7 @@ IGUISpriteBank* CGUIEnvironment::getSpriteBank(const io::path& filename)
// search for the file name
SSpriteBank b;
b.Filename = filename;
b.Filename.make_lower();
b.NamedPath.setPath(filename);
s32 index = Banks.binary_search(b);
if (index != -1)
......@@ -1449,9 +1447,9 @@ IGUISpriteBank* CGUIEnvironment::getSpriteBank(const io::path& filename)
// we don't have this sprite bank, we should load it
if (!FileSystem->existFile(b.Filename))
if (!FileSystem->existFile(b.NamedPath.getPath()))
{
os::Printer::log("Could not load sprite bank because the file does not exist", filename, ELL_ERROR);
os::Printer::log("Could not load sprite bank because the file does not exist", b.NamedPath.getPath(), ELL_ERROR);
return 0;
}
......@@ -1466,8 +1464,7 @@ IGUISpriteBank* CGUIEnvironment::addEmptySpriteBank(const io::path& name)
// no duplicate names allowed
SSpriteBank b;
b.Filename = name;
b.Filename.make_lower();
b.NamedPath.setPath(name);
const s32 index = Banks.binary_search(b);
if (index != -1)
......
......@@ -258,23 +258,23 @@ private:
struct SFont
{
io::path Filename;
io::SNamedPath NamedPath;
IGUIFont* Font;
bool operator < (const SFont& other) const
{
return (Filename < other.Filename);
return (NamedPath < other.NamedPath);
}
};
struct SSpriteBank
{
core::stringc Filename;
io::SNamedPath NamedPath;
IGUISpriteBank* Bank;
bool operator < (const SSpriteBank& other) const
{
return (Filename < other.Filename);
return (NamedPath < other.NamedPath);
}
};
......
......@@ -11,7 +11,7 @@ namespace irr
namespace scene
{
static const io::path emptyPath = "";
static const io::SNamedPath emptyNamedPath;
CMeshCache::~CMeshCache()
......@@ -111,78 +111,121 @@ IAnimatedMesh* CMeshCache::getMeshByIndex(u32 number)
//! Returns a mesh based on its file name.
IAnimatedMesh* CMeshCache::getMeshByFilename(const io::path& filename)
{
MeshEntry e ( filename );
s32 id = Meshes.binary_search(e);
return (id != -1) ? Meshes[id].Mesh : 0;
return getMeshByName(filename);
}
//! Returns name of a mesh based on its index number
const io::path& CMeshCache::getMeshFilename(u32 number) const
{
if (number >= Meshes.size())
return emptyPath;
return Meshes[number].Name;
return getMeshName(number).getName();
}
//! Returns the filename of a loaded mesh, if there is any.
const io::path& CMeshCache::getMeshFilename(const IAnimatedMesh* const mesh) const
{
return getMeshName(mesh).getName();
}
//! Returns the filename of a loaded mesh, if there is any. Returns 0 if there is none.
const io::path& CMeshCache::getMeshFilename(const IMesh* const mesh) const
{
return getMeshName(mesh).getName();
}
//! Renames a loaded mesh, if possible.
bool CMeshCache::setMeshFilename(u32 index, const io::path& filename)
{
return renameMesh(index, filename);
}
//! Renames a loaded mesh, if possible.
bool CMeshCache::setMeshFilename(const IAnimatedMesh* const mesh, const io::path& filename)
{
return renameMesh(mesh, filename);
}
//! Renames a loaded mesh, if possible.
bool CMeshCache::setMeshFilename(const IMesh* const mesh, const io::path& filename)
{
return renameMesh(mesh, filename);
}
//! Returns a mesh based on its name.
IAnimatedMesh* CMeshCache::getMeshByName(const io::path& name)
{
MeshEntry e ( name );
s32 id = Meshes.binary_search(e);
return (id != -1) ? Meshes[id].Mesh : 0;
}
//! Get the name of a loaded mesh, based on its index.
const io::SNamedPath& CMeshCache::getMeshName(u32 index) const
{
if (index >= Meshes.size())
return emptyNamedPath;
return Meshes[index].NamedPath;
}
//! Get the name of a loaded mesh, if there is any.
const io::SNamedPath& CMeshCache::getMeshName(const IAnimatedMesh* const mesh) const
{
if(!mesh)
return emptyPath;
return emptyNamedPath;
for (u32 i=0; i<Meshes.size(); ++i)
{
if (Meshes[i].Mesh == mesh)
return Meshes[i].Name;
return Meshes[i].NamedPath;
}
return emptyPath;
return emptyNamedPath;
}
//! Returns the filename of a loaded mesh, if there is any. Returns 0 if there is none.
const io::path& CMeshCache::getMeshFilename(const IMesh* const mesh) const
//! Get the name of a loaded mesh, if there is any.
const io::SNamedPath& CMeshCache::getMeshName(const IMesh* const mesh) const
{
if (!mesh)
return emptyPath;
return emptyNamedPath;
for (u32 i=0; i<Meshes.size(); ++i)
{
// IMesh may actually be an IAnimatedMesh, so do a direct comparison
// as well as getting an IMesh from our stored IAnimatedMeshes
if (Meshes[i].Mesh && (Meshes[i].Mesh == mesh || Meshes[i].Mesh->getMesh(0) == mesh))
return Meshes[i].Name;
return Meshes[i].NamedPath;
}
return emptyPath;
return emptyNamedPath;
}
//! Renames a loaded mesh, if possible.
bool CMeshCache::setMeshFilename(u32 index, const io::path& filename)
//! Renames a loaded mesh.
bool CMeshCache::renameMesh(u32 index, const io::path& name)
{
if (index >= Meshes.size())
return false;
Meshes[index].Name = filename;
Meshes[index].NamedPath.rename(name);
Meshes.sort();
return true;
}
//! Renames a loaded mesh, if possible.
bool CMeshCache::setMeshFilename(const IAnimatedMesh* const mesh, const io::path& filename)
//! Renames a loaded mesh.
bool CMeshCache::renameMesh(const IAnimatedMesh* const mesh, const io::path& name)
{
for (u32 i=0; i<Meshes.size(); ++i)
{
if (Meshes[i].Mesh == mesh)
{
Meshes[i].Name = filename;
Meshes[i].NamedPath.rename(name);
Meshes.sort();
return true;
}
......@@ -191,15 +234,14 @@ bool CMeshCache::setMeshFilename(const IAnimatedMesh* const mesh, const io::path
return false;
}
//! Renames a loaded mesh, if possible.
bool CMeshCache::setMeshFilename(const IMesh* const mesh, const io::path& filename)
//! Renames a loaded mesh.
bool CMeshCache::renameMesh(const IMesh* const mesh, const io::path& name)
{
for (u32 i=0; i<Meshes.size(); ++i)
{
if (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)
{
Meshes[i].Name = filename;
Meshes[i].NamedPath.rename(name);
Meshes.sort();
return true;
}
......@@ -210,9 +252,9 @@ bool CMeshCache::setMeshFilename(const IMesh* const mesh, const io::path& filena
//! returns if a mesh already was loaded
bool CMeshCache::isMeshLoaded(const io::path& filename)
bool CMeshCache::isMeshLoaded(const io::path& name)
{
return getMeshByFilename(filename) != 0;
return getMeshByName(name) != 0;
}
......
......@@ -62,32 +62,79 @@ namespace scene
//! Returns a mesh based on its file name.
/** \return Returns pointer to the mesh or 0 if there is none with this number. */
virtual IAnimatedMesh* getMeshByFilename(const io::path& filename);
_IRR_DEPRECATED_ virtual IAnimatedMesh* getMeshByFilename(const io::path& filename);
//! Returns name of a mesh based on its index number.
/** \param index: Index of the mesh, number between 0 and getMeshCount()-1.
Note that this is only valid until a new mesh is loaded */
virtual const io::path& getMeshFilename(u32 index) const;
_IRR_DEPRECATED_ virtual const io::path& getMeshFilename(u32 index) const;
//! Returns the filename of a loaded mesh, if there is any.
/** Returns an empty path if there is none. */
virtual const io::path& getMeshFilename(const IAnimatedMesh* const mesh) const;
_IRR_DEPRECATED_ virtual const io::path& getMeshFilename(const IAnimatedMesh* const mesh) const;
//! Returns the filename of a loaded mesh, if there is any.
/** Returns an empty path if there is none.*/
virtual const io::path& getMeshFilename(const IMesh* const mesh) const;
_IRR_DEPRECATED_ virtual const io::path& getMeshFilename(const IMesh* const mesh) const;
//! Renames a loaded mesh, if possible.
virtual bool setMeshFilename(u32 index, const io::path& filename);
_IRR_DEPRECATED_ virtual bool setMeshFilename(u32 index, const io::path& filename);
//! Renames a loaded mesh, if possible.
virtual bool setMeshFilename(const IAnimatedMesh* const mesh, const io::path& filename);
_IRR_DEPRECATED_ virtual bool setMeshFilename(const IAnimatedMesh* const mesh, const io::path& filename);
//! Renames a loaded mesh, if possible.
virtual bool setMeshFilename(const IMesh* const mesh, const io::path& filename);
_IRR_DEPRECATED_ virtual bool setMeshFilename(const IMesh* const mesh, const io::path& filename);
//! Returns a mesh based on its name.
/** \param name Name of the mesh. Usually a filename.
\return Pointer to the mesh or 0 if there is none with this number. */
virtual IAnimatedMesh* getMeshByName(const io::path& name);
//! Get the name of a loaded mesh, based on its index.
/** \param index: Index of the mesh, number between 0 and getMeshCount()-1.
\return The name if mesh was found and has a name, else the path is empty. */
virtual const io::SNamedPath& getMeshName(u32 index) const;
//! Get the name of a loaded mesh, if there is any.
/** \param mesh Pointer to mesh to query.
\return The name if mesh was found and has a name, else the path is empty. */
virtual const io::SNamedPath& getMeshName(const IAnimatedMesh* const mesh) const;
//! Get the name of a loaded mesh, if there is any.
/** \param mesh Pointer to mesh to query.
\return The name if mesh was found and has a name, else the path is empty. */
virtual const io::SNamedPath& getMeshName(const IMesh* const mesh) const;
//! Renames a loaded mesh.
/** Note that renaming meshes might change the ordering of the
meshes, and so the index of the meshes as returned by
getMeshIndex() or taken by some methods will change.
\param index The index of the mesh in the cache.
\param name New name for the mesh.
\return True if mesh was renamed. */
virtual bool renameMesh(u32 index, const io::path& name);
//! Renames a loaded mesh.
/** Note that renaming meshes might change the ordering of the
meshes, and so the index of the meshes as returned by
getMeshIndex() or taken by some methods will change.
\param mesh Mesh to be renamed.
\param name New name for the mesh.
\return True if mesh was renamed. */
virtual bool renameMesh(const IAnimatedMesh* const mesh, const io::path& name);
//! Renames a loaded mesh.
/** Note that renaming meshes might change the ordering of the
meshes, and so the index of the meshes as returned by
getMeshIndex() or taken by some methods will change.
\param mesh Mesh to be renamed.
\param name New name for the mesh.
\return True if mesh was renamed. */
virtual bool renameMesh(const IMesh* const mesh, const io::path& name);
//! returns if a mesh already was loaded
virtual bool isMeshLoaded(const io::path& filename);
virtual bool isMeshLoaded(const io::path& name);
//! Clears the whole mesh cache, removing all meshes.
virtual void clear();
......@@ -99,17 +146,16 @@ namespace scene
struct MeshEntry
{
MeshEntry ( const io::path name )
: Name ( name )
MeshEntry ( const io::path& name )
: NamedPath ( name )
{
Name.make_lower ();
}
io::path Name;
io::SNamedPath NamedPath;
IAnimatedMesh* Mesh;
bool operator < (const MeshEntry& other) const
{
return (Name < other.Name);
return (NamedPath < other.NamedPath);
}
};
......
......@@ -318,14 +318,14 @@ void CMeshSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeRea
{
IMeshSceneNode::serializeAttributes(out, options);
out->addString("Mesh", SceneManager->getMeshCache()->getMeshFilename(Mesh).c_str());
out->addString("Mesh", SceneManager->getMeshCache()->getMeshName(Mesh).getSerializationName().c_str());
out->addBool("ReadOnlyMaterials", ReadOnlyMaterials);
}
//! Reads attributes of the scene node.
void CMeshSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
io::path oldMeshStr = SceneManager->getMeshCache()->getMeshFilename(Mesh);
io::path oldMeshStr = SceneManager->getMeshCache()->getMeshName(Mesh).getSerializationName();
io::path newMeshStr = in->getAttributeAsString("Mesh");
ReadOnlyMaterials = in->getAttributeAsBool("ReadOnlyMaterials");
......
......@@ -350,8 +350,8 @@ void CNullDriver::renameTexture(ITexture* texture, const io::path& newName)
// is just readonly to prevent the user changing the texture name without invoking
// this method, because the textures will need resorting afterwards
io::path& name = const_cast<io::path&>(texture->getName());
name = newName;
io::SNamedPath& name = const_cast<io::SNamedPath&>(texture->getName());
name.rename(newName);
Textures.sort();
}
......
......@@ -2,7 +2,7 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_OBJ_WRITER_
......@@ -64,14 +64,14 @@ bool COBJMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 fla
// write OBJ MESH header
const core::stringc name(FileSystem->getFileBasename(SceneManager->getMeshCache()->getMeshFilename(mesh), false)+".mtl");
const core::stringc name(FileSystem->getFileBasename(SceneManager->getMeshCache()->getMeshName(mesh).getSerializationName(), false)+".mtl");
file->write("# exported by Irrlicht\n",23);
file->write("mtllib ",7);
file->write(name.c_str(),name.size());
file->write("\n\n",2);
// write mesh buffers
core::array<video::SMaterial*> mat;
u32 allVertexCount=1; // count vertices over the whole file
......@@ -192,7 +192,7 @@ bool COBJMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 fla
if (mat[i]->getTexture(0))
{
file->write("map_Kd ", 7);
file->write(mat[i]->getTexture(0)->getName().c_str(), mat[i]->getTexture(0)->getName().size());
file->write(mat[i]->getTexture(0)->getName().getSerializationName().c_str(), mat[i]->getTexture(0)->getName().getSerializationName().size());
file->write("\n",1);
}
file->write("\n",1);
......
......@@ -284,7 +284,7 @@ bool COctTreeSceneNode::createTree(IMesh* mesh)
if (!mesh)
return false;
MeshName = SceneManager->getMeshCache()->getMeshFilename( mesh );
MeshName = SceneManager->getMeshCache()->getMeshName( mesh ).getSerializationName();
mesh->grab();
deleteTree();
......
......@@ -2,7 +2,7 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_STL_WRITER_
......@@ -66,7 +66,7 @@ bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, scene::IMesh* mesh, s
// write STL MESH header
file->write("binary ",7);
const core::stringc name(SceneManager->getMeshCache()->getMeshFilename(mesh));
const core::stringc name(SceneManager->getMeshCache()->getMeshName(mesh).getSerializationName());
const s32 sizeleft = 73-name.size(); // 80 byte header
if (sizeleft<0)
file->write(name.c_str(),73);
......@@ -115,12 +115,12 @@ bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, scene::IMesh* mesh, s3
// write STL MESH header
file->write("solid ",6);
const core::stringc name(SceneManager->getMeshCache()->getMeshFilename(mesh));
const core::stringc name(SceneManager->getMeshCache()->getMeshName(mesh).getSerializationName());
file->write(name.c_str(),name.size());
file->write("\n\n",2);
// write mesh buffers
for (u32 i=0; i<mesh->getMeshBufferCount(); ++i)
{
IMeshBuffer* buffer = mesh->getMeshBuffer(i);
......
......@@ -340,7 +340,7 @@ CSceneManager::~CSceneManager()
//! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
IAnimatedMesh* CSceneManager::getMesh(const io::path& filename)
{
IAnimatedMesh* msh = MeshCache->getMeshByFilename(filename);
IAnimatedMesh* msh = MeshCache->getMeshByName(filename);
if (msh)
return msh;
......@@ -386,11 +386,10 @@ IAnimatedMesh* CSceneManager::getMesh(io::IReadFile* file)
return 0;
io::path name = file->getFileName();
IAnimatedMesh* msh = MeshCache->getMeshByFilename(file->getFileName());
IAnimatedMesh* msh = MeshCache->getMeshByName(file->getFileName());
if (msh)
return msh;
name.make_lower();
s32 count = MeshLoaderList.size();
for (s32 i=count-1; i>=0; --i)
{
......@@ -921,7 +920,7 @@ IAnimatedMesh* CSceneManager::addHillPlaneMesh(const io::path& name,
const core::dimension2d<f32>& textureRepeatCount)
{
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByFilename(name);
return MeshCache->getMeshByName(name);
IMesh* mesh = GeometryCreator->createHillPlaneMesh(tileSize,
tileCount, material, hillHeight, countHills,
......@@ -955,7 +954,7 @@ IAnimatedMesh* CSceneManager::addTerrainMesh(const io::path& name,
const core::dimension2d<u32>& defaultVertexBlockSize)
{
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByFilename(name);
return MeshCache->getMeshByName(name);
IMesh* mesh = GeometryCreator->createTerrainMesh(texture, heightmap,
stretchSize, maxHeight, getVideoDriver(),
......@@ -988,7 +987,7 @@ IAnimatedMesh* CSceneManager::addArrowMesh(const io::path& name,
f32 cylinderHeight, f32 width0,f32 width1)
{
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByFilename(name);
return MeshCache->getMeshByName(name);
IMesh* mesh = GeometryCreator->createArrowMesh( tesselationCylinder,
tesselationCone, height, cylinderHeight, width0,width1,
......@@ -1019,7 +1018,7 @@ IAnimatedMesh* CSceneManager::addSphereMesh(const io::path& name,
f32 radius, u32 polyCountX, u32 polyCountY)
{
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByFilename(name);
return MeshCache->getMeshByName(name);
IMesh* mesh = GeometryCreator->createSphereMesh(radius, polyCountX, polyCountY);
if (!mesh)
......@@ -1050,7 +1049,7 @@ IAnimatedMesh* CSceneManager::addVolumeLightMesh(const io::path& name,
const video::SColor FootColor, const video::SColor TailColor)
{
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByFilename(name);
return MeshCache->getMeshByName(name);
IMesh* mesh = GeometryCreator->createVolumeLightMesh(SubdivideU, SubdivideV, FootColor, TailColor);
if (!mesh)
......
......@@ -100,7 +100,7 @@ void CWaterSurfaceSceneNode::serializeAttributes(io::IAttributes* out, io::SAttr
CMeshSceneNode::serializeAttributes(out, options);
// serialize original mesh
out->setAttribute("Mesh", SceneManager->getMeshCache()->getMeshFilename(OriginalMesh).c_str());
out->setAttribute("Mesh", SceneManager->getMeshCache()->getMeshName(OriginalMesh).getSerializationName().c_str());
}
......
Test suite pass at GMT Sat Dec 05 11:31:52 2009
Test suite pass at GMT Sun Dec 6 04:47:00 2009
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