Add ServerActiveObject::removingFromEnvironment()

master
Perttu Ahola 2011-12-01 13:22:33 +02:00
parent 0e113a4c81
commit e6e3eef0ef
3 changed files with 17 additions and 6 deletions

View File

@ -741,8 +741,12 @@ void ServerEnvironment::clearAllObjects()
obj->m_removed = true; obj->m_removed = true;
continue; continue;
} }
// Tell the object about removal
obj->removingFromEnvironment();
// Deregister in scripting api // Deregister in scripting api
scriptapi_rm_object_reference(m_lua, obj); scriptapi_rm_object_reference(m_lua, obj);
// Delete active object // Delete active object
delete obj; delete obj;
// Id to be removed from m_active_objects // Id to be removed from m_active_objects
@ -1395,6 +1399,8 @@ void ServerEnvironment::removeRemovedObjects()
if(obj->m_known_by_count > 0) if(obj->m_known_by_count > 0)
continue; continue;
// Tell the object about removal
obj->removingFromEnvironment();
// Deregister in scripting api // Deregister in scripting api
scriptapi_rm_object_reference(m_lua, obj); scriptapi_rm_object_reference(m_lua, obj);
@ -1680,6 +1686,8 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
<<"object id="<<id<<" is not known by clients" <<"object id="<<id<<" is not known by clients"
<<"; deleting"<<std::endl; <<"; deleting"<<std::endl;
// Tell the object about removal
obj->removingFromEnvironment();
// Deregister in scripting api // Deregister in scripting api
scriptapi_rm_object_reference(m_lua, obj); scriptapi_rm_object_reference(m_lua, obj);

View File

@ -37,10 +37,6 @@ ServerActiveObject::~ServerActiveObject()
{ {
} }
void ServerActiveObject::addedToEnvironment()
{
}
ServerActiveObject* ServerActiveObject::create(u8 type, ServerActiveObject* ServerActiveObject::create(u8 type,
ServerEnvironment *env, u16 id, v3f pos, ServerEnvironment *env, u16 id, v3f pos,
const std::string &data) const std::string &data)

View File

@ -54,8 +54,10 @@ public:
ServerActiveObject(ServerEnvironment *env, v3f pos); ServerActiveObject(ServerEnvironment *env, v3f pos);
virtual ~ServerActiveObject(); virtual ~ServerActiveObject();
// Call after id has been set and has been inserted in environment // Called after id has been set and has been inserted in environment
virtual void addedToEnvironment(); virtual void addedToEnvironment(){};
// Called before removing from environment
virtual void removingFromEnvironment(){};
// Create a certain type of ServerActiveObject // Create a certain type of ServerActiveObject
static ServerActiveObject* create(u8 type, static ServerActiveObject* create(u8 type,
@ -111,6 +113,11 @@ public:
the data is the static form) the data is the static form)
*/ */
virtual std::string getStaticData(){return "";} virtual std::string getStaticData(){return "";}
/*
Return false in here to never save and instead remove object
on unload. getStaticData() will not be called in that case.
*/
virtual bool isStaticAllowed(){return true;}
virtual void punch(ServerActiveObject *puncher){} virtual void punch(ServerActiveObject *puncher){}
virtual void rightClick(ServerActiveObject *clicker){} virtual void rightClick(ServerActiveObject *clicker){}