Skip to content

Commit

Permalink
Use std::vector instead of std::map in class ABMHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogier-5 authored and sfan5 committed Jan 4, 2017
1 parent 3f82618 commit ad10b8b
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/environment.cpp
Expand Up @@ -767,7 +767,7 @@ class ABMHandler
{ {
private: private:
ServerEnvironment *m_env; ServerEnvironment *m_env;
std::map<content_t, std::vector<ActiveABM> > m_aabms; std::vector<std::vector<ActiveABM> *> m_aabms;
public: public:
ABMHandler(std::vector<ABMWithState> &abms, ABMHandler(std::vector<ABMWithState> &abms,
float dtime_s, ServerEnvironment *env, float dtime_s, ServerEnvironment *env,
Expand Down Expand Up @@ -826,18 +826,22 @@ class ABMHandler
k != ids.end(); ++k) k != ids.end(); ++k)
{ {
content_t c = *k; content_t c = *k;
std::map<content_t, std::vector<ActiveABM> >::iterator j; if (c >= m_aabms.size())
j = m_aabms.find(c); m_aabms.resize(c + 256, (std::vector<ActiveABM> *) NULL);
if(j == m_aabms.end()){ if (!m_aabms[c])
std::vector<ActiveABM> aabmlist; m_aabms[c] = new std::vector<ActiveABM>;
m_aabms[c] = aabmlist; m_aabms[c]->push_back(aabm);
j = m_aabms.find(c);
}
j->second.push_back(aabm);
} }
} }
} }
} }

~ABMHandler()
{
for (size_t i = 0; i < m_aabms.size(); i++)
delete m_aabms[i];
}

// Find out how many objects the given block and its neighbours contain. // Find out how many objects the given block and its neighbours contain.
// Returns the number of objects in the block, and also in 'wider' the // Returns the number of objects in the block, and also in 'wider' the
// number of objects in the block and all its neighbours. The latter // number of objects in the block and all its neighbours. The latter
Expand Down Expand Up @@ -886,13 +890,11 @@ class ABMHandler
content_t c = n.getContent(); content_t c = n.getContent();
v3s16 p = p0 + block->getPosRelative(); v3s16 p = p0 + block->getPosRelative();


std::map<content_t, std::vector<ActiveABM> >::iterator j; if (!m_aabms[c])
j = m_aabms.find(c);
if(j == m_aabms.end())
continue; continue;


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


Expand Down

0 comments on commit ad10b8b

Please sign in to comment.