Made use of smart pointers :)

Former-commit-id: 5380752e0da3f4b958a944e41fcde38722e3c4c2
This commit is contained in:
Lynix
2013-05-23 02:13:45 +02:00
parent c934d8ed6b
commit 738788b4c3
6 changed files with 63 additions and 95 deletions

View File

@@ -11,6 +11,7 @@
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
#include <memory>
#include <vector>
#include <Nazara/Utility/Debug.hpp>
@@ -132,10 +133,10 @@ namespace
struct NzSkeletalMeshImpl
{
std::unique_ptr<nzUInt8[]> bindPoseBuffer;
std::vector<NzVertexWeight> vertexWeights;
std::vector<NzWeight> weights;
NzCubef aabb;
nzUInt8* bindPoseBuffer;
NzIndexBufferConstRef indexBuffer;
unsigned int vertexCount;
};
@@ -169,7 +170,7 @@ bool NzSkeletalMesh::Create(unsigned int vertexCount, unsigned int weightCount)
#endif
m_impl = new NzSkeletalMeshImpl;
m_impl->bindPoseBuffer = new nzUInt8[vertexCount*sizeof(NzMeshVertex)];
m_impl->bindPoseBuffer.reset(new nzUInt8[vertexCount*sizeof(NzMeshVertex)]);
m_impl->vertexCount = vertexCount;
m_impl->vertexWeights.resize(vertexCount);
m_impl->weights.resize(weightCount);
@@ -181,7 +182,6 @@ void NzSkeletalMesh::Destroy()
{
if (m_impl)
{
delete[] m_impl->bindPoseBuffer;
delete m_impl;
m_impl = nullptr;
}
@@ -217,7 +217,7 @@ void* NzSkeletalMesh::GetBindPoseBuffer()
}
#endif
return m_impl->bindPoseBuffer;
return m_impl->bindPoseBuffer.get();
}
const void* NzSkeletalMesh::GetBindPoseBuffer() const
@@ -230,7 +230,7 @@ const void* NzSkeletalMesh::GetBindPoseBuffer() const
}
#endif
return m_impl->bindPoseBuffer;
return m_impl->bindPoseBuffer.get();
}
const NzIndexBuffer* NzSkeletalMesh::GetIndexBuffer() const
@@ -358,7 +358,7 @@ void NzSkeletalMesh::Skin(NzMeshVertex* outputBuffer, const NzSkeleton* skeleton
#endif
SkinningInfos skinningInfos;
skinningInfos.inputVertex = reinterpret_cast<const NzMeshVertex*>(m_impl->bindPoseBuffer);
skinningInfos.inputVertex = reinterpret_cast<const NzMeshVertex*>(m_impl->bindPoseBuffer.get());
skinningInfos.outputVertex = outputBuffer;
skinningInfos.joints = skeleton->GetJoints();
skinningInfos.vertexWeights = &m_impl->vertexWeights[0];

View File

@@ -18,6 +18,7 @@
#include <Nazara/Utility/Win32/CursorImpl.hpp>
#include <Nazara/Utility/Win32/IconImpl.hpp>
#include <cstdio>
#include <memory>
#include <windowsx.h>
#include <Nazara/Utility/Debug.hpp>
@@ -120,7 +121,7 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
m_callback = 0;
wchar_t* wtitle = title.GetWideBuffer();
std::unique_ptr<wchar_t> wtitle(title.GetWideBuffer());
#if NAZARA_UTILITY_THREADED_WINDOW
NzMutex mutex;
@@ -129,15 +130,13 @@ bool NzWindowImpl::Create(NzVideoMode mode, const NzString& title, nzUInt32 styl
// On attend que la fenêtre soit créée
mutex.Lock();
m_thread = new NzThread(WindowThread, &m_handle, win32StyleEx, wtitle, win32Style, x, y, width, height, this, &mutex, &condition);
m_thread = new NzThread(WindowThread, &m_handle, win32StyleEx, wtitle.get(), win32Style, x, y, width, height, this, &mutex, &condition);
condition.Wait(&mutex);
mutex.Unlock();
#else
m_handle = CreateWindowExW(win32StyleEx, className, wtitle, win32Style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), this);
m_handle = CreateWindowExW(win32StyleEx, className, wtitle.get(), win32Style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), this);
#endif
delete[] wtitle;
if (fullscreen)
{
SetForegroundWindow(m_handle);
@@ -245,14 +244,10 @@ NzString NzWindowImpl::GetTitle() const
titleSize++; // Caractère nul
wchar_t* wTitle = new wchar_t[titleSize];
GetWindowTextW(m_handle, wTitle, titleSize);
std::unique_ptr<wchar_t[]> wTitle(new wchar_t[titleSize]);
GetWindowTextW(m_handle, wTitle.get(), titleSize);
NzString title = NzString::Unicode(wTitle);
delete[] wTitle;
return title;
return NzString::Unicode(wTitle.get());
}
unsigned int NzWindowImpl::GetWidth() const
@@ -463,9 +458,8 @@ void NzWindowImpl::SetStayOnTop(bool stayOnTop)
void NzWindowImpl::SetTitle(const NzString& title)
{
wchar_t* wtitle = title.GetWideBuffer();
SetWindowTextW(m_handle, wtitle);
delete[] wtitle;
std::unique_ptr<wchar_t[]> wTitle(title.GetWideBuffer());
SetWindowTextW(m_handle, wTitle.get());
}
void NzWindowImpl::SetVisible(bool visible)