Replace boost::unordered_map, boost::unordered_set with std::unordered_map, std::unordered_set to establish consistency.

Replace boost::hash_combine with a lib/hash.h hash_combine performing
the same statement.
Replace inconspicuous global boost hash_value specializations with
std::hash specializations.
No performance difference was observed in three simple MeshManager
measurements.

Remove unused TAG_MASK and h_tag in h_mgr.cpp following 0748c5a75e.
Replace typedef with using keyword and sort header includes.

Differential Revision: https://code.wildfiregames.com/D2441
Tested on: clang  9.0.0, gcc 9.2.0, Jenkins/vs2015, Jenkins/gcc6

This was SVN commit r23191.
This commit is contained in:
elexis 2019-11-25 14:30:25 +00:00
parent acbfd21992
commit 5d2c20beb0
33 changed files with 295 additions and 270 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -18,10 +18,11 @@
#ifndef INCLUDED_FONTMANAGER
#define INCLUDED_FONTMANAGER
#include <boost/unordered_map.hpp>
#include "ps/CStrIntern.h"
#include <unordered_map>
class CFont;
class CStrIntern;
/**
* Font manager: loads and caches bitmap fonts.
@ -34,7 +35,7 @@ public:
private:
bool ReadFont(CFont* font, CStrIntern fontName);
typedef boost::unordered_map<CStrIntern, shared_ptr<CFont> > FontsMap;
using FontsMap = std::unordered_map<CStrIntern, shared_ptr<CFont> >;
FontsMap m_Fonts;
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -20,11 +20,11 @@
#include "lib/file/vfs/vfs_path.h"
#include <boost/unordered_map.hpp>
#include <memory>
#include <unordered_map>
class CModelDef;
typedef std::shared_ptr<CModelDef> CModelDefPtr;
using CModelDefPtr = std::shared_ptr<CModelDef>;
class CColladaManager;
@ -38,7 +38,7 @@ public:
CModelDefPtr GetMesh(const VfsPath& pathname);
private:
typedef boost::unordered_map<VfsPath, std::weak_ptr<CModelDef> > mesh_map;
using mesh_map = std::unordered_map<VfsPath, std::weak_ptr<CModelDef> >;
mesh_map m_MeshMap;
CColladaManager& m_ColladaManager;
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -18,27 +18,26 @@
#ifndef INCLUDED_OBJECTBASE
#define INCLUDED_OBJECTBASE
class CModel;
class CSkeletonAnim;
class CObjectManager;
class CXeromyces;
class XMBElement;
#include <vector>
#include <set>
#include <map>
#include <boost/unordered_set.hpp>
#include "lib/file/vfs/vfs_path.h"
#include "ps/CStr.h"
#include "ps/CStrIntern.h"
class CModel;
class CObjectManager;
class CSkeletonAnim;
class CXeromyces;
class XMBElement;
#include <boost/random/mersenne_twister.hpp>
#include <map>
#include <set>
#include <unordered_set>
#include <vector>
class CObjectBase
{
NONCOPYABLE(CObjectBase);
public:
struct Anim
{
// constructor
@ -184,14 +183,14 @@ private:
// A low-quality RNG like rand48 causes visible non-random patterns (particularly
// in large grids of the same actor with consecutive seeds, e.g. forests),
// so use a better one that appears to avoid those patterns
typedef boost::mt19937 rng_t;
using rng_t = boost::mt19937;
std::set<CStr> CalculateRandomRemainingSelections(rng_t& rng, const std::vector<std::set<CStr> >& initialSelections);
std::vector< std::vector<Variant> > m_VariantGroups;
CObjectManager& m_ObjectManager;
boost::unordered_set<VfsPath> m_UsedFiles;
std::unordered_set<VfsPath> m_UsedFiles;
void LoadVariant(const CXeromyces& XeroFile, const XMBElement& variant, Variant& currentVariant);
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -23,6 +23,8 @@
#include "ps/Profile.h"
#include "renderer/Scene.h"
#include <unordered_map>
static Status ReloadChangedFileCB(void* param, const VfsPath& path)
{
return static_cast<CParticleManager*>(param)->ReloadChangedFile(path);
@ -41,7 +43,7 @@ CParticleManager::~CParticleManager()
CParticleEmitterTypePtr CParticleManager::LoadEmitterType(const VfsPath& path)
{
boost::unordered_map<VfsPath, CParticleEmitterTypePtr>::iterator it = m_EmitterTypes.find(path);
std::unordered_map<VfsPath, CParticleEmitterTypePtr>::iterator it = m_EmitterTypes.find(path);
if (it != m_EmitterTypes.end())
return it->second;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -22,7 +22,7 @@
#include "graphics/ParticleEmitterType.h"
#include <boost/random/mersenne_twister.hpp>
#include <boost/unordered_map.hpp>
#include <unordered_map>
class SceneCollector;
@ -61,7 +61,7 @@ private:
std::list<CParticleEmitterPtr> m_UnattachedEmitters;
boost::unordered_map<VfsPath, CParticleEmitterTypePtr> m_EmitterTypes;
std::unordered_map<VfsPath, CParticleEmitterTypePtr> m_EmitterTypes;
};
#endif // INCLUDED_PARTICLEMANAGER

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -20,29 +20,27 @@
#include "ShaderDefines.h"
#include "graphics/ShaderProgram.h"
#include "lib/hash.h"
#include "maths/Vector4D.h"
#include "ps/ThreadUtil.h"
#include <sstream>
size_t hash_value(const CVector4D& v)
namespace std
{
size_t hash = 0;
boost::hash_combine(hash, v.X);
boost::hash_combine(hash, v.Y);
boost::hash_combine(hash, v.Z);
boost::hash_combine(hash, v.W);
return hash;
}
size_t hash_value(const CShaderParams<CStrIntern>::SItems& items)
template<>
struct hash<CVector4D>
{
return items.hash;
}
size_t hash_value(const CShaderParams<CVector4D>::SItems& items)
{
return items.hash;
std::size_t operator()(const CVector4D& v) const
{
size_t hash = 0;
hash_combine(hash, v.X);
hash_combine(hash, v.Y);
hash_combine(hash, v.Z);
hash_combine(hash, v.W);
return hash;
}
};
}
bool operator==(const CShaderParams<CStrIntern>::SItems& a, const CShaderParams<CStrIntern>::SItems& b)
@ -180,8 +178,8 @@ void CShaderParams<value_t>::SItems::RecalcHash()
size_t h = 0;
for (size_t i = 0; i < items.size(); ++i)
{
boost::hash_combine(h, items[i].first);
boost::hash_combine(h, items[i].second);
hash_combine(h, items[i].first);
hash_combine(h, items[i].second);
}
hash = h;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -22,8 +22,8 @@
#include "ps/CStr.h"
#include "ps/CStrIntern.h"
#include <boost/unordered_map.hpp>
#include <map>
#include <unordered_map>
class CVector4D;
@ -96,7 +96,7 @@ public:
struct SItems
{
// Name/value pair
typedef std::pair<CStrIntern, value_t> Item;
using Item = std::pair<CStrIntern, value_t>;
// Sorted by name; no duplicated names
std::vector<Item> items;
@ -106,11 +106,19 @@ public:
void RecalcHash();
};
struct SItemsHash
{
std::size_t operator()(const SItems& items) const
{
return items.hash;
}
};
protected:
SItems* m_Items; // interned value
private:
typedef boost::unordered_map<SItems, shared_ptr<SItems> > InternedItems_t;
using InternedItems_t = std::unordered_map<SItems, shared_ptr<SItems>, SItemsHash >;
static InternedItems_t s_InternedItems;
/**
@ -188,7 +196,7 @@ enum RENDER_QUERIES
class CShaderRenderQueries
{
public:
typedef std::pair<int, CStrIntern> RenderQuery;
using RenderQuery = std::pair<int, CStrIntern>;
void Add(const char* name);
size_t GetSize() const { return m_Items.size(); }

View File

@ -21,6 +21,7 @@
#include "graphics/ShaderTechnique.h"
#include "lib/config2.h"
#include "lib/hash.h"
#include "lib/timer.h"
#include "lib/utf8.h"
#include "ps/CLogger.h"
@ -335,9 +336,9 @@ static GLenum ParseBlendFunc(const CStr& str)
size_t CShaderManager::EffectCacheKeyHash::operator()(const EffectCacheKey& key) const
{
size_t hash = 0;
boost::hash_combine(hash, key.name.GetHash());
boost::hash_combine(hash, key.defines1.GetHash());
boost::hash_combine(hash, key.defines2.GetHash());
hash_combine(hash, key.name.GetHash());
hash_combine(hash, key.defines1.GetHash());
hash_combine(hash, key.defines2.GetHash());
return hash;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -20,10 +20,6 @@
#define USE_SHADER_XML_VALIDATION 1
#include <boost/unordered_map.hpp>
#include <memory>
#include <set>
#include "graphics/ShaderDefines.h"
#include "graphics/ShaderProgram.h"
#include "graphics/ShaderTechnique.h"
@ -32,6 +28,9 @@
# include "ps/XML/RelaxNG.h"
#endif
#include <unordered_map>
#include <memory>
#include <set>
/**
* Shader manager: loads and caches shader programs.
@ -114,11 +113,11 @@ private:
size_t operator()(const EffectCacheKey& key) const;
};
typedef boost::unordered_map<EffectCacheKey, CShaderTechniquePtr, EffectCacheKeyHash> EffectCacheMap;
using EffectCacheMap = std::unordered_map<EffectCacheKey, CShaderTechniquePtr, EffectCacheKeyHash>;
EffectCacheMap m_EffectCache;
// Store the set of shaders that need to be reloaded when the given file is modified
typedef boost::unordered_map<VfsPath, std::set<std::weak_ptr<CShaderProgram>, std::owner_less<std::weak_ptr<CShaderProgram>>>> HotloadFilesMap;
using HotloadFilesMap = std::unordered_map<VfsPath, std::set<std::weak_ptr<CShaderProgram>, std::owner_less<std::weak_ptr<CShaderProgram> > > >;
HotloadFilesMap m_HotloadFiles;
bool NewProgram(const char* name, const CShaderDefines& defines, CShaderProgramPtr& program);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -29,6 +29,7 @@
#include "ps/CLogger.h"
#include "ps/FileIo.h"
#include <unordered_map>
///////////////////////////////////////////////////////////////////////////////
// CSkeletonAnimManager constructor
@ -41,7 +42,7 @@ CSkeletonAnimManager::CSkeletonAnimManager(CColladaManager& colladaManager)
// CSkeletonAnimManager destructor
CSkeletonAnimManager::~CSkeletonAnimManager()
{
typedef boost::unordered_map<VfsPath,CSkeletonAnimDef*>::iterator Iter;
using Iter = std::unordered_map<VfsPath,CSkeletonAnimDef*>::iterator;
for (Iter i = m_Animations.begin(); i != m_Animations.end(); ++i)
delete i->second;
}
@ -54,7 +55,7 @@ CSkeletonAnimDef* CSkeletonAnimManager::GetAnimation(const VfsPath& pathname)
VfsPath name = pathname.ChangeExtension(L"");
// Find if it's already been loaded
boost::unordered_map<VfsPath, CSkeletonAnimDef*>::iterator iter = m_Animations.find(name);
std::unordered_map<VfsPath, CSkeletonAnimDef*>::iterator iter = m_Animations.find(name);
if (iter != m_Animations.end())
return iter->second;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -22,10 +22,11 @@
#ifndef INCLUDED_SKELETONANIMMANAGER
#define INCLUDED_SKELETONANIMMANAGER
#include "lib/file/vfs/vfs_path.h"
#include <map>
#include <set>
#include "lib/file/vfs/vfs_path.h"
#include <boost/unordered_map.hpp>
#include <unordered_map>
class CColladaManager;
class CSkeletonAnimDef;
@ -48,7 +49,7 @@ public:
private:
// map of all known animations. Value is NULL if it failed to load.
boost::unordered_map<VfsPath, CSkeletonAnimDef*> m_Animations;
std::unordered_map<VfsPath, CSkeletonAnimDef*> m_Animations;
CColladaManager& m_ColladaManager;
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -19,16 +19,12 @@
#include "TextureManager.h"
#include <boost/functional/hash.hpp>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include <iomanip>
#include "graphics/TextureConverter.h"
#include "lib/allocators/shared_ptr.h"
#include "lib/res/h_mgr.h"
#include "lib/file/vfs/vfs_tree.h"
#include "lib/hash.h"
#include "lib/res/graphics/ogl_tex.h"
#include "lib/res/h_mgr.h"
#include "lib/timer.h"
#include "maths/MD5.h"
#include "ps/CacheLoader.h"
@ -36,25 +32,31 @@
#include "ps/Filesystem.h"
#include "ps/Profile.h"
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
struct TPhash
: std::unary_function<CTextureProperties, std::size_t>,
std::unary_function<CTexturePtr, std::size_t>
{
std::size_t operator()(CTextureProperties const& a) const
{
std::size_t seed = 0;
boost::hash_combine(seed, a.m_Path);
boost::hash_combine(seed, a.m_Filter);
boost::hash_combine(seed, a.m_WrapS);
boost::hash_combine(seed, a.m_WrapT);
boost::hash_combine(seed, a.m_Aniso);
boost::hash_combine(seed, a.m_Format);
hash_combine(seed, m_PathHash(a.m_Path));
hash_combine(seed, a.m_Filter);
hash_combine(seed, a.m_WrapS);
hash_combine(seed, a.m_WrapT);
hash_combine(seed, a.m_Aniso);
hash_combine(seed, a.m_Format);
return seed;
}
std::size_t operator()(CTexturePtr const& a) const
{
return (*this)(a->m_Properties);
}
private:
std::hash<Path> m_PathHash;
};
struct TPequal_to
@ -73,17 +75,6 @@ struct TPequal_to
}
};
std::size_t hash_value(const CTexturePtr& v)
{
TPhash h;
return h(v);
}
std::size_t hash_value(const CTextureProperties& v)
{
TPhash h;
return h(v);
}
class CTextureManagerImpl
{
friend class CTexture;
@ -516,17 +507,20 @@ private:
CTexturePtr m_ErrorTexture;
// Cache of all loaded textures
typedef boost::unordered_set<CTexturePtr, TPhash, TPequal_to> TextureCache;
using TextureCache =
std::unordered_set<CTexturePtr, TPhash, TPequal_to>;
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 boost::unordered_map<VfsPath, std::set<std::weak_ptr<CTexture>, std::owner_less<std::weak_ptr<CTexture>>>> HotloadFilesMap;
using HotloadFilesMap =
std::unordered_map<VfsPath, std::set<std::weak_ptr<CTexture>, std::owner_less<std::weak_ptr<CTexture> > > >;
HotloadFilesMap m_HotloadFiles;
// Cache for the conversion settings files
typedef boost::unordered_map<VfsPath, shared_ptr<CTextureConverter::SettingsFile> > SettingsFilesMap;
using SettingsFilesMap =
std::unordered_map<VfsPath, shared_ptr<CTextureConverter::SettingsFile> >;
SettingsFilesMap m_SettingsFiles;
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -18,14 +18,13 @@
#ifndef INCLUDED_TEXTUREMANAGER
#define INCLUDED_TEXTUREMANAGER
#include "Texture.h"
#include "graphics/Texture.h"
#include "lib/file/vfs/vfs.h"
#include "lib/ogl.h"
#include "lib/res/handle.h"
#include <memory>
#include "lib/ogl.h"
#include "lib/file/vfs/vfs.h"
#include "lib/res/handle.h"
class CTextureProperties;
class CTextureManagerImpl;
@ -312,7 +311,4 @@ private:
std::weak_ptr<CTexture> m_Self;
};
std::size_t hash_value(const CTexturePtr& v);
std::size_t hash_value(const CTextureProperties& v);
#endif // INCLUDED_TEXTUREMANAGER

View File

@ -40,6 +40,7 @@
#include "scriptinterface/ScriptInterface.h"
#include <string>
#include <unordered_set>
extern int g_yres;
@ -437,7 +438,7 @@ const SGUIScrollBarStyle* CGUI::GetScrollBarStyle(const CStr& style) const
/**
* @callgraph
*/
void CGUI::LoadXmlFile(const VfsPath& Filename, boost::unordered_set<VfsPath>& Paths)
void CGUI::LoadXmlFile(const VfsPath& Filename, std::unordered_set<VfsPath>& Paths)
{
Paths.insert(Filename);
@ -474,7 +475,7 @@ void CGUI::LoadedXmlFiles()
// XML Reading Xeromyces Specific Sub-Routines
//===================================================================
void CGUI::Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths)
void CGUI::Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, std::unordered_set<VfsPath>& Paths)
{
int el_script = pFile->GetElementID("script");
@ -524,7 +525,7 @@ void CGUI::Xeromyces_ReadRootSetup(XMBElement Element, CXeromyces* pFile)
}
}
void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, std::unordered_set<VfsPath>& Paths, u32 nesting_depth)
{
ENSURE(pParent);
@ -822,7 +823,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
delete object;
}
void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, std::unordered_set<VfsPath>& Paths, u32 nesting_depth)
{
#define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
#define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
@ -850,7 +851,7 @@ void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObjec
}
}
void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths)
void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, std::unordered_set<VfsPath>& Paths)
{
// Check for a 'file' parameter
CStrW file(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("file")).FromUTF8());

