From 264be2108c51837fa92085f6c839e66aebbcfc9e Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 28 Jan 2024 20:56:41 +0100 Subject: Added support for map/layer mask A custom "Mask" property on a layer or a "foregroundXmask" property on a map can now be used in combination with the SMSG_MAP_MASK to dynamically disable certain map layers from the server. Feature previously seen on ManaPlus and implemented for Mana client for compatibility. Also added a ResourceRef class for automating the Resource reference counting. Closes #44 --- src/resources/resource.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/resources/resource.h') diff --git a/src/resources/resource.h b/src/resources/resource.h index af688eb0..988b78a5 100644 --- a/src/resources/resource.h +++ b/src/resources/resource.h @@ -69,4 +69,72 @@ class Resource unsigned mRefCount; /**< Reference count. */ }; +/** + * Automatically counting Resource reference. + */ +template +class ResourceRef +{ +public: + // Allow implicit construction from RESOURCE * + ResourceRef(RESOURCE *resource = nullptr) + : mResource(resource) + { + if (mResource) + mResource->incRef(); + } + + // Copy constructor + ResourceRef(const ResourceRef &other) + : mResource(other.mResource) + { + if (mResource) + mResource->incRef(); + } + + // Move constructor + ResourceRef(ResourceRef &&other) + : mResource(other.mResource) + { + other.mResource = nullptr; + } + + // Destructor + ~ResourceRef() + { + if (mResource) + mResource->decRef(); + } + + // Assignment operator + ResourceRef &operator=(const ResourceRef &other) + { + if (this != &other) + { + if (mResource) + mResource->decRef(); + + mResource = other.mResource; + + if (mResource) + mResource->incRef(); + } + return *this; + } + + // Allow dereferencing + RESOURCE *operator->() const + { return mResource; } + + RESOURCE *get() const + { return mResource; } + + // Allow implicit conversion to RESOURCE * + operator RESOURCE *() const + { return mResource; } + +private: + RESOURCE *mResource; +}; + #endif -- cgit v1.2.3-60-g2f50