Core: Added Listenable class (Made class Listener system generic)

Former-commit-id: 3baed32d6720c6455f50af51f262292ece9943fa
This commit is contained in:
Lynix
2015-05-06 18:17:18 +02:00
parent 3195a50114
commit 44ff678002
11 changed files with 121 additions and 206 deletions

View File

@@ -8,6 +8,7 @@
#define NAZARA_ABSTRACTATLAS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Listenable.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Utility/Enums.hpp>
@@ -16,16 +17,12 @@
class NzAbstractImage;
class NzImage;
class NAZARA_API NzAbstractAtlas
class NAZARA_API NzAbstractAtlas : public NzListenable<NzAbstractAtlas>
{
public:
class Listener;
NzAbstractAtlas();
NzAbstractAtlas() = default;
virtual ~NzAbstractAtlas();
void AddListener(Listener* font, void* userdata = nullptr) const;
virtual void Clear() = 0;
virtual void Free(NzSparsePtr<const NzRectui> rects, NzSparsePtr<unsigned int> layers, unsigned int count) = 0;
virtual NzAbstractImage* GetLayer(unsigned int layerIndex) const = 0;
@@ -33,8 +30,6 @@ class NAZARA_API NzAbstractAtlas
virtual nzUInt32 GetStorage() const = 0;
virtual bool Insert(const NzImage& image, NzRectui* rect, bool* flipped, unsigned int* layerIndex) = 0;
void RemoveListener(Listener* font) const;
class NAZARA_API Listener
{
public:
@@ -45,14 +40,6 @@ class NAZARA_API NzAbstractAtlas
virtual bool OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* oldLayer, NzAbstractImage* newLayer, void* userdata);
virtual void OnAtlasReleased(const NzAbstractAtlas* atlas, void* userdata);
};
protected:
void NotifyCleared();
void NotifyLayerChange(NzAbstractImage* oldLayer, NzAbstractImage* newLayer);
private:
mutable std::unordered_map<Listener*, void*> m_listeners;
bool m_listenersLocked;
};
#endif // NAZARA_ABSTRACTATLAS_HPP

View File

@@ -8,6 +8,7 @@
#define NAZARA_NODE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Listenable.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
@@ -15,17 +16,13 @@
#include <unordered_map>
#include <vector>
class NAZARA_API NzNode
class NAZARA_API NzNode : public NzListenable<NzNode>
{
public:
class Listener;
NzNode();
NzNode(const NzNode& node);
virtual ~NzNode();
void AddListener(Listener* listener, void* userdata = nullptr) const;
void EnsureDerivedUpdate() const;
void EnsureTransformMatrixUpdate() const;
@@ -56,7 +53,6 @@ class NAZARA_API NzNode
NzNode& Move(const NzVector3f& movement, nzCoordSys coordSys = nzCoordSys_Local);
NzNode& Move(float movementX, float movementY, float movementZ = 0.f, nzCoordSys coordSys = nzCoordSys_Local);
void RemoveListener(Listener* listener) const;
NzNode& Rotate(const NzQuaternionf& rotation, nzCoordSys coordSys = nzCoordSys_Local);
NzNode& Scale(const NzVector3f& scale);
@@ -131,14 +127,6 @@ class NAZARA_API NzNode
bool m_inheritScale;
mutable bool m_transformMatrixUpdated;
private:
void NotifyInvalidation();
void NotifyParented(const NzNode* parent);
private:
mutable std::unordered_map<Listener*, void*> m_listeners;
bool m_listenersLocked;
};
#endif // NAZARA_NODE_HPP