Skip to content

Commit 4f23038

Browse files
authoredOct 19, 2020
Implement unloading of static_save=false objects according to existing docs (#10485)
1 parent 660115c commit 4f23038

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed
 

Diff for: ‎src/server/luaentity_sao.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class LuaEntitySAO : public UnitSAO
4242
void step(float dtime, bool send_recommended);
4343
std::string getClientInitializationData(u16 protocol_version);
4444
bool isStaticAllowed() const { return m_prop.static_save; }
45+
bool shouldUnload() const { return true; }
4546
void getStaticData(std::string *result) const;
4647
u16 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
4748
ServerActiveObject *puncher = nullptr,

Diff for: ‎src/server/player_sao.h

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class PlayerSAO : public UnitSAO
8383
void addedToEnvironment(u32 dtime_s);
8484
void removingFromEnvironment();
8585
bool isStaticAllowed() const { return false; }
86+
bool shouldUnload() const { return false; }
8687
std::string getClientInitializationData(u16 protocol_version);
8788
void getStaticData(std::string *result) const;
8889
void step(float dtime, bool send_recommended);

Diff for: ‎src/server/serveractiveobject.h

+9
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,22 @@ class ServerActiveObject : public ActiveObject
125125
assert(isStaticAllowed());
126126
*result = "";
127127
}
128+
128129
/*
129130
Return false in here to never save and instead remove object
130131
on unload. getStaticData() will not be called in that case.
131132
*/
132133
virtual bool isStaticAllowed() const
133134
{return true;}
134135

136+
/*
137+
Return false here to never unload the object.
138+
isStaticAllowed && shouldUnload -> unload when out of active block range
139+
!isStaticAllowed && shouldUnload -> unload when block is unloaded
140+
*/
141+
virtual bool shouldUnload() const
142+
{ return true; }
143+
135144
// Returns tool wear
136145
virtual u16 punch(v3f dir,
137146
const ToolCapabilities *toolcap = nullptr,

Diff for: ‎src/serverenvironment.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1972,8 +1972,8 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
19721972
// force_delete might be overriden per object
19731973
bool force_delete = _force_delete;
19741974

1975-
// Do not deactivate if static data creation not allowed
1976-
if (!force_delete && !obj->isStaticAllowed())
1975+
// Do not deactivate if disallowed
1976+
if (!force_delete && !obj->shouldUnload())
19771977
return false;
19781978

19791979
// removeRemovedObjects() is responsible for these
@@ -2002,7 +2002,10 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
20022002
}
20032003

20042004
// If block is still active, don't remove
2005-
if (!force_delete && m_active_blocks.contains(blockpos_o))
2005+
bool still_active = obj->isStaticAllowed() ?
2006+
m_active_blocks.contains(blockpos_o) :
2007+
getMap().getBlockNoCreateNoEx(blockpos_o) != nullptr;
2008+
if (!force_delete && still_active)
20062009
return false;
20072010

20082011
verbosestream << "ServerEnvironment::deactivateFarObjects(): "

0 commit comments

Comments
 (0)
Please sign in to comment.