RetroDataSpec: Make use of make_unique where applicable

Same behavior, but without a mildly wonky way of performing it.
This commit is contained in:
Lioncash 2020-03-31 12:50:26 -04:00
parent 53694481e5
commit 9ef2fbba5a
9 changed files with 82 additions and 77 deletions

View File

@ -27,11 +27,11 @@ void MAPA::Enumerate<BigDNA::Read>(typename Read::StreamT& __dna_reader) {
/* version */ /* version */
version = __dna_reader.readUint32Big(); version = __dna_reader.readUint32Big();
if (version == 2) if (version == 2)
header.reset(new HeaderMP1); header = std::make_unique<HeaderMP1>();
else if (version == 3) else if (version == 3)
header.reset(new HeaderMP2); header = std::make_unique<HeaderMP2>();
else if (version == 5) else if (version == 5)
header.reset(new HeaderMP3); header = std::make_unique<HeaderMP3>();
else { else {
LogDNACommon.report(logvisor::Error, fmt("invalid MAPA version")); LogDNACommon.report(logvisor::Error, fmt("invalid MAPA version"));
return; return;
@ -41,10 +41,11 @@ void MAPA::Enumerate<BigDNA::Read>(typename Read::StreamT& __dna_reader) {
for (atUint32 i = 0; i < header->mappableObjectCount(); i++) { for (atUint32 i = 0; i < header->mappableObjectCount(); i++) {
std::unique_ptr<IMappableObject> mo = nullptr; std::unique_ptr<IMappableObject> mo = nullptr;
if (version != 5) if (version != 5) {
mo.reset(new MappableObjectMP1_2); mo = std::make_unique<MappableObjectMP1_2>();
else } else {
mo.reset(new MappableObjectMP3); mo = std::make_unique<MappableObjectMP3>();
}
mo->read(__dna_reader); mo->read(__dna_reader);
mappableObjects.push_back(std::move(mo)); mappableObjects.push_back(std::move(mo));
} }

View File

@ -611,30 +611,30 @@ std::string_view ANCS::CharacterSet::CharacterInfo::DNAType() {
template <> template <>
void ANCS::AnimationSet::MetaAnimFactory::Enumerate<BigDNA::Read>(athena::io::IStreamReader& reader) { void ANCS::AnimationSet::MetaAnimFactory::Enumerate<BigDNA::Read>(athena::io::IStreamReader& reader) {
IMetaAnim::Type type(IMetaAnim::Type(reader.readUint32Big())); const auto type = IMetaAnim::Type(reader.readUint32Big());
switch (type) { switch (type) {
case IMetaAnim::Type::Primitive: case IMetaAnim::Type::Primitive:
m_anim.reset(new struct MetaAnimPrimitive); m_anim = std::make_unique<MetaAnimPrimitive>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case IMetaAnim::Type::Blend: case IMetaAnim::Type::Blend:
m_anim.reset(new struct MetaAnimBlend); m_anim = std::make_unique<MetaAnimBlend>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case IMetaAnim::Type::PhaseBlend: case IMetaAnim::Type::PhaseBlend:
m_anim.reset(new struct MetaAnimPhaseBlend); m_anim = std::make_unique<MetaAnimPhaseBlend>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case IMetaAnim::Type::Random: case IMetaAnim::Type::Random:
m_anim.reset(new struct MetaAnimRandom); m_anim = std::make_unique<MetaAnimRandom>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case IMetaAnim::Type::Sequence: case IMetaAnim::Type::Sequence:
m_anim.reset(new struct MetaAnimSequence); m_anim = std::make_unique<MetaAnimSequence>();
m_anim->read(reader); m_anim->read(reader);
break; break;
default: default:
m_anim.reset(nullptr); m_anim.reset();
break; break;
} }
} }
@ -660,22 +660,22 @@ void ANCS::AnimationSet::MetaAnimFactory::Enumerate<BigDNA::ReadYaml>(athena::io
std::string type = reader.readString("type"); std::string type = reader.readString("type");
std::transform(type.begin(), type.end(), type.begin(), tolower); std::transform(type.begin(), type.end(), type.begin(), tolower);
if (type == "primitive") { if (type == "primitive") {
m_anim.reset(new struct MetaAnimPrimitive); m_anim = std::make_unique<MetaAnimPrimitive>();
m_anim->read(reader); m_anim->read(reader);
} else if (type == "blend") { } else if (type == "blend") {
m_anim.reset(new struct MetaAnimBlend); m_anim = std::make_unique<MetaAnimBlend>();
m_anim->read(reader); m_anim->read(reader);
} else if (type == "phaseblend") { } else if (type == "phaseblend") {
m_anim.reset(new struct MetaAnimPhaseBlend); m_anim = std::make_unique<MetaAnimPhaseBlend>();
m_anim->read(reader); m_anim->read(reader);
} else if (type == "random") { } else if (type == "random") {
m_anim.reset(new struct MetaAnimRandom); m_anim = std::make_unique<MetaAnimRandom>();
m_anim->read(reader); m_anim->read(reader);
} else if (type == "sequence") { } else if (type == "sequence") {
m_anim.reset(new struct MetaAnimSequence); m_anim = std::make_unique<MetaAnimSequence>();
m_anim->read(reader); m_anim->read(reader);
} else { } else {
m_anim.reset(nullptr); m_anim.reset();
} }
} }
@ -696,20 +696,20 @@ void ANCS::AnimationSet::MetaTransFactory::Enumerate<BigDNA::Read>(athena::io::I
IMetaTrans::Type type(IMetaTrans::Type(reader.readUint32Big())); IMetaTrans::Type type(IMetaTrans::Type(reader.readUint32Big()));
switch (type) { switch (type) {
case IMetaTrans::Type::MetaAnim: case IMetaTrans::Type::MetaAnim:
m_trans.reset(new struct MetaTransMetaAnim); m_trans = std::make_unique<MetaTransMetaAnim>();
m_trans->read(reader); m_trans->read(reader);
break; break;
case IMetaTrans::Type::Trans: case IMetaTrans::Type::Trans:
m_trans.reset(new struct MetaTransTrans); m_trans = std::make_unique<MetaTransTrans>();
m_trans->read(reader); m_trans->read(reader);
break; break;
case IMetaTrans::Type::PhaseTrans: case IMetaTrans::Type::PhaseTrans:
m_trans.reset(new struct MetaTransPhaseTrans); m_trans = std::make_unique<MetaTransPhaseTrans>();
m_trans->read(reader); m_trans->read(reader);
break; break;
case IMetaTrans::Type::NoTrans: case IMetaTrans::Type::NoTrans:
default: default:
m_trans.reset(nullptr); m_trans.reset();
break; break;
} }
} }
@ -737,16 +737,16 @@ void ANCS::AnimationSet::MetaTransFactory::Enumerate<BigDNA::ReadYaml>(athena::i
std::string type = reader.readString("type"); std::string type = reader.readString("type");
std::transform(type.begin(), type.end(), type.begin(), tolower); std::transform(type.begin(), type.end(), type.begin(), tolower);
if (type == "metaanim") { if (type == "metaanim") {
m_trans.reset(new struct MetaTransMetaAnim); m_trans = std::make_unique<MetaTransMetaAnim>();
m_trans->read(reader); m_trans->read(reader);
} else if (type == "trans") { } else if (type == "trans") {
m_trans.reset(new struct MetaTransTrans); m_trans = std::make_unique<MetaTransTrans>();
m_trans->read(reader); m_trans->read(reader);
} else if (type == "phasetrans") { } else if (type == "phasetrans") {
m_trans.reset(new struct MetaTransPhaseTrans); m_trans = std::make_unique<MetaTransPhaseTrans>();
m_trans->read(reader); m_trans->read(reader);
} else { } else {
m_trans.reset(nullptr); m_trans.reset();
} }
} }

View File

@ -122,15 +122,15 @@ void ANIM::Enumerate<BigDNA::Read>(typename Read::StreamT& reader) {
atUint32 version = reader.readUint32Big(); atUint32 version = reader.readUint32Big();
switch (version) { switch (version) {
case 0: case 0:
m_anim.reset(new struct ANIM0); m_anim = std::make_unique<ANIM0>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case 2: case 2:
m_anim.reset(new struct ANIM2(false)); m_anim = std::make_unique<ANIM2>(false);
m_anim->read(reader); m_anim->read(reader);
break; break;
case 3: case 3:
m_anim.reset(new struct ANIM2(true)); m_anim = std::make_unique<ANIM2>(true);
m_anim->read(reader); m_anim->read(reader);
break; break;
default: default:
@ -548,7 +548,7 @@ void ANIM::ANIM2::Enumerate<BigDNA::BinarySize>(size_t& __isz) {
ANIM::ANIM(const BlenderAction& act, const std::unordered_map<std::string, atInt32>& idMap, ANIM::ANIM(const BlenderAction& act, const std::unordered_map<std::string, atInt32>& idMap,
const DNAANIM::RigInverter<CINF>& rig, bool pc) { const DNAANIM::RigInverter<CINF>& rig, bool pc) {
m_anim.reset(new struct ANIM2(pc)); m_anim = std::make_unique<ANIM2>(pc);
IANIM& newAnim = *m_anim; IANIM& newAnim = *m_anim;
newAnim.looping = act.looping; newAnim.looping = act.looping;

View File

@ -99,15 +99,18 @@ void DCLN::Collision::Node::Enumerate(typename Op::StreamT& s) {
Do<Op>(athena::io::PropId{"halfExtent"}, halfExtent, s); Do<Op>(athena::io::PropId{"halfExtent"}, halfExtent, s);
Do<Op>(athena::io::PropId{"isLeaf"}, isLeaf, s); Do<Op>(athena::io::PropId{"isLeaf"}, isLeaf, s);
if (isLeaf) { if (isLeaf) {
if (!leafData) if (!leafData) {
leafData.reset(new LeafData); leafData = std::make_unique<LeafData>();
}
Do<Op>(athena::io::PropId{"leafData"}, *leafData, s); Do<Op>(athena::io::PropId{"leafData"}, *leafData, s);
} else { } else {
if (!left) if (!left) {
left.reset(new Node); left = std::make_unique<Node>();
}
Do<Op>(athena::io::PropId{"left"}, *left, s); Do<Op>(athena::io::PropId{"left"}, *left, s);
if (!right) if (!right) {
right.reset(new Node); right = std::make_unique<Node>();
}
Do<Op>(athena::io::PropId{"right"}, *right, s); Do<Op>(athena::io::PropId{"right"}, *right, s);
} }
} }

View File

@ -54,43 +54,43 @@ void FRME::Widget::Enumerate<BigDNA::Read>(athena::io::IStreamReader& __dna_read
header.read(__dna_reader); header.read(__dna_reader);
switch (type.toUint32()) { switch (type.toUint32()) {
case SBIG('BWIG'): case SBIG('BWIG'):
widgetInfo.reset(new BWIGInfo); widgetInfo = std::make_unique<BWIGInfo>();
break; break;
case SBIG('HWIG'): case SBIG('HWIG'):
widgetInfo.reset(new HWIGInfo); widgetInfo = std::make_unique<HWIGInfo>();
break; break;
case SBIG('CAMR'): case SBIG('CAMR'):
widgetInfo.reset(new CAMRInfo); widgetInfo = std::make_unique<CAMRInfo>();
break; break;
case SBIG('LITE'): case SBIG('LITE'):
widgetInfo.reset(new LITEInfo); widgetInfo = std::make_unique<LITEInfo>();
break; break;
case SBIG('ENRG'): case SBIG('ENRG'):
widgetInfo.reset(new ENRGInfo); widgetInfo = std::make_unique<ENRGInfo>();
break; break;
case SBIG('MODL'): case SBIG('MODL'):
widgetInfo.reset(new MODLInfo); widgetInfo = std::make_unique<MODLInfo>();
break; break;
case SBIG('METR'): case SBIG('METR'):
widgetInfo.reset(new METRInfo); widgetInfo = std::make_unique<METRInfo>();
break; break;
case SBIG('GRUP'): case SBIG('GRUP'):
widgetInfo.reset(new GRUPInfo); widgetInfo = std::make_unique<GRUPInfo>();
break; break;
case SBIG('PANE'): case SBIG('PANE'):
widgetInfo.reset(new PANEInfo); widgetInfo = std::make_unique<PANEInfo>();
break; break;
case SBIG('TXPN'): case SBIG('TXPN'):
widgetInfo.reset(new TXPNInfo(owner->version)); widgetInfo = std::make_unique<TXPNInfo>(owner->version);
break; break;
case SBIG('IMGP'): case SBIG('IMGP'):
widgetInfo.reset(new IMGPInfo); widgetInfo = std::make_unique<IMGPInfo>();
break; break;
case SBIG('TBGP'): case SBIG('TBGP'):
widgetInfo.reset(new TBGPInfo); widgetInfo = std::make_unique<TBGPInfo>();
break; break;
case SBIG('SLGP'): case SBIG('SLGP'):
widgetInfo.reset(new SLGPInfo); widgetInfo = std::make_unique<SLGPInfo>();
break; break;
default: default:
Log.report(logvisor::Fatal, fmt(_SYS_STR("Unsupported FRME widget type {}")), type); Log.report(logvisor::Fatal, fmt(_SYS_STR("Unsupported FRME widget type {}")), type);
@ -169,12 +169,13 @@ void FRME::Widget::Enumerate<BigDNA::BinarySize>(size_t& __isz) {
template <> template <>
void FRME::Widget::CAMRInfo::Enumerate<BigDNA::Read>(athena::io::IStreamReader& __dna_reader) { void FRME::Widget::CAMRInfo::Enumerate<BigDNA::Read>(athena::io::IStreamReader& __dna_reader) {
projectionType = ProjectionType(__dna_reader.readUint32Big()); projectionType = ProjectionType(__dna_reader.readUint32Big());
if (projectionType == ProjectionType::Perspective) if (projectionType == ProjectionType::Perspective) {
projection.reset(new PerspectiveProjection); projection = std::make_unique<PerspectiveProjection>();
else if (projectionType == ProjectionType::Orthographic) } else if (projectionType == ProjectionType::Orthographic) {
projection.reset(new OrthographicProjection); projection = std::make_unique<OrthographicProjection>();
else } else {
Log.report(logvisor::Fatal, fmt(_SYS_STR("Invalid CAMR projection mode! {}")), int(projectionType)); Log.report(logvisor::Fatal, fmt(_SYS_STR("Invalid CAMR projection mode! {}")), int(projectionType));
}
projection->read(__dna_reader); projection->read(__dna_reader);
} }

View File

@ -126,11 +126,11 @@ void ANIM::Enumerate<BigDNA::Read>(typename Read::StreamT& reader) {
atUint32 version = reader.readUint32Big(); atUint32 version = reader.readUint32Big();
switch (version) { switch (version) {
case 0: case 0:
m_anim.reset(new struct ANIM0); m_anim = std::make_unique<ANIM0>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case 2: case 2:
m_anim.reset(new struct ANIM2); m_anim = std::make_unique<ANIM2>();
m_anim->read(reader); m_anim->read(reader);
break; break;
default: default:

View File

@ -130,11 +130,11 @@ void ANIM::Enumerate<BigDNA::Read>(typename Read::StreamT& reader) {
atUint32 version = reader.readUint32Big(); atUint32 version = reader.readUint32Big();
switch (version) { switch (version) {
case 0: case 0:
m_anim.reset(new struct ANIM0); m_anim = std::make_unique<ANIM0>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case 1: case 1:
m_anim.reset(new struct ANIM1); m_anim = std::make_unique<ANIM1>();
m_anim->read(reader); m_anim->read(reader);
break; break;
default: default:

View File

@ -74,30 +74,30 @@ std::string_view CHAR::AnimationInfo::EVNT::SFXEvent::DNAType() {
template <> template <>
void CHAR::AnimationInfo::MetaAnimFactory::Enumerate<BigDNA::Read>(athena::io::IStreamReader& reader) { void CHAR::AnimationInfo::MetaAnimFactory::Enumerate<BigDNA::Read>(athena::io::IStreamReader& reader) {
IMetaAnim::Type type(IMetaAnim::Type(reader.readUint32Big())); const auto type = IMetaAnim::Type(reader.readUint32Big());
switch (type) { switch (type) {
case IMetaAnim::Type::Primitive: case IMetaAnim::Type::Primitive:
m_anim.reset(new struct MetaAnimPrimitive); m_anim = std::make_unique<MetaAnimPrimitive>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case IMetaAnim::Type::Blend: case IMetaAnim::Type::Blend:
m_anim.reset(new struct MetaAnimBlend); m_anim = std::make_unique<MetaAnimBlend>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case IMetaAnim::Type::PhaseBlend: case IMetaAnim::Type::PhaseBlend:
m_anim.reset(new struct MetaAnimPhaseBlend); m_anim = std::make_unique<MetaAnimPhaseBlend>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case IMetaAnim::Type::Random: case IMetaAnim::Type::Random:
m_anim.reset(new struct MetaAnimRandom); m_anim = std::make_unique<MetaAnimRandom>();
m_anim->read(reader); m_anim->read(reader);
break; break;
case IMetaAnim::Type::Sequence: case IMetaAnim::Type::Sequence:
m_anim.reset(new struct MetaAnimSequence); m_anim = std::make_unique<MetaAnimSequence>();
m_anim->read(reader); m_anim->read(reader);
break; break;
default: default:
m_anim.reset(nullptr); m_anim.reset();
break; break;
} }
} }
@ -123,22 +123,22 @@ void CHAR::AnimationInfo::MetaAnimFactory::Enumerate<BigDNA::ReadYaml>(athena::i
std::string type = reader.readString("type"); std::string type = reader.readString("type");
std::transform(type.begin(), type.end(), type.begin(), tolower); std::transform(type.begin(), type.end(), type.begin(), tolower);
if (type == "primitive") { if (type == "primitive") {
m_anim.reset(new struct MetaAnimPrimitive); m_anim = std::make_unique<MetaAnimPrimitive>();
m_anim->read(reader); m_anim->read(reader);
} else if (type == "blend") { } else if (type == "blend") {
m_anim.reset(new struct MetaAnimBlend); m_anim = std::make_unique<MetaAnimBlend>();
m_anim->read(reader); m_anim->read(reader);
} else if (type == "phaseblend") { } else if (type == "phaseblend") {
m_anim.reset(new struct MetaAnimPhaseBlend); m_anim = std::make_unique<MetaAnimPhaseBlend>();
m_anim->read(reader); m_anim->read(reader);
} else if (type == "random") { } else if (type == "random") {
m_anim.reset(new struct MetaAnimRandom); m_anim = std::make_unique<MetaAnimRandom>();
m_anim->read(reader); m_anim->read(reader);
} else if (type == "sequence") { } else if (type == "sequence") {
m_anim.reset(new struct MetaAnimSequence); m_anim = std::make_unique<MetaAnimSequence>();
m_anim->read(reader); m_anim->read(reader);
} else { } else {
m_anim.reset(nullptr); m_anim.reset();
} }
} }

View File

@ -12,19 +12,19 @@ void MaterialSet::Material::SectionFactory::Enumerate<BigDNA::Read>(typename Rea
type.read(reader); type.read(reader);
switch (ISection::Type(type.toUint32())) { switch (ISection::Type(type.toUint32())) {
case ISection::Type::PASS: case ISection::Type::PASS:
section.reset(new struct SectionPASS); section = std::make_unique<SectionPASS>();
section->read(reader); section->read(reader);
break; break;
case ISection::Type::CLR: case ISection::Type::CLR:
section.reset(new struct SectionCLR); section = std::make_unique<SectionCLR>();
section->read(reader); section->read(reader);
break; break;
case ISection::Type::INT: case ISection::Type::INT:
section.reset(new struct SectionINT); section = std::make_unique<SectionINT>();
section->read(reader); section->read(reader);
break; break;
default: default:
section.reset(nullptr); section.reset();
break; break;
} }
} }