"...svn:/svn.code.sf.net/p/irrlicht/code/trunk@3615" did not exist on "c9d021cc360fb7902f3f752b3f4133a087c28a83"
Commit 7e91fcb0 authored by cutealien's avatar cutealien

Simplyfy SNamedPath


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3020 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 1f574c60
...@@ -101,21 +101,21 @@ namespace scene ...@@ -101,21 +101,21 @@ namespace scene
/** \deprecated Use getMeshName() instead. */ /** \deprecated Use getMeshName() instead. */
_IRR_DEPRECATED_ const io::path& getMeshFilename(u32 index) const _IRR_DEPRECATED_ const io::path& getMeshFilename(u32 index) const
{ {
return getMeshName(index).getName(); return getMeshName(index).getInternalName();
} }
//! Get the name of a loaded mesh, if there is any. (Name is often identical to the filename). //! Get the name of a loaded mesh, if there is any. (Name is often identical to the filename).
/** \deprecated Use getMeshName() instead. */ /** \deprecated Use getMeshName() instead. */
_IRR_DEPRECATED_ const io::path& getMeshFilename(const IAnimatedMesh* const mesh) const _IRR_DEPRECATED_ const io::path& getMeshFilename(const IAnimatedMesh* const mesh) const
{ {
return getMeshName(mesh).getName(); return getMeshName(mesh).getInternalName();
} }
//! Get the name of a loaded mesh, if there is any. (Name is often identical to the filename). //! Get the name of a loaded mesh, if there is any. (Name is often identical to the filename).
/** \deprecated Use getMeshName() instead. */ /** \deprecated Use getMeshName() instead. */
_IRR_DEPRECATED_ const io::path& getMeshFilename(const IMesh* const mesh) const _IRR_DEPRECATED_ const io::path& getMeshFilename(const IMesh* const mesh) const
{ {
return getMeshName(mesh).getName(); return getMeshName(mesh).getInternalName();
} }
//! Renames a loaded mesh. //! Renames a loaded mesh.
......
...@@ -26,66 +26,45 @@ struct SNamedPath ...@@ -26,66 +26,45 @@ struct SNamedPath
SNamedPath() {} SNamedPath() {}
//! Constructor //! Constructor
SNamedPath(const path& p) : Path(p), Name( PathToName(p) ) SNamedPath(const path& p) : Path(p), InternalName( PathToName(p) )
{ {
} }
//! Is smaller comparator //! Is smaller comparator
bool operator <(const SNamedPath& other) const bool operator <(const SNamedPath& other) const
{ {
return Name < other.Name; return InternalName < other.InternalName;
} }
//! Set the path. As the name depends on the path the name will also be changed. //! Set the path.
void setPath(const path& p) void setPath(const path& p)
{ {
Path = p; Path = p;
Name = PathToName(p); InternalName = PathToName(p);
} }
//! Get the path. This is the original, unprocessed string passed to SNamedPath. //! Get the path.
const path& getPath() const const path& getPath() const
{ {
return Path; 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
{
// Note: memory over speed here because of the typical use-cases.
return PathToName(Path) != Name;
}
//! Get the name which is used to identify the file. //! Get the name which is used to identify the file.
//! This string is similar to the names and filenames used before Irrlicht 1.7 //! This string is similar to the names and filenames used before Irrlicht 1.7
const path& getName() const const path& getInternalName() const
{ {
return Name; return InternalName;
} }
//! Implicit cast to io::path //! Implicit cast to io::path
operator core::stringc() const operator core::stringc() const
{ {
return core::stringc(getSerializationName()); return core::stringc(getPath());
} }
//! Implicit cast to io::path //! Implicit cast to io::path
operator core::stringw() const operator core::stringw() const
{ {
return core::stringw(getSerializationName()); return core::stringw(getPath());
}
//! Returns the string which should be used in serialization.
const path& getSerializationName() const
{
if ( isRenamed() )
return getName();
return Path;
} }
protected: protected:
...@@ -100,7 +79,7 @@ protected: ...@@ -100,7 +79,7 @@ protected:
private: private:
path Path; path Path;
path Name; path InternalName;
}; };
} // io } // io
......
...@@ -770,7 +770,7 @@ void CAnimatedMeshSceneNode::serializeAttributes(io::IAttributes* out, io::SAttr ...@@ -770,7 +770,7 @@ void CAnimatedMeshSceneNode::serializeAttributes(io::IAttributes* out, io::SAttr
{ {
IAnimatedMeshSceneNode::serializeAttributes(out, options); IAnimatedMeshSceneNode::serializeAttributes(out, options);
out->addString("Mesh", SceneManager->getMeshCache()->getMeshName(Mesh).getSerializationName().c_str()); out->addString("Mesh", SceneManager->getMeshCache()->getMeshName(Mesh).getPath().c_str());
out->addBool("Looping", Looping); out->addBool("Looping", Looping);
out->addBool("ReadOnlyMaterials", ReadOnlyMaterials); out->addBool("ReadOnlyMaterials", ReadOnlyMaterials);
out->addFloat("FramesPerSecond", FramesPerSecond); out->addFloat("FramesPerSecond", FramesPerSecond);
...@@ -784,7 +784,7 @@ void CAnimatedMeshSceneNode::deserializeAttributes(io::IAttributes* in, io::SAtt ...@@ -784,7 +784,7 @@ void CAnimatedMeshSceneNode::deserializeAttributes(io::IAttributes* in, io::SAtt
{ {
IAnimatedMeshSceneNode::deserializeAttributes(in, options); IAnimatedMeshSceneNode::deserializeAttributes(in, options);
io::path oldMeshStr = SceneManager->getMeshCache()->getMeshName(Mesh).getSerializationName(); io::path oldMeshStr = SceneManager->getMeshCache()->getMeshName(Mesh).getPath();
io::path newMeshStr = in->getAttributeAsString("Mesh"); io::path newMeshStr = in->getAttributeAsString("Mesh");
Looping = in->getAttributeAsBool("Looping"); Looping = in->getAttributeAsBool("Looping");
......
...@@ -1828,13 +1828,13 @@ public: ...@@ -1828,13 +1828,13 @@ public:
virtual core::stringw getStringW() virtual core::stringw getStringW()
{ {
return core::stringw(Value ? Value->getName().getSerializationName().c_str() : 0); return core::stringw(Value ? Value->getName().getPath().c_str() : 0);
} }
virtual core::stringc getString() virtual core::stringc getString()
{ {
// since texture names can be stringw we are careful with the types // since texture names can be stringw we are careful with the types
return core::stringc(Value ? Value->getName().getSerializationName().c_str() : 0); return core::stringc(Value ? Value->getName().getPath().c_str() : 0);
} }
virtual void setString(const char* text) virtual void setString(const char* text)
......
...@@ -1375,7 +1375,7 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename) ...@@ -1375,7 +1375,7 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename)
else if (t==EGFT_VECTOR) else if (t==EGFT_VECTOR)
{ {
// todo: vector fonts // todo: vector fonts
os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.NamedPath.getName().c_str(), ELL_ERROR); os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.NamedPath.getPath().c_str(), ELL_ERROR);
//CGUIFontVector* font = new CGUIFontVector(Driver); //CGUIFontVector* font = new CGUIFontVector(Driver);
//ifont = (IGUIFont*)font; //ifont = (IGUIFont*)font;
......
...@@ -163,7 +163,7 @@ bool CMeshCache::renameMesh(u32 index, const io::path& name) ...@@ -163,7 +163,7 @@ bool CMeshCache::renameMesh(u32 index, const io::path& name)
if (index >= Meshes.size()) if (index >= Meshes.size())
return false; return false;
Meshes[index].NamedPath.rename(name); Meshes[index].NamedPath.setPath(name);
Meshes.sort(); Meshes.sort();
return true; return true;
} }
...@@ -175,7 +175,7 @@ bool CMeshCache::renameMesh(const IAnimatedMesh* const mesh, const io::path& nam ...@@ -175,7 +175,7 @@ bool CMeshCache::renameMesh(const IAnimatedMesh* const mesh, const io::path& nam
{ {
if (Meshes[i].Mesh == mesh) if (Meshes[i].Mesh == mesh)
{ {
Meshes[i].NamedPath.rename(name); Meshes[i].NamedPath.setPath(name);
Meshes.sort(); Meshes.sort();
return true; return true;
} }
...@@ -191,7 +191,7 @@ bool CMeshCache::renameMesh(const IMesh* const mesh, const io::path& name) ...@@ -191,7 +191,7 @@ bool CMeshCache::renameMesh(const IMesh* const mesh, const io::path& name)
{ {
if (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh) if (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)
{ {
Meshes[i].NamedPath.rename(name); Meshes[i].NamedPath.setPath(name);
Meshes.sort(); Meshes.sort();
return true; return true;
} }
......
...@@ -318,14 +318,14 @@ void CMeshSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeRea ...@@ -318,14 +318,14 @@ void CMeshSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeRea
{ {
IMeshSceneNode::serializeAttributes(out, options); IMeshSceneNode::serializeAttributes(out, options);
out->addString("Mesh", SceneManager->getMeshCache()->getMeshName(Mesh).getSerializationName().c_str()); out->addString("Mesh", SceneManager->getMeshCache()->getMeshName(Mesh).getPath().c_str());
out->addBool("ReadOnlyMaterials", ReadOnlyMaterials); out->addBool("ReadOnlyMaterials", ReadOnlyMaterials);
} }
//! Reads attributes of the scene node. //! Reads attributes of the scene node.
void CMeshSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) void CMeshSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{ {
io::path oldMeshStr = SceneManager->getMeshCache()->getMeshName(Mesh).getSerializationName(); io::path oldMeshStr = SceneManager->getMeshCache()->getMeshName(Mesh).getPath();
io::path newMeshStr = in->getAttributeAsString("Mesh"); io::path newMeshStr = in->getAttributeAsString("Mesh");
ReadOnlyMaterials = in->getAttributeAsBool("ReadOnlyMaterials"); ReadOnlyMaterials = in->getAttributeAsBool("ReadOnlyMaterials");
......
...@@ -351,7 +351,7 @@ void CNullDriver::renameTexture(ITexture* texture, const io::path& newName) ...@@ -351,7 +351,7 @@ void CNullDriver::renameTexture(ITexture* texture, const io::path& newName)
// this method, because the textures will need resorting afterwards // this method, because the textures will need resorting afterwards
io::SNamedPath& name = const_cast<io::SNamedPath&>(texture->getName()); io::SNamedPath& name = const_cast<io::SNamedPath&>(texture->getName());
name.rename(newName); name.setPath(newName);
Textures.sort(); Textures.sort();
} }
......
...@@ -64,7 +64,7 @@ bool COBJMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 fla ...@@ -64,7 +64,7 @@ bool COBJMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 fla
// write OBJ MESH header // write OBJ MESH header
const core::stringc name(FileSystem->getFileBasename(SceneManager->getMeshCache()->getMeshName(mesh).getSerializationName(), false)+".mtl"); const core::stringc name(FileSystem->getFileBasename(SceneManager->getMeshCache()->getMeshName(mesh).getPath(), false)+".mtl");
file->write("# exported by Irrlicht\n",23); file->write("# exported by Irrlicht\n",23);
file->write("mtllib ",7); file->write("mtllib ",7);
file->write(name.c_str(),name.size()); file->write(name.c_str(),name.size());
...@@ -192,7 +192,7 @@ bool COBJMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 fla ...@@ -192,7 +192,7 @@ bool COBJMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 fla
if (mat[i]->getTexture(0)) if (mat[i]->getTexture(0))
{ {
file->write("map_Kd ", 7); file->write("map_Kd ", 7);
file->write(mat[i]->getTexture(0)->getName().getSerializationName().c_str(), mat[i]->getTexture(0)->getName().getSerializationName().size()); file->write(mat[i]->getTexture(0)->getName().getPath().c_str(), mat[i]->getTexture(0)->getName().getPath().size());
file->write("\n",1); file->write("\n",1);
} }
file->write("\n",1); file->write("\n",1);
......
...@@ -284,7 +284,7 @@ bool COctTreeSceneNode::createTree(IMesh* mesh) ...@@ -284,7 +284,7 @@ bool COctTreeSceneNode::createTree(IMesh* mesh)
if (!mesh) if (!mesh)
return false; return false;
MeshName = SceneManager->getMeshCache()->getMeshName( mesh ).getSerializationName(); MeshName = SceneManager->getMeshCache()->getMeshName( mesh ).getPath();
mesh->grab(); mesh->grab();
deleteTree(); deleteTree();
......
...@@ -66,7 +66,7 @@ bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, scene::IMesh* mesh, s ...@@ -66,7 +66,7 @@ bool CSTLMeshWriter::writeMeshBinary(io::IWriteFile* file, scene::IMesh* mesh, s
// write STL MESH header // write STL MESH header
file->write("binary ",7); file->write("binary ",7);
const core::stringc name(SceneManager->getMeshCache()->getMeshName(mesh).getSerializationName()); const core::stringc name(SceneManager->getMeshCache()->getMeshName(mesh).getPath());
const s32 sizeleft = 73-name.size(); // 80 byte header const s32 sizeleft = 73-name.size(); // 80 byte header
if (sizeleft<0) if (sizeleft<0)
file->write(name.c_str(),73); file->write(name.c_str(),73);
...@@ -115,7 +115,7 @@ bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, scene::IMesh* mesh, s3 ...@@ -115,7 +115,7 @@ bool CSTLMeshWriter::writeMeshASCII(io::IWriteFile* file, scene::IMesh* mesh, s3
// write STL MESH header // write STL MESH header
file->write("solid ",6); file->write("solid ",6);
const core::stringc name(SceneManager->getMeshCache()->getMeshName(mesh).getSerializationName()); const core::stringc name(SceneManager->getMeshCache()->getMeshName(mesh).getPath());
file->write(name.c_str(),name.size()); file->write(name.c_str(),name.size());
file->write("\n\n",2); file->write("\n\n",2);
......
...@@ -100,7 +100,7 @@ void CWaterSurfaceSceneNode::serializeAttributes(io::IAttributes* out, io::SAttr ...@@ -100,7 +100,7 @@ void CWaterSurfaceSceneNode::serializeAttributes(io::IAttributes* out, io::SAttr
CMeshSceneNode::serializeAttributes(out, options); CMeshSceneNode::serializeAttributes(out, options);
// serialize original mesh // serialize original mesh
out->setAttribute("Mesh", SceneManager->getMeshCache()->getMeshName(OriginalMesh).getSerializationName().c_str()); out->setAttribute("Mesh", SceneManager->getMeshCache()->getMeshName(OriginalMesh).getPath().c_str());
} }
......
Test suite pass at GMT Sun Dec 6 20:41:05 2009 Test suite pass at GMT Mon Dec 7 22:44:25 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