summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-12-01 13:22:33 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-12-01 13:22:33 +0200
commite6e3eef0ef0873b5853b6d055cea0f2b812c65c8 (patch)
tree03ec348b6ccaa3d95152e92e8a3171302d2824b8
parent0e113a4c811e8772924a7f0a842d448e196a3d8f (diff)
downloadminetest-e6e3eef0ef0873b5853b6d055cea0f2b812c65c8.tar.gz
minetest-e6e3eef0ef0873b5853b6d055cea0f2b812c65c8.tar.bz2
minetest-e6e3eef0ef0873b5853b6d055cea0f2b812c65c8.zip
Add ServerActiveObject::removingFromEnvironment()
-rw-r--r--src/environment.cpp8
-rw-r--r--src/serverobject.cpp4
-rw-r--r--src/serverobject.h11
3 files changed, 17 insertions, 6 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index 9748f6b71..81021ad83 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -741,8 +741,12 @@ void ServerEnvironment::clearAllObjects()
obj->m_removed = true;
continue;
}
+
+ // Tell the object about removal
+ obj->removingFromEnvironment();
// Deregister in scripting api
scriptapi_rm_object_reference(m_lua, obj);
+
// Delete active object
delete obj;
// Id to be removed from m_active_objects
@@ -1395,6 +1399,8 @@ void ServerEnvironment::removeRemovedObjects()
if(obj->m_known_by_count > 0)
continue;
+ // Tell the object about removal
+ obj->removingFromEnvironment();
// Deregister in scripting api
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"
<<"; deleting"<<std::endl;
+ // Tell the object about removal
+ obj->removingFromEnvironment();
// Deregister in scripting api
scriptapi_rm_object_reference(m_lua, obj);
diff --git a/src/serverobject.cpp b/src/serverobject.cpp
index 428ad6484..344ae406a 100644
--- a/src/serverobject.cpp
+++ b/src/serverobject.cpp
@@ -37,10 +37,6 @@ ServerActiveObject::~ServerActiveObject()
{
}
-void ServerActiveObject::addedToEnvironment()
-{
-}
-
ServerActiveObject* ServerActiveObject::create(u8 type,
ServerEnvironment *env, u16 id, v3f pos,
const std::string &data)
diff --git a/src/serverobject.h b/src/serverobject.h
index 9e9513a7c..b901cbf4d 100644
--- a/src/serverobject.h
+++ b/src/serverobject.h
@@ -54,8 +54,10 @@ public:
ServerActiveObject(ServerEnvironment *env, v3f pos);
virtual ~ServerActiveObject();
- // Call after id has been set and has been inserted in environment
- virtual void addedToEnvironment();
+ // Called after id has been set and has been inserted in environment
+ virtual void addedToEnvironment(){};
+ // Called before removing from environment
+ virtual void removingFromEnvironment(){};
// Create a certain type of ServerActiveObject
static ServerActiveObject* create(u8 type,
@@ -111,6 +113,11 @@ public:
the data is the static form)
*/
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 rightClick(ServerActiveObject *clicker){}