mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 22:52:25 +01:00
Fix static_save=false not working & related cleanups
This commit is contained in:
parent
ef0009aea7
commit
2386bfda7e
@ -94,7 +94,7 @@ bool MapBlock::onObjectsActivation()
|
||||
|
||||
const auto count = m_static_objects.getStoredSize();
|
||||
verbosestream << "MapBlock::onObjectsActivation(): "
|
||||
<< "activating " << count << "objects in block " << getPos()
|
||||
<< "activating " << count << " objects in block " << getPos()
|
||||
<< std::endl;
|
||||
|
||||
if (count > g_settings->getU16("max_objects_per_block")) {
|
||||
|
@ -71,7 +71,7 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d
|
||||
break;
|
||||
}
|
||||
// create object
|
||||
infostream << "LuaEntitySAO::create(name=\"" << name << "\" state is";
|
||||
infostream << "LuaEntitySAO(name=\"" << name << "\" state is ";
|
||||
if (state.empty())
|
||||
infostream << "empty";
|
||||
else
|
||||
@ -289,6 +289,8 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
|
||||
|
||||
void LuaEntitySAO::getStaticData(std::string *result) const
|
||||
{
|
||||
assert(isStaticAllowed());
|
||||
|
||||
std::ostringstream os(std::ios::binary);
|
||||
// version must be 1 to keep backwards-compatibility. See version2
|
||||
writeU8(os, 1);
|
||||
|
@ -1251,12 +1251,11 @@ void ServerEnvironment::clearObjects(ClearObjectsMode mode)
|
||||
|
||||
// Delete static object if block is loaded
|
||||
deleteStaticFromBlock(obj, id, MOD_REASON_CLEAR_ALL_OBJECTS, true);
|
||||
obj->markForRemoval();
|
||||
|
||||
// If known by some client, don't delete immediately
|
||||
if (obj->m_known_by_count > 0) {
|
||||
obj->markForRemoval();
|
||||
if (obj->m_known_by_count > 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
processActiveObjectRemove(obj);
|
||||
|
||||
@ -1894,6 +1893,12 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr<ServerActiveObject> ob
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Register reference in scripting api (must be done before post-init)
|
||||
m_script->addObjectReference(object);
|
||||
// Post-initialize object
|
||||
// Note that this can change the value of isStaticAllowed() in case of LuaEntitySAO
|
||||
object->addedToEnvironment(dtime_s);
|
||||
|
||||
// Add static data to block
|
||||
if (object->isStaticAllowed()) {
|
||||
// Add static object to active static list of the block
|
||||
@ -1916,15 +1921,14 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr<ServerActiveObject> ob
|
||||
<< "could not emerge block " << p << " for storing id="
|
||||
<< object->getId() << " statically" << std::endl;
|
||||
// clean in case of error
|
||||
object->markForRemoval();
|
||||
processActiveObjectRemove(object);
|
||||
m_ao_manager.removeObject(object->getId());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Register reference in scripting api (must be done before post-init)
|
||||
m_script->addObjectReference(object);
|
||||
// Post-initialize object
|
||||
object->addedToEnvironment(dtime_s);
|
||||
assert(object->m_static_exists == object->isStaticAllowed());
|
||||
|
||||
return object->getId();
|
||||
}
|
||||
@ -1937,13 +1941,6 @@ void ServerEnvironment::removeRemovedObjects()
|
||||
ScopeProfiler sp(g_profiler, "ServerEnvironment::removeRemovedObjects()", SPT_AVG);
|
||||
|
||||
auto clear_cb = [this](ServerActiveObject *obj, u16 id) {
|
||||
// This shouldn't happen but check it
|
||||
if (!obj) {
|
||||
errorstream << "ServerEnvironment::removeRemovedObjects(): "
|
||||
<< "NULL object found. id=" << id << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
We will handle objects marked for removal or deactivation
|
||||
*/
|
||||
@ -2280,6 +2277,11 @@ bool ServerEnvironment::saveStaticToBlock(
|
||||
|
||||
void ServerEnvironment::processActiveObjectRemove(ServerActiveObject *obj)
|
||||
{
|
||||
// markForRemoval or markForDeactivation should have been called before
|
||||
// Not because it's strictly necessary but because the Lua callback is
|
||||
// bound to that.
|
||||
assert(obj->isGone());
|
||||
|
||||
// Tell the object about removal
|
||||
obj->removingFromEnvironment();
|
||||
// Deregister in scripting api
|
||||
|
@ -25,6 +25,7 @@ StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_):
|
||||
type(s_obj->getType()),
|
||||
pos(pos_)
|
||||
{
|
||||
assert(s_obj->isStaticAllowed());
|
||||
s_obj->getStaticData(&data);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user