View File

@ -33,8 +33,8 @@
#include "ps/XML/Xeromyces.h"
#include "scriptinterface/ScriptInterface.h"
#include <boost/unordered_set.hpp>
#include <map>
#include <unordered_set>
#include <vector>
extern const double SELECT_DBLCLICK_RATE;
@ -120,7 +120,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, boost::unordered_set<VfsPath>& Paths);
void LoadXmlFile(const VfsPath& Filename, std::unordered_set<VfsPath>& Paths);
/**
* Called after all XML files linked in the page file were loaded.
@ -346,7 +346,7 @@ private:
*
* @see LoadXmlFile()
*/
void Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths);
void Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, std::unordered_set<VfsPath>& Paths);
/**
* Reads in the root element \<sprites\> (the DOMElement).
@ -405,7 +405,7 @@ private:
*
* @see LoadXmlFile()
*/
void Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth);
void Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, std::unordered_set<VfsPath>& Paths, u32 nesting_depth);
/**
* Reads in the element \<repeat\>, which repeats its child \<object\>s
@ -413,7 +413,7 @@ private:
* 'var' enclosed in square brackets) in its descendants' names with "[0]",
* "[1]", etc.
*/
void Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth);
void Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, std::unordered_set<VfsPath>& Paths, u32 nesting_depth);
/**
* Reads in the element \<script\> (the XMBElement) and executes
@ -426,7 +426,7 @@ private:
*
* @see LoadXmlFile()
*/
void Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths);
void Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, std::unordered_set<VfsPath>& Paths);
/**
* Reads in the element \<sprite\> (the XMBElement) and stores the

View File

@ -24,9 +24,9 @@
#include "ps/TemplateLoader.h"
#include "scriptinterface/ScriptInterface.h"
#include <boost/unordered_set.hpp>
#include <string>
#include <set>
#include <string>
#include <unordered_set>
class CGUI;
@ -150,7 +150,7 @@ private:
void PerformCallbackFunction(shared_ptr<ScriptInterface::StructuredClone> args);
CStrW name;
boost::unordered_set<VfsPath> inputs; // for hotloading
std::unordered_set<VfsPath> inputs; // for hotloading
shared_ptr<ScriptInterface::StructuredClone> initData; // data to be passed to the init() function
shared_ptr<CGUI> gui; // the actual GUI page

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -28,17 +28,10 @@
#define INCLUDED_CACHE_ADT
#include <cfloat>
#include <list>
#include <map>
#include <queue> // std::priority_queue
#if CONFIG_ENABLE_BOOST
# include <boost/unordered_map.hpp>
# define MAP boost::unordered_map
#else
# define MAP stdext::hash_map
#endif
#include <unordered_map>
/*
Cache for items of variable size and value/"cost".
@ -313,7 +306,7 @@ again:
}
protected:
class Map : public MAP<Key, Entry>
class Map : public std::unordered_map<Key, Entry>
{
public:
static Entry& entry_from_it(typename Map::iterator it) { return it->second; }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -28,11 +28,11 @@
#ifndef ALLOCATOR_ADAPTERS
#define ALLOCATOR_ADAPTERS
#include <memory>
#include "lib/sysdep/rtl.h"
#include "lib/sysdep/vm.h"
#include <memory>
// NB: STL allocators are parameterized on the object type and indicate
// the number of elements to [de]allocate. however, these adapters are
// only used for allocating storage and receive the number of bytes.
@ -115,9 +115,6 @@ public:
typedef ProxyAllocator<U, Allocator> other;
};
// (required to be declared by boost::unordered_map, but should never be called)
explicit NOTHROW_DEFINE ProxyAllocator();
explicit NOTHROW_DEFINE ProxyAllocator(Allocator& allocator)
: allocator(&allocator)
{

35
source/lib/hash.h Normal file
View File

@ -0,0 +1,35 @@
/* Copyright (C) 2019 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef INCLUDED_HASH
#define INCLUDED_HASH
/**
* This function is the same as hash_combine, i.e. allows dropping the boost dependency just for this function.
*/
template <typename T>
void hash_combine(std::size_t& seed, const T& val)
{
seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
#endif // #ifndef INCLUDED_HASH

View File

@ -37,13 +37,10 @@
#ifndef INCLUDED_PATH
#define INCLUDED_PATH
#if CONFIG_ENABLE_BOOST
# include "boost/functional/hash.hpp"
#endif
#include "lib/utf8.h"
#include <cstring>
#include <functional>
namespace ERR
{
@ -73,11 +70,11 @@ LIB_API const wchar_t* path_name_only(const wchar_t* path);
// NB: there is a need for 'generic' paths (e.g. for Trace entry / archive pathnames).
// converting between specialized variants via c_str would be inefficient, and the
// Os/VfsPath typedefs are hopefully sufficient to avoid errors.
// Os/VfsPath types are hopefully sufficient to avoid errors.
class Path
{
public:
typedef std::wstring String;
using String = std::wstring;
Path()
{
@ -307,21 +304,19 @@ static inline std::wistream& operator>>(std::wistream& s, Path& path)
return s;
}
#if CONFIG_ENABLE_BOOST
namespace boost {
namespace std
{
template<>
struct hash<Path> : std::unary_function<Path, std::size_t>
struct hash<Path>
{
std::size_t operator()(const Path& path) const
{
return hash_value(path.string());
return m_StringHash(path.string());
}
};
private:
std::hash<std::wstring> m_StringHash;
};
}
#endif // #if CONFIG_ENABLE_BOOST
#endif // #ifndef INCLUDED_PATH

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -27,7 +27,7 @@
#include "precompiled.h"
#include "h_mgr.h"
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <limits.h> // CHAR_BIT
#include <string.h>
@ -94,9 +94,8 @@ static const u64 IDX_MASK = (1l << IDX_BITS) - 1;
// - tag (1-based) ensures the handle references a certain resource instance.
// (field width determines maximum unambiguous resource allocs)
typedef i64 Tag;
using Tag = i64;
#define TAG_BITS 48
static const u64 TAG_MASK = 0xFFFFFFFF; // safer than (1 << 32) - 1
// make sure both fields fit within a Handle variable
cassert(IDX_BITS + TAG_BITS <= sizeof(Handle)*CHAR_BIT);
@ -109,13 +108,6 @@ static inline size_t h_idx(const Handle h)
return (size_t)(h & IDX_MASK) - 1;
}
// return the handle's tag field.
// no error checking!
static inline Tag h_tag(Handle h)
{
return h >> IDX_BITS;
}
// build a handle from index and tag.
// can't fail.
static inline Handle handle(size_t idx, u64 tag)
@ -282,8 +274,8 @@ static Status h_data_tag_type(const Handle h, const H_Type type, HDATA*& hd)
// that wasn't foreseen here, so we'll just refrain from adding to the index.
// that means they won't be found via h_find - no biggie.
typedef boost::unordered_multimap<uintptr_t, ssize_t> Key2Idx;
typedef Key2Idx::iterator It;
using Key2Idx = std::unordered_multimap<uintptr_t, ssize_t>;
using It = Key2Idx::iterator;
static OverrunProtector<Key2Idx> key2idx_wrapper;
enum KeyRemoveFlag { KEY_NOREMOVE, KEY_REMOVE };

View File

@ -27,6 +27,6 @@
#include "ps/CStr.h"
#include "ps/Game.h"
#include <boost/unordered_map.hpp>
#include <unordered_map>
#endif // HAVE_PCH

View File

@ -16,8 +16,6 @@
*/
/**
* File : CStr.cpp
* Project : engine
* Description : Controls compilation of CStr class and
* : includes some function implementations.
**/

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -16,8 +16,6 @@
*/
/**
* File : CStr.h
* Project : engine
* Description : Contains CStr class which is a versatile class for making string use easy.
* : The class implements a series of string manipulation/formatting functions.
**/
@ -341,9 +339,4 @@ public:
const u8* Deserialize(const u8* buffer, const u8* bufferend);
};
static inline size_t hash_value(const CStr& s)
{
return s.GetHashCode();
}
#endif

View File

@ -23,7 +23,7 @@
#include "ps/CLogger.h"
#include "ps/ThreadUtil.h"
#include <boost/unordered_map.hpp>
#include <unordered_map>
class CStrInternInternals
{
@ -49,7 +49,7 @@ private:
// Interned strings are stored in a hash table, indexed by string:
typedef std::string StringsKey;
using StringsKey = std::string;
struct StringsKeyHash
{
@ -60,7 +60,7 @@ struct StringsKeyHash
};
// To avoid std::string memory allocations when GetString does lookups in the
// hash table of interned strings, we make use of boost::unordered_map's ability
// hash table of interned strings, we make use of std::unordered_map's ability
// to do lookups with a functionally equivalent proxy object:
struct StringsKeyProxy
@ -85,7 +85,7 @@ struct StringsKeyProxyEq
}
};
static boost::unordered_map<StringsKey, shared_ptr<CStrInternInternals>, StringsKeyHash> g_Strings;
static std::unordered_map<StringsKey, shared_ptr<CStrInternInternals>, StringsKeyHash> g_Strings;
#define X(id) CStrIntern str_##id(#id);
#define X2(id, str) CStrIntern str_##id(str);
@ -100,15 +100,7 @@ static CStrInternInternals* GetString(const char* str, size_t len)
// to be thread-safe, preferably without sacrificing performance.)
ENSURE(ThreadUtil::IsMainThread());
#if BOOST_VERSION >= 104200
StringsKeyProxy proxy = { str, len };
boost::unordered_map<StringsKey, shared_ptr<CStrInternInternals> >::iterator it =
g_Strings.find(proxy, StringsKeyProxyHash(), StringsKeyProxyEq());
#else
// Boost <= 1.41 doesn't support the new find(), so do a slightly less efficient lookup
boost::unordered_map<StringsKey, shared_ptr<CStrInternInternals> >::iterator it =
g_Strings.find(str);
#endif
std::unordered_map<StringsKey, shared_ptr<CStrInternInternals> >::iterator it = g_Strings.find(str);
if (it != g_Strings.end())
return it->second.get();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -90,9 +90,16 @@ private:
CStrInternInternals* m;
};
static inline size_t hash_value(const CStrIntern& str)
namespace std
{
return str.GetHash();
template<>
struct hash<CStrIntern>
{
std::size_t operator()(const CStrIntern& str) const
{
return str.GetHash();
}
};
}
#define X(id) extern CStrIntern str_##id;

