VertexLoaderBase: Get rid of explicit delete and new

This commit is contained in:
Lioncash 2015-12-22 19:59:32 -05:00
parent 3cf16f8573
commit 8371c428cd
5 changed files with 24 additions and 24 deletions

View File

@ -44,8 +44,8 @@ void SWVertexLoader::SetFormat(u8 attributeIndex, u8 primitiveType)
if (!m_CurrentLoader)
{
m_CurrentLoader = VertexLoaderBase::CreateVertexLoader(g_main_cp_state.vtx_desc, g_main_cp_state.vtx_attr[m_attributeIndex]);
m_VertexLoaderMap[uid] = std::unique_ptr<VertexLoaderBase>(m_CurrentLoader);
m_VertexLoaderMap[uid] = VertexLoaderBase::CreateVertexLoader(g_main_cp_state.vtx_desc, g_main_cp_state.vtx_attr[m_attributeIndex]);
m_CurrentLoader = m_VertexLoaderMap[uid].get();
}
m_VertexSize = m_CurrentLoader->m_VertexSize;

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <cinttypes>
#include <memory>
#include <vector>
#include "Common/Common.h"
@ -130,8 +131,8 @@ void VertexLoaderBase::AppendToString(std::string *dest) const
class VertexLoaderTester : public VertexLoaderBase
{
public:
VertexLoaderTester(VertexLoaderBase* _a, VertexLoaderBase* _b, const TVtxDesc& vtx_desc, const VAT& vtx_attr)
: VertexLoaderBase(vtx_desc, vtx_attr), a(_a), b(_b)
VertexLoaderTester(std::unique_ptr<VertexLoaderBase> a_, std::unique_ptr<VertexLoaderBase> b_, const TVtxDesc& vtx_desc, const VAT& vtx_attr)
: VertexLoaderBase(vtx_desc, vtx_attr), a(std::move(a_)), b(std::move(b_))
{
m_initialized = a && b && a->IsInitialized() && b->IsInitialized();
@ -159,8 +160,6 @@ public:
}
~VertexLoaderTester() override
{
delete a;
delete b;
}
int RunVertices(DataReader src, DataReader dst, int count) override
@ -187,43 +186,43 @@ public:
bool IsInitialized() override { return m_initialized; }
private:
VertexLoaderBase *a, *b;
bool m_initialized;
std::vector<u8> buffer_a, buffer_b;
std::unique_ptr<VertexLoaderBase> a;
std::unique_ptr<VertexLoaderBase> b;
std::vector<u8> buffer_a;
std::vector<u8> buffer_b;
};
VertexLoaderBase* VertexLoaderBase::CreateVertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
std::unique_ptr<VertexLoaderBase> VertexLoaderBase::CreateVertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
{
VertexLoaderBase* loader;
std::unique_ptr<VertexLoaderBase> loader;
//#define COMPARE_VERTEXLOADERS
#if defined(COMPARE_VERTEXLOADERS) && defined(_M_X86_64)
// first try: Any new VertexLoader vs the old one
loader = new VertexLoaderTester(
new VertexLoader(vtx_desc, vtx_attr), // the software one
new VertexLoaderX64(vtx_desc, vtx_attr), // the new one to compare
loader = std::make_unique<VertexLoaderTester>(
std::make_unique<VertexLoader>(vtx_desc, vtx_attr), // the software one
std::make_unique<VertexLoaderX64>(vtx_desc, vtx_attr), // the new one to compare
vtx_desc, vtx_attr);
if (loader->IsInitialized())
return loader;
delete loader;
#elif defined(_M_X86_64)
loader = new VertexLoaderX64(vtx_desc, vtx_attr);
loader = std::make_unique<VertexLoaderX64>(vtx_desc, vtx_attr);
if (loader->IsInitialized())
return loader;
delete loader;
#elif defined(_M_ARM_64)
loader = new VertexLoaderARM64(vtx_desc, vtx_attr);
loader = std::make_unique<VertexLoaderARM64>(vtx_desc, vtx_attr);
if (loader->IsInitialized())
return loader;
delete loader;
#endif
// last try: The old VertexLoader
loader = new VertexLoader(vtx_desc, vtx_attr);
loader = std::make_unique<VertexLoader>(vtx_desc, vtx_attr);
if (loader->IsInitialized())
return loader;
delete loader;
PanicAlert("No Vertex Loader found.");
return nullptr;

View File

@ -5,6 +5,7 @@
#pragma once
#include <array>
#include <memory>
#include <string>
#include "Common/CommonTypes.h"
@ -71,7 +72,7 @@ template <> struct hash<VertexLoaderUID>
class VertexLoaderBase
{
public:
static VertexLoaderBase* CreateVertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr);
static std::unique_ptr<VertexLoaderBase> CreateVertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr);
virtual ~VertexLoaderBase() {}
virtual int RunVertices(DataReader src, DataReader dst, int count) = 0;

View File

@ -141,8 +141,8 @@ static VertexLoaderBase* RefreshLoader(int vtx_attr_group, bool preprocess = fal
}
else
{
loader = VertexLoaderBase::CreateVertexLoader(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
s_vertex_loader_map[uid] = std::unique_ptr<VertexLoaderBase>(loader);
s_vertex_loader_map[uid] = VertexLoaderBase::CreateVertexLoader(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
loader = s_vertex_loader_map[uid].get();
INCSTAT(stats.numVertexLoaders);
}
if (check_for_native_format)

View File

@ -61,7 +61,7 @@ protected:
void CreateAndCheckSizes(size_t input_size, size_t output_size)
{
m_loader.reset(VertexLoaderBase::CreateVertexLoader(m_vtx_desc, m_vtx_attr));
m_loader = VertexLoaderBase::CreateVertexLoader(m_vtx_desc, m_vtx_attr);
ASSERT_EQ((int)input_size, m_loader->m_VertexSize);
ASSERT_EQ((int)output_size, m_loader->m_native_vtx_decl.stride);
}