From 4f2303849e0f929524695a9e3719ec486b47ddd1 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 19 Oct 2020 20:38:33 +0200 Subject: Implement unloading of static_save=false objects according to existing docs (#10485) --- src/server/luaentity_sao.h | 1 + src/server/player_sao.h | 1 + src/server/serveractiveobject.h | 9 +++++++++ 3 files changed, 11 insertions(+) (limited to 'src/server') diff --git a/src/server/luaentity_sao.h b/src/server/luaentity_sao.h index 2520c8f5d..e060aa06d 100644 --- a/src/server/luaentity_sao.h +++ b/src/server/luaentity_sao.h @@ -42,6 +42,7 @@ public: void step(float dtime, bool send_recommended); std::string getClientInitializationData(u16 protocol_version); bool isStaticAllowed() const { return m_prop.static_save; } + bool shouldUnload() const { return true; } void getStaticData(std::string *result) const; u16 punch(v3f dir, const ToolCapabilities *toolcap = nullptr, ServerActiveObject *puncher = nullptr, diff --git a/src/server/player_sao.h b/src/server/player_sao.h index 8571bd4f9..3e178d4fc 100644 --- a/src/server/player_sao.h +++ b/src/server/player_sao.h @@ -83,6 +83,7 @@ public: void addedToEnvironment(u32 dtime_s); void removingFromEnvironment(); bool isStaticAllowed() const { return false; } + bool shouldUnload() const { return false; } std::string getClientInitializationData(u16 protocol_version); void getStaticData(std::string *result) const; void step(float dtime, bool send_recommended); diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h index 927009aef..2764d159e 100644 --- a/src/server/serveractiveobject.h +++ b/src/server/serveractiveobject.h @@ -125,6 +125,7 @@ public: assert(isStaticAllowed()); *result = ""; } + /* Return false in here to never save and instead remove object on unload. getStaticData() will not be called in that case. @@ -132,6 +133,14 @@ public: virtual bool isStaticAllowed() const {return true;} + /* + Return false here to never unload the object. + isStaticAllowed && shouldUnload -> unload when out of active block range + !isStaticAllowed && shouldUnload -> unload when block is unloaded + */ + virtual bool shouldUnload() const + { return true; } + // Returns tool wear virtual u16 punch(v3f dir, const ToolCapabilities *toolcap = nullptr, -- cgit v1.2.3