View File

@ -17,15 +17,6 @@
#include "precompiled.h"
#include "lib/allocators/allocator_adapters.h"
#include "lib/allocators/arena.h"
#include "lib/ogl.h"
#include "maths/Vector3D.h"
#include "maths/Vector4D.h"
#include "ps/CLogger.h"
#include "ps/Profile.h"
#include "graphics/Color.h"
#include "graphics/LightEnv.h"
#include "graphics/Material.h"
@ -33,7 +24,14 @@
#include "graphics/ModelDef.h"
#include "graphics/ShaderManager.h"
#include "graphics/TextureManager.h"
#include "lib/allocators/allocator_adapters.h"
#include "lib/allocators/arena.h"
#include "lib/hash.h"
#include "lib/ogl.h"
#include "maths/Vector3D.h"
#include "maths/Vector4D.h"
#include "ps/CLogger.h"
#include "ps/Profile.h"
#include "renderer/MikktspaceWrap.h"
#include "renderer/ModelRenderer.h"
#include "renderer/ModelVertexRenderer.h"
@ -338,8 +336,8 @@ struct SMRMaterialBucketKeyHash
size_t operator()(const SMRMaterialBucketKey& key) const
{
size_t hash = 0;
boost::hash_combine(hash, key.effect.GetHash());
boost::hash_combine(hash, key.defines.GetHash());
hash_combine(hash, key.effect.GetHash());
hash_combine(hash, key.defines.GetHash());
return hash;
}
};
@ -424,12 +422,17 @@ void ShaderModelRenderer::Render(const RenderModifierPtr& modifier, const CShade
*/
Allocators::DynamicArena arena(256 * KiB);
typedef ProxyAllocator<CModel*, Allocators::DynamicArena> ModelListAllocator;
typedef std::vector<CModel*, ModelListAllocator> ModelList_t;
typedef boost::unordered_map<SMRMaterialBucketKey, ModelList_t,
SMRMaterialBucketKeyHash, std::equal_to<SMRMaterialBucketKey>,
ProxyAllocator<std::pair<const SMRMaterialBucketKey, ModelList_t>, Allocators::DynamicArena>
> MaterialBuckets_t;
using ModelListAllocator = ProxyAllocator<CModel*, Allocators::DynamicArena>;
using ModelList_t = std::vector<CModel*, ModelListAllocator>;
using MaterialBuckets_t = std::unordered_map<
SMRMaterialBucketKey,
ModelList_t,
SMRMaterialBucketKeyHash,
std::equal_to<SMRMaterialBucketKey>,
ProxyAllocator<
std::pair<const SMRMaterialBucketKey, ModelList_t>,
Allocators::DynamicArena> >;
MaterialBuckets_t materialBuckets((MaterialBuckets_t::allocator_type(arena)));
{

View File

@ -19,11 +19,11 @@
#include "OverlayRenderer.h"
#include <boost/unordered_map.hpp>
#include "graphics/LOSTexture.h"
#include "graphics/Overlay.h"
#include "graphics/Terrain.h"
#include "graphics/TextureManager.h"
#include "lib/hash.h"
#include "lib/ogl.h"
#include "maths/MathUtil.h"
#include "maths/Quaternion.h"
@ -34,10 +34,12 @@
#include "renderer/VertexArray.h"
#include "renderer/VertexBuffer.h"
#include "renderer/VertexBufferManager.h"
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpWaterManager.h"
#include "simulation2/Simulation2.h"
#include "simulation2/system/SimContext.h"
#include <unordered_map>
/**
* Key used to group quads into batches for more efficient rendering. Currently groups by the combination
* of the main texture and the texture mask, to minimize texture swapping during rendering.
@ -57,6 +59,17 @@ struct QuadBatchKey
CTexturePtr m_TextureMask;
};
struct QuadBatchHash
{
std::size_t operator()(const QuadBatchKey& d) const
{
size_t seed = 0;
hash_combine(seed, d.m_Texture);
hash_combine(seed, d.m_TextureMask);
return seed;
}
};
/**
* Holds information about a single quad rendering batch.
*/
@ -79,7 +92,7 @@ public:
struct OverlayRendererInternals
{
typedef boost::unordered_map<QuadBatchKey, QuadBatchData> QuadBatchMap;
using QuadBatchMap = std::unordered_map<QuadBatchKey, QuadBatchData, QuadBatchHash>;
OverlayRendererInternals();
~OverlayRendererInternals(){ }
@ -178,14 +191,6 @@ void OverlayRendererInternals::Initialize()
quadIndices.FreeBackingStore();
}
static size_t hash_value(const QuadBatchKey& d)
{
size_t seed = 0;
boost::hash_combine(seed, d.m_Texture);
boost::hash_combine(seed, d.m_TextureMask);
return seed;
}
OverlayRenderer::OverlayRenderer()
{
m = new OverlayRendererInternals();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -18,26 +18,24 @@
#ifndef INCLUDED_SIMULATION2
#define INCLUDED_SIMULATION2
#include "lib/file/vfs/vfs_path.h"
#include "scriptinterface/ScriptVal.h"
#include "simulation2/helpers/SimulationCommand.h"
#include "simulation2/system/CmpPtr.h"
#include "simulation2/system/Components.h"
#include "simulation2/helpers/SimulationCommand.h"
#include "scriptinterface/ScriptVal.h"
#include "lib/file/vfs/vfs_path.h"
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <map>
class CSimulation2Impl;
class CSimContext;
class CUnitManager;
class CTerrain;
class IComponent;
class ScriptInterface;
class CMessage;
class SceneCollector;
class CFrustum;
class CMessage;
class CSimContext;
class CSimulation2Impl;
class CTerrain;
class CUnitManager;
class IComponent;
class SceneCollector;
class ScriptInterface;
class ScriptRuntime;
/**
@ -206,8 +204,11 @@ public:
void PostMessage(entity_id_t ent, const CMessage& msg) const;
void BroadcastMessage(const CMessage& msg) const;
typedef std::vector<std::pair<entity_id_t, IComponent*> > InterfaceList;
typedef boost::unordered_map<entity_id_t, IComponent*> InterfaceListUnordered;
using InterfaceList =
std::vector<std::pair<entity_id_t, IComponent*> >;
using InterfaceListUnordered =
std::unordered_map<entity_id_t, IComponent*>;
/**
* Returns a list of components implementing the given interface, and their

View File

@ -27,7 +27,7 @@
#include "simulation2/serialization/IDeserializer.h"
#include "simulation2/serialization/ISerializer.h"
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <utility>
template<typename ELEM>
@ -200,14 +200,14 @@ template<typename KS, typename VS>
struct SerializeUnorderedMap
{
template<typename K, typename V>
void operator()(ISerializer& serialize, const char* name, boost::unordered_map<K, V>& value)
void operator()(ISerializer& serialize, const char* name, std::unordered_map<K, V>& value)
{
std::map<K, V> ordered_value(value.begin(), value.end());
SerializeMap<KS, VS>()(serialize, name, ordered_value);
}
template<typename K, typename V>
void operator()(IDeserializer& deserialize, const char* name, boost::unordered_map<K, V>& value)
void operator()(IDeserializer& deserialize, const char* name, std::unordered_map<K, V>& value)
{
SerializeMap<KS, VS>()(deserialize, name, value);
}

View File

@ -19,19 +19,17 @@
#include "ComponentManager.h"
#include "DynamicSubscription.h"
#include "IComponent.h"
#include "ParamNode.h"
#include "SimContext.h"
#include "simulation2/MessageTypes.h"
#include "simulation2/components/ICmpTemplateManager.h"
#include "lib/utf8.h"
#include "ps/CLogger.h"
#include "ps/Profile.h"
#include "ps/Filesystem.h"
#include "ps/Profile.h"
#include "ps/scripting/JSInterface_VFS.h"
#include "simulation2/components/ICmpTemplateManager.h"
#include "simulation2/MessageTypes.h"
#include "simulation2/system/DynamicSubscription.h"
#include "simulation2/system/IComponent.h"
#include "simulation2/system/ParamNode.h"
#include "simulation2/system/SimContext.h"
/**
* Used for script-only message types.
@ -507,7 +505,7 @@ void CComponentManager::ResetState()
}
}
std::vector<boost::unordered_map<entity_id_t, IComponent*> >::iterator ifcit = m_ComponentsByInterface.begin();
std::vector<std::unordered_map<entity_id_t, IComponent*> >::iterator ifcit = m_ComponentsByInterface.begin();
for (; ifcit != m_ComponentsByInterface.end(); ++ifcit)
ifcit->clear();
@ -742,7 +740,7 @@ IComponent* CComponentManager::ConstructComponent(CEntityHandle ent, ComponentTy
ENSURE((size_t)ct.iid < m_ComponentsByInterface.size());
boost::unordered_map<entity_id_t, IComponent*>& emap1 = m_ComponentsByInterface[ct.iid];
std::unordered_map<entity_id_t, IComponent*>& emap1 = m_ComponentsByInterface[ct.iid];
if (emap1.find(ent.GetId()) != emap1.end())
{
LOGERROR("Multiple components for interface %d", ct.iid);
@ -791,7 +789,7 @@ void CComponentManager::AddMockComponent(CEntityHandle ent, InterfaceId iid, ICo
// Just add it into the by-interface map, not the by-component-type map,
// so it won't be considered for messages or deletion etc
boost::unordered_map<entity_id_t, IComponent*>& emap1 = m_ComponentsByInterface.at(iid);
std::unordered_map<entity_id_t, IComponent*>& emap1 = m_ComponentsByInterface.at(iid);
if (emap1.find(ent.GetId()) != emap1.end())
debug_warn(L"Multiple components for interface");
emap1.insert(std::make_pair(ent.GetId(), &component));
@ -942,7 +940,7 @@ void CComponentManager::FlushDestroyedComponents()
m_ComponentCaches.erase(ent);
// Remove from m_ComponentsByInterface
std::vector<boost::unordered_map<entity_id_t, IComponent*> >::iterator ifcit = m_ComponentsByInterface.begin();
std::vector<std::unordered_map<entity_id_t, IComponent*> >::iterator ifcit = m_ComponentsByInterface.begin();
for (; ifcit != m_ComponentsByInterface.end(); ++ifcit)
{
ifcit->erase(ent);
@ -959,7 +957,7 @@ IComponent* CComponentManager::QueryInterface(entity_id_t ent, InterfaceId iid)
return NULL;
}
boost::unordered_map<entity_id_t, IComponent*>::const_iterator eit = m_ComponentsByInterface[iid].find(ent);
std::unordered_map<entity_id_t, IComponent*>::const_iterator eit = m_ComponentsByInterface[iid].find(ent);
if (eit == m_ComponentsByInterface[iid].end())
{
// This entity doesn't implement this interface
@ -981,7 +979,7 @@ CComponentManager::InterfaceList CComponentManager::GetEntitiesWithInterface(Int
ret.reserve(m_ComponentsByInterface[iid].size());
boost::unordered_map<entity_id_t, IComponent*>::const_iterator it = m_ComponentsByInterface[iid].begin();
std::unordered_map<entity_id_t, IComponent*>::const_iterator it = m_ComponentsByInterface[iid].begin();
for (; it != m_ComponentsByInterface[iid].end(); ++it)
ret.push_back(*it);

View File

@ -18,15 +18,14 @@
#ifndef INCLUDED_COMPONENTMANAGER
#define INCLUDED_COMPONENTMANAGER
#include "Entity.h"
#include "Components.h"
#include "ps/Filesystem.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptVal.h"
#include "simulation2/helpers/Player.h"
#include "ps/Filesystem.h"
#include "simulation2/system/Components.h"
#include "simulation2/system/Entity.h"
#include <boost/random/linear_congruential.hpp>
#include <boost/unordered_map.hpp>
#include <map>
#include <set>
#include <unordered_map>
@ -270,9 +269,9 @@ public:
IComponent* QueryInterface(entity_id_t ent, InterfaceId iid) const;
typedef std::pair<entity_id_t, IComponent*> InterfacePair;
typedef std::vector<InterfacePair> InterfaceList;
typedef boost::unordered_map<entity_id_t, IComponent*> InterfaceListUnordered;
using InterfacePair = std::pair<entity_id_t, IComponent*>;
using InterfaceList = std::vector<InterfacePair>;
using InterfaceListUnordered = std::unordered_map<entity_id_t, IComponent*>;
InterfaceList GetEntitiesWithInterface(InterfaceId iid) const;
const InterfaceListUnordered& GetEntitiesWithInterfaceUnordered(InterfaceId iid) const;
@ -353,7 +352,7 @@ private:
// TODO: some of these should be vectors
std::map<ComponentTypeId, ComponentType> m_ComponentTypesById;
std::vector<CComponentManager::ComponentTypeId> m_ScriptedSystemComponents;
std::vector<boost::unordered_map<entity_id_t, IComponent*> > m_ComponentsByInterface; // indexed by InterfaceId
std::vector<std::unordered_map<entity_id_t, IComponent*> > m_ComponentsByInterface; // indexed by InterfaceId
std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> > m_ComponentsByTypeId;
std::map<MessageTypeId, std::vector<ComponentTypeId> > m_LocalMessageSubscriptions;
std::map<MessageTypeId, std::vector<ComponentTypeId> > m_GlobalMessageSubscriptions;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -35,18 +35,34 @@ protected:
virtual void setNew(ssize_t x, ssize_t y, const T& val) = 0;
private:
std::size_t hash_value(const std::pair<ssize_t, ssize_t>& p)
// TODO: more efficient representation
using Data = std::unordered_map<std::pair<ssize_t, ssize_t>, std::pair<T, T> >; // map of <x,y> -> <old_val, new_val>
Data m_Data;
};
namespace std
{
template<>
struct hash<std::pair<ssize_t, ssize_t> >
{
std::size_t operator()(const std::pair<ssize_t, ssize_t>& p) const
{
std::size_t seed = 0;
boost::hash_combine(seed, p.first << 16);
boost::hash_combine(seed, p.second);
hash_combine(seed, p.first << 16);
hash_combine(seed, p.second);
return seed;
}
// TODO: more efficient representation
typedef boost::unordered_map<std::pair<ssize_t, ssize_t>, std::pair<T, T> > Data; // map of <x,y> -> <old_val, new_val>
Data m_Data;
// Same as boost::hash_combine
void hash_combine(std::size_t& seed, const ssize_t val) const
{
seed ^= m_SizeHash(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
private:
std::hash<ssize_t> m_SizeHash;
};
}
//////////////////////////////////////////////////////////////////////////