1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-14 00:55:20 +02:00

Add on_deactivate callback for luaentities (#10723)

This commit is contained in:
hecks
2021-01-02 15:14:29 +01:00
committed by GitHub
parent ad58fb2206
commit dd5a732fa9
12 changed files with 106 additions and 27 deletions

View File

@@ -70,6 +70,10 @@ public:
virtual bool environmentDeletes() const
{ return true; }
// Safely mark the object for removal or deactivation
void markForRemoval();
void markForDeactivation();
// Create a certain type of ServerActiveObject
static ServerActiveObject* create(ActiveObjectType type,
ServerEnvironment *env, u16 id, v3f pos,
@@ -213,25 +217,6 @@ public:
*/
u16 m_known_by_count = 0;
/*
- Whether this object is to be removed when nobody knows about
it anymore.
- Removal is delayed to preserve the id for the time during which
it could be confused to some other object by some client.
- This is usually set to true by the step() method when the object wants
to be deleted but can be set by anything else too.
*/
bool m_pending_removal = false;
/*
Same purpose as m_pending_removal but for deactivation.
deactvation = save static data in block, remove active object
If this is set alongside with m_pending_removal, removal takes
priority.
*/
bool m_pending_deactivation = false;
/*
A getter that unifies the above to answer the question:
"Can the environment still interact with this object?"
@@ -239,6 +224,9 @@ public:
inline bool isGone() const
{ return m_pending_removal || m_pending_deactivation; }
inline bool isPendingRemoval() const
{ return m_pending_removal; }
/*
Whether the object's static data has been stored to a block
*/
@@ -250,6 +238,9 @@ public:
v3s16 m_static_block = v3s16(1337,1337,1337);
protected:
virtual void onMarkedForDeactivation() {}
virtual void onMarkedForRemoval() {}
virtual void onAttach(int parent_id) {}
virtual void onDetach(int parent_id) {}
@@ -257,6 +248,27 @@ protected:
v3f m_base_position;
std::unordered_set<u32> m_attached_particle_spawners;
/*
Same purpose as m_pending_removal but for deactivation.
deactvation = save static data in block, remove active object
If this is set alongside with m_pending_removal, removal takes
priority.
Note: Do not assign this directly, use markForDeactivation() instead.
*/
bool m_pending_deactivation = false;
/*
- Whether this object is to be removed when nobody knows about
it anymore.
- Removal is delayed to preserve the id for the time during which
it could be confused to some other object by some client.
- This is usually set to true by the step() method when the object wants
to be deleted but can be set by anything else too.
Note: Do not assign this directly, use markForRemoval() instead.
*/
bool m_pending_removal = false;
/*
Queue of messages to be sent to the client
*/