summaryrefslogtreecommitdiff
path: root/src/serverenvironment.cpp
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2018-03-09 08:25:48 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-03-09 23:27:26 +0100
commit2c860a6a420e16289c56f6185f333a2dd0cde386 (patch)
treea7cf1cafcc95703480f1f475c775fe57a53d35f5 /src/serverenvironment.cpp
parentdef46c6cdb73c98b6bc73d5a4655b95e8442ce2f (diff)
downloadminetest-2c860a6a420e16289c56f6185f333a2dd0cde386.tar.gz
minetest-2c860a6a420e16289c56f6185f333a2dd0cde386.tar.bz2
minetest-2c860a6a420e16289c56f6185f333a2dd0cde386.zip
ServerEnvironment & StaticObject cleanups
* isFreeServerActiveObjectId is now part of ServerEnvironment * getFreeServerActiveObjectId is now part of ServerEnvironment * StaticObject constructor now take ServerActiveObject instead of type + string. This permits to remove a big string copy in some code parts
Diffstat (limited to 'src/serverenvironment.cpp')
-rw-r--r--src/serverenvironment.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp
index ae0f397ee..8a26c0272 100644
--- a/src/serverenvironment.cpp
+++ b/src/serverenvironment.cpp
@@ -1416,26 +1416,34 @@ ServerActiveObject* ServerEnvironment::getActiveObject(u16 id)
return (n != m_active_objects.end() ? n->second : NULL);
}
-bool isFreeServerActiveObjectId(u16 id, ServerActiveObjectMap &objects)
+/**
+ * Verify if id is a free active object id
+ * @param id
+ * @return true if slot is free
+ */
+bool ServerEnvironment::isFreeServerActiveObjectId(u16 id) const
{
if (id == 0)
return false;
- return objects.find(id) == objects.end();
+ return m_active_objects.find(id) == m_active_objects.end();
}
-u16 getFreeServerActiveObjectId(ServerActiveObjectMap &objects)
+/**
+ * Retrieve the next free activeobject ID
+ * @return free activeobject ID or zero if not free ID found
+ */
+u16 ServerEnvironment::getFreeServerActiveObjectId()
{
- //try to reuse id's as late as possible
+ // try to reuse id's as late as possible
static u16 last_used_id = 0;
u16 startid = last_used_id;
- for(;;)
- {
- last_used_id ++;
- if(isFreeServerActiveObjectId(last_used_id, objects))
+ for (;;) {
+ last_used_id++;
+ if (isFreeServerActiveObjectId(last_used_id))
return last_used_id;
- if(last_used_id == startid)
+ if (last_used_id == startid)
return 0;
}
}
@@ -1623,7 +1631,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
{
assert(object); // Pre-condition
if(object->getId() == 0){
- u16 new_id = getFreeServerActiveObjectId(m_active_objects);
+ u16 new_id = getFreeServerActiveObjectId();
if(new_id == 0)
{
errorstream<<"ServerEnvironment::addActiveObjectRaw(): "
@@ -1639,7 +1647,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
<<"supplied with id "<<object->getId()<<std::endl;
}
- if(!isFreeServerActiveObjectId(object->getId(), m_active_objects)) {
+ if(!isFreeServerActiveObjectId(object->getId())) {
errorstream<<"ServerEnvironment::addActiveObjectRaw(): "
<<"id is not free ("<<object->getId()<<")"<<std::endl;
if(object->environmentDeletes())
@@ -1677,9 +1685,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
{
// Add static object to active static list of the block
v3f objectpos = object->getBasePosition();
- std::string staticdata;
- object->getStaticData(&staticdata);
- StaticObject s_obj(object->getType(), objectpos, staticdata);
+ StaticObject s_obj(object, objectpos);
// Add to the block where the object is located in
v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
MapBlock *block = m_map->emergeBlock(blockpos);
@@ -1929,9 +1935,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
// Delete from block where object was located
deleteStaticFromBlock(obj, id, MOD_REASON_STATIC_DATA_REMOVED, false);
- std::string staticdata_new;
- obj->getStaticData(&staticdata_new);
- StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
+ StaticObject s_obj(obj, objectpos);
// Save to block where object is located
saveStaticToBlock(blockpos_o, id, obj, s_obj, MOD_REASON_STATIC_DATA_ADDED);
@@ -1952,12 +1956,9 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
/*
Update the static data
*/
- if(obj->isStaticAllowed())
- {
+ if (obj->isStaticAllowed()) {
// Create new static object
- std::string staticdata_new;
- obj->getStaticData(&staticdata_new);
- StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
+ StaticObject s_obj(obj, objectpos);
bool stays_in_same_block = false;
bool data_changed = true;
@@ -1977,7 +1978,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
float save_movem = obj->getMinimumSavedMovement();
- if (static_old.data == staticdata_new &&
+ if (static_old.data == s_obj.data &&
(static_old.pos - objectpos).getLength() < save_movem)
data_changed = false;
} else {