Replace various std::map with UNORDERED_MAP + various cleanups

This is part 2 for 5f084cd98d

Other improvements:

* Use the defined ItemGroupList when used
* make Client::checkPrivilege const
* inline some trivial functions
* Add ActiveObjectMap typedef
* Add SettingsEntries typedef
This commit is contained in:
Loic Blot 2016-10-05 09:03:55 +02:00 committed by Ner'zhul
parent 5f084cd98d
commit 613797a304
23 changed files with 110 additions and 167 deletions

View File

@ -303,7 +303,7 @@ Client::~Client()
delete m_inventory_from_server; delete m_inventory_from_server;
// Delete detached inventories // Delete detached inventories
for (std::map<std::string, Inventory*>::iterator for (UNORDERED_MAP<std::string, Inventory*>::iterator
i = m_detached_inventories.begin(); i = m_detached_inventories.begin();
i != m_detached_inventories.end(); ++i) { i != m_detached_inventories.end(); ++i) {
delete i->second; delete i->second;
@ -1437,7 +1437,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc)
break; break;
case InventoryLocation::DETACHED: case InventoryLocation::DETACHED:
{ {
if(m_detached_inventories.count(loc.name) == 0) if (m_detached_inventories.count(loc.name) == 0)
return NULL; return NULL;
return m_detached_inventories[loc.name]; return m_detached_inventories[loc.name];
} }

View File

@ -462,7 +462,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
u16 getHP(); u16 getHP();
u16 getBreath(); u16 getBreath();
bool checkPrivilege(const std::string &priv) bool checkPrivilege(const std::string &priv) const
{ return (m_privileges.count(priv) != 0); } { return (m_privileges.count(priv) != 0); }
bool getChatMessage(std::wstring &message); bool getChatMessage(std::wstring &message);
@ -670,11 +670,11 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
std::map<int, u16> m_sounds_to_objects; std::map<int, u16> m_sounds_to_objects;
// Privileges // Privileges
std::set<std::string> m_privileges; UNORDERED_SET<std::string> m_privileges;
// Detached inventories // Detached inventories
// key = name // key = name
std::map<std::string, Inventory*> m_detached_inventories; UNORDERED_MAP<std::string, Inventory*> m_detached_inventories;
// Storage for mesh data for creating multiple instances of the same mesh // Storage for mesh data for creating multiple instances of the same mesh
StringMap m_mesh_data; StringMap m_mesh_data;

View File

@ -605,11 +605,8 @@ ClientInterface::~ClientInterface()
{ {
MutexAutoLock clientslock(m_clients_mutex); MutexAutoLock clientslock(m_clients_mutex);
for(std::map<u16, RemoteClient*>::iterator for (UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
i = m_clients.begin(); i != m_clients.end(); ++i) {
i != m_clients.end(); ++i)
{
// Delete client // Delete client
delete i->second; delete i->second;
} }
@ -621,10 +618,8 @@ std::vector<u16> ClientInterface::getClientIDs(ClientState min_state)
std::vector<u16> reply; std::vector<u16> reply;
MutexAutoLock clientslock(m_clients_mutex); MutexAutoLock clientslock(m_clients_mutex);
for(std::map<u16, RemoteClient*>::iterator for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
i = m_clients.begin(); i != m_clients.end(); ++i) {
i != m_clients.end(); ++i)
{
if (i->second->getState() >= min_state) if (i->second->getState() >= min_state)
reply.push_back(i->second->peer_id); reply.push_back(i->second->peer_id);
} }
@ -691,8 +686,7 @@ void ClientInterface::sendToAll(u16 channelnum,
NetworkPacket* pkt, bool reliable) NetworkPacket* pkt, bool reliable)
{ {
MutexAutoLock clientslock(m_clients_mutex); MutexAutoLock clientslock(m_clients_mutex);
for(std::map<u16, RemoteClient*>::iterator for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
i = m_clients.begin();
i != m_clients.end(); ++i) { i != m_clients.end(); ++i) {
RemoteClient *client = i->second; RemoteClient *client = i->second;
@ -705,11 +699,10 @@ void ClientInterface::sendToAll(u16 channelnum,
RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min) RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
{ {
MutexAutoLock clientslock(m_clients_mutex); MutexAutoLock clientslock(m_clients_mutex);
std::map<u16, RemoteClient*>::iterator n; UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their // The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then. // access is denied, and this event occurs later then.
if(n == m_clients.end()) if (n == m_clients.end())
return NULL; return NULL;
if (n->second->getState() >= state_min) if (n->second->getState() >= state_min)
@ -720,11 +713,10 @@ RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min) RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min)
{ {
std::map<u16, RemoteClient*>::iterator n; UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their // The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then. // access is denied, and this event occurs later then.
if(n == m_clients.end()) if (n == m_clients.end())
return NULL; return NULL;
if (n->second->getState() >= state_min) if (n->second->getState() >= state_min)
@ -736,11 +728,10 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState stat
ClientState ClientInterface::getClientState(u16 peer_id) ClientState ClientInterface::getClientState(u16 peer_id)
{ {
MutexAutoLock clientslock(m_clients_mutex); MutexAutoLock clientslock(m_clients_mutex);
std::map<u16, RemoteClient*>::iterator n; UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their // The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then. // access is denied, and this event occurs later then.
if(n == m_clients.end()) if (n == m_clients.end())
return CS_Invalid; return CS_Invalid;
return n->second->getState(); return n->second->getState();
@ -749,11 +740,10 @@ ClientState ClientInterface::getClientState(u16 peer_id)
void ClientInterface::setPlayerName(u16 peer_id,std::string name) void ClientInterface::setPlayerName(u16 peer_id,std::string name)
{ {
MutexAutoLock clientslock(m_clients_mutex); MutexAutoLock clientslock(m_clients_mutex);
std::map<u16, RemoteClient*>::iterator n; UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their // The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then. // access is denied, and this event occurs later then.
if(n != m_clients.end()) if (n != m_clients.end())
n->second->setName(name); n->second->setName(name);
} }
@ -762,11 +752,10 @@ void ClientInterface::DeleteClient(u16 peer_id)
MutexAutoLock conlock(m_clients_mutex); MutexAutoLock conlock(m_clients_mutex);
// Error check // Error check
std::map<u16, RemoteClient*>::iterator n; UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their // The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then. // access is denied, and this event occurs later then.
if(n == m_clients.end()) if (n == m_clients.end())
return; return;
/* /*
@ -797,10 +786,9 @@ void ClientInterface::CreateClient(u16 peer_id)
MutexAutoLock conlock(m_clients_mutex); MutexAutoLock conlock(m_clients_mutex);
// Error check // Error check
std::map<u16, RemoteClient*>::iterator n; UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
n = m_clients.find(peer_id);
// The client shouldn't already exist // The client shouldn't already exist
if(n != m_clients.end()) return; if (n != m_clients.end()) return;
// Create client // Create client
RemoteClient *client = new RemoteClient(); RemoteClient *client = new RemoteClient();
@ -814,8 +802,7 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event)
MutexAutoLock clientlock(m_clients_mutex); MutexAutoLock clientlock(m_clients_mutex);
// Error check // Error check
std::map<u16, RemoteClient*>::iterator n; UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
n = m_clients.find(peer_id);
// No client to deliver event // No client to deliver event
if (n == m_clients.end()) if (n == m_clients.end())
@ -836,8 +823,7 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id)
MutexAutoLock conlock(m_clients_mutex); MutexAutoLock conlock(m_clients_mutex);
// Error check // Error check
std::map<u16, RemoteClient*>::iterator n; UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
n = m_clients.find(peer_id);
// No client to get version // No client to get version
if (n == m_clients.end()) if (n == m_clients.end())
@ -851,8 +837,7 @@ void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch
MutexAutoLock conlock(m_clients_mutex); MutexAutoLock conlock(m_clients_mutex);
// Error check // Error check
std::map<u16, RemoteClient*>::iterator n; UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
n = m_clients.find(peer_id);
// No client to set versions // No client to set versions
if (n == m_clients.end()) if (n == m_clients.end())

View File

@ -25,10 +25,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serialization.h" // for SER_FMT_VER_INVALID #include "serialization.h" // for SER_FMT_VER_INVALID
#include "threading/mutex.h" #include "threading/mutex.h"
#include "network/networkpacket.h" #include "network/networkpacket.h"
#include "util/cpp11_container.h"
#include <list> #include <list>
#include <vector> #include <vector>
#include <map>
#include <set> #include <set>
class MapBlock; class MapBlock;
@ -502,8 +502,7 @@ class ClientInterface {
void lock() { m_clients_mutex.lock(); } void lock() { m_clients_mutex.lock(); }
void unlock() { m_clients_mutex.unlock(); } void unlock() { m_clients_mutex.unlock(); }
std::map<u16, RemoteClient*>& getClientList() UNORDERED_MAP<u16, RemoteClient*>& getClientList() { return m_clients; }
{ return m_clients; }
private: private:
/* update internal player list */ /* update internal player list */
@ -513,7 +512,7 @@ class ClientInterface {
con::Connection* m_con; con::Connection* m_con;
Mutex m_clients_mutex; Mutex m_clients_mutex;
// Connected clients (behind the con mutex) // Connected clients (behind the con mutex)
std::map<u16, RemoteClient*> m_clients; UNORDERED_MAP<u16, RemoteClient*> m_clients;
std::vector<std::string> m_clients_names; //for announcing masterserver std::vector<std::string> m_clients_names; //for announcing masterserver
// Environment // Environment

View File

@ -1505,10 +1505,8 @@ void GenericCAO::updateBonePosition()
return; return;
m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
for(std::map<std::string, for(UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
ii != m_bone_position.end(); ++ii)
{
std::string bone_name = (*ii).first; std::string bone_name = (*ii).first;
v3f bone_pos = (*ii).second.X; v3f bone_pos = (*ii).second.X;
v3f bone_rot = (*ii).second.Y; v3f bone_rot = (*ii).second.Y;

View File

@ -90,7 +90,7 @@ class GenericCAO : public ClientActiveObject
int m_animation_speed; int m_animation_speed;
int m_animation_blend; int m_animation_blend;
bool m_animation_loop; bool m_animation_loop;
std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
std::string m_attachment_bone; std::string m_attachment_bone;
v3f m_attachment_position; v3f m_attachment_position;
v3f m_attachment_rotation; v3f m_attachment_rotation;

View File

@ -369,12 +369,10 @@ bool EmergeManager::pushBlockEmergeData(
} }
bool EmergeManager::popBlockEmergeData( bool EmergeManager::popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata)
v3s16 pos,
BlockEmergeData *bedata)
{ {
std::map<v3s16, BlockEmergeData>::iterator it; std::map<v3s16, BlockEmergeData>::iterator it;
std::map<u16, u16>::iterator it2; UNORDERED_MAP<u16, u16>::iterator it2;
it = m_blocks_enqueued.find(pos); it = m_blocks_enqueued.find(pos);
if (it == m_blocks_enqueued.end()) if (it == m_blocks_enqueued.end())

View File

@ -156,7 +156,7 @@ class EmergeManager {
Mutex m_queue_mutex; Mutex m_queue_mutex;
std::map<v3s16, BlockEmergeData> m_blocks_enqueued; std::map<v3s16, BlockEmergeData> m_blocks_enqueued;
std::map<u16, u16> m_peer_queue_count; UNORDERED_MAP<u16, u16> m_peer_queue_count;
u16 m_qlimit_total; u16 m_qlimit_total;
u16 m_qlimit_diskonly; u16 m_qlimit_diskonly;

View File

@ -1124,14 +1124,12 @@ bool ServerEnvironment::swapNode(v3s16 p, const MapNode &n)
void ServerEnvironment::getObjectsInsideRadius(std::vector<u16> &objects, v3f pos, float radius) void ServerEnvironment::getObjectsInsideRadius(std::vector<u16> &objects, v3f pos, float radius)
{ {
for(std::map<u16, ServerActiveObject*>::iterator for (ActiveObjectMap::iterator i = m_active_objects.begin();
i = m_active_objects.begin(); i != m_active_objects.end(); ++i) {
i != m_active_objects.end(); ++i)
{
ServerActiveObject* obj = i->second; ServerActiveObject* obj = i->second;
u16 id = i->first; u16 id = i->first;
v3f objectpos = obj->getBasePosition(); v3f objectpos = obj->getBasePosition();
if(objectpos.getDistanceFrom(pos) > radius) if (objectpos.getDistanceFrom(pos) > radius)
continue; continue;
objects.push_back(id); objects.push_back(id);
} }
@ -1142,8 +1140,7 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
infostream << "ServerEnvironment::clearObjects(): " infostream << "ServerEnvironment::clearObjects(): "
<< "Removing all active objects" << std::endl; << "Removing all active objects" << std::endl;
std::vector<u16> objects_to_remove; std::vector<u16> objects_to_remove;
for (std::map<u16, ServerActiveObject*>::iterator for (ActiveObjectMap::iterator i = m_active_objects.begin();
i = m_active_objects.begin();
i != m_active_objects.end(); ++i) { i != m_active_objects.end(); ++i) {
ServerActiveObject* obj = i->second; ServerActiveObject* obj = i->second;
if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER) if (obj->getType() == ACTIVEOBJECT_TYPE_PLAYER)
@ -1518,10 +1515,8 @@ void ServerEnvironment::step(float dtime)
send_recommended = true; send_recommended = true;
} }
for(std::map<u16, ServerActiveObject*>::iterator for(ActiveObjectMap::iterator i = m_active_objects.begin();
i = m_active_objects.begin(); i != m_active_objects.end(); ++i) {
i != m_active_objects.end(); ++i)
{
ServerActiveObject* obj = i->second; ServerActiveObject* obj = i->second;
// Don't step if is to be removed or stored statically // Don't step if is to be removed or stored statically
if(obj->m_removed || obj->m_pending_deactivation) if(obj->m_removed || obj->m_pending_deactivation)
@ -1554,7 +1549,7 @@ void ServerEnvironment::step(float dtime)
Manage particle spawner expiration Manage particle spawner expiration
*/ */
if (m_particle_management_interval.step(dtime, 1.0)) { if (m_particle_management_interval.step(dtime, 1.0)) {
for (std::map<u32, float>::iterator i = m_particle_spawners.begin(); for (UNORDERED_MAP<u32, float>::iterator i = m_particle_spawners.begin();
i != m_particle_spawners.end(); ) { i != m_particle_spawners.end(); ) {
//non expiring spawners //non expiring spawners
if (i->second == PARTICLE_SPAWNER_NO_EXPIRY) { if (i->second == PARTICLE_SPAWNER_NO_EXPIRY) {
@ -1579,8 +1574,7 @@ u32 ServerEnvironment::addParticleSpawner(float exptime)
u32 id = 0; u32 id = 0;
for (;;) { // look for unused particlespawner id for (;;) { // look for unused particlespawner id
id++; id++;
std::map<u32, float>::iterator f; UNORDERED_MAP<u32, float>::iterator f = m_particle_spawners.find(id);
f = m_particle_spawners.find(id);
if (f == m_particle_spawners.end()) { if (f == m_particle_spawners.end()) {
m_particle_spawners[id] = time; m_particle_spawners[id] = time;
break; break;
@ -1589,31 +1583,21 @@ u32 ServerEnvironment::addParticleSpawner(float exptime)
return id; return id;
} }
void ServerEnvironment::deleteParticleSpawner(u32 id)
{
m_particle_spawners.erase(id);
}
ServerActiveObject* ServerEnvironment::getActiveObject(u16 id) ServerActiveObject* ServerEnvironment::getActiveObject(u16 id)
{ {
std::map<u16, ServerActiveObject*>::iterator n; ActiveObjectMap::iterator n = m_active_objects.find(id);
n = m_active_objects.find(id); return (n != m_active_objects.end() ? n->second : NULL);
if(n == m_active_objects.end())
return NULL;
return n->second;
} }
bool isFreeServerActiveObjectId(u16 id, bool isFreeServerActiveObjectId(u16 id, ActiveObjectMap &objects)
std::map<u16, ServerActiveObject*> &objects)
{ {
if(id == 0) if (id == 0)
return false; return false;
return objects.find(id) == objects.end(); return objects.find(id) == objects.end();
} }
u16 getFreeServerActiveObjectId( u16 getFreeServerActiveObjectId(ActiveObjectMap &objects)
std::map<u16, ServerActiveObject*> &objects)
{ {
//try to reuse id's as late as possible //try to reuse id's as late as possible
static u16 last_used_id = 0; static u16 last_used_id = 0;
@ -1659,8 +1643,7 @@ void ServerEnvironment::getAddedActiveObjects(Player *player, s16 radius,
- discard objects that are found in current_objects. - discard objects that are found in current_objects.
- add remaining objects to added_objects - add remaining objects to added_objects
*/ */
for(std::map<u16, ServerActiveObject*>::iterator for(ActiveObjectMap::iterator i = m_active_objects.begin();
i = m_active_objects.begin();
i != m_active_objects.end(); ++i) { i != m_active_objects.end(); ++i) {
u16 id = i->first; u16 id = i->first;
@ -1756,8 +1739,7 @@ void ServerEnvironment::setStaticForActiveObjectsInBlock(
so_it = block->m_static_objects.m_active.begin(); so_it = block->m_static_objects.m_active.begin();
so_it != block->m_static_objects.m_active.end(); ++so_it) { so_it != block->m_static_objects.m_active.end(); ++so_it) {
// Get the ServerActiveObject counterpart to this StaticObject // Get the ServerActiveObject counterpart to this StaticObject
std::map<u16, ServerActiveObject *>::iterator ao_it; ActiveObjectMap::iterator ao_it = m_active_objects.find(so_it->first);
ao_it = m_active_objects.find(so_it->first);
if (ao_it == m_active_objects.end()) { if (ao_it == m_active_objects.end()) {
// If this ever happens, there must be some kind of nasty bug. // If this ever happens, there must be some kind of nasty bug.
errorstream << "ServerEnvironment::setStaticForObjectsInBlock(): " errorstream << "ServerEnvironment::setStaticForObjectsInBlock(): "
@ -1806,8 +1788,8 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
verbosestream<<"ServerEnvironment::addActiveObjectRaw(): " verbosestream<<"ServerEnvironment::addActiveObjectRaw(): "
<<"supplied with id "<<object->getId()<<std::endl; <<"supplied with id "<<object->getId()<<std::endl;
} }
if(isFreeServerActiveObjectId(object->getId(), m_active_objects) == false)
{ if(!isFreeServerActiveObjectId(object->getId(), m_active_objects)) {
errorstream<<"ServerEnvironment::addActiveObjectRaw(): " errorstream<<"ServerEnvironment::addActiveObjectRaw(): "
<<"id is not free ("<<object->getId()<<")"<<std::endl; <<"id is not free ("<<object->getId()<<")"<<std::endl;
if(object->environmentDeletes()) if(object->environmentDeletes())
@ -1875,8 +1857,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
void ServerEnvironment::removeRemovedObjects() void ServerEnvironment::removeRemovedObjects()
{ {
std::vector<u16> objects_to_remove; std::vector<u16> objects_to_remove;
for(std::map<u16, ServerActiveObject*>::iterator for(ActiveObjectMap::iterator i = m_active_objects.begin();
i = m_active_objects.begin();
i != m_active_objects.end(); ++i) { i != m_active_objects.end(); ++i) {
u16 id = i->first; u16 id = i->first;
ServerActiveObject* obj = i->second; ServerActiveObject* obj = i->second;
@ -1894,7 +1875,7 @@ void ServerEnvironment::removeRemovedObjects()
We will delete objects that are marked as removed or thatare We will delete objects that are marked as removed or thatare
waiting for deletion after deactivation waiting for deletion after deactivation
*/ */
if(obj->m_removed == false && obj->m_pending_deactivation == false) if (!obj->m_removed && !obj->m_pending_deactivation)
continue; continue;
/* /*
@ -2094,8 +2075,7 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
void ServerEnvironment::deactivateFarObjects(bool force_delete) void ServerEnvironment::deactivateFarObjects(bool force_delete)
{ {
std::vector<u16> objects_to_remove; std::vector<u16> objects_to_remove;
for(std::map<u16, ServerActiveObject*>::iterator for(ActiveObjectMap::iterator i = m_active_objects.begin();
i = m_active_objects.begin();
i != m_active_objects.end(); ++i) { i != m_active_objects.end(); ++i) {
ServerActiveObject* obj = i->second; ServerActiveObject* obj = i->second;
assert(obj); assert(obj);

View File

@ -300,6 +300,8 @@ enum ClearObjectsMode {
This is not thread-safe. Server uses an environment mutex. This is not thread-safe. Server uses an environment mutex.
*/ */
typedef UNORDERED_MAP<u16, ServerActiveObject *> ActiveObjectMap;
class ServerEnvironment : public Environment class ServerEnvironment : public Environment
{ {
public: public:
@ -338,7 +340,7 @@ class ServerEnvironment : public Environment
void loadDefaultMeta(); void loadDefaultMeta();
u32 addParticleSpawner(float exptime); u32 addParticleSpawner(float exptime);
void deleteParticleSpawner(u32 id); void deleteParticleSpawner(u32 id) { m_particle_spawners.erase(id); }
/* /*
External ActiveObject interface External ActiveObject interface
@ -491,7 +493,7 @@ class ServerEnvironment : public Environment
// World path // World path
const std::string m_path_world; const std::string m_path_world;
// Active object list // Active object list
std::map<u16, ServerActiveObject*> m_active_objects; ActiveObjectMap m_active_objects;
// Outgoing network message buffer for active objects // Outgoing network message buffer for active objects
std::queue<ActiveObjectMessage> m_active_object_messages; std::queue<ActiveObjectMessage> m_active_object_messages;
// Some timers // Some timers
@ -522,7 +524,7 @@ class ServerEnvironment : public Environment
// Particles // Particles
IntervalLimiter m_particle_management_interval; IntervalLimiter m_particle_management_interval;
std::map<u32, float> m_particle_spawners; UNORDERED_MAP<u32, float> m_particle_spawners;
}; };
#ifndef SERVER #ifndef SERVER

View File

@ -605,7 +605,7 @@ class ProfilerGraph
void draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver, void draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
gui::IGUIFont *font) const gui::IGUIFont *font) const
{ {
std::map<std::string, Meta> m_meta; UNORDERED_MAP<std::string, Meta> m_meta;
for (std::deque<Piece>::const_iterator k = m_log.begin(); for (std::deque<Piece>::const_iterator k = m_log.begin();
k != m_log.end(); ++k) { k != m_log.end(); ++k) {
@ -615,8 +615,7 @@ class ProfilerGraph
i != piece.values.end(); ++i) { i != piece.values.end(); ++i) {
const std::string &id = i->first; const std::string &id = i->first;
const float &value = i->second; const float &value = i->second;
std::map<std::string, Meta>::iterator j = UNORDERED_MAP<std::string, Meta>::iterator j = m_meta.find(id);
m_meta.find(id);
if (j == m_meta.end()) { if (j == m_meta.end()) {
m_meta[id] = Meta(value); m_meta[id] = Meta(value);
@ -643,7 +642,7 @@ class ProfilerGraph
sizeof(usable_colors) / sizeof(*usable_colors); sizeof(usable_colors) / sizeof(*usable_colors);
u32 next_color_i = 0; u32 next_color_i = 0;
for (std::map<std::string, Meta>::iterator i = m_meta.begin(); for (UNORDERED_MAP<std::string, Meta>::iterator i = m_meta.begin();
i != m_meta.end(); ++i) { i != m_meta.end(); ++i) {
Meta &meta = i->second; Meta &meta = i->second;
video::SColor color(255, 200, 200, 200); video::SColor color(255, 200, 200, 200);
@ -659,7 +658,7 @@ class ProfilerGraph
s32 textx2 = textx + 200 - 15; s32 textx2 = textx + 200 - 15;
s32 meta_i = 0; s32 meta_i = 0;
for (std::map<std::string, Meta>::const_iterator i = m_meta.begin(); for (UNORDERED_MAP<std::string, Meta>::const_iterator i = m_meta.begin();
i != m_meta.end(); ++i) { i != m_meta.end(); ++i) {
const std::string &id = i->first; const std::string &id = i->first;
const Meta &meta = i->second; const Meta &meta = i->second;

View File

@ -146,9 +146,9 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
} }
os<<serializeString(tool_capabilities_s); os<<serializeString(tool_capabilities_s);
writeU16(os, groups.size()); writeU16(os, groups.size());
for(std::map<std::string, int>::const_iterator for (ItemGroupList::const_iterator
i = groups.begin(); i != groups.end(); ++i){ i = groups.begin(); i != groups.end(); ++i){
os<<serializeString(i->first); os << serializeString(i->first);
writeS16(os, i->second); writeS16(os, i->second);
} }
os<<serializeString(node_placement_prediction); os<<serializeString(node_placement_prediction);

View File

@ -21,14 +21,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define ITEMGROUP_HEADER #define ITEMGROUP_HEADER
#include <string> #include <string>
#include <map> #include "util/cpp11_container.h"
typedef std::map<std::string, int> ItemGroupList; typedef UNORDERED_MAP<std::string, int> ItemGroupList;
static inline int itemgroup_get(const ItemGroupList &groups, static inline int itemgroup_get(const ItemGroupList &groups,
const std::string &name) const std::string &name)
{ {
std::map<std::string, int>::const_iterator i = groups.find(name); ItemGroupList::const_iterator i = groups.find(name);
if(i == groups.end()) if(i == groups.end())
return 0; return 0;
return i->second; return i->second;

View File

@ -42,9 +42,8 @@ void MapSector::deleteBlocks()
m_block_cache = NULL; m_block_cache = NULL;
// Delete all // Delete all
for(std::map<s16, MapBlock*>::iterator i = m_blocks.begin(); for (UNORDERED_MAP<s16, MapBlock*>::iterator i = m_blocks.begin();
i != m_blocks.end(); ++i) i != m_blocks.end(); ++i) {
{
delete i->second; delete i->second;
} }
@ -56,20 +55,13 @@ MapBlock * MapSector::getBlockBuffered(s16 y)
{ {
MapBlock *block; MapBlock *block;
if(m_block_cache != NULL && y == m_block_cache_y){ if (m_block_cache != NULL && y == m_block_cache_y) {
return m_block_cache; return m_block_cache;
} }
// If block doesn't exist, return NULL // If block doesn't exist, return NULL
std::map<s16, MapBlock*>::iterator n = m_blocks.find(y); UNORDERED_MAP<s16, MapBlock*>::iterator n = m_blocks.find(y);
if(n == m_blocks.end()) block = (n != m_blocks.end() ? n->second : NULL);
{
block = NULL;
}
// If block exists, return it
else{
block = n->second;
}
// Cache the last result // Cache the last result
m_block_cache_y = y; m_block_cache_y = y;
@ -135,18 +127,12 @@ void MapSector::deleteBlock(MapBlock *block)
void MapSector::getBlocks(MapBlockVect &dest) void MapSector::getBlocks(MapBlockVect &dest)
{ {
for(std::map<s16, MapBlock*>::iterator bi = m_blocks.begin(); for (UNORDERED_MAP<s16, MapBlock*>::iterator bi = m_blocks.begin();
bi != m_blocks.end(); ++bi) bi != m_blocks.end(); ++bi) {
{
dest.push_back(bi->second); dest.push_back(bi->second);
} }
} }
bool MapSector::empty()
{
return m_blocks.empty();
}
/* /*
ServerMapSector ServerMapSector
*/ */

View File

@ -63,7 +63,7 @@ class MapSector
void getBlocks(MapBlockVect &dest); void getBlocks(MapBlockVect &dest);
bool empty(); bool empty() const { return m_blocks.empty(); }
// Always false at the moment, because sector contains no metadata. // Always false at the moment, because sector contains no metadata.
bool differs_from_disk; bool differs_from_disk;
@ -71,7 +71,7 @@ class MapSector
protected: protected:
// The pile of MapBlocks // The pile of MapBlocks
std::map<s16, MapBlock*> m_blocks; UNORDERED_MAP<s16, MapBlock*> m_blocks;
Map *m_parent; Map *m_parent;
// Position on parent (in MapBlock widths) // Position on parent (in MapBlock widths)

View File

@ -564,14 +564,14 @@ void Schematic::applyProbabilities(v3s16 p0,
void generate_nodelist_and_update_ids(MapNode *nodes, size_t nodecount, void generate_nodelist_and_update_ids(MapNode *nodes, size_t nodecount,
std::vector<std::string> *usednodes, INodeDefManager *ndef) std::vector<std::string> *usednodes, INodeDefManager *ndef)
{ {
std::map<content_t, content_t> nodeidmap; UNORDERED_MAP<content_t, content_t> nodeidmap;
content_t numids = 0; content_t numids = 0;
for (size_t i = 0; i != nodecount; i++) { for (size_t i = 0; i != nodecount; i++) {
content_t id; content_t id;
content_t c = nodes[i].getContent(); content_t c = nodes[i].getContent();
std::map<content_t, content_t>::const_iterator it = nodeidmap.find(c); UNORDERED_MAP<content_t, content_t>::const_iterator it = nodeidmap.find(c);
if (it == nodeidmap.end()) { if (it == nodeidmap.end()) {
id = numids; id = numids;
numids++; numids++;

View File

@ -1063,8 +1063,7 @@ void push_flags_string(lua_State *L, FlagDesc *flagdesc, u32 flags, u32 flagmask
/******************************************************************************/ /******************************************************************************/
/******************************************************************************/ /******************************************************************************/
void read_groups(lua_State *L, int index, void read_groups(lua_State *L, int index, ItemGroupList &result)
std::map<std::string, int> &result)
{ {
if (!lua_istable(L,index)) if (!lua_istable(L,index))
return; return;
@ -1083,11 +1082,10 @@ void read_groups(lua_State *L, int index,
} }
/******************************************************************************/ /******************************************************************************/
void push_groups(lua_State *L, const std::map<std::string, int> &groups) void push_groups(lua_State *L, const ItemGroupList &groups)
{ {
lua_newtable(L); lua_newtable(L);
std::map<std::string, int>::const_iterator it; for (ItemGroupList::const_iterator it = groups.begin(); it != groups.end(); ++it) {
for (it = groups.begin(); it != groups.end(); ++it) {
lua_pushnumber(L, it->second); lua_pushnumber(L, it->second);
lua_setfield(L, -2, it->first.c_str()); lua_setfield(L, -2, it->first.c_str());
} }

View File

@ -33,11 +33,11 @@ extern "C" {
} }
#include <iostream> #include <iostream>
#include <map>
#include <vector> #include <vector>
#include "irrlichttypes_bloated.h" #include "irrlichttypes_bloated.h"
#include "util/string.h" #include "util/string.h"
#include "itemgroup.h"
namespace Json { class Value; } namespace Json { class Value; }
@ -106,10 +106,10 @@ void pushnode (lua_State *L, const MapNode &n,
NodeBox read_nodebox (lua_State *L, int index); NodeBox read_nodebox (lua_State *L, int index);
void read_groups (lua_State *L, int index, void read_groups (lua_State *L, int index,
std::map<std::string, int> &result); ItemGroupList &result);
void push_groups (lua_State *L, void push_groups (lua_State *L,
const std::map<std::string, int> &groups); const ItemGroupList &groups);
//TODO rename to "read_enum_field" //TODO rename to "read_enum_field"
int getenumfield (lua_State *L, int table, int getenumfield (lua_State *L, int table,

View File

@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define C_CONVERTER_H_ #define C_CONVERTER_H_
#include <vector> #include <vector>
#include <map> #include "util/cpp11_container.h"
#include "irrlichttypes_bloated.h" #include "irrlichttypes_bloated.h"
#include "common/c_types.h" #include "common/c_types.h"
@ -60,7 +60,7 @@ bool getintfield(lua_State *L, int table,
bool getintfield(lua_State *L, int table, bool getintfield(lua_State *L, int table,
const char *fieldname, u32 &result); const char *fieldname, u32 &result);
void read_groups(lua_State *L, int index, void read_groups(lua_State *L, int index,
std::map<std::string, int> &result); UNORDERED_MAP<std::string, int> &result);
bool getboolfield(lua_State *L, int table, bool getboolfield(lua_State *L, int table,
const char *fieldname, bool &result); const char *fieldname, bool &result);
bool getfloatfield(lua_State *L, int table, bool getfloatfield(lua_State *L, int table,

View File

@ -220,7 +220,7 @@ int ModApiUtil::l_write_json(lua_State *L)
int ModApiUtil::l_get_dig_params(lua_State *L) int ModApiUtil::l_get_dig_params(lua_State *L)
{ {
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
std::map<std::string, int> groups; ItemGroupList groups;
read_groups(L, 1, groups); read_groups(L, 1, groups);
ToolCapabilities tp = read_tool_capabilities(L, 2); ToolCapabilities tp = read_tool_capabilities(L, 2);
if(lua_isnoneornil(L, 3)) if(lua_isnoneornil(L, 3))
@ -235,7 +235,7 @@ int ModApiUtil::l_get_dig_params(lua_State *L)
int ModApiUtil::l_get_hit_params(lua_State *L) int ModApiUtil::l_get_hit_params(lua_State *L)
{ {
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
std::map<std::string, int> groups; UNORDERED_MAP<std::string, int> groups;
read_groups(L, 1, groups); read_groups(L, 1, groups);
ToolCapabilities tp = read_tool_capabilities(L, 2); ToolCapabilities tp = read_tool_capabilities(L, 2);
if(lua_isnoneornil(L, 3)) if(lua_isnoneornil(L, 3))

View File

@ -669,7 +669,7 @@ void Server::AsyncRunStep(bool initial_step)
MutexAutoLock envlock(m_env_mutex); MutexAutoLock envlock(m_env_mutex);
m_clients.lock(); m_clients.lock();
std::map<u16, RemoteClient*> clients = m_clients.getClientList(); UNORDERED_MAP<u16, RemoteClient*> clients = m_clients.getClientList();
ScopeProfiler sp(g_profiler, "Server: checking added and deleted objs"); ScopeProfiler sp(g_profiler, "Server: checking added and deleted objs");
// Radius inside which objects are active // Radius inside which objects are active
@ -685,8 +685,7 @@ void Server::AsyncRunStep(bool initial_step)
if (player_radius == 0 && is_transfer_limited) if (player_radius == 0 && is_transfer_limited)
player_radius = radius; player_radius = radius;
for (std::map<u16, RemoteClient*>::iterator for (UNORDERED_MAP<u16, RemoteClient*>::iterator i = clients.begin();
i = clients.begin();
i != clients.end(); ++i) { i != clients.end(); ++i) {
RemoteClient *client = i->second; RemoteClient *client = i->second;
@ -696,7 +695,7 @@ void Server::AsyncRunStep(bool initial_step)
continue; continue;
Player *player = m_env->getPlayer(client->peer_id); Player *player = m_env->getPlayer(client->peer_id);
if(player == NULL) { if (player == NULL) {
// This can happen if the client timeouts somehow // This can happen if the client timeouts somehow
/*warningstream<<FUNCTION_NAME<<": Client " /*warningstream<<FUNCTION_NAME<<": Client "
<<client->peer_id <<client->peer_id
@ -817,10 +816,9 @@ void Server::AsyncRunStep(bool initial_step)
} }
m_clients.lock(); m_clients.lock();
std::map<u16, RemoteClient*> clients = m_clients.getClientList(); UNORDERED_MAP<u16, RemoteClient*> clients = m_clients.getClientList();
// Route data to every client // Route data to every client
for (std::map<u16, RemoteClient*>::iterator for (UNORDERED_MAP<u16, RemoteClient*>::iterator i = clients.begin();
i = clients.begin();
i != clients.end(); ++i) { i != clients.end(); ++i) {
RemoteClient *client = i->second; RemoteClient *client = i->second;
std::string reliable_data; std::string reliable_data;

View File

@ -196,9 +196,8 @@ void Settings::writeLines(std::ostream &os, u32 tab_depth) const
{ {
MutexAutoLock lock(m_mutex); MutexAutoLock lock(m_mutex);
for (std::map<std::string, SettingsEntry>::const_iterator for (SettingEntries::const_iterator it = m_settings.begin();
it = m_settings.begin(); it != m_settings.end(); ++it)
it != m_settings.end(); ++it)
printEntry(os, it->first, it->second, tab_depth); printEntry(os, it->first, it->second, tab_depth);
} }
@ -231,7 +230,7 @@ void Settings::printEntry(std::ostream &os, const std::string &name,
bool Settings::updateConfigObject(std::istream &is, std::ostream &os, bool Settings::updateConfigObject(std::istream &is, std::ostream &os,
const std::string &end, u32 tab_depth) const std::string &end, u32 tab_depth)
{ {
std::map<std::string, SettingsEntry>::const_iterator it; SettingEntries::const_iterator it;
std::set<std::string> present_entries; std::set<std::string> present_entries;
std::string line, name, value; std::string line, name, value;
bool was_modified = false; bool was_modified = false;
@ -381,7 +380,7 @@ const SettingsEntry &Settings::getEntry(const std::string &name) const
{ {
MutexAutoLock lock(m_mutex); MutexAutoLock lock(m_mutex);
std::map<std::string, SettingsEntry>::const_iterator n; SettingEntries::const_iterator n;
if ((n = m_settings.find(name)) == m_settings.end()) { if ((n = m_settings.find(name)) == m_settings.end()) {
if ((n = m_defaults.find(name)) == m_defaults.end()) if ((n = m_defaults.find(name)) == m_defaults.end())
throw SettingNotFoundException("Setting [" + name + "] not found."); throw SettingNotFoundException("Setting [" + name + "] not found.");
@ -572,9 +571,8 @@ bool Settings::exists(const std::string &name) const
std::vector<std::string> Settings::getNames() const std::vector<std::string> Settings::getNames() const
{ {
std::vector<std::string> names; std::vector<std::string> names;
for (std::map<std::string, SettingsEntry>::const_iterator for (SettingEntries::const_iterator i = m_settings.begin();
i = m_settings.begin(); i != m_settings.end(); ++i) {
i != m_settings.end(); ++i) {
names.push_back(i->first); names.push_back(i->first);
} }
return names; return names;
@ -880,7 +878,7 @@ bool Settings::remove(const std::string &name)
{ {
MutexAutoLock lock(m_mutex); MutexAutoLock lock(m_mutex);
std::map<std::string, SettingsEntry>::iterator it = m_settings.find(name); SettingEntries::iterator it = m_settings.find(name);
if (it != m_settings.end()) { if (it != m_settings.end()) {
delete it->second.group; delete it->second.group;
m_settings.erase(it); m_settings.erase(it);
@ -912,7 +910,6 @@ void Settings::updateValue(const Settings &other, const std::string &name)
try { try {
std::string val = other.get(name); std::string val = other.get(name);
m_settings[name] = val; m_settings[name] = val;
} catch (SettingNotFoundException &e) { } catch (SettingNotFoundException &e) {
} }
@ -968,8 +965,9 @@ void Settings::updateNoLock(const Settings &other)
void Settings::clearNoLock() void Settings::clearNoLock()
{ {
std::map<std::string, SettingsEntry>::const_iterator it;
for (it = m_settings.begin(); it != m_settings.end(); ++it) for (SettingEntries::const_iterator it = m_settings.begin();
it != m_settings.end(); ++it)
delete it->second.group; delete it->second.group;
m_settings.clear(); m_settings.clear();
@ -978,8 +976,8 @@ void Settings::clearNoLock()
void Settings::clearDefaultsNoLock() void Settings::clearDefaultsNoLock()
{ {
std::map<std::string, SettingsEntry>::const_iterator it; for (SettingEntries::const_iterator it = m_defaults.begin();
for (it = m_defaults.begin(); it != m_defaults.end(); ++it) it != m_defaults.end(); ++it)
delete it->second.group; delete it->second.group;
m_defaults.clear(); m_defaults.clear();
} }

View File

@ -98,6 +98,8 @@ struct SettingsEntry {
bool is_group; bool is_group;
}; };
typedef UNORDERED_MAP<std::string, SettingsEntry> SettingEntries;
class Settings { class Settings {
public: public:
Settings() {} Settings() {}
@ -231,8 +233,8 @@ class Settings {
void doCallbacks(const std::string &name) const; void doCallbacks(const std::string &name) const;
std::map<std::string, SettingsEntry> m_settings; SettingEntries m_settings;
std::map<std::string, SettingsEntry> m_defaults; SettingEntries m_defaults;
SettingsCallbackMap m_callbacks; SettingsCallbackMap m_callbacks;