Fully replace listener system by signals

Former-commit-id: 032dfddd12cc3a792c71426148c758ffac3621f9
This commit is contained in:
Lynix
2015-06-07 20:42:41 +02:00
parent 0f4cf3c910
commit a069b105e6
63 changed files with 291 additions and 606 deletions

View File

@@ -44,6 +44,8 @@ NzSoundBuffer::NzSoundBuffer(nzAudioFormat format, unsigned int sampleCount, uns
NzSoundBuffer::~NzSoundBuffer()
{
OnSoundBufferRelease(this);
Destroy();
}
@@ -108,7 +110,6 @@ bool NzSoundBuffer::Create(nzAudioFormat format, unsigned int sampleCount, unsig
m_impl->samples.reset(new nzInt16[sampleCount]);
std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(nzInt16));
NotifyCreated();
return true;
}
@@ -116,7 +117,7 @@ void NzSoundBuffer::Destroy()
{
if (m_impl)
{
NotifyDestroy();
OnSoundBufferDestroy(this);
delete m_impl;
m_impl = nullptr;

View File

@@ -1,39 +0,0 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/ObjectListener.hpp>
#include <Nazara/Core/Debug.hpp>
NzObjectListener::~NzObjectListener() = default;
bool NzObjectListener::OnObjectCreated(const NzRefCounted* object, int index)
{
NazaraUnused(object);
NazaraUnused(index);
return true;
}
bool NzObjectListener::OnObjectDestroy(const NzRefCounted* object, int index)
{
NazaraUnused(object);
NazaraUnused(index);
return true;
}
bool NzObjectListener::OnObjectModified(const NzRefCounted* object, int index, unsigned int code)
{
NazaraUnused(object);
NazaraUnused(index);
NazaraUnused(code);
return true;
}
void NzObjectListener::OnObjectReleased(const NzRefCounted* object, int index)
{
NazaraUnused(object);
NazaraUnused(index);
}

View File

@@ -5,7 +5,6 @@
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ObjectListener.hpp>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_REFCOUNTED
#include <Nazara/Core/ThreadSafety.hpp>
@@ -17,36 +16,18 @@
NzRefCounted::NzRefCounted(bool persistent) :
m_persistent(persistent),
m_referenceCount(0),
m_objectListenersLocked(false)
m_referenceCount(0)
{
}
NzRefCounted::~NzRefCounted()
{
m_objectListenersLocked = true;
for (auto& pair : m_objectListeners)
pair.first->OnObjectReleased(this, pair.second.first);
#if NAZARA_CORE_SAFE
if (m_referenceCount > 0)
NazaraWarning("Resource destroyed while still referenced " + NzString::Number(m_referenceCount) + " time(s)");
#endif
}
void NzRefCounted::AddObjectListener(NzObjectListener* listener, int index) const
{
///DOC: Est ignoré si appelé depuis un évènement
NazaraLock(m_mutex)
if (!m_objectListenersLocked)
{
auto pair = m_objectListeners.insert(std::make_pair(listener, std::make_pair(index, 1U)));
if (!pair.second)
pair.first->second.second++;
}
}
void NzRefCounted::AddReference() const
{
m_referenceCount++;
@@ -62,23 +43,6 @@ bool NzRefCounted::IsPersistent() const
return m_persistent;
}
void NzRefCounted::RemoveObjectListener(NzObjectListener* listener) const
{
///DOC: Est ignoré si appelé depuis un évènement
NazaraLock(m_mutex);
if (!m_objectListenersLocked)
{
ObjectListenerMap::iterator it = m_objectListeners.find(listener);
if (it != m_objectListeners.end())
{
unsigned int& referenceCount = it->second.second;
if (--referenceCount == 0)
m_objectListeners.erase(it);
}
}
}
bool NzRefCounted::RemoveReference() const
{
#if NAZARA_CORE_SAFE
@@ -113,56 +77,3 @@ bool NzRefCounted::SetPersistent(bool persistent, bool checkReferenceCount)
return false;
}
void NzRefCounted::NotifyCreated()
{
NazaraLock(m_mutex)
m_objectListenersLocked = true;
auto it = m_objectListeners.begin();
while (it != m_objectListeners.end())
{
if (!it->first->OnObjectCreated(this, it->second.first))
m_objectListeners.erase(it++);
else
++it;
}
m_objectListenersLocked = false;
}
void NzRefCounted::NotifyDestroy()
{
NazaraLock(m_mutex)
m_objectListenersLocked = true;
auto it = m_objectListeners.begin();
while (it != m_objectListeners.end())
{
if (!it->first->OnObjectDestroy(this, it->second.first))
m_objectListeners.erase(it++);
else
++it;
}
m_objectListenersLocked = false;
}
void NzRefCounted::NotifyModified(unsigned int code)
{
NazaraLock(m_mutex)
m_objectListenersLocked = true;
auto it = m_objectListeners.begin();
while (it != m_objectListeners.end())
{
if (!it->first->OnObjectModified(this, it->second.first, code))
m_objectListeners.erase(it++);
else
++it;
}
m_objectListenersLocked = false;
}

View File

@@ -375,7 +375,7 @@ bool NzMaterial::LoadFromStream(NzInputStream& stream, const NzMaterialParams& p
void NzMaterial::Reset()
{
NotifyDestroy();
OnMaterialReset(this);
m_alphaMap.Reset();
m_diffuseMap.Reset();

View File

@@ -11,7 +11,10 @@ NzRefCounted()
NazaraUnused(controller);
}
NzParticleController::~NzParticleController() = default;
NzParticleController::~NzParticleController()
{
OnParticleControllerRelease(this);
}
bool NzParticleController::Initialize()
{

View File

@@ -27,7 +27,7 @@ m_stride(declaration.m_stride)
NzParticleDeclaration::~NzParticleDeclaration()
{
NotifyDestroy();
OnParticleDeclarationRelease(this);
}
void NzParticleDeclaration::DisableComponent(nzParticleComponent component)

View File

@@ -11,7 +11,10 @@ NzRefCounted()
NazaraUnused(generator);
}
NzParticleGenerator::~NzParticleGenerator() = default;
NzParticleGenerator::~NzParticleGenerator()
{
OnParticleGeneratorRelease(this);
}
bool NzParticleGenerator::Initialize()
{

View File

@@ -11,7 +11,10 @@ NzRefCounted()
NazaraUnused(renderer);
}
NzParticleRenderer::~NzParticleRenderer() = default;
NzParticleRenderer::~NzParticleRenderer()
{
OnParticleRendererRelease(this);
}
bool NzParticleRenderer::Initialize()
{

View File

@@ -5,7 +5,10 @@
#include <Nazara/Graphics/Renderable.hpp>
#include <Nazara/Graphics/Debug.hpp>
NzRenderable::~NzRenderable() = default;
NzRenderable::~NzRenderable()
{
OnRenderableRelease(this);
}
bool NzRenderable::Cull(const NzFrustumf& frustum, const NzBoundingVolumef& volume, const NzMatrix4f& transformMatrix) const
{

View File

@@ -4,7 +4,6 @@
#include <Nazara/Graphics/SkinningManager.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/ObjectListener.hpp>
#include <Nazara/Core/TaskScheduler.hpp>
#include <Nazara/Utility/Algorithm.hpp>
#include <Nazara/Utility/SkeletalMesh.hpp>
@@ -16,92 +15,35 @@
namespace
{
enum ObjectType
{
ObjectType_SkeletalMesh,
ObjectType_Skeleton,
};
struct BufferData
{
NazaraSlot(NzSkeletalMesh, OnSkeletalMeshDestroy, skeletalMeshDestroySlot);
NzVertexBufferRef buffer;
bool updated;
};
struct SkinningData
{
const NzSkeletalMesh* mesh;
const NzSkeleton* skeleton;
NzVertexBuffer* buffer;
};
using MeshMap = std::unordered_map<const NzSkeletalMesh*, BufferData>;
using MeshMap = std::unordered_map<const NzSkeletalMesh*, std::pair<NzSkeletalMeshConstListener, BufferData>>;
using SkeletonMap = std::unordered_map<const NzSkeleton*, std::pair<NzSkeletonConstListener, MeshMap>>;
struct MeshData
{
NazaraSlot(NzSkeleton, OnSkeletonDestroy, skeletonDestroySlot);
NazaraSlot(NzSkeleton, OnSkeletonJointsInvalidated, skeletonJointsInvalidatedSlot);
MeshMap meshMap;
};
struct SkinningData
{
const NzSkeletalMesh* mesh;
const NzSkeleton* skeleton;
NzVertexBuffer* buffer;
};
using SkeletonMap = std::unordered_map<const NzSkeleton*, MeshData>;
SkeletonMap s_cache;
std::vector<SkinningData> s_skinningQueue;
class ObjectListener : public NzObjectListener
{
public:
bool OnObjectDestroy(const NzRefCounted* object, int index) override
{
switch (index)
{
case ObjectType_SkeletalMesh:
{
for (auto& pair : s_cache)
{
MeshMap& meshMap = pair.second.second;
meshMap.erase(static_cast<const NzSkeletalMesh*>(object));
}
break;
}
case ObjectType_Skeleton:
s_cache.erase(static_cast<const NzSkeleton*>(object));
break;
}
return false;
}
bool OnObjectModified(const NzRefCounted* object, int index, unsigned int code) override
{
NazaraUnused(code);
switch (index)
{
case ObjectType_SkeletalMesh:
{
for (auto& pair : s_cache)
{
MeshMap& meshMap = pair.second.second;
for (auto& pair2 : meshMap)
pair2.second.second.updated = false;
}
break;
}
case ObjectType_Skeleton:
{
const NzSkeleton* skeleton = static_cast<const NzSkeleton*>(object);
for (auto& pair : s_cache.at(skeleton).second)
pair.second.second.updated = false;
break;
}
}
return true;
}
void OnObjectReleased(const NzRefCounted* resource, int index) override
{
OnObjectDestroy(resource, index);
}
};
ObjectListener listener;
void Skin_MonoCPU(const NzSkeletalMesh* mesh, const NzSkeleton* skeleton, NzVertexBuffer* buffer)
{
@@ -163,18 +105,28 @@ NzVertexBuffer* NzSkinningManager::GetBuffer(const NzSkeletalMesh* mesh, const N
SkeletonMap::iterator it = s_cache.find(skeleton);
if (it == s_cache.end())
it = s_cache.insert(std::make_pair(skeleton, std::make_pair(NzSkeletonConstListener(&listener, ObjectType_Skeleton, skeleton), MeshMap{}))).first;
{
MeshData meshData;
meshData.skeletonDestroySlot.Connect(skeleton->OnSkeletonDestroy, OnSkeletonRelease);
meshData.skeletonJointsInvalidatedSlot.Connect(skeleton->OnSkeletonJointsInvalidated, OnSkeletonInvalidated);
it = s_cache.insert(std::make_pair(skeleton, std::move(meshData))).first;
}
NzVertexBuffer* buffer;
MeshMap& meshMap = it->second.second;
MeshMap& meshMap = it->second.meshMap;
MeshMap::iterator it2 = meshMap.find(mesh);
if (it2 == meshMap.end())
{
NzVertexBufferRef vertexBuffer = NzVertexBuffer::New(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), mesh->GetVertexCount(), nzDataStorage_Hardware, nzBufferUsage_Dynamic);
BufferData data({vertexBuffer, true});
meshMap.insert(std::make_pair(mesh, std::make_pair(NzSkeletalMeshConstListener(&listener, ObjectType_SkeletalMesh, mesh), data)));
BufferData data;
data.skeletalMeshDestroySlot.Connect(mesh->OnSkeletalMeshDestroy, OnSkeletalMeshDestroy);
data.buffer = vertexBuffer;
data.updated = true;
meshMap.insert(std::make_pair(mesh, std::move(data)));
s_skinningQueue.push_back(SkinningData{mesh, skeleton, vertexBuffer});
@@ -182,7 +134,7 @@ NzVertexBuffer* NzSkinningManager::GetBuffer(const NzSkeletalMesh* mesh, const N
}
else
{
BufferData& data = it2->second.second;
BufferData& data = it2->second;
if (!data.updated)
{
s_skinningQueue.push_back(SkinningData{mesh, skeleton, data.buffer});
@@ -214,6 +166,26 @@ bool NzSkinningManager::Initialize()
return true; // Rien de particulier à faire
}
void NzSkinningManager::OnSkeletalMeshDestroy(const NzSkeletalMesh* mesh)
{
for (auto& pair : s_cache)
{
MeshMap& meshMap = pair.second.meshMap;
meshMap.erase(mesh);
}
}
void NzSkinningManager::OnSkeletonInvalidated(const NzSkeleton* skeleton)
{
for (auto& pair : s_cache.at(skeleton).meshMap)
pair.second.updated = false;
}
void NzSkinningManager::OnSkeletonRelease(const NzSkeleton* skeleton)
{
s_cache.erase(skeleton);
}
void NzSkinningManager::Uninitialize()
{
s_cache.clear();

View File

@@ -176,8 +176,6 @@ bool NzContext::Create(const NzContextParameters& parameters)
onExit.Reset();
NotifyCreated();
return true;
}
@@ -185,7 +183,7 @@ void NzContext::Destroy()
{
if (m_impl)
{
NotifyDestroy();
OnContextDestroy(this);
NzOpenGL::OnContextDestruction(this);
SetActive(false);

View File

@@ -16,6 +16,8 @@ m_id(0)
NzRenderBuffer::~NzRenderBuffer()
{
OnRenderBufferRelease(this);
Destroy();
}
@@ -67,7 +69,6 @@ bool NzRenderBuffer::Create(nzPixelFormat format, unsigned int width, unsigned i
m_id = renderBuffer;
m_width = width;
NotifyCreated();
return true;
}
@@ -75,7 +76,7 @@ void NzRenderBuffer::Destroy()
{
if (m_id)
{
NotifyDestroy();
OnRenderBufferDestroy(this);
NzContext::EnsureContext();

View File

@@ -9,7 +9,9 @@
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderBuffer.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <functional>
#include <limits>
#include <memory>
#include <vector>
@@ -19,17 +21,11 @@ namespace
{
struct Attachment
{
Attachment(NzObjectListener* listener, int bufferIndex = 0, int textureIndex = 0) :
bufferListener(listener, bufferIndex),
textureListener(listener, textureIndex)
{
}
NazaraSlot(NzRenderBuffer, OnRenderBufferDestroy, renderBufferDestroySlot);
NazaraSlot(NzTexture, OnTextureDestroy, textureDestroySlot);
NzRenderBufferRef buffer;
NzTextureRef texture;
// Les listeners doivent se trouver après les références (pour être libérés avant elles)
NzRenderBufferListener bufferListener;
NzTextureListener textureListener;
nzAttachmentPoint attachmentPoint;
bool isBuffer;
@@ -60,16 +56,13 @@ namespace
struct NzRenderTextureImpl
{
NzRenderTextureImpl(NzObjectListener* listener, int contextIndex = 0) :
context(listener, contextIndex)
{
}
NazaraSlot(NzContext, OnContextDestroy, contextDestroySlot);
GLuint fbo;
std::vector<Attachment> attachments;
std::vector<nzUInt8> colorTargets;
mutable std::vector<GLenum> drawBuffers;
NzContextConstListener context;
const NzContext* context;
bool checked = false;
bool complete = false;
bool userDefinedTargets = false;
@@ -155,17 +148,10 @@ bool NzRenderTexture::AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 in
Unlock();
unsigned int attachIndex = attachmentIndex[attachmentPoint] + index;
// On créé les attachements si ça n'a pas déjà été fait
for (unsigned int i = m_impl->attachments.size(); i <= attachIndex; ++i)
{
Attachment attachment(this, attachIndex, attachIndex);
m_impl->attachments.emplace_back(std::move(attachment));
}
Attachment& attachment = m_impl->attachments[attachIndex];
attachment.attachmentPoint = attachmentPoint;
attachment.buffer = buffer;
attachment.bufferListener = buffer;
attachment.renderBufferDestroySlot.Connect(buffer->OnRenderBufferDestroy, std::bind(OnRenderBufferDestroy, this, std::placeholders::_1, attachIndex));
attachment.isBuffer = true;
attachment.isUsed = true;
attachment.height = buffer->GetHeight();
@@ -300,21 +286,13 @@ bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 i
Unlock();
unsigned int attachIndex = attachmentIndex[attachmentPoint] + index;
// On créé les attachements si ça n'a pas déjà été fait
for (unsigned int i = m_impl->attachments.size(); i <= attachIndex; ++i)
{
Attachment attachment(this, attachIndex, attachIndex);
m_impl->attachments.emplace_back(std::move(attachment));
}
Attachment& attachment = m_impl->attachments[attachIndex];
attachment.attachmentPoint = attachmentPoint;
attachment.isBuffer = false;
attachment.isUsed = true;
attachment.height = texture->GetHeight();
attachment.texture = texture;
attachment.textureListener = texture;
attachment.textureDestroySlot.Connect(texture->OnTextureDestroy, std::bind(OnTextureDestroy, this, std::placeholders::_1, attachIndex));
attachment.width = texture->GetWidth();
m_impl->checked = false;
@@ -348,7 +326,7 @@ bool NzRenderTexture::Create(bool lock)
}
#endif
std::unique_ptr<NzRenderTextureImpl> impl(new NzRenderTextureImpl(this));
std::unique_ptr<NzRenderTextureImpl> impl(new NzRenderTextureImpl);
impl->fbo = 0;
glGenFramebuffers(1, &impl->fbo);
@@ -361,6 +339,7 @@ bool NzRenderTexture::Create(bool lock)
m_impl = impl.release();
m_impl->context = NzContext::GetCurrent();
m_impl->contextDestroySlot.Connect(m_impl->context->OnContextDestroy, this, OnContextDestroy);
if (lock)
{
@@ -437,8 +416,8 @@ void NzRenderTexture::Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index)
{
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_RENDERBUFFER, 0);
attachement.bufferListener = nullptr;
attachement.buffer = nullptr;
attachement.renderBufferDestroySlot.Disconnect();
}
else
{
@@ -447,8 +426,8 @@ void NzRenderTexture::Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index)
else
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, 0, 0, 0);
attachement.textureListener = nullptr;
attachement.texture = nullptr;
attachement.textureDestroySlot.Disconnect();
}
m_impl->sizeUpdated = false;
@@ -887,27 +866,52 @@ void NzRenderTexture::EnsureTargetUpdated() const
}
}
bool NzRenderTexture::OnObjectDestroy(const NzRefCounted* object, int index)
void NzRenderTexture::OnContextDestroy(const NzContext* context)
{
if (object == m_impl->context)
// Notre contexte va être détruit, libérons la RenderTexture pour éviter un éventuel leak
Destroy();
else // Sinon, c'est une texture
NazaraAssert(m_impl, "Invalid internal state");
NazaraUnused(context);
#ifdef NAZARA_DEBUG
if (m_impl->context != context)
{
// La ressource n'est plus, du coup nous mettons à jour
Attachment& attachment = m_impl->attachments[index];
if (attachment.isBuffer)
attachment.buffer = nullptr;
else
attachment.texture = nullptr;
attachment.isUsed = false;
m_impl->checked = false;
m_impl->targetsUpdated = false;
NazaraInternalError("Not listening to " + NzString::Pointer(font));
return;
}
#endif
return false;
Destroy();
}
void NzRenderTexture::OnRenderBufferDestroy(const NzRenderBuffer* renderBuffer, int attachmentIndex)
{
NazaraAssert(m_impl, "Invalid internal state");
NazaraAssert(attachmentIndex < m_impl->attachments.size(), "Invalid attachment index");
NazaraAssert(m_impl->attachments[attachmentIndex].isBuffer, "Invalid attachment state");
NazaraUnused(renderBuffer);
Attachment& attachment = m_impl->attachments[attachmentIndex];
attachment.buffer = nullptr;
attachment.isUsed = false;
attachment.renderBufferDestroySlot.Disconnect();
m_impl->checked = false;
m_impl->targetsUpdated = false;
}
void NzRenderTexture::OnTextureDestroy(const NzTexture* texture, int attachmentIndex)
{
NazaraAssert(m_impl, "Invalid internal state");
NazaraAssert(attachmentIndex < m_impl->attachments.size(), "Invalid attachment index");
NazaraAssert(!m_impl->attachments[attachmentIndex].isBuffer, "Invalid attachment state");
NazaraUnused(texture);
Attachment& attachment = m_impl->attachments[attachmentIndex];
attachment.isUsed = false;
attachment.texture = nullptr;
attachment.textureDestroySlot.Disconnect();
m_impl->checked = false;
m_impl->targetsUpdated = false;
}
void NzRenderTexture::UpdateDrawBuffers() const

View File

@@ -178,9 +178,14 @@ bool NzShader::Create()
void NzShader::Destroy()
{
NzContext::EnsureContext();
if (m_program)
{
OnShaderDestroy(this);
NzOpenGL::DeleteProgram(m_program);
NzContext::EnsureContext();
NzOpenGL::DeleteProgram(m_program);
m_program = 0;
}
}
NzByteArray NzShader::GetBinary() const

View File

@@ -202,8 +202,6 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
}
onExit.Reset();
NotifyCreated();
return true;
}
@@ -211,7 +209,7 @@ void NzTexture::Destroy()
{
if (m_impl)
{
NotifyDestroy();
OnTextureDestroy(this);
NzContext::EnsureContext();
NzOpenGL::DeleteTexture(m_impl->id);

View File

@@ -5,7 +5,10 @@
#include <Nazara/Renderer/UberShader.hpp>
#include <Nazara/Renderer/Debug.hpp>
NzUberShader::~NzUberShader() = default;
NzUberShader::~NzUberShader()
{
OnUberShaderRelease(this);
}
bool NzUberShader::Initialize()
{

View File

@@ -10,6 +10,11 @@
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
NzUberShaderPreprocessor::~NzUberShaderPreprocessor()
{
OnUberShaderPreprocessorRelease(this);
}
NzUberShaderInstance* NzUberShaderPreprocessor::Get(const NzParameterList& parameters) const
{
// Première étape, transformer les paramètres en un flag

View File

@@ -34,7 +34,7 @@ bool NzAnimationParams::IsValid() const
NzAnimation::~NzAnimation()
{
Destroy();
OnAnimationRelease(this);
}
bool NzAnimation::AddSequence(const NzSequence& sequence)
@@ -172,7 +172,6 @@ bool NzAnimation::CreateSkeletal(unsigned int frameCount, unsigned int jointCoun
m_impl->sequenceJoints.resize(frameCount*jointCount);
m_impl->type = nzAnimationType_Skeletal;
NotifyCreated();
return true;
}
@@ -180,7 +179,7 @@ void NzAnimation::Destroy()
{
if (m_impl)
{
NotifyDestroy();
OnAnimationDestroy(this);
delete m_impl;
m_impl = nullptr;

View File

@@ -40,6 +40,8 @@ m_impl(nullptr)
NzBuffer::~NzBuffer()
{
OnBufferRelease(this);
Destroy();
}
@@ -86,7 +88,6 @@ bool NzBuffer::Create(unsigned int size, nzUInt32 storage, nzBufferUsage usage)
m_storage = storage;
m_usage = usage;
NotifyCreated();
return true; // Si on arrive ici c'est que tout s'est bien passé.
}
@@ -94,7 +95,7 @@ void NzBuffer::Destroy()
{
if (m_impl)
{
NotifyDestroy();
OnBufferDestroy(this);
m_impl->Destroy();
delete m_impl;

View File

@@ -90,17 +90,21 @@ bool NzFont::Create(NzFontData* data)
#endif
m_data.reset(data);
return true;
}
void NzFont::Destroy()
{
ClearGlyphCache();
if (m_data)
{
OnFontDestroy(this);
m_data.reset();
m_kerningCache.clear();
m_sizeInfoCache.clear();
ClearGlyphCache();
m_data.reset();
m_kerningCache.clear();
m_sizeInfoCache.clear();
}
}
bool NzFont::ExtractGlyph(unsigned int characterSize, char32_t character, nzUInt32 style, NzFontGlyph* glyph) const

View File

@@ -65,6 +65,8 @@ m_sharedImage(sharedImage)
NzImage::~NzImage()
{
OnImageRelease(this);
Destroy();
}
@@ -306,7 +308,6 @@ bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width,
m_sharedImage = new SharedImage(1, type, format, levelCount, levels, width, height, depth);
NotifyCreated();
return true;
}
@@ -314,7 +315,7 @@ void NzImage::Destroy()
{
if (m_sharedImage != &emptyImage)
{
NotifyDestroy();
OnImageDestroy(this);
ReleaseImage();
}
}

View File

@@ -66,6 +66,8 @@ struct NzMeshImpl
NzMesh::~NzMesh()
{
OnMeshRelease(this);
Destroy();
}
@@ -359,7 +361,6 @@ bool NzMesh::CreateSkeletal(unsigned int jointCount)
return false;
}
NotifyCreated();
return true;
}
@@ -370,7 +371,6 @@ bool NzMesh::CreateStatic()
m_impl = new NzMeshImpl;
m_impl->animationType = nzAnimationType_Static;
NotifyCreated();
return true;
}
@@ -378,7 +378,7 @@ void NzMesh::Destroy()
{
if (m_impl)
{
NotifyDestroy();
OnMeshDestroy(this);
delete m_impl;
m_impl = nullptr;

View File

@@ -24,6 +24,8 @@ m_characterSize(drawer.m_characterSize)
SetFont(drawer.m_font);
}
NzSimpleTextDrawer::~NzSimpleTextDrawer() = default;
const NzRectui& NzSimpleTextDrawer::GetBounds() const
{
if (!m_glyphUpdated)

View File

@@ -16,6 +16,8 @@ NzSubMesh(parent)
NzSkeletalMesh::~NzSkeletalMesh()
{
OnSkeletalMeshRelease(this);
Destroy();
}
@@ -39,7 +41,7 @@ void NzSkeletalMesh::Destroy()
{
if (m_vertexBuffer)
{
NotifyDestroy();
OnSkeletalMeshDestroy(this);
m_indexBuffer.Reset();
m_vertexBuffer.Reset();

View File

@@ -24,6 +24,8 @@ m_impl(nullptr)
NzSkeleton::~NzSkeleton()
{
OnSkeletonRelease(this);
Destroy();
}
@@ -47,6 +49,8 @@ void NzSkeleton::Destroy()
{
if (m_impl)
{
OnSkeletonDestroy(this);
delete m_impl;
m_impl = nullptr;
}
@@ -372,7 +376,8 @@ NzSkeleton& NzSkeleton::operator=(const NzSkeleton& skeleton)
void NzSkeleton::InvalidateJoints()
{
m_impl->aabbUpdated = false;
NotifyModified(0);
OnSkeletonJointsInvalidated(this);
}
void NzSkeleton::InvalidateJointMap()

View File

@@ -18,6 +18,8 @@ NzSubMesh(parent)
NzStaticMesh::~NzStaticMesh()
{
OnStaticMeshRelease(this);
Destroy();
}
@@ -57,7 +59,7 @@ void NzStaticMesh::Destroy()
{
if (m_vertexBuffer)
{
NotifyDestroy();
OnStaticMeshDestroy(this);
m_indexBuffer.Reset();
m_vertexBuffer.Reset();

View File

@@ -20,7 +20,10 @@ m_matIndex(0)
{
}
NzSubMesh::~NzSubMesh() = default;
NzSubMesh::~NzSubMesh()
{
OnSubMeshRelease(this);
}
void NzSubMesh::GenerateNormals()
{