1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Allow managing object observers

-----

Co-authored-by: sfan5 <sfan5@live.de>
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
This commit is contained in:
Lars Mueller 2023-11-12 15:28:29 +01:00 committed by sfan5
parent cc8e7a569e
commit 6874c358ea
15 changed files with 284 additions and 22 deletions

View file

@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cassert>
#include <unordered_set>
#include <optional>
#include "irrlichttypes_bloated.h"
#include "activeobject.h"
#include "itemgroup.h"
@ -236,7 +237,25 @@ public:
*/
v3s16 m_static_block = v3s16(1337,1337,1337);
// Names of players to whom the object is to be sent, not considering parents.
using Observers = std::optional<std::unordered_set<std::string>>;
Observers m_observers;
/// Invalidate final observer cache. This needs to be done whenever
/// the observers of this object or any of its ancestors may have changed.
void invalidateEffectiveObservers();
/// Cache `m_effective_observers` with the names of all observers,
/// also indirect observers (object attachment chain).
const Observers &getEffectiveObservers();
/// Force a recalculation of final observers (including all parents).
const Observers &recalculateEffectiveObservers();
/// Whether the object is sent to `player_name`
bool isEffectivelyObservedBy(const std::string &player_name);
protected:
// Cached intersection of m_observers of this object and all its parents.
std::optional<Observers> m_effective_observers;
virtual void onMarkedForDeactivation() {}
virtual void onMarkedForRemoval() {}