@@ -1416,26 +1416,34 @@ ServerActiveObject* ServerEnvironment::getActiveObject(u16 id)
1416
1416
return (n != m_active_objects.end () ? n->second : NULL );
1417
1417
}
1418
1418
1419
- bool isFreeServerActiveObjectId (u16 id, ServerActiveObjectMap &objects)
1419
+ /* *
1420
+ * Verify if id is a free active object id
1421
+ * @param id
1422
+ * @return true if slot is free
1423
+ */
1424
+ bool ServerEnvironment::isFreeServerActiveObjectId (u16 id) const
1420
1425
{
1421
1426
if (id == 0 )
1422
1427
return false ;
1423
1428
1424
- return objects .find (id) == objects .end ();
1429
+ return m_active_objects .find (id) == m_active_objects .end ();
1425
1430
}
1426
1431
1427
- u16 getFreeServerActiveObjectId (ServerActiveObjectMap &objects)
1432
+ /* *
1433
+ * Retrieve the next free activeobject ID
1434
+ * @return free activeobject ID or zero if not free ID found
1435
+ */
1436
+ u16 ServerEnvironment::getFreeServerActiveObjectId ()
1428
1437
{
1429
- // try to reuse id's as late as possible
1438
+ // try to reuse id's as late as possible
1430
1439
static u16 last_used_id = 0 ;
1431
1440
u16 startid = last_used_id;
1432
- for (;;)
1433
- {
1434
- last_used_id ++;
1435
- if (isFreeServerActiveObjectId (last_used_id, objects))
1441
+ for (;;) {
1442
+ last_used_id++;
1443
+ if (isFreeServerActiveObjectId (last_used_id))
1436
1444
return last_used_id;
1437
1445
1438
- if (last_used_id == startid)
1446
+ if (last_used_id == startid)
1439
1447
return 0 ;
1440
1448
}
1441
1449
}
@@ -1623,7 +1631,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
1623
1631
{
1624
1632
assert (object); // Pre-condition
1625
1633
if (object->getId () == 0 ){
1626
- u16 new_id = getFreeServerActiveObjectId (m_active_objects );
1634
+ u16 new_id = getFreeServerActiveObjectId ();
1627
1635
if (new_id == 0 )
1628
1636
{
1629
1637
errorstream<<" ServerEnvironment::addActiveObjectRaw(): "
@@ -1639,7 +1647,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
1639
1647
<<" supplied with id " <<object->getId ()<<std::endl;
1640
1648
}
1641
1649
1642
- if (!isFreeServerActiveObjectId (object->getId (), m_active_objects )) {
1650
+ if (!isFreeServerActiveObjectId (object->getId ())) {
1643
1651
errorstream<<" ServerEnvironment::addActiveObjectRaw(): "
1644
1652
<<" id is not free (" <<object->getId ()<<" )" <<std::endl;
1645
1653
if (object->environmentDeletes ())
@@ -1677,9 +1685,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
1677
1685
{
1678
1686
// Add static object to active static list of the block
1679
1687
v3f objectpos = object->getBasePosition ();
1680
- std::string staticdata;
1681
- object->getStaticData (&staticdata);
1682
- StaticObject s_obj (object->getType (), objectpos, staticdata);
1688
+ StaticObject s_obj (object, objectpos);
1683
1689
// Add to the block where the object is located in
1684
1690
v3s16 blockpos = getNodeBlockPos (floatToInt (objectpos, BS));
1685
1691
MapBlock *block = m_map->emergeBlock (blockpos);
@@ -1929,9 +1935,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
1929
1935
// Delete from block where object was located
1930
1936
deleteStaticFromBlock (obj, id, MOD_REASON_STATIC_DATA_REMOVED, false );
1931
1937
1932
- std::string staticdata_new;
1933
- obj->getStaticData (&staticdata_new);
1934
- StaticObject s_obj (obj->getType (), objectpos, staticdata_new);
1938
+ StaticObject s_obj (obj, objectpos);
1935
1939
// Save to block where object is located
1936
1940
saveStaticToBlock (blockpos_o, id, obj, s_obj, MOD_REASON_STATIC_DATA_ADDED);
1937
1941
@@ -1952,12 +1956,9 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
1952
1956
/*
1953
1957
Update the static data
1954
1958
*/
1955
- if (obj->isStaticAllowed ())
1956
- {
1959
+ if (obj->isStaticAllowed ()) {
1957
1960
// Create new static object
1958
- std::string staticdata_new;
1959
- obj->getStaticData (&staticdata_new);
1960
- StaticObject s_obj (obj->getType (), objectpos, staticdata_new);
1961
+ StaticObject s_obj (obj, objectpos);
1961
1962
1962
1963
bool stays_in_same_block = false ;
1963
1964
bool data_changed = true ;
@@ -1977,7 +1978,7 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
1977
1978
1978
1979
float save_movem = obj->getMinimumSavedMovement ();
1979
1980
1980
- if (static_old.data == staticdata_new &&
1981
+ if (static_old.data == s_obj. data &&
1981
1982
(static_old.pos - objectpos).getLength () < save_movem)
1982
1983
data_changed = false ;
1983
1984
} else {
0 commit comments