diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2016-10-05 09:03:55 +0200 |
---|---|---|
committer | Ner'zhul <nerzhul@users.noreply.github.com> | 2016-10-05 10:53:19 +0200 |
commit | 613797a3048907275ceebe29582b9fc2761b1f25 (patch) | |
tree | 1d8f90a75c86dd3a32a72d3789bc108042d8f65d /src/clientiface.cpp | |
parent | 5f084cd98d7b3326b51320455364337539710efd (diff) | |
download | minetest-613797a3048907275ceebe29582b9fc2761b1f25.tar.gz minetest-613797a3048907275ceebe29582b9fc2761b1f25.tar.bz2 minetest-613797a3048907275ceebe29582b9fc2761b1f25.zip |
Replace various std::map with UNORDERED_MAP + various cleanups
This is part 2 for 5f084cd98d7b3326b51320455364337539710efd
Other improvements:
* Use the defined ItemGroupList when used
* make Client::checkPrivilege const
* inline some trivial functions
* Add ActiveObjectMap typedef
* Add SettingsEntries typedef
Diffstat (limited to 'src/clientiface.cpp')
-rw-r--r-- | src/clientiface.cpp | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/src/clientiface.cpp b/src/clientiface.cpp index a3a17d435..e7ad39579 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -605,11 +605,8 @@ ClientInterface::~ClientInterface() { MutexAutoLock clientslock(m_clients_mutex); - for(std::map<u16, RemoteClient*>::iterator - i = m_clients.begin(); - i != m_clients.end(); ++i) - { - + for (UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin(); + i != m_clients.end(); ++i) { // Delete client delete i->second; } @@ -621,10 +618,8 @@ std::vector<u16> ClientInterface::getClientIDs(ClientState min_state) std::vector<u16> reply; MutexAutoLock clientslock(m_clients_mutex); - for(std::map<u16, RemoteClient*>::iterator - i = m_clients.begin(); - i != m_clients.end(); ++i) - { + for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin(); + i != m_clients.end(); ++i) { if (i->second->getState() >= min_state) reply.push_back(i->second->peer_id); } @@ -691,8 +686,7 @@ void ClientInterface::sendToAll(u16 channelnum, NetworkPacket* pkt, bool reliable) { MutexAutoLock clientslock(m_clients_mutex); - for(std::map<u16, RemoteClient*>::iterator - i = m_clients.begin(); + for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin(); i != m_clients.end(); ++i) { RemoteClient *client = i->second; @@ -705,11 +699,10 @@ void ClientInterface::sendToAll(u16 channelnum, RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min) { MutexAutoLock clientslock(m_clients_mutex); - std::map<u16, RemoteClient*>::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return NULL; 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) { - std::map<u16, RemoteClient*>::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return NULL; if (n->second->getState() >= state_min) @@ -736,11 +728,10 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState stat ClientState ClientInterface::getClientState(u16 peer_id) { MutexAutoLock clientslock(m_clients_mutex); - std::map<u16, RemoteClient*>::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return CS_Invalid; return n->second->getState(); @@ -749,11 +740,10 @@ ClientState ClientInterface::getClientState(u16 peer_id) void ClientInterface::setPlayerName(u16 peer_id,std::string name) { MutexAutoLock clientslock(m_clients_mutex); - std::map<u16, RemoteClient*>::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n != m_clients.end()) + if (n != m_clients.end()) n->second->setName(name); } @@ -762,11 +752,10 @@ void ClientInterface::DeleteClient(u16 peer_id) MutexAutoLock conlock(m_clients_mutex); // Error check - std::map<u16, RemoteClient*>::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id); // The client may not exist; clients are immediately removed if their // access is denied, and this event occurs later then. - if(n == m_clients.end()) + if (n == m_clients.end()) return; /* @@ -797,10 +786,9 @@ void ClientInterface::CreateClient(u16 peer_id) MutexAutoLock conlock(m_clients_mutex); // Error check - std::map<u16, RemoteClient*>::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id); // The client shouldn't already exist - if(n != m_clients.end()) return; + if (n != m_clients.end()) return; // Create client RemoteClient *client = new RemoteClient(); @@ -814,8 +802,7 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event) MutexAutoLock clientlock(m_clients_mutex); // Error check - std::map<u16, RemoteClient*>::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id); // No client to deliver event if (n == m_clients.end()) @@ -836,8 +823,7 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id) MutexAutoLock conlock(m_clients_mutex); // Error check - std::map<u16, RemoteClient*>::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id); // No client to get version 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); // Error check - std::map<u16, RemoteClient*>::iterator n; - n = m_clients.find(peer_id); + UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id); // No client to set versions if (n == m_clients.end()) |