aboutsummaryrefslogtreecommitdiff
path: root/src/environment.cpp
diff options
context:
space:
mode:
authorWeblate <42@minetest.ru>2013-05-01 15:33:15 +0200
committerWeblate <42@minetest.ru>2013-05-01 15:33:15 +0200
commit97cddd1b960e3b60ce74ff9ad16307b39676144e (patch)
tree0547ab284acc0fdf8aad2a36643be6f78f786ef1 /src/environment.cpp
parentf1f2004cb9efb026625b192b404064c26ceb6d5f (diff)
parent898a4e441fc0245aaf4821ff5e3dad0daccda3b5 (diff)
downloadminetest-97cddd1b960e3b60ce74ff9ad16307b39676144e.tar.gz
minetest-97cddd1b960e3b60ce74ff9ad16307b39676144e.tar.bz2
minetest-97cddd1b960e3b60ce74ff9ad16307b39676144e.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/environment.cpp')
-rw-r--r--src/environment.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index fc7972b2c..438c9ef4f 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -1295,16 +1295,17 @@ bool isFreeServerActiveObjectId(u16 id,
u16 getFreeServerActiveObjectId(
std::map<u16, ServerActiveObject*> &objects)
{
- u16 new_id = 1;
+ //try to reuse id's as late as possible
+ static u16 last_used_id = 0;
+ u16 startid = last_used_id;
for(;;)
{
- if(isFreeServerActiveObjectId(new_id, objects))
- return new_id;
+ last_used_id ++;
+ if(isFreeServerActiveObjectId(last_used_id, objects))
+ return last_used_id;
- if(new_id == 65535)
+ if(last_used_id == startid)
return 0;
-
- new_id++;
}
}
@@ -2296,16 +2297,17 @@ bool isFreeClientActiveObjectId(u16 id,
u16 getFreeClientActiveObjectId(
std::map<u16, ClientActiveObject*> &objects)
{
- u16 new_id = 1;
+ //try to reuse id's as late as possible
+ static u16 last_used_id = 0;
+ u16 startid = last_used_id;
for(;;)
{
- if(isFreeClientActiveObjectId(new_id, objects))
- return new_id;
+ last_used_id ++;
+ if(isFreeClientActiveObjectId(last_used_id, objects))
+ return last_used_id;
- if(new_id == 65535)
+ if(last_used_id == startid)
return 0;
-
- new_id++;
}
}