diff --git a/include/IMeshCache.h b/include/IMeshCache.h index ff66dc39..33601b72 100644 --- a/include/IMeshCache.h +++ b/include/IMeshCache.h @@ -6,6 +6,7 @@ #define __I_MESH_CACHE_H_INCLUDED__ #include "IUnknown.h" +#include "irrString.h" namespace irr { @@ -28,7 +29,7 @@ namespace scene public: //! destructor - virtual ~IMeshCache() {}; + virtual ~IMeshCache() = 0; //! Adds a mesh to the internal list of loaded meshes. /** Usually, ISceneManager::getMesh() is called to load a mesh from a file. @@ -45,31 +46,31 @@ namespace scene //! Removes a mesh from the cache. /** After loading a mesh with getMesh(), the mesh can be removed from the cache - using this method, freeing a lot of memory. */ - virtual void removeMesh(IAnimatedMesh* mesh) = 0; + using this method, freeing a lot of memory. */ + virtual void removeMesh(const IAnimatedMesh* const mesh) = 0; //! Removes a mesh from the cache. /** After loading a mesh with getMesh(), the mesh can be removed from the cache - using this method, freeing a lot of memory. */ - virtual void removeMesh(IMesh* mesh) = 0; + using this method, freeing a lot of memory. */ + virtual void removeMesh(const IMesh* const mesh) = 0; //! Returns amount of loaded meshes in the cache. /** 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() */ - virtual s32 getMeshCount() = 0; + virtual u32 getMeshCount() const = 0; //! Returns current index number of the mesh, and -1 if it is not in the cache. - virtual s32 getMeshIndex(IAnimatedMesh* mesh) = 0; + virtual s32 getMeshIndex(const IAnimatedMesh* const mesh) const = 0; //! Returns current index number of the mesh, and -1 if it is not in the cache. - virtual s32 getMeshIndex(IMesh* mesh) = 0; + virtual s32 getMeshIndex(const IMesh* const mesh) const = 0; //! Returns a mesh based on its index number. /** \param index: Index of the mesh, number between 0 and getMeshCount()-1. Note that this number is only valid until a new mesh is loaded or removed * \return Returns pointer to the mesh or 0 if there is none with this number. */ - virtual IAnimatedMesh* getMeshByIndex(s32 index) = 0; + virtual IAnimatedMesh* getMeshByIndex(u32 index) = 0; //! Returns a mesh based on its file name. /** \return Returns pointer to the mesh or 0 if there is none with this number. */ @@ -78,33 +79,36 @@ namespace scene //! 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 c8* getMeshFilename(s32 index) = 0; + virtual const c8* getMeshFilename(u32 index) const = 0; //! Returns the filename of a loaded mesh, if there is any. /** Returns 0 if there is none. */ - virtual const c8* getMeshFilename(IAnimatedMesh* mesh) = 0; + virtual const c8* getMeshFilename(const IAnimatedMesh* const mesh) const = 0; //! Returns the filename of a loaded mesh, if there is any. /* Returns 0 if there is none.*/ - virtual const c8* getMeshFilename(IMesh* mesh) = 0; + virtual const c8* getMeshFilename(const IMesh* const mesh) const = 0; //! Renames a loaded mesh, if possible. /** Returns true if sucessful. 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. */ - virtual bool setMeshFilename(s32 index, const c8* filename) = 0; + virtual bool setMeshFilename(u32 index, const c8* filename) = 0; //! Renames a loaded mesh, if possible. /** Returns true if sucessful. 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. */ - virtual bool setMeshFilename(IAnimatedMesh* mesh, const c8* filename) = 0; + virtual bool setMeshFilename(const IAnimatedMesh* const mesh, const c8* filename) = 0; //! Renames a loaded mesh, if possible. /** Returns true if sucessful. 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. */ - virtual bool setMeshFilename(IMesh* mesh, const c8* filename) = 0; + virtual bool setMeshFilename(const IMesh* const mesh, const c8* filename) = 0; + + //! returns if a mesh already was loaded + virtual bool isMeshLoaded(const c8* filename); //! Clears the whole mesh cache, removing all meshes. /** All meshes will be reloaded completely when using ISceneManager::getMesh() diff --git a/source/Irrlicht/CMeshCache.cpp b/source/Irrlicht/CMeshCache.cpp index c90bbe5e..893659d6 100644 --- a/source/Irrlicht/CMeshCache.cpp +++ b/source/Irrlicht/CMeshCache.cpp @@ -33,29 +33,39 @@ void CMeshCache::addMesh(const c8* filename, IAnimatedMesh* mesh) //! Returns amount of loaded meshes -s32 CMeshCache::getMeshCount() +u32 CMeshCache::getMeshCount() const { return Meshes.size(); } //! Returns a mesh based on its index number -IAnimatedMesh* CMeshCache::getMeshByIndex(s32 number) +IAnimatedMesh* CMeshCache::getMeshByIndex(u32 number) { - if (number < 0 || number >= (s32)Meshes.size()) + if (number >= Meshes.size()) return 0; return Meshes[number].Mesh; } +//! Returns a mesh based on its file name. +IAnimatedMesh* CMeshCache::getMeshByFilename(const c8* filename) +{ + MeshEntry e; + e.Name = filename; + e.Name.make_lower(); + s32 id = Meshes.binary_search(e); + return (id != -1) ? Meshes[id].Mesh : 0; +} + //! Returns current number of the mesh -s32 CMeshCache::getMeshIndex(IAnimatedMesh* mesh) +s32 CMeshCache::getMeshIndex(const IAnimatedMesh* const mesh) const { - for (int i=0; i<(int)Meshes.size(); ++i) + for (u32 i=0; igetMesh(0) == mesh) - return i; + return (s32)i; } return -1; @@ -76,9 +86,9 @@ s32 CMeshCache::getMeshIndex(IMesh* mesh) //! Returns name of a mesh based on its index number -const c8* CMeshCache::getMeshFilename(s32 number) +const c8* CMeshCache::getMeshFilename(u32 number) const { - if (number < 0 || number >= (s32)Meshes.size()) + if (number >= Meshes.size()) return 0; return Meshes[number].Name.c_str(); @@ -87,9 +97,9 @@ const c8* CMeshCache::getMeshFilename(s32 number) //! Returns the filename of a loaded mesh, if there is any. Returns 0 if there is none. -const c8* CMeshCache::getMeshFilename(IAnimatedMesh* mesh) +const c8* CMeshCache::getMeshFilename(const IAnimatedMesh* const mesh) const { - for (s32 i=0; i<(s32)Meshes.size(); ++i) + for (u32 i=0; igetMesh(0) == mesh) return Meshes[i].Name.c_str(); @@ -116,27 +126,16 @@ const c8* CMeshCache::getMeshFilename(IMesh* mesh) //! returns if a mesh already was loaded bool CMeshCache::isMeshLoaded(const c8* filename) { - core::stringc name = filename; - name.make_lower(); - return findMesh(name.c_str()) != 0; -} - - -//! returns an already loaded mesh -IAnimatedMesh* CMeshCache::findMesh(const c8* lowerMadeFilename) -{ - MeshEntry e; - e.Name = lowerMadeFilename; - s32 id = Meshes.binary_search(e); - return (id != -1) ? Meshes[id].Mesh : 0; + return getMeshByFilename(filename) != 0; } //! Removes a mesh from the cache. -void CMeshCache::removeMesh(IAnimatedMesh* mesh) +void CMeshCache::removeMesh(const IAnimatedMesh* const mesh) { - if ( mesh ) - for (int i=0; i<(int)Meshes.size(); ++i) + if ( !mesh ) + return; + for (u32 i=0; igetMesh(0) == mesh) { - if (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh) - { - Meshes[i].Mesh->drop(); - Meshes.erase(i); - return; - } + Meshes[i].Mesh->drop(); + Meshes.erase(i); + return; } + } } //! Renames a loaded mesh, if possible. -bool CMeshCache::setMeshFilename(s32 index, const c8* filename) +bool CMeshCache::setMeshFilename(u32 index, const c8* filename) { - if (index < 0 || index >= (s32)Meshes.size()) + if (index >= Meshes.size()) return false; Meshes[index].Name = filename; @@ -177,9 +177,9 @@ bool CMeshCache::setMeshFilename(s32 index, const c8* filename) //! Renames a loaded mesh, if possible. -bool CMeshCache::setMeshFilename(IAnimatedMesh* mesh, const c8* filename) +bool CMeshCache::setMeshFilename(const IAnimatedMesh* const mesh, const c8* filename) { - for (s32 i=0; i<(s32)Meshes.size(); ++i) + for (u32 i=0; igetMesh(0) == mesh) { @@ -218,15 +218,6 @@ void CMeshCache::clear() Meshes.clear(); } -//! Returns a mesh based on its file name. -IAnimatedMesh* CMeshCache::getMeshByFilename(const c8* filename) -{ - core::stringc str = filename; - str.make_lower(); - return findMesh(str.c_str()); -} - } // end namespace scene } // end namespace irr - diff --git a/source/Irrlicht/CMeshCache.h b/source/Irrlicht/CMeshCache.h index dcf7c920..c0e277b7 100644 --- a/source/Irrlicht/CMeshCache.h +++ b/source/Irrlicht/CMeshCache.h @@ -6,7 +6,6 @@ #define __C_MESH_CACHE_H_INCLUDED__ #include "IMeshCache.h" -#include "irrString.h" #include "irrArray.h" namespace irr @@ -35,31 +34,31 @@ namespace scene //! Removes a mesh from the cache. /** After loading a mesh with getMesh(), the mesh can be removed from the cache - using this method, freeing a lot of memory. */ - virtual void removeMesh(IAnimatedMesh* mesh); + using this method, freeing a lot of memory. */ + virtual void removeMesh(const IAnimatedMesh* const mesh); //! Removes a mesh from the cache. /** After loading a mesh with getMesh(), the mesh can be removed from the cache - using this method, freeing a lot of memory. */ - virtual void removeMesh(IMesh* mesh); + using this method, freeing a lot of memory. */ + virtual void removeMesh(const IMesh* const mesh); //! Returns amount of loaded meshes in the cache. /** 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() */ - virtual s32 getMeshCount(); + virtual u32 getMeshCount() const; //! Returns current index number of the mesh, and -1 if it is not in the cache. - virtual s32 getMeshIndex(IAnimatedMesh* mesh); + virtual s32 getMeshIndex(const IAnimatedMesh* const mesh) const; //! Returns current index number of the mesh, and -1 if it is not in the cache. - virtual s32 getMeshIndex(IMesh* mesh); + virtual s32 getMeshIndex(const IMesh* const mesh) const; //! Returns a mesh based on its index number. /** \param index: Index of the mesh, number between 0 and getMeshCount()-1. Note that this number is only valid until a new mesh is loaded or removed * \return Returns pointer to the mesh or 0 if there is none with this number. */ - virtual IAnimatedMesh* getMeshByIndex(s32 index); + virtual IAnimatedMesh* getMeshByIndex(u32 index); //! Returns a mesh based on its file name. /** \return Returns pointer to the mesh or 0 if there is none with this number. */ @@ -68,31 +67,28 @@ namespace scene //! 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 c8* getMeshFilename(s32 index); + virtual const c8* getMeshFilename(u32 index) const; //! Returns the filename of a loaded mesh, if there is any. /** Returns 0 if there is none. */ - virtual const c8* getMeshFilename(IAnimatedMesh* mesh); + virtual const c8* getMeshFilename(const IAnimatedMesh* const mesh) const; //! Returns the filename of a loaded mesh, if there is any. /* Returns 0 if there is none.*/ - virtual const c8* getMeshFilename(IMesh* mesh); + virtual const c8* getMeshFilename(const IMesh* const mesh) const; + + //! Renames a loaded mesh, if possible. + virtual bool setMeshFilename(u32 index, const c8* filename); + + //! Renames a loaded mesh, if possible. + virtual bool setMeshFilename(const IAnimatedMesh* const mesh, const c8* filename); + + //! Renames a loaded mesh, if possible. + virtual bool setMeshFilename(const IMesh* const mesh, const c8* filename); //! returns if a mesh already was loaded virtual bool isMeshLoaded(const c8* filename); - //! returns an already loaded mesh - IAnimatedMesh* findMesh(const c8* lowerMadeFilename); - - //! Renames a loaded mesh, if possible. - virtual bool setMeshFilename(s32 index, const c8* filename); - - //! Renames a loaded mesh, if possible. - virtual bool setMeshFilename(IAnimatedMesh* mesh, const c8* filename); - - //! Renames a loaded mesh, if possible. - virtual bool setMeshFilename(IMesh* mesh, const c8* filename); - //! Clears the whole mesh cache, removing all meshes. virtual void clear(); diff --git a/source/Irrlicht/CSceneManager.cpp b/source/Irrlicht/CSceneManager.cpp index 5ad41af1..51eaa24b 100644 --- a/source/Irrlicht/CSceneManager.cpp +++ b/source/Irrlicht/CSceneManager.cpp @@ -79,7 +79,7 @@ namespace scene //! constructor CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, - gui::ICursorControl* cursorControl, CMeshCache* cache, + gui::ICursorControl* cursorControl, IMeshCache* cache, gui::IGUIEnvironment * gui) : ISceneNode(0, 0), Driver(driver), FileSystem(fs), GUIEnvironment(gui), CursorControl(cursorControl), CollisionManager(0), MeshManipulator(0), @@ -188,10 +188,7 @@ CSceneManager::~CSceneManager() //! gets an animateable mesh. loads it if needed. returned pointer must not be dropped. IAnimatedMesh* CSceneManager::getMesh(const c8* filename) { - core::stringc name = filename; - name.make_lower(); - - IAnimatedMesh* msh = MeshCache->findMesh(name.c_str()); + IAnimatedMesh* msh = MeshCache->getMeshByFilename(filename); if (msh) return msh; @@ -202,6 +199,8 @@ IAnimatedMesh* CSceneManager::getMesh(const c8* filename) return 0; } + core::stringc name = filename; + name.make_lower(); s32 count = MeshLoaderList.size(); for (s32 i=count-1; i>=0; --i) { @@ -679,7 +678,7 @@ IDummyTransformationSceneNode* CSceneManager::addDummyTransformationSceneNode( //! and looks like a plane with some hills on it. It is uses mostly for quick //! tests of the engine only. You can specify how many hills there should be //! on the plane and how high they should be. Also you must specify a name for -//! the mesh, because the mesh is added to the mesh pool, and can be retieved +//! the mesh, because the mesh is added to the mesh pool, and can be retrieved //! again using ISceneManager::getMesh with the name as parameter. IAnimatedMesh* CSceneManager::addHillPlaneMesh(const c8* name, const core::dimension2d& tileSize, const core::dimension2d& tileCount, diff --git a/source/Irrlicht/CSceneManager.h b/source/Irrlicht/CSceneManager.h index 34806201..1eb6b6e1 100644 --- a/source/Irrlicht/CSceneManager.h +++ b/source/Irrlicht/CSceneManager.h @@ -21,7 +21,7 @@ namespace io } namespace scene { - class CMeshCache; + class IMeshCache; /*! The Scene Manager manages scene nodes, mesh recources, cameras and all the other stuff. @@ -32,7 +32,7 @@ namespace scene //! constructor CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, - gui::ICursorControl* cursorControl, CMeshCache* cache = 0, + gui::ICursorControl* cursorControl, IMeshCache* cache = 0, gui::IGUIEnvironment *guiEnvironment = 0); //! destructor @@ -586,7 +586,7 @@ namespace scene io::CAttributes Parameters; //! Mesh cache - CMeshCache* MeshCache; + IMeshCache* MeshCache; E_SCENE_NODE_RENDER_PASS CurrentRendertime;