Skip to content

Commit ad10b8b

Browse files
Rogier-5sfan5
authored andcommittedJan 4, 2017
Use std::vector instead of std::map in class ABMHandler
1 parent 3f82618 commit ad10b8b

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed
 

‎src/environment.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ class ABMHandler
767767
{
768768
private:
769769
ServerEnvironment *m_env;
770-
std::map<content_t, std::vector<ActiveABM> > m_aabms;
770+
std::vector<std::vector<ActiveABM> *> m_aabms;
771771
public:
772772
ABMHandler(std::vector<ABMWithState> &abms,
773773
float dtime_s, ServerEnvironment *env,
@@ -826,18 +826,22 @@ class ABMHandler
826826
k != ids.end(); ++k)
827827
{
828828
content_t c = *k;
829-
std::map<content_t, std::vector<ActiveABM> >::iterator j;
830-
j = m_aabms.find(c);
831-
if(j == m_aabms.end()){
832-
std::vector<ActiveABM> aabmlist;
833-
m_aabms[c] = aabmlist;
834-
j = m_aabms.find(c);
835-
}
836-
j->second.push_back(aabm);
829+
if (c >= m_aabms.size())
830+
m_aabms.resize(c + 256, (std::vector<ActiveABM> *) NULL);
831+
if (!m_aabms[c])
832+
m_aabms[c] = new std::vector<ActiveABM>;
833+
m_aabms[c]->push_back(aabm);
837834
}
838835
}
839836
}
840837
}
838+
839+
~ABMHandler()
840+
{
841+
for (size_t i = 0; i < m_aabms.size(); i++)
842+
delete m_aabms[i];
843+
}
844+
841845
// Find out how many objects the given block and its neighbours contain.
842846
// Returns the number of objects in the block, and also in 'wider' the
843847
// number of objects in the block and all its neighbours. The latter
@@ -886,13 +890,11 @@ class ABMHandler
886890
content_t c = n.getContent();
887891
v3s16 p = p0 + block->getPosRelative();
888892

889-
std::map<content_t, std::vector<ActiveABM> >::iterator j;
890-
j = m_aabms.find(c);
891-
if(j == m_aabms.end())
893+
if (!m_aabms[c])
892894
continue;
893895

894896
for(std::vector<ActiveABM>::iterator
895-
i = j->second.begin(); i != j->second.end(); ++i) {
897+
i = m_aabms[c]->begin(); i != m_aabms[c]->end(); ++i) {
896898
if(myrand() % i->chance != 0)
897899
continue;
898900

0 commit comments

Comments
 (0)
Please sign in to comment.