Skip to content

Commit befc3bb

Browse files
committedJul 24, 2017
LBM: use range based for and fixed a loop variable overloading in applyLBMs
1 parent dc9e451 commit befc3bb

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed
 

Diff for: ‎src/serverenvironment.cpp

+24-33
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ ABMWithState::ABMWithState(ActiveBlockModifier *abm_):
6969

7070
void LBMContentMapping::deleteContents()
7171
{
72-
for (std::vector<LoadingBlockModifierDef *>::iterator it = lbm_list.begin();
73-
it != lbm_list.end(); ++it) {
74-
delete *it;
72+
for (auto &it : lbm_list) {
73+
delete it;
7574
}
7675
}
7776

@@ -83,24 +82,21 @@ void LBMContentMapping::addLBM(LoadingBlockModifierDef *lbm_def, IGameDef *gamed
8382

8483
lbm_list.push_back(lbm_def);
8584

86-
for (std::set<std::string>::const_iterator it = lbm_def->trigger_contents.begin();
87-
it != lbm_def->trigger_contents.end(); ++it) {
85+
for (const std::string &nodeTrigger: lbm_def->trigger_contents) {
8886
std::set<content_t> c_ids;
89-
bool found = nodedef->getIds(*it, c_ids);
87+
bool found = nodedef->getIds(nodeTrigger, c_ids);
9088
if (!found) {
91-
content_t c_id = gamedef->allocateUnknownNodeId(*it);
89+
content_t c_id = gamedef->allocateUnknownNodeId(nodeTrigger);
9290
if (c_id == CONTENT_IGNORE) {
9391
// Seems it can't be allocated.
94-
warningstream << "Could not internalize node name \"" << *it
92+
warningstream << "Could not internalize node name \"" << nodeTrigger
9593
<< "\" while loading LBM \"" << lbm_def->name << "\"." << std::endl;
9694
continue;
9795
}
9896
c_ids.insert(c_id);
9997
}
10098

101-
for (std::set<content_t>::const_iterator iit =
102-
c_ids.begin(); iit != c_ids.end(); ++iit) {
103-
content_t c_id = *iit;
99+
for (content_t c_id : c_ids) {
104100
map[c_id].push_back(lbm_def);
105101
}
106102
}
@@ -120,13 +116,12 @@ LBMContentMapping::lookup(content_t c) const
120116

121117
LBMManager::~LBMManager()
122118
{
123-
for (std::map<std::string, LoadingBlockModifierDef *>::iterator it =
124-
m_lbm_defs.begin(); it != m_lbm_defs.end(); ++it) {
125-
delete it->second;
119+
for (auto &m_lbm_def : m_lbm_defs) {
120+
delete m_lbm_def.second;
126121
}
127-
for (lbm_lookup_map::iterator it = m_lbm_lookup.begin();
128-
it != m_lbm_lookup.end(); ++it) {
129-
(it->second).deleteContents();
122+
123+
for (auto &it : m_lbm_lookup) {
124+
(it.second).deleteContents();
130125
}
131126
}
132127

@@ -212,12 +207,11 @@ void LBMManager::loadIntroductionTimes(const std::string &times,
212207
LBMContentMapping &lbms_we_introduce_now = m_lbm_lookup[now];
213208
LBMContentMapping &lbms_running_always = m_lbm_lookup[U32_MAX];
214209

215-
for (std::map<std::string, LoadingBlockModifierDef *>::iterator it =
216-
m_lbm_defs.begin(); it != m_lbm_defs.end(); ++it) {
217-
if (it->second->run_at_every_load) {
218-
lbms_running_always.addLBM(it->second, gamedef);
210+
for (auto &m_lbm_def : m_lbm_defs) {
211+
if (m_lbm_def.second->run_at_every_load) {
212+
lbms_running_always.addLBM(m_lbm_def.second, gamedef);
219213
} else {
220-
lbms_we_introduce_now.addLBM(it->second, gamedef);
214+
lbms_we_introduce_now.addLBM(m_lbm_def.second, gamedef);
221215
}
222216
}
223217

@@ -233,18 +227,16 @@ std::string LBMManager::createIntroductionTimesString()
233227
"attempted to query on non fully set up LBMManager");
234228

235229
std::ostringstream oss;
236-
for (lbm_lookup_map::iterator it = m_lbm_lookup.begin();
237-
it != m_lbm_lookup.end(); ++it) {
238-
u32 time = it->first;
239-
std::vector<LoadingBlockModifierDef *> &lbm_list = it->second.lbm_list;
240-
for (std::vector<LoadingBlockModifierDef *>::iterator iit = lbm_list.begin();
241-
iit != lbm_list.end(); ++iit) {
230+
for (const auto &it : m_lbm_lookup) {
231+
u32 time = it.first;
232+
const std::vector<LoadingBlockModifierDef *> &lbm_list = it.second.lbm_list;
233+
for (const auto &lbm_def : lbm_list) {
242234
// Don't add if the LBM runs at every load,
243235
// then introducement time is hardcoded
244236
// and doesn't need to be stored
245-
if ((*iit)->run_at_every_load)
237+
if (lbm_def->run_at_every_load)
246238
continue;
247-
oss << (*iit)->name << "~" << time << ";";
239+
oss << lbm_def->name << "~" << time << ";";
248240
}
249241
}
250242
return oss.str();
@@ -272,9 +264,8 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp)
272264
iit->second.lookup(c);
273265
if (!lbm_list)
274266
continue;
275-
for (std::vector<LoadingBlockModifierDef *>::const_iterator iit =
276-
lbm_list->begin(); iit != lbm_list->end(); ++iit) {
277-
(*iit)->trigger(env, pos + pos_of_block, n);
267+
for (auto lbmdef : *lbm_list) {
268+
lbmdef->trigger(env, pos + pos_of_block, n);
278269
}
279270
}
280271
}

0 commit comments

Comments
 (0)
Please sign in to comment.