diff --git a/src/environment.cpp b/src/environment.cpp index 5bf127a..0a5bff1 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -331,7 +331,8 @@ void ActiveBlockList::update(core::list &active_positions, m_active_block_interval_overload_skip(0), m_game_time(0), m_game_time_fraction_counter(0), - m_recommended_send_interval(0.1) + m_recommended_send_interval(0.1), + m_next_active_object_id(1) { } @@ -1238,20 +1239,21 @@ bool isFreeServerActiveObjectId(u16 id, return true; } -u16 getFreeServerActiveObjectId( +u16 ServerEnvironment::getFreeServerActiveObjectId( core::map &objects) { - u16 new_id = 1; - for(;;) + u16 new_id = m_next_active_object_id++; + // Try all of them if the wanted one is already allocated + for(u32 i=0; i<65535; i++) { + if(new_id == 0) // 0 is an invalid id + new_id++; if(isFreeServerActiveObjectId(new_id, objects)) return new_id; - - if(new_id == 65535) - return 0; - new_id++; } + // Not found + return 0; } u16 ServerEnvironment::addActiveObject(ServerActiveObject *object) diff --git a/src/environment.h b/src/environment.h index 0cc53f9..8dafe80 100644 --- a/src/environment.h +++ b/src/environment.h @@ -300,6 +300,9 @@ class ServerEnvironment : public Environment ------------------------------------------- */ + u16 getFreeServerActiveObjectId( + core::map &objects); + /* Add an active object to the environment. @@ -367,6 +370,8 @@ class ServerEnvironment : public Environment core::list m_abms; // An interval for generally sending object positions and stuff float m_recommended_send_interval; + // Preferred next active object id + u16 m_next_active_object_id; }; #ifndef SERVER