Skip to content

Commit 155288e

Browse files
nerzhulsfan5
authored andcommittedOct 6, 2016
use unordered containers where possible (patch 4 on X)
Also remove some unused parameters/functions
1 parent b66a5d2 commit 155288e

13 files changed

+63
-99
lines changed
 

‎src/content_sao.cpp

+18-10
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,10 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
347347

348348
if(m_bone_position_sent == false){
349349
m_bone_position_sent = true;
350-
for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
351-
std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y);
350+
for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
351+
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
352+
std::string str = gob_cmd_update_bone_position((*ii).first,
353+
(*ii).second.X, (*ii).second.Y);
352354
// create message and add to list
353355
ActiveObjectMessage aom(getId(), true, str);
354356
m_messages_out.push(aom);
@@ -383,8 +385,10 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
383385
os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
384386
os<<serializeLongString(gob_cmd_update_animation(
385387
m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
386-
for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
387-
os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
388+
for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
389+
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
390+
os << serializeLongString(gob_cmd_update_bone_position((*ii).first,
391+
(*ii).second.X, (*ii).second.Y)); // m_bone_position.size
388392
}
389393
os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
390394
}
@@ -862,7 +866,8 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
862866
os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
863867
os<<serializeLongString(gob_cmd_update_animation(
864868
m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
865-
for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
869+
for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
870+
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
866871
os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
867872
}
868873
os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
@@ -1007,19 +1012,22 @@ void PlayerSAO::step(float dtime, bool send_recommended)
10071012
m_messages_out.push(aom);
10081013
}
10091014

1010-
if(m_bone_position_sent == false){
1015+
if (!m_bone_position_sent) {
10111016
m_bone_position_sent = true;
1012-
for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
1013-
std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y);
1017+
for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
1018+
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
1019+
std::string str = gob_cmd_update_bone_position((*ii).first,
1020+
(*ii).second.X, (*ii).second.Y);
10141021
// create message and add to list
10151022
ActiveObjectMessage aom(getId(), true, str);
10161023
m_messages_out.push(aom);
10171024
}
10181025
}
10191026

1020-
if(m_attachment_sent == false){
1027+
if (!m_attachment_sent){
10211028
m_attachment_sent = true;
1022-
std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation);
1029+
std::string str = gob_cmd_update_attachment(m_attachment_parent_id,
1030+
m_attachment_bone, m_attachment_position, m_attachment_rotation);
10231031
// create message and add to list
10241032
ActiveObjectMessage aom(getId(), true, str);
10251033
m_messages_out.push(aom);

‎src/content_sao.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class LuaEntitySAO : public ServerActiveObject
112112
bool m_animation_loop;
113113
bool m_animation_sent;
114114

115-
std::map<std::string, core::vector2d<v3f> > m_bone_position;
115+
UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
116116
bool m_bone_position_sent;
117117

118118
int m_attachment_parent_id;
@@ -321,7 +321,8 @@ class PlayerSAO : public ServerActiveObject
321321
bool m_animation_loop;
322322
bool m_animation_sent;
323323

324-
std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
324+
// Stores position and rotation for each bone name
325+
UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
325326
bool m_bone_position_sent;
326327

327328
int m_attachment_parent_id;

‎src/guiFormSpecMenu.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,6 @@ class GUIFormSpecMenu : public GUIModalMenu
409409
std::vector<std::pair<FieldSpec, std::vector<std::string> > > m_dropdowns;
410410

411411
ItemSpec *m_selected_item;
412-
f32 m_timer1;
413-
f32 m_timer2;
414412
u32 m_selected_amount;
415413
bool m_selected_dragging;
416414

@@ -462,7 +460,7 @@ class GUIFormSpecMenu : public GUIModalMenu
462460
GUITable::TableOptions table_options;
463461
GUITable::TableColumns table_columns;
464462
// used to restore table selection/scroll/treeview state
465-
std::map<std::string, GUITable::DynamicData> table_dyndata;
463+
UNORDERED_MAP<std::string, GUITable::DynamicData> table_dyndata;
466464
} parserData;
467465

