Core: Added Listenable class (Made class Listener system generic)
Former-commit-id: 3baed32d6720c6455f50af51f262292ece9943fa
This commit is contained in:
@@ -50,15 +50,7 @@ NzNode::~NzNode()
|
||||
|
||||
SetParent(nullptr);
|
||||
|
||||
m_listenersLocked = true;
|
||||
for (auto& pair : m_listeners)
|
||||
pair.first->OnNodeReleased(this, pair.second);
|
||||
}
|
||||
|
||||
void NzNode::AddListener(Listener* listener, void* userdata) const
|
||||
{
|
||||
if (!m_listenersLocked)
|
||||
m_listeners.insert(std::make_pair(listener, userdata));
|
||||
NotifyRelease(Listener::OnNodeReleased);
|
||||
}
|
||||
|
||||
void NzNode::EnsureDerivedUpdate() const
|
||||
@@ -293,12 +285,6 @@ NzNode& NzNode::Move(float moveX, float moveY, float moveZ, nzCoordSys coordSys)
|
||||
return Move(NzVector3f(moveX, moveY, moveZ), coordSys);
|
||||
}
|
||||
|
||||
void NzNode::RemoveListener(Listener* listener) const
|
||||
{
|
||||
if (!m_listenersLocked)
|
||||
m_listeners.erase(listener);
|
||||
}
|
||||
|
||||
NzNode& NzNode::Rotate(const NzQuaternionf& rotation, nzCoordSys coordSys)
|
||||
{
|
||||
// Évitons toute mauvaise surprise ..
|
||||
@@ -662,12 +648,12 @@ void NzNode::InvalidateNode()
|
||||
for (NzNode* node : m_childs)
|
||||
node->InvalidateNode();
|
||||
|
||||
NotifyInvalidation();
|
||||
Notify(Listener::OnNodeInvalidated);
|
||||
}
|
||||
|
||||
void NzNode::OnParenting(const NzNode* parent)
|
||||
{
|
||||
NotifyParented(parent);
|
||||
Notify(Listener::OnNodeParented, parent);
|
||||
}
|
||||
|
||||
void NzNode::RemoveChild(NzNode* node) const
|
||||
@@ -722,38 +708,6 @@ void NzNode::UpdateTransformMatrix() const
|
||||
m_transformMatrixUpdated = true;
|
||||
}
|
||||
|
||||
void NzNode::NotifyInvalidation()
|
||||
{
|
||||
m_listenersLocked = true;
|
||||
|
||||
auto it = m_listeners.begin();
|
||||
while (it != m_listeners.end())
|
||||
{
|
||||
if (!it->first->OnNodeInvalidated(this, it->second))
|
||||
m_listeners.erase(it++);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
m_listenersLocked = false;
|
||||
}
|
||||
|
||||
void NzNode::NotifyParented(const NzNode* parent)
|
||||
{
|
||||
m_listenersLocked = true;
|
||||
|
||||
auto it = m_listeners.begin();
|
||||
while (it != m_listeners.end())
|
||||
{
|
||||
if (!it->first->OnNodeParented(this, parent, it->second))
|
||||
m_listeners.erase(it++);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
m_listenersLocked = false;
|
||||
}
|
||||
|
||||
NzNode::Listener::~Listener() = default;
|
||||
|
||||
bool NzNode::Listener::OnNodeInvalidated(const NzNode* node, void* userdata)
|
||||
|
||||
Reference in New Issue
Block a user