@@ -767,7 +767,7 @@ class ABMHandler
767
767
{
768
768
private:
769
769
ServerEnvironment *m_env;
770
- std::map< content_t , std::vector<ActiveABM> > m_aabms;
770
+ std::vector< std::vector<ActiveABM> * > m_aabms;
771
771
public:
772
772
ABMHandler (std::vector<ABMWithState> &abms,
773
773
float dtime_s, ServerEnvironment *env,
@@ -826,18 +826,22 @@ class ABMHandler
826
826
k != ids.end (); ++k)
827
827
{
828
828
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);
837
834
}
838
835
}
839
836
}
840
837
}
838
+
839
+ ~ABMHandler ()
840
+ {
841
+ for (size_t i = 0 ; i < m_aabms.size (); i++)
842
+ delete m_aabms[i];
843
+ }
844
+
841
845
// Find out how many objects the given block and its neighbours contain.
842
846
// Returns the number of objects in the block, and also in 'wider' the
843
847
// number of objects in the block and all its neighbours. The latter
@@ -886,13 +890,11 @@ class ABMHandler
886
890
content_t c = n.getContent ();
887
891
v3s16 p = p0 + block->getPosRelative ();
888
892
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])
892
894
continue ;
893
895
894
896
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) {
896
898
if (myrand () % i->chance != 0 )
897
899
continue ;
898
900
0 commit comments