468466
typedef struct {

‎src/map.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3232
#include "voxel.h"
3333
#include "modifiedstate.h"
3434
#include "util/container.h"
35+
#include "util/cpp11_container.h"
3536
#include "nodetimer.h"
3637
#include "map_settings_manager.h"
3738

‎src/mapblock_mesh.cpp

+10-14
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
10331033
m_enable_shaders = data->m_use_shaders;
10341034
m_use_tangent_vertices = data->m_use_tangent_vertices;
10351035
m_enable_vbo = g_settings->getBool("enable_vbo");
1036-
1036+
10371037
if (g_settings->getBool("enable_minimap")) {
10381038
m_minimap_mapblock = new MinimapMapblock;
10391039
m_minimap_mapblock->getMinimapNodes(
@@ -1298,10 +1298,8 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
12981298
// Cracks
12991299
if(crack != m_last_crack)
13001300
{
1301-
for(std::map<u32, std::string>::iterator
1302-
i = m_crack_materials.begin();
1303-
i != m_crack_materials.end(); ++i)
1304-
{
1301+
for (UNORDERED_MAP<u32, std::string>::iterator i = m_crack_materials.begin();
1302+
i != m_crack_materials.end(); ++i) {
13051303
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
13061304
std::string basename = i->second;
13071305

@@ -1315,9 +1313,9 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
13151313

13161314
// If the current material is also animated,
13171315
// update animation info
1318-
std::map<u32, TileSpec>::iterator anim_iter =
1319-
m_animation_tiles.find(i->first);
1320-
if(anim_iter != m_animation_tiles.end()){
1316+
UNORDERED_MAP<u32, TileSpec>::iterator anim_iter =
1317+
m_animation_tiles.find(i->first);
1318+
if (anim_iter != m_animation_tiles.end()){
13211319
TileSpec &tile = anim_iter->second;
13221320
tile.texture = new_texture;
13231321
tile.texture_id = new_texture_id;
@@ -1330,10 +1328,8 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
13301328
}
13311329

13321330
// Texture animation
1333-
for(std::map<u32, TileSpec>::iterator
1334-
i = m_animation_tiles.begin();
1335-
i != m_animation_tiles.end(); ++i)
1336-
{
1331+
for (UNORDERED_MAP<u32, TileSpec>::iterator i = m_animation_tiles.begin();
1332+
i != m_animation_tiles.end(); ++i) {
13371333
const TileSpec &tile = i->second;
13381334
// Figure out current frame
13391335
int frameoffset = m_animation_frame_offsets[i->first];
@@ -1443,7 +1439,7 @@ void MeshCollector::append(const TileSpec &tile,
14431439
vertices[i].Color, vertices[i].TCoords);
14441440
p->vertices.push_back(vert);
14451441
}
1446-
}
1442+
}
14471443

14481444
for (u32 i = 0; i < numIndices; i++) {
14491445
u32 j = indices[i] + vertex_count;
@@ -1499,7 +1495,7 @@ void MeshCollector::append(const TileSpec &tile,
14991495
vertices[i].Normal, c, vertices[i].TCoords);
15001496
p->vertices.push_back(vert);
15011497
}
1502-
}
1498+
}
15031499

15041500
for (u32 i = 0; i < numIndices; i++) {
15051501
u32 j = indices[i] + vertex_count;

‎src/mapblock_mesh.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "irrlichttypes_extrabloated.h"
2424
#include "client/tile.h"
2525
#include "voxel.h"
26+
#include "util/cpp11_container.h"
2627
#include <map>
2728

2829
class IGameDef;
@@ -121,7 +122,7 @@ class MapBlockMesh
121122
if(m_animation_force_timer > 0)
122123
m_animation_force_timer--;
123124
}
124-
125+
125126
void updateCameraOffset(v3s16 camera_offset);
126127

127128
private:
@@ -144,20 +145,20 @@ class MapBlockMesh
144145
// Last crack value passed to animate()
145146
int m_last_crack;
146147
// Maps mesh buffer (i.e. material) indices to base texture names
147-
std::map<u32, std::string> m_crack_materials;
148+
UNORDERED_MAP<u32, std::string> m_crack_materials;
148149

149150
// Animation info: texture animationi
150151
// Maps meshbuffers to TileSpecs
151-
std::map<u32, TileSpec> m_animation_tiles;
152-
std::map<u32, int> m_animation_frames; // last animation frame
153-
std::map<u32, int> m_animation_frame_offsets;
154-
152+
UNORDERED_MAP<u32, TileSpec> m_animation_tiles;
153+
UNORDERED_MAP<u32, int> m_animation_frames; // last animation frame
154+
UNORDERED_MAP<u32, int> m_animation_frame_offsets;
155+
155156
// Animation info: day/night transitions
156157
// Last daynight_ratio value passed to animate()
157158
u32 m_last_daynight_ratio;
158159
// For each meshbuffer, maps vertex indices to (day,night) pairs
159160
std::map<u32, std::map<u32, std::pair<u8, u8> > > m_daynight_diffs;
160-
161+
161162
// Camera offset info -> do we have to translate the mesh?
162163
v3s16 m_camera_offset;
163164
};

‎src/network/serverpackethandler.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1693,9 +1693,7 @@ void Server::handleCommand_RemovedSounds(NetworkPacket* pkt)
16931693

16941694
*pkt >> id;
16951695

1696-
std::map<s32, ServerPlayingSound>::iterator i =
1697-
m_playing_sounds.find(id);
1698-
1696+
UNORDERED_MAP<s32, ServerPlayingSound>::iterator i = m_playing_sounds.find(id);
16991697
if (i == m_playing_sounds.end())
17001698
continue;
17011699

‎src/script/cpp_api/s_async.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ bool AsyncEngine::registerFunction(const char* name, lua_CFunction func)
8181
if (initDone) {
8282
return false;
8383
}
84+
8485
functionList[name] = func;
8586
return true;
8687
}
@@ -203,7 +204,7 @@ void AsyncEngine::pushFinishedJobs(lua_State* L) {
203204
/******************************************************************************/
204205
void AsyncEngine::prepareEnvironment(lua_State* L, int top)
205206
{
206-
for (std::map<std::string, lua_CFunction>::iterator it = functionList.begin();
207+
for (UNORDERED_MAP<std::string, lua_CFunction>::iterator it = functionList.begin();
207208
it != functionList.end(); it++) {
208209
lua_pushstring(L, it->first.c_str());
209210
lua_pushcfunction(L, it->second);

‎src/script/cpp_api/s_async.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class AsyncEngine {
132132
bool initDone;
133133

134134
// Internal store for registred functions
135-
std::map<std::string, lua_CFunction> functionList;
135+
UNORDERED_MAP<std::string, lua_CFunction> functionList;
136136

137137
// Internal counter to create job IDs
138138
unsigned int jobIdCounter;

‎src/server.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ void Server::AsyncRunStep(bool initial_step)
868868
m_clients.unlock();
869869

870870
// Clear buffered_messages
871-
for(UNORDERED_MAP<u16, std::vector<ActiveObjectMessage>* >::iterator
871+
for (UNORDERED_MAP<u16, std::vector<ActiveObjectMessage>* >::iterator
872872
i = buffered_messages.begin();
873873
i != buffered_messages.end(); ++i) {
874874
delete i->second;
@@ -2016,16 +2016,15 @@ s32 Server::playSound(const SimpleSoundSpec &spec,
20162016
void Server::stopSound(s32 handle)
20172017
{
20182018
// Get sound reference
2019-
std::map<s32, ServerPlayingSound>::iterator i =
2020-
m_playing_sounds.find(handle);
2021-
if(i == m_playing_sounds.end())
2019+
UNORDERED_MAP<s32, ServerPlayingSound>::iterator i = m_playing_sounds.find(handle);
2020+
if (i == m_playing_sounds.end())
20222021
return;
20232022
ServerPlayingSound &psound = i->second;
20242023

20252024
NetworkPacket pkt(TOCLIENT_STOP_SOUND, 4);
20262025
pkt << handle;
20272026

2028-
for(std::set<u16>::iterator i = psound.clients.begin();
2027+
for (UNORDERED_SET<u16>::iterator i = psound.clients.begin();
20292028
i != psound.clients.end(); ++i) {
20302029
// Send as reliable
20312030
m_clients.send(*i, 0, &pkt, true);
@@ -2322,7 +2321,7 @@ void Server::sendMediaAnnouncement(u16 peer_id)
23222321
NetworkPacket pkt(TOCLIENT_ANNOUNCE_MEDIA, 0, peer_id);
23232322
pkt << (u16) m_media.size();
23242323

2325-
for (std::map<std::string, MediaInfo>::iterator i = m_media.begin();
2324+
for (UNORDERED_MAP<std::string, MediaInfo>::iterator i = m_media.begin();
23262325
i != m_media.end(); ++i) {
23272326
pkt << i->first << i->second.sha1_digest;
23282327
}
@@ -2367,7 +2366,7 @@ void Server::sendRequestedMedia(u16 peer_id,
23672366
i != tosend.end(); ++i) {
23682367
const std::string &name = *i;
23692368

2370-
if(m_media.find(name) == m_media.end()) {
2369+
if (m_media.find(name) == m_media.end()) {
23712370
errorstream<<"Server::sendRequestedMedia(): Client asked for "
23722371
<<"unknown file \""<<(name)<<"\""<<std::endl;
23732372
continue;
@@ -2628,13 +2627,11 @@ void Server::DeleteClient(u16 peer_id, ClientDeletionReason reason)
26282627
/*
26292628
Clear references to playing sounds
26302629
*/
2631-
for(std::map<s32, ServerPlayingSound>::iterator
2632-
i = m_playing_sounds.begin();
2633-
i != m_playing_sounds.end();)
2634-
{
2630+
for (UNORDERED_MAP<s32, ServerPlayingSound>::iterator
2631+
i = m_playing_sounds.begin(); i != m_playing_sounds.end();) {
26352632
ServerPlayingSound &psound = i->second;
26362633
psound.clients.erase(peer_id);
2637-
if(psound.clients.empty())
2634+
if (psound.clients.empty())
26382635
m_playing_sounds.erase(i++);
26392636
else
26402637
++i;

‎src/server.h

+6-10
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct ServerSoundParams
157157
struct ServerPlayingSound
158158
{
159159
ServerSoundParams params;
160-
std::set<u16> clients; // peer ids
160+
UNORDERED_SET<u16> clients; // peer ids
161161
};
162162

163163
class Server : public con::PeerHandler, public MapEventReceiver,
@@ -243,11 +243,9 @@ class Server : public con::PeerHandler, public MapEventReceiver,
243243
std::wstring getStatusString();
244244

245245
// read shutdown state
246-
inline bool getShutdownRequested()
247-
{ return m_shutdown_requested; }
246+
inline bool getShutdownRequested() const { return m_shutdown_requested; }
248247

249248
// request server to shutdown
250-
inline void requestShutdown() { m_shutdown_requested = true; }
251249
void requestShutdown(const std::string &msg, bool reconnect)
252250
{
253251
m_shutdown_requested = true;
@@ -323,8 +321,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
323321
const ModSpec* getModSpec(const std::string &modname) const;
324322
void getModNames(std::vector<std::string> &modlist);
325323
std::string getBuiltinLuaPath();
326-
inline std::string getWorldPath() const
327-
{ return m_path_world; }
324+
inline std::string getWorldPath() const { return m_path_world; }
328325

329326
inline bool isSingleplayer()
330327
{ return m_simple_singleplayer_mode; }
@@ -356,8 +353,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
356353
bool setSky(Player *player, const video::SColor &bgcolor,
357354
const std::string &type, const std::vector<std::string> &params);
358355

359-
bool overrideDayNightRatio(Player *player, bool do_override,
360-
float brightness);
356+
bool overrideDayNightRatio(Player *player, bool do_override, float brightness);
361357

362358
/* con::PeerHandler implementation. */
363359
void peerAdded(con::Peer *peer);
@@ -654,12 +650,12 @@ class Server : public con::PeerHandler, public MapEventReceiver,
654650
u16 m_ignore_map_edit_events_peer_id;
655651

656652
// media files known to server
657-
std::map<std::string,MediaInfo> m_media;
653+
UNORDERED_MAP<std::string, MediaInfo> m_media;
658654

659655
/*
660656
Sounds
661657
*/
662-
std::map<s32, ServerPlayingSound> m_playing_sounds;
658+
UNORDERED_MAP<s32, ServerPlayingSound> m_playing_sounds;
663659
s32 m_next_sound_id;
664660

665661
/*

‎src/util/numeric.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2727
#include <string.h>
2828
#include <iostream>
2929

30-
std::map<u16, std::vector<v3s16> > FacePositionCache::m_cache;
30+
UNORDERED_MAP<u16, std::vector<v3s16> > FacePositionCache::m_cache;
3131
Mutex FacePositionCache::m_cache_mutex;
3232
// Calculate the borders of a "d-radius" cube
3333
// TODO: Make it work without mutex and data races, probably thread-local

0 commit comments

Comments
 (0)
Please sign in to comment.