diff --git a/source/graphics/SkeletonAnimManager.cpp b/source/graphics/SkeletonAnimManager.cpp index f494d08295..7516dc20cb 100644 --- a/source/graphics/SkeletonAnimManager.cpp +++ b/source/graphics/SkeletonAnimManager.cpp @@ -41,7 +41,7 @@ CSkeletonAnimManager::CSkeletonAnimManager(CColladaManager& colladaManager) // CSkeletonAnimManager destructor CSkeletonAnimManager::~CSkeletonAnimManager() { - typedef std::map::iterator Iter; + typedef boost::unordered_map::iterator Iter; for (Iter i = m_Animations.begin(); i != m_Animations.end(); ++i) delete i->second; } @@ -54,7 +54,7 @@ CSkeletonAnimDef* CSkeletonAnimManager::GetAnimation(const VfsPath& pathname) VfsPath name = fs::change_extension(pathname, L""); // Find if it's already been loaded - std::map::iterator iter = m_Animations.find(name); + boost::unordered_map::iterator iter = m_Animations.find(name); if (iter != m_Animations.end()) return iter->second; diff --git a/source/graphics/SkeletonAnimManager.h b/source/graphics/SkeletonAnimManager.h index c6d4c147d5..3100ab5752 100644 --- a/source/graphics/SkeletonAnimManager.h +++ b/source/graphics/SkeletonAnimManager.h @@ -25,6 +25,7 @@ #include #include #include "lib/file/vfs/vfs_path.h" +#include class CColladaManager; class CSkeletonAnimDef; @@ -47,7 +48,7 @@ public: private: // map of all known animations. Value is NULL if it failed to load. - std::map m_Animations; + boost::unordered_map m_Animations; CColladaManager& m_ColladaManager; }; diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index 9d73872d05..cbbd3cbaf3 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -31,42 +31,44 @@ #include "ps/Filesystem.h" #include +#include +#include +#include -// Comparison functor that operates over texture properties, or -// over the properties of a CTexturePtr (ignoring the mutable state like Handle). -struct TextureCacheCmp +struct TPhash + : std::unary_function, + std::unary_function { - bool operator()(const CTexturePtr& a, const CTexturePtr& b) const + std::size_t operator()(CTextureProperties const& a) const + { + std::size_t seed = 0; + boost::hash_combine(seed, a.m_Path.string()); + boost::hash_combine(seed, a.m_Filter); + boost::hash_combine(seed, a.m_Wrap); + boost::hash_combine(seed, a.m_Aniso); + return seed; + } + std::size_t operator()(CTexturePtr const& a) const + { + return (*this)(a->m_Properties); + } +}; +struct TPequal_to + : std::binary_function, + std::binary_function +{ + bool operator()(CTextureProperties const& a, CTextureProperties const& b) const + { + return a.m_Path == b.m_Path && a.m_Filter == b.m_Filter + && a.m_Wrap == b.m_Wrap && a.m_Aniso == b.m_Aniso; + } + bool operator()(CTexturePtr const& a, CTexturePtr const& b) const { return (*this)(a->m_Properties, b->m_Properties); } - - bool operator()(const CTextureProperties& a, const CTextureProperties& b) const - { - if (a.m_Path < b.m_Path) - return true; - if (b.m_Path < a.m_Path) - return false; - - if (a.m_Filter < b.m_Filter) - return true; - if (b.m_Filter < a.m_Filter) - return false; - - if (a.m_Wrap < b.m_Wrap) - return true; - if (b.m_Wrap < a.m_Wrap) - return false; - - if (a.m_Aniso < b.m_Aniso) - return true; - if (b.m_Aniso < a.m_Aniso) - return false; - - return false; - } }; + class CTextureManagerImpl { friend class CTexture; @@ -479,21 +481,20 @@ private: CTexturePtr m_ErrorTexture; // Cache of all loaded textures - typedef std::set TextureCache; + typedef boost::unordered_set TextureCache; TextureCache m_TextureCache; // TODO: we ought to expire unused textures from the cache eventually // Store the set of textures that need to be reloaded when the given file // (a source file or settings.xml) is modified - typedef std::map > > HotloadFilesMap; + typedef boost::unordered_map > > HotloadFilesMap; HotloadFilesMap m_HotloadFiles; // Cache for the conversion settings files - typedef std::map > SettingsFilesMap; + typedef boost::unordered_map > SettingsFilesMap; SettingsFilesMap m_SettingsFiles; }; - CTexture::CTexture(Handle handle, const CTextureProperties& props, CTextureManagerImpl* textureManager) : m_Handle(handle), m_BaseColour(0), m_State(UNLOADED), m_Properties(props), m_TextureManager(textureManager) { diff --git a/source/graphics/TextureManager.h b/source/graphics/TextureManager.h index 8c2a2d5c53..2f8651a18e 100644 --- a/source/graphics/TextureManager.h +++ b/source/graphics/TextureManager.h @@ -121,6 +121,8 @@ class CTextureProperties { friend class CTextureManagerImpl; friend struct TextureCacheCmp; + friend struct TPequal_to; + friend struct TPhash; public: /** @@ -180,6 +182,8 @@ class CTexture { friend class CTextureManagerImpl; friend struct TextureCacheCmp; + friend struct TPequal_to; + friend struct TPhash; // Only the texture manager can create these explicit CTexture(Handle handle, const CTextureProperties& props, CTextureManagerImpl* textureManager); @@ -187,6 +191,7 @@ class CTexture NONCOPYABLE(CTexture); public: + ~CTexture(); /** diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 1cba6a6e4d..fa7f132f5d 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -1035,7 +1035,7 @@ bool CGUI::GetPreDefinedColor(const CStr& name, CColor &Output) /** * @callgraph */ -void CGUI::LoadXmlFile(const VfsPath& Filename, std::set& Paths) +void CGUI::LoadXmlFile(const VfsPath& Filename, boost::unordered_set& Paths) { Paths.insert(Filename); @@ -1092,7 +1092,7 @@ void CGUI::LoadXmlFile(const VfsPath& Filename, std::set& Paths) // XML Reading Xeromyces Specific Sub-Routines //=================================================================== -void CGUI::Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, std::set& Paths) +void CGUI::Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, boost::unordered_set& Paths) { int el_script = pFile->GetElementID("script"); @@ -1182,7 +1182,7 @@ void CGUI::Xeromyces_ReadRootSetup(XMBElement Element, CXeromyces* pFile) } } -void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, const std::vector >& NameSubst, std::set& Paths) +void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, const std::vector >& NameSubst, boost::unordered_set& Paths) { debug_assert(pParent); int i; @@ -1422,7 +1422,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec } } -void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, std::set& Paths) +void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, boost::unordered_set& Paths) { #define ELMT(x) int elmt_##x = pFile->GetElementID(#x) #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x) @@ -1448,7 +1448,7 @@ void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObjec } } -void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, std::set& Paths) +void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set& Paths) { // Check for a 'file' parameter CStrW file (Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("file") ).FromUTF8()); diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index a0467247a9..59cc7e86df 100644 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -47,7 +47,7 @@ CGUI #include "ps/XML/Xeromyces.h" -#include +#include //-------------------------------------------------------- // Macros @@ -182,7 +182,7 @@ public: * @param Filename Name of file * @param Paths Set of paths; all XML and JS files loaded will be added to this */ - void LoadXmlFile(const VfsPath& Filename, std::set& Paths); + void LoadXmlFile(const VfsPath& Filename, boost::unordered_set& Paths); /** * Checks if object exists and return true or false accordingly @@ -387,7 +387,7 @@ private: * * @see LoadXmlFile() */ - void Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, std::set& Paths); + void Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, boost::unordered_set& Paths); /** * Reads in the root element \ (the DOMElement). @@ -446,14 +446,14 @@ private: * * @see LoadXmlFile() */ - void Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, const std::vector >& NameSubst, std::set& Paths); + void Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, const std::vector >& NameSubst, boost::unordered_set& Paths); /** * Reads in the element \, which repeats its child \s * 'count' times, replacing the string "[n]" in its descendants' names * with "[0]", "[1]", etc. */ - void Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, std::set& Paths); + void Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, boost::unordered_set& Paths); /** * Reads in the element \ (the XMBElement) and executes @@ -466,7 +466,7 @@ private: * * @see LoadXmlFile() */ - void Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, std::set& Paths); + void Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set& Paths); /** * Reads in the element \ (the XMBElement) and stores the diff --git a/source/gui/GUIManager.h b/source/gui/GUIManager.h index 4957e621e4..f1c996ece6 100644 --- a/source/gui/GUIManager.h +++ b/source/gui/GUIManager.h @@ -18,6 +18,8 @@ #ifndef INCLUDED_GUIMANAGER #define INCLUDED_GUIMANAGER +#include + #include "lib/input.h" #include "lib/file/vfs/vfs_path.h" #include "ps/CStr.h" @@ -136,7 +138,7 @@ private: struct SGUIPage { CStrW name; - std::set inputs; // for hotloading + boost::unordered_set inputs; // for hotloading JSContext* cx; CScriptValRooted initData; // data to be passed to the init() function diff --git a/source/lib/cache_adt.h b/source/lib/cache_adt.h index 8e37bd0887..0b26fab343 100644 --- a/source/lib/cache_adt.h +++ b/source/lib/cache_adt.h @@ -32,6 +32,7 @@ #include #include #include // std::priority_queue +#include /* Cache for items of variable size and value/"cost". @@ -306,10 +307,7 @@ again: } protected: - // note: hash_map is probably better in terms of locality - // (relevant when iterating over all items in remove_least_valuable), - // but would require a hash comparator for VfsPath. - class Map : public std::map + class Map : public boost::unordered_map { public: static Entry& entry_from_it(typename Map::iterator it) { return it->second; } diff --git a/source/lib/file/vfs/vfs_path.cpp b/source/lib/file/vfs/vfs_path.cpp index 6f02d93afb..bd0b069da3 100644 --- a/source/lib/file/vfs/vfs_path.cpp +++ b/source/lib/file/vfs/vfs_path.cpp @@ -22,3 +22,13 @@ #include "precompiled.h" #include "lib/file/vfs/vfs_path.h" + +#include +#include + +std::size_t hash_value(VfsPath const& b) +{ + boost::hash hasher; + return hasher(b.string()); +} + diff --git a/source/lib/file/vfs/vfs_path.h b/source/lib/file/vfs/vfs_path.h index 494c7660e4..48ab959056 100644 --- a/source/lib/file/vfs/vfs_path.h +++ b/source/lib/file/vfs/vfs_path.h @@ -23,6 +23,8 @@ #ifndef INCLUDED_VFS_PATH #define INCLUDED_VFS_PATH +#include + struct VfsPathTraits; /** @@ -43,6 +45,8 @@ typedef fs::basic_path VfsPath; typedef std::vector VfsPaths; +std::size_t hash_value(VfsPath const& b); + struct VfsPathTraits { typedef std::wstring internal_string_type;