Ticket #695: ro_695_r2.patch

File ro_695_r2.patch, 7.5 KB (added by Rodolphe Ortalo, 13 years ago)

Patch with respect to source/ directory

  • graphics/SkeletonAnimManager.cpp

     
    4141// CSkeletonAnimManager destructor
    4242CSkeletonAnimManager::~CSkeletonAnimManager()
    4343{
    44     typedef std::map<VfsPath,CSkeletonAnimDef*>::iterator Iter;
     44    typedef boost::unordered_map<VfsPath,CSkeletonAnimDef*>::iterator Iter;
    4545    for (Iter i = m_Animations.begin(); i != m_Animations.end(); ++i)
    4646        delete i->second;
    4747}
     
    5454    VfsPath name = fs::change_extension(pathname, L"");
    5555
    5656    // Find if it's already been loaded
    57     std::map<VfsPath, CSkeletonAnimDef*>::iterator iter = m_Animations.find(name);
     57    boost::unordered_map<VfsPath, CSkeletonAnimDef*>::iterator iter = m_Animations.find(name);
    5858    if (iter != m_Animations.end())
    5959        return iter->second;
    6060
  • graphics/TextureManager.h

     
    121121{
    122122    friend class CTextureManagerImpl;
    123123    friend struct TextureCacheCmp;
     124    friend struct TPequal_to;
     125    friend struct TPhash;
    124126
    125127public:
    126128    /**
     
    151153    // easily tweaked in an Options menu? e.g. the caller just specifies
    152154    // "terrain texture mode" and we combine it with the user's options.
    153155    // That'd let us dynamically change texture properties easily.
    154     //
     156    //std::size_t hash_value(const CTexturePtr& a)
    155157    // enum EQualityMode
    156158    // {
    157159    //   NONE,
     
    180182{
    181183    friend class CTextureManagerImpl;
    182184    friend struct TextureCacheCmp;
     185    friend struct TPequal_to;
     186    friend struct TPhash;
    183187
    184188    // Only the texture manager can create these
    185189    explicit CTexture(Handle handle, const CTextureProperties& props, CTextureManagerImpl* textureManager);
     
    187191    NONCOPYABLE(CTexture);
    188192
    189193public:
     194
    190195    ~CTexture();
    191196
    192197    /**
  • graphics/SkeletonAnimManager.h

     
    2525#include <map>
    2626#include <set>
    2727#include "lib/file/vfs/vfs_path.h"
     28#include <boost/unordered_map.hpp>
    2829
    2930class CColladaManager;
    3031class CSkeletonAnimDef;
     
    4748
    4849private:
    4950    // map of all known animations. Value is NULL if it failed to load.
    50     std::map<VfsPath, CSkeletonAnimDef*> m_Animations;
     51    boost::unordered_map<VfsPath, CSkeletonAnimDef*> m_Animations;
    5152
    5253    CColladaManager& m_ColladaManager;
    5354};
  • graphics/TextureManager.cpp

     
    3131#include "ps/Filesystem.h"
    3232
    3333#include <iomanip>
     34#include <boost/unordered_map.hpp>
     35#include <boost/unordered_set.hpp>
     36#include <boost/functional/hash.hpp>
    3437
    35 // Comparison functor that operates over texture properties, or
    36 // over the properties of a CTexturePtr (ignoring the mutable state like Handle).
    37 struct TextureCacheCmp
     38struct TPhash
     39     : std::unary_function<CTextureProperties, std::size_t>,
     40     std::unary_function<CTexturePtr, std::size_t>
    3841{
    39     bool operator()(const CTexturePtr& a, const CTexturePtr& b) const
     42    std::size_t operator()(CTextureProperties const& a) const
    4043    {
    41         return (*this)(a->m_Properties, b->m_Properties);
     44        std::size_t seed = 0;
     45        boost::hash_combine(seed, a.m_Path.string());
     46        boost::hash_combine(seed, a.m_Filter);
     47        boost::hash_combine(seed, a.m_Wrap);
     48        boost::hash_combine(seed, a.m_Aniso);
     49        return seed;
    4250    }
    43 
    44     bool operator()(const CTextureProperties& a, const CTextureProperties& b) const
     51    std::size_t operator()(CTexturePtr const& a) const
    4552    {
    46         if (a.m_Path < b.m_Path)
    47             return true;
    48         if (b.m_Path < a.m_Path)
    49             return false;
    50 
    51         if (a.m_Filter < b.m_Filter)
    52             return true;
    53         if (b.m_Filter < a.m_Filter)
    54             return false;
    55 
    56         if (a.m_Wrap < b.m_Wrap)
    57             return true;
    58         if (b.m_Wrap < a.m_Wrap)
    59             return false;
    60 
    61         if (a.m_Aniso < b.m_Aniso)
    62             return true;
    63         if (b.m_Aniso < a.m_Aniso)
    64             return false;
    65 
    66         return false;
     53        return (*this)(a->m_Properties);
    6754    }
    6855};
     56struct TPequal_to
     57    : std::binary_function<CTextureProperties, CTextureProperties, bool>,
     58    std::binary_function<CTexturePtr, CTexturePtr, bool>
     59{   
     60    bool operator()(CTextureProperties const& a, CTextureProperties const& b) const
     61    {
     62        return a.m_Path == b.m_Path && a.m_Filter == b.m_Filter
     63            && a.m_Wrap == b.m_Wrap && a.m_Aniso == b.m_Aniso;
     64    }
     65    bool operator()(CTexturePtr const& a, CTexturePtr const& b) const
     66    {
     67        return (*this)(a->m_Properties, b->m_Properties);
     68    }
     69};
    6970
     71
    7072class CTextureManagerImpl
    7173{
    7274    friend class CTexture;
     
    479481    CTexturePtr m_ErrorTexture;
    480482
    481483    // Cache of all loaded textures
    482     typedef std::set<CTexturePtr, TextureCacheCmp> TextureCache;
     484    typedef boost::unordered_set<CTexturePtr, TPhash, TPequal_to > TextureCache;
    483485    TextureCache m_TextureCache;
    484486    // TODO: we ought to expire unused textures from the cache eventually
    485487
    486488    // Store the set of textures that need to be reloaded when the given file
    487489    // (a source file or settings.xml) is modified
    488     typedef std::map<VfsPath, std::set<boost::weak_ptr<CTexture> > > HotloadFilesMap;
     490    typedef boost::unordered_map<VfsPath, std::set<boost::weak_ptr<CTexture> > > HotloadFilesMap;
    489491    HotloadFilesMap m_HotloadFiles;
    490492
    491493    // Cache for the conversion settings files
    492     typedef std::map<VfsPath, shared_ptr<CTextureConverter::SettingsFile> > SettingsFilesMap;
     494    typedef boost::unordered_map<VfsPath, shared_ptr<CTextureConverter::SettingsFile> > SettingsFilesMap;
    493495    SettingsFilesMap m_SettingsFiles;
    494496};
    495497
    496 
    497498CTexture::CTexture(Handle handle, const CTextureProperties& props, CTextureManagerImpl* textureManager) :
    498499    m_Handle(handle), m_BaseColour(0), m_State(UNLOADED), m_Properties(props), m_TextureManager(textureManager)
    499500{
  • lib/file/vfs/vfs_path.h

     
    2323#ifndef INCLUDED_VFS_PATH
    2424#define INCLUDED_VFS_PATH
    2525
     26#include <boost/functional/hash.hpp>
     27
    2628struct VfsPathTraits;
    2729
    2830/**
     
    4345
    4446typedef std::vector<VfsPath> VfsPaths;
    4547
     48std::size_t hash_value(VfsPath const& b);
     49
    4650struct VfsPathTraits
    4751{
    4852    typedef std::wstring internal_string_type;
  • lib/file/vfs/vfs_path.cpp

     
    2222
    2323#include "precompiled.h"
    2424#include "lib/file/vfs/vfs_path.h"
     25
     26#include <iostream>
     27#include <string>
     28
     29std::size_t hash_value(VfsPath const& b)
     30{
     31    boost::hash<std::wstring> hasher;
     32    return hasher(b.string());
     33}
     34
  • lib/cache_adt.h

     
    3232#include <list>
    3333#include <map>
    3434#include <queue> // std::priority_queue
     35#include <boost/unordered_map.hpp>
    3536
    3637/*
    3738Cache for items of variable size and value/"cost".
     
    306307    }
    307308
    308309protected:
    309     // note: hash_map is probably better in terms of locality
    310     // (relevant when iterating over all items in remove_least_valuable),
    311     // but would require a hash comparator for VfsPath.
    312     class Map : public std::map<Key, Entry>
     310    class Map : public boost::unordered_map<Key, Entry>
    313311    {
    314312    public:
    315313        static Entry& entry_from_it(typename Map::iterator it) { return it->second; }