Added Resource modification notification
Former-commit-id: b2fafa22ddf125ef2f1cbc0cd473ae06eb99bcd3
This commit is contained in:
parent
e36c42900d
commit
945c6514a9
|
|
@ -40,9 +40,10 @@ class NAZARA_API NzResource
|
|||
protected:
|
||||
void NotifyCreated();
|
||||
void NotifyDestroy();
|
||||
void NotifyModified(unsigned int code);
|
||||
|
||||
private:
|
||||
typedef std::unordered_map<NzResourceListener*, std::pair<int, unsigned int>> ResourceListenerMap;
|
||||
using ResourceListenerMap = std::unordered_map<NzResourceListener*, std::pair<int, unsigned int>>;
|
||||
|
||||
void RemoveResourceListenerIterator(ResourceListenerMap::iterator iterator) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class NAZARA_API NzResourceListener
|
|||
|
||||
virtual bool OnResourceCreated(const NzResource* resource, int index);
|
||||
virtual bool OnResourceDestroy(const NzResource* resource, int index);
|
||||
virtual bool OnResourceModified(const NzResource* resource, int index, unsigned int code);
|
||||
virtual void OnResourceReleased(const NzResource* resource, int index);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -148,6 +148,24 @@ void NzResource::NotifyDestroy()
|
|||
m_resourceListenersLocked = false;
|
||||
}
|
||||
|
||||
void NzResource::NotifyModified(unsigned int code)
|
||||
{
|
||||
NazaraLock(m_mutex)
|
||||
|
||||
m_resourceListenersLocked = true;
|
||||
|
||||
auto it = m_resourceListeners.begin();
|
||||
while (it != m_resourceListeners.end())
|
||||
{
|
||||
if (!it->first->OnResourceModified(this, it->second.first, code))
|
||||
RemoveResourceListenerIterator(it++);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
m_resourceListenersLocked = false;
|
||||
}
|
||||
|
||||
void NzResource::RemoveResourceListenerIterator(ResourceListenerMap::iterator iterator) const
|
||||
{
|
||||
unsigned int& referenceCount = iterator->second.second;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,15 @@ bool NzResourceListener::OnResourceDestroy(const NzResource* resource, int index
|
|||
return true;
|
||||
}
|
||||
|
||||
bool NzResourceListener::OnResourceModified(const NzResource* resource, int index, unsigned int code)
|
||||
{
|
||||
NazaraUnused(resource);
|
||||
NazaraUnused(index);
|
||||
NazaraUnused(code);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzResourceListener::OnResourceReleased(const NzResource* resource, int index)
|
||||
{
|
||||
NazaraUnused(resource);
|
||||
|
|
|
|||
Loading…
Reference in New Issue