From 9ef2fbba5aae53310f7eab16590bb25ad7df680c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 31 Mar 2020 12:50:26 -0400 Subject: [PATCH] RetroDataSpec: Make use of make_unique where applicable Same behavior, but without a mildly wonky way of performing it. --- DataSpec/DNACommon/MAPA.cpp | 15 +++++------ DataSpec/DNAMP1/ANCS.cpp | 42 +++++++++++++++---------------- DataSpec/DNAMP1/ANIM.cpp | 8 +++--- DataSpec/DNAMP1/DCLN.hpp | 15 ++++++----- DataSpec/DNAMP1/FRME.cpp | 37 ++++++++++++++------------- DataSpec/DNAMP2/ANIM.cpp | 4 +-- DataSpec/DNAMP3/ANIM.cpp | 4 +-- DataSpec/DNAMP3/CHAR.cpp | 26 +++++++++---------- DataSpec/DNAMP3/CMDLMaterials.cpp | 8 +++--- 9 files changed, 82 insertions(+), 77 deletions(-) diff --git a/DataSpec/DNACommon/MAPA.cpp b/DataSpec/DNACommon/MAPA.cpp index 46a58a3ef..3e8a868f5 100644 --- a/DataSpec/DNACommon/MAPA.cpp +++ b/DataSpec/DNACommon/MAPA.cpp @@ -27,11 +27,11 @@ void MAPA::Enumerate(typename Read::StreamT& __dna_reader) { /* version */ version = __dna_reader.readUint32Big(); if (version == 2) - header.reset(new HeaderMP1); + header = std::make_unique(); else if (version == 3) - header.reset(new HeaderMP2); + header = std::make_unique(); else if (version == 5) - header.reset(new HeaderMP3); + header = std::make_unique(); else { LogDNACommon.report(logvisor::Error, fmt("invalid MAPA version")); return; @@ -41,10 +41,11 @@ void MAPA::Enumerate(typename Read::StreamT& __dna_reader) { for (atUint32 i = 0; i < header->mappableObjectCount(); i++) { std::unique_ptr mo = nullptr; - if (version != 5) - mo.reset(new MappableObjectMP1_2); - else - mo.reset(new MappableObjectMP3); + if (version != 5) { + mo = std::make_unique(); + } else { + mo = std::make_unique(); + } mo->read(__dna_reader); mappableObjects.push_back(std::move(mo)); } diff --git a/DataSpec/DNAMP1/ANCS.cpp b/DataSpec/DNAMP1/ANCS.cpp index a0d51c72b..3a9337759 100644 --- a/DataSpec/DNAMP1/ANCS.cpp +++ b/DataSpec/DNAMP1/ANCS.cpp @@ -611,30 +611,30 @@ std::string_view ANCS::CharacterSet::CharacterInfo::DNAType() { template <> void ANCS::AnimationSet::MetaAnimFactory::Enumerate(athena::io::IStreamReader& reader) { - IMetaAnim::Type type(IMetaAnim::Type(reader.readUint32Big())); + const auto type = IMetaAnim::Type(reader.readUint32Big()); switch (type) { case IMetaAnim::Type::Primitive: - m_anim.reset(new struct MetaAnimPrimitive); + m_anim = std::make_unique(); m_anim->read(reader); break; case IMetaAnim::Type::Blend: - m_anim.reset(new struct MetaAnimBlend); + m_anim = std::make_unique(); m_anim->read(reader); break; case IMetaAnim::Type::PhaseBlend: - m_anim.reset(new struct MetaAnimPhaseBlend); + m_anim = std::make_unique(); m_anim->read(reader); break; case IMetaAnim::Type::Random: - m_anim.reset(new struct MetaAnimRandom); + m_anim = std::make_unique(); m_anim->read(reader); break; case IMetaAnim::Type::Sequence: - m_anim.reset(new struct MetaAnimSequence); + m_anim = std::make_unique(); m_anim->read(reader); break; default: - m_anim.reset(nullptr); + m_anim.reset(); break; } } @@ -660,22 +660,22 @@ void ANCS::AnimationSet::MetaAnimFactory::Enumerate(athena::io std::string type = reader.readString("type"); std::transform(type.begin(), type.end(), type.begin(), tolower); if (type == "primitive") { - m_anim.reset(new struct MetaAnimPrimitive); + m_anim = std::make_unique(); m_anim->read(reader); } else if (type == "blend") { - m_anim.reset(new struct MetaAnimBlend); + m_anim = std::make_unique(); m_anim->read(reader); } else if (type == "phaseblend") { - m_anim.reset(new struct MetaAnimPhaseBlend); + m_anim = std::make_unique(); m_anim->read(reader); } else if (type == "random") { - m_anim.reset(new struct MetaAnimRandom); + m_anim = std::make_unique(); m_anim->read(reader); } else if (type == "sequence") { - m_anim.reset(new struct MetaAnimSequence); + m_anim = std::make_unique(); m_anim->read(reader); } else { - m_anim.reset(nullptr); + m_anim.reset(); } } @@ -696,20 +696,20 @@ void ANCS::AnimationSet::MetaTransFactory::Enumerate(athena::io::I IMetaTrans::Type type(IMetaTrans::Type(reader.readUint32Big())); switch (type) { case IMetaTrans::Type::MetaAnim: - m_trans.reset(new struct MetaTransMetaAnim); + m_trans = std::make_unique(); m_trans->read(reader); break; case IMetaTrans::Type::Trans: - m_trans.reset(new struct MetaTransTrans); + m_trans = std::make_unique(); m_trans->read(reader); break; case IMetaTrans::Type::PhaseTrans: - m_trans.reset(new struct MetaTransPhaseTrans); + m_trans = std::make_unique(); m_trans->read(reader); break; case IMetaTrans::Type::NoTrans: default: - m_trans.reset(nullptr); + m_trans.reset(); break; } } @@ -737,16 +737,16 @@ void ANCS::AnimationSet::MetaTransFactory::Enumerate(athena::i std::string type = reader.readString("type"); std::transform(type.begin(), type.end(), type.begin(), tolower); if (type == "metaanim") { - m_trans.reset(new struct MetaTransMetaAnim); + m_trans = std::make_unique(); m_trans->read(reader); } else if (type == "trans") { - m_trans.reset(new struct MetaTransTrans); + m_trans = std::make_unique(); m_trans->read(reader); } else if (type == "phasetrans") { - m_trans.reset(new struct MetaTransPhaseTrans); + m_trans = std::make_unique(); m_trans->read(reader); } else { - m_trans.reset(nullptr); + m_trans.reset(); } } diff --git a/DataSpec/DNAMP1/ANIM.cpp b/DataSpec/DNAMP1/ANIM.cpp index 203831ebf..0fce2c36a 100644 --- a/DataSpec/DNAMP1/ANIM.cpp +++ b/DataSpec/DNAMP1/ANIM.cpp @@ -122,15 +122,15 @@ void ANIM::Enumerate(typename Read::StreamT& reader) { atUint32 version = reader.readUint32Big(); switch (version) { case 0: - m_anim.reset(new struct ANIM0); + m_anim = std::make_unique(); m_anim->read(reader); break; case 2: - m_anim.reset(new struct ANIM2(false)); + m_anim = std::make_unique(false); m_anim->read(reader); break; case 3: - m_anim.reset(new struct ANIM2(true)); + m_anim = std::make_unique(true); m_anim->read(reader); break; default: @@ -548,7 +548,7 @@ void ANIM::ANIM2::Enumerate(size_t& __isz) { ANIM::ANIM(const BlenderAction& act, const std::unordered_map& idMap, const DNAANIM::RigInverter& rig, bool pc) { - m_anim.reset(new struct ANIM2(pc)); + m_anim = std::make_unique(pc); IANIM& newAnim = *m_anim; newAnim.looping = act.looping; diff --git a/DataSpec/DNAMP1/DCLN.hpp b/DataSpec/DNAMP1/DCLN.hpp index 503c72172..2136e029d 100644 --- a/DataSpec/DNAMP1/DCLN.hpp +++ b/DataSpec/DNAMP1/DCLN.hpp @@ -99,15 +99,18 @@ void DCLN::Collision::Node::Enumerate(typename Op::StreamT& s) { Do(athena::io::PropId{"halfExtent"}, halfExtent, s); Do(athena::io::PropId{"isLeaf"}, isLeaf, s); if (isLeaf) { - if (!leafData) - leafData.reset(new LeafData); + if (!leafData) { + leafData = std::make_unique(); + } Do(athena::io::PropId{"leafData"}, *leafData, s); } else { - if (!left) - left.reset(new Node); + if (!left) { + left = std::make_unique(); + } Do(athena::io::PropId{"left"}, *left, s); - if (!right) - right.reset(new Node); + if (!right) { + right = std::make_unique(); + } Do(athena::io::PropId{"right"}, *right, s); } } diff --git a/DataSpec/DNAMP1/FRME.cpp b/DataSpec/DNAMP1/FRME.cpp index b0405c334..4fdced531 100644 --- a/DataSpec/DNAMP1/FRME.cpp +++ b/DataSpec/DNAMP1/FRME.cpp @@ -54,43 +54,43 @@ void FRME::Widget::Enumerate(athena::io::IStreamReader& __dna_read header.read(__dna_reader); switch (type.toUint32()) { case SBIG('BWIG'): - widgetInfo.reset(new BWIGInfo); + widgetInfo = std::make_unique(); break; case SBIG('HWIG'): - widgetInfo.reset(new HWIGInfo); + widgetInfo = std::make_unique(); break; case SBIG('CAMR'): - widgetInfo.reset(new CAMRInfo); + widgetInfo = std::make_unique(); break; case SBIG('LITE'): - widgetInfo.reset(new LITEInfo); + widgetInfo = std::make_unique(); break; case SBIG('ENRG'): - widgetInfo.reset(new ENRGInfo); + widgetInfo = std::make_unique(); break; case SBIG('MODL'): - widgetInfo.reset(new MODLInfo); + widgetInfo = std::make_unique(); break; case SBIG('METR'): - widgetInfo.reset(new METRInfo); + widgetInfo = std::make_unique(); break; case SBIG('GRUP'): - widgetInfo.reset(new GRUPInfo); + widgetInfo = std::make_unique(); break; case SBIG('PANE'): - widgetInfo.reset(new PANEInfo); + widgetInfo = std::make_unique(); break; case SBIG('TXPN'): - widgetInfo.reset(new TXPNInfo(owner->version)); + widgetInfo = std::make_unique(owner->version); break; case SBIG('IMGP'): - widgetInfo.reset(new IMGPInfo); + widgetInfo = std::make_unique(); break; case SBIG('TBGP'): - widgetInfo.reset(new TBGPInfo); + widgetInfo = std::make_unique(); break; case SBIG('SLGP'): - widgetInfo.reset(new SLGPInfo); + widgetInfo = std::make_unique(); break; default: Log.report(logvisor::Fatal, fmt(_SYS_STR("Unsupported FRME widget type {}")), type); @@ -169,12 +169,13 @@ void FRME::Widget::Enumerate(size_t& __isz) { template <> void FRME::Widget::CAMRInfo::Enumerate(athena::io::IStreamReader& __dna_reader) { projectionType = ProjectionType(__dna_reader.readUint32Big()); - if (projectionType == ProjectionType::Perspective) - projection.reset(new PerspectiveProjection); - else if (projectionType == ProjectionType::Orthographic) - projection.reset(new OrthographicProjection); - else + if (projectionType == ProjectionType::Perspective) { + projection = std::make_unique(); + } else if (projectionType == ProjectionType::Orthographic) { + projection = std::make_unique(); + } else { Log.report(logvisor::Fatal, fmt(_SYS_STR("Invalid CAMR projection mode! {}")), int(projectionType)); + } projection->read(__dna_reader); } diff --git a/DataSpec/DNAMP2/ANIM.cpp b/DataSpec/DNAMP2/ANIM.cpp index c2757f36a..333d543a1 100644 --- a/DataSpec/DNAMP2/ANIM.cpp +++ b/DataSpec/DNAMP2/ANIM.cpp @@ -126,11 +126,11 @@ void ANIM::Enumerate(typename Read::StreamT& reader) { atUint32 version = reader.readUint32Big(); switch (version) { case 0: - m_anim.reset(new struct ANIM0); + m_anim = std::make_unique(); m_anim->read(reader); break; case 2: - m_anim.reset(new struct ANIM2); + m_anim = std::make_unique(); m_anim->read(reader); break; default: diff --git a/DataSpec/DNAMP3/ANIM.cpp b/DataSpec/DNAMP3/ANIM.cpp index ab0b1bd8e..9abfea7ac 100644 --- a/DataSpec/DNAMP3/ANIM.cpp +++ b/DataSpec/DNAMP3/ANIM.cpp @@ -130,11 +130,11 @@ void ANIM::Enumerate(typename Read::StreamT& reader) { atUint32 version = reader.readUint32Big(); switch (version) { case 0: - m_anim.reset(new struct ANIM0); + m_anim = std::make_unique(); m_anim->read(reader); break; case 1: - m_anim.reset(new struct ANIM1); + m_anim = std::make_unique(); m_anim->read(reader); break; default: diff --git a/DataSpec/DNAMP3/CHAR.cpp b/DataSpec/DNAMP3/CHAR.cpp index 3836601d7..2f7324128 100644 --- a/DataSpec/DNAMP3/CHAR.cpp +++ b/DataSpec/DNAMP3/CHAR.cpp @@ -74,30 +74,30 @@ std::string_view CHAR::AnimationInfo::EVNT::SFXEvent::DNAType() { template <> void CHAR::AnimationInfo::MetaAnimFactory::Enumerate(athena::io::IStreamReader& reader) { - IMetaAnim::Type type(IMetaAnim::Type(reader.readUint32Big())); + const auto type = IMetaAnim::Type(reader.readUint32Big()); switch (type) { case IMetaAnim::Type::Primitive: - m_anim.reset(new struct MetaAnimPrimitive); + m_anim = std::make_unique(); m_anim->read(reader); break; case IMetaAnim::Type::Blend: - m_anim.reset(new struct MetaAnimBlend); + m_anim = std::make_unique(); m_anim->read(reader); break; case IMetaAnim::Type::PhaseBlend: - m_anim.reset(new struct MetaAnimPhaseBlend); + m_anim = std::make_unique(); m_anim->read(reader); break; case IMetaAnim::Type::Random: - m_anim.reset(new struct MetaAnimRandom); + m_anim = std::make_unique(); m_anim->read(reader); break; case IMetaAnim::Type::Sequence: - m_anim.reset(new struct MetaAnimSequence); + m_anim = std::make_unique(); m_anim->read(reader); break; default: - m_anim.reset(nullptr); + m_anim.reset(); break; } } @@ -123,22 +123,22 @@ void CHAR::AnimationInfo::MetaAnimFactory::Enumerate(athena::i std::string type = reader.readString("type"); std::transform(type.begin(), type.end(), type.begin(), tolower); if (type == "primitive") { - m_anim.reset(new struct MetaAnimPrimitive); + m_anim = std::make_unique(); m_anim->read(reader); } else if (type == "blend") { - m_anim.reset(new struct MetaAnimBlend); + m_anim = std::make_unique(); m_anim->read(reader); } else if (type == "phaseblend") { - m_anim.reset(new struct MetaAnimPhaseBlend); + m_anim = std::make_unique(); m_anim->read(reader); } else if (type == "random") { - m_anim.reset(new struct MetaAnimRandom); + m_anim = std::make_unique(); m_anim->read(reader); } else if (type == "sequence") { - m_anim.reset(new struct MetaAnimSequence); + m_anim = std::make_unique(); m_anim->read(reader); } else { - m_anim.reset(nullptr); + m_anim.reset(); } } diff --git a/DataSpec/DNAMP3/CMDLMaterials.cpp b/DataSpec/DNAMP3/CMDLMaterials.cpp index a6449dbf7..75f82dae7 100644 --- a/DataSpec/DNAMP3/CMDLMaterials.cpp +++ b/DataSpec/DNAMP3/CMDLMaterials.cpp @@ -12,19 +12,19 @@ void MaterialSet::Material::SectionFactory::Enumerate(typename Rea type.read(reader); switch (ISection::Type(type.toUint32())) { case ISection::Type::PASS: - section.reset(new struct SectionPASS); + section = std::make_unique(); section->read(reader); break; case ISection::Type::CLR: - section.reset(new struct SectionCLR); + section = std::make_unique(); section->read(reader); break; case ISection::Type::INT: - section.reset(new struct SectionINT); + section = std::make_unique(); section->read(reader); break; default: - section.reset(nullptr); + section.reset(); break; } }