mirror of
https://github.com/minetest/minetest.git
synced 2024-11-05 07:13:46 +01:00
Add reason parameter to setModified and print it out to verbosestream when saving block
This commit is contained in:
parent
0ce0c8fcfb
commit
1b765b9740
@ -583,7 +583,8 @@ void spawnRandomObjects(MapBlock *block)
|
|||||||
// Add one
|
// Add one
|
||||||
block->m_static_objects.insert(0, s_obj);
|
block->m_static_objects.insert(0, s_obj);
|
||||||
delete obj;
|
delete obj;
|
||||||
block->setChangedFlag();
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"spawnRandomObjects");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -620,7 +621,8 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
|
|||||||
event.p = block->getPos();
|
event.p = block->getPos();
|
||||||
m_map->dispatchEvent(&event);
|
m_map->dispatchEvent(&event);
|
||||||
|
|
||||||
block->setChangedFlag();
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"node metadata modified in activateBlock");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Do something
|
// TODO: Do something
|
||||||
@ -671,7 +673,8 @@ void ServerEnvironment::clearAllObjects()
|
|||||||
MapBlock *block = m_map->getBlockNoCreateNoEx(obj->m_static_block);
|
MapBlock *block = m_map->getBlockNoCreateNoEx(obj->m_static_block);
|
||||||
if(block){
|
if(block){
|
||||||
block->m_static_objects.remove(id);
|
block->m_static_objects.remove(id);
|
||||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"clearAllObjects");
|
||||||
obj->m_static_exists = false;
|
obj->m_static_exists = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -722,7 +725,8 @@ void ServerEnvironment::clearAllObjects()
|
|||||||
if(num_stored != 0 || num_active != 0){
|
if(num_stored != 0 || num_active != 0){
|
||||||
block->m_static_objects.m_stored.clear();
|
block->m_static_objects.m_stored.clear();
|
||||||
block->m_static_objects.m_active.clear();
|
block->m_static_objects.m_active.clear();
|
||||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"clearAllObjects");
|
||||||
num_objs_cleared += num_stored + num_active;
|
num_objs_cleared += num_stored + num_active;
|
||||||
num_blocks_cleared++;
|
num_blocks_cleared++;
|
||||||
}
|
}
|
||||||
@ -930,7 +934,8 @@ void ServerEnvironment::step(float dtime)
|
|||||||
event.p = p;
|
event.p = p;
|
||||||
m_map->dispatchEvent(&event);
|
m_map->dispatchEvent(&event);
|
||||||
|
|
||||||
block->setChangedFlag();
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"node metadata modified in step");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1338,7 +1343,8 @@ bool ServerEnvironment::addActiveObjectAsStatic(ServerActiveObject *obj)
|
|||||||
if(block)
|
if(block)
|
||||||
{
|
{
|
||||||
block->m_static_objects.insert(0, s_obj);
|
block->m_static_objects.insert(0, s_obj);
|
||||||
block->raiseModified(MOD_STATE_WRITE_AT_UNLOAD);
|
block->raiseModified(MOD_STATE_WRITE_AT_UNLOAD,
|
||||||
|
"addActiveObjectAsStatic");
|
||||||
succeeded = true;
|
succeeded = true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@ -1503,7 +1509,8 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
|
|||||||
object->m_static_block = blockpos;
|
object->m_static_block = blockpos;
|
||||||
|
|
||||||
if(set_changed)
|
if(set_changed)
|
||||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"addActiveObjectRaw");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
errorstream<<"ServerEnvironment::addActiveObjectRaw(): "
|
errorstream<<"ServerEnvironment::addActiveObjectRaw(): "
|
||||||
@ -1557,7 +1564,8 @@ void ServerEnvironment::removeRemovedObjects()
|
|||||||
if(block)
|
if(block)
|
||||||
{
|
{
|
||||||
block->m_static_objects.remove(id);
|
block->m_static_objects.remove(id);
|
||||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"removeRemovedObjects");
|
||||||
obj->m_static_exists = false;
|
obj->m_static_exists = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1638,7 +1646,9 @@ void ServerEnvironment::activateObjects(MapBlock *block)
|
|||||||
<<"; removing all of them."<<std::endl;
|
<<"; removing all of them."<<std::endl;
|
||||||
// Clear stored list
|
// Clear stored list
|
||||||
block->m_static_objects.m_stored.clear();
|
block->m_static_objects.m_stored.clear();
|
||||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"stored list cleared in activateObjects due to "
|
||||||
|
"large amount of objects");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// A list for objects that couldn't be converted to static for some
|
// A list for objects that couldn't be converted to static for some
|
||||||
@ -1688,7 +1698,7 @@ void ServerEnvironment::activateObjects(MapBlock *block)
|
|||||||
The objects have just been activated and moved from the stored
|
The objects have just been activated and moved from the stored
|
||||||
static list to the active static list.
|
static list to the active static list.
|
||||||
As such, the block is essentially the same.
|
As such, the block is essentially the same.
|
||||||
Thus, do not call block->setChangedFlag().
|
Thus, do not call block->raiseModified(MOD_STATE_WRITE_NEEDED).
|
||||||
Otherwise there would be a huge amount of unnecessary I/O.
|
Otherwise there would be a huge amount of unnecessary I/O.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
@ -1788,7 +1798,9 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||||||
obj->m_static_exists = false;
|
obj->m_static_exists = false;
|
||||||
// Only mark block as modified if data changed considerably
|
// Only mark block as modified if data changed considerably
|
||||||
if(shall_be_written)
|
if(shall_be_written)
|
||||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"deactivateFarObjects: Static data "
|
||||||
|
"changed considerably");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1813,7 +1825,9 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||||||
|
|
||||||
// Only mark block as modified if data changed considerably
|
// Only mark block as modified if data changed considerably
|
||||||
if(shall_be_written)
|
if(shall_be_written)
|
||||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"deactivateFarObjects: Static data "
|
||||||
|
"changed considerably");
|
||||||
|
|
||||||
obj->m_static_exists = true;
|
obj->m_static_exists = true;
|
||||||
obj->m_static_block = block->getPos();
|
obj->m_static_block = block->getPos();
|
||||||
|
@ -1423,6 +1423,9 @@ void Map::timerUpdate(float dtime, float unload_timeout,
|
|||||||
if(block->getModified() != MOD_STATE_CLEAN
|
if(block->getModified() != MOD_STATE_CLEAN
|
||||||
&& save_before_unloading)
|
&& save_before_unloading)
|
||||||
{
|
{
|
||||||
|
verbosestream<<"Saving block before unloading, "
|
||||||
|
<<"modified by: "
|
||||||
|
<<block->getModifiedReason()<<std::endl;
|
||||||
saveBlock(block);
|
saveBlock(block);
|
||||||
saved_blocks_count++;
|
saved_blocks_count++;
|
||||||
}
|
}
|
||||||
@ -2281,7 +2284,8 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
|
|||||||
/*
|
/*
|
||||||
Set block as modified
|
Set block as modified
|
||||||
*/
|
*/
|
||||||
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"finishBlockMake updateDayNightDiff");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2849,6 +2853,9 @@ void ServerMap::save(bool only_changed)
|
|||||||
if(block->getModified() >= MOD_STATE_WRITE_NEEDED
|
if(block->getModified() >= MOD_STATE_WRITE_NEEDED
|
||||||
|| only_changed == false)
|
|| only_changed == false)
|
||||||
{
|
{
|
||||||
|
verbosestream<<"Saving block because of MOD_STATE_WRITE_NEEDED, "
|
||||||
|
<<"modified by: "
|
||||||
|
<<block->getModifiedReason()<<std::endl;
|
||||||
saveBlock(block);
|
saveBlock(block);
|
||||||
block_count++;
|
block_count++;
|
||||||
|
|
||||||
|
@ -41,6 +41,8 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
|
|||||||
m_pos(pos),
|
m_pos(pos),
|
||||||
m_gamedef(gamedef),
|
m_gamedef(gamedef),
|
||||||
m_modified(MOD_STATE_WRITE_NEEDED),
|
m_modified(MOD_STATE_WRITE_NEEDED),
|
||||||
|
m_modified_reason("initial"),
|
||||||
|
m_modified_reason_too_long(false),
|
||||||
is_underground(false),
|
is_underground(false),
|
||||||
m_lighting_expired(true),
|
m_lighting_expired(true),
|
||||||
m_day_night_differs(false),
|
m_day_night_differs(false),
|
||||||
|
@ -143,7 +143,7 @@ public:
|
|||||||
//data[i] = MapNode();
|
//data[i] = MapNode();
|
||||||
data[i] = MapNode(CONTENT_IGNORE);
|
data[i] = MapNode(CONTENT_IGNORE);
|
||||||
}
|
}
|
||||||
raiseModified(MOD_STATE_WRITE_NEEDED);
|
raiseModified(MOD_STATE_WRITE_NEEDED, "reallocate");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -160,45 +160,37 @@ public:
|
|||||||
reallocate();
|
reallocate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
This is called internally or externally after the block is
|
|
||||||
modified, so that the block is saved and possibly not deleted from
|
|
||||||
memory.
|
|
||||||
*/
|
|
||||||
// DEPRECATED, use *Modified()
|
|
||||||
void setChangedFlag()
|
|
||||||
{
|
|
||||||
//dstream<<"Deprecated setChangedFlag() called"<<std::endl;
|
|
||||||
raiseModified(MOD_STATE_WRITE_NEEDED);
|
|
||||||
}
|
|
||||||
// DEPRECATED, use *Modified()
|
|
||||||
void resetChangedFlag()
|
|
||||||
{
|
|
||||||
//dstream<<"Deprecated resetChangedFlag() called"<<std::endl;
|
|
||||||
resetModified();
|
|
||||||
}
|
|
||||||
// DEPRECATED, use *Modified()
|
|
||||||
bool getChangedFlag()
|
|
||||||
{
|
|
||||||
//dstream<<"Deprecated getChangedFlag() called"<<std::endl;
|
|
||||||
if(getModified() == MOD_STATE_CLEAN)
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// m_modified methods
|
// m_modified methods
|
||||||
void raiseModified(u32 mod)
|
void raiseModified(u32 mod, const std::string &reason="unknown")
|
||||||
{
|
{
|
||||||
m_modified = MYMAX(m_modified, mod);
|
if(mod > m_modified){
|
||||||
|
m_modified = mod;
|
||||||
|
m_modified_reason = reason;
|
||||||
|
m_modified_reason_too_long = false;
|
||||||
|
} else if(mod == m_modified){
|
||||||
|
if(!m_modified_reason_too_long){
|
||||||
|
if(m_modified_reason.size() < 40)
|
||||||
|
m_modified_reason += ", " + reason;
|
||||||
|
else{
|
||||||
|
m_modified_reason += "...";
|
||||||
|
m_modified_reason_too_long = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
u32 getModified()
|
u32 getModified()
|
||||||
{
|
{
|
||||||
return m_modified;
|
return m_modified;
|
||||||
}
|
}
|
||||||
|
std::string getModifiedReason()
|
||||||
|
{
|
||||||
|
return m_modified_reason;
|
||||||
|
}
|
||||||
void resetModified()
|
void resetModified()
|
||||||
{
|
{
|
||||||
m_modified = MOD_STATE_CLEAN;
|
m_modified = MOD_STATE_CLEAN;
|
||||||
|
m_modified_reason = "none";
|
||||||
|
m_modified_reason_too_long = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// is_underground getter/setter
|
// is_underground getter/setter
|
||||||
@ -209,7 +201,7 @@ public:
|
|||||||
void setIsUnderground(bool a_is_underground)
|
void setIsUnderground(bool a_is_underground)
|
||||||
{
|
{
|
||||||
is_underground = a_is_underground;
|
is_underground = a_is_underground;
|
||||||
raiseModified(MOD_STATE_WRITE_NEEDED);
|
raiseModified(MOD_STATE_WRITE_NEEDED, "setIsUnderground");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
@ -228,7 +220,7 @@ public:
|
|||||||
{
|
{
|
||||||
if(expired != m_lighting_expired){
|
if(expired != m_lighting_expired){
|
||||||
m_lighting_expired = expired;
|
m_lighting_expired = expired;
|
||||||
raiseModified(MOD_STATE_WRITE_NEEDED);
|
raiseModified(MOD_STATE_WRITE_NEEDED, "setLightingExpired");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool getLightingExpired()
|
bool getLightingExpired()
|
||||||
@ -243,7 +235,7 @@ public:
|
|||||||
void setGenerated(bool b)
|
void setGenerated(bool b)
|
||||||
{
|
{
|
||||||
if(b != m_generated){
|
if(b != m_generated){
|
||||||
raiseModified(MOD_STATE_WRITE_NEEDED);
|
raiseModified(MOD_STATE_WRITE_NEEDED, "setGenerated");
|
||||||
m_generated = b;
|
m_generated = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -324,7 +316,7 @@ public:
|
|||||||
if(y < 0 || y >= MAP_BLOCKSIZE) throw InvalidPositionException();
|
if(y < 0 || y >= MAP_BLOCKSIZE) throw InvalidPositionException();
|
||||||
if(z < 0 || z >= MAP_BLOCKSIZE) throw InvalidPositionException();
|
if(z < 0 || z >= MAP_BLOCKSIZE) throw InvalidPositionException();
|
||||||
data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x] = n;
|
data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x] = n;
|
||||||
raiseModified(MOD_STATE_WRITE_NEEDED);
|
raiseModified(MOD_STATE_WRITE_NEEDED, "setNode");
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNode(v3s16 p, MapNode & n)
|
void setNode(v3s16 p, MapNode & n)
|
||||||
@ -353,7 +345,7 @@ public:
|
|||||||
if(data == NULL)
|
if(data == NULL)
|
||||||
throw InvalidPositionException();
|
throw InvalidPositionException();
|
||||||
data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x] = n;
|
data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x] = n;
|
||||||
raiseModified(MOD_STATE_WRITE_NEEDED);
|
raiseModified(MOD_STATE_WRITE_NEEDED, "setNodeNoCheck");
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNodeNoCheck(v3s16 p, MapNode & n)
|
void setNodeNoCheck(v3s16 p, MapNode & n)
|
||||||
@ -507,7 +499,7 @@ public:
|
|||||||
void setTimestamp(u32 time)
|
void setTimestamp(u32 time)
|
||||||
{
|
{
|
||||||
m_timestamp = time;
|
m_timestamp = time;
|
||||||
raiseModified(MOD_STATE_WRITE_AT_UNLOAD);
|
raiseModified(MOD_STATE_WRITE_AT_UNLOAD, "setTimestamp");
|
||||||
}
|
}
|
||||||
void setTimestampNoChangedFlag(u32 time)
|
void setTimestampNoChangedFlag(u32 time)
|
||||||
{
|
{
|
||||||
@ -608,6 +600,8 @@ private:
|
|||||||
- On the client, this is used for nothing.
|
- On the client, this is used for nothing.
|
||||||
*/
|
*/
|
||||||
u32 m_modified;
|
u32 m_modified;
|
||||||
|
std::string m_modified_reason;
|
||||||
|
bool m_modified_reason_too_long;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
When propagating sunlight and the above block doesn't exist,
|
When propagating sunlight and the above block doesn't exist,
|
||||||
|
@ -1478,7 +1478,7 @@ void add_random_objects(MapBlock *block)
|
|||||||
last_node_walkable = false;
|
last_node_walkable = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
block->setChangedFlag();
|
block->raiseModified(MOD_STATE_WRITE_NEEDED, "mapgen::add_random_objects");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3087,16 +3087,11 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(blockpos);
|
MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(blockpos);
|
||||||
if(block)
|
if(block)
|
||||||
{
|
{
|
||||||
block->setChangedFlag();
|
block->raiseModified(MOD_STATE_WRITE_NEEDED,
|
||||||
|
"sign node text");
|
||||||
}
|
}
|
||||||
|
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
setBlockNotSent(blockpos);
|
||||||
i = m_clients.getIterator();
|
|
||||||
i.atEnd()==false; i++)
|
|
||||||
{
|
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
|
||||||
client->SetBlockNotSent(blockpos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(command == TOSERVER_INVENTORY_ACTION)
|
else if(command == TOSERVER_INVENTORY_ACTION)
|
||||||
{
|
{
|
||||||
|
@ -393,9 +393,9 @@ struct TestMapBlock
|
|||||||
MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
|
MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
|
||||||
|
|
||||||
// Changed flag should be initially set
|
// Changed flag should be initially set
|
||||||
assert(b.getChangedFlag() == true);
|
assert(b.getModified() == MOD_STATE_WRITE_NEEDED);
|
||||||
b.resetChangedFlag();
|
b.resetModified();
|
||||||
assert(b.getChangedFlag() == false);
|
assert(b.getModified() == MOD_STATE_CLEAN);
|
||||||
|
|
||||||
// All nodes should have been set to
|
// All nodes should have been set to
|
||||||
// .d=CONTENT_IGNORE and .getLight() = 0
|
// .d=CONTENT_IGNORE and .getLight() = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user