diff --git a/DataSpec/DNACommon/AROTBuilder.cpp b/DataSpec/DNACommon/AROTBuilder.cpp index 52315572a..fbe48dd41 100644 --- a/DataSpec/DNACommon/AROTBuilder.cpp +++ b/DataSpec/DNACommon/AROTBuilder.cpp @@ -1,15 +1,19 @@ #include "AROTBuilder.hpp" + +#include +#include + #include "hecl/Blender/Connection.hpp" #include "../DNAMP1/PATH.hpp" namespace DataSpec { logvisor::Module Log("AROTBuilder"); -#define AROT_MAX_LEVEL 10 -#define AROT_MIN_SUBDIV 10.f -#define AROT_MIN_MODELS 8 -#define COLLISION_MIN_NODE_TRIANGLES 8 -#define PATH_MIN_NODE_REGIONS 16 +constexpr s32 AROT_MAX_LEVEL = 10; +constexpr s32 AROT_MIN_MODELS = 8; +constexpr s32 COLLISION_MIN_NODE_TRIANGLES = 8; +constexpr s32 PATH_MIN_NODE_REGIONS = 16; +constexpr float AROT_MIN_SUBDIV = 10.f; static zeus::CAABox SplitAABB(const zeus::CAABox& aabb, int i) { zeus::CAABox pos, neg; @@ -128,7 +132,9 @@ size_t AROTBuilder::BitmapPool::addIndices(const std::set& indices) { return m_pool.size() - 1; } -static const uint32_t AROTChildCounts[] = {0, 2, 2, 4, 2, 4, 4, 8}; +constexpr std::array AROTChildCounts{ + 0, 2, 2, 4, 2, 4, 4, 8, +}; void AROTBuilder::Node::nodeCount(size_t& sz, size_t& idxRefs, BitmapPool& bmpPool, size_t& curOff) { sz += 1; @@ -176,7 +182,7 @@ void AROTBuilder::Node::writeNodes(athena::io::MemoryWriter& w, int nodeIdx) { if (curIdx > 65535) Log.report(logvisor::Fatal, fmt("AROT node exceeds 16-bit node addressing; area too complex")); - int childIndices[8]; + std::array childIndices; for (int k = 0; k < 1 + ((compSubdivs & 0x4) != 0); ++k) { for (int j = 0; j < 1 + ((compSubdivs & 0x2) != 0); ++j) { @@ -280,17 +286,16 @@ void AROTBuilder::Node::pathWrite(DNAMP1::PATH& path, const zeus::CAABox& curAAB n.aabb[0] = curAABB.min; n.aabb[1] = curAABB.max; n.centroid = curAABB.center(); - for (int i = 0; i < 8; ++i) - n.children[i] = 0xffffffff; + std::fill(std::begin(n.children), std::end(n.children), 0xFFFFFFFF); n.regionCount = childIndices.size(); n.regionStart = path.octreeRegionLookup.size(); for (int r : childIndices) path.octreeRegionLookup.push_back(r); } else { - atUint32 children[8]; - for (int i = 0; i < 8; ++i) { + std::array children; + for (size_t i = 0; i < children.size(); ++i) { /* Head recursion (first node will be a leaf) */ - childNodes[i].pathWrite(path, SplitAABB(curAABB, i)); + childNodes[i].pathWrite(path, SplitAABB(curAABB, static_cast(i))); children[i] = path.octree.size() - 1; } @@ -300,8 +305,7 @@ void AROTBuilder::Node::pathWrite(DNAMP1::PATH& path, const zeus::CAABox& curAAB n.aabb[0] = curAABB.min; n.aabb[1] = curAABB.max; n.centroid = curAABB.center(); - for (int i = 0; i < 8; ++i) - n.children[i] = children[i]; + std::copy(children.cbegin(), children.cend(), std::begin(n.children)); n.regionCount = 0; n.regionStart = 0; } @@ -343,18 +347,20 @@ void AROTBuilder::build(std::vector>& secs, const zeus::CAA auto bmpIt = bmp.cbegin(); if (bmpIt != bmp.cend()) { int curIdx = 0; - for (size_t w = 0; w < bmpWordCount; ++w) { - for (int b = 0; b < 32; ++b) { + for (size_t word = 0; word < bmpWordCount; ++word) { + for (u32 b = 0; b < 32; ++b) { if (*bmpIt == curIdx) { - bmpWords[w] |= 1 << b; + bmpWords[word] |= 1U << b; ++bmpIt; - if (bmpIt == bmp.cend()) + if (bmpIt == bmp.cend()) { break; + } } ++curIdx; } - if (bmpIt == bmp.cend()) + if (bmpIt == bmp.cend()) { break; + } } } @@ -377,12 +383,11 @@ std::pair, uint32_t> AROTBuilder::buildCol(const ColM std::vector triBoxes; triBoxes.reserve(mesh.trianges.size()); for (const ColMesh::Triangle& tri : mesh.trianges) { - triBoxes.emplace_back(); - zeus::CAABox& aabb = triBoxes.back(); - for (int e = 0; e < 3; ++e) { - const ColMesh::Edge& edge = mesh.edges[tri.edges[e]]; - for (int v = 0; v < 2; ++v) { - const auto& vert = mesh.verts[edge.verts[v]]; + zeus::CAABox& aabb = triBoxes.emplace_back(); + for (const u32 edgeIdx : tri.edges) { + const ColMesh::Edge& edge = mesh.edges[edgeIdx]; + for (const u32 vertIdx : edge.verts) { + const auto& vert = mesh.verts[vertIdx]; aabb.accumulateBounds(zeus::CVector3f(vert)); } } diff --git a/DataSpec/DNACommon/ATBL.cpp b/DataSpec/DNACommon/ATBL.cpp index 24b4a37f1..10e5f3ead 100644 --- a/DataSpec/DNACommon/ATBL.cpp +++ b/DataSpec/DNACommon/ATBL.cpp @@ -48,9 +48,7 @@ bool ATBL::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat maxI = std::max(maxI, i); } - std::vector vecOut; - vecOut.resize(maxI + 1, 0xffff); - + std::vector vecOut(maxI + 1, 0xffff); for (const auto& pair : dr.getRootNode()->m_mapChildren) { unsigned long i = strtoul(pair.first.c_str(), nullptr, 0); vecOut[i] = hecl::SBig(uint16_t(strtoul(pair.second->m_scalarString.c_str(), nullptr, 0))); diff --git a/DataSpec/DNACommon/CRSC.cpp b/DataSpec/DNACommon/CRSC.cpp index e5e8c7878..45069cd35 100644 --- a/DataSpec/DNACommon/CRSC.cpp +++ b/DataSpec/DNACommon/CRSC.cpp @@ -1,248 +1,24 @@ #include "DataSpec/DNACommon/CRSC.hpp" - -#include - #include "DataSpec/DNACommon/PAK.hpp" -#include - namespace DataSpec::DNAParticle { -static const std::vector GeneratorTypes = { - SBIG('NODP'), SBIG('DEFS'), SBIG('CRTS'), SBIG('MTLS'), SBIG('GRAS'), SBIG('ICEE'), SBIG('GOOO'), SBIG('WODS'), - SBIG('WATR'), SBIG('1MUD'), SBIG('1LAV'), SBIG('1SAN'), SBIG('1PRJ'), SBIG('DCHR'), SBIG('DCHS'), SBIG('DCSH'), - SBIG('DENM'), SBIG('DESP'), SBIG('DESH'), SBIG('BTLE'), SBIG('WASP'), SBIG('TALP'), SBIG('PTGM'), SBIG('SPIR'), - SBIG('FPIR'), SBIG('FFLE'), SBIG('PARA'), SBIG('BMON'), SBIG('BFLR'), SBIG('PBOS'), SBIG('IBOS'), SBIG('1SVA'), - SBIG('1RPR'), SBIG('1MTR'), SBIG('1PDS'), SBIG('1FLB'), SBIG('1DRN'), SBIG('1MRE'), SBIG('CHOZ'), SBIG('JZAP'), - SBIG('1ISE'), SBIG('1BSE'), SBIG('1ATB'), SBIG('1ATA'), SBIG('BTSP'), SBIG('WWSP'), SBIG('TASP'), SBIG('TGSP'), - SBIG('SPSP'), SBIG('FPSP'), SBIG('FFSP'), SBIG('PSSP'), SBIG('BMSP'), SBIG('BFSP'), SBIG('PBSP'), SBIG('IBSP'), - SBIG('2SVA'), SBIG('2RPR'), SBIG('2MTR'), SBIG('2PDS'), SBIG('2FLB'), SBIG('2DRN'), SBIG('2MRE'), SBIG('CHSP'), - SBIG('JZSP'), SBIG('3ISE'), SBIG('3BSE'), SBIG('3ATB'), SBIG('3ATA'), SBIG('BTSH'), SBIG('WWSH'), SBIG('TASH'), - SBIG('TGSH'), SBIG('SPSH'), SBIG('FPSH'), SBIG('FFSH'), SBIG('PSSH'), SBIG('BMSH'), SBIG('BFSH'), SBIG('PBSH'), - SBIG('IBSH'), SBIG('3SVA'), SBIG('3RPR'), SBIG('3MTR'), SBIG('3PDS'), SBIG('3FLB'), SBIG('3DRN'), SBIG('3MRE'), - SBIG('CHSH'), SBIG('JZSH'), SBIG('5ISE'), SBIG('5BSE'), SBIG('5ATB'), SBIG('5ATA')}; -static const std::vector SFXTypes = { - SBIG('DSFX'), SBIG('CSFX'), SBIG('MSFX'), SBIG('GRFX'), SBIG('NSFX'), SBIG('DSFX'), SBIG('CSFX'), SBIG('MSFX'), - SBIG('GRFX'), SBIG('ICFX'), SBIG('GOFX'), SBIG('WSFX'), SBIG('WTFX'), SBIG('2MUD'), SBIG('2LAV'), SBIG('2SAN'), - SBIG('2PRJ'), SBIG('DCFX'), SBIG('DSFX'), SBIG('DSHX'), SBIG('DEFX'), SBIG('ESFX'), SBIG('SHFX'), SBIG('BEFX'), - SBIG('WWFX'), SBIG('TAFX'), SBIG('GTFX'), SBIG('SPFX'), SBIG('FPFX'), SBIG('FFFX'), SBIG('PAFX'), SBIG('BMFX'), - SBIG('BFFX'), SBIG('PBFX'), SBIG('IBFX'), SBIG('4SVA'), SBIG('4RPR'), SBIG('4MTR'), SBIG('4PDS'), SBIG('4FLB'), - SBIG('4DRN'), SBIG('4MRE'), SBIG('CZFX'), SBIG('JZAS'), SBIG('2ISE'), SBIG('2BSE'), SBIG('2ATB'), SBIG('2ATA'), - SBIG('BSFX'), SBIG('WSFX'), SBIG('TSFX'), SBIG('GSFX'), SBIG('SSFX'), SBIG('FSFX'), SBIG('SFFX'), SBIG('PSFX'), - SBIG('MSFX'), SBIG('SBFX'), SBIG('PBSX'), SBIG('IBSX'), SBIG('5SVA'), SBIG('5RPR'), SBIG('5MTR'), SBIG('5PDS'), - SBIG('5FLB'), SBIG('5DRN'), SBIG('5MRE'), SBIG('CSFX'), SBIG('JZPS'), SBIG('4ISE'), SBIG('4BSE'), SBIG('4ATB'), - SBIG('4ATA'), SBIG('BHFX'), SBIG('WHFX'), SBIG('THFX'), SBIG('GHFX'), SBIG('SHFX'), SBIG('FHFX'), SBIG('HFFX'), - SBIG('PHFX'), SBIG('MHFX'), SBIG('HBFX'), SBIG('PBHX'), SBIG('IBHX'), SBIG('6SVA'), SBIG('6RPR'), SBIG('6MTR'), - SBIG('6PDS'), SBIG('6FLB'), SBIG('6DRN'), SBIG('6MRE'), SBIG('CHFX'), SBIG('JZHS'), SBIG('6ISE'), SBIG('6BSE'), - SBIG('6ATB'), SBIG('6ATA'), -}; +template struct PPImpl<_CRSM>; +template struct PPImpl<_CRSM>; -static const std::vector DecalTypes = {SBIG('NCDL'), SBIG('DDCL'), SBIG('CODL'), SBIG('MEDL'), SBIG('GRDL'), - SBIG('ICDL'), SBIG('GODL'), SBIG('WODL'), SBIG('WTDL'), SBIG('3MUD'), - SBIG('3LAV'), SBIG('3SAN'), SBIG('CHDL'), SBIG('ENDL')}; +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_CRSM>) +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_CRSM>) template <> -std::string_view CRSM::DNAType() { - return "CRSM"sv; +std::string_view PPImpl<_CRSM>::DNAType() { + return "urde::CRSM"sv; } template <> -std::string_view CRSM::DNAType() { - return "CRSM"sv; +std::string_view PPImpl<_CRSM>::DNAType() { + return "urde::CRSM"sv; } -template -void CRSM::_read(athena::io::YAMLDocReader& r) { - for (const auto& elem : r.getCurNode()->m_mapChildren) { - if (elem.first.size() < 4) { - LogModule.report(logvisor::Warning, fmt("short FourCC in element '{}'"), elem.first); - continue; - } - - if (auto rec = r.enterSubRecord(elem.first.c_str())) { - FourCC clsId(elem.first.c_str()); - auto gen = std::find_if(GeneratorTypes.begin(), GeneratorTypes.end(), - [&clsId](const FourCC& other) { return clsId == other; }); - if (gen != GeneratorTypes.end()) { - x0_generators[clsId].read(r); - continue; - } - - auto sfx = std::find_if(SFXTypes.begin(), SFXTypes.end(), - [&clsId](const FourCC& other) { return clsId == other; }); - if (sfx != SFXTypes.end()) { - x10_sfx[clsId] = r.readInt32(clsId.toString()); - continue; - } - - auto decal = std::find_if(DecalTypes.begin(), DecalTypes.end(), - [&clsId](const FourCC& other) { return clsId == other; }); - if (decal != DecalTypes.end()) { - x20_decals[clsId].read(r); - continue; - } - if (clsId == SBIG('RNGE')) - x30_RNGE = r.readFloat(); - else if (clsId == SBIG('FOFF')) - x34_FOFF = r.readFloat(); - } - } -} - -template -void CRSM::_write(athena::io::YAMLDocWriter& w) const { - for (const auto& pair : x0_generators) - if (pair.second) - if (auto rec = w.enterSubRecord(pair.first.toString())) - pair.second.write(w); - - for (const auto& pair : x10_sfx) - if (pair.second != UINT32_MAX) - w.writeUint32(pair.first.toString(), pair.second); - - for (const auto& pair : x20_decals) - if (pair.second) - if (auto rec = w.enterSubRecord(pair.first.toString())) - pair.second.write(w); - - if (x30_RNGE != 50.f) - w.writeFloat("RNGE", x30_RNGE); - if (x34_FOFF != 0.2f) - w.writeFloat("FOFF", x34_FOFF); -} - -template -void CRSM::_binarySize(size_t& __isz) const { - __isz += 4; - for (const auto& pair : x0_generators) { - if (pair.second) { - __isz += 4; - pair.second.binarySize(__isz); - } - } - for (const auto& pair : x10_sfx) { - if (pair.second != UINT32_MAX) - __isz += 12; - } - - for (const auto& pair : x20_decals) { - if (pair.second) { - __isz += 4; - pair.second.binarySize(__isz); - } - } - - if (x30_RNGE != 50.f) - __isz += 12; - if (x34_FOFF != 0.2f) - __isz += 12; -} - -template -void CRSM::_read(athena::io::IStreamReader& r) { - DNAFourCC clsId; - clsId.read(r); - if (clsId != SBIG('CRSM')) { - LogModule.report(logvisor::Warning, fmt("non CRSM provided to CRSM parser")); - return; - } - - while (clsId != SBIG('_END')) { - clsId.read(r); - auto gen = std::find_if(GeneratorTypes.begin(), GeneratorTypes.end(), - [&clsId](const FourCC& other) { return clsId == other; }); - if (gen != GeneratorTypes.end()) { - x0_generators[clsId].read(r); - continue; - } - - auto sfx = std::find_if(SFXTypes.begin(), SFXTypes.end(), - [&clsId](const FourCC& other) { return clsId == other; }); - if (sfx != SFXTypes.end()) { - DNAFourCC fcc; - fcc.read(r); - if (fcc != SBIG('NONE')) - x10_sfx[clsId] = r.readInt32Big(); - else - x10_sfx[clsId] = ~0; - continue; - } - - auto decal = std::find_if(DecalTypes.begin(), DecalTypes.end(), - [&clsId](const FourCC& other) { return clsId == other; }); - if (decal != DecalTypes.end()) { - x20_decals[clsId].read(r); - continue; - } - if (clsId == SBIG('RNGE')) { - r.readUint32(); - x30_RNGE = r.readFloatBig(); - continue; - } - if (clsId == SBIG('FOFF')) { - r.readUint32(); - x34_FOFF = r.readFloatBig(); - continue; - } - if (clsId != SBIG('_END')) - LogModule.report(logvisor::Fatal, fmt("Unknown CRSM class {} @{}"), clsId, r.position()); - } -} - -template -void CRSM::_write(athena::io::IStreamWriter& w) const { - w.writeBytes("CRSM", 4); - for (const auto& pair : x0_generators) { - w.writeBytes(pair.first.getChars(), 4); - pair.second.write(w); - } - - for (const auto& pair : x10_sfx) { - w.writeBytes(pair.first.getChars(), 4); - if (pair.second != UINT32_MAX) { - w.writeBytes("CNST", 4); - w.writeUint32Big(pair.second); - } else { - w.writeBytes("NONE", 4); - } - } - - for (const auto& pair : x20_decals) { - w.writeBytes(pair.first.getChars(), 4); - pair.second.write(w); - } - - if (x30_RNGE != 50.f) { - w.writeBytes("RNGECNST", 8); - w.writeFloatBig(x30_RNGE); - } - if (x34_FOFF != 0.2f) { - w.writeBytes("FOFFCNST", 8); - w.writeFloatBig(x34_FOFF); - } - w.writeBytes("_END", 4); -} - -AT_SUBSPECIALIZE_DNA_YAML(CRSM) -AT_SUBSPECIALIZE_DNA_YAML(CRSM) - -template -void CRSM::gatherDependencies(std::vector& pathsOut) const { - for (const auto& p : x0_generators) - g_curSpec->flattenDependencies(p.second.id, pathsOut); - for (const auto& p : x20_decals) - g_curSpec->flattenDependencies(p.second.id, pathsOut); -} - -template -CRSM::CRSM() : x30_RNGE(50.f), x34_FOFF(0.2f) { - for (const auto& sfx : SFXTypes) - x10_sfx[sfx] = ~0; -} - -template struct CRSM; -template struct CRSM; - template bool ExtractCRSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) { athena::io::FileWriter writer(outPath.getAbsolutePath()); diff --git a/DataSpec/DNACommon/CRSC.def b/DataSpec/DNACommon/CRSC.def new file mode 100644 index 000000000..6fe2e2b7e --- /dev/null +++ b/DataSpec/DNACommon/CRSC.def @@ -0,0 +1,222 @@ +#ifndef ENTRY +#define ENTRY(name, identifier) +#endif + +#ifndef RES_ENTRY +#define RES_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef U32_ENTRY +#define U32_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef FLOAT_ENTRY +#define FLOAT_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +RES_ENTRY('NODP', NODP) +RES_ENTRY('DEFS', DEFS) +RES_ENTRY('CRTS', CRTS) +RES_ENTRY('MTLS', MTLS) +RES_ENTRY('GRAS', GRAS) +RES_ENTRY('ICEE', ICEE) +RES_ENTRY('GOOO', GOOO) +RES_ENTRY('WODS', WODS) +RES_ENTRY('WATR', WATR) +RES_ENTRY('1MUD', _1MUD) +RES_ENTRY('1LAV', _1LAV) +RES_ENTRY('1SAN', _1SAN) +RES_ENTRY('1PRJ', _1PRJ) +RES_ENTRY('DCHR', DCHR) +RES_ENTRY('DCHS', DCHS) +RES_ENTRY('DCSH', DCSH) +RES_ENTRY('DENM', DENM) +RES_ENTRY('DESP', DESP) +RES_ENTRY('DESH', DESH) +RES_ENTRY('BTLE', BTLE) +RES_ENTRY('WASP', WASP) +RES_ENTRY('TALP', TALP) +RES_ENTRY('PTGM', PTGM) +RES_ENTRY('SPIR', SPIR) +RES_ENTRY('FPIR', FPIR) +RES_ENTRY('FFLE', FFLE) +RES_ENTRY('PARA', PARA) +RES_ENTRY('BMON', BMON) +RES_ENTRY('BFLR', BFLR) +RES_ENTRY('PBOS', PBOS) +RES_ENTRY('IBOS', IBOS) +RES_ENTRY('1SVA', _1SVA) +RES_ENTRY('1RPR', _1RPR) +RES_ENTRY('1MTR', _1MTR) +RES_ENTRY('1PDS', _1PDS) +RES_ENTRY('1FLB', _1FLB) +RES_ENTRY('1DRN', _1DRN) +RES_ENTRY('1MRE', _1MRE) +RES_ENTRY('CHOZ', CHOZ) +RES_ENTRY('JZAP', JZAP) +RES_ENTRY('1ISE', _1ISE) +RES_ENTRY('1BSE', _1BSE) +RES_ENTRY('1ATB', _1ATB) +RES_ENTRY('1ATA', _1ATA) +RES_ENTRY('BTSP', BTSP) +RES_ENTRY('WWSP', WWSP) +RES_ENTRY('TASP', TASP) +RES_ENTRY('TGSP', TGSP) +RES_ENTRY('SPSP', SPSP) +RES_ENTRY('FPSP', FPSP) +RES_ENTRY('FFSP', FFSP) +RES_ENTRY('PSSP', PSSP) +RES_ENTRY('BMSP', BMSP) +RES_ENTRY('BFSP', BFSP) +RES_ENTRY('PBSP', PBSP) +RES_ENTRY('IBSP', IBSP) +RES_ENTRY('2SVA', _2SVA) +RES_ENTRY('2RPR', _2RPR) +RES_ENTRY('2MTR', _2MTR) +RES_ENTRY('2PDS', _2PDS) +RES_ENTRY('2FLB', _2FLB) +RES_ENTRY('2DRN', _2DRN) +RES_ENTRY('2MRE', _2MRE) +RES_ENTRY('CHSP', CHSP) +RES_ENTRY('JZSP', JZSP) +RES_ENTRY('3ISE', _3ISE) +RES_ENTRY('3BSE', _3BSE) +RES_ENTRY('3ATB', _3ATB) +RES_ENTRY('3ATA', _3ATA) +RES_ENTRY('BTSH', BTSH) +RES_ENTRY('WWSH', WWSH) +RES_ENTRY('TASH', TASH) +RES_ENTRY('TGSH', TGSH) +RES_ENTRY('SPSH', SPSH) +RES_ENTRY('FPSH', FPSH) +RES_ENTRY('FFSH', FFSH) +RES_ENTRY('PSSH', PSSH) +RES_ENTRY('BMSH', BMSH) +RES_ENTRY('BFSH', BFSH) +RES_ENTRY('PBSH', PBSH) +RES_ENTRY('IBSH', IBSH) +RES_ENTRY('3SVA', _3SVA) +RES_ENTRY('3RPR', _3RPR) +RES_ENTRY('3MTR', _3MTR) +RES_ENTRY('3PDS', _3PDS) +RES_ENTRY('3FLB', _3FLB) +RES_ENTRY('3DRN', _3DRN) +RES_ENTRY('3MRE', _3MRE) +RES_ENTRY('CHSH', CHSH) +RES_ENTRY('JZSH', JZSH) +RES_ENTRY('5ISE', _5ISE) +RES_ENTRY('5BSE', _5BSE) +RES_ENTRY('5ATB', _5ATB) +RES_ENTRY('5ATA', _5ATA) +RES_ENTRY('NCDL', NCDL) +RES_ENTRY('DDCL', DDCL) +RES_ENTRY('CODL', CODL) +RES_ENTRY('MEDL', MEDL) +RES_ENTRY('GRDL', GRDL) +RES_ENTRY('ICDL', ICDL) +RES_ENTRY('GODL', GODL) +RES_ENTRY('WODL', WODL) +RES_ENTRY('WTDL', WTDL) +RES_ENTRY('3MUD', _3MUD) +RES_ENTRY('3LAV', _3LAV) +RES_ENTRY('3SAN', _3SAN) +RES_ENTRY('CHDL', CHDL) +RES_ENTRY('ENDL', ENDL) + +U32_ENTRY('NSFX', NSFX) +U32_ENTRY('DSFX', DSFX) +U32_ENTRY('CSFX', CSFX) +U32_ENTRY('MSFX', MSFX) +U32_ENTRY('GRFX', GRFX) +U32_ENTRY('ICFX', ICFX) +U32_ENTRY('GOFX', GOFX) +U32_ENTRY('WSFX', WSFX) +U32_ENTRY('WTFX', WTFX) +U32_ENTRY('2MUD', _2MUD) +U32_ENTRY('2LAV', _2LAV) +U32_ENTRY('2SAN', _2SAN) +U32_ENTRY('2PRJ', _2PRJ) +U32_ENTRY('DCFX', DCFX) +U32_ENTRY('DSHX', DSHX) +U32_ENTRY('DEFX', DEFX) +U32_ENTRY('ESFX', ESFX) +U32_ENTRY('SHFX', SHFX) +U32_ENTRY('BEFX', BEFX) +U32_ENTRY('WWFX', WWFX) +U32_ENTRY('TAFX', TAFX) +U32_ENTRY('GTFX', GTFX) +U32_ENTRY('SPFX', SPFX) +U32_ENTRY('FPFX', FPFX) +U32_ENTRY('FFFX', FFFX) +U32_ENTRY('PAFX', PAFX) +U32_ENTRY('BMFX', BMFX) +U32_ENTRY('BFFX', BFFX) +U32_ENTRY('PBFX', PBFX) +U32_ENTRY('IBFX', IBFX) +U32_ENTRY('4SVA', _4SVA) +U32_ENTRY('4RPR', _4RPR) +U32_ENTRY('4MTR', _4MTR) +U32_ENTRY('4PDS', _4PDS) +U32_ENTRY('4FLB', _4FLB) +U32_ENTRY('4DRN', _4DRN) +U32_ENTRY('4MRE', _4MRE) +U32_ENTRY('CZFX', CZFX) +U32_ENTRY('JZAS', JZAS) +U32_ENTRY('2ISE', _2ISE) +U32_ENTRY('2BSE', _2BSE) +U32_ENTRY('2ATB', _2ATB) +U32_ENTRY('2ATA', _2ATA) +U32_ENTRY('BSFX', BSFX) +U32_ENTRY('TSFX', TSFX) +U32_ENTRY('GSFX', GSFX) +U32_ENTRY('SSFX', SSFX) +U32_ENTRY('FSFX', FSFX) +U32_ENTRY('SFFX', SFFX) +U32_ENTRY('PSFX', PSFX) +U32_ENTRY('SBFX', SBFX) +U32_ENTRY('PBSX', PBSX) +U32_ENTRY('IBSX', IBSX) +U32_ENTRY('5SVA', _5SVA) +U32_ENTRY('5RPR', _5RPR) +U32_ENTRY('5MTR', _5MTR) +U32_ENTRY('5PDS', _5PDS) +U32_ENTRY('5FLB', _5FLB) +U32_ENTRY('5DRN', _5DRN) +U32_ENTRY('5MRE', _5MRE) +U32_ENTRY('JZPS', JZPS) +U32_ENTRY('4ISE', _4ISE) +U32_ENTRY('4BSE', _4BSE) +U32_ENTRY('4ATB', _4ATB) +U32_ENTRY('4ATA', _4ATA) +U32_ENTRY('BHFX', BHFX) +U32_ENTRY('WHFX', WHFX) +U32_ENTRY('THFX', THFX) +U32_ENTRY('GHFX', GHFX) +U32_ENTRY('FHFX', FHFX) +U32_ENTRY('HFFX', HFFX) +U32_ENTRY('PHFX', PHFX) +U32_ENTRY('MHFX', MHFX) +U32_ENTRY('HBFX', HBFX) +U32_ENTRY('PBHX', PBHX) +U32_ENTRY('IBHX', IBHX) +U32_ENTRY('6SVA', _6SVA) +U32_ENTRY('6RPR', _6RPR) +U32_ENTRY('6MTR', _6MTR) +U32_ENTRY('6PDS', _6PDS) +U32_ENTRY('6FLB', _6FLB) +U32_ENTRY('6DRN', _6DRN) +U32_ENTRY('6MRE', _6MRE) +U32_ENTRY('CHFX', CHFX) +U32_ENTRY('JZHS', JZHS) +U32_ENTRY('6ISE', _6ISE) +U32_ENTRY('6BSE', _6BSE) +U32_ENTRY('6ATB', _6ATB) +U32_ENTRY('6ATA', _6ATA) + +FLOAT_ENTRY('RNGE', x30_RNGE) +FLOAT_ENTRY('FOFF', x34_FOFF) + +#undef ENTRY +#undef RES_ENTRY +#undef U32_ENTRY +#undef FLOAT_ENTRY diff --git a/DataSpec/DNACommon/CRSC.hpp b/DataSpec/DNACommon/CRSC.hpp index 3bc7ff2f1..bab40f942 100644 --- a/DataSpec/DNACommon/CRSC.hpp +++ b/DataSpec/DNACommon/CRSC.hpp @@ -18,20 +18,33 @@ class ProjectPath; } namespace DataSpec::DNAParticle { + template -struct CRSM : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - AT_SUBDECL_DNA - std::unordered_map> x0_generators; - std::unordered_map x10_sfx; - std::unordered_map> x20_decals; - float x30_RNGE; - float x34_FOFF; +struct _CRSM { + static constexpr ParticleType Type = ParticleType::CRSM; +#define RES_ENTRY(name, identifier) ChildResourceFactory identifier; +#define U32_ENTRY(name, identifier) uint32_t identifier = ~0; +#define FLOAT_ENTRY(name, identifier) float identifier = 0.f; +#include "CRSC.def" - CRSM(); + template + void constexpr Enumerate(_Func f) { +#define ENTRY(name, identifier) f(FOURCC(name), identifier); +#include "CRSC.def" + } - void gatherDependencies(std::vector&) const; + template + bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { +#define ENTRY(name, identifier) case SBIG(name): f(identifier); return true; +#include "CRSC.def" + default: return false; + } + } }; +template +using CRSM = PPImpl<_CRSM>; + template bool ExtractCRSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath); diff --git a/DataSpec/DNACommon/DNACommon.hpp b/DataSpec/DNACommon/DNACommon.hpp index e66593c9d..08587bb3d 100644 --- a/DataSpec/DNACommon/DNACommon.hpp +++ b/DataSpec/DNACommon/DNACommon.hpp @@ -118,40 +118,40 @@ public: using value_type = uint32_t; static UniqueID32 kInvalidId; AT_DECL_EXPLICIT_DNA_YAML - bool isValid() const { return m_id != 0xffffffff && m_id != 0; } - void assign(uint32_t id) { m_id = id ? id : 0xffffffff; } + bool isValid() const noexcept { return m_id != 0xffffffff && m_id != 0; } + void assign(uint32_t id) noexcept { m_id = id ? id : 0xffffffff; } - UniqueID32& operator=(const hecl::ProjectPath& path) { + UniqueID32& operator=(const hecl::ProjectPath& path) noexcept { assign(path.parsedHash32()); return *this; } - bool operator!=(const UniqueID32& other) const { return m_id != other.m_id; } - bool operator==(const UniqueID32& other) const { return m_id == other.m_id; } - bool operator<(const UniqueID32& other) const { return m_id < other.m_id; } - uint32_t toUint32() const { return m_id; } - uint64_t toUint64() const { return m_id; } + bool operator!=(const UniqueID32& other) const noexcept { return m_id != other.m_id; } + bool operator==(const UniqueID32& other) const noexcept { return m_id == other.m_id; } + bool operator<(const UniqueID32& other) const noexcept { return m_id < other.m_id; } + uint32_t toUint32() const noexcept { return m_id; } + uint64_t toUint64() const noexcept { return m_id; } std::string toString() const; - void clear() { m_id = 0xffffffff; } + void clear() noexcept { m_id = 0xffffffff; } - UniqueID32() = default; - UniqueID32(uint32_t idin) { assign(idin); } + UniqueID32() noexcept = default; + UniqueID32(uint32_t idin) noexcept { assign(idin); } UniqueID32(athena::io::IStreamReader& reader) { read(reader); } - UniqueID32(const hecl::ProjectPath& path) { *this = path; } - UniqueID32(const char* hexStr) { + UniqueID32(const hecl::ProjectPath& path) noexcept { *this = path; } + UniqueID32(const char* hexStr) noexcept { char copy[9]; strncpy(copy, hexStr, 8); copy[8] = '\0'; assign(strtoul(copy, nullptr, 16)); } - UniqueID32(const wchar_t* hexStr) { + UniqueID32(const wchar_t* hexStr) noexcept{ wchar_t copy[9]; wcsncpy(copy, hexStr, 8); copy[8] = L'\0'; assign(wcstoul(copy, nullptr, 16)); } - static constexpr size_t BinarySize() { return 4; } + static constexpr size_t BinarySize() noexcept { return 4; } }; /** PAK 32-bit Unique ID - writes zero when invalid */ @@ -169,39 +169,39 @@ class UniqueID64 : public BigDNA { public: using value_type = uint64_t; AT_DECL_EXPLICIT_DNA_YAML - bool isValid() const { return m_id != 0xffffffffffffffff && m_id != 0; } - void assign(uint64_t id) { m_id = id ? id : 0xffffffffffffffff; } + bool isValid() const noexcept { return m_id != 0xffffffffffffffff && m_id != 0; } + void assign(uint64_t id) noexcept { m_id = id ? id : 0xffffffffffffffff; } - UniqueID64& operator=(const hecl::ProjectPath& path) { + UniqueID64& operator=(const hecl::ProjectPath& path) noexcept { assign(path.hash().val64()); return *this; } - bool operator!=(const UniqueID64& other) const { return m_id != other.m_id; } - bool operator==(const UniqueID64& other) const { return m_id == other.m_id; } - bool operator<(const UniqueID64& other) const { return m_id < other.m_id; } - uint64_t toUint64() const { return m_id; } + bool operator!=(const UniqueID64& other) const noexcept { return m_id != other.m_id; } + bool operator==(const UniqueID64& other) const noexcept { return m_id == other.m_id; } + bool operator<(const UniqueID64& other) const noexcept { return m_id < other.m_id; } + uint64_t toUint64() const noexcept { return m_id; } std::string toString() const; - void clear() { m_id = 0xffffffffffffffff; } + void clear() noexcept { m_id = 0xffffffffffffffff; } - UniqueID64() = default; - UniqueID64(uint64_t idin) { assign(idin); } + UniqueID64() noexcept = default; + UniqueID64(uint64_t idin) noexcept { assign(idin); } UniqueID64(athena::io::IStreamReader& reader) { read(reader); } - UniqueID64(const hecl::ProjectPath& path) { *this = path; } - UniqueID64(const char* hexStr) { + UniqueID64(const hecl::ProjectPath& path) noexcept { *this = path; } + UniqueID64(const char* hexStr) noexcept { char copy[17]; std::strncpy(copy, hexStr, 16); copy[16] = '\0'; assign(std::strtoull(copy, nullptr, 16)); } - UniqueID64(const wchar_t* hexStr) { + UniqueID64(const wchar_t* hexStr) noexcept { wchar_t copy[17]; std::wcsncpy(copy, hexStr, 16); copy[16] = L'\0'; assign(std::wcstoull(copy, nullptr, 16)); } - static constexpr size_t BinarySize() { return 8; } + static constexpr size_t BinarySize() noexcept { return 8; } }; /** PAK 128-bit Unique ID */ @@ -220,26 +220,26 @@ private: public: using value_type = uint64_t; AT_DECL_EXPLICIT_DNA_YAML - UniqueID128() { + UniqueID128() noexcept { m_id.id[0] = 0xffffffffffffffff; m_id.id[1] = 0xffffffffffffffff; } - UniqueID128(uint64_t idin) { + UniqueID128(uint64_t idin) noexcept { m_id.id[0] = idin; m_id.id[1] = 0; } - bool isValid() const { + bool isValid() const noexcept { return m_id.id[0] != 0xffffffffffffffff && m_id.id[0] != 0 && m_id.id[1] != 0xffffffffffffffff && m_id.id[1] != 0; } - UniqueID128& operator=(const hecl::ProjectPath& path) { + UniqueID128& operator=(const hecl::ProjectPath& path) noexcept { m_id.id[0] = path.hash().val64(); m_id.id[1] = 0; return *this; } - UniqueID128(const hecl::ProjectPath& path) { *this = path; } + UniqueID128(const hecl::ProjectPath& path) noexcept { *this = path; } - bool operator!=(const UniqueID128& other) const { + bool operator!=(const UniqueID128& other) const noexcept { #if __SSE__ __m128i vcmp = _mm_cmpeq_epi32(m_id.id128, other.m_id.id128); int vmask = _mm_movemask_epi8(vcmp); @@ -248,7 +248,7 @@ public: return (m_id.id[0] != other.m_id.id[0]) || (m_id.id[1] != other.m_id.id[1]); #endif } - bool operator==(const UniqueID128& other) const { + bool operator==(const UniqueID128& other) const noexcept { #if __SSE__ __m128i vcmp = _mm_cmpeq_epi32(m_id.id128, other.m_id.id128); int vmask = _mm_movemask_epi8(vcmp); @@ -257,19 +257,19 @@ public: return (m_id.id[0] == other.m_id.id[0]) && (m_id.id[1] == other.m_id.id[1]); #endif } - bool operator<(const UniqueID128& other) const { + bool operator<(const UniqueID128& other) const noexcept { return m_id.id[0] < other.m_id.id[0] || (m_id.id[0] == other.m_id.id[0] && m_id.id[1] < other.m_id.id[1]); } - void clear() { + void clear() noexcept { m_id.id[0] = 0xffffffffffffffff; m_id.id[1] = 0xffffffffffffffff; } - uint64_t toUint64() const { return m_id.id[0]; } - uint64_t toHighUint64() const { return m_id.id[0]; } - uint64_t toLowUint64() const { return m_id.id[1]; } + uint64_t toUint64() const noexcept { return m_id.id[0]; } + uint64_t toHighUint64() const noexcept { return m_id.id[0]; } + uint64_t toLowUint64() const noexcept { return m_id.id[1]; } std::string toString() const; - static constexpr size_t BinarySize() { return 16; } + static constexpr size_t BinarySize() noexcept { return 16; } }; /** Casts ID type to its null-zero equivalent */ @@ -340,7 +340,7 @@ public: }; /** Resource cooker function */ -typedef std::function ResCooker; +using ResCooker = std::function; /** Mappings of resources involved in extracting characters */ template @@ -377,22 +377,22 @@ inline hecl::ProjectPath GetPathBeginsWith(const hecl::ProjectPath& parentPath, namespace std { template <> struct hash { - size_t operator()(const DataSpec::DNAFourCC& fcc) const { return fcc.toUint32(); } + size_t operator()(const DataSpec::DNAFourCC& fcc) const noexcept{ return fcc.toUint32(); } }; template <> struct hash { - size_t operator()(const DataSpec::UniqueID32& id) const { return id.toUint32(); } + size_t operator()(const DataSpec::UniqueID32& id) const noexcept{ return id.toUint32(); } }; template <> struct hash { - size_t operator()(const DataSpec::UniqueID64& id) const { return id.toUint64(); } + size_t operator()(const DataSpec::UniqueID64& id) const noexcept{ return id.toUint64(); } }; template <> struct hash { - size_t operator()(const DataSpec::UniqueID128& id) const { return id.toHighUint64() ^ id.toLowUint64(); } + size_t operator()(const DataSpec::UniqueID128& id) const noexcept { return id.toHighUint64() ^ id.toLowUint64(); } }; } // namespace std diff --git a/DataSpec/DNACommon/DPSC.cpp b/DataSpec/DNACommon/DPSC.cpp index ed3bc334d..4b88eda08 100644 --- a/DataSpec/DNACommon/DPSC.cpp +++ b/DataSpec/DNACommon/DPSC.cpp @@ -1,391 +1,24 @@ #include "DataSpec/DNACommon/DPSC.hpp" - #include "DataSpec/DNACommon/PAK.hpp" -#include -#include - namespace DataSpec::DNAParticle { +template struct PPImpl<_DPSM>; +template struct PPImpl<_DPSM>; + +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_DPSM>) +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_DPSM>) + template <> -std::string_view DPSM::DNAType() { +std::string_view PPImpl<_DPSM>::DNAType() { return "DPSM"sv; } template <> -std::string_view DPSM::DNAType() { +std::string_view PPImpl<_DPSM>::DNAType() { return "DPSM"sv; } -template -void DPSM::_read(athena::io::YAMLDocReader& r) { - for (const auto& elem : r.getCurNode()->m_mapChildren) { - if (elem.first.size() < 4) { - LogModule.report(logvisor::Warning, fmt("short FourCC in element '{}'"), elem.first); - continue; - } - - if (auto rec = r.enterSubRecord(elem.first.c_str())) { - bool loadFirstDesc = false; - uint32_t clsId = *reinterpret_cast(elem.first.c_str()); - switch (clsId) { - case SBIG('1SZE'): - case SBIG('1LFT'): - case SBIG('1ROT'): - case SBIG('1OFF'): - case SBIG('1CLR'): - case SBIG('1TEX'): - case SBIG('1ADD'): - loadFirstDesc = true; - [[fallthrough]]; - case SBIG('2SZE'): - case SBIG('2LFT'): - case SBIG('2ROT'): - case SBIG('2OFF'): - case SBIG('2CLR'): - case SBIG('2TEX'): - case SBIG('2ADD'): - if (loadFirstDesc) - readQuadDecalInfo(r, clsId, x0_quad); - else - readQuadDecalInfo(r, clsId, x1c_quad); - break; - case SBIG('DMDL'): - x38_DMDL.read(r); - break; - case SBIG('DLFT'): - x48_DLFT.read(r); - break; - case SBIG('DMOP'): - x4c_DMOP.read(r); - break; - case SBIG('DMRT'): - x50_DMRT.read(r); - break; - case SBIG('DMSC'): - x54_DMSC.read(r); - break; - case SBIG('DMCL'): - x58_DMCL.read(r); - break; - case SBIG('DMAB'): - x5c_24_DMAB = r.readBool(); - break; - case SBIG('DMOO'): - x5c_25_DMOO = r.readBool(); - break; - } - } - } -} - -template -void DPSM::_write(athena::io::YAMLDocWriter& w) const { - writeQuadDecalInfo(w, x0_quad, true); - writeQuadDecalInfo(w, x1c_quad, false); - - if (x38_DMDL) - if (auto rec = w.enterSubRecord("DMDL")) - x38_DMDL.write(w); - if (x48_DLFT) - if (auto rec = w.enterSubRecord("DLFT")) - x48_DLFT.write(w); - if (x4c_DMOP) - if (auto rec = w.enterSubRecord("DMOP")) - x4c_DMOP.write(w); - if (x50_DMRT) - if (auto rec = w.enterSubRecord("DMRT")) - x50_DMRT.write(w); - if (x54_DMSC) - if (auto rec = w.enterSubRecord("DMSC")) - x54_DMSC.write(w); - if (x58_DMCL) - if (auto rec = w.enterSubRecord("DMCL")) - x54_DMSC.write(w); - - if (x5c_24_DMAB) - w.writeBool("DMAB", x5c_24_DMAB); - if (x5c_25_DMOO) - w.writeBool("DMOO", x5c_25_DMOO); -} - -template -template -void DPSM::readQuadDecalInfo(Reader& r, FourCC clsId, typename DPSM::SQuadDescr& quad) { - switch (clsId.toUint32()) { - case SBIG('1LFT'): - case SBIG('2LFT'): - quad.x0_LFT.read(r); - break; - case SBIG('1SZE'): - case SBIG('2SZE'): - quad.x4_SZE.read(r); - break; - case SBIG('1ROT'): - case SBIG('2ROT'): - quad.x8_ROT.read(r); - break; - case SBIG('1OFF'): - case SBIG('2OFF'): - quad.xc_OFF.read(r); - break; - case SBIG('1CLR'): - case SBIG('2CLR'): - quad.x10_CLR.read(r); - break; - case SBIG('1TEX'): - case SBIG('2TEX'): - quad.x14_TEX.read(r); - break; - case SBIG('1ADD'): - case SBIG('2ADD'): - quad.x18_ADD.read(r); - break; - } -} - -template -void DPSM::writeQuadDecalInfo(athena::io::YAMLDocWriter& w, const typename DPSM::SQuadDescr& quad, - bool first) const { - if (quad.x0_LFT) - if (auto rec = w.enterSubRecord((first ? "1LFT" : "2LFT"))) - quad.x0_LFT.write(w); - if (quad.x4_SZE) - if (auto rec = w.enterSubRecord((first ? "1SZE" : "2SZE"))) - quad.x4_SZE.write(w); - if (quad.x8_ROT) - if (auto rec = w.enterSubRecord((first ? "1ROT" : "2ROT"))) - quad.x8_ROT.write(w); - if (quad.xc_OFF) - if (auto rec = w.enterSubRecord((first ? "1OFF" : "2OFF"))) - quad.xc_OFF.write(w); - if (quad.x10_CLR) - if (auto rec = w.enterSubRecord((first ? "1CLR" : "2CLR"))) - quad.x10_CLR.write(w); - if (quad.x14_TEX) - if (auto rec = w.enterSubRecord((first ? "1TEX" : "2TEX"))) - quad.x14_TEX.write(w); - if (quad.x18_ADD) - if (auto rec = w.enterSubRecord((first ? "1ADD" : "2ADD"))) - quad.x18_ADD.write(w); -} - -template -void DPSM::_binarySize(size_t& s) const { - s += 4; - getQuadDecalBinarySize(s, x0_quad); - getQuadDecalBinarySize(s, x1c_quad); - if (x38_DMDL) { - s += 4; - x38_DMDL.binarySize(s); - } - if (x48_DLFT) { - s += 4; - x48_DLFT.binarySize(s); - } - if (x4c_DMOP) { - s += 4; - x4c_DMOP.binarySize(s); - } - if (x50_DMRT) { - s += 4; - x50_DMRT.binarySize(s); - } - if (x54_DMSC) { - s += 4; - x54_DMSC.binarySize(s); - } - if (x58_DMCL) { - x58_DMCL.binarySize(s); - } - if (x5c_24_DMAB) - s += 9; - if (x5c_25_DMOO) - s += 9; -} - -template -void DPSM::getQuadDecalBinarySize(size_t& s, const typename DPSM::SQuadDescr& quad) const { - if (quad.x0_LFT) { - s += 4; - quad.x0_LFT.binarySize(s); - } - if (quad.x4_SZE) { - s += 4; - quad.x4_SZE.binarySize(s); - } - if (quad.x8_ROT) { - s += 4; - quad.x8_ROT.binarySize(s); - } - if (quad.xc_OFF) { - s += 4; - quad.xc_OFF.binarySize(s); - } - if (quad.x10_CLR) { - s += 4; - quad.x10_CLR.binarySize(s); - } - if (quad.x14_TEX) { - s += 4; - quad.x14_TEX.binarySize(s); - } - if (quad.x18_ADD) { - s += 4; - quad.x18_ADD.binarySize(s); - } -} - -template -void DPSM::_read(athena::io::IStreamReader& r) { - DNAFourCC clsId; - clsId.read(r); - if (clsId != SBIG('DPSM')) { - LogModule.report(logvisor::Warning, fmt("non DPSM provided to DPSM parser")); - return; - } - bool loadFirstDesc = false; - clsId.read(r); - while (clsId != SBIG('_END')) { - switch (clsId.toUint32()) { - case SBIG('1SZE'): - case SBIG('1LFT'): - case SBIG('1ROT'): - case SBIG('1OFF'): - case SBIG('1CLR'): - case SBIG('1TEX'): - case SBIG('1ADD'): - loadFirstDesc = true; - [[fallthrough]]; - case SBIG('2SZE'): - case SBIG('2LFT'): - case SBIG('2ROT'): - case SBIG('2OFF'): - case SBIG('2CLR'): - case SBIG('2TEX'): - case SBIG('2ADD'): - if (loadFirstDesc) - readQuadDecalInfo(r, clsId, x0_quad); - else - readQuadDecalInfo(r, clsId, x1c_quad); - break; - case SBIG('DMDL'): - x38_DMDL.read(r); - break; - case SBIG('DLFT'): - x48_DLFT.read(r); - break; - case SBIG('DMOP'): - x4c_DMOP.read(r); - break; - case SBIG('DMRT'): - x50_DMRT.read(r); - break; - case SBIG('DMSC'): - x54_DMSC.read(r); - break; - case SBIG('DMCL'): - x58_DMCL.read(r); - break; - case SBIG('DMAB'): - r.readUint32(); - x5c_24_DMAB = r.readBool(); - break; - case SBIG('DMOO'): - r.readUint32(); - x5c_25_DMOO = r.readBool(); - break; - default: - LogModule.report(logvisor::Fatal, fmt("Unknown DPSM class {} @{}"), clsId, r.position()); - break; - } - clsId.read(r); - } -} - -template -void DPSM::_write(athena::io::IStreamWriter& w) const { - w.writeBytes("DPSM", 4); - writeQuadDecalInfo(w, x0_quad, true); - writeQuadDecalInfo(w, x1c_quad, false); - if (x38_DMDL) { - w.writeBytes("DMDL", 4); - x38_DMDL.write(w); - } - if (x48_DLFT) { - w.writeBytes("DLFT", 4); - x48_DLFT.write(w); - } - if (x4c_DMOP) { - w.writeBytes("DMOP", 4); - x4c_DMOP.write(w); - } - if (x50_DMRT) { - w.writeBytes("DMRT", 4); - x50_DMRT.write(w); - } - if (x54_DMSC) { - w.writeBytes("DMSC", 4); - x54_DMSC.write(w); - } - if (x58_DMCL) { - w.writeBytes("DMCL", 4); - x58_DMCL.write(w); - } - if (x5c_24_DMAB) - w.writeBytes("DMABCNST\x01", 9); - if (x5c_25_DMOO) - w.writeBytes("DMOOCNST\x01", 9); - w.writeBytes("_END", 4); -} - -template -void DPSM::writeQuadDecalInfo(athena::io::IStreamWriter& w, const typename DPSM::SQuadDescr& quad, - bool first) const { - if (quad.x0_LFT) { - w.writeBytes((first ? "1LFT" : "2LFT"), 4); - quad.x0_LFT.write(w); - } - if (quad.x4_SZE) { - w.writeBytes((first ? "1SZE" : "2SZE"), 4); - quad.x4_SZE.write(w); - } - if (quad.x8_ROT) { - w.writeBytes((first ? "1ROT" : "2ROT"), 4); - quad.x8_ROT.write(w); - } - if (quad.xc_OFF) { - w.writeBytes((first ? "1OFF" : "2OFF"), 4); - quad.xc_OFF.write(w); - } - if (quad.x10_CLR) { - w.writeBytes((first ? "1CLR" : "2CLR"), 4); - quad.x10_CLR.write(w); - } - if (quad.x14_TEX) { - w.writeBytes((first ? "1TEX" : "2TEX"), 4); - quad.x14_TEX.write(w); - } - if (quad.x18_ADD) { - w.writeBytes((first ? "1ADD" : "2ADD"), 4); - quad.x18_ADD.write(w); - } -} - -template -void DPSM::gatherDependencies(std::vector& pathsOut) const { - if (x0_quad.x14_TEX.m_elem) - x0_quad.x14_TEX.m_elem->gatherDependencies(pathsOut); - if (x1c_quad.x14_TEX.m_elem) - x1c_quad.x14_TEX.m_elem->gatherDependencies(pathsOut); - g_curSpec->flattenDependencies(x38_DMDL.id, pathsOut); -} - -AT_SUBSPECIALIZE_DNA_YAML(DPSM) -AT_SUBSPECIALIZE_DNA_YAML(DPSM) -template struct DPSM; -template struct DPSM; - template bool ExtractDPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) { athena::io::FileWriter writer(outPath.getAbsolutePath()); diff --git a/DataSpec/DNACommon/DPSC.def b/DataSpec/DNACommon/DPSC.def new file mode 100644 index 000000000..ac61eb49f --- /dev/null +++ b/DataSpec/DNACommon/DPSC.def @@ -0,0 +1,28 @@ +#ifndef ENTRY +#define ENTRY(name, identifier) +#endif + +ENTRY('1LFT', x0_quad.x0_LFT) +ENTRY('1SZE', x0_quad.x4_SZE) +ENTRY('1ROT', x0_quad.x8_ROT) +ENTRY('1OFF', x0_quad.xc_OFF) +ENTRY('1CLR', x0_quad.x10_CLR) +ENTRY('1TEX', x0_quad.x14_TEX) +ENTRY('1ADD', x0_quad.x18_ADD) +ENTRY('2LFT', x1c_quad.x0_LFT) +ENTRY('2SZE', x1c_quad.x4_SZE) +ENTRY('2ROT', x1c_quad.x8_ROT) +ENTRY('2OFF', x1c_quad.xc_OFF) +ENTRY('2CLR', x1c_quad.x10_CLR) +ENTRY('2TEX', x1c_quad.x14_TEX) +ENTRY('2ADD', x1c_quad.x18_ADD) +ENTRY('DMDL', x38_DMDL) +ENTRY('DLFT', x48_DLFT) +ENTRY('DMOP', x4c_DMOP) +ENTRY('DMRT', x50_DMRT) +ENTRY('DMSC', x54_DMSC) +ENTRY('DMCL', x58_DMCL) +ENTRY('DMAB', x5c_24_DMAB) +ENTRY('DMOO', x5c_25_DMOO) + +#undef ENTRY diff --git a/DataSpec/DNACommon/DPSC.hpp b/DataSpec/DNACommon/DPSC.hpp index f8feab5eb..2ef2c547c 100644 --- a/DataSpec/DNACommon/DPSC.hpp +++ b/DataSpec/DNACommon/DPSC.hpp @@ -20,9 +20,8 @@ class ProjectPath; namespace DataSpec::DNAParticle { template -struct DPSM : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - AT_SUBDECL_DNA +struct _DPSM { + static constexpr ParticleType Type = ParticleType::DPSM; struct SQuadDescr { IntElementFactory x0_LFT; @@ -31,7 +30,7 @@ struct DPSM : BigDNA { VectorElementFactory xc_OFF; ColorElementFactory x10_CLR; UVElementFactory x14_TEX; - BoolHelper x18_ADD; + bool x18_ADD = false; }; SQuadDescr x0_quad; @@ -42,21 +41,27 @@ struct DPSM : BigDNA { VectorElementFactory x50_DMRT; VectorElementFactory x54_DMSC; ColorElementFactory x58_DMCL; - union { - struct { - bool x5c_24_DMAB : 1; - bool x5c_25_DMOO : 1; - }; - uint8_t dummy; - }; - template - void readQuadDecalInfo(Reader& r, FourCC clsId, SQuadDescr& quad); - void writeQuadDecalInfo(athena::io::YAMLDocWriter& w, const SQuadDescr& quad, bool first) const; - void getQuadDecalBinarySize(size_t& s, const SQuadDescr& desc) const; - void writeQuadDecalInfo(athena::io::IStreamWriter& w, const SQuadDescr& quad, bool first) const; - void gatherDependencies(std::vector&) const; + bool x5c_24_DMAB = false; + bool x5c_25_DMOO = false; + + template + void constexpr Enumerate(_Func f) { +#define ENTRY(name, identifier) f(FOURCC(name), identifier); +#include "DPSC.def" + } + + template + bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { +#define ENTRY(name, identifier) case SBIG(name): f(identifier); return true; +#include "DPSC.def" + default: return false; + } + } }; +template +using DPSM = PPImpl<_DPSM>; template bool ExtractDPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath); diff --git a/DataSpec/DNACommon/ELSC.cpp b/DataSpec/DNACommon/ELSC.cpp index b0e4703c7..7ea266f71 100644 --- a/DataSpec/DNACommon/ELSC.cpp +++ b/DataSpec/DNACommon/ELSC.cpp @@ -1,403 +1,13 @@ #include "DataSpec/DNACommon/ELSC.hpp" - -#include +#include "DataSpec/DNACommon/PAK.hpp" namespace DataSpec::DNAParticle { -template -void ELSM::_read(athena::io::IStreamReader& r) { - DNAFourCC clsId; - clsId.read(r); - if (clsId != SBIG('ELSM')) { - LogModule.report(logvisor::Warning, fmt("non ELSM provided to ELSM parser")); - return; - } +template struct PPImpl<_ELSM>; +template struct PPImpl<_ELSM>; - clsId.read(r); - while (clsId != SBIG('_END')) { - switch (clsId.toUint32()) { - case SBIG('LIFE'): - x0_LIFE.read(r); - break; - case SBIG('SLIF'): - x4_SLIF.read(r); - break; - case SBIG('GRAT'): - x8_GRAT.read(r); - break; - case SBIG('SCNT'): - xc_SCNT.read(r); - break; - case SBIG('SSEG'): - x10_SSEG.read(r); - break; - case SBIG('COLR'): - x14_COLR.read(r); - break; - case SBIG('IEMT'): - x18_IEMT.read(r); - break; - case SBIG('FEMT'): - x1c_FEMT.read(r); - break; - case SBIG('AMPL'): - x20_AMPL.read(r); - break; - case SBIG('AMPD'): - x24_AMPD.read(r); - break; - case SBIG('LWD1'): - x28_LWD1.read(r); - break; - case SBIG('LWD2'): - x2c_LWD2.read(r); - break; - case SBIG('LWD3'): - x30_LWD3.read(r); - break; - case SBIG('LCL1'): - x34_LCL1.read(r); - break; - case SBIG('LCL2'): - x38_LCL2.read(r); - break; - case SBIG('LCL3'): - x3c_LCL3.read(r); - break; - case SBIG('SSWH'): - x40_SSWH.read(r); - break; - case SBIG('GPSM'): - x50_GPSM.read(r); - break; - case SBIG('EPSM'): - x60_EPSM.read(r); - break; - case SBIG('ZERY'): - x70_ZERY.read(r); - break; - default: - LogModule.report(logvisor::Fatal, fmt("Unknown ELSM class {} @{}"), clsId, r.position()); - break; - } - clsId.read(r); - } -} - -template -void ELSM::_write(athena::io::IStreamWriter& w) const { - w.writeBytes((atInt8*)"ELSM", 4); - if (x0_LIFE) { - w.writeBytes((atInt8*)"LIFE", 4); - x0_LIFE.write(w); - } - if (x4_SLIF) { - w.writeBytes((atInt8*)"SLIF", 4); - x4_SLIF.write(w); - } - if (x8_GRAT) { - w.writeBytes((atInt8*)"GRAT", 4); - x8_GRAT.write(w); - } - if (xc_SCNT) { - w.writeBytes((atInt8*)"SCNT", 4); - xc_SCNT.write(w); - } - if (x10_SSEG) { - w.writeBytes((atInt8*)"SSEG", 4); - x10_SSEG.write(w); - } - if (x14_COLR) { - w.writeBytes((atInt8*)"COLR", 4); - x14_COLR.write(w); - } - if (x18_IEMT) { - w.writeBytes((atInt8*)"IEMT", 4); - x18_IEMT.write(w); - } - if (x1c_FEMT) { - w.writeBytes((atInt8*)"FEMT", 4); - x1c_FEMT.write(w); - } - if (x20_AMPL) { - w.writeBytes((atInt8*)"AMPL", 4); - x20_AMPL.write(w); - } - if (x24_AMPD) { - w.writeBytes((atInt8*)"AMPD", 4); - x24_AMPD.write(w); - } - if (x28_LWD1) { - w.writeBytes((atInt8*)"LWD1", 4); - x28_LWD1.write(w); - } - if (x2c_LWD2) { - w.writeBytes((atInt8*)"LWD2", 4); - x2c_LWD2.write(w); - } - if (x30_LWD3) { - w.writeBytes((atInt8*)"LWD3", 4); - x30_LWD3.write(w); - } - if (x34_LCL1) { - w.writeBytes((atInt8*)"LCL1", 4); - x34_LCL1.write(w); - } - if (x38_LCL2) { - w.writeBytes((atInt8*)"LCL2", 4); - x38_LCL2.write(w); - } - if (x3c_LCL3) { - w.writeBytes((atInt8*)"LCL3", 4); - x3c_LCL3.write(w); - } - if (x40_SSWH) { - w.writeBytes((atInt8*)"SSWH", 4); - x40_SSWH.write(w); - } - if (x50_GPSM) { - w.writeBytes((atInt8*)"GPSM", 4); - x50_GPSM.write(w); - } - if (x60_EPSM) { - w.writeBytes((atInt8*)"EPSM", 4); - x60_EPSM.write(w); - } - if (x70_ZERY) { - w.writeBytes((atInt8*)"ZERY", 4); - x70_ZERY.write(w); - } - w.writeBytes("_END", 4); -} - -template -void ELSM::_binarySize(size_t& s) const { - s += 4; - if (x0_LIFE) { - s += 4; - x0_LIFE.binarySize(s); - } - if (x4_SLIF) { - s += 4; - x4_SLIF.binarySize(s); - } - if (x8_GRAT) { - s += 4; - x8_GRAT.binarySize(s); - } - if (xc_SCNT) { - s += 4; - xc_SCNT.binarySize(s); - } - if (x10_SSEG) { - s += 4; - x10_SSEG.binarySize(s); - } - if (x14_COLR) { - s += 4; - x14_COLR.binarySize(s); - } - if (x18_IEMT) { - s += 4; - x18_IEMT.binarySize(s); - } - if (x1c_FEMT) { - s += 4; - x1c_FEMT.binarySize(s); - } - if (x20_AMPL) { - s += 4; - x20_AMPL.binarySize(s); - } - if (x24_AMPD) { - s += 4; - x24_AMPD.binarySize(s); - } - if (x28_LWD1) { - s += 4; - x28_LWD1.binarySize(s); - } - if (x2c_LWD2) { - s += 4; - x2c_LWD2.binarySize(s); - } - if (x30_LWD3) { - s += 4; - x30_LWD3.binarySize(s); - } - if (x34_LCL1) { - s += 4; - x34_LCL1.binarySize(s); - } - if (x38_LCL2) { - s += 4; - x38_LCL2.binarySize(s); - } - if (x3c_LCL3) { - s += 4; - x3c_LCL3.binarySize(s); - } - if (x40_SSWH) { - s += 4; - x40_SSWH.binarySize(s); - } - if (x50_GPSM) { - s += 4; - x50_GPSM.binarySize(s); - } - if (x60_EPSM) { - s += 4; - x60_EPSM.binarySize(s); - } - if (x70_ZERY) { - s += 4; - x70_ZERY.binarySize(s); - } -} - -template -void ELSM::_read(athena::io::YAMLDocReader& r) { - for (const auto& elem : r.getCurNode()->m_mapChildren) { - if (elem.first.size() < 4) { - LogModule.report(logvisor::Warning, fmt("short FourCC in element '{}'"), elem.first); - continue; - } - - if (auto rec = r.enterSubRecord(elem.first.c_str())) { - switch (*reinterpret_cast(elem.first.data())) { - case SBIG('LIFE'): - x0_LIFE.read(r); - break; - case SBIG('SLIF'): - x4_SLIF.read(r); - break; - case SBIG('GRAT'): - x8_GRAT.read(r); - break; - case SBIG('SCNT'): - xc_SCNT.read(r); - break; - case SBIG('SSEG'): - x10_SSEG.read(r); - break; - case SBIG('COLR'): - x14_COLR.read(r); - break; - case SBIG('IEMT'): - x18_IEMT.read(r); - break; - case SBIG('FEMT'): - x1c_FEMT.read(r); - break; - case SBIG('AMPL'): - x20_AMPL.read(r); - break; - case SBIG('AMPD'): - x24_AMPD.read(r); - break; - case SBIG('LWD1'): - x28_LWD1.read(r); - break; - case SBIG('LWD2'): - x2c_LWD2.read(r); - break; - case SBIG('LWD3'): - x30_LWD3.read(r); - break; - case SBIG('LCL1'): - x34_LCL1.read(r); - break; - case SBIG('LCL2'): - x38_LCL2.read(r); - break; - case SBIG('LCL3'): - x3c_LCL3.read(r); - break; - case SBIG('SSWH'): - x40_SSWH.read(r); - break; - case SBIG('GPSM'): - x50_GPSM.read(r); - break; - case SBIG('EPSM'): - x60_EPSM.read(r); - break; - case SBIG('ZERY'): - x70_ZERY.read(r); - break; - default: - break; - } - } - } -} - -template -void ELSM::_write(athena::io::YAMLDocWriter& w) const { - if (x0_LIFE) - if (auto rec = w.enterSubRecord("LIFE")) - x0_LIFE.write(w); - if (x4_SLIF) - if (auto rec = w.enterSubRecord("SLIF")) - x4_SLIF.write(w); - if (x8_GRAT) - if (auto rec = w.enterSubRecord("GRAT")) - x8_GRAT.write(w); - if (xc_SCNT) - if (auto rec = w.enterSubRecord("SCNT")) - xc_SCNT.write(w); - if (x10_SSEG) - if (auto rec = w.enterSubRecord("SSEG")) - x10_SSEG.write(w); - if (x14_COLR) - if (auto rec = w.enterSubRecord("COLR")) - x14_COLR.write(w); - if (x18_IEMT) - if (auto rec = w.enterSubRecord("IEMT")) - x18_IEMT.write(w); - if (x1c_FEMT) - if (auto rec = w.enterSubRecord("FEMT")) - x1c_FEMT.write(w); - if (x20_AMPL) - if (auto rec = w.enterSubRecord("AMPL")) - x20_AMPL.write(w); - if (x24_AMPD) - if (auto rec = w.enterSubRecord("AMPD")) - x24_AMPD.write(w); - if (x28_LWD1) - if (auto rec = w.enterSubRecord("LWD1")) - x28_LWD1.write(w); - if (x2c_LWD2) - if (auto rec = w.enterSubRecord("LWD2")) - x2c_LWD2.write(w); - if (x30_LWD3) - if (auto rec = w.enterSubRecord("LWD3")) - x30_LWD3.write(w); - if (x34_LCL1) - if (auto rec = w.enterSubRecord("LCL1")) - x34_LCL1.write(w); - if (x38_LCL2) - if (auto rec = w.enterSubRecord("LCL2")) - x38_LCL2.write(w); - if (x3c_LCL3) - if (auto rec = w.enterSubRecord("LCL3")) - x3c_LCL3.write(w); - if (x40_SSWH) - if (auto rec = w.enterSubRecord("SSWH")) - x40_SSWH.write(w); - if (x50_GPSM) - if (auto rec = w.enterSubRecord("GPSM")) - x50_GPSM.write(w); - if (x60_EPSM) - if (auto rec = w.enterSubRecord("EPSM")) - x60_EPSM.write(w); - if (x70_ZERY) - if (auto rec = w.enterSubRecord("ZERY")) - x70_ZERY.write(w); -} - -AT_SUBSPECIALIZE_DNA_YAML(ELSM) -AT_SUBSPECIALIZE_DNA_YAML(ELSM) +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_ELSM>) +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_ELSM>) template <> std::string_view ELSM::DNAType() { @@ -409,16 +19,6 @@ std::string_view ELSM::DNAType() { return "urde::ELSM"sv; } -template -void ELSM::gatherDependencies(std::vector& pathsOut) const { - g_curSpec->flattenDependencies(x40_SSWH.id, pathsOut); - g_curSpec->flattenDependencies(x50_GPSM.id, pathsOut); - g_curSpec->flattenDependencies(x60_EPSM.id, pathsOut); -} - -template struct ELSM; -template struct ELSM; - template bool ExtractELSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) { athena::io::FileWriter writer(outPath.getAbsolutePath()); diff --git a/DataSpec/DNACommon/ELSC.def b/DataSpec/DNACommon/ELSC.def new file mode 100644 index 000000000..b8498ab1a --- /dev/null +++ b/DataSpec/DNACommon/ELSC.def @@ -0,0 +1,56 @@ +#ifndef ENTRY +#define ENTRY(name, identifier) +#endif + +#ifndef INT_ENTRY +#define INT_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef REAL_ENTRY +#define REAL_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef COLOR_ENTRY +#define COLOR_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef EMITTER_ENTRY +#define EMITTER_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef RES_ENTRY +#define RES_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef BOOL_ENTRY +#define BOOL_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +INT_ENTRY('LIFE', x0_LIFE) +INT_ENTRY('SLIF', x4_SLIF) +REAL_ENTRY('GRAT', x8_GRAT) +INT_ENTRY('SCNT', xc_SCNT) +INT_ENTRY('SSEG', x10_SSEG) +COLOR_ENTRY('COLR', x14_COLR) +EMITTER_ENTRY('IEMT', x18_IEMT) +EMITTER_ENTRY('FEMT', x1c_FEMT) +REAL_ENTRY('AMPL', x20_AMPL) +REAL_ENTRY('AMPD', x24_AMPD) +REAL_ENTRY('LWD1', x28_LWD1) +REAL_ENTRY('LWD2', x2c_LWD2) +REAL_ENTRY('LWD3', x30_LWD3) +COLOR_ENTRY('LCL1', x34_LCL1) +COLOR_ENTRY('LCL2', x38_LCL2) +COLOR_ENTRY('LCL3', x3c_LCL3) +RES_ENTRY('SSWH', x40_SSWH) +RES_ENTRY('GPSM', x50_GPSM) +RES_ENTRY('EPSM', x60_EPSM) +BOOL_ENTRY('ZERY', x70_ZERY) + +#undef ENTRY +#undef INT_ENTRY +#undef REAL_ENTRY +#undef COLOR_ENTRY +#undef EMITTER_ENTRY +#undef RES_ENTRY +#undef BOOL_ENTRY diff --git a/DataSpec/DNACommon/ELSC.hpp b/DataSpec/DNACommon/ELSC.hpp index 52ff09e35..a6eaaf41d 100644 --- a/DataSpec/DNACommon/ELSC.hpp +++ b/DataSpec/DNACommon/ELSC.hpp @@ -12,33 +12,36 @@ class ProjectPath; } namespace DataSpec::DNAParticle { -template -struct ELSM : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - AT_SUBDECL_DNA - IntElementFactory x0_LIFE; - IntElementFactory x4_SLIF; - RealElementFactory x8_GRAT; - IntElementFactory xc_SCNT; - IntElementFactory x10_SSEG; - ColorElementFactory x14_COLR; - EmitterElementFactory x18_IEMT; - EmitterElementFactory x1c_FEMT; - RealElementFactory x20_AMPL; - RealElementFactory x24_AMPD; - RealElementFactory x28_LWD1; - RealElementFactory x2c_LWD2; - RealElementFactory x30_LWD3; - ColorElementFactory x34_LCL1; - ColorElementFactory x38_LCL2; - ColorElementFactory x3c_LCL3; - ChildResourceFactory x40_SSWH; - ChildResourceFactory x50_GPSM; - ChildResourceFactory x60_EPSM; - BoolHelper x70_ZERY; - void gatherDependencies(std::vector&) const; +template +struct _ELSM { + static constexpr ParticleType Type = ParticleType::ELSM; + +#define INT_ENTRY(name, identifier) IntElementFactory identifier; +#define REAL_ENTRY(name, identifier) RealElementFactory identifier; +#define COLOR_ENTRY(name, identifier) ColorElementFactory identifier; +#define EMITTER_ENTRY(name, identifier) EmitterElementFactory identifier; +#define RES_ENTRY(name, identifier) ChildResourceFactory identifier; +#define BOOL_ENTRY(name, identifier) bool identifier = false; +#include "ELSC.def" + + template + void constexpr Enumerate(_Func f) { +#define ENTRY(name, identifier) f(FOURCC(name), identifier); +#include "ELSC.def" + } + + template + bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { +#define ENTRY(name, identifier) case SBIG(name): f(identifier); return true; +#include "ELSC.def" + default: return false; + } + } }; +template +using ELSM = PPImpl<_ELSM>; template bool ExtractELSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath); 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/DNACommon/PART.cpp b/DataSpec/DNACommon/PART.cpp index abdeea0d2..23176e42a 100644 --- a/DataSpec/DNACommon/PART.cpp +++ b/DataSpec/DNACommon/PART.cpp @@ -1,9 +1,14 @@ #include "DataSpec/DNACommon/PART.hpp" - #include "DataSpec/DNACommon/PAK.hpp" namespace DataSpec::DNAParticle { +template struct PPImpl<_GPSM>; +template struct PPImpl<_GPSM>; + +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_GPSM>) +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_GPSM>) + template <> std::string_view GPSM::DNAType() { return "GPSM"sv; @@ -14,1399 +19,6 @@ std::string_view GPSM::DNAType() { return "GPSM"sv; } -template -void GPSM::_read(typename ReadYaml::StreamT& r) { - for (const auto& elem : r.getCurNode()->m_mapChildren) { - if (elem.first.size() < 4) { - LogModule.report(logvisor::Warning, fmt("short FourCC in element '{}'"), elem.first); - continue; - } - - if (auto rec = r.enterSubRecord(elem.first.c_str())) { - switch (*reinterpret_cast(elem.first.data())) { - case SBIG('PMCL'): - x78_PMCL.read(r); - break; - case SBIG('LFOR'): - x118_LFOR.read(r); - break; - case SBIG('IDTS'): - xa4_IDTS.read(r); - break; - case SBIG('EMTR'): - x40_EMTR.read(r); - break; - case SBIG('COLR'): - x30_COLR.read(r); - break; - case SBIG('CIND'): - x45_30_CIND = r.readBool(); - break; - case SBIG('AAPH'): - x44_26_AAPH = r.readBool(); - break; - case SBIG('CSSD'): - xa0_CSSD.read(r); - break; - case SBIG('GRTE'): - x2c_GRTE.read(r); - break; - case SBIG('FXLL'): - x44_25_FXLL = r.readBool(); - break; - case SBIG('ICTS'): - x8c_ICTS.read(r); - break; - case SBIG('KSSM'): - xd0_KSSM.read(r); - break; - case SBIG('ILOC'): - x38_ILOC.read(r); - break; - case SBIG('IITS'): - xb8_IITS.read(r); - break; - case SBIG('IVEC'): - x3c_IVEC.read(r); - break; - case SBIG('LDIR'): - x110_LDIR.read(r); - break; - case SBIG('LCLR'): - x104_LCLR.read(r); - break; - case SBIG('LENG'): - x20_LENG.read(r); - break; - case SBIG('MAXP'): - x28_MAXP.read(r); - break; - case SBIG('LOFF'): - x10c_LOFF.read(r); - break; - case SBIG('LINT'): - x108_LINT.read(r); - break; - case SBIG('LINE'): - x44_24_LINE = r.readBool(); - break; - case SBIG('LFOT'): - x114_LFOT.read(r); - break; - case SBIG('LIT_'): - x44_29_LIT_ = r.readBool(); - break; - case SBIG('LTME'): - x34_LTME.read(r); - break; - case SBIG('LSLA'): - x11c_LSLA.read(r); - break; - case SBIG('LTYP'): - x100_LTYP.read(r); - break; - case SBIG('NDSY'): - xb4_NDSY.read(r); - break; - case SBIG('MBSP'): - x48_MBSP.read(r); - break; - case SBIG('MBLR'): - x44_30_MBLR = r.readBool(); - break; - case SBIG('NCSY'): - x9c_NCSY.read(r); - break; - case SBIG('PISY'): - xc8_PISY.read(r); - break; - case SBIG('OPTS'): - x45_31_OPTS = r.readBool(); - break; - case SBIG('PMAB'): - x44_31_PMAB = r.readBool(); - break; - case SBIG('SESD'): - xf8_SESD.read(r); - break; - case SBIG('SEPO'): - xfc_SEPO.read(r); - break; - case SBIG('PSLT'): - xc_PSLT.read(r); - break; - case SBIG('PMSC'): - x74_PMSC.read(r); - break; - case SBIG('PMOP'): - x6c_PMOP.read(r); - break; - case SBIG('PMDL'): - x5c_PMDL.read(r); - break; - case SBIG('PMRT'): - x70_PMRT.read(r); - break; - case SBIG('POFS'): - x18_POFS.read(r); - break; - case SBIG('PMUS'): - x45_24_PMUS = r.readBool(); - break; - case SBIG('PSIV'): - x0_PSIV.read(r); - break; - case SBIG('ROTA'): - x50_ROTA.read(r); - break; - case SBIG('PSVM'): - x4_PSVM.read(r); - break; - case SBIG('PSTS'): - x14_PSTS.read(r); - break; - case SBIG('PSOV'): - x8_PSOV.read(r); - break; - case SBIG('PSWT'): - x10_PSWT.read(r); - break; - case SBIG('PMLC'): - xec_PMLC.read(r); - break; - case SBIG('SEED'): - x1c_SEED.read(r); - break; - case SBIG('PMOO'): - x45_25_PMOO = r.readBool(); - break; - case SBIG('SSSD'): - xe4_SSSD.read(r); - break; - case SBIG('SORT'): - x44_28_SORT = r.readBool(); - break; - case SBIG('SIZE'): - x4c_SIZE.read(r); - break; - case SBIG('SISY'): - xcc_SISY.read(r); - break; - case SBIG('SSPO'): - xe8_SSPO.read(r); - break; - case SBIG('TEXR'): - x54_TEXR.read(r); - break; - case SBIG('SSWH'): - xd4_SSWH.read(r); - break; - case SBIG('TIND'): - x58_TIND.read(r); - break; - case SBIG('VMD4'): - x45_29_VMD4 = r.readBool(); - break; - case SBIG('VMD3'): - x45_28_VMD3 = r.readBool(); - break; - case SBIG('VMD2'): - x45_27_VMD2 = r.readBool(); - break; - case SBIG('VMD1'): - x45_26_VMD1 = r.readBool(); - break; - case SBIG('VEL4'): - x88_VEL4.read(r); - break; - case SBIG('VEL3'): - x84_VEL3.read(r); - break; - case SBIG('VEL2'): - x80_VEL2.read(r); - break; - case SBIG('VEL1'): - x7c_VEL1.read(r); - break; - case SBIG('ZBUF'): - x44_27_ZBUF = r.readBool(); - break; - case SBIG('WIDT'): - x24_WIDT.read(r); - break; - case SBIG('ORNT'): - x30_30_ORNT = r.readBool(); - break; - case SBIG('RSOP'): - x30_31_RSOP = r.readBool(); - break; - case SBIG('ADV1'): - x10c_ADV1.read(r); - break; - case SBIG('ADV2'): - x110_ADV2.read(r); - break; - case SBIG('ADV3'): - x114_ADV3.read(r); - break; - case SBIG('ADV4'): - x118_ADV4.read(r); - break; - case SBIG('ADV5'): - x11c_ADV5.read(r); - break; - case SBIG('ADV6'): - x120_ADV6.read(r); - break; - case SBIG('ADV7'): - x124_ADV7.read(r); - break; - case SBIG('SELC'): - xd8_SELC.read(r); - break; - default: - break; - } - } - } -} - -template -void GPSM::_write(typename WriteYaml::StreamT& w) const { - if (x0_PSIV) - if (auto rec = w.enterSubRecord("PSIV")) - x0_PSIV.write(w); - if (x4_PSVM) - if (auto rec = w.enterSubRecord("PSVM")) - x4_PSVM.write(w); - if (x8_PSOV) - if (auto rec = w.enterSubRecord("PSOV")) - x8_PSOV.write(w); - if (xc_PSLT) - if (auto rec = w.enterSubRecord("PSLT")) - xc_PSLT.write(w); - if (x10_PSWT) - if (auto rec = w.enterSubRecord("PSWT")) - x10_PSWT.write(w); - if (x14_PSTS) - if (auto rec = w.enterSubRecord("PSTS")) - x14_PSTS.write(w); - if (x18_POFS) - if (auto rec = w.enterSubRecord("POFS")) - x18_POFS.write(w); - if (x1c_SEED) - if (auto rec = w.enterSubRecord("SEED")) - x1c_SEED.write(w); - if (x20_LENG) - if (auto rec = w.enterSubRecord("LENG")) - x20_LENG.write(w); - if (x24_WIDT) - if (auto rec = w.enterSubRecord("WIDT")) - x24_WIDT.write(w); - if (x28_MAXP) - if (auto rec = w.enterSubRecord("MAXP")) - x28_MAXP.write(w); - if (x2c_GRTE) - if (auto rec = w.enterSubRecord("GRTE")) - x2c_GRTE.write(w); - if (x30_COLR) - if (auto rec = w.enterSubRecord("COLR")) - x30_COLR.write(w); - if (x34_LTME) - if (auto rec = w.enterSubRecord("LTME")) - x34_LTME.write(w); - if (x38_ILOC) - if (auto rec = w.enterSubRecord("ILOC")) - x38_ILOC.write(w); - if (x3c_IVEC) - if (auto rec = w.enterSubRecord("IVEC")) - x3c_IVEC.write(w); - if (x40_EMTR) - if (auto rec = w.enterSubRecord("EMTR")) - x40_EMTR.write(w); - if (x44_24_LINE) - w.writeBool("LINE", true); - if (x44_25_FXLL) - w.writeBool("FXLL", true); - if (x44_26_AAPH) - w.writeBool("AAPH", true); - if (x44_27_ZBUF) - w.writeBool("ZBUF", true); - if (x44_28_SORT) - w.writeBool("SORT", true); - if (x44_29_LIT_) - w.writeBool("LIT_", true); - if (x44_30_MBLR) - w.writeBool("MBLR", true); - if (x44_31_PMAB) - w.writeBool("PMAB", true); - if (x45_24_PMUS) - w.writeBool("PMUS", true); - if (!x45_25_PMOO) - w.writeBool("PMOO", false); - if (x45_26_VMD1) - w.writeBool("VMD1", true); - if (x45_27_VMD2) - w.writeBool("VMD2", true); - if (x45_28_VMD3) - w.writeBool("VMD3", true); - if (x45_29_VMD4) - w.writeBool("VMD4", true); - if (x45_30_CIND) - w.writeBool("CIND", true); - if (x45_31_OPTS) - w.writeBool("OPTS", true); - if (x30_30_ORNT) - w.writeBool("ORNT", true); - if (x30_31_RSOP) - w.writeBool("RSOP", true); - if (x48_MBSP) - if (auto rec = w.enterSubRecord("MBSP")) - x48_MBSP.write(w); - if (x4c_SIZE) - if (auto rec = w.enterSubRecord("SIZE")) - x4c_SIZE.write(w); - if (x50_ROTA) - if (auto rec = w.enterSubRecord("ROTA")) - x50_ROTA.write(w); - if (x54_TEXR) - if (auto rec = w.enterSubRecord("TEXR")) - x54_TEXR.write(w); - if (x58_TIND) - if (auto rec = w.enterSubRecord("TIND")) - x58_TIND.write(w); - if (x5c_PMDL) - if (auto rec = w.enterSubRecord("PMDL")) - x5c_PMDL.write(w); - if (x6c_PMOP) - if (auto rec = w.enterSubRecord("PMOP")) - x6c_PMOP.write(w); - if (x70_PMRT) - if (auto rec = w.enterSubRecord("PMRT")) - x70_PMRT.write(w); - if (x74_PMSC) - if (auto rec = w.enterSubRecord("PMSC")) - x74_PMSC.write(w); - if (x78_PMCL) - if (auto rec = w.enterSubRecord("PMCL")) - x78_PMCL.write(w); - if (x7c_VEL1) - if (auto rec = w.enterSubRecord("VEL1")) - x7c_VEL1.write(w); - if (x80_VEL2) - if (auto rec = w.enterSubRecord("VEL2")) - x80_VEL2.write(w); - if (x84_VEL3) - if (auto rec = w.enterSubRecord("VEL3")) - x84_VEL3.write(w); - if (x88_VEL4) - if (auto rec = w.enterSubRecord("VEL4")) - x88_VEL4.write(w); - if (x8c_ICTS) - if (auto rec = w.enterSubRecord("ICTS")) - x8c_ICTS.write(w); - if (x9c_NCSY) - if (auto rec = w.enterSubRecord("NCSY")) - x9c_NCSY.write(w); - if (xa0_CSSD) - if (auto rec = w.enterSubRecord("CSSD")) - xa0_CSSD.write(w); - if (xa4_IDTS) - if (auto rec = w.enterSubRecord("IDTS")) - xa4_IDTS.write(w); - if (xb4_NDSY) - if (auto rec = w.enterSubRecord("NDSY")) - xb4_NDSY.write(w); - if (xb8_IITS) - if (auto rec = w.enterSubRecord("IITS")) - xb8_IITS.write(w); - if (xc8_PISY) - if (auto rec = w.enterSubRecord("PISY")) - xc8_PISY.write(w); - if (xcc_SISY) - if (auto rec = w.enterSubRecord("SISY")) - xcc_SISY.write(w); - if (xd0_KSSM) - if (auto rec = w.enterSubRecord("KSSM")) - xd0_KSSM.write(w); - if (xd4_SSWH) - if (auto rec = w.enterSubRecord("SSWH")) - xd4_SSWH.write(w); - if (xd8_SELC) - if (auto rec = w.enterSubRecord("SELC")) - xd8_SELC.write(w); - if (xe4_SSSD) - if (auto rec = w.enterSubRecord("SSSD")) - xe4_SSSD.write(w); - if (xe8_SSPO) - if (auto rec = w.enterSubRecord("SSPO")) - xe8_SSPO.write(w); - if (xf8_SESD) - if (auto rec = w.enterSubRecord("SESD")) - xf8_SESD.write(w); - if (xfc_SEPO) - if (auto rec = w.enterSubRecord("SEPO")) - xfc_SEPO.write(w); - if (xec_PMLC) - if (auto rec = w.enterSubRecord("PMLC")) - xec_PMLC.write(w); - if (x100_LTYP) - if (auto rec = w.enterSubRecord("LTYP")) - x100_LTYP.write(w); - if (x104_LCLR) - if (auto rec = w.enterSubRecord("LCLR")) - x104_LCLR.write(w); - if (x108_LINT) - if (auto rec = w.enterSubRecord("LINT")) - x108_LINT.write(w); - if (x10c_LOFF) - if (auto rec = w.enterSubRecord("LOFF")) - x10c_LOFF.write(w); - if (x110_LDIR) - if (auto rec = w.enterSubRecord("LDIR")) - x110_LDIR.write(w); - if (x114_LFOT) - if (auto rec = w.enterSubRecord("LFOT")) - x114_LFOT.write(w); - if (x118_LFOR) - if (auto rec = w.enterSubRecord("LFOR")) - x118_LFOR.write(w); - if (x11c_LSLA) - if (auto rec = w.enterSubRecord("LSLA")) - x11c_LSLA.write(w); - if (x10c_ADV1) - if (auto rec = w.enterSubRecord("ADV1")) - x10c_ADV1.write(w); - if (x110_ADV2) - if (auto rec = w.enterSubRecord("ADV2")) - x110_ADV2.write(w); - if (x114_ADV3) - if (auto rec = w.enterSubRecord("ADV3")) - x114_ADV3.write(w); - if (x118_ADV4) - if (auto rec = w.enterSubRecord("ADV4")) - x118_ADV4.write(w); - if (x11c_ADV5) - if (auto rec = w.enterSubRecord("ADV5")) - x11c_ADV5.write(w); - if (x120_ADV6) - if (auto rec = w.enterSubRecord("ADV6")) - x120_ADV6.write(w); - if (x124_ADV7) - if (auto rec = w.enterSubRecord("ADV7")) - x124_ADV7.write(w); - if (x128_ADV8) - if (auto rec = w.enterSubRecord("ADV8")) - x128_ADV8.write(w); -} - -template -void GPSM::_binarySize(typename BinarySize::StreamT& s) const { - s += 4; - if (x0_PSIV) { - s += 4; - x0_PSIV.binarySize(s); - } - if (x4_PSVM) { - s += 4; - x4_PSVM.binarySize(s); - } - if (x8_PSOV) { - s += 4; - x8_PSOV.binarySize(s); - } - if (xc_PSLT) { - s += 4; - xc_PSLT.binarySize(s); - } - if (x10_PSWT) { - s += 4; - x10_PSWT.binarySize(s); - } - if (x14_PSTS) { - s += 4; - x14_PSTS.binarySize(s); - } - if (x18_POFS) { - s += 4; - x18_POFS.binarySize(s); - } - if (x1c_SEED) { - s += 4; - x1c_SEED.binarySize(s); - } - if (x20_LENG) { - s += 4; - x20_LENG.binarySize(s); - } - if (x24_WIDT) { - s += 4; - x24_WIDT.binarySize(s); - } - if (x28_MAXP) { - s += 4; - x28_MAXP.binarySize(s); - } - if (x2c_GRTE) { - s += 4; - x2c_GRTE.binarySize(s); - } - if (x30_COLR) { - s += 4; - x30_COLR.binarySize(s); - } - if (x34_LTME) { - s += 4; - x34_LTME.binarySize(s); - } - if (x38_ILOC) { - s += 4; - x38_ILOC.binarySize(s); - } - if (x3c_IVEC) { - s += 4; - x3c_IVEC.binarySize(s); - } - if (x40_EMTR) { - s += 4; - x40_EMTR.binarySize(s); - } - if (x44_24_LINE) - s += 9; - if (x44_25_FXLL) - s += 9; - if (x44_26_AAPH) - s += 9; - if (x44_27_ZBUF) - s += 9; - if (x44_28_SORT) - s += 9; - if (x44_29_LIT_) - s += 9; - if (x44_30_MBLR) - s += 9; - if (x44_31_PMAB) - s += 9; - if (x45_24_PMUS) - s += 9; - if (!x45_25_PMOO) - s += 9; - if (x45_26_VMD1) - s += 9; - if (x45_27_VMD2) - s += 9; - if (x45_28_VMD3) - s += 9; - if (x45_29_VMD4) - s += 9; - if (x45_30_CIND) - s += 9; - if (x45_31_OPTS) - s += 9; - if (x30_30_ORNT) - s += 9; - if (x30_31_RSOP) - s += 9; - if (x48_MBSP) { - s += 4; - x48_MBSP.binarySize(s); - } - if (x4c_SIZE) { - s += 4; - x4c_SIZE.binarySize(s); - } - if (x50_ROTA) { - s += 4; - x50_ROTA.binarySize(s); - } - if (x54_TEXR) { - s += 4; - x54_TEXR.binarySize(s); - } - if (x58_TIND) { - s += 4; - x58_TIND.binarySize(s); - } - if (x5c_PMDL) { - s += 4; - x5c_PMDL.binarySize(s); - } - if (x6c_PMOP) { - s += 4; - x6c_PMOP.binarySize(s); - } - if (x70_PMRT) { - s += 4; - x70_PMRT.binarySize(s); - } - if (x74_PMSC) { - s += 4; - x74_PMSC.binarySize(s); - } - if (x78_PMCL) { - s += 4; - x78_PMCL.binarySize(s); - } - if (x7c_VEL1) { - s += 4; - x7c_VEL1.binarySize(s); - } - if (x80_VEL2) { - s += 4; - x80_VEL2.binarySize(s); - } - if (x84_VEL3) { - s += 4; - x84_VEL3.binarySize(s); - } - if (x88_VEL4) { - s += 4; - x88_VEL4.binarySize(s); - } - if (x8c_ICTS) { - s += 4; - x8c_ICTS.binarySize(s); - } - if (x9c_NCSY) { - s += 4; - x9c_NCSY.binarySize(s); - } - if (xa0_CSSD) { - s += 4; - xa0_CSSD.binarySize(s); - } - if (xa4_IDTS) { - s += 4; - xa4_IDTS.binarySize(s); - } - if (xb4_NDSY) { - s += 4; - xb4_NDSY.binarySize(s); - } - if (xb8_IITS) { - s += 4; - xb8_IITS.binarySize(s); - } - if (xc8_PISY) { - s += 4; - xc8_PISY.binarySize(s); - } - if (xcc_SISY) { - s += 4; - xcc_SISY.binarySize(s); - } - if (xd0_KSSM) { - s += 4; - xd0_KSSM.binarySize(s); - } - if (xd4_SSWH) { - s += 4; - xd4_SSWH.binarySize(s); - } - if (xd8_SELC) { - s += 4; - xd8_SELC.binarySize(s); - } - if (xe4_SSSD) { - s += 4; - xe4_SSSD.binarySize(s); - } - if (xe8_SSPO) { - s += 4; - xe8_SSPO.binarySize(s); - } - if (xf8_SESD) { - s += 4; - xf8_SESD.binarySize(s); - } - if (xfc_SEPO) { - s += 4; - xfc_SEPO.binarySize(s); - } - if (xec_PMLC) { - s += 4; - xec_PMLC.binarySize(s); - } - if (x100_LTYP) { - s += 4; - x100_LTYP.binarySize(s); - } - if (x104_LCLR) { - s += 4; - x104_LCLR.binarySize(s); - } - if (x108_LINT) { - s += 4; - x108_LINT.binarySize(s); - } - if (x10c_LOFF) { - s += 4; - x10c_LOFF.binarySize(s); - } - if (x110_LDIR) { - s += 4; - x110_LDIR.binarySize(s); - } - if (x114_LFOT) { - s += 4; - x114_LFOT.binarySize(s); - } - if (x118_LFOR) { - s += 4; - x118_LFOR.binarySize(s); - } - if (x11c_LSLA) { - s += 4; - x11c_LSLA.binarySize(s); - } - if (x10c_ADV1) { - s += 4; - x10c_ADV1.binarySize(s); - } - if (x110_ADV2) { - s += 4; - x110_ADV2.binarySize(s); - } - if (x114_ADV3) { - s += 4; - x114_ADV3.binarySize(s); - } - if (x118_ADV4) { - s += 4; - x118_ADV4.binarySize(s); - } - if (x11c_ADV5) { - s += 4; - x11c_ADV5.binarySize(s); - } - if (x120_ADV6) { - s += 4; - x120_ADV6.binarySize(s); - } - if (x124_ADV7) { - s += 4; - x124_ADV7.binarySize(s); - } - if (x128_ADV8) { - s += 4; - x128_ADV8.binarySize(s); - } -} - -template -void GPSM::_read(typename Read::StreamT& r) { - DNAFourCC clsId; - clsId.read(r); - if (clsId != SBIG('GPSM')) { - LogModule.report(logvisor::Warning, fmt("non GPSM provided to GPSM parser")); - return; - } - clsId.read(r); - while (clsId != SBIG('_END')) { - switch (clsId.toUint32()) { - case SBIG('PMCL'): - x78_PMCL.read(r); - break; - case SBIG('LFOR'): - x118_LFOR.read(r); - break; - case SBIG('IDTS'): - xa4_IDTS.read(r); - break; - case SBIG('EMTR'): - x40_EMTR.read(r); - break; - case SBIG('COLR'): - x30_COLR.read(r); - break; - case SBIG('CIND'): - r.readUint32Big(); - x45_30_CIND = r.readBool(); - break; - case SBIG('AAPH'): - r.readUint32Big(); - x44_26_AAPH = r.readBool(); - break; - case SBIG('CSSD'): - xa0_CSSD.read(r); - break; - case SBIG('GRTE'): - x2c_GRTE.read(r); - break; - case SBIG('FXLL'): - r.readUint32Big(); - x44_25_FXLL = r.readBool(); - break; - case SBIG('ICTS'): - x8c_ICTS.read(r); - break; - case SBIG('KSSM'): - xd0_KSSM.read(r); - break; - case SBIG('ILOC'): - x38_ILOC.read(r); - break; - case SBIG('IITS'): - xb8_IITS.read(r); - break; - case SBIG('IVEC'): - x3c_IVEC.read(r); - break; - case SBIG('LDIR'): - x110_LDIR.read(r); - break; - case SBIG('LCLR'): - x104_LCLR.read(r); - break; - case SBIG('LENG'): - x20_LENG.read(r); - break; - case SBIG('MAXP'): - x28_MAXP.read(r); - break; - case SBIG('LOFF'): - x10c_LOFF.read(r); - break; - case SBIG('LINT'): - x108_LINT.read(r); - break; - case SBIG('LINE'): - r.readUint32Big(); - x44_24_LINE = r.readBool(); - break; - case SBIG('LFOT'): - x114_LFOT.read(r); - break; - case SBIG('LIT_'): - r.readUint32Big(); - x44_29_LIT_ = r.readBool(); - break; - case SBIG('LTME'): - x34_LTME.read(r); - break; - case SBIG('LSLA'): - x11c_LSLA.read(r); - break; - case SBIG('LTYP'): - x100_LTYP.read(r); - break; - case SBIG('NDSY'): - xb4_NDSY.read(r); - break; - case SBIG('MBSP'): - x48_MBSP.read(r); - break; - case SBIG('MBLR'): - r.readUint32Big(); - x44_30_MBLR = r.readBool(); - break; - case SBIG('NCSY'): - x9c_NCSY.read(r); - break; - case SBIG('PISY'): - xc8_PISY.read(r); - break; - case SBIG('OPTS'): - r.readUint32Big(); - x45_31_OPTS = r.readBool(); - break; - case SBIG('PMAB'): - r.readUint32Big(); - x44_31_PMAB = r.readBool(); - break; - case SBIG('SESD'): - xf8_SESD.read(r); - break; - case SBIG('SEPO'): - xfc_SEPO.read(r); - break; - case SBIG('PSLT'): - xc_PSLT.read(r); - break; - case SBIG('PMSC'): - x74_PMSC.read(r); - break; - case SBIG('PMOP'): - x6c_PMOP.read(r); - break; - case SBIG('PMDL'): - x5c_PMDL.read(r); - break; - case SBIG('PMRT'): - x70_PMRT.read(r); - break; - case SBIG('POFS'): - x18_POFS.read(r); - break; - case SBIG('PMUS'): - r.readUint32Big(); - x45_24_PMUS = r.readBool(); - break; - case SBIG('PSIV'): - x0_PSIV.read(r); - break; - case SBIG('ROTA'): - x50_ROTA.read(r); - break; - case SBIG('PSVM'): - x4_PSVM.read(r); - break; - case SBIG('PSTS'): - x14_PSTS.read(r); - break; - case SBIG('PSOV'): - x8_PSOV.read(r); - break; - case SBIG('PSWT'): - x10_PSWT.read(r); - break; - case SBIG('PMLC'): - xec_PMLC.read(r); - break; - case SBIG('SEED'): - x1c_SEED.read(r); - break; - case SBIG('PMOO'): - r.readUint32Big(); - x45_25_PMOO = r.readBool(); - break; - case SBIG('SSSD'): - xe4_SSSD.read(r); - break; - case SBIG('SORT'): - r.readUint32Big(); - x44_28_SORT = r.readBool(); - break; - case SBIG('SIZE'): - x4c_SIZE.read(r); - break; - case SBIG('SISY'): - xcc_SISY.read(r); - break; - case SBIG('SSPO'): - xe8_SSPO.read(r); - break; - case SBIG('TEXR'): - x54_TEXR.read(r); - break; - case SBIG('SSWH'): - xd4_SSWH.read(r); - break; - case SBIG('TIND'): - x58_TIND.read(r); - break; - case SBIG('VMD4'): - r.readUint32Big(); - x45_29_VMD4 = r.readBool(); - break; - case SBIG('VMD3'): - r.readUint32Big(); - x45_28_VMD3 = r.readBool(); - break; - case SBIG('VMD2'): - r.readUint32Big(); - x45_27_VMD2 = r.readBool(); - break; - case SBIG('VMD1'): - r.readUint32Big(); - x45_26_VMD1 = r.readBool(); - break; - case SBIG('VEL4'): - x88_VEL4.read(r); - break; - case SBIG('VEL3'): - x84_VEL3.read(r); - break; - case SBIG('VEL2'): - x80_VEL2.read(r); - break; - case SBIG('VEL1'): - x7c_VEL1.read(r); - break; - case SBIG('ZBUF'): - r.readUint32Big(); - x44_27_ZBUF = r.readBool(); - break; - case SBIG('WIDT'): - x24_WIDT.read(r); - break; - case SBIG('ORNT'): - r.readUint32Big(); - x30_30_ORNT = r.readBool(); - break; - case SBIG('RSOP'): - r.readUint32Big(); - x30_31_RSOP = r.readBool(); - break; - case SBIG('ADV1'): - x10c_ADV1.read(r); - break; - case SBIG('ADV2'): - x110_ADV2.read(r); - break; - case SBIG('ADV3'): - x114_ADV3.read(r); - break; - case SBIG('ADV4'): - x118_ADV4.read(r); - break; - case SBIG('ADV5'): - x11c_ADV5.read(r); - break; - case SBIG('ADV6'): - x120_ADV6.read(r); - break; - case SBIG('ADV7'): - x124_ADV7.read(r); - break; - case SBIG('ADV8'): - x128_ADV8.read(r); - break; - case SBIG('SELC'): - xd8_SELC.read(r); - break; - default: - LogModule.report(logvisor::Fatal, fmt("Unknown GPSM class {} @{}"), clsId, r.position()); - break; - } - clsId.read(r); - } -} - -template -void GPSM::_write(typename Write::StreamT& w) const { - w.writeBytes((atInt8*)"GPSM", 4); - if (x0_PSIV) { - w.writeBytes((atInt8*)"PSIV", 4); - x0_PSIV.write(w); - } - if (x4_PSVM) { - w.writeBytes((atInt8*)"PSVM", 4); - x4_PSVM.write(w); - } - if (x8_PSOV) { - w.writeBytes((atInt8*)"PSOV", 4); - x8_PSOV.write(w); - } - if (xc_PSLT) { - w.writeBytes((atInt8*)"PSLT", 4); - xc_PSLT.write(w); - } - if (x10_PSWT) { - w.writeBytes((atInt8*)"PSWT", 4); - x10_PSWT.write(w); - } - if (x14_PSTS) { - w.writeBytes((atInt8*)"PSTS", 4); - x14_PSTS.write(w); - } - if (x18_POFS) { - w.writeBytes((atInt8*)"POFS", 4); - x18_POFS.write(w); - } - if (x1c_SEED) { - w.writeBytes((atInt8*)"SEED", 4); - x1c_SEED.write(w); - } - if (x20_LENG) { - w.writeBytes((atInt8*)"LENG", 4); - x20_LENG.write(w); - } - if (x24_WIDT) { - w.writeBytes((atInt8*)"WIDT", 4); - x24_WIDT.write(w); - } - if (x28_MAXP) { - w.writeBytes((atInt8*)"MAXP", 4); - x28_MAXP.write(w); - } - if (x2c_GRTE) { - w.writeBytes((atInt8*)"GRTE", 4); - x2c_GRTE.write(w); - } - if (x30_COLR) { - w.writeBytes((atInt8*)"COLR", 4); - x30_COLR.write(w); - } - if (x34_LTME) { - w.writeBytes((atInt8*)"LTME", 4); - x34_LTME.write(w); - } - if (x38_ILOC) { - w.writeBytes((atInt8*)"ILOC", 4); - x38_ILOC.write(w); - } - if (x3c_IVEC) { - w.writeBytes((atInt8*)"IVEC", 4); - x3c_IVEC.write(w); - } - if (x40_EMTR) { - w.writeBytes((atInt8*)"EMTR", 4); - x40_EMTR.write(w); - } - if (x44_24_LINE) { - w.writeBytes((atInt8*)"LINECNST\x01", 9); - } - if (x44_25_FXLL) { - w.writeBytes((atInt8*)"FXLLCNST\x01", 9); - } - if (x44_26_AAPH) { - w.writeBytes((atInt8*)"AAPHCNST\x01", 9); - } - if (x44_27_ZBUF) { - w.writeBytes((atInt8*)"ZBUFCNST\x01", 9); - } - if (x44_28_SORT) { - w.writeBytes((atInt8*)"SORTCNST\x01", 9); - } - if (x44_29_LIT_) { - w.writeBytes((atInt8*)"LIT_CNST\x01", 9); - } - if (x44_30_MBLR) { - w.writeBytes((atInt8*)"MBLRCNST\x01", 9); - } - if (x44_31_PMAB) { - w.writeBytes((atInt8*)"PMABCNST\x01", 9); - } - if (x45_24_PMUS) { - w.writeBytes((atInt8*)"PMUSCNST\x01", 9); - } - if (!x45_25_PMOO) { - w.writeBytes((atInt8*)"PMOOCNST\x00", 9); - } - if (x45_26_VMD1) { - w.writeBytes((atInt8*)"VMD1CNST\x01", 9); - } - if (x45_27_VMD2) { - w.writeBytes((atInt8*)"VMD2CNST\x01", 9); - } - if (x45_28_VMD3) { - w.writeBytes((atInt8*)"VMD3CNST\x01", 9); - } - if (x45_29_VMD4) { - w.writeBytes((atInt8*)"VMD4CNST\x01", 9); - } - if (x45_30_CIND) { - w.writeBytes((atInt8*)"CINDCNST\x01", 9); - } - if (x45_31_OPTS) { - w.writeBytes((atInt8*)"OPTSCNST\x01", 9); - } - if (x30_30_ORNT) { - w.writeBytes((atInt8*)"ORNTCNST\x01", 9); - } - if (x30_31_RSOP) { - w.writeBytes((atInt8*)"RSOPCNST\x01", 9); - } - if (x48_MBSP) { - w.writeBytes((atInt8*)"MBSP", 4); - x48_MBSP.write(w); - } - if (x4c_SIZE) { - w.writeBytes((atInt8*)"SIZE", 4); - x4c_SIZE.write(w); - } - if (x50_ROTA) { - w.writeBytes((atInt8*)"ROTA", 4); - x50_ROTA.write(w); - } - if (x54_TEXR) { - w.writeBytes((atInt8*)"TEXR", 4); - x54_TEXR.write(w); - } - if (x58_TIND) { - w.writeBytes((atInt8*)"TIND", 4); - x58_TIND.write(w); - } - if (x5c_PMDL) { - w.writeBytes((atInt8*)"PMDL", 4); - x5c_PMDL.write(w); - } - if (x6c_PMOP) { - w.writeBytes((atInt8*)"PMOP", 4); - x6c_PMOP.write(w); - } - if (x70_PMRT) { - w.writeBytes((atInt8*)"PMRT", 4); - x70_PMRT.write(w); - } - if (x74_PMSC) { - w.writeBytes((atInt8*)"PMSC", 4); - x74_PMSC.write(w); - } - if (x78_PMCL) { - w.writeBytes((atInt8*)"PMCL", 4); - x78_PMCL.write(w); - } - if (x7c_VEL1) { - w.writeBytes((atInt8*)"VEL1", 4); - x7c_VEL1.write(w); - } - if (x80_VEL2) { - w.writeBytes((atInt8*)"VEL2", 4); - x80_VEL2.write(w); - } - if (x84_VEL3) { - w.writeBytes((atInt8*)"VEL3", 4); - x84_VEL3.write(w); - } - if (x88_VEL4) { - w.writeBytes((atInt8*)"VEL4", 4); - x88_VEL4.write(w); - } - if (x8c_ICTS) { - w.writeBytes((atInt8*)"ICTS", 4); - x8c_ICTS.write(w); - } - if (x9c_NCSY) { - w.writeBytes((atInt8*)"NCSY", 4); - x9c_NCSY.write(w); - } - if (xa0_CSSD) { - w.writeBytes((atInt8*)"CSSD", 4); - xa0_CSSD.write(w); - } - if (xa4_IDTS) { - w.writeBytes((atInt8*)"IDTS", 4); - xa4_IDTS.write(w); - } - if (xb4_NDSY) { - w.writeBytes((atInt8*)"NDSY", 4); - xb4_NDSY.write(w); - } - if (xb8_IITS) { - w.writeBytes((atInt8*)"IITS", 4); - xb8_IITS.write(w); - } - if (xc8_PISY) { - w.writeBytes((atInt8*)"PISY", 4); - xc8_PISY.write(w); - } - if (xcc_SISY) { - w.writeBytes((atInt8*)"SISY", 4); - xcc_SISY.write(w); - } - if (xd0_KSSM) { - w.writeBytes((atInt8*)"KSSM", 4); - xd0_KSSM.write(w); - } - if (xd4_SSWH) { - w.writeBytes((atInt8*)"SSWH", 4); - xd4_SSWH.write(w); - } - if (xd8_SELC) { - w.writeBytes((atInt8*)"SELC", 4); - xd8_SELC.write(w); - } - if (xe4_SSSD) { - w.writeBytes((atInt8*)"SSSD", 4); - xe4_SSSD.write(w); - } - if (xe8_SSPO) { - w.writeBytes((atInt8*)"SSPO", 4); - xe8_SSPO.write(w); - } - if (xf8_SESD) { - w.writeBytes((atInt8*)"SESD", 4); - xf8_SESD.write(w); - } - if (xfc_SEPO) { - w.writeBytes((atInt8*)"SEPO", 4); - xfc_SEPO.write(w); - } - if (xec_PMLC) { - w.writeBytes((atInt8*)"PMLC", 4); - xec_PMLC.write(w); - } - if (x100_LTYP) { - w.writeBytes((atInt8*)"LTYP", 4); - x100_LTYP.write(w); - } - if (x104_LCLR) { - w.writeBytes((atInt8*)"LCLR", 4); - x104_LCLR.write(w); - } - if (x108_LINT) { - w.writeBytes((atInt8*)"LINT", 4); - x108_LINT.write(w); - } - if (x10c_LOFF) { - w.writeBytes((atInt8*)"LOFF", 4); - x10c_LOFF.write(w); - } - if (x110_LDIR) { - w.writeBytes((atInt8*)"LDIR", 4); - x110_LDIR.write(w); - } - if (x114_LFOT) { - w.writeBytes((atInt8*)"LFOT", 4); - x114_LFOT.write(w); - } - if (x118_LFOR) { - w.writeBytes((atInt8*)"LFOR", 4); - x118_LFOR.write(w); - } - if (x11c_LSLA) { - w.writeBytes((atInt8*)"LSLA", 4); - x11c_LSLA.write(w); - } - if (x10c_ADV1) { - w.writeBytes((atInt8*)"ADV1", 4); - x10c_ADV1.write(w); - } - if (x110_ADV2) { - w.writeBytes((atInt8*)"ADV2", 4); - x110_ADV2.write(w); - } - if (x114_ADV3) { - w.writeBytes((atInt8*)"ADV3", 4); - x114_ADV3.write(w); - } - if (x118_ADV4) { - w.writeBytes((atInt8*)"ADV4", 4); - x118_ADV4.write(w); - } - if (x11c_ADV5) { - w.writeBytes((atInt8*)"ADV5", 4); - x11c_ADV5.write(w); - } - if (x120_ADV6) { - w.writeBytes((atInt8*)"ADV6", 4); - x120_ADV6.write(w); - } - if (x124_ADV7) { - w.writeBytes((atInt8*)"ADV7", 4); - x124_ADV7.write(w); - } - if (x128_ADV8) { - w.writeBytes((atInt8*)"ADV8", 4); - x128_ADV8.write(w); - } - w.writeBytes("_END", 4); -} - -AT_SUBSPECIALIZE_DNA_YAML(GPSM) -AT_SUBSPECIALIZE_DNA_YAML(GPSM) - -template -void GPSM::gatherDependencies(std::vector& pathsOut) const { - if (x54_TEXR.m_elem) - x54_TEXR.m_elem->gatherDependencies(pathsOut); - if (x58_TIND.m_elem) - x58_TIND.m_elem->gatherDependencies(pathsOut); - g_curSpec->flattenDependencies(x5c_PMDL.id, pathsOut); - g_curSpec->flattenDependencies(x8c_ICTS.id, pathsOut); - g_curSpec->flattenDependencies(xa4_IDTS.id, pathsOut); - g_curSpec->flattenDependencies(xb8_IITS.id, pathsOut); - xd0_KSSM.gatherDependencies(pathsOut); - g_curSpec->flattenDependencies(xd4_SSWH.id, pathsOut); - g_curSpec->flattenDependencies(xec_PMLC.id, pathsOut); - g_curSpec->flattenDependencies(xd8_SELC.id, pathsOut); -} - -template struct GPSM; -template struct GPSM; - template bool ExtractGPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) { athena::io::FileWriter writer(outPath.getAbsolutePath()); diff --git a/DataSpec/DNACommon/PART.def b/DataSpec/DNACommon/PART.def new file mode 100644 index 000000000..8b932cbf3 --- /dev/null +++ b/DataSpec/DNACommon/PART.def @@ -0,0 +1,141 @@ +#ifndef ENTRY +#define ENTRY(name, identifier) +#endif + +#ifndef INT_ENTRY +#define INT_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef REAL_ENTRY +#define REAL_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef VECTOR_ENTRY +#define VECTOR_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef MOD_VECTOR_ENTRY +#define MOD_VECTOR_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef COLOR_ENTRY +#define COLOR_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef EMITTER_ENTRY +#define EMITTER_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef UV_ENTRY +#define UV_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef RES_ENTRY +#define RES_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef KSSM_ENTRY +#define KSSM_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef BOOL_ENTRY +#define BOOL_ENTRY(name, identifier, def) ENTRY(name, identifier) +#endif + +VECTOR_ENTRY('PSIV', x0_PSIV) +MOD_VECTOR_ENTRY('PSVM', x4_PSVM) +VECTOR_ENTRY('PSOV', x8_PSOV) +INT_ENTRY('PSLT', xc_PSLT) +INT_ENTRY('PSWT', x10_PSWT) +REAL_ENTRY('PSTS', x14_PSTS) +VECTOR_ENTRY('POFS', x18_POFS) +INT_ENTRY('SEED', x1c_SEED) +REAL_ENTRY('LENG', x20_LENG) +REAL_ENTRY('WIDT', x24_WIDT) +INT_ENTRY('MAXP', x28_MAXP) +REAL_ENTRY('GRTE', x2c_GRTE) +COLOR_ENTRY('COLR', x30_COLR) +INT_ENTRY('LTME', x34_LTME) +VECTOR_ENTRY('ILOC', x38_ILOC) +VECTOR_ENTRY('IVEC', x3c_IVEC) +EMITTER_ENTRY('EMTR', x40_EMTR) +INT_ENTRY('MBSP', x48_MBSP) +REAL_ENTRY('SIZE', x4c_SIZE) +REAL_ENTRY('ROTA', x50_ROTA) +UV_ENTRY('TEXR', x54_TEXR) +UV_ENTRY('TIND', x58_TIND) +RES_ENTRY('PMDL', x5c_PMDL) +VECTOR_ENTRY('PMOP', x6c_PMOP) +VECTOR_ENTRY('PMRT', x70_PMRT) +VECTOR_ENTRY('PMSC', x74_PMSC) +COLOR_ENTRY('PMCL', x78_PMCL) +MOD_VECTOR_ENTRY('VEL1', x7c_VEL1) +MOD_VECTOR_ENTRY('VEL2', x80_VEL2) +MOD_VECTOR_ENTRY('VEL3', x84_VEL3) +MOD_VECTOR_ENTRY('VEL4', x88_VEL4) +RES_ENTRY('ICTS', x8c_ICTS) +INT_ENTRY('NCSY', x9c_NCSY) +INT_ENTRY('CSSD', xa0_CSSD) +RES_ENTRY('IDTS', xa4_IDTS) +INT_ENTRY('NDSY', xb4_NDSY) +RES_ENTRY('IITS', xb8_IITS) +INT_ENTRY('PISY', xc8_PISY) +INT_ENTRY('SISY', xcc_SISY) +KSSM_ENTRY('KSSM', xd0_KSSM) +RES_ENTRY('SSWH', xd4_SSWH) +INT_ENTRY('SSSD', xe4_SSSD) +VECTOR_ENTRY('SSPO', xe8_SSPO) +INT_ENTRY('SESD', xf8_SESD) +VECTOR_ENTRY('SEPO', xfc_SEPO) +RES_ENTRY('PMLC', xec_PMLC) +INT_ENTRY('LTYP', x100_LTYP) +COLOR_ENTRY('LCLR', x104_LCLR) +REAL_ENTRY('LINT', x108_LINT) +VECTOR_ENTRY('LOFF', x10c_LOFF) +VECTOR_ENTRY('LDIR', x110_LDIR) +INT_ENTRY('LFOT', x114_LFOT) +REAL_ENTRY('LFOR', x118_LFOR) +REAL_ENTRY('LSLA', x11c_LSLA) + +/* 0-00 additions */ +RES_ENTRY('SELC', xd8_SELC) +REAL_ENTRY('ADV1', x10c_ADV1) +REAL_ENTRY('ADV2', x110_ADV2) +REAL_ENTRY('ADV3', x114_ADV3) +REAL_ENTRY('ADV4', x118_ADV4) +REAL_ENTRY('ADV5', x11c_ADV5) +REAL_ENTRY('ADV6', x120_ADV6) +REAL_ENTRY('ADV7', x124_ADV7) +REAL_ENTRY('ADV8', x128_ADV8) + +BOOL_ENTRY('SORT', x44_28_SORT, false) +BOOL_ENTRY('MBLR', x44_30_MBLR, false) +BOOL_ENTRY('LINE', x44_24_LINE, false) +BOOL_ENTRY('LIT_', x44_29_LIT_, false) +BOOL_ENTRY('AAPH', x44_26_AAPH, false) +BOOL_ENTRY('ZBUF', x44_27_ZBUF, false) +BOOL_ENTRY('FXLL', x44_25_FXLL, false) +BOOL_ENTRY('PMAB', x44_31_PMAB, false) +BOOL_ENTRY('VMD4', x45_29_VMD4, false) +BOOL_ENTRY('VMD3', x45_28_VMD3, false) +BOOL_ENTRY('VMD2', x45_27_VMD2, false) +BOOL_ENTRY('VMD1', x45_26_VMD1, false) +BOOL_ENTRY('OPTS', x45_31_OPTS, false) +BOOL_ENTRY('PMUS', x45_24_PMUS, false) +BOOL_ENTRY('PMOO', x45_25_PMOO, true) +BOOL_ENTRY('CIND', x45_30_CIND, false) + +BOOL_ENTRY('ORNT', x30_30_ORNT, false) +BOOL_ENTRY('RSOP', x30_31_RSOP, false) + +#undef ENTRY +#undef INT_ENTRY +#undef REAL_ENTRY +#undef VECTOR_ENTRY +#undef MOD_VECTOR_ENTRY +#undef COLOR_ENTRY +#undef EMITTER_ENTRY +#undef UV_ENTRY +#undef RES_ENTRY +#undef KSSM_ENTRY +#undef BOOL_ENTRY diff --git a/DataSpec/DNACommon/PART.hpp b/DataSpec/DNACommon/PART.hpp index 0475dc217..8c30dc28d 100644 --- a/DataSpec/DNACommon/PART.hpp +++ b/DataSpec/DNACommon/PART.hpp @@ -17,107 +17,39 @@ class ProjectPath; namespace DataSpec::DNAParticle { template -struct GPSM : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - AT_SUBDECL_DNA - VectorElementFactory x0_PSIV; - ModVectorElementFactory x4_PSVM; - VectorElementFactory x8_PSOV; - IntElementFactory xc_PSLT; - IntElementFactory x10_PSWT; - RealElementFactory x14_PSTS; - VectorElementFactory x18_POFS; - IntElementFactory x1c_SEED; - RealElementFactory x20_LENG; - RealElementFactory x24_WIDT; - IntElementFactory x28_MAXP; - RealElementFactory x2c_GRTE; - ColorElementFactory x30_COLR; - IntElementFactory x34_LTME; - VectorElementFactory x38_ILOC; - VectorElementFactory x3c_IVEC; - EmitterElementFactory x40_EMTR; - union { - struct { - bool x44_28_SORT : 1; - bool x44_30_MBLR : 1; - bool x44_24_LINE : 1; - bool x44_29_LIT_ : 1; - bool x44_26_AAPH : 1; - bool x44_27_ZBUF : 1; - bool x44_25_FXLL : 1; - bool x44_31_PMAB : 1; - bool x45_29_VMD4 : 1; - bool x45_28_VMD3 : 1; - bool x45_27_VMD2 : 1; - bool x45_26_VMD1 : 1; - bool x45_31_OPTS : 1; - bool x45_24_PMUS : 1; - bool x45_25_PMOO : 1; - bool x45_30_CIND : 1; - }; - uint16_t dummy1 = 0; - }; - IntElementFactory x48_MBSP; - RealElementFactory x4c_SIZE; - RealElementFactory x50_ROTA; - UVElementFactory x54_TEXR; - UVElementFactory x58_TIND; - ChildResourceFactory x5c_PMDL; - VectorElementFactory x6c_PMOP; - VectorElementFactory x70_PMRT; - VectorElementFactory x74_PMSC; - ColorElementFactory x78_PMCL; - ModVectorElementFactory x7c_VEL1; - ModVectorElementFactory x80_VEL2; - ModVectorElementFactory x84_VEL3; - ModVectorElementFactory x88_VEL4; - ChildResourceFactory x8c_ICTS; - IntElementFactory x9c_NCSY; - IntElementFactory xa0_CSSD; - ChildResourceFactory xa4_IDTS; - IntElementFactory xb4_NDSY; - ChildResourceFactory xb8_IITS; - IntElementFactory xc8_PISY; - IntElementFactory xcc_SISY; - SpawnSystemKeyframeData xd0_KSSM; - ChildResourceFactory xd4_SSWH; - IntElementFactory xe4_SSSD; - VectorElementFactory xe8_SSPO; - IntElementFactory xf8_SESD; - VectorElementFactory xfc_SEPO; - ChildResourceFactory xec_PMLC; - IntElementFactory x100_LTYP; - ColorElementFactory x104_LCLR; - RealElementFactory x108_LINT; - VectorElementFactory x10c_LOFF; - VectorElementFactory x110_LDIR; - IntElementFactory x114_LFOT; - RealElementFactory x118_LFOR; - RealElementFactory x11c_LSLA; +struct _GPSM { + static constexpr ParticleType Type = ParticleType::GPSM; - /* 0-00 additions */ - ChildResourceFactory xd8_SELC; - union { - struct { - bool x30_30_ORNT : 1; - bool x30_31_RSOP : 1; - }; - uint16_t dummy2 = 0; - }; - RealElementFactory x10c_ADV1; - RealElementFactory x110_ADV2; - RealElementFactory x114_ADV3; - RealElementFactory x118_ADV4; - RealElementFactory x11c_ADV5; - RealElementFactory x120_ADV6; - RealElementFactory x124_ADV7; - RealElementFactory x128_ADV8; +#define INT_ENTRY(name, identifier) IntElementFactory identifier; +#define REAL_ENTRY(name, identifier) RealElementFactory identifier; +#define VECTOR_ENTRY(name, identifier) VectorElementFactory identifier; +#define MOD_VECTOR_ENTRY(name, identifier) ModVectorElementFactory identifier; +#define COLOR_ENTRY(name, identifier) ColorElementFactory identifier; +#define EMITTER_ENTRY(name, identifier) EmitterElementFactory identifier; +#define UV_ENTRY(name, identifier) UVElementFactory identifier; +#define RES_ENTRY(name, identifier) ChildResourceFactory identifier; +#define KSSM_ENTRY(name, identifier) SpawnSystemKeyframeData identifier; +#define BOOL_ENTRY(name, identifier, def) bool identifier = def; +#include "PART.def" - GPSM() { x45_25_PMOO = true; } + template + void constexpr Enumerate(_Func f) { +#define ENTRY(name, identifier) f(FOURCC(name), identifier); +#define BOOL_ENTRY(name, identifier, def) f(FOURCC(name), identifier, def); +#include "PART.def" + } - void gatherDependencies(std::vector&) const; + template + bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { +#define ENTRY(name, identifier) case SBIG(name): f(identifier); return true; +#include "PART.def" + default: return false; + } + } }; +template +using GPSM = PPImpl<_GPSM>; template bool ExtractGPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath); diff --git a/DataSpec/DNACommon/ParticleCommon.cpp b/DataSpec/DNACommon/ParticleCommon.cpp index 7ef172e8b..301f6ac56 100644 --- a/DataSpec/DNACommon/ParticleCommon.cpp +++ b/DataSpec/DNACommon/ParticleCommon.cpp @@ -3,6 +3,24 @@ namespace DataSpec::DNAParticle { logvisor::Module LogModule("urde::DNAParticle"); +template struct PEImpl<_RealElementFactory>; +template struct PEImpl<_IntElementFactory>; +template struct PEImpl<_VectorElementFactory>; +template struct PEImpl<_ColorElementFactory>; +template struct PEImpl<_ModVectorElementFactory>; +template struct PEImpl<_EmitterElementFactory>; +template struct PEImpl<_UVElementFactory>; +template struct PEImpl<_UVElementFactory>; + +AT_SUBSPECIALIZE_DNA_YAML(PEImpl<_RealElementFactory>) +AT_SUBSPECIALIZE_DNA_YAML(PEImpl<_IntElementFactory>) +AT_SUBSPECIALIZE_DNA_YAML(PEImpl<_VectorElementFactory>) +AT_SUBSPECIALIZE_DNA_YAML(PEImpl<_ColorElementFactory>) +AT_SUBSPECIALIZE_DNA_YAML(PEImpl<_ModVectorElementFactory>) +AT_SUBSPECIALIZE_DNA_YAML(PEImpl<_EmitterElementFactory>) +AT_SUBSPECIALIZE_DNA_YAML(PEImpl<_UVElementFactory>) +AT_SUBSPECIALIZE_DNA_YAML(PEImpl<_UVElementFactory>) + template <> void REConstant::Enumerate(typename ReadYaml::StreamT& r) { val = r.readFloat(); @@ -148,908 +166,6 @@ void MVEConstant::Enumerate(typename Write::StreamT& w) { comps[2].write(w); } -template <> -void RealElementFactory::Enumerate(typename ReadYaml::StreamT& r) { - const auto& mapChildren = r.getCurNode()->m_mapChildren; - if (mapChildren.empty()) { - m_elem.reset(); - return; - } - - const auto& elem = mapChildren[0]; - if (elem.first.size() < 4) - LogModule.report(logvisor::Fatal, fmt("short FourCC in element '{}'"), elem.first); - - switch (*reinterpret_cast(elem.first.data())) { - case SBIG('LFTW'): - m_elem.reset(new struct RELifetimeTween); - break; - case SBIG('CNST'): - m_elem.reset(new struct REConstant); - break; - case SBIG('CHAN'): - m_elem.reset(new struct RETimeChain); - break; - case SBIG('ADD_'): - m_elem.reset(new struct REAdd); - break; - case SBIG('CLMP'): - m_elem.reset(new struct REClamp); - break; - case SBIG('KEYE'): - case SBIG('KEYP'): - m_elem.reset(new struct REKeyframeEmitter); - break; - case SBIG('IRND'): - m_elem.reset(new struct REInitialRandom); - break; - case SBIG('RAND'): - m_elem.reset(new struct RERandom); - break; - case SBIG('MULT'): - m_elem.reset(new struct REMultiply); - break; - case SBIG('PULS'): - m_elem.reset(new struct REPulse); - break; - case SBIG('SCAL'): - m_elem.reset(new struct RETimeScale); - break; - case SBIG('RLPT'): - m_elem.reset(new struct RELifetimePercent); - break; - case SBIG('SINE'): - m_elem.reset(new struct RESineWave); - break; - case SBIG('ISWT'): - m_elem.reset(new struct REInitialSwitch); - break; - case SBIG('CLTN'): - m_elem.reset(new struct RECompareLessThan); - break; - case SBIG('CEQL'): - m_elem.reset(new struct RECompareEquals); - break; - case SBIG('PAP1'): - m_elem.reset(new struct REParticleAdvanceParam1); - break; - case SBIG('PAP2'): - m_elem.reset(new struct REParticleAdvanceParam2); - break; - case SBIG('PAP3'): - m_elem.reset(new struct REParticleAdvanceParam3); - break; - case SBIG('PAP4'): - m_elem.reset(new struct REParticleAdvanceParam4); - break; - case SBIG('PAP5'): - m_elem.reset(new struct REParticleAdvanceParam5); - break; - case SBIG('PAP6'): - m_elem.reset(new struct REParticleAdvanceParam6); - break; - case SBIG('PAP7'): - m_elem.reset(new struct REParticleAdvanceParam7); - break; - case SBIG('PAP8'): - m_elem.reset(new struct REParticleAdvanceParam8); - break; - case SBIG('PSLL'): - m_elem.reset(new struct REParticleSizeOrLineLength); - break; - case SBIG('PRLW'): - m_elem.reset(new struct REParticleRotationOrLineWidth); - break; - case SBIG('SUB_'): - m_elem.reset(new struct RESubtract); - break; - case SBIG('VMAG'): - m_elem.reset(new struct REVectorMagnitude); - break; - case SBIG('VXTR'): - m_elem.reset(new struct REVectorXToReal); - break; - case SBIG('VYTR'): - m_elem.reset(new struct REVectorYToReal); - break; - case SBIG('VZTR'): - m_elem.reset(new struct REVectorZToReal); - break; - case SBIG('CEXT'): - m_elem.reset(new struct RECEXT); - break; - case SBIG('ITRL'): - m_elem.reset(new struct REIntTimesReal); - break; - default: - m_elem.reset(); - return; - } - if (auto rec = r.enterSubRecord(elem.first.c_str())) - m_elem->read(r); -} - -template <> -void RealElementFactory::Enumerate(typename WriteYaml::StreamT& w) { - if (m_elem) - if (auto rec = w.enterSubRecord(m_elem->ClassID())) - m_elem->write(w); -} - -template <> -void RealElementFactory::Enumerate(typename BinarySize::StreamT& s) { - s += 4; - if (m_elem) - m_elem->binarySize(s); -} - -template <> -void RealElementFactory::Enumerate(typename Read::StreamT& r) { - DNAFourCC clsId; - clsId.read(r); - switch (clsId.toUint32()) { - case SBIG('LFTW'): - m_elem.reset(new struct RELifetimeTween); - break; - case SBIG('CNST'): - m_elem.reset(new struct REConstant); - break; - case SBIG('CHAN'): - m_elem.reset(new struct RETimeChain); - break; - case SBIG('ADD_'): - m_elem.reset(new struct REAdd); - break; - case SBIG('CLMP'): - m_elem.reset(new struct REClamp); - break; - case SBIG('KEYE'): - case SBIG('KEYP'): - m_elem.reset(new struct REKeyframeEmitter); - break; - case SBIG('IRND'): - m_elem.reset(new struct REInitialRandom); - break; - case SBIG('RAND'): - m_elem.reset(new struct RERandom); - break; - case SBIG('MULT'): - m_elem.reset(new struct REMultiply); - break; - case SBIG('PULS'): - m_elem.reset(new struct REPulse); - break; - case SBIG('SCAL'): - m_elem.reset(new struct RETimeScale); - break; - case SBIG('RLPT'): - m_elem.reset(new struct RELifetimePercent); - break; - case SBIG('SINE'): - m_elem.reset(new struct RESineWave); - break; - case SBIG('ISWT'): - m_elem.reset(new struct REInitialSwitch); - break; - case SBIG('CLTN'): - m_elem.reset(new struct RECompareLessThan); - break; - case SBIG('CEQL'): - m_elem.reset(new struct RECompareEquals); - break; - case SBIG('PAP1'): - m_elem.reset(new struct REParticleAdvanceParam1); - break; - case SBIG('PAP2'): - m_elem.reset(new struct REParticleAdvanceParam2); - break; - case SBIG('PAP3'): - m_elem.reset(new struct REParticleAdvanceParam3); - break; - case SBIG('PAP4'): - m_elem.reset(new struct REParticleAdvanceParam4); - break; - case SBIG('PAP5'): - m_elem.reset(new struct REParticleAdvanceParam5); - break; - case SBIG('PAP6'): - m_elem.reset(new struct REParticleAdvanceParam6); - break; - case SBIG('PAP7'): - m_elem.reset(new struct REParticleAdvanceParam7); - break; - case SBIG('PAP8'): - m_elem.reset(new struct REParticleAdvanceParam8); - break; - case SBIG('PSLL'): - m_elem.reset(new struct REParticleSizeOrLineLength); - break; - case SBIG('PRLW'): - m_elem.reset(new struct REParticleRotationOrLineWidth); - break; - case SBIG('SUB_'): - m_elem.reset(new struct RESubtract); - break; - case SBIG('VMAG'): - m_elem.reset(new struct REVectorMagnitude); - break; - case SBIG('VXTR'): - m_elem.reset(new struct REVectorXToReal); - break; - case SBIG('VYTR'): - m_elem.reset(new struct REVectorYToReal); - break; - case SBIG('VZTR'): - m_elem.reset(new struct REVectorZToReal); - break; - case SBIG('CEXT'): - m_elem.reset(new struct RECEXT); - break; - case SBIG('ITRL'): - m_elem.reset(new struct REIntTimesReal); - break; - case SBIG('NONE'): - m_elem.reset(); - return; - default: - m_elem.reset(); - LogModule.report(logvisor::Fatal, fmt("Unknown RealElement class {} @{}"), clsId, r.position()); - return; - } - m_elem->read(r); -} - -template <> -void RealElementFactory::Enumerate(typename Write::StreamT& w) { - if (m_elem) { - w.writeBytes((atInt8*)m_elem->ClassID().data(), 4); - m_elem->write(w); - } else - w.writeBytes((atInt8*)"NONE", 4); -} - -template <> -void IntElementFactory::Enumerate(typename ReadYaml::StreamT& r) { - const auto& mapChildren = r.getCurNode()->m_mapChildren; - if (mapChildren.empty()) { - m_elem.reset(); - return; - } - - const auto& elem = mapChildren[0]; - if (elem.first.size() < 4) - LogModule.report(logvisor::Fatal, fmt("short FourCC in element '{}'"), elem.first); - - switch (*reinterpret_cast(elem.first.data())) { - case SBIG('KEYE'): - case SBIG('KEYP'): - m_elem.reset(new struct IEKeyframeEmitter); - break; - case SBIG('DETH'): - m_elem.reset(new struct IEDeath); - break; - case SBIG('CLMP'): - m_elem.reset(new struct IEClamp); - break; - case SBIG('CHAN'): - m_elem.reset(new struct IETimeChain); - break; - case SBIG('ADD_'): - m_elem.reset(new struct IEAdd); - break; - case SBIG('CNST'): - m_elem.reset(new struct IEConstant); - break; - case SBIG('IMPL'): - m_elem.reset(new struct IEImpulse); - break; - case SBIG('ILPT'): - m_elem.reset(new struct IELifetimePercent); - break; - case SBIG('IRND'): - m_elem.reset(new struct IEInitialRandom); - break; - case SBIG('PULS'): - m_elem.reset(new struct IEPulse); - break; - case SBIG('MULT'): - m_elem.reset(new struct IEMultiply); - break; - case SBIG('SPAH'): - m_elem.reset(new struct IESampleAndHold); - break; - case SBIG('RAND'): - m_elem.reset(new struct IERandom); - break; - case SBIG('TSCL'): - m_elem.reset(new struct IETimeScale); - break; - case SBIG('GTCP'): - m_elem.reset(new struct IEGTCP); - break; - case SBIG('MODU'): - m_elem.reset(new struct IEModulo); - break; - case SBIG('SUB_'): - m_elem.reset(new struct IESubtract); - break; - default: - m_elem.reset(); - return; - } - if (auto rec = r.enterSubRecord(elem.first.c_str())) - m_elem->read(r); -} - -template <> -void IntElementFactory::Enumerate(typename WriteYaml::StreamT& w) { - if (m_elem) - if (auto rec = w.enterSubRecord(m_elem->ClassID())) - m_elem->write(w); -} - -template <> -void IntElementFactory::Enumerate(typename BinarySize::StreamT& s) { - s += 4; - if (m_elem) - m_elem->binarySize(s); -} - -template <> -void IntElementFactory::Enumerate(typename Read::StreamT& r) { - DNAFourCC clsId; - clsId.read(r); - switch (clsId.toUint32()) { - case SBIG('KEYE'): - case SBIG('KEYP'): - m_elem.reset(new struct IEKeyframeEmitter); - break; - case SBIG('DETH'): - m_elem.reset(new struct IEDeath); - break; - case SBIG('CLMP'): - m_elem.reset(new struct IEClamp); - break; - case SBIG('CHAN'): - m_elem.reset(new struct IETimeChain); - break; - case SBIG('ADD_'): - m_elem.reset(new struct IEAdd); - break; - case SBIG('CNST'): - m_elem.reset(new struct IEConstant); - break; - case SBIG('IMPL'): - m_elem.reset(new struct IEImpulse); - break; - case SBIG('ILPT'): - m_elem.reset(new struct IELifetimePercent); - break; - case SBIG('IRND'): - m_elem.reset(new struct IEInitialRandom); - break; - case SBIG('PULS'): - m_elem.reset(new struct IEPulse); - break; - case SBIG('MULT'): - m_elem.reset(new struct IEMultiply); - break; - case SBIG('SPAH'): - m_elem.reset(new struct IESampleAndHold); - break; - case SBIG('RAND'): - m_elem.reset(new struct IERandom); - break; - case SBIG('TSCL'): - m_elem.reset(new struct IETimeScale); - break; - case SBIG('GTCP'): - m_elem.reset(new struct IEGTCP); - break; - case SBIG('MODU'): - m_elem.reset(new struct IEModulo); - break; - case SBIG('SUB_'): - m_elem.reset(new struct IESubtract); - break; - case SBIG('NONE'): - m_elem.reset(); - return; - default: - m_elem.reset(); - LogModule.report(logvisor::Fatal, fmt("Unknown IntElement class {} @{}"), clsId, r.position()); - return; - } - m_elem->read(r); -} - -template <> -void IntElementFactory::Enumerate(typename Write::StreamT& w) { - if (m_elem) { - w.writeBytes((atInt8*)m_elem->ClassID().data(), 4); - m_elem->write(w); - } else - w.writeBytes((atInt8*)"NONE", 4); -} - -template <> -void VectorElementFactory::Enumerate(typename ReadYaml::StreamT& r) { - const auto& mapChildren = r.getCurNode()->m_mapChildren; - if (mapChildren.empty()) { - m_elem.reset(); - return; - } - - const auto& elem = mapChildren[0]; - if (elem.first.size() < 4) - LogModule.report(logvisor::Fatal, fmt("short FourCC in element '{}'"), elem.first); - - switch (*reinterpret_cast(elem.first.data())) { - case SBIG('CONE'): - m_elem.reset(new struct VECone); - break; - case SBIG('CHAN'): - m_elem.reset(new struct VETimeChain); - break; - case SBIG('ANGC'): - m_elem.reset(new struct VEAngleCone); - break; - case SBIG('ADD_'): - m_elem.reset(new struct VEAdd); - break; - case SBIG('CCLU'): - m_elem.reset(new struct VECircleCluster); - break; - case SBIG('CNST'): - m_elem.reset(new struct VEConstant); - break; - case SBIG('CIRC'): - m_elem.reset(new struct VECircle); - break; - case SBIG('KEYE'): - case SBIG('KEYP'): - m_elem.reset(new struct VEKeyframeEmitter); - break; - case SBIG('MULT'): - m_elem.reset(new struct VEMultiply); - break; - case SBIG('RTOV'): - m_elem.reset(new struct VERealToVector); - break; - case SBIG('PULS'): - m_elem.reset(new struct VEPulse); - break; - case SBIG('PVEL'): - m_elem.reset(new struct VEParticleVelocity); - break; - case SBIG('SPOS'): - m_elem.reset(new struct VESPOS); - break; - case SBIG('PLCO'): - m_elem.reset(new struct VEPLCO); - break; - case SBIG('PLOC'): - m_elem.reset(new struct VEPLOC); - break; - case SBIG('PSOR'): - m_elem.reset(new struct VEPSOR); - break; - case SBIG('PSOF'): - m_elem.reset(new struct VEPSOF); - break; - default: - m_elem.reset(); - return; - } - if (auto rec = r.enterSubRecord(elem.first.c_str())) - m_elem->read(r); -} - -template <> -void VectorElementFactory::Enumerate(typename WriteYaml::StreamT& w) { - if (m_elem) - if (auto rec = w.enterSubRecord(m_elem->ClassID())) - m_elem->write(w); -} - -template <> -void VectorElementFactory::Enumerate(typename BinarySize::StreamT& s) { - s += 4; - if (m_elem) - m_elem->binarySize(s); -} - -template <> -void VectorElementFactory::Enumerate(typename Read::StreamT& r) { - DNAFourCC clsId; - clsId.read(r); - switch (clsId.toUint32()) { - case SBIG('CONE'): - m_elem.reset(new struct VECone); - break; - case SBIG('CHAN'): - m_elem.reset(new struct VETimeChain); - break; - case SBIG('ANGC'): - m_elem.reset(new struct VEAngleCone); - break; - case SBIG('ADD_'): - m_elem.reset(new struct VEAdd); - break; - case SBIG('CCLU'): - m_elem.reset(new struct VECircleCluster); - break; - case SBIG('CNST'): - m_elem.reset(new struct VEConstant); - break; - case SBIG('CIRC'): - m_elem.reset(new struct VECircle); - break; - case SBIG('KEYE'): - case SBIG('KEYP'): - m_elem.reset(new struct VEKeyframeEmitter); - break; - case SBIG('MULT'): - m_elem.reset(new struct VEMultiply); - break; - case SBIG('RTOV'): - m_elem.reset(new struct VERealToVector); - break; - case SBIG('PULS'): - m_elem.reset(new struct VEPulse); - break; - case SBIG('PVEL'): - m_elem.reset(new struct VEParticleVelocity); - break; - case SBIG('SPOS'): - m_elem.reset(new struct VESPOS); - break; - case SBIG('PLCO'): - m_elem.reset(new struct VEPLCO); - break; - case SBIG('PLOC'): - m_elem.reset(new struct VEPLOC); - break; - case SBIG('PSOR'): - m_elem.reset(new struct VEPSOR); - break; - case SBIG('PSOF'): - m_elem.reset(new struct VEPSOF); - break; - case SBIG('NONE'): - m_elem.reset(); - return; - default: - m_elem.reset(); - LogModule.report(logvisor::Fatal, fmt("Unknown VectorElement class {} @{}"), clsId, r.position()); - return; - } - m_elem->read(r); -} - -template <> -void VectorElementFactory::Enumerate(typename Write::StreamT& w) { - if (m_elem) { - w.writeBytes((atInt8*)m_elem->ClassID().data(), 4); - m_elem->write(w); - } else - w.writeBytes((atInt8*)"NONE", 4); -} - -template <> -void ColorElementFactory::Enumerate(typename ReadYaml::StreamT& r) { - const auto& mapChildren = r.getCurNode()->m_mapChildren; - if (mapChildren.empty()) { - m_elem.reset(); - return; - } - - const auto& elem = mapChildren[0]; - if (elem.first.size() < 4) - LogModule.report(logvisor::Fatal, fmt("short FourCC in element '{}'"), elem.first); - - switch (*reinterpret_cast(elem.first.data())) { - case SBIG('KEYE'): - case SBIG('KEYP'): - m_elem.reset(new struct CEKeyframeEmitter); - break; - case SBIG('CNST'): - m_elem.reset(new struct CEConstant); - break; - case SBIG('CHAN'): - m_elem.reset(new struct CETimeChain); - break; - case SBIG('CFDE'): - m_elem.reset(new struct CEFadeEnd); - break; - case SBIG('FADE'): - m_elem.reset(new struct CEFade); - break; - case SBIG('PULS'): - m_elem.reset(new struct CEPulse); - break; - default: - m_elem.reset(); - return; - } - if (auto rec = r.enterSubRecord(elem.first.c_str())) - m_elem->read(r); -} - -template <> -void ColorElementFactory::Enumerate(typename WriteYaml::StreamT& w) { - if (m_elem) - if (auto rec = w.enterSubRecord(m_elem->ClassID())) - m_elem->write(w); -} - -template <> -void ColorElementFactory::Enumerate(typename BinarySize::StreamT& s) { - s += 4; - if (m_elem) - m_elem->binarySize(s); -} - -template <> -void ColorElementFactory::Enumerate(typename Read::StreamT& r) { - DNAFourCC clsId; - clsId.read(r); - switch (clsId.toUint32()) { - case SBIG('KEYE'): - case SBIG('KEYP'): - m_elem.reset(new struct CEKeyframeEmitter); - break; - case SBIG('CNST'): - m_elem.reset(new struct CEConstant); - break; - case SBIG('CHAN'): - m_elem.reset(new struct CETimeChain); - break; - case SBIG('CFDE'): - m_elem.reset(new struct CEFadeEnd); - break; - case SBIG('FADE'): - m_elem.reset(new struct CEFade); - break; - case SBIG('PULS'): - m_elem.reset(new struct CEPulse); - break; - case SBIG('NONE'): - m_elem.reset(); - return; - default: - m_elem.reset(); - LogModule.report(logvisor::Fatal, fmt("Unknown ColorElement class {} @{}"), clsId, r.position()); - return; - } - m_elem->read(r); -} - -template <> -void ColorElementFactory::Enumerate(typename Write::StreamT& w) { - if (m_elem) { - w.writeBytes((atInt8*)m_elem->ClassID().data(), 4); - m_elem->write(w); - } else - w.writeBytes((atInt8*)"NONE", 4); -} - -template <> -void ModVectorElementFactory::Enumerate(typename ReadYaml::StreamT& r) { - const auto& mapChildren = r.getCurNode()->m_mapChildren; - if (mapChildren.empty()) { - m_elem.reset(); - return; - } - - const auto& elem = mapChildren[0]; - if (elem.first.size() < 4) - LogModule.report(logvisor::Fatal, fmt("short FourCC in element '{}'"), elem.first); - - switch (*reinterpret_cast(elem.first.data())) { - case SBIG('IMPL'): - m_elem.reset(new struct MVEImplosion); - break; - case SBIG('EMPL'): - m_elem.reset(new struct MVEExponentialImplosion); - break; - case SBIG('CHAN'): - m_elem.reset(new struct MVETimeChain); - break; - case SBIG('BNCE'): - m_elem.reset(new struct MVEBounce); - break; - case SBIG('CNST'): - m_elem.reset(new struct MVEConstant); - break; - case SBIG('GRAV'): - m_elem.reset(new struct MVEGravity); - break; - case SBIG('EXPL'): - m_elem.reset(new struct MVEExplode); - break; - case SBIG('SPOS'): - m_elem.reset(new struct MVESetPosition); - break; - case SBIG('LMPL'): - m_elem.reset(new struct MVELinearImplosion); - break; - case SBIG('PULS'): - m_elem.reset(new struct MVEPulse); - break; - case SBIG('WIND'): - m_elem.reset(new struct MVEWind); - break; - case SBIG('SWRL'): - m_elem.reset(new struct MVESwirl); - break; - default: - m_elem.reset(); - return; - } - if (auto rec = r.enterSubRecord(elem.first.c_str())) - m_elem->read(r); -} - -template <> -void ModVectorElementFactory::Enumerate(typename WriteYaml::StreamT& w) { - if (m_elem) - if (auto rec = w.enterSubRecord(m_elem->ClassID())) - m_elem->write(w); -} - -template <> -void ModVectorElementFactory::Enumerate(typename BinarySize::StreamT& s) { - s += 4; - if (m_elem) - m_elem->binarySize(s); -} - -template <> -void ModVectorElementFactory::Enumerate(typename Read::StreamT& r) { - DNAFourCC clsId; - clsId.read(r); - switch (clsId.toUint32()) { - case SBIG('IMPL'): - m_elem.reset(new struct MVEImplosion); - break; - case SBIG('EMPL'): - m_elem.reset(new struct MVEExponentialImplosion); - break; - case SBIG('CHAN'): - m_elem.reset(new struct MVETimeChain); - break; - case SBIG('BNCE'): - m_elem.reset(new struct MVEBounce); - break; - case SBIG('CNST'): - m_elem.reset(new struct MVEConstant); - break; - case SBIG('GRAV'): - m_elem.reset(new struct MVEGravity); - break; - case SBIG('EXPL'): - m_elem.reset(new struct MVEExplode); - break; - case SBIG('SPOS'): - m_elem.reset(new struct MVESetPosition); - break; - case SBIG('LMPL'): - m_elem.reset(new struct MVELinearImplosion); - break; - case SBIG('PULS'): - m_elem.reset(new struct MVEPulse); - break; - case SBIG('WIND'): - m_elem.reset(new struct MVEWind); - break; - case SBIG('SWRL'): - m_elem.reset(new struct MVESwirl); - break; - case SBIG('NONE'): - m_elem.reset(); - return; - default: - m_elem.reset(); - LogModule.report(logvisor::Fatal, fmt("Unknown ModVectorElement class {} @{}"), clsId, r.position()); - return; - } - m_elem->read(r); -} - -template <> -void ModVectorElementFactory::Enumerate(typename Write::StreamT& w) { - if (m_elem) { - w.writeBytes((atInt8*)m_elem->ClassID().data(), 4); - m_elem->write(w); - } else - w.writeBytes((atInt8*)"NONE", 4); -} - -template <> -void EmitterElementFactory::Enumerate(typename ReadYaml::StreamT& r) { - const auto& mapChildren = r.getCurNode()->m_mapChildren; - if (mapChildren.empty()) { - m_elem.reset(); - return; - } - - const auto& elem = mapChildren[0]; - if (elem.first.size() < 4) - LogModule.report(logvisor::Fatal, fmt("short FourCC in element '{}'"), elem.first); - - switch (*reinterpret_cast(elem.first.data())) { - case SBIG('SETR'): - m_elem.reset(new struct EESimpleEmitterTR); - break; - case SBIG('SEMR'): - m_elem.reset(new struct EESimpleEmitter); - break; - case SBIG('SPHE'): - m_elem.reset(new struct VESphere); - break; - case SBIG('ASPH'): - m_elem.reset(new struct VEAngleSphere); - break; - default: - m_elem.reset(); - return; - } - if (auto rec = r.enterSubRecord(elem.first.c_str())) - m_elem->read(r); -} - -template <> -void EmitterElementFactory::Enumerate(typename WriteYaml::StreamT& w) { - if (m_elem) - if (auto rec = w.enterSubRecord(m_elem->ClassID())) - m_elem->write(w); -} - -template <> -void EmitterElementFactory::Enumerate(typename BinarySize::StreamT& s) { - s += 4; - if (m_elem) - m_elem->binarySize(s); -} - -template <> -void EmitterElementFactory::Enumerate(typename Read::StreamT& r) { - DNAFourCC clsId; - clsId.read(r); - switch (clsId.toUint32()) { - case SBIG('SETR'): - m_elem.reset(new struct EESimpleEmitterTR); - break; - case SBIG('SEMR'): - m_elem.reset(new struct EESimpleEmitter); - break; - case SBIG('SPHE'): - m_elem.reset(new struct VESphere); - break; - case SBIG('ASPH'): - m_elem.reset(new struct VEAngleSphere); - break; - case SBIG('NONE'): - m_elem.reset(); - return; - default: - m_elem.reset(); - LogModule.report(logvisor::Fatal, fmt("Unknown EmitterElement class {} @{}"), clsId, r.position()); - return; - } - m_elem->read(r); -} - -template <> -void EmitterElementFactory::Enumerate(typename Write::StreamT& w) { - if (m_elem) { - w.writeBytes((atInt8*)m_elem->ClassID().data(), 4); - m_elem->write(w); - } else - w.writeBytes((atInt8*)"NONE", 4); -} - template <> void BoolHelper::Enumerate(typename ReadYaml::StreamT& r) { value = r.readBool(); @@ -1073,14 +189,20 @@ void BoolHelper::Enumerate(typename Read::StreamT& r) { } template <> void BoolHelper::Enumerate(typename Write::StreamT& w) { - w.writeBytes((atInt8*)"CNST", 4); + w.writeBytes("CNST", 4); w.writeBool(value); } +template struct ValueHelper; +template struct ValueHelper; + +AT_SUBSPECIALIZE_DNA_YAML(ValueHelper) +AT_SUBSPECIALIZE_DNA_YAML(ValueHelper) + template <> void EESimpleEmitterTR::Enumerate(typename ReadYaml::StreamT& r) { - position.m_elem.reset(); - velocity.m_elem.reset(); + position.reset(); + velocity.reset(); if (auto rec = r.enterSubRecord("ILOC")) position.read(r); if (auto rec = r.enterSubRecord("IVEC")) @@ -1101,8 +223,8 @@ void EESimpleEmitterTR::Enumerate(typename BinarySize::Strea } template <> void EESimpleEmitterTR::Enumerate(typename Read::StreamT& r) { - position.m_elem.reset(); - velocity.m_elem.reset(); + position.reset(); + velocity.reset(); uint32_t clsId; r.readBytesToBuf(&clsId, 4); if (clsId == SBIG('ILOC')) { @@ -1114,9 +236,9 @@ void EESimpleEmitterTR::Enumerate(typename Read::StreamT& r) { } template <> void EESimpleEmitterTR::Enumerate(typename Write::StreamT& w) { - w.writeBytes((atInt8*)"ILOC", 4); + w.writeBytes("ILOC", 4); position.write(w); - w.writeBytes((atInt8*)"IVEC", 4); + w.writeBytes("IVEC", 4); velocity.write(w); } @@ -1155,7 +277,7 @@ void UVEConstant::_read(typename Read::StreamT& r) { } template void UVEConstant::_write(typename Write::StreamT& w) const { - w.writeBytes((atInt8*)"CNST", 4); + w.writeBytes("CNST", 4); tex.write(w); } @@ -1236,14 +358,14 @@ void UVEAnimTexture::_read(typename Read::StreamT& r) { } template void UVEAnimTexture::_write(typename Write::StreamT& w) const { - w.writeBytes((atInt8*)"CNST", 4); + w.writeBytes("CNST", 4); tex.write(w); tileW.write(w); tileH.write(w); strideW.write(w); strideH.write(w); cycleFrames.write(w); - w.writeBytes((atInt8*)"CNST", 4); + w.writeBytes("CNST", 4); w.writeBool(loop); } @@ -1262,61 +384,6 @@ std::string_view UVElementFactory::DNAType() { return "UVElementFactory"sv; } -template -void UVElementFactory::_read(typename Read::StreamT& r) { - uint32_t clsId; - r.readBytesToBuf(&clsId, 4); - switch (clsId) { - case SBIG('CNST'): - m_elem.reset(new struct UVEConstant); - break; - case SBIG('ATEX'): - m_elem.reset(new struct UVEAnimTexture); - break; - default: - m_elem.reset(); - return; - } - m_elem->read(r); -} -template -void UVElementFactory::_write(typename Write::StreamT& w) const { - if (m_elem) { - w.writeBytes((atInt8*)m_elem->ClassID().data(), 4); - m_elem->write(w); - } else - w.writeBytes((atInt8*)"NONE", 4); -} -template -void UVElementFactory::_read(typename ReadYaml::StreamT& r) { - if (auto rec = r.enterSubRecord("CNST")) { - m_elem.reset(new struct UVEConstant); - m_elem->read(r); - } else if (auto rec = r.enterSubRecord("ATEX")) { - m_elem.reset(new struct UVEAnimTexture); - m_elem->read(r); - } else - m_elem.reset(); -} -template -void UVElementFactory::_write(typename WriteYaml::StreamT& w) const { - if (m_elem) - if (auto rec = w.enterSubRecord(m_elem->ClassID())) - m_elem->write(w); -} -template -void UVElementFactory::_binarySize(typename BinarySize::StreamT& _s) const { - if (m_elem) - m_elem->binarySize(_s); - _s += 4; -} - -AT_SUBSPECIALIZE_DNA_YAML(UVElementFactory) -AT_SUBSPECIALIZE_DNA_YAML(UVElementFactory) - -template struct UVElementFactory; -template struct UVElementFactory; - template <> std::string_view SpawnSystemKeyframeData::SpawnSystemKeyframeInfo::DNAType() { return "SpawnSystemKeyframeData::SpawnSystemKeyframeInfo"sv; @@ -1439,10 +506,10 @@ void SpawnSystemKeyframeData::_read(typename Read::StreamT& r) { template void SpawnSystemKeyframeData::_write(typename Write::StreamT& w) const { if (spawns.empty()) { - w.writeBytes((atInt8*)"NONE", 4); + w.writeBytes("NONE", 4); return; } - w.writeBytes((atInt8*)"CNST", 4); + w.writeBytes("CNST", 4); w.writeUint32Big(a); w.writeUint32Big(b); w.writeUint32Big(endFrame); @@ -1504,10 +571,10 @@ void ChildResourceFactory::_read(typename Read::StreamT& r) { template void ChildResourceFactory::_write(typename Write::StreamT& w) const { if (id.isValid()) { - w.writeBytes((atInt8*)"CNST", 4); + w.writeBytes("CNST", 4); id.write(w); } else - w.writeBytes((atInt8*)"NONE", 4); + w.writeBytes("NONE", 4); } AT_SUBSPECIALIZE_DNA_YAML(ChildResourceFactory) diff --git a/DataSpec/DNACommon/ParticleCommon.hpp b/DataSpec/DNACommon/ParticleCommon.hpp index 803a02f41..159cc85fd 100644 --- a/DataSpec/DNACommon/ParticleCommon.hpp +++ b/DataSpec/DNACommon/ParticleCommon.hpp @@ -10,6 +10,257 @@ namespace DataSpec::DNAParticle { extern logvisor::Module LogModule; +enum class ParticleType { + GPSM = SBIG('GPSM'), + SWSH = SBIG('SWSH'), + ELSM = SBIG('ELSM'), + DPSM = SBIG('DPSM'), + CRSM = SBIG('CRSM'), + WPSM = SBIG('WPSM') +}; + +/* + * The particle property (PP) metaclass system provides common compile-time utilities + * for storing, enumerating, and streaming particle scripts. + */ + +template +struct PPImpl : BigDNA, _Basis { + AT_DECL_EXPLICIT_DNA_YAML + + template + static constexpr bool _shouldStore(T& p, bool defaultBool) { + if constexpr (std::is_same_v) { + return p != defaultBool; + } else if constexpr (std::is_same_v) { + return p != 0xffffffff; + } else if constexpr (std::is_same_v) { + return true; + } else { + return p.operator bool(); + } + } + + constexpr void _read(athena::io::IStreamReader& r) { + constexpr FourCC RefType = uint32_t(_Basis::Type); + DNAFourCC clsId(r); + if (clsId != RefType) { + LogModule.report(logvisor::Warning, fmt("non {} provided to {} parser"), RefType, RefType); + return; + } + clsId.read(r); + while (clsId != SBIG('_END')) { + if (!_Basis::Lookup(clsId, [&](auto& p) { + using Tp = std::decay_t; + if constexpr (std::is_same_v) { + DNAFourCC tp(r); + if (tp == SBIG('CNST')) + p = r.readBool(); + } else if constexpr (std::is_same_v) { + DNAFourCC tp(r); + if (tp == SBIG('CNST')) + p = r.readUint32Big(); + } else if constexpr (std::is_same_v) { + DNAFourCC tp(r); + if (tp == SBIG('CNST')) + p = r.readFloatBig(); + } else { + p.read(r); + } + })) { + LogModule.report(logvisor::Fatal, fmt("Unknown {} class {} @{}"), RefType, clsId, r.position()); + } + clsId.read(r); + } + } + + constexpr void _write(athena::io::IStreamWriter& w) { + constexpr DNAFourCC RefType = uint32_t(_Basis::Type); + RefType.write(w); + _Basis::Enumerate([&](FourCC fcc, auto& p, bool defaultBool = false) { + if (_shouldStore(p, defaultBool)) { + using Tp = std::decay_t; + DNAFourCC(fcc).write(w); + if constexpr (std::is_same_v) { + w.writeBytes("CNST", 4); + w.writeBool(p); + } else if constexpr (std::is_same_v) { + w.writeBytes("CNST", 4); + w.writeUint32Big(p); + } else if constexpr (std::is_same_v) { + w.writeBytes("CNST", 4); + w.writeFloatBig(p); + } else { + p.write(w); + } + } + }); + w.writeBytes("_END", 4); + } + + constexpr void _binarySize(std::size_t& s) { + constexpr DNAFourCC RefType = uint32_t(_Basis::Type); + RefType.binarySize(s); + _Basis::Enumerate([&](FourCC fcc, auto& p, bool defaultBool = false) { + if (_shouldStore(p, defaultBool)) { + using Tp = std::decay_t; + DNAFourCC(fcc).binarySize(s); + if constexpr (std::is_same_v) { + s += 5; + } else if constexpr (std::is_same_v || std::is_same_v) { + s += 8; + } else { + p.binarySize(s); + } + } + }); + s += 4; + } + + void _read(athena::io::YAMLDocReader& r) { + constexpr DNAFourCC RefType = uint32_t(_Basis::Type); + + for (const auto& [key, value] : r.getCurNode()->m_mapChildren) { + if (key == "DNAType"sv) + continue; + if (key.size() < 4) { + LogModule.report(logvisor::Warning, fmt("short FourCC in element '{}'"), key); + continue; + } + + if (auto rec = r.enterSubRecord(key)) { + const DNAFourCC clsId = key.c_str(); + if (!_Basis::Lookup(clsId, [&](auto& p) { + using Tp = std::decay_t; + if constexpr (std::is_same_v) { + p = r.readBool(); + } else if constexpr (std::is_same_v) { + p = r.readUint32(); + } else if constexpr (std::is_same_v) { + p = r.readFloat(); + } else { + p.read(r); + } + })) { + LogModule.report(logvisor::Fatal, fmt("Unknown {} class {}"), RefType, clsId); + } + } + } + } + + constexpr void _write(athena::io::YAMLDocWriter& w) { + _Basis::Enumerate([&](FourCC fcc, auto& p, bool defaultBool = false) { + if (_shouldStore(p, defaultBool)) { + using Tp = std::decay_t; + if (auto rec = w.enterSubRecord(fcc.toStringView())) { + if constexpr (std::is_same_v) { + w.writeBool(p); + } else if constexpr (std::is_same_v) { + w.writeUint32(p); + } else if constexpr (std::is_same_v) { + w.writeFloat(p); + } else { + p.write(w); + } + } + } + }); + } + + constexpr void gatherDependencies(std::vector& deps) { + _Basis::Enumerate([&](FourCC fcc, auto& p, bool defaultBool = false) { + using Tp = std::decay_t; + if constexpr (!std::is_same_v && !std::is_same_v && !std::is_same_v) + p.gatherDependencies(deps); + }); + } + + constexpr void gatherDependencies(std::vector& deps) const { + const_cast(*this).gatherDependencies(deps); + } +}; + +template +struct PEType { + using Type = _Type; +}; + +template +struct PEImpl : BigDNA { + AT_DECL_EXPLICIT_DNA_YAML + using _PtrType = typename _Basis::PtrType; + + void _read(athena::io::IStreamReader& r) { + DNAFourCC clsId(r); + if (clsId == FOURCC('NONE')) { + m_elem.reset(); + return; + } + if (!_Basis::Lookup(clsId, [&](auto&& p) { + using Tp = std::decay_t; + m_elem = std::make_unique(); + m_elem->read(r); + })) { + LogModule.report(logvisor::Fatal, fmt("Unknown {} class {} @{}"), _PtrType::TypeName, clsId, r.position()); + } + } + + void _write(athena::io::IStreamWriter& w) { + if (m_elem) { + w.writeBytes(m_elem->ClassID().data(), 4); + m_elem->write(w); + } else { + w.writeBytes("NONE", 4); + } + } + + void _binarySize(std::size_t& s) { + if (m_elem) + m_elem->binarySize(s); + s += 4; + } + + void _read(athena::io::YAMLDocReader& r) { + const auto& mapChildren = r.getCurNode()->m_mapChildren; + if (mapChildren.empty()) { + m_elem.reset(); + return; + } + + const auto& [key, value] = mapChildren[0]; + if (key.size() < 4) + LogModule.report(logvisor::Fatal, fmt("short FourCC in element '{}'"), key); + + if (auto rec = r.enterSubRecord(key)) { + const DNAFourCC clsId = key.c_str(); + if (!_Basis::Lookup(clsId, [&](auto&& p) { + using Tp = std::decay_t; + m_elem = std::make_unique(); + m_elem->read(r); + })) { + LogModule.report(logvisor::Fatal, fmt("Unknown {} class {}"), _PtrType::TypeName, clsId); + } + } + } + + void _write(athena::io::YAMLDocWriter& w) { + if (m_elem) + if (auto rec = w.enterSubRecord(m_elem->ClassID())) + m_elem->write(w); + } + + void gatherDependencies(std::vector& deps) const { + _Basis::gatherDependencies(deps, m_elem); + } + + operator bool() const { return m_elem.operator bool(); } + auto* get() const { return m_elem.get(); } + auto* operator->() const { return get(); } + void reset() { m_elem.reset(); } +private: + std::unique_ptr<_PtrType> m_elem; +}; + struct IElement : BigDNAVYaml { Delete _d; ~IElement() override = default; @@ -19,61 +270,296 @@ struct IElement : BigDNAVYaml { struct IRealElement : IElement { Delete _d2; + static constexpr std::string_view TypeName = "RealElement"sv; }; -struct RealElementFactory : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - std::unique_ptr m_elem; - operator bool() const { return m_elem.operator bool(); } +struct RELifetimeTween; +struct REConstant; +struct RETimeChain; +struct REAdd; +struct REClamp; +struct REKeyframeEmitter; +struct REKeyframeEmitter; +struct REInitialRandom; +struct RERandom; +struct REMultiply; +struct REPulse; +struct RETimeScale; +struct RELifetimePercent; +struct RESineWave; +struct REInitialSwitch; +struct RECompareLessThan; +struct RECompareEquals; +struct REParticleAdvanceParam1; +struct REParticleAdvanceParam2; +struct REParticleAdvanceParam3; +struct REParticleAdvanceParam4; +struct REParticleAdvanceParam5; +struct REParticleAdvanceParam6; +struct REParticleAdvanceParam7; +struct REParticleAdvanceParam8; +struct REParticleSizeOrLineLength; +struct REParticleRotationOrLineWidth; +struct RESubtract; +struct REVectorMagnitude; +struct REVectorXToReal; +struct REVectorYToReal; +struct REVectorZToReal; +struct RECEXT; +struct REIntTimesReal; +struct _RealElementFactory { + using PtrType = IRealElement; + template + static bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { + case SBIG('LFTW'): f(PEType{}); return true; + case SBIG('CNST'): f(PEType{}); return true; + case SBIG('CHAN'): f(PEType{}); return true; + case SBIG('ADD_'): f(PEType{}); return true; + case SBIG('CLMP'): f(PEType{}); return true; + case SBIG('KEYE'): f(PEType{}); return true; + case SBIG('KEYP'): f(PEType{}); return true; + case SBIG('IRND'): f(PEType{}); return true; + case SBIG('RAND'): f(PEType{}); return true; + case SBIG('MULT'): f(PEType{}); return true; + case SBIG('PULS'): f(PEType{}); return true; + case SBIG('SCAL'): f(PEType{}); return true; + case SBIG('RLPT'): f(PEType{}); return true; + case SBIG('SINE'): f(PEType{}); return true; + case SBIG('ISWT'): f(PEType{}); return true; + case SBIG('CLTN'): f(PEType{}); return true; + case SBIG('CEQL'): f(PEType{}); return true; + case SBIG('PAP1'): f(PEType{}); return true; + case SBIG('PAP2'): f(PEType{}); return true; + case SBIG('PAP3'): f(PEType{}); return true; + case SBIG('PAP4'): f(PEType{}); return true; + case SBIG('PAP5'): f(PEType{}); return true; + case SBIG('PAP6'): f(PEType{}); return true; + case SBIG('PAP7'): f(PEType{}); return true; + case SBIG('PAP8'): f(PEType{}); return true; + case SBIG('PSLL'): f(PEType{}); return true; + case SBIG('PRLW'): f(PEType{}); return true; + case SBIG('SUB_'): f(PEType{}); return true; + case SBIG('VMAG'): f(PEType{}); return true; + case SBIG('VXTR'): f(PEType{}); return true; + case SBIG('VYTR'): f(PEType{}); return true; + case SBIG('VZTR'): f(PEType{}); return true; + case SBIG('CEXT'): f(PEType{}); return true; + case SBIG('ITRL'): f(PEType{}); return true; + default: return false; + } + } + static constexpr void gatherDependencies(std::vector& pathsOut, + const std::unique_ptr& elemPtr) {} }; +using RealElementFactory = PEImpl<_RealElementFactory>; struct IIntElement : IElement { Delete _d2; + static constexpr std::string_view TypeName = "IntElement"sv; }; -struct IntElementFactory : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - std::unique_ptr m_elem; - operator bool() const { return m_elem.operator bool(); } +struct IEKeyframeEmitter; +struct IEKeyframeEmitter; +struct IEDeath; +struct IEClamp; +struct IETimeChain; +struct IEAdd; +struct IEConstant; +struct IEImpulse; +struct IELifetimePercent; +struct IEInitialRandom; +struct IEPulse; +struct IEMultiply; +struct IESampleAndHold; +struct IERandom; +struct IETimeScale; +struct IEGTCP; +struct IEModulo; +struct IESubtract; +struct _IntElementFactory { + using PtrType = IIntElement; + template + static bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { + case SBIG('KEYE'): f(PEType{}); return true; + case SBIG('KEYP'): f(PEType{}); return true; + case SBIG('DETH'): f(PEType{}); return true; + case SBIG('CLMP'): f(PEType{}); return true; + case SBIG('CHAN'): f(PEType{}); return true; + case SBIG('ADD_'): f(PEType{}); return true; + case SBIG('CNST'): f(PEType{}); return true; + case SBIG('IMPL'): f(PEType{}); return true; + case SBIG('ILPT'): f(PEType{}); return true; + case SBIG('IRND'): f(PEType{}); return true; + case SBIG('PULS'): f(PEType{}); return true; + case SBIG('MULT'): f(PEType{}); return true; + case SBIG('SPAH'): f(PEType{}); return true; + case SBIG('RAND'): f(PEType{}); return true; + case SBIG('TSCL'): f(PEType{}); return true; + case SBIG('GTCP'): f(PEType{}); return true; + case SBIG('MODU'): f(PEType{}); return true; + case SBIG('SUB_'): f(PEType{}); return true; + default: return false; + } + } + static constexpr void gatherDependencies(std::vector& pathsOut, + const std::unique_ptr& elemPtr) {} }; +using IntElementFactory = PEImpl<_IntElementFactory>; struct IVectorElement : IElement { Delete _d2; + static constexpr std::string_view TypeName = "VectorElement"sv; }; -struct VectorElementFactory : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - std::unique_ptr m_elem; - operator bool() const { return m_elem.operator bool(); } +struct VECone; +struct VETimeChain; +struct VEAngleCone; +struct VEAdd; +struct VECircleCluster; +struct VEConstant; +struct VECircle; +struct VEKeyframeEmitter; +struct VEKeyframeEmitter; +struct VEMultiply; +struct VERealToVector; +struct VEPulse; +struct VEParticleVelocity; +struct VESPOS; +struct VEPLCO; +struct VEPLOC; +struct VEPSOR; +struct VEPSOF; +struct _VectorElementFactory { + using PtrType = IVectorElement; + template + static bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { + case SBIG('CONE'): f(PEType{}); return true; + case SBIG('CHAN'): f(PEType{}); return true; + case SBIG('ANGC'): f(PEType{}); return true; + case SBIG('ADD_'): f(PEType{}); return true; + case SBIG('CCLU'): f(PEType{}); return true; + case SBIG('CNST'): f(PEType{}); return true; + case SBIG('CIRC'): f(PEType{}); return true; + case SBIG('KEYE'): f(PEType{}); return true; + case SBIG('KEYP'): f(PEType{}); return true; + case SBIG('MULT'): f(PEType{}); return true; + case SBIG('RTOV'): f(PEType{}); return true; + case SBIG('PULS'): f(PEType{}); return true; + case SBIG('PVEL'): f(PEType{}); return true; + case SBIG('SPOS'): f(PEType{}); return true; + case SBIG('PLCO'): f(PEType{}); return true; + case SBIG('PLOC'): f(PEType{}); return true; + case SBIG('PSOR'): f(PEType{}); return true; + case SBIG('PSOF'): f(PEType{}); return true; + default: return false; + } + } + static constexpr void gatherDependencies(std::vector& pathsOut, + const std::unique_ptr& elemPtr) {} }; +using VectorElementFactory = PEImpl<_VectorElementFactory>; struct IColorElement : IElement { Delete _d2; + static constexpr std::string_view TypeName = "ColorElement"sv; }; -struct ColorElementFactory : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - std::unique_ptr m_elem; - operator bool() const { return m_elem.operator bool(); } +struct CEKeyframeEmitter; +struct CEKeyframeEmitter; +struct CEConstant; +struct CETimeChain; +struct CEFadeEnd; +struct CEFade; +struct CEPulse; +struct _ColorElementFactory { + using PtrType = IColorElement; + template + static bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { + case SBIG('KEYE'): f(PEType{}); return true; + case SBIG('KEYP'): f(PEType{}); return true; + case SBIG('CNST'): f(PEType{}); return true; + case SBIG('CHAN'): f(PEType{}); return true; + case SBIG('CFDE'): f(PEType{}); return true; + case SBIG('FADE'): f(PEType{}); return true; + case SBIG('PULS'): f(PEType{}); return true; + default: return false; + } + } + static constexpr void gatherDependencies(std::vector& pathsOut, + const std::unique_ptr& elemPtr) {} }; +using ColorElementFactory = PEImpl<_ColorElementFactory>; struct IModVectorElement : IElement { Delete _d2; + static constexpr std::string_view TypeName = "ModVectorElement"sv; }; -struct ModVectorElementFactory : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - std::unique_ptr m_elem; - operator bool() const { return m_elem.operator bool(); } +struct MVEImplosion; +struct MVEExponentialImplosion; +struct MVETimeChain; +struct MVEBounce; +struct MVEConstant; +struct MVEGravity; +struct MVEExplode; +struct MVESetPosition; +struct MVELinearImplosion; +struct MVEPulse; +struct MVEWind; +struct MVESwirl; +struct _ModVectorElementFactory { + using PtrType = IModVectorElement; + template + static bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { + case SBIG('IMPL'): f(PEType{}); return true; + case SBIG('EMPL'): f(PEType{}); return true; + case SBIG('CHAN'): f(PEType{}); return true; + case SBIG('BNCE'): f(PEType{}); return true; + case SBIG('CNST'): f(PEType{}); return true; + case SBIG('GRAV'): f(PEType{}); return true; + case SBIG('EXPL'): f(PEType{}); return true; + case SBIG('SPOS'): f(PEType{}); return true; + case SBIG('LMPL'): f(PEType{}); return true; + case SBIG('PULS'): f(PEType{}); return true; + case SBIG('WIND'): f(PEType{}); return true; + case SBIG('SWRL'): f(PEType{}); return true; + default: return false; + } + } + static constexpr void gatherDependencies(std::vector& pathsOut, + const std::unique_ptr& elemPtr) {} }; +using ModVectorElementFactory = PEImpl<_ModVectorElementFactory>; struct IEmitterElement : IElement { Delete _d2; + static constexpr std::string_view TypeName = "EmitterElement"sv; }; -struct EmitterElementFactory : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - std::unique_ptr m_elem; - operator bool() const { return m_elem.operator bool(); } +struct EESimpleEmitterTR; +struct EESimpleEmitter; +struct VESphere; +struct VEAngleSphere; +struct _EmitterElementFactory { + using PtrType = IEmitterElement; + template + static bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { + case SBIG('SETR'): f(PEType{}); return true; + case SBIG('SEMR'): f(PEType{}); return true; + case SBIG('SPHE'): f(PEType{}); return true; + case SBIG('ASPH'): f(PEType{}); return true; + default: return false; + } + } + static constexpr void gatherDependencies(std::vector& pathsOut, + const std::unique_ptr& elemPtr) {} }; +using EmitterElementFactory = PEImpl<_EmitterElementFactory>; struct IUVElement : IElement { Delete _d2; virtual void gatherDependencies(std::vector& pathsOut) const = 0; + static constexpr std::string_view TypeName = "UVElement"sv; }; struct BoolHelper : IElement { @@ -87,6 +573,46 @@ struct BoolHelper : IElement { std::string_view ClassID() const override { return "BoolHelper"sv; } }; +template +struct ValueHelper : BigDNA { + AT_DECL_EXPLICIT_DNA_YAML + + void _read(athena::io::IStreamReader& r) { + hecl::DNAFourCC ValueType; + ValueType.read(r); + if (ValueType == FOURCC('CNST')) + athena::io::Read::Do({}, value.emplace(), r); + else + value = std::nullopt; + } + void _write(athena::io::IStreamWriter& w) { + if (value) { + w.writeBytes("CNST", 4); + athena::io::Write::Do({}, *value, w); + } else { + w.writeBytes("NONE", 4); + } + } + void _binarySize(std::size_t& s) { + s += 4; + if (value) + athena::io::BinarySize::Do({}, *value, s); + } + void _read(athena::io::YAMLDocReader& r) { + athena::io::ReadYaml::Do({}, value.emplace(), r); + } + void _write(athena::io::YAMLDocWriter& w) { + athena::io::WriteYaml::Do({}, *value, w); + } + + static constexpr void gatherDependencies(std::vector& pathsOut) {} + + std::optional value = {}; + void emplace(Tp val) { value.emplace(val); } + Tp operator*() const { return *value; } + operator bool() const { return value.operator bool(); } +}; + struct RELifetimeTween : IRealElement { AT_DECL_DNA_YAMLV_NO_TYPE RealElementFactory a; @@ -743,7 +1269,8 @@ struct UVEConstant : IUVElement { std::string_view ClassID() const override { return "CNST"sv; } void gatherDependencies(std::vector& pathsOut) const override { - g_curSpec->flattenDependencies(tex, pathsOut); + if (tex.isValid()) + g_curSpec->flattenDependencies(tex, pathsOut); } }; @@ -761,18 +1288,30 @@ struct UVEAnimTexture : IUVElement { std::string_view ClassID() const override { return "ATEX"sv; } void gatherDependencies(std::vector& pathsOut) const override { - g_curSpec->flattenDependencies(tex, pathsOut); + if (tex.isValid()) + g_curSpec->flattenDependencies(tex, pathsOut); } }; template -struct UVElementFactory : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - AT_SUBDECL_DNA - DNAFourCC m_type; - std::unique_ptr m_elem; - operator bool() const { return m_elem.operator bool(); } +struct _UVElementFactory { + using PtrType = IUVElement; + template + static bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { + case SBIG('CNST'): f(PEType>{}); return true; + case SBIG('ATEX'): f(PEType>{}); return true; + default: return false; + } + } + static constexpr void gatherDependencies(std::vector& pathsOut, + const std::unique_ptr& elemPtr) { + if (elemPtr) + elemPtr->gatherDependencies(pathsOut); + } }; +template +using UVElementFactory = PEImpl<_UVElementFactory>; template struct SpawnSystemKeyframeData : BigDNA { @@ -809,6 +1348,10 @@ struct ChildResourceFactory : BigDNA { AT_DECL_EXPLICIT_DNA_YAML AT_SUBDECL_DNA operator bool() const { return id.isValid(); } + void gatherDependencies(std::vector& pathsOut) const { + if (id.isValid()) + g_curSpec->flattenDependencies(id, pathsOut); + } }; } // namespace DataSpec::DNAParticle diff --git a/DataSpec/DNACommon/SWHC.cpp b/DataSpec/DNACommon/SWHC.cpp index 3ff2b8ebd..404de21af 100644 --- a/DataSpec/DNACommon/SWHC.cpp +++ b/DataSpec/DNACommon/SWHC.cpp @@ -1,11 +1,14 @@ #include "DataSpec/DNACommon/SWHC.hpp" - #include "DataSpec/DNACommon/PAK.hpp" -#include - namespace DataSpec::DNAParticle { +template struct PPImpl<_SWSH>; +template struct PPImpl<_SWSH>; + +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_SWSH>) +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_SWSH>) + template <> std::string_view SWSH::DNAType() { return "SWSH"sv; @@ -16,504 +19,6 @@ std::string_view SWSH::DNAType() { return "SWSH"sv; } -template -void SWSH::_read(typename BigDNA::ReadYaml::StreamT& r) { - for (const auto& elem : r.getCurNode()->m_mapChildren) { - if (elem.first.size() < 4) { - LogModule.report(logvisor::Warning, fmt("short FourCC in element '{}'"), elem.first); - continue; - } - - if (auto rec = r.enterSubRecord(elem.first.c_str())) { - switch (*reinterpret_cast(elem.first.data())) { - case SBIG('PSLT'): - x0_PSLT.read(r); - break; - case SBIG('TIME'): - x4_TIME.read(r); - break; - case SBIG('LRAD'): - x8_LRAD.read(r); - break; - case SBIG('RRAD'): - xc_RRAD.read(r); - break; - case SBIG('LENG'): - x10_LENG.read(r); - break; - case SBIG('COLR'): - x14_COLR.read(r); - break; - case SBIG('SIDE'): - x18_SIDE.read(r); - break; - case SBIG('IROT'): - x1c_IROT.read(r); - break; - case SBIG('ROTM'): - x20_ROTM.read(r); - break; - case SBIG('POFS'): - x24_POFS.read(r); - break; - case SBIG('IVEL'): - x28_IVEL.read(r); - break; - case SBIG('NPOS'): - x2c_NPOS.read(r); - break; - case SBIG('VELM'): - x30_VELM.read(r); - break; - case SBIG('VLM2'): - x34_VLM2.read(r); - break; - case SBIG('SPLN'): - x38_SPLN.read(r); - break; - case SBIG('TEXR'): - x3c_TEXR.read(r); - break; - case SBIG('TSPN'): - x40_TSPN.read(r); - break; - case SBIG('LLRD'): - x44_24_LLRD = r.readBool(); - break; - case SBIG('CROS'): - x44_25_CROS = r.readBool(); - break; - case SBIG('VLS1'): - x44_26_VLS1 = r.readBool(); - break; - case SBIG('VLS2'): - x44_27_VLS2 = r.readBool(); - break; - case SBIG('SROT'): - x44_28_SROT = r.readBool(); - break; - case SBIG('WIRE'): - x44_29_WIRE = r.readBool(); - break; - case SBIG('TEXW'): - x44_30_TEXW = r.readBool(); - break; - case SBIG('AALP'): - x44_31_AALP = r.readBool(); - break; - case SBIG('ZBUF'): - x45_24_ZBUF = r.readBool(); - break; - case SBIG('ORNT'): - x45_25_ORNT = r.readBool(); - break; - case SBIG('CRND'): - x45_26_CRND = r.readBool(); - break; - default: - break; - } - } - } -} - -template -void SWSH::_write(typename BigDNA::WriteYaml::StreamT& w) const { - if (x0_PSLT) - if (auto rec = w.enterSubRecord("PSLT")) - x0_PSLT.write(w); - if (x4_TIME) - if (auto rec = w.enterSubRecord("TIME")) - x4_TIME.write(w); - if (x8_LRAD) - if (auto rec = w.enterSubRecord("LRAD")) - x8_LRAD.write(w); - if (xc_RRAD) - if (auto rec = w.enterSubRecord("RRAD")) - xc_RRAD.write(w); - if (x10_LENG) - if (auto rec = w.enterSubRecord("LENG")) - x10_LENG.write(w); - if (x14_COLR) - if (auto rec = w.enterSubRecord("COLR")) - x14_COLR.write(w); - if (x18_SIDE) - if (auto rec = w.enterSubRecord("SIDE")) - x18_SIDE.write(w); - if (x1c_IROT) - if (auto rec = w.enterSubRecord("IROT")) - x1c_IROT.write(w); - if (x20_ROTM) - if (auto rec = w.enterSubRecord("ROTM")) - x20_ROTM.write(w); - if (x24_POFS) - if (auto rec = w.enterSubRecord("POFS")) - x24_POFS.write(w); - if (x28_IVEL) - if (auto rec = w.enterSubRecord("IVEL")) - x28_IVEL.write(w); - if (x2c_NPOS) - if (auto rec = w.enterSubRecord("NPOS")) - x2c_NPOS.write(w); - if (x30_VELM) - if (auto rec = w.enterSubRecord("VELM")) - x30_VELM.write(w); - if (x34_VLM2) - if (auto rec = w.enterSubRecord("VLM2")) - x34_VLM2.write(w); - if (x38_SPLN) - if (auto rec = w.enterSubRecord("SPLN")) - x38_SPLN.write(w); - if (x3c_TEXR) - if (auto rec = w.enterSubRecord("TEXR")) - x3c_TEXR.write(w); - if (x40_TSPN) - if (auto rec = w.enterSubRecord("TSPN")) - x40_TSPN.write(w); - - if (x44_24_LLRD) - w.writeBool("LLRD", true); - if (!x44_25_CROS) - w.writeBool("CROS", false); - if (x44_26_VLS1) - w.writeBool("VLS1", true); - if (x44_27_VLS2) - w.writeBool("VLS2", true); - if (x44_28_SROT) - w.writeBool("SROT", true); - if (x44_29_WIRE) - w.writeBool("WIRE", true); - if (x44_30_TEXW) - w.writeBool("TEXW", true); - if (x44_31_AALP) - w.writeBool("AALP", true); - if (x45_24_ZBUF) - w.writeBool("ZBUF", true); - if (x45_25_ORNT) - w.writeBool("ORNT", true); - if (x45_26_CRND) - w.writeBool("CRND", true); -} - -template -void SWSH::_binarySize(typename BigDNA::BinarySize::StreamT& s) const { - s += 4; - if (x0_PSLT) { - s += 4; - x0_PSLT.binarySize(s); - } - if (x4_TIME) { - s += 4; - x4_TIME.binarySize(s); - } - if (x8_LRAD) { - s += 4; - x8_LRAD.binarySize(s); - } - if (xc_RRAD) { - s += 4; - xc_RRAD.binarySize(s); - } - if (x10_LENG) { - s += 4; - x10_LENG.binarySize(s); - } - if (x14_COLR) { - s += 4; - x14_COLR.binarySize(s); - } - if (x18_SIDE) { - s += 4; - x18_SIDE.binarySize(s); - } - if (x1c_IROT) { - s += 4; - x1c_IROT.binarySize(s); - } - if (x20_ROTM) { - s += 4; - x20_ROTM.binarySize(s); - } - if (x24_POFS) { - s += 4; - x24_POFS.binarySize(s); - } - if (x28_IVEL) { - s += 4; - x28_IVEL.binarySize(s); - } - if (x2c_NPOS) { - s += 4; - x2c_NPOS.binarySize(s); - } - if (x30_VELM) { - s += 4; - x30_VELM.binarySize(s); - } - if (x34_VLM2) { - s += 4; - x34_VLM2.binarySize(s); - } - if (x38_SPLN) { - s += 4; - x38_SPLN.binarySize(s); - } - if (x3c_TEXR) { - s += 4; - x3c_TEXR.binarySize(s); - } - if (x40_TSPN) { - s += 4; - x40_TSPN.binarySize(s); - } - if (x44_24_LLRD) - s += 9; - if (!x44_25_CROS) - s += 9; - if (x44_26_VLS1) - s += 9; - if (x44_27_VLS2) - s += 9; - if (x44_28_SROT) - s += 9; - if (x44_29_WIRE) - s += 9; - if (x44_30_TEXW) - s += 9; - if (x44_31_AALP) - s += 9; - if (x45_24_ZBUF) - s += 9; - if (x45_25_ORNT) - s += 9; - if (x45_26_CRND) - s += 9; -} - -template -void SWSH::_read(typename BigDNA::Read::StreamT& r) { - DNAFourCC clsId; - clsId.read(r); - if (clsId != SBIG('SWSH')) { - LogModule.report(logvisor::Warning, fmt("non SWSH provided to SWSH parser")); - return; - } - - clsId.read(r); - while (clsId != SBIG('_END')) { - switch (clsId.toUint32()) { - case SBIG('PSLT'): - x0_PSLT.read(r); - break; - case SBIG('TIME'): - x4_TIME.read(r); - break; - case SBIG('LRAD'): - x8_LRAD.read(r); - break; - case SBIG('RRAD'): - xc_RRAD.read(r); - break; - case SBIG('LENG'): - x10_LENG.read(r); - break; - case SBIG('COLR'): - x14_COLR.read(r); - break; - case SBIG('SIDE'): - x18_SIDE.read(r); - break; - case SBIG('IROT'): - x1c_IROT.read(r); - break; - case SBIG('ROTM'): - x20_ROTM.read(r); - break; - case SBIG('POFS'): - x24_POFS.read(r); - break; - case SBIG('IVEL'): - x28_IVEL.read(r); - break; - case SBIG('NPOS'): - x2c_NPOS.read(r); - break; - case SBIG('VELM'): - x30_VELM.read(r); - break; - case SBIG('VLM2'): - x34_VLM2.read(r); - break; - case SBIG('SPLN'): - x38_SPLN.read(r); - break; - case SBIG('TEXR'): - x3c_TEXR.read(r); - break; - case SBIG('TSPN'): - x40_TSPN.read(r); - break; - case SBIG('LLRD'): - r.readUint32Big(); - x44_24_LLRD = r.readBool(); - break; - case SBIG('CROS'): - r.readUint32Big(); - x44_25_CROS = r.readBool(); - break; - case SBIG('VLS1'): - r.readUint32Big(); - x44_26_VLS1 = r.readBool(); - break; - case SBIG('VLS2'): - r.readUint32Big(); - x44_27_VLS2 = r.readBool(); - break; - case SBIG('SROT'): - r.readUint32Big(); - x44_28_SROT = r.readBool(); - break; - case SBIG('WIRE'): - r.readUint32Big(); - x44_29_WIRE = r.readBool(); - break; - case SBIG('TEXW'): - r.readUint32Big(); - x44_30_TEXW = r.readBool(); - break; - case SBIG('AALP'): - r.readUint32Big(); - x44_31_AALP = r.readBool(); - break; - case SBIG('ZBUF'): - r.readUint32Big(); - x45_24_ZBUF = r.readBool(); - break; - case SBIG('ORNT'): - r.readUint32Big(); - x45_25_ORNT = r.readBool(); - break; - case SBIG('CRND'): - r.readUint32Big(); - x45_26_CRND = r.readBool(); - break; - default: - LogModule.report(logvisor::Fatal, fmt("Unknown SWSH class {} @{}"), clsId, r.position()); - break; - } - clsId.read(r); - } -} - -template -void SWSH::_write(typename BigDNA::Write::StreamT& w) const { - w.writeBytes((atInt8*)"SWSH", 4); - if (x0_PSLT) { - w.writeBytes((atInt8*)"PSLT", 4); - x0_PSLT.write(w); - } - if (x4_TIME) { - w.writeBytes((atInt8*)"TIME", 4); - x4_TIME.write(w); - } - if (x8_LRAD) { - w.writeBytes((atInt8*)"LRAD", 4); - x8_LRAD.write(w); - } - if (xc_RRAD) { - w.writeBytes((atInt8*)"RRAD", 4); - xc_RRAD.write(w); - } - if (x10_LENG) { - w.writeBytes((atInt8*)"LENG", 4); - x10_LENG.write(w); - } - if (x14_COLR) { - w.writeBytes((atInt8*)"COLR", 4); - x14_COLR.write(w); - } - if (x18_SIDE) { - w.writeBytes((atInt8*)"SIDE", 4); - x18_SIDE.write(w); - } - if (x1c_IROT) { - w.writeBytes((atInt8*)"IROT", 4); - x1c_IROT.write(w); - } - if (x20_ROTM) { - w.writeBytes((atInt8*)"ROTM", 4); - x20_ROTM.write(w); - } - if (x24_POFS) { - w.writeBytes((atInt8*)"POFS", 4); - x24_POFS.write(w); - } - if (x28_IVEL) { - w.writeBytes((atInt8*)"IVEL", 4); - x28_IVEL.write(w); - } - if (x2c_NPOS) { - w.writeBytes((atInt8*)"NPOS", 4); - x2c_NPOS.write(w); - } - if (x30_VELM) { - w.writeBytes((atInt8*)"VELM", 4); - x30_VELM.write(w); - } - if (x34_VLM2) { - w.writeBytes((atInt8*)"VLM2", 4); - x34_VLM2.write(w); - } - if (x38_SPLN) { - w.writeBytes((atInt8*)"SPLN", 4); - x38_SPLN.write(w); - } - if (x3c_TEXR) { - w.writeBytes((atInt8*)"TEXR", 4); - x3c_TEXR.write(w); - } - if (x40_TSPN) { - w.writeBytes((atInt8*)"TSPN", 4); - x40_TSPN.write(w); - } - - if (x44_24_LLRD) - w.writeBytes("LLRDCNST\x01", 9); - if (!x44_25_CROS) - w.writeBytes("CROSCNST\x00", 9); - if (x44_26_VLS1) - w.writeBytes("VLS1CNST\x01", 9); - if (x44_27_VLS2) - w.writeBytes("VLS2CNST\x01", 9); - if (x44_28_SROT) - w.writeBytes("SROTCNST\x01", 9); - if (x44_29_WIRE) - w.writeBytes("WIRECNST\x01", 9); - if (x44_30_TEXW) - w.writeBytes("TEXWCNST\x01", 9); - if (x44_31_AALP) - w.writeBytes("AALPCNST\x01", 9); - if (x45_24_ZBUF) - w.writeBytes("ZBUFCNST\x01", 9); - if (x45_25_ORNT) - w.writeBytes("ORNTCNST\x01", 9); - if (x45_26_CRND) - w.writeBytes("CRNDCNST\x01", 9); - w.writeBytes("_END", 4); -} - -AT_SUBSPECIALIZE_DNA_YAML(SWSH) -AT_SUBSPECIALIZE_DNA_YAML(SWSH) - -template -void SWSH::gatherDependencies(std::vector& pathsOut) const { - if (x3c_TEXR.m_elem) - x3c_TEXR.m_elem->gatherDependencies(pathsOut); -} - -template struct SWSH; -template struct SWSH; - template bool ExtractSWSH(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) { athena::io::FileWriter writer(outPath.getAbsolutePath()); diff --git a/DataSpec/DNACommon/SWHC.def b/DataSpec/DNACommon/SWHC.def new file mode 100644 index 000000000..675d8b5ec --- /dev/null +++ b/DataSpec/DNACommon/SWHC.def @@ -0,0 +1,69 @@ +#ifndef ENTRY +#define ENTRY(name, identifier) +#endif + +#ifndef INT_ENTRY +#define INT_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef REAL_ENTRY +#define REAL_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef VECTOR_ENTRY +#define VECTOR_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef MOD_VECTOR_ENTRY +#define MOD_VECTOR_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef COLOR_ENTRY +#define COLOR_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef UV_ENTRY +#define UV_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef BOOL_ENTRY +#define BOOL_ENTRY(name, identifier, def) ENTRY(name, identifier) +#endif + +INT_ENTRY('PSLT', x0_PSLT) +REAL_ENTRY('TIME', x4_TIME) +REAL_ENTRY('LRAD', x8_LRAD) +REAL_ENTRY('RRAD', xc_RRAD) +INT_ENTRY('LENG', x10_LENG) +COLOR_ENTRY('COLR', x14_COLR) +INT_ENTRY('SIDE', x18_SIDE) +REAL_ENTRY('IROT', x1c_IROT) +REAL_ENTRY('ROTM', x20_ROTM) +VECTOR_ENTRY('POFS', x24_POFS) +VECTOR_ENTRY('IVEL', x28_IVEL) +VECTOR_ENTRY('NPOS', x2c_NPOS) +MOD_VECTOR_ENTRY('VELM', x30_VELM) +MOD_VECTOR_ENTRY('VLM2', x34_VLM2) +INT_ENTRY('SPLN', x38_SPLN) +UV_ENTRY('TEXR', x3c_TEXR) +INT_ENTRY('TSPN', x40_TSPN) +BOOL_ENTRY('LLRD', x44_24_LLRD, false) +BOOL_ENTRY('CROS', x44_25_CROS, true) +BOOL_ENTRY('VLS1', x44_26_VLS1, false) +BOOL_ENTRY('VLS2', x44_27_VLS2, false) +BOOL_ENTRY('SROT', x44_28_SROT, false) +BOOL_ENTRY('WIRE', x44_29_WIRE, false) +BOOL_ENTRY('TEXW', x44_30_TEXW, false) +BOOL_ENTRY('AALP', x44_31_AALP, false) +BOOL_ENTRY('ZBUF', x45_24_ZBUF, false) +BOOL_ENTRY('ORNT', x45_25_ORNT, false) +BOOL_ENTRY('CRND', x45_26_CRND, false) + +#undef ENTRY +#undef INT_ENTRY +#undef REAL_ENTRY +#undef VECTOR_ENTRY +#undef MOD_VECTOR_ENTRY +#undef COLOR_ENTRY +#undef UV_ENTRY +#undef BOOL_ENTRY diff --git a/DataSpec/DNACommon/SWHC.hpp b/DataSpec/DNACommon/SWHC.hpp index 3c81344c0..269828ed2 100644 --- a/DataSpec/DNACommon/SWHC.hpp +++ b/DataSpec/DNACommon/SWHC.hpp @@ -16,48 +16,36 @@ class ProjectPath; namespace DataSpec::DNAParticle { template -struct SWSH : public BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - AT_SUBDECL_DNA +struct _SWSH { + static constexpr ParticleType Type = ParticleType::SWSH; - IntElementFactory x0_PSLT; - RealElementFactory x4_TIME; - RealElementFactory x8_LRAD; - RealElementFactory xc_RRAD; - IntElementFactory x10_LENG; - ColorElementFactory x14_COLR; - IntElementFactory x18_SIDE; - RealElementFactory x1c_IROT; - RealElementFactory x20_ROTM; - VectorElementFactory x24_POFS; - VectorElementFactory x28_IVEL; - VectorElementFactory x2c_NPOS; - ModVectorElementFactory x30_VELM; - ModVectorElementFactory x34_VLM2; - IntElementFactory x38_SPLN; - UVElementFactory x3c_TEXR; - IntElementFactory x40_TSPN; - union { - struct { - bool x44_24_LLRD : 1; - bool x44_25_CROS : 1; - bool x44_26_VLS1 : 1; - bool x44_27_VLS2 : 1; - bool x44_28_SROT : 1; - bool x44_29_WIRE : 1; - bool x44_30_TEXW : 1; - bool x44_31_AALP : 1; - bool x45_24_ZBUF : 1; - bool x45_25_ORNT : 1; - bool x45_26_CRND : 1; - }; - uint16_t dummy = 0; - }; +#define INT_ENTRY(name, identifier) IntElementFactory identifier; +#define REAL_ENTRY(name, identifier) RealElementFactory identifier; +#define VECTOR_ENTRY(name, identifier) VectorElementFactory identifier; +#define MOD_VECTOR_ENTRY(name, identifier) ModVectorElementFactory identifier; +#define COLOR_ENTRY(name, identifier) ColorElementFactory identifier; +#define UV_ENTRY(name, identifier) UVElementFactory identifier; +#define BOOL_ENTRY(name, identifier, def) bool identifier = def; +#include "SWHC.def" - SWSH() { x44_25_CROS = true; } + template + void constexpr Enumerate(_Func f) { +#define ENTRY(name, identifier) f(FOURCC(name), identifier); +#define BOOL_ENTRY(name, identifier, def) f(FOURCC(name), identifier, def); +#include "SWHC.def" + } - void gatherDependencies(std::vector&) const; + template + bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { +#define ENTRY(name, identifier) case SBIG(name): f(identifier); return true; +#include "SWHC.def" + default: return false; + } + } }; +template +using SWSH = PPImpl<_SWSH>; template bool ExtractSWSH(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath); diff --git a/DataSpec/DNACommon/TXTR.cpp b/DataSpec/DNACommon/TXTR.cpp index 0923baaa1..413b6f0ba 100644 --- a/DataSpec/DNACommon/TXTR.cpp +++ b/DataSpec/DNACommon/TXTR.cpp @@ -17,9 +17,11 @@ static logvisor::Module Log("libpng"); static int CountBits(uint32_t n) { int ret = 0; - for (int i = 0; i < 32; ++i) - if (((n >> i) & 1) != 0) + for (int i = 0; i < 32; ++i) { + if (((n >> i) & 1) != 0) { ++ret; + } + } return ret; } @@ -28,27 +30,29 @@ static void BoxFilter(const uint8_t* input, unsigned chanCount, unsigned inWidth bool dxt1) { unsigned mipWidth = 1; unsigned mipHeight = 1; - if (inWidth > 1) + if (inWidth > 1) { mipWidth = inWidth / 2; - if (inHeight > 1) + } + if (inHeight > 1) { mipHeight = inHeight / 2; + } - unsigned y, x, c; - for (y = 0; y < mipHeight; ++y) { - unsigned miplineBase = mipWidth * y; - unsigned in1LineBase = inWidth * (y * 2); - unsigned in2LineBase = inWidth * (y * 2 + 1); - for (x = 0; x < mipWidth; ++x) { + for (unsigned y = 0; y < mipHeight; ++y) { + const unsigned miplineBase = mipWidth * y; + const unsigned in1LineBase = inWidth * (y * 2); + const unsigned in2LineBase = inWidth * (y * 2 + 1); + for (unsigned x = 0; x < mipWidth; ++x) { uint8_t* out = &output[(miplineBase + x) * chanCount]; - for (c = 0; c < chanCount; ++c) { + for (unsigned c = 0; c < chanCount; ++c) { uint32_t tmp = 0; tmp += input[(in1LineBase + (x * 2)) * chanCount + c]; tmp += input[(in1LineBase + (x * 2 + 1)) * chanCount + c]; tmp += input[(in2LineBase + (x * 2)) * chanCount + c]; tmp += input[(in2LineBase + (x * 2 + 1)) * chanCount + c]; out[c] = uint8_t(tmp / 4); - if (c == 3 && dxt1) + if (c == 3 && dxt1) { out[c] = uint8_t(out[c] ? 0xff : 0x0); + } } } } @@ -65,52 +69,52 @@ static size_t ComputeMippedTexelCount(unsigned inWidth, unsigned inHeight) { } /* GX uses this upsampling technique to extract full 8-bit range */ -constexpr uint8_t Convert3To8(uint8_t v) { +static constexpr uint8_t Convert3To8(uint8_t v) { /* Swizzle bits: 00000123 -> 12312312 */ return (v << 5) | (v << 2) | (v >> 1); } -constexpr uint8_t Convert8To3(uint8_t v) { return v >> 5; } +static constexpr uint8_t Convert8To3(uint8_t v) { return v >> 5; } -constexpr uint8_t Convert4To8(uint8_t v) { +static constexpr uint8_t Convert4To8(uint8_t v) { /* Swizzle bits: 00001234 -> 12341234 */ return (v << 4) | v; } -constexpr uint8_t Convert8To4(uint8_t v) { return v >> 4; } +static constexpr uint8_t Convert8To4(uint8_t v) { return v >> 4; } -constexpr uint8_t Convert5To8(uint8_t v) { +static constexpr uint8_t Convert5To8(uint8_t v) { /* Swizzle bits: 00012345 -> 12345123 */ return (v << 3) | (v >> 2); } -constexpr uint8_t Convert8To5(uint8_t v) { return v >> 3; } +static constexpr uint8_t Convert8To5(uint8_t v) { return v >> 3; } -constexpr uint8_t Convert6To8(uint8_t v) { +static constexpr uint8_t Convert6To8(uint8_t v) { /* Swizzle bits: 00123456 -> 12345612 */ return (v << 2) | (v >> 4); } -constexpr uint8_t Convert8To6(uint8_t v) { return v >> 2; } +static constexpr uint8_t Convert8To6(uint8_t v) { return v >> 2; } static uint8_t Lookup4BPP(const uint8_t* texels, int width, int x, int y) { - int bwidth = (width + 7) / 8; - int bx = x / 8; - int by = y / 8; - int rx = x % 8; - int ry = y % 8; - int bidx = by * bwidth + bx; + const int bwidth = (width + 7) / 8; + const int bx = x / 8; + const int by = y / 8; + const int rx = x % 8; + const int ry = y % 8; + const int bidx = by * bwidth + bx; const uint8_t* btexels = &texels[32 * bidx]; return btexels[ry * 4 + rx / 2] >> ((rx & 1) ? 0 : 4) & 0xf; } static void Set4BPP(uint8_t* texels, int width, int x, int y, uint8_t val) { - int bwidth = (width + 7) / 8; - int bx = x / 8; - int by = y / 8; - int rx = x % 8; - int ry = y % 8; - int bidx = by * bwidth + bx; + const int bwidth = (width + 7) / 8; + const int bx = x / 8; + const int by = y / 8; + const int rx = x % 8; + const int ry = y % 8; + const int bidx = by * bwidth + bx; uint8_t* btexels = &texels[32 * bidx]; btexels[ry * 4 + rx / 2] |= (val & 0xf) << ((rx & 1) ? 0 : 4); } @@ -127,68 +131,68 @@ static uint8_t Lookup8BPP(const uint8_t* texels, int width, int x, int y) { } static void Set8BPP(uint8_t* texels, int width, int x, int y, uint8_t val) { - int bwidth = (width + 7) / 8; - int bx = x / 8; - int by = y / 4; - int rx = x % 8; - int ry = y % 4; - int bidx = by * bwidth + bx; + const int bwidth = (width + 7) / 8; + const int bx = x / 8; + const int by = y / 4; + const int rx = x % 8; + const int ry = y % 4; + const int bidx = by * bwidth + bx; uint8_t* btexels = &texels[32 * bidx]; btexels[ry * 8 + rx] = val; } static uint16_t Lookup16BPP(const uint8_t* texels, int width, int x, int y) { - int bwidth = (width + 3) / 4; - int bx = x / 4; - int by = y / 4; - int rx = x % 4; - int ry = y % 4; + const int bwidth = (width + 3) / 4; + const int bx = x / 4; + const int by = y / 4; + const int rx = x % 4; + const int ry = y % 4; int bidx = by * bwidth + bx; - const uint16_t* btexels = (uint16_t*)&texels[32 * bidx]; + const uint16_t* btexels = reinterpret_cast(&texels[32 * bidx]); return btexels[ry * 4 + rx]; } static void Set16BPP(uint8_t* texels, int width, int x, int y, uint16_t val) { - int bwidth = (width + 3) / 4; - int bx = x / 4; - int by = y / 4; - int rx = x % 4; - int ry = y % 4; - int bidx = by * bwidth + bx; - uint16_t* btexels = (uint16_t*)&texels[32 * bidx]; + const int bwidth = (width + 3) / 4; + const int bx = x / 4; + const int by = y / 4; + const int rx = x % 4; + const int ry = y % 4; + const int bidx = by * bwidth + bx; + auto* btexels = reinterpret_cast(&texels[32 * bidx]); btexels[ry * 4 + rx] = val; } static void LookupRGBA8(const uint8_t* texels, int width, int x, int y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) { - int bwidth = (width + 3) / 4; - int bx = x / 4; - int by = y / 4; - int rx = x % 4; - int ry = y % 4; - int bidx = (by * bwidth + bx) * 2; - const uint16_t* artexels = (uint16_t*)&texels[32 * bidx]; - const uint16_t* gbtexels = (uint16_t*)&texels[32 * (bidx + 1)]; - uint16_t ar = hecl::SBig(artexels[ry * 4 + rx]); + const int bwidth = (width + 3) / 4; + const int bx = x / 4; + const int by = y / 4; + const int rx = x % 4; + const int ry = y % 4; + const int bidx = (by * bwidth + bx) * 2; + const auto* artexels = reinterpret_cast(&texels[32 * bidx]); + const auto* gbtexels = reinterpret_cast(&texels[32 * (bidx + 1)]); + const uint16_t ar = hecl::SBig(artexels[ry * 4 + rx]); *a = ar >> 8 & 0xff; *r = ar & 0xff; - uint16_t gb = hecl::SBig(gbtexels[ry * 4 + rx]); + const uint16_t gb = hecl::SBig(gbtexels[ry * 4 + rx]); *g = gb >> 8 & 0xff; *b = gb & 0xff; } static void SetRGBA8(uint8_t* texels, int width, int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { - int bwidth = (width + 3) / 4; - int bx = x / 4; - int by = y / 4; - int rx = x % 4; - int ry = y % 4; - int bidx = (by * bwidth + bx) * 2; - uint16_t* artexels = (uint16_t*)&texels[32 * bidx]; - uint16_t* gbtexels = (uint16_t*)&texels[32 * (bidx + 1)]; - uint16_t ar = (a << 8) | r; + const int bwidth = (width + 3) / 4; + const int bx = x / 4; + const int by = y / 4; + const int rx = x % 4; + const int ry = y % 4; + const int bidx = (by * bwidth + bx) * 2; + uint16_t* artexels = reinterpret_cast(&texels[32 * bidx]); + uint16_t* gbtexels = reinterpret_cast(&texels[32 * (bidx + 1)]); + const uint16_t ar = (a << 8) | r; artexels[ry * 4 + rx] = hecl::SBig(ar); - uint16_t gb = (g << 8) | b; + const uint16_t gb = (g << 8) | b; gbtexels[ry * 4 + rx] = hecl::SBig(gb); } @@ -199,8 +203,9 @@ static void DecodeI4(png_structp png, png_infop info, const uint8_t* texels, int std::unique_ptr buf(new uint8_t[width]); // memset(buf.get(), 0, width); for (int y = height - 1; y >= 0; --y) { - for (int x = 0; x < width; ++x) + for (int x = 0; x < width; ++x) { buf[x] = Convert4To8(Lookup4BPP(texels, width, x, y)); + } png_write_row(png, buf.get()); } } @@ -223,16 +228,18 @@ static void DecodeI8(png_structp png, png_infop info, const uint8_t* texels, int png_write_info(png, info); std::unique_ptr buf(new uint8_t[width]); for (int y = height - 1; y >= 0; --y) { - for (int x = 0; x < width; ++x) + for (int x = 0; x < width; ++x) { buf[x] = Lookup8BPP(texels, width, x, y); + } png_write_row(png, buf.get()); } } static void EncodeI8(const uint8_t* rgbaIn, uint8_t* texels, int width, int height) { for (int y = height - 1; y >= 0; --y) { - for (int x = 0; x < width; ++x) + for (int x = 0; x < width; ++x) { Set8BPP(texels, width, x, y, rgbaIn[x]); + } rgbaIn += width; } } @@ -244,7 +251,7 @@ static void DecodeIA4(png_structp png, png_infop info, const uint8_t* texels, in std::unique_ptr buf(new uint8_t[width * 2]); for (int y = height - 1; y >= 0; --y) { for (int x = 0; x < width; ++x) { - uint8_t texel = Lookup8BPP(texels, width, x, y); + const uint8_t texel = Lookup8BPP(texels, width, x, y); buf[x * 2 ] = Convert4To8(texel & 0xf); buf[x * 2 + 1] = Convert4To8(texel >> 4 & 0xf); } @@ -274,22 +281,24 @@ static void DecodeIA8(png_structp png, png_infop info, const uint8_t* texels, in png_write_info(png, info); std::unique_ptr buf(new uint16_t[width]); for (int y = height - 1; y >= 0; --y) { - for (int x = 0; x < width; ++x) + for (int x = 0; x < width; ++x) { buf[x] = hecl::SBig(Lookup16BPP(texels, width, x, y)); - png_write_row(png, (png_bytep)buf.get()); + } + png_write_row(png, reinterpret_cast(buf.get())); } } static void EncodeIA8(const uint8_t* rgbaIn, uint8_t* texels, int width, int height) { for (int y = height - 1; y >= 0; --y) { - for (int x = 0; x < width; ++x) - Set16BPP(texels, width, x, y, hecl::SBig(((uint16_t*)rgbaIn)[x])); + for (int x = 0; x < width; ++x) { + Set16BPP(texels, width, x, y, hecl::SBig(reinterpret_cast(rgbaIn)[x])); + } rgbaIn += width * 2; } } static const uint8_t* DecodePalette(png_structp png, png_infop info, int numEntries, const uint8_t* data) { - uint32_t format = hecl::SBig(*(uint32_t*)data); + const auto format = hecl::SBig(*reinterpret_cast(data)); data += 8; png_color cEntries[256]; png_byte aEntries[256]; @@ -306,9 +315,9 @@ static const uint8_t* DecodePalette(png_structp png, png_infop info, int numEntr } case 1: { /* RGB565 */ - const uint16_t* data16 = (uint16_t*)data; + const auto* data16 = reinterpret_cast(data); for (int e = 0; e < numEntries; ++e) { - uint16_t texel = hecl::SBig(data16[e]); + const uint16_t texel = hecl::SBig(data16[e]); cEntries[e].red = Convert5To8(texel >> 11 & 0x1f); cEntries[e].green = Convert6To8(texel >> 5 & 0x3f); cEntries[e].blue = Convert5To8(texel & 0x1f); @@ -317,9 +326,9 @@ static const uint8_t* DecodePalette(png_structp png, png_infop info, int numEntr } case 2: { /* RGB5A3 */ - const uint16_t* data16 = (uint16_t*)data; + const auto* data16 = reinterpret_cast(data); for (int e = 0; e < numEntries; ++e) { - uint16_t texel = hecl::SBig(data16[e]); + const uint16_t texel = hecl::SBig(data16[e]); if (texel & 0x8000) { cEntries[e].red = Convert5To8(texel >> 10 & 0x1f); cEntries[e].green = Convert5To8(texel >> 5 & 0x1f); @@ -336,8 +345,9 @@ static const uint8_t* DecodePalette(png_structp png, png_infop info, int numEntr } } png_set_PLTE(png, info, cEntries, numEntries); - if (format == 0 || format == 2) + if (format == 0 || format == 2) { png_set_tRNS(png, info, aEntries, numEntries, nullptr); + } data += numEntries * 2; return data; } @@ -360,20 +370,21 @@ static uint8_t* EncodePalette(png_structp png, png_infop info, int numEntries, u uint32_t format = 0; /* Default IA8 */ for (int e = 0; e < pngNumEntries; ++e) { - png_colorp ent = &cEntries[e]; + const png_const_colorp ent = &cEntries[e]; if (ent->red != ent->green || ent->red != ent->blue) { - if (pngNumAEntries) + if (pngNumAEntries) { format = 2; /* RGB565 if not greyscale and has alpha */ - else + } else { format = 1; /* RGB565 if not greyscale */ + } break; } } - ((uint32_t*)data)[0] = hecl::SBig(format); + reinterpret_cast(data)[0] = hecl::SBig(format); data += 4; - ((uint16_t*)data)[0] = hecl::SBig(uint16_t(numEntries)); - ((uint16_t*)data)[1] = hecl::SBig(uint16_t(1)); + reinterpret_cast(data)[0] = hecl::SBig(uint16_t(numEntries)); + reinterpret_cast(data)[1] = hecl::SBig(uint16_t(1)); data += 4; switch (format) { @@ -393,7 +404,7 @@ static uint8_t* EncodePalette(png_structp png, png_infop info, int numEntries, u } case 1: { /* RGB565 */ - uint16_t* data16 = (uint16_t*)data; + uint16_t* data16 = reinterpret_cast(data); for (int e = 0; e < numEntries; ++e) { if (e < pngNumEntries) { uint16_t texel = Convert8To5(cEntries[e].red) << 11; @@ -408,11 +419,12 @@ static uint8_t* EncodePalette(png_structp png, png_infop info, int numEntries, u } case 2: { /* RGB5A3 */ - uint16_t* data16 = (uint16_t*)data; + auto* data16 = reinterpret_cast(data); for (int e = 0; e < numEntries; ++e) { uint8_t alpha = 0; - if (e < pngNumAEntries) + if (e < pngNumAEntries) { alpha = aEntries[e]; + } uint16_t texel = 0; if (alpha == 0xff) { @@ -440,7 +452,7 @@ static uint8_t* EncodePalette(png_structp png, png_infop info, int numEntries, u } static const uint8_t* DecodePaletteSPLT(png_structp png, png_infop info, int numEntries, const uint8_t* data) { - uint32_t format = hecl::SBig(*(uint32_t*)data); + const auto format = hecl::SBig(*reinterpret_cast(data)); data += 8; png_sPLT_entry entries[256] = {}; png_sPLT_t GXEntry = {(char*)"GXPalette", 8, entries, numEntries}; @@ -459,9 +471,9 @@ static const uint8_t* DecodePaletteSPLT(png_structp png, png_infop info, int num case 1: { /* RGB565 */ GXEntry.name = (char*)"GX_RGB565"; - const uint16_t* data16 = (uint16_t*)data; + const auto* data16 = reinterpret_cast(data); for (int e = 0; e < numEntries; ++e) { - uint16_t texel = hecl::SBig(data16[e]); + const uint16_t texel = hecl::SBig(data16[e]); entries[e].red = Convert5To8(texel >> 11 & 0x1f); entries[e].green = Convert6To8(texel >> 5 & 0x3f); entries[e].blue = Convert5To8(texel & 0x1f); @@ -472,9 +484,9 @@ static const uint8_t* DecodePaletteSPLT(png_structp png, png_infop info, int num case 2: { /* RGB5A3 */ GXEntry.name = (char*)"GX_RGB5A3"; - const uint16_t* data16 = (uint16_t*)data; + const auto* data16 = reinterpret_cast(data); for (int e = 0; e < numEntries; ++e) { - uint16_t texel = hecl::SBig(data16[e]); + const uint16_t texel = hecl::SBig(data16[e]); if (texel & 0x8000) { entries[e].red = Convert5To8(texel >> 10 & 0x1f); entries[e].green = Convert5To8(texel >> 5 & 0x1f); @@ -497,12 +509,12 @@ static const uint8_t* DecodePaletteSPLT(png_structp png, png_infop info, int num static uint8_t* EncodePaletteSPLT(png_structp png, png_infop info, int numEntries, uint8_t* data) { png_sPLT_tp palettes; - int pngNumPalettes = png_get_sPLT(png, info, &palettes); + const int pngNumPalettes = png_get_sPLT(png, info, &palettes); int pngNumEntries = 0; png_sPLT_entryp cEntries = nullptr; for (int i = 0; i < pngNumPalettes; ++i) { - png_sPLT_tp palette = &palettes[i]; - if (!strncmp(palette->name, "GX_", 3)) { + const png_const_sPLT_tp palette = &palettes[i]; + if (strncmp(palette->name, "GX_", 3) == 0) { pngNumEntries = palette->nentries; cEntries = palette->entries; break; @@ -511,20 +523,21 @@ static uint8_t* EncodePaletteSPLT(png_structp png, png_infop info, int numEntrie uint32_t format = 2; /* Default RGB5A3 */ for (int e = 0; e < pngNumEntries; ++e) { - png_sPLT_entryp ent = &cEntries[e]; + const png_const_sPLT_entryp ent = &cEntries[e]; if (ent->red != ent->green || ent->red != ent->blue) { if (ent->alpha) { format = 2; break; - } else + } else { format = 1; + } } } - ((uint32_t*)data)[0] = hecl::SBig(format); + reinterpret_cast(data)[0] = hecl::SBig(format); data += 4; - ((uint16_t*)data)[0] = hecl::SBig(uint16_t(1)); - ((uint16_t*)data)[1] = hecl::SBig(uint16_t(numEntries)); + reinterpret_cast(data)[0] = hecl::SBig(uint16_t(1)); + reinterpret_cast(data)[1] = hecl::SBig(uint16_t(numEntries)); data += 4; switch (format) { @@ -543,7 +556,7 @@ static uint8_t* EncodePaletteSPLT(png_structp png, png_infop info, int numEntrie } case 1: { /* RGB565 */ - uint16_t* data16 = (uint16_t*)data; + auto* data16 = reinterpret_cast(data); for (int e = 0; e < numEntries; ++e) { if (e < pngNumEntries) { uint16_t texel = Convert8To5(cEntries[e].red) << 11; @@ -558,7 +571,7 @@ static uint8_t* EncodePaletteSPLT(png_structp png, png_infop info, int numEntrie } case 2: { /* RGB5A3 */ - uint16_t* data16 = (uint16_t*)data; + auto* data16 = reinterpret_cast(data); for (int e = 0; e < numEntries; ++e) { uint16_t texel = 0; if (cEntries && cEntries[e].alpha == 0xff) { @@ -599,8 +612,9 @@ static void DecodeC4(png_structp png, png_infop info, const uint8_t* data, int w png_write_info(png, info); std::unique_ptr buf(new uint8_t[width]); for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; ++x) + for (int x = 0; x < width; ++x) { buf[x] = Lookup4BPP(texels, width, x, y); + } png_write_row(png, buf.get()); } } @@ -608,8 +622,9 @@ static void DecodeC4(png_structp png, png_infop info, const uint8_t* data, int w static void EncodeC4(png_structp png, png_infop info, const uint8_t* rgbaIn, uint8_t* data, int width, int height) { uint8_t* texels = EncodePaletteSPLT(png, info, 16, data); for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; ++x) + for (int x = 0; x < width; ++x) { Set4BPP(texels, width, x, y, rgbaIn[x]); + } rgbaIn += width; } } @@ -621,8 +636,9 @@ static void DecodeC8(png_structp png, png_infop info, const uint8_t* data, int w png_write_info(png, info); std::unique_ptr buf(new uint8_t[width]); for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; ++x) + for (int x = 0; x < width; ++x) { buf[x] = Lookup8BPP(texels, width, x, y); + } png_write_row(png, buf.get()); } } @@ -630,8 +646,9 @@ static void DecodeC8(png_structp png, png_infop info, const uint8_t* data, int w static void EncodeC8(png_structp png, png_infop info, const uint8_t* rgbaIn, uint8_t* data, int width, int height) { uint8_t* texels = EncodePalette(png, info, 256, data); for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; ++x) + for (int x = 0; x < width; ++x) { Set8BPP(texels, width, x, y, rgbaIn[x]); + } rgbaIn += width; } } @@ -643,7 +660,7 @@ static void DecodeRGB565(png_structp png, png_infop info, const uint8_t* texels, std::unique_ptr buf(new uint8_t[width * 3]); for (int y = height - 1; y >= 0; --y) { for (int x = 0; x < width; ++x) { - uint16_t texel = hecl::SBig(Lookup16BPP(texels, width, x, y)); + const uint16_t texel = hecl::SBig(Lookup16BPP(texels, width, x, y)); buf[x * 3] = Convert5To8(texel >> 11 & 0x1f); buf[x * 3 + 1] = Convert6To8(texel >> 5 & 0x3f); buf[x * 3 + 2] = Convert5To8(texel & 0x1f); @@ -676,7 +693,7 @@ static void DecodeRGB5A3(png_structp png, png_infop info, const uint8_t* texels, std::unique_ptr buf(new uint8_t[width * 4]); for (int y = height - 1; y >= 0; --y) { for (int x = 0; x < width; ++x) { - uint16_t texel = hecl::SBig(Lookup16BPP(texels, width, x, y)); + const uint16_t texel = hecl::SBig(Lookup16BPP(texels, width, x, y)); if (texel & 0x8000) { buf[x * 4] = Convert5To8(texel >> 10 & 0x1f); buf[x * 4 + 1] = Convert5To8(texel >> 5 & 0x1f); @@ -728,16 +745,18 @@ static void DecodeRGBA8(png_structp png, png_infop info, const uint8_t* texels, png_write_info(png, info); std::unique_ptr buf(new uint8_t[width * 4]); for (int y = height - 1; y >= 0; --y) { - for (int x = 0; x < width; ++x) + for (int x = 0; x < width; ++x) { LookupRGBA8(texels, width, x, y, &buf[x * 4], &buf[x * 4 + 1], &buf[x * 4 + 2], &buf[x * 4 + 3]); + } png_write_row(png, buf.get()); } } static void EncodeRGBA8(const uint8_t* rgbaIn, uint8_t* texels, int width, int height) { for (int y = height - 1; y >= 0; --y) { - for (int x = 0; x < width; ++x) + for (int x = 0; x < width; ++x) { SetRGBA8(texels, width, x, y, rgbaIn[x * 4], rgbaIn[x * 4 + 1], rgbaIn[x * 4 + 2], rgbaIn[x * 4 + 3]); + } rgbaIn += width * 4; } } @@ -754,50 +773,55 @@ static void DecodeCMPR(png_structp png, png_infop info, const uint8_t* texels, i png_write_info(png, info); /* Decode 8 rows at a time */ - int bwidth = (width + 7) / 8; - int bpwidth = bwidth * 8; + const int bwidth = (width + 7) / 8; + const int bpwidth = bwidth * 8; std::unique_ptr buf(new uint32_t[bpwidth * 8]); uint32_t* bTargets[4] = {buf.get(), buf.get() + 4, buf.get() + 4 * width, buf.get() + 4 * width + 4}; for (int y = height / 8 - 1; y >= 0; --y) { - const DXTBlock* blks = (DXTBlock*)(texels + 32 * bwidth * y); + const auto* blks = reinterpret_cast(texels + 32 * bwidth * y); for (int x = 0; x < width; x += 8) { uint32_t blkOut[4][4][4]; - squish::Decompress((uint8_t*)blkOut[0][0], blks++, squish::kDxt1GCN); - squish::Decompress((uint8_t*)blkOut[1][0], blks++, squish::kDxt1GCN); - squish::Decompress((uint8_t*)blkOut[2][0], blks++, squish::kDxt1GCN); - squish::Decompress((uint8_t*)blkOut[3][0], blks++, squish::kDxt1GCN); + squish::Decompress(reinterpret_cast(blkOut[0][0]), blks++, squish::kDxt1GCN); + squish::Decompress(reinterpret_cast(blkOut[1][0]), blks++, squish::kDxt1GCN); + squish::Decompress(reinterpret_cast(blkOut[2][0]), blks++, squish::kDxt1GCN); + squish::Decompress(reinterpret_cast(blkOut[3][0]), blks++, squish::kDxt1GCN); - for (int bt = 0; bt < 4; ++bt) - for (int by = 0; by < 4; ++by) - memcpy(bTargets[bt] + x + width * by, blkOut[bt][by], 16); + for (int bt = 0; bt < 4; ++bt) { + for (int by = 0; by < 4; ++by) { + std::memcpy(bTargets[bt] + x + width * by, blkOut[bt][by], 16); + } + } + } + for (int r = 7; r >= 0; --r) { + png_write_row(png, reinterpret_cast(bTargets[0] + width * r)); } - for (int r = 7; r >= 0; --r) - png_write_row(png, (png_bytep)(bTargets[0] + width * r)); } } static void EncodeCMPR(const uint8_t* rgbaIn, uint8_t* texels, int width, int height) { /* Encode 8 rows at a time */ - int bwidth = (width + 7) / 8; - int bpwidth = bwidth * 8; + const int bwidth = (width + 7) / 8; + const int bpwidth = bwidth * 8; std::unique_ptr buf(new uint32_t[bpwidth * 8]); uint32_t* bTargets[4] = {buf.get(), buf.get() + 4, buf.get() + 4 * width, buf.get() + 4 * width + 4}; for (int y = height / 8 - 1; y >= 0; --y) { for (int r = 7; r >= 0; --r) { - memcpy(bTargets[0] + width * r, rgbaIn, width * 4); + std::memcpy(bTargets[0] + width * r, rgbaIn, width * 4); rgbaIn += width * 4; } - DXTBlock* blks = (DXTBlock*)(texels + 32 * bwidth * y); + auto* blks = reinterpret_cast(texels + 32 * bwidth * y); for (int x = 0; x < width; x += 8) { uint32_t blkIn[4][4][4]; - for (int bt = 0; bt < 4; ++bt) - for (int by = 0; by < 4; ++by) - memcpy(blkIn[bt][by], bTargets[bt] + x + width * by, 16); + for (int bt = 0; bt < 4; ++bt) { + for (int by = 0; by < 4; ++by) { + std::memcpy(blkIn[bt][by], bTargets[bt] + x + width * by, 16); + } + } - squish::Compress((uint8_t*)blkIn[0][0], blks++, squish::kDxt1GCN); - squish::Compress((uint8_t*)blkIn[1][0], blks++, squish::kDxt1GCN); - squish::Compress((uint8_t*)blkIn[2][0], blks++, squish::kDxt1GCN); - squish::Compress((uint8_t*)blkIn[3][0], blks++, squish::kDxt1GCN); + squish::Compress(reinterpret_cast(blkIn[0][0]), blks++, squish::kDxt1GCN); + squish::Compress(reinterpret_cast(blkIn[1][0]), blks++, squish::kDxt1GCN); + squish::Compress(reinterpret_cast(blkIn[2][0]), blks++, squish::kDxt1GCN); + squish::Compress(reinterpret_cast(blkIn[3][0]), blks++, squish::kDxt1GCN); } } } @@ -807,10 +831,10 @@ static void PNGErr(png_structp png, png_const_charp msg) { Log.report(logvisor:: static void PNGWarn(png_structp png, png_const_charp msg) { Log.report(logvisor::Warning, fmt("{}"), msg); } bool TXTR::Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) { - uint32_t format = rs.readUint32Big(); - uint16_t width = rs.readUint16Big(); - uint16_t height = rs.readUint16Big(); - uint32_t numMips = rs.readUint32Big(); + const uint32_t format = rs.readUint32Big(); + const uint16_t width = rs.readUint16Big(); + const uint16_t height = rs.readUint16Big(); + const uint32_t numMips = rs.readUint32Big(); auto fp = hecl::FopenUnique(outPath.getAbsolutePath().data(), _SYS_STR("wb")); if (fp == nullptr) { @@ -869,11 +893,11 @@ bool TXTR::Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) { static std::unique_ptr ReadPalette(png_structp png, png_infop info, size_t& szOut) { std::unique_ptr ret; png_sPLT_tp palettes; - int paletteCount = png_get_sPLT(png, info, &palettes); - if (paletteCount) { + const int paletteCount = png_get_sPLT(png, info, &palettes); + if (paletteCount != 0) { for (int i = 0; i < paletteCount; ++i) { - png_sPLT_tp palette = &palettes[i]; - if (!strncmp(palette->name, "GX_", 3)) { + const png_const_sPLT_tp palette = &palettes[i]; + if (strncmp(palette->name, "GX_", 3) == 0) { if (palette->nentries > 16) { /* This is a C8 palette */ ret.reset(new uint8_t[4 * 257]); @@ -882,7 +906,7 @@ static std::unique_ptr ReadPalette(png_structp png, png_infop info, s uint8_t* cur = ret.get() + 4; for (int j = 0; j < 256; ++j) { if (j < palette->nentries) { - png_sPLT_entryp entry = &palette->entries[j]; + const png_const_sPLT_entryp entry = &palette->entries[j]; if (palette->depth == 16) { *cur++ = entry->red >> 8; *cur++ = entry->green >> 8; @@ -909,7 +933,7 @@ static std::unique_ptr ReadPalette(png_structp png, png_infop info, s uint8_t* cur = ret.get() + 4; for (int j = 0; j < 16; ++j) { if (j < palette->nentries) { - png_sPLT_entryp entry = &palette->entries[j]; + const png_const_sPLT_entryp entry = &palette->entries[j]; if (palette->depth == 16) { *cur++ = entry->red >> 8; *cur++ = entry->green >> 8; @@ -933,9 +957,9 @@ static std::unique_ptr ReadPalette(png_structp png, png_infop info, s } } } else { - png_colorp palettes; + png_colorp palettes2; int colorCount; - if (png_get_PLTE(png, info, &palettes, &colorCount) == PNG_INFO_PLTE) { + if (png_get_PLTE(png, info, &palettes2, &colorCount) == PNG_INFO_PLTE) { if (colorCount > 16) { /* This is a C8 palette */ ret.reset(new uint8_t[4 * 257]); @@ -944,7 +968,7 @@ static std::unique_ptr ReadPalette(png_structp png, png_infop info, s uint8_t* cur = ret.get() + 4; for (int j = 0; j < 256; ++j) { if (j < colorCount) { - png_colorp entry = &palettes[j]; + const png_const_colorp entry = &palettes2[j]; *cur++ = entry->red; *cur++ = entry->green; *cur++ = entry->blue; @@ -964,7 +988,7 @@ static std::unique_ptr ReadPalette(png_structp png, png_infop info, s uint8_t* cur = ret.get() + 4; for (int j = 0; j < 16; ++j) { if (j < colorCount) { - png_colorp entry = &palettes[j]; + const png_const_colorp entry = &palettes2[j]; *cur++ = entry->red; *cur++ = entry->green; *cur++ = entry->blue; @@ -984,11 +1008,11 @@ static std::unique_ptr ReadPalette(png_structp png, png_infop info, s static int GetNumPaletteEntriesForGCN(png_structp png, png_infop info) { png_sPLT_tp palettes; - int paletteCount = png_get_sPLT(png, info, &palettes); - if (paletteCount) { + const int paletteCount = png_get_sPLT(png, info, &palettes); + if (paletteCount != 0) { for (int i = 0; i < paletteCount; ++i) { - png_sPLT_tp palette = &palettes[i]; - if (!strncmp(palette->name, "GX_", 3)) { + const png_const_sPLT_tp palette = &palettes[i]; + if (strncmp(palette->name, "GX_", 3) == 0) { if (palette->nentries > 16) { /* This is a C8 palette */ return 256; @@ -996,13 +1020,12 @@ static int GetNumPaletteEntriesForGCN(png_structp png, png_infop info) { /* This is a C4 palette */ return 16; } - break; } } } else { - png_colorp palettes; + png_colorp palletes2; int colorCount; - if (png_get_PLTE(png, info, &palettes, &colorCount) == PNG_INFO_PLTE) { + if (png_get_PLTE(png, info, &palletes2, &colorCount) == PNG_INFO_PLTE) { if (colorCount > 16) { /* This is a C8 palette */ return 256; @@ -1054,10 +1077,10 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat png_read_info(pngRead, info); - png_uint_32 width = png_get_image_width(pngRead, info); - png_uint_32 height = png_get_image_height(pngRead, info); - png_byte colorType = png_get_color_type(pngRead, info); - png_byte bitDepth = png_get_bit_depth(pngRead, info); + const png_uint_32 width = png_get_image_width(pngRead, info); + const png_uint_32 height = png_get_image_height(pngRead, info); + const png_byte colorType = png_get_color_type(pngRead, info); + const png_byte bitDepth = png_get_bit_depth(pngRead, info); if (width < 4 || height < 4) { Log.report(logvisor::Error, fmt("image must be 4x4 or larger")); @@ -1070,18 +1093,22 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat png_text* textStruct; int numText; png_get_text(pngRead, info, &textStruct, &numText); - for (int i = 0; i < numText; ++i) - if (!strcmp(textStruct[i].key, "urde_nomip")) + for (int i = 0; i < numText; ++i) { + if (std::strcmp(textStruct[i].key, "urde_nomip") == 0) { mipmap = false; - if (colorType == PNG_COLOR_TYPE_PALETTE) + } + } + if (colorType == PNG_COLOR_TYPE_PALETTE) { mipmap = false; + } /* Compute mipmap levels */ size_t numMips = 1; if (mipmap && CountBits(width) == 1 && CountBits(height) == 1) { size_t index = std::min(width, height); - while (index >>= 1) + while (index >>= 1) { ++numMips; + } } if (bitDepth != 8) { @@ -1149,8 +1176,8 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat if (colorType == PNG_COLOR_TYPE_RGB) { png_read_row(pngRead, rowBuf.get(), nullptr); for (unsigned i = 0; i < width; ++i) { - size_t inbase = i * 3; - size_t outbase = (r * width + i) * 4; + const size_t inbase = i * 3; + const size_t outbase = (r * width + i) * 4; bufOut[outbase] = rowBuf[inbase]; bufOut[outbase + 1] = rowBuf[inbase + 1]; bufOut[outbase + 2] = rowBuf[inbase + 2]; @@ -1160,9 +1187,10 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat png_read_row(pngRead, &bufOut[(r * width) * nComps], nullptr); if (colorType == PNG_COLOR_TYPE_RGB_ALPHA) { for (unsigned i = 0; i < width; ++i) { - size_t outbase = (r * width + i) * nComps; - if (bufOut[outbase + 3] != 0 && bufOut[outbase + 3] != 255) + const size_t outbase = (r * width + i) * nComps; + if (bufOut[outbase + 3] != 0 && bufOut[outbase + 3] != 255) { doDXT1 = false; + } } } } @@ -1253,9 +1281,9 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat filterHeight = height; const uint8_t* rgbaIn = bufOut.get(); uint8_t* blocksOut = compOut.get(); - memset(blocksOut, 0, compLen); + std::memset(blocksOut, 0, compLen); for (size_t i = 0; i < numMips; ++i) { - int thisLen = squish::GetStorageRequirements(filterWidth, filterHeight, squish::kDxt1); + const int thisLen = squish::GetStorageRequirements(filterWidth, filterHeight, squish::kDxt1); EncodeCMPR(rgbaIn, blocksOut, filterWidth, filterHeight); rgbaIn += filterWidth * filterHeight * nComps; blocksOut += thisLen; @@ -1269,14 +1297,15 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat int filterHeight = height; compLen = bufLen; if (colorType == PNG_COLOR_TYPE_PALETTE) { - if (nPaletteEntries == 16) + if (nPaletteEntries == 16) { compLen /= 2; + } compLen += 8 + nPaletteEntries * 2; } compOut.reset(new uint8_t[compLen]); const uint8_t* rgbaIn = bufOut.get(); uint8_t* dataOut = compOut.get(); - memset(dataOut, 0, compLen); + std::memset(dataOut, 0, compLen); for (size_t i = 0; i < numMips; ++i) { switch (colorType) { case PNG_COLOR_TYPE_GRAY: @@ -1367,28 +1396,32 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP png_read_info(pngRead, info); - png_uint_32 width = png_get_image_width(pngRead, info); - png_uint_32 height = png_get_image_height(pngRead, info); - png_byte colorType = png_get_color_type(pngRead, info); - png_byte bitDepth = png_get_bit_depth(pngRead, info); + const png_uint_32 width = png_get_image_width(pngRead, info); + const png_uint_32 height = png_get_image_height(pngRead, info); + const png_byte colorType = png_get_color_type(pngRead, info); + const png_byte bitDepth = png_get_bit_depth(pngRead, info); /* Disable mipmapping if urde_nomip embedded */ bool mipmap = true; png_text* textStruct; int numText; png_get_text(pngRead, info, &textStruct, &numText); - for (int i = 0; i < numText; ++i) - if (!strcmp(textStruct[i].key, "urde_nomip")) + for (int i = 0; i < numText; ++i) { + if (std::strcmp(textStruct[i].key, "urde_nomip") == 0) { mipmap = false; - if (colorType == PNG_COLOR_TYPE_PALETTE) + } + } + if (colorType == PNG_COLOR_TYPE_PALETTE) { mipmap = false; + } /* Compute mipmap levels */ size_t numMips = 1; if (mipmap && CountBits(width) == 1 && CountBits(height) == 1) { size_t index = std::min(width, height); - while (index >>= 1) + while (index >>= 1) { ++numMips; + } } if (bitDepth != 8) { @@ -1454,7 +1487,7 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP switch (colorType) { case PNG_COLOR_TYPE_GRAY: for (unsigned i = 0; i < width; ++i) { - size_t outbase = (r * width + i) * 4; + const size_t outbase = (r * width + i) * 4; bufOut[outbase] = rowBuf[i]; bufOut[outbase + 1] = rowBuf[i]; bufOut[outbase + 2] = rowBuf[i]; @@ -1463,8 +1496,8 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP break; case PNG_COLOR_TYPE_GRAY_ALPHA: for (unsigned i = 0; i < width; ++i) { - size_t inbase = i * 2; - size_t outbase = (r * width + i) * 4; + const size_t inbase = i * 2; + const size_t outbase = (r * width + i) * 4; bufOut[outbase] = rowBuf[inbase]; bufOut[outbase + 1] = rowBuf[inbase]; bufOut[outbase + 2] = rowBuf[inbase]; @@ -1473,8 +1506,8 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP break; case PNG_COLOR_TYPE_RGB: for (unsigned i = 0; i < width; ++i) { - size_t inbase = i * 3; - size_t outbase = (r * width + i) * 4; + const size_t inbase = i * 3; + const size_t outbase = (r * width + i) * 4; bufOut[outbase] = rowBuf[inbase]; bufOut[outbase + 1] = rowBuf[inbase + 1]; bufOut[outbase + 2] = rowBuf[inbase + 2]; @@ -1483,8 +1516,8 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP break; case PNG_COLOR_TYPE_RGB_ALPHA: for (unsigned i = 0; i < width; ++i) { - size_t inbase = i * 4; - size_t outbase = (r * width + i) * 4; + const size_t inbase = i * 4; + const size_t outbase = (r * width + i) * 4; bufOut[outbase] = rowBuf[inbase]; bufOut[outbase + 1] = rowBuf[inbase + 1]; bufOut[outbase + 2] = rowBuf[inbase + 2]; @@ -1548,7 +1581,7 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP const uint8_t* rgbaIn = bufOut.get(); uint8_t* blocksOut = compOut.get(); for (i = 0; i < numMips; ++i) { - int thisLen = squish::GetStorageRequirements(filterWidth, filterHeight, compFlags); + const int thisLen = squish::GetStorageRequirements(filterWidth, filterHeight, compFlags); squish::CompressImage(rgbaIn, filterWidth, filterHeight, blocksOut, compFlags); rgbaIn += filterWidth * filterHeight * nComps; blocksOut += thisLen; @@ -1621,8 +1654,8 @@ static const atInt32 RetroToDol[11] { }; TXTR::Meta TXTR::GetMetaData(DataSpec::PAKEntryReadStream& rs) { - atUint32 retroFormat = rs.readUint32Big(); - atUint32 format = RetroToDol[retroFormat]; + const atUint32 retroFormat = rs.readUint32Big(); + const atUint32 format = RetroToDol[retroFormat]; if (format == UINT32_MAX) return {}; @@ -1636,10 +1669,10 @@ TXTR::Meta TXTR::GetMetaData(DataSpec::PAKEntryReadStream& rs) { meta.hasPalette = true; PaletteMeta& palMeta = meta.palette; palMeta.format = rs.readUint32Big(); - atUint16 palWidth = rs.readUint16Big(); - atUint16 palHeight = rs.readUint16Big(); + const atUint16 palWidth = rs.readUint16Big(); + const atUint16 palHeight = rs.readUint16Big(); palMeta.elementCount = palWidth * palHeight; - atUint32 palSize = atUint32(palWidth * palHeight * 2); + const atUint32 palSize = atUint32(palWidth * palHeight * 2); if (format == 8) textureSize /= 2; std::unique_ptr palData(new u8[palSize]); diff --git a/DataSpec/DNACommon/WPSC.cpp b/DataSpec/DNACommon/WPSC.cpp index 67fcfb57c..c801d8789 100644 --- a/DataSpec/DNACommon/WPSC.cpp +++ b/DataSpec/DNACommon/WPSC.cpp @@ -1,645 +1,13 @@ #include "DataSpec/DNACommon/WPSC.hpp" - #include "DataSpec/DNACommon/PAK.hpp" -#include - namespace DataSpec::DNAParticle { -template -void WPSM::_read(athena::io::YAMLDocReader& r) { - for (const auto& elem : r.getCurNode()->m_mapChildren) { - if (elem.first.size() < 4) { - LogModule.report(logvisor::Warning, fmt("short FourCC in element '{}'"), elem.first); - continue; - } +template struct PPImpl<_WPSM>; +template struct PPImpl<_WPSM>; - if (auto rec = r.enterSubRecord(elem.first.c_str())) { - switch (*reinterpret_cast(elem.first.data())) { - case SBIG('IORN'): - x0_IORN.read(r); - break; - case SBIG('IVEC'): - x4_IVEC.read(r); - break; - case SBIG('PSOV'): - x8_PSOV.read(r); - break; - case SBIG('PSVM'): - xc_PSVM.read(r); - break; - case SBIG('VMD2'): - x10_VMD2.read(r); - break; - case SBIG('PSLT'): - x14_PSLT.read(r); - break; - case SBIG('PSCL'): - x18_PSCL.read(r); - break; - case SBIG('PCOL'): - x1c_PCOL.read(r); - break; - case SBIG('POFS'): - x20_POFS.read(r); - break; - case SBIG('OFST'): - x24_OFST.read(r); - break; - case SBIG('APSO'): - x28_APSO.read(r); - break; - case SBIG('HOMG'): - x29_HOMG.read(r); - break; - case SBIG('AP11'): - x2a_AP11.read(r); - break; - case SBIG('AP21'): - x2b_AP21.read(r); - break; - case SBIG('AS11'): - x2c_AS11.read(r); - break; - case SBIG('AS12'): - x2d_AS12.read(r); - break; - case SBIG('AS13'): - x2e_AS13.read(r); - break; - case SBIG('TRAT'): - x30_TRAT.read(r); - break; - case SBIG('APSM'): - x34_APSM.read(r); - break; - case SBIG('APS2'): - x44_APS2.read(r); - break; - case SBIG('ASW1'): - x54_ASW1.read(r); - break; - case SBIG('ASW2'): - x64_ASW2.read(r); - break; - case SBIG('ASW3'): - x74_ASW3.read(r); - break; - case SBIG('OHEF'): - x84_OHEF.read(r); - break; - case SBIG('COLR'): - x94_COLR.read(r); - break; - case SBIG('EWTR'): - xa4_EWTR.read(r); - break; - case SBIG('LWTR'): - xa5_LWTR.read(r); - break; - case SBIG('SWTR'): - xa6_SWTR.read(r); - break; - case SBIG('PJFX'): - xa8_PJFX = r.readUint32(); - break; - case SBIG('RNGE'): - xac_RNGE.read(r); - break; - case SBIG('FOFF'): - xb0_FOFF.read(r); - break; - case SBIG('FC60'): - xunk_FC60.read(r); - break; - case SBIG('SPS1'): - xunk_SPS1.read(r); - break; - case SBIG('SPS2'): - xunk_SPS2.read(r); - break; - } - } - } -} - -template -void WPSM::_write(athena::io::YAMLDocWriter& w) const { - if (x0_IORN) - if (auto rec = w.enterSubRecord("IORN")) - x0_IORN.write(w); - if (x4_IVEC) - if (auto rec = w.enterSubRecord("IVEC")) - x4_IVEC.write(w); - if (x8_PSOV) - if (auto rec = w.enterSubRecord("PSOV")) - x8_PSOV.write(w); - if (xc_PSVM) - if (auto rec = w.enterSubRecord("PSVM")) - xc_PSVM.write(w); - if (x10_VMD2) - if (auto rec = w.enterSubRecord("VMD2")) - x10_VMD2.write(w); - if (x14_PSLT) - if (auto rec = w.enterSubRecord("PSLT")) - x14_PSLT.write(w); - if (x18_PSCL) - if (auto rec = w.enterSubRecord("PSCL")) - x18_PSCL.write(w); - if (x1c_PCOL) - if (auto rec = w.enterSubRecord("PCOL")) - x1c_PCOL.write(w); - if (x20_POFS) - if (auto rec = w.enterSubRecord("POFS")) - x20_POFS.write(w); - if (x24_OFST) - if (auto rec = w.enterSubRecord("OFST")) - x24_OFST.write(w); - if (x28_APSO) - if (auto rec = w.enterSubRecord("APSO")) - x28_APSO.write(w); - if (x29_HOMG) - if (auto rec = w.enterSubRecord("HOMG")) - x29_HOMG.write(w); - if (x2a_AP11) - if (auto rec = w.enterSubRecord("AP11")) - x2a_AP11.write(w); - if (x2b_AP21) - if (auto rec = w.enterSubRecord("AP21")) - x2b_AP21.write(w); - if (x2c_AS11) - if (auto rec = w.enterSubRecord("AS11")) - x2c_AS11.write(w); - if (x2d_AS12) - if (auto rec = w.enterSubRecord("AS12")) - x2d_AS12.write(w); - if (x2e_AS13) - if (auto rec = w.enterSubRecord("AS13")) - x2e_AS13.write(w); - if (x30_TRAT) - if (auto rec = w.enterSubRecord("TRAT")) - x30_TRAT.write(w); - if (x34_APSM) - if (auto rec = w.enterSubRecord("APSM")) - x34_APSM.write(w); - if (x44_APS2) - if (auto rec = w.enterSubRecord("APS2")) - x44_APS2.write(w); - if (x54_ASW1) - if (auto rec = w.enterSubRecord("ASW1")) - x54_ASW1.write(w); - if (x64_ASW2) - if (auto rec = w.enterSubRecord("ASW2")) - x64_ASW2.write(w); - if (x74_ASW3) - if (auto rec = w.enterSubRecord("ASW3")) - x74_ASW3.write(w); - if (x84_OHEF) - if (auto rec = w.enterSubRecord("OHEF")) - x84_OHEF.write(w); - if (x94_COLR) - if (auto rec = w.enterSubRecord("COLR")) - x94_COLR.write(w); - if (!xa4_EWTR) - if (auto rec = w.enterSubRecord("EWTR")) - xa4_EWTR.write(w); - if (!xa5_LWTR) - if (auto rec = w.enterSubRecord("LWTR")) - xa5_LWTR.write(w); - if (!xa6_SWTR) - if (auto rec = w.enterSubRecord("SWTR")) - xa6_SWTR.write(w); - if (xa8_PJFX != UINT32_MAX) - w.writeUint32("PJFX", xa8_PJFX); - if (xac_RNGE) - if (auto rec = w.enterSubRecord("RNGE")) - xac_RNGE.write(w); - if (xb0_FOFF) - if (auto rec = w.enterSubRecord("FOFF")) - xb0_FOFF.write(w); - if (xunk_FC60) - if (auto rec = w.enterSubRecord("FC60")) - xunk_FC60.write(w); - if (xunk_SPS1) - if (auto rec = w.enterSubRecord("SPS1")) - xunk_SPS1.write(w); - if (xunk_SPS1) - if (auto rec = w.enterSubRecord("SPS2")) - xunk_SPS2.write(w); -} - -template -void WPSM::_binarySize(size_t& __isz) const { - __isz += 4; - if (x0_IORN) { - __isz += 4; - x0_IORN.binarySize(__isz); - } - if (x4_IVEC) { - __isz += 4; - x4_IVEC.binarySize(__isz); - } - if (x8_PSOV) { - __isz += 4; - x8_PSOV.binarySize(__isz); - } - if (xc_PSVM) { - __isz += 4; - xc_PSVM.binarySize(__isz); - } - if (x10_VMD2) { - __isz += 4; - x10_VMD2.binarySize(__isz); - } - if (x14_PSLT) { - __isz += 4; - x14_PSLT.binarySize(__isz); - } - if (x18_PSCL) { - __isz += 4; - x18_PSCL.binarySize(__isz); - } - if (x1c_PCOL) { - __isz += 4; - x1c_PCOL.binarySize(__isz); - } - if (x20_POFS) { - __isz += 4; - x20_POFS.binarySize(__isz); - } - if (x24_OFST) { - __isz += 4; - x24_OFST.binarySize(__isz); - } - if (x28_APSO) { - __isz += 4; - x28_APSO.binarySize(__isz); - } - if (x29_HOMG) { - __isz += 4; - x29_HOMG.binarySize(__isz); - } - if (x2a_AP11) { - __isz += 4; - x2a_AP11.binarySize(__isz); - } - if (x2b_AP21) { - __isz += 4; - x2b_AP21.binarySize(__isz); - } - if (x2c_AS11) { - __isz += 4; - x2c_AS11.binarySize(__isz); - } - if (x2d_AS12) { - __isz += 4; - x2d_AS12.binarySize(__isz); - } - if (x2e_AS13) { - __isz += 4; - x2e_AS13.binarySize(__isz); - } - if (x30_TRAT) { - __isz += 4; - x30_TRAT.binarySize(__isz); - } - if (x34_APSM) { - __isz += 4; - x34_APSM.binarySize(__isz); - } - if (x44_APS2) { - __isz += 4; - x44_APS2.binarySize(__isz); - } - if (x54_ASW1) { - __isz += 4; - x54_ASW1.binarySize(__isz); - } - if (x64_ASW2) { - __isz += 4; - x64_ASW2.binarySize(__isz); - } - if (x74_ASW3) { - __isz += 4; - x74_ASW3.binarySize(__isz); - } - if (x84_OHEF) { - __isz += 4; - x84_OHEF.binarySize(__isz); - } - if (x94_COLR) { - __isz += 4; - x94_COLR.binarySize(__isz); - } - if (!xa4_EWTR) { - __isz += 4; - xa4_EWTR.binarySize(__isz); - } - if (!xa5_LWTR) { - __isz += 4; - xa5_LWTR.binarySize(__isz); - } - if (!xa6_SWTR) { - __isz += 4; - xa6_SWTR.binarySize(__isz); - } - if (xa8_PJFX != UINT32_MAX) - __isz += 12; - if (xac_RNGE) { - __isz += 4; - xac_RNGE.binarySize(__isz); - } - if (xb0_FOFF) { - __isz += 4; - xb0_FOFF.binarySize(__isz); - } - if (xunk_FC60) { - __isz += 4; - xunk_FC60.binarySize(__isz); - } - if (xunk_SPS1) { - __isz += 4; - xunk_SPS1.binarySize(__isz); - } - if (xunk_SPS2) { - __isz += 4; - xunk_SPS2.binarySize(__isz); - } -} - -template -void WPSM::_read(athena::io::IStreamReader& r) { - DNAFourCC clsId; - clsId.read(r); - if (clsId != SBIG('WPSM')) { - LogModule.report(logvisor::Warning, fmt("non WPSM provided to WPSM parser")); - return; - } - clsId.read(r); - while (clsId != SBIG('_END')) { - switch (clsId.toUint32()) { - case SBIG('IORN'): - x0_IORN.read(r); - break; - case SBIG('IVEC'): - x4_IVEC.read(r); - break; - case SBIG('PSOV'): - x8_PSOV.read(r); - break; - case SBIG('PSVM'): - xc_PSVM.read(r); - break; - case SBIG('VMD2'): - x10_VMD2.read(r); - break; - case SBIG('PSLT'): - x14_PSLT.read(r); - break; - case SBIG('PSCL'): - x18_PSCL.read(r); - break; - case SBIG('PCOL'): - x1c_PCOL.read(r); - break; - case SBIG('POFS'): - x20_POFS.read(r); - break; - case SBIG('OFST'): - x24_OFST.read(r); - break; - case SBIG('APSO'): - r.readUint32(); - x28_APSO = r.readBool(); - break; - case SBIG('HOMG'): - x29_HOMG.read(r); - break; - case SBIG('AP11'): - x2a_AP11.read(r); - break; - case SBIG('AP21'): - x2b_AP21.read(r); - break; - case SBIG('AS11'): - x2c_AS11.read(r); - break; - case SBIG('AS12'): - x2d_AS12.read(r); - break; - case SBIG('AS13'): - x2e_AS13.read(r); - break; - case SBIG('TRAT'): - x30_TRAT.read(r); - break; - case SBIG('APSM'): - x34_APSM.read(r); - break; - case SBIG('APS2'): - x44_APS2.read(r); - break; - case SBIG('ASW1'): - x54_ASW1.read(r); - break; - case SBIG('ASW2'): - x64_ASW2.read(r); - break; - case SBIG('ASW3'): - x74_ASW3.read(r); - break; - case SBIG('OHEF'): - x84_OHEF.read(r); - break; - case SBIG('COLR'): - x94_COLR.read(r); - break; - case SBIG('EWTR'): - r.readUint32(); - xa4_EWTR = r.readBool(); - break; - case SBIG('LWTR'): - r.readUint32(); - xa5_LWTR = r.readBool(); - break; - case SBIG('SWTR'): - r.readUint32(); - xa6_SWTR = r.readBool(); - break; - case SBIG('PJFX'): { - uint32_t fcc; - r.readBytesToBuf(&fcc, 4); - if (fcc != SBIG('NONE')) - xa8_PJFX = r.readUint32Big(); - } break; - case SBIG('RNGE'): - xac_RNGE.read(r); - break; - case SBIG('FOFF'): - xb0_FOFF.read(r); - break; - case SBIG('FC60'): - xunk_FC60.read(r); - break; - case SBIG('SPS1'): - xunk_SPS1.read(r); - break; - case SBIG('SPS2'): - xunk_SPS2.read(r); - break; - default: - LogModule.report(logvisor::Fatal, fmt("Unknown WPSM class {} @{}"), clsId, r.position()); - break; - } - clsId.read(r); - } -} - -template -void WPSM::_write(athena::io::IStreamWriter& w) const { - w.writeBytes("WPSM", 4); - if (x0_IORN) { - w.writeBytes("IORN", 4); - x0_IORN.write(w); - } - if (x4_IVEC) { - w.writeBytes("IVEC", 4); - x4_IVEC.write(w); - } - if (x8_PSOV) { - w.writeBytes("PSOV", 4); - x8_PSOV.write(w); - } - if (xc_PSVM) { - w.writeBytes("PSVM", 4); - xc_PSVM.write(w); - } - if (x10_VMD2) { - w.writeBytes("VMD2", 4); - x10_VMD2.write(w); - } - if (x14_PSLT) { - w.writeBytes("PSLT", 4); - x14_PSLT.write(w); - } - if (x18_PSCL) { - w.writeBytes("PSCL", 4); - x18_PSCL.write(w); - } - if (x1c_PCOL) { - w.writeBytes("PCOL", 4); - x1c_PCOL.write(w); - } - if (x20_POFS) { - w.writeBytes("POFS", 4); - x20_POFS.write(w); - } - if (x24_OFST) { - w.writeBytes("OFST", 4); - x24_OFST.write(w); - } - if (x28_APSO) { - w.writeBytes("APSO", 4); - x28_APSO.write(w); - } - if (x29_HOMG) { - w.writeBytes("HOMG", 4); - x29_HOMG.write(w); - } - if (x2a_AP11) { - w.writeBytes("AP11", 4); - x2a_AP11.write(w); - } - if (x2b_AP21) { - w.writeBytes("AP21", 4); - x2b_AP21.write(w); - } - if (x2c_AS11) { - w.writeBytes("AS11", 4); - x2c_AS11.write(w); - } - if (x2d_AS12) { - w.writeBytes("AS12", 4); - x2d_AS12.write(w); - } - if (x2e_AS13) { - w.writeBytes("AS13", 4); - x2e_AS13.write(w); - } - if (x30_TRAT) { - w.writeBytes("TRAT", 4); - x30_TRAT.write(w); - } - if (x34_APSM) { - w.writeBytes("APSM", 4); - x34_APSM.write(w); - } - if (x44_APS2) { - w.writeBytes("APS2", 4); - x44_APS2.write(w); - } - if (x54_ASW1) { - w.writeBytes("ASW1", 4); - x54_ASW1.write(w); - } - if (x64_ASW2) { - w.writeBytes("ASW2", 4); - x64_ASW2.write(w); - } - if (x74_ASW3) { - w.writeBytes("ASW3", 4); - x74_ASW3.write(w); - } - if (x84_OHEF) { - w.writeBytes("OHEF", 4); - x84_OHEF.write(w); - } - if (x94_COLR) { - w.writeBytes("COLR", 4); - x94_COLR.write(w); - } - if (!xa4_EWTR) { - w.writeBytes("EWTR", 4); - xa4_EWTR.write(w); - } - if (!xa5_LWTR) { - w.writeBytes("LWTR", 4); - xa5_LWTR.write(w); - } - if (!xa6_SWTR) { - w.writeBytes("SWTR", 4); - xa6_SWTR.write(w); - } - if (xa8_PJFX != UINT32_MAX) { - w.writeBytes("PJFXCNST", 8); - w.writeUint32(xa8_PJFX); - } - if (xac_RNGE) { - w.writeBytes("RNGE", 4); - xac_RNGE.write(w); - } - if (xb0_FOFF) { - w.writeBytes("FOFF", 4); - xb0_FOFF.write(w); - } - if (xunk_FC60) { - w.writeBytes("FC60", 4); - xunk_FC60.write(w); - } - if (xunk_SPS1) { - w.writeBytes("SPS1", 4); - xunk_SPS1.write(w); - } - if (xunk_SPS2) { - w.writeBytes("SPS2", 4); - xunk_SPS2.write(w); - } - - w.writeBytes("_END", 4); -} - -AT_SUBSPECIALIZE_DNA_YAML(WPSM) -AT_SUBSPECIALIZE_DNA_YAML(WPSM) +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_WPSM>) +AT_SUBSPECIALIZE_DNA_YAML(PPImpl<_WPSM>) template <> std::string_view WPSM::DNAType() { @@ -651,20 +19,6 @@ std::string_view WPSM::DNAType() { return "WPSM"sv; } -template -void WPSM::gatherDependencies(std::vector& pathsOut) const { - g_curSpec->flattenDependencies(x34_APSM.id, pathsOut); - g_curSpec->flattenDependencies(x44_APS2.id, pathsOut); - g_curSpec->flattenDependencies(x54_ASW1.id, pathsOut); - g_curSpec->flattenDependencies(x64_ASW2.id, pathsOut); - g_curSpec->flattenDependencies(x74_ASW3.id, pathsOut); - g_curSpec->flattenDependencies(x84_OHEF.id, pathsOut); - g_curSpec->flattenDependencies(x94_COLR.id, pathsOut); -} - -template struct WPSM; -template struct WPSM; - template bool ExtractWPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) { athena::io::FileWriter writer(outPath.getAbsolutePath()); diff --git a/DataSpec/DNACommon/WPSC.def b/DataSpec/DNACommon/WPSC.def new file mode 100644 index 000000000..04b6ce33f --- /dev/null +++ b/DataSpec/DNACommon/WPSC.def @@ -0,0 +1,87 @@ +#ifndef ENTRY +#define ENTRY(name, identifier) +#endif + +#ifndef INT_ENTRY +#define INT_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef U32_ENTRY +#define U32_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef REAL_ENTRY +#define REAL_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef VECTOR_ENTRY +#define VECTOR_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef MOD_VECTOR_ENTRY +#define MOD_VECTOR_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef COLOR_ENTRY +#define COLOR_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef UV_ENTRY +#define UV_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef RES_ENTRY +#define RES_ENTRY(name, identifier) ENTRY(name, identifier) +#endif + +#ifndef BOOL_ENTRY +#define BOOL_ENTRY(name, identifier, def) ENTRY(name, identifier) +#endif + +VECTOR_ENTRY('IORN', x0_IORN) +VECTOR_ENTRY('IVEC', x4_IVEC) +VECTOR_ENTRY('PSOV', x8_PSOV) +MOD_VECTOR_ENTRY('PSVM', xc_PSVM) +INT_ENTRY('PSLT', x14_PSLT) +VECTOR_ENTRY('PSCL', x18_PSCL) +COLOR_ENTRY('PCOL', x1c_PCOL) +VECTOR_ENTRY('POFS', x20_POFS) +VECTOR_ENTRY('OFST', x24_OFST) + +REAL_ENTRY('TRAT', x30_TRAT) +RES_ENTRY('APSM', x34_APSM) +RES_ENTRY('APS2', x44_APS2) +RES_ENTRY('ASW1', x54_ASW1) +RES_ENTRY('ASW2', x64_ASW2) +RES_ENTRY('ASW3', x74_ASW3) +RES_ENTRY('OHEF', x84_OHEF) +RES_ENTRY('COLR', x94_COLR) +U32_ENTRY('PJFX', xa8_PJFX) +REAL_ENTRY('RNGE', xac_RNGE) +REAL_ENTRY('FOFF', xb0_FOFF) + +BOOL_ENTRY('VMD2', x10_VMD2, false) +BOOL_ENTRY('APSO', x28_APSO, false) +BOOL_ENTRY('HOMG', x29_HOMG, false) +BOOL_ENTRY('AP11', x2a_AP11, false) +BOOL_ENTRY('AP21', x2b_AP21, false) +BOOL_ENTRY('AS11', x2c_AS11, false) +BOOL_ENTRY('AS12', x2d_AS12, false) +BOOL_ENTRY('AS13', x2e_AS13, false) +BOOL_ENTRY('EWTR', xa4_EWTR, true) +BOOL_ENTRY('LWTR', xa5_LWTR, true) +BOOL_ENTRY('SWTR', xa6_SWTR, true) +BOOL_ENTRY('FC60', xunk_FC60, false) +BOOL_ENTRY('SPS1', xunk_SPS1, false) +BOOL_ENTRY('SPS2', xunk_SPS2, false) + +#undef ENTRY +#undef INT_ENTRY +#undef U32_ENTRY +#undef REAL_ENTRY +#undef VECTOR_ENTRY +#undef MOD_VECTOR_ENTRY +#undef COLOR_ENTRY +#undef UV_ENTRY +#undef RES_ENTRY +#undef BOOL_ENTRY diff --git a/DataSpec/DNACommon/WPSC.hpp b/DataSpec/DNACommon/WPSC.hpp index 3df67b7bd..6a387ef7a 100644 --- a/DataSpec/DNACommon/WPSC.hpp +++ b/DataSpec/DNACommon/WPSC.hpp @@ -12,53 +12,40 @@ class ProjectPath; } namespace DataSpec::DNAParticle { -template -struct WPSM : BigDNA { - AT_DECL_EXPLICIT_DNA_YAML - AT_SUBDECL_DNA - VectorElementFactory x0_IORN; - VectorElementFactory x4_IVEC; - VectorElementFactory x8_PSOV; - ModVectorElementFactory xc_PSVM; - BoolHelper x10_VMD2; - IntElementFactory x14_PSLT; - VectorElementFactory x18_PSCL; - ColorElementFactory x1c_PCOL; - VectorElementFactory x20_POFS; - VectorElementFactory x24_OFST; - BoolHelper x28_APSO; - BoolHelper x29_HOMG; - BoolHelper x2a_AP11; - BoolHelper x2b_AP21; - BoolHelper x2c_AS11; - BoolHelper x2d_AS12; - BoolHelper x2e_AS13; - RealElementFactory x30_TRAT; - ChildResourceFactory x34_APSM; - ChildResourceFactory x44_APS2; - ChildResourceFactory x54_ASW1; - ChildResourceFactory x64_ASW2; - ChildResourceFactory x74_ASW3; - ChildResourceFactory x84_OHEF; - ChildResourceFactory x94_COLR; - BoolHelper xa4_EWTR; - BoolHelper xa5_LWTR; - BoolHelper xa6_SWTR; - uint32_t xa8_PJFX = ~0; - RealElementFactory xac_RNGE; - RealElementFactory xb0_FOFF; - BoolHelper xunk_FC60; - BoolHelper xunk_SPS1; - BoolHelper xunk_SPS2; - WPSM() { - xa4_EWTR = true; - xa5_LWTR = true; - xa6_SWTR = true; +template +struct _WPSM { + static constexpr ParticleType Type = ParticleType::WPSM; + +#define INT_ENTRY(name, identifier) IntElementFactory identifier; +#define U32_ENTRY(name, identifier) uint32_t identifier = ~0; +#define REAL_ENTRY(name, identifier) RealElementFactory identifier; +#define VECTOR_ENTRY(name, identifier) VectorElementFactory identifier; +#define MOD_VECTOR_ENTRY(name, identifier) ModVectorElementFactory identifier; +#define COLOR_ENTRY(name, identifier) ColorElementFactory identifier; +#define UV_ENTRY(name, identifier) UVElementFactory identifier; +#define RES_ENTRY(name, identifier) ChildResourceFactory identifier; +#define BOOL_ENTRY(name, identifier, def) bool identifier = def; +#include "WPSC.def" + + template + void constexpr Enumerate(_Func f) { +#define ENTRY(name, identifier) f(FOURCC(name), identifier); +#define BOOL_ENTRY(name, identifier, def) f(FOURCC(name), identifier, def); +#include "WPSC.def" } - void gatherDependencies(std::vector&) const; + template + bool constexpr Lookup(FourCC fcc, _Func f) { + switch (fcc.toUint32()) { +#define ENTRY(name, identifier) case SBIG(name): f(identifier); return true; +#include "WPSC.def" + default: return false; + } + } }; +template +using WPSM = PPImpl<_WPSM>; template bool ExtractWPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath); 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/DNAMP1/SCAN.cpp b/DataSpec/DNAMP1/SCAN.cpp index beabf6a5e..c09371284 100644 --- a/DataSpec/DNAMP1/SCAN.cpp +++ b/DataSpec/DNAMP1/SCAN.cpp @@ -1,12 +1,16 @@ #include "SCAN.hpp" +#include +#include + namespace DataSpec::DNAMP1 { -static const std::vector PaneNames = { - "imagepane_pane0", "imagepane_pane1", "imagepane_pane2", "imagepane_pane3", "imagepane_pane01", - "imagepane_pane12", "imagepane_pane23", "imagepane_pane012", "imagepane_pane123", "imagepane_pane0123", - "imagepane_pane4", "imagepane_pane5", "imagepane_pane6", "imagepane_pane7", "imagepane_pane45", - "imagepane_pane56", "imagepane_pane67", "imagepane_pane456", "imagepane_pane567", "imagepane_pane4567"}; +constexpr std::array PaneNames{ + "imagepane_pane0"sv, "imagepane_pane1"sv, "imagepane_pane2"sv, "imagepane_pane3"sv, "imagepane_pane01"sv, + "imagepane_pane12"sv, "imagepane_pane23"sv, "imagepane_pane012"sv, "imagepane_pane123"sv, "imagepane_pane0123"sv, + "imagepane_pane4"sv, "imagepane_pane5"sv, "imagepane_pane6"sv, "imagepane_pane7"sv, "imagepane_pane45"sv, + "imagepane_pane56"sv, "imagepane_pane67"sv, "imagepane_pane456"sv, "imagepane_pane567"sv, "imagepane_pane4567"sv, +}; template <> void SCAN::Texture::Enumerate(typename Read::StreamT& r) { diff --git a/DataSpec/DNAMP1/STRG.cpp b/DataSpec/DNAMP1/STRG.cpp index 4a52b3b17..6acf994ba 100644 --- a/DataSpec/DNAMP1/STRG.cpp +++ b/DataSpec/DNAMP1/STRG.cpp @@ -1,10 +1,14 @@ #include "STRG.hpp" + +#include + #include "DNAMP1.hpp" namespace DataSpec::DNAMP1 { -const std::vector skLanguages = {FOURCC('ENGL'), FOURCC('FREN'), FOURCC('GERM'), FOURCC('SPAN'), - FOURCC('ITAL'), FOURCC('DUTC'), FOURCC('JAPN')}; +constexpr std::array skLanguages{ + FOURCC('ENGL'), FOURCC('FREN'), FOURCC('GERM'), FOURCC('SPAN'), FOURCC('ITAL'), FOURCC('DUTC'), FOURCC('JAPN'), +}; static uint32_t ParseTag(const char16_t* str) { char parseStr[9]; 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/DNAMP2/DNAMP2.cpp b/DataSpec/DNAMP2/DNAMP2.cpp index 1f6027844..f0e1d7bc9 100644 --- a/DataSpec/DNAMP2/DNAMP2.cpp +++ b/DataSpec/DNAMP2/DNAMP2.cpp @@ -151,7 +151,7 @@ void PAKBridge::build() { } void PAKBridge::addCMDLRigPairs(PAKRouter& pakRouter, CharacterAssociations& charAssoc) const { - for (const std::pair& entry : m_pak.m_entries) { + for (const auto& entry : m_pak.m_entries) { if (entry.second.type == FOURCC('ANCS')) { PAKEntryReadStream rs = entry.second.beginReadStream(m_node); ANCS ancs; @@ -175,7 +175,7 @@ static const atVec4f BottomRow = {{0.f, 0.f, 0.f, 1.f}}; void PAKBridge::addMAPATransforms(PAKRouter& pakRouter, std::unordered_map& addTo, std::unordered_map& pathOverrides) const { - for (const std::pair& entry : m_pak.m_entries) { + for (const auto& entry : m_pak.m_entries) { if (entry.second.type == FOURCC('MLVL')) { MLVL mlvl; { diff --git a/DataSpec/DNAMP2/STRG.cpp b/DataSpec/DNAMP2/STRG.cpp index 891c7b3da..30d0cb24a 100644 --- a/DataSpec/DNAMP2/STRG.cpp +++ b/DataSpec/DNAMP2/STRG.cpp @@ -67,8 +67,8 @@ void STRG::Enumerate(athena::io::IStreamWriter& writer) { writer.writeUint32Big(strCount); atUint32 offset = 0; - for (const std::pair>& lang : langs) { - lang.first.write(writer); + for (const auto& lang : langs) { + DNAFourCC{lang.first}.write(writer); writer.writeUint32Big(offset); offset += strCount * 4 + 4; atUint32 langStrCount = lang.second.size(); @@ -87,20 +87,22 @@ void STRG::Enumerate(athena::io::IStreamWriter& writer) { } atUint32 nameTableSz = names.size() * 8; - for (const std::pair& name : names) + for (const auto& name : names) { nameTableSz += name.first.size() + 1; + } writer.writeUint32Big(names.size()); writer.writeUint32Big(nameTableSz); offset = names.size() * 8; - for (const std::pair& name : names) { + for (const auto& name : names) { writer.writeUint32Big(offset); writer.writeInt32Big(name.second); offset += name.first.size() + 1; } - for (const std::pair& name : names) + for (const auto& name : names) { writer.writeString(name.first); + } - for (const std::pair>& lang : langs) { + for (const auto& lang : langs) { offset = strCount * 4; atUint32 langStrCount = lang.second.size(); for (atUint32 s = 0; s < strCount; ++s) { @@ -128,11 +130,12 @@ void STRG::Enumerate(size_t& __isz) { __isz += 8; __isz += names.size() * 8; - for (const std::pair& name : names) + for (const auto& name : names) { __isz += name.first.size() + 1; + } size_t strCount = STRG::count(); - for (const std::pair>& lang : langs) { + for (const auto& lang : langs) { atUint32 langStrCount = lang.second.size(); __isz += strCount * 4; 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; } } diff --git a/DataSpec/DNAMP3/DNAMP3.cpp b/DataSpec/DNAMP3/DNAMP3.cpp index 05158846c..a2b8199b0 100644 --- a/DataSpec/DNAMP3/DNAMP3.cpp +++ b/DataSpec/DNAMP3/DNAMP3.cpp @@ -157,7 +157,7 @@ void PAKBridge::build() { } void PAKBridge::addCMDLRigPairs(PAKRouter& pakRouter, CharacterAssociations& charAssoc) const { - for (const std::pair& entry : m_pak.m_entries) { + for (const auto& entry : m_pak.m_entries) { if (entry.second.type == FOURCC('CHAR')) { PAKEntryReadStream rs = entry.second.beginReadStream(m_node); CHAR aChar; @@ -180,7 +180,7 @@ static const atVec4f BottomRow = {{0.f, 0.f, 0.f, 1.f}}; void PAKBridge::addMAPATransforms(PAKRouter& pakRouter, std::unordered_map& addTo, std::unordered_map& pathOverrides) const { - for (const std::pair& entry : m_pak.m_entries) { + for (const auto& entry : m_pak.m_entries) { if (entry.second.type == FOURCC('MLVL')) { MLVL mlvl; { diff --git a/DataSpec/DNAMP3/PAK.hpp b/DataSpec/DNAMP3/PAK.hpp index d45fe4785..298dc5770 100644 --- a/DataSpec/DNAMP3/PAK.hpp +++ b/DataSpec/DNAMP3/PAK.hpp @@ -61,7 +61,7 @@ struct PAK : BigDNA { bool mreaHasDupeResources(const UniqueID64& id) const { return m_dupeMREAs.find(id) != m_dupeMREAs.cend(); } - typedef UniqueID64 IDType; + using IDType = UniqueID64; }; } // namespace DataSpec::DNAMP3 diff --git a/DataSpec/SpecMP1.cpp b/DataSpec/SpecMP1.cpp index ddf973351..c98a0a940 100644 --- a/DataSpec/SpecMP1.cpp +++ b/DataSpec/SpecMP1.cpp @@ -108,7 +108,7 @@ struct TextureCache { auto rec = r.enterSubRecord(node.first.c_str()); TXTR::Meta meta; meta.read(r); - metaPairs.push_back(std::make_pair(projectPath.parsedHash32(), meta)); + metaPairs.emplace_back(projectPath.parsedHash32(), meta); } std::sort(metaPairs.begin(), metaPairs.end(), [](const auto& a, const auto& b) -> bool { @@ -201,11 +201,12 @@ struct SpecMP1 : SpecBase { /* Assemble extract report */ rep.childOpts.reserve(m_orderedPaks.size()); - for (const std::pair& item : m_orderedPaks) { - if (!item.second->m_doExtract) + for (const auto& item : m_orderedPaks) { + if (!item.second->m_doExtract) { continue; - rep.childOpts.emplace_back(); - ExtractReport& childRep = rep.childOpts.back(); + } + + ExtractReport& childRep = rep.childOpts.emplace_back(); hecl::SystemStringConv nameView(item.first); childRep.name = nameView.sys_str(); childRep.desc = item.second->getLevelString(); @@ -222,8 +223,7 @@ struct SpecMP1 : SpecBase { return false; /* Root Report */ - reps.emplace_back(); - ExtractReport& rep = reps.back(); + ExtractReport& rep = reps.emplace_back(); rep.name = _SYS_STR("MP1"); rep.desc = _SYS_STR("Metroid Prime ") + regstr; if (buildInfo) { @@ -277,8 +277,7 @@ struct SpecMP1 : SpecBase { const char* buildInfo = (char*)memmem(m_dolBuf.get(), dolIt->size(), "MetroidBuildInfo", 16) + 19; /* Root Report */ - reps.emplace_back(); - ExtractReport& rep = reps.back(); + ExtractReport& rep = reps.emplace_back(); rep.name = _SYS_STR("MP1"); rep.desc = _SYS_STR("Metroid Prime ") + regstr; if (buildInfo) { @@ -1023,7 +1022,7 @@ struct SpecMP1 : SpecBase { for (const auto& dep : area.deps) { urde::CAssetId newId = dep.id.toUint64(); if (dupeRes || addedTags.find(newId) == addedTags.end()) { - listOut.push_back({dep.type, newId}); + listOut.emplace_back(dep.type, newId); addedTags.insert(newId); } } @@ -1083,7 +1082,7 @@ struct SpecMP1 : SpecBase { for (atUint32 i = 0; i < mapaCount; ++i) { UniqueID32 id; id.read(r); - listOut.push_back({FOURCC('MAPA'), id.toUint64()}); + listOut.emplace_back(FOURCC('MAPA'), id.toUint64()); } } } diff --git a/DataSpec/SpecMP2.cpp b/DataSpec/SpecMP2.cpp index 47a8e96cb..8111b2400 100644 --- a/DataSpec/SpecMP2.cpp +++ b/DataSpec/SpecMP2.cpp @@ -101,11 +101,12 @@ struct SpecMP2 : SpecBase { m_orderedPaks[std::string(dpak.getName())] = &dpak; /* Assemble extract report */ - for (const std::pair& item : m_orderedPaks) { - if (!item.second->m_doExtract) + for (const auto& item : m_orderedPaks) { + if (!item.second->m_doExtract) { continue; - rep.childOpts.emplace_back(); - ExtractReport& childRep = rep.childOpts.back(); + } + + ExtractReport& childRep = rep.childOpts.emplace_back(); hecl::SystemStringConv nameView(item.first); childRep.name = hecl::SystemString(nameView.sys_str()); childRep.desc = item.second->getLevelString(); @@ -121,8 +122,7 @@ struct SpecMP2 : SpecBase { return false; /* Root Report */ - reps.emplace_back(); - ExtractReport& rep = reps.back(); + ExtractReport& rep = reps.emplace_back(); rep.name = _SYS_STR("MP2"); rep.desc = _SYS_STR("Metroid Prime 2 ") + regstr; std::string buildStr(buildInfo); @@ -174,8 +174,7 @@ struct SpecMP2 : SpecBase { const char* buildInfo = (char*)memmem(dolBuf.get(), dolIt->size(), "MetroidBuildInfo", 16) + 19; /* Root Report */ - reps.emplace_back(); - ExtractReport& rep = reps.back(); + ExtractReport& rep = reps.emplace_back(); rep.name = _SYS_STR("MP2"); rep.desc = _SYS_STR("Metroid Prime 2 ") + regstr; if (buildInfo) { diff --git a/DataSpec/SpecMP3.cpp b/DataSpec/SpecMP3.cpp index 4429e6ee9..632d3c68d 100644 --- a/DataSpec/SpecMP3.cpp +++ b/DataSpec/SpecMP3.cpp @@ -132,11 +132,11 @@ struct SpecMP3 : SpecBase { } /* Assemble extract report */ - for (const std::pair& item : fe ? m_feOrderedPaks : m_orderedPaks) { + for (const auto& item : fe ? m_feOrderedPaks : m_orderedPaks) { if (!item.second->m_doExtract) continue; - rep.childOpts.emplace_back(); - ExtractReport& childRep = rep.childOpts.back(); + + ExtractReport& childRep = rep.childOpts.emplace_back(); hecl::SystemStringConv nameView(item.first); childRep.name = hecl::SystemString(nameView.sys_str()); if (item.first == "Worlds.pak") @@ -168,8 +168,7 @@ struct SpecMP3 : SpecBase { return false; /* Root Report */ - reps.emplace_back(); - ExtractReport& rep = reps.back(); + ExtractReport& rep = reps.emplace_back(); rep.name = _SYS_STR("MP3"); rep.desc = _SYS_STR("Metroid Prime 3 ") + regstr; std::string buildStr(buildInfo); @@ -250,8 +249,7 @@ struct SpecMP3 : SpecBase { } /* Root Report */ - reps.emplace_back(); - ExtractReport& rep = reps.back(); + ExtractReport& rep = reps.emplace_back(); rep.name = _SYS_STR("MP3"); rep.desc = _SYS_STR("Metroid Prime 3 ") + regstr; @@ -281,8 +279,7 @@ struct SpecMP3 : SpecBase { const char* buildInfo = (char*)memmem(dolBuf.get(), dolIt->size(), "MetroidBuildInfo", 16) + 19; /* Root Report */ - reps.emplace_back(); - ExtractReport& rep = reps.back(); + ExtractReport& rep = reps.emplace_back(); rep.name = _SYS_STR("fe"); rep.desc = _SYS_STR("Metroid Prime Trilogy Frontend ") + regstr; if (buildInfo) { @@ -305,7 +302,7 @@ struct SpecMP3 : SpecBase { } bool extractFromDisc(nod::DiscBase& disc, bool force, const hecl::MultiProgressPrinter& progress) override { - hecl::SystemString currentTarget = _SYS_STR(""); + hecl::SystemString currentTarget; size_t nodeCount = 0; int prog = 0; nod::ExtractionContext ctx = {force, [&](std::string_view name, float) { @@ -394,7 +391,7 @@ struct SpecMP3 : SpecBase { progress.startNewLine(); hecl::ClientProcess process; - for (std::pair pair : m_feOrderedPaks) { + for (auto& pair : m_feOrderedPaks) { DNAMP3::PAKBridge& pak = *pair.second; if (!pak.m_doExtract) continue; diff --git a/Runtime/Audio/CAudioGroupSet.hpp b/Runtime/Audio/CAudioGroupSet.hpp index ef9d37f2e..d0b8c968b 100644 --- a/Runtime/Audio/CAudioGroupSet.hpp +++ b/Runtime/Audio/CAudioGroupSet.hpp @@ -21,7 +21,7 @@ class CAudioGroupSet { amuse::AudioGroupData LoadData(); public: - CAudioGroupSet(std::unique_ptr&& in); + explicit CAudioGroupSet(std::unique_ptr&& in); const amuse::AudioGroupData& GetAudioGroupData() const { return m_data; } std::string_view GetName() const { return x20_name; } }; diff --git a/Runtime/Audio/CMidiManager.hpp b/Runtime/Audio/CMidiManager.hpp index ebf757d5c..75b915473 100644 --- a/Runtime/Audio/CMidiManager.hpp +++ b/Runtime/Audio/CMidiManager.hpp @@ -19,7 +19,7 @@ public: u16 GetGroupId() const { return x2_groupId; } CAssetId GetAGSCAssetId() const { return x4_agscId; } const u8* GetArrData() const { return x8_arrData.get(); } - CMidiData(CInputStream& in); + explicit CMidiData(CInputStream& in); }; class CMidiWrapper { diff --git a/Runtime/Audio/CStaticAudioPlayer.hpp b/Runtime/Audio/CStaticAudioPlayer.hpp index b2ee5551e..8ffb59460 100644 --- a/Runtime/Audio/CStaticAudioPlayer.hpp +++ b/Runtime/Audio/CStaticAudioPlayer.hpp @@ -53,7 +53,7 @@ class CStaticAudioPlayer { memset(data, 0, 4 * frames); return frames; } - AudioVoiceCallback(CStaticAudioPlayer& p) : m_parent(p) {} + explicit AudioVoiceCallback(CStaticAudioPlayer& p) : m_parent(p) {} } m_voiceCallback; boo::ObjToken m_voice; diff --git a/Runtime/Audio/CStreamAudioManager.cpp b/Runtime/Audio/CStreamAudioManager.cpp index adf9d3175..1660e097f 100644 --- a/Runtime/Audio/CStreamAudioManager.cpp +++ b/Runtime/Audio/CStreamAudioManager.cpp @@ -50,7 +50,7 @@ struct SDSPStreamInfo { s16 x1c_coef[8][2]; SDSPStreamInfo() = default; - SDSPStreamInfo(const CDSPStreamManager& stream); + explicit SDSPStreamInfo(const CDSPStreamManager& stream); }; struct SDSPStream : boo::IAudioVoiceCallback { diff --git a/Runtime/AutoMapper/CAutoMapper.hpp b/Runtime/AutoMapper/CAutoMapper.hpp index a49a76984..a2d5d168d 100644 --- a/Runtime/AutoMapper/CAutoMapper.hpp +++ b/Runtime/AutoMapper/CAutoMapper.hpp @@ -224,7 +224,7 @@ private: CAssetId GetAreaHintDescriptionString(CAssetId mreaId); public: - CAutoMapper(CStateManager& stateMgr); + explicit CAutoMapper(CStateManager& stateMgr); bool CheckLoadComplete(); bool CanLeaveMapScreen(const CStateManager& mgr) const; float GetMapRotationX() const { return xa8_renderStates[0].x1c_camAngle; } diff --git a/Runtime/AutoMapper/CMapArea.hpp b/Runtime/AutoMapper/CMapArea.hpp index 80c6c8379..ff4f8233f 100644 --- a/Runtime/AutoMapper/CMapArea.hpp +++ b/Runtime/AutoMapper/CMapArea.hpp @@ -38,7 +38,7 @@ public: std::vector m_instances; public: - CMapAreaSurface(const void* surfBuf); + explicit CMapAreaSurface(const void* surfBuf); CMapAreaSurface(CMapAreaSurface&&) = default; void PostConstruct(const u8* buf, std::vector& index); void Draw(const zeus::CVector3f* verts, const zeus::CColor& surfColor, const zeus::CColor& lineColor, @@ -69,7 +69,7 @@ private: boo::ObjToken m_ibo; public: - CMapArea(CInputStream& in, u32 size); + explicit CMapArea(CInputStream& in, u32 size); void PostConstruct(); bool GetIsVisibleToAutoMapper(bool worldVis, bool areaVis) const; zeus::CVector3f GetAreaCenterPoint() const { return x10_box.center(); } diff --git a/Runtime/AutoMapper/CMapUniverse.hpp b/Runtime/AutoMapper/CMapUniverse.hpp index 989a629f5..c961db60e 100644 --- a/Runtime/AutoMapper/CMapUniverse.hpp +++ b/Runtime/AutoMapper/CMapUniverse.hpp @@ -84,7 +84,7 @@ public: zeus::CVector3f x64_centerPoint = zeus::skZero3f; public: - CMapWorldData(CInputStream& in, u32 version); + explicit CMapWorldData(CInputStream& in, u32 version); CAssetId GetWorldAssetId() const { return x10_worldAssetId; } const zeus::CVector3f& GetWorldCenterPoint() const { return x64_centerPoint; } std::string_view GetWorldLabel() const { return x0_label; } @@ -105,7 +105,7 @@ private: float x2c_universeRadius = 1600.f; public: - CMapUniverse(CInputStream&, u32); + explicit CMapUniverse(CInputStream&, u32); const CMapWorldData& GetMapWorldData(s32 idx) const { return x10_worldDatas[idx]; } const CMapWorldData& GetMapWorldDataByWorldId(CAssetId id) const { for (const CMapWorldData& data : x10_worldDatas) diff --git a/Runtime/AutoMapper/CMapWorld.cpp b/Runtime/AutoMapper/CMapWorld.cpp index 481474da1..6defe74ce 100644 --- a/Runtime/AutoMapper/CMapWorld.cpp +++ b/Runtime/AutoMapper/CMapWorld.cpp @@ -1,6 +1,7 @@ #include "Runtime/AutoMapper/CMapWorld.hpp" #include +#include #include "Runtime/CSimplePool.hpp" #include "Runtime/CStateManager.hpp" @@ -9,6 +10,254 @@ #include "Runtime/World/CWorld.hpp" namespace urde { +namespace { +struct Support { + int x0_; + std::array x4_; +}; + +struct Circle2 { + zeus::CVector2f x0_point; + float x8_radiusSq; +}; + +struct Circle { + zeus::CVector2f x0_point; + float x8_radius; + Circle(const Circle2& circ2) : x0_point(circ2.x0_point), x8_radius(std::sqrt(circ2.x8_radiusSq)) {} +}; + +Circle2 ExactCircle1(const zeus::CVector2f* a) { return {*a, 0.f}; } + +Circle2 ExactCircle2(const zeus::CVector2f* a, const zeus::CVector2f* b) { + Circle2 ret = {}; + ret.x0_point = 0.5f * (*a + *b); + ret.x8_radiusSq = (*b - *a).magSquared() * 0.25f; + return ret; +} + +Circle2 ExactCircle3(const zeus::CVector2f* a, const zeus::CVector2f* b, const zeus::CVector2f* c) { + Circle2 ret = {}; + zeus::CVector2f d1 = *b - *a; + zeus::CVector2f d2 = *c - *a; + float cross = d1.cross(d2); + zeus::CVector2f magVec(d1.magSquared() * 0.5f, d2.magSquared() * 0.5f); + if (std::fabs(cross) > 0.01f) { + zeus::CVector2f tmp((d2.y() * magVec.x() - d1.y() * magVec.y()) / cross, + (d1.x() * magVec.y() - d2.x() * magVec.x()) / cross); + ret.x0_point = *a + tmp; + ret.x8_radiusSq = tmp.magSquared(); + } else { + ret.x8_radiusSq = FLT_MAX; + } + return ret; +} + +bool PointInsideCircle(const zeus::CVector2f& point, const Circle2& circ, float& intersect) { + intersect = (point - circ.x0_point).magSquared() - circ.x8_radiusSq; + return intersect <= 0.f; +} + +Circle2 UpdateSupport1(int idx, const zeus::CVector2f** list, Support& support) { + Circle2 ret = ExactCircle2(list[support.x4_[0]], list[idx]); + support.x0_ = 2; + support.x4_[1] = idx; + return ret; +} + +Circle2 UpdateSupport2(int idx, const zeus::CVector2f** list, Support& support) { + std::array circs{}; + float intersect; + int circIdx = -1; + float minRad = FLT_MAX; + + circs[0] = ExactCircle2(list[support.x4_[0]], list[idx]); + if (PointInsideCircle(*list[support.x4_[1]], circs[0], intersect)) { + minRad = circs[0].x8_radiusSq; + circIdx = 0; + } + + circs[1] = ExactCircle2(list[support.x4_[1]], list[idx]); + if (circs[1].x8_radiusSq < minRad && PointInsideCircle(*list[support.x4_[0]], circs[1], intersect)) { + circIdx = 1; + } + + Circle2 ret; + if (circIdx != -1) { + ret = circs[circIdx]; + support.x4_[1 - circIdx] = idx; + } else { + ret = ExactCircle3(list[support.x4_[0]], list[support.x4_[1]], list[idx]); + support.x0_ = 3; + support.x4_[2] = idx; + } + return ret; +} + +Circle2 UpdateSupport3(int idx, const zeus::CVector2f** list, Support& support) { + std::array circs{}; + float intersect; + int circIdxA = -1; + int circIdxB = -1; + float minRadA = FLT_MAX; + float minRadB = FLT_MAX; + + circs[0] = ExactCircle2(list[support.x4_[0]], list[idx]); + if (PointInsideCircle(*list[support.x4_[1]], circs[0], intersect)) { + if (PointInsideCircle(*list[support.x4_[2]], circs[0], intersect)) { + minRadA = circs[0].x8_radiusSq; + circIdxA = 0; + } else { + minRadB = intersect; + circIdxB = 0; + } + } else { + minRadB = intersect; + circIdxB = 0; + } + + circs[1] = ExactCircle2(list[support.x4_[1]], list[idx]); + if (circs[1].x8_radiusSq < minRadA) { + if (PointInsideCircle(*list[support.x4_[0]], circs[1], intersect)) { + if (PointInsideCircle(*list[support.x4_[2]], circs[1], intersect)) { + minRadA = circs[1].x8_radiusSq; + circIdxA = 1; + } else if (intersect < minRadB) { + minRadB = intersect; + circIdxB = 1; + } + } else if (intersect < minRadB) { + minRadB = intersect; + circIdxB = 1; + } + } + + circs[2] = ExactCircle2(list[support.x4_[2]], list[idx]); + if (circs[2].x8_radiusSq < minRadA) { + if (PointInsideCircle(*list[support.x4_[0]], circs[2], intersect)) { + if (PointInsideCircle(*list[support.x4_[1]], circs[2], intersect)) { + minRadA = circs[2].x8_radiusSq; + circIdxA = 2; + } else if (intersect < minRadB) { + minRadB = intersect; + circIdxB = 2; + } + } else if (intersect < minRadB) { + minRadB = intersect; + circIdxB = 2; + } + } + + circs[3] = ExactCircle3(list[support.x4_[0]], list[support.x4_[1]], list[idx]); + if (circs[3].x8_radiusSq < minRadA) { + if (PointInsideCircle(*list[support.x4_[2]], circs[3], intersect)) { + minRadA = circs[3].x8_radiusSq; + circIdxA = 3; + } else if (intersect < minRadB) { + minRadB = intersect; + circIdxB = 3; + } + } + + circs[4] = ExactCircle3(list[support.x4_[0]], list[support.x4_[2]], list[idx]); + if (circs[4].x8_radiusSq < minRadA) { + if (PointInsideCircle(*list[support.x4_[1]], circs[4], intersect)) { + minRadA = circs[4].x8_radiusSq; + circIdxA = 4; + } else if (intersect < minRadB) { + minRadB = intersect; + circIdxB = 4; + } + } + + circs[5] = ExactCircle3(list[support.x4_[1]], list[support.x4_[2]], list[idx]); + if (circs[5].x8_radiusSq < minRadA) { + if (PointInsideCircle(*list[support.x4_[0]], circs[5], intersect)) { + circIdxA = 5; + } else if (intersect < minRadB) { + circIdxB = 5; + } + } + + if (circIdxA == -1) + circIdxA = circIdxB; + + switch (circIdxA) { + case 0: + support.x0_ = 2; + support.x4_[1] = idx; + break; + case 1: + support.x0_ = 2; + support.x4_[0] = idx; + break; + case 2: + support.x0_ = 2; + support.x4_[0] = support.x4_[2]; + support.x4_[1] = idx; + break; + case 3: + support.x4_[2] = idx; + break; + case 4: + support.x4_[1] = idx; + break; + case 5: + support.x4_[0] = idx; + break; + default: + break; + } + + return circs[circIdxA]; +} + +using FSupport = Circle2 (*)(int idx, const zeus::CVector2f** list, Support& support); +constexpr std::array SupportFuncs{ + nullptr, + UpdateSupport1, + UpdateSupport2, + UpdateSupport3, +}; + +Circle MinCircle(const std::vector& coords) { + Circle2 ret = {}; + if (coords.size() >= 1) { + std::unique_ptr randArr(new const zeus::CVector2f*[coords.size()]); + for (size_t i = 0; i < coords.size(); ++i) + randArr[i] = &coords[i]; + for (int i = coords.size() - 1; i >= 0; --i) { + int shuf = rand() % (i + 1); + if (shuf != i) + std::swap(randArr[i], randArr[shuf]); + } + ret = ExactCircle1(randArr[0]); + + Support support = {}; + support.x0_ = 1; + for (size_t i = 1; i < coords.size();) { + bool broke = false; + for (int j = 0; j < support.x0_; ++j) { + if ((*randArr[i] - *randArr[support.x4_[j]]).magSquared() < 0.01f) { + broke = true; + break; + } + } + float intersect; + if (!broke && !PointInsideCircle(*randArr[i], ret, intersect)) { + Circle2 circ = SupportFuncs[support.x0_](i, randArr.get(), support); + if (circ.x8_radiusSq > ret.x8_radiusSq) { + i = 0; + ret = circ; + continue; + } + } + ++i; + } + } + return ret; +} +} // Anonymous namespace CMapWorld::CMapAreaData::CMapAreaData(CAssetId areaRes, EMapAreaList list, CMapAreaData* next) : x0_area(g_SimplePool->GetObj(SObjectTag{FOURCC('MAPA'), areaRes})), x10_list(list), x14_next(next) {} @@ -378,248 +627,6 @@ void CMapWorld::DrawAreas(const CMapWorld::CMapWorldDrawParms& parms, int selAre } } -struct Support { - int x0_; - int x4_[3]; -}; - -struct Circle2 { - zeus::CVector2f x0_point; - float x8_radiusSq; -}; - -struct Circle { - zeus::CVector2f x0_point; - float x8_radius; - Circle(const Circle2& circ2) : x0_point(circ2.x0_point), x8_radius(std::sqrt(circ2.x8_radiusSq)) {} -}; - -static Circle2 ExactCircle1(const zeus::CVector2f* a) { return {*a, 0.f}; } - -static Circle2 ExactCircle2(const zeus::CVector2f* a, const zeus::CVector2f* b) { - Circle2 ret = {}; - ret.x0_point = 0.5f * (*a + *b); - ret.x8_radiusSq = (*b - *a).magSquared() * 0.25f; - return ret; -} - -static Circle2 ExactCircle3(const zeus::CVector2f* a, const zeus::CVector2f* b, const zeus::CVector2f* c) { - Circle2 ret = {}; - zeus::CVector2f d1 = *b - *a; - zeus::CVector2f d2 = *c - *a; - float cross = d1.cross(d2); - zeus::CVector2f magVec(d1.magSquared() * 0.5f, d2.magSquared() * 0.5f); - if (std::fabs(cross) > 0.01f) { - zeus::CVector2f tmp((d2.y() * magVec.x() - d1.y() * magVec.y()) / cross, - (d1.x() * magVec.y() - d2.x() * magVec.x()) / cross); - ret.x0_point = *a + tmp; - ret.x8_radiusSq = tmp.magSquared(); - } else { - ret.x8_radiusSq = FLT_MAX; - } - return ret; -} - -static bool PointInsideCircle(const zeus::CVector2f& point, const Circle2& circ, float& intersect) { - intersect = (point - circ.x0_point).magSquared() - circ.x8_radiusSq; - return intersect <= 0.f; -} - -static Circle2 UpdateSupport1(int idx, const zeus::CVector2f** list, Support& support) { - Circle2 ret = ExactCircle2(list[support.x4_[0]], list[idx]); - support.x0_ = 2; - support.x4_[1] = idx; - return ret; -} - -static Circle2 UpdateSupport2(int idx, const zeus::CVector2f** list, Support& support) { - Circle2 circs[3] = {}; - float intersect; - int circIdx = -1; - float minRad = FLT_MAX; - - circs[0] = ExactCircle2(list[support.x4_[0]], list[idx]); - if (PointInsideCircle(*list[support.x4_[1]], circs[0], intersect)) { - minRad = circs[0].x8_radiusSq; - circIdx = 0; - } - - circs[1] = ExactCircle2(list[support.x4_[1]], list[idx]); - if (circs[1].x8_radiusSq < minRad && PointInsideCircle(*list[support.x4_[0]], circs[1], intersect)) { - circIdx = 1; - } - - Circle2 ret; - if (circIdx != -1) { - ret = circs[circIdx]; - support.x4_[1 - circIdx] = idx; - } else { - ret = ExactCircle3(list[support.x4_[0]], list[support.x4_[1]], list[idx]); - support.x0_ = 3; - support.x4_[2] = idx; - } - return ret; -} - -static Circle2 UpdateSupport3(int idx, const zeus::CVector2f** list, Support& support) { - Circle2 circs[6] = {}; - float intersect; - int circIdxA = -1; - int circIdxB = -1; - float minRadA = FLT_MAX; - float minRadB = FLT_MAX; - - circs[0] = ExactCircle2(list[support.x4_[0]], list[idx]); - if (PointInsideCircle(*list[support.x4_[1]], circs[0], intersect)) { - if (PointInsideCircle(*list[support.x4_[2]], circs[0], intersect)) { - minRadA = circs[0].x8_radiusSq; - circIdxA = 0; - } else { - minRadB = intersect; - circIdxB = 0; - } - } else { - minRadB = intersect; - circIdxB = 0; - } - - circs[1] = ExactCircle2(list[support.x4_[1]], list[idx]); - if (circs[1].x8_radiusSq < minRadA) { - if (PointInsideCircle(*list[support.x4_[0]], circs[1], intersect)) { - if (PointInsideCircle(*list[support.x4_[2]], circs[1], intersect)) { - minRadA = circs[1].x8_radiusSq; - circIdxA = 1; - } else if (intersect < minRadB) { - minRadB = intersect; - circIdxB = 1; - } - } else if (intersect < minRadB) { - minRadB = intersect; - circIdxB = 1; - } - } - - circs[2] = ExactCircle2(list[support.x4_[2]], list[idx]); - if (circs[2].x8_radiusSq < minRadA) { - if (PointInsideCircle(*list[support.x4_[0]], circs[2], intersect)) { - if (PointInsideCircle(*list[support.x4_[1]], circs[2], intersect)) { - minRadA = circs[2].x8_radiusSq; - circIdxA = 2; - } else if (intersect < minRadB) { - minRadB = intersect; - circIdxB = 2; - } - } else if (intersect < minRadB) { - minRadB = intersect; - circIdxB = 2; - } - } - - circs[3] = ExactCircle3(list[support.x4_[0]], list[support.x4_[1]], list[idx]); - if (circs[3].x8_radiusSq < minRadA) { - if (PointInsideCircle(*list[support.x4_[2]], circs[3], intersect)) { - minRadA = circs[3].x8_radiusSq; - circIdxA = 3; - } else if (intersect < minRadB) { - minRadB = intersect; - circIdxB = 3; - } - } - - circs[4] = ExactCircle3(list[support.x4_[0]], list[support.x4_[2]], list[idx]); - if (circs[4].x8_radiusSq < minRadA) { - if (PointInsideCircle(*list[support.x4_[1]], circs[4], intersect)) { - minRadA = circs[4].x8_radiusSq; - circIdxA = 4; - } else if (intersect < minRadB) { - minRadB = intersect; - circIdxB = 4; - } - } - - circs[5] = ExactCircle3(list[support.x4_[1]], list[support.x4_[2]], list[idx]); - if (circs[5].x8_radiusSq < minRadA) { - if (PointInsideCircle(*list[support.x4_[0]], circs[5], intersect)) { - circIdxA = 5; - } else if (intersect < minRadB) { - circIdxB = 5; - } - } - - if (circIdxA == -1) - circIdxA = circIdxB; - - switch (circIdxA) { - case 0: - support.x0_ = 2; - support.x4_[1] = idx; - break; - case 1: - support.x0_ = 2; - support.x4_[0] = idx; - break; - case 2: - support.x0_ = 2; - support.x4_[0] = support.x4_[2]; - support.x4_[1] = idx; - break; - case 3: - support.x4_[2] = idx; - break; - case 4: - support.x4_[1] = idx; - break; - case 5: - support.x4_[0] = idx; - break; - default: - break; - } - - return circs[circIdxA]; -} - -typedef Circle2 (*FSupport)(int idx, const zeus::CVector2f** list, Support& support); -static const FSupport SupportFuncs[] = {nullptr, UpdateSupport1, UpdateSupport2, UpdateSupport3}; - -static Circle MinCircle(const std::vector& coords) { - Circle2 ret = {}; - if (coords.size() >= 1) { - std::unique_ptr randArr(new const zeus::CVector2f*[coords.size()]); - for (size_t i = 0; i < coords.size(); ++i) - randArr[i] = &coords[i]; - for (int i = coords.size() - 1; i >= 0; --i) { - int shuf = rand() % (i + 1); - if (shuf != i) - std::swap(randArr[i], randArr[shuf]); - } - ret = ExactCircle1(randArr[0]); - - Support support = {}; - support.x0_ = 1; - for (size_t i = 1; i < coords.size();) { - bool broke = false; - for (int j = 0; j < support.x0_; ++j) { - if ((*randArr[i] - *randArr[support.x4_[j]]).magSquared() < 0.01f) { - broke = true; - break; - } - } - float intersect; - if (!broke && !PointInsideCircle(*randArr[i], ret, intersect)) { - Circle2 circ = SupportFuncs[support.x0_](i, randArr.get(), support); - if (circ.x8_radiusSq > ret.x8_radiusSq) { - i = 0; - ret = circ; - continue; - } - } - ++i; - } - } - return ret; -} - void CMapWorld::RecalculateWorldSphere(const CMapWorldInfo& mwInfo, const IWorld& wld) { std::vector coords; coords.reserve(x0_areas.size() * 8); diff --git a/Runtime/AutoMapper/CMapWorldInfo.hpp b/Runtime/AutoMapper/CMapWorldInfo.hpp index ae18e2d3e..030d4fbca 100644 --- a/Runtime/AutoMapper/CMapWorldInfo.hpp +++ b/Runtime/AutoMapper/CMapWorldInfo.hpp @@ -18,7 +18,7 @@ class CMapWorldInfo { public: CMapWorldInfo() = default; - CMapWorldInfo(CBitStreamReader&, const CSaveWorld& saveWorld, CAssetId mlvlId); + explicit CMapWorldInfo(CBitStreamReader&, const CSaveWorld& saveWorld, CAssetId mlvlId); void PutTo(CBitStreamWriter& writer, const CSaveWorld& savw, CAssetId mlvlId) const; bool IsMapped(TAreaId) const; void SetIsMapped(TAreaId, bool); diff --git a/Runtime/AutoMapper/CMappableObject.hpp b/Runtime/AutoMapper/CMappableObject.hpp index 53cde42bb..7a50cf8e5 100644 --- a/Runtime/AutoMapper/CMappableObject.hpp +++ b/Runtime/AutoMapper/CMappableObject.hpp @@ -63,7 +63,7 @@ private: struct DoorSurface { CMapSurfaceShader m_surface; CLineRenderer m_outline; - DoorSurface(boo::IGraphicsDataFactory::Context& ctx) + explicit DoorSurface(boo::IGraphicsDataFactory::Context& ctx) : m_surface(ctx, g_doorVbo, g_doorIbo) , m_outline(ctx, CLineRenderer::EPrimitiveMode::LineLoop, 5, nullptr, false, false, true) {} }; @@ -74,7 +74,7 @@ private: std::pair GetDoorColors(int idx, const CMapWorldInfo& mwInfo, float alpha) const; public: - CMappableObject(const void* buf); + explicit CMappableObject(const void* buf); CMappableObject(CMappableObject&&) = default; void PostConstruct(const void*); const zeus::CTransform& GetTransform() const { return x10_transform; } diff --git a/Runtime/CDependencyGroup.hpp b/Runtime/CDependencyGroup.hpp index 603fb2471..e38a176d2 100644 --- a/Runtime/CDependencyGroup.hpp +++ b/Runtime/CDependencyGroup.hpp @@ -8,7 +8,7 @@ class CDependencyGroup { std::vector x0_objectTags; public: - CDependencyGroup(CInputStream& in); + explicit CDependencyGroup(CInputStream& in); void ReadFromStream(CInputStream& in); const std::vector& GetObjectTagVector() const { return x0_objectTags; } }; diff --git a/Runtime/CGameOptions.hpp b/Runtime/CGameOptions.hpp index acc3bec0c..554ecea86 100644 --- a/Runtime/CGameOptions.hpp +++ b/Runtime/CGameOptions.hpp @@ -71,7 +71,7 @@ class CPersistentOptions { public: CPersistentOptions() = default; - CPersistentOptions(CBitStreamReader& stream); + explicit CPersistentOptions(CBitStreamReader& stream); bool GetCinematicState(CAssetId mlvlId, TEditorId cineId) const; void SetCinematicState(CAssetId mlvlId, TEditorId cineId, bool state); @@ -134,7 +134,7 @@ class CGameOptions { public: CGameOptions(); - CGameOptions(CBitStreamReader& stream); + explicit CGameOptions(CBitStreamReader& stream); void ResetToDefaults(); void InitSoundMode(); void EnsureSettings(); @@ -201,7 +201,7 @@ private: public: CHintOptions() = default; - CHintOptions(CBitStreamReader& stream); + explicit CHintOptions(CBitStreamReader& stream); void PutTo(CBitStreamWriter& writer) const; void SetNextHintTime(); void InitializeMemoryState(); diff --git a/Runtime/CGameState.cpp b/Runtime/CGameState.cpp index d15b41bed..2bd9531f6 100644 --- a/Runtime/CGameState.cpp +++ b/Runtime/CGameState.cpp @@ -38,15 +38,17 @@ CWorldLayerState::CWorldLayerState(CBitStreamReader& reader, const CSaveWorld& s void CWorldLayerState::PutTo(CBitStreamWriter& writer) const { u32 totalLayerCount = 0; - for (int i = 0; i < x0_areaLayers.size(); ++i) - totalLayerCount += GetAreaLayerCount(i) - 1; + for (size_t i = 0; i < x0_areaLayers.size(); ++i) { + totalLayerCount += GetAreaLayerCount(s32(i)) - 1; + } writer.WriteEncoded(totalLayerCount, 10); - for (int i = 0; i < x0_areaLayers.size(); ++i) { - u32 count = GetAreaLayerCount(i); - for (u32 l = 1; l < count; ++l) - writer.WriteEncoded(IsLayerActive(i, l), 1); + for (size_t i = 0; i < x0_areaLayers.size(); ++i) { + const u32 count = GetAreaLayerCount(s32(i)); + for (u32 l = 1; l < count; ++l) { + writer.WriteEncoded(IsLayerActive(s32(i), s32(l)), 1); + } } } @@ -95,8 +97,9 @@ CGameState::GameFileStateInfo CGameState::LoadGameFileState(const u8* data) { CBitStreamReader stream(data, 4096); GameFileStateInfo ret; - for (u32 i = 0; i < 128; i++) + for (u32 i = 0; i < 128; i++) { stream.ReadEncoded(8); + } ret.x14_timestamp = stream.ReadEncoded(32); ret.x20_hardMode = stream.ReadEncoded(1); @@ -143,8 +146,9 @@ CGameState::CGameState(CBitStreamReader& stream, u32 saveIdx) : x20c_saveFileIdx x9c_transManager = std::make_shared(); x228_25_initPowerupsAtFirstSpawn = true; - for (u32 i = 0; i < 128; i++) - x0_[i] = stream.ReadEncoded(8); + for (bool& value : x0_) { + value = stream.ReadEncoded(8) != 0; + } stream.ReadEncoded(32); x228_24_hardMode = stream.ReadEncoded(1); @@ -205,9 +209,10 @@ void CGameState::WriteBackupBuf() { PutTo(w); } -void CGameState::PutTo(CBitStreamWriter& writer) const { - for (u32 i = 0; i < 128; i++) - writer.WriteEncoded(x0_[i], 8); +void CGameState::PutTo(CBitStreamWriter& writer) { + for (const bool value : x0_) { + writer.WriteEncoded(u32(value), 8); + } writer.WriteEncoded(CBasics::ToWiiTime(std::chrono::system_clock::now()) / CBasics::TICKS_PER_SECOND, 32); writer.WriteEncoded(x228_24_hardMode, 1); @@ -227,7 +232,7 @@ void CGameState::PutTo(CBitStreamWriter& writer) const { for (const auto& memWorld : memWorlds) { TLockedToken saveWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), memWorld.second.GetSaveWorldAssetId()}); - const CWorldState& wld = const_cast(*this).StateForWorld(memWorld.first); + const CWorldState& wld = StateForWorld(memWorld.first); wld.PutTo(writer, *saveWorld); } } diff --git a/Runtime/CGameState.hpp b/Runtime/CGameState.hpp index 5790af0d9..32349f8d9 100644 --- a/Runtime/CGameState.hpp +++ b/Runtime/CGameState.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -67,7 +68,7 @@ public: class CGameState { friend class CStateManager; - bool x0_[128] = {}; + std::array x0_{}; u32 x80_; CAssetId x84_mlvlId; std::vector x88_worldStates; @@ -116,7 +117,7 @@ public: void SetFileIdx(u32 idx) { x20c_saveFileIdx = idx; } void SetCardSerial(u64 serial) { x210_cardSerial = serial; } u64 GetCardSerial() const { return x210_cardSerial; } - void PutTo(CBitStreamWriter& writer) const; + void PutTo(CBitStreamWriter& writer); float GetHardModeDamageMultiplier() const; float GetHardModeWeaponMultiplier() const; void InitializeMemoryWorlds(); diff --git a/Runtime/CIOWin.hpp b/Runtime/CIOWin.hpp index ef5b5f396..43a3df3d8 100644 --- a/Runtime/CIOWin.hpp +++ b/Runtime/CIOWin.hpp @@ -16,13 +16,13 @@ class CIOWin { public: enum class EMessageReturn { Normal = 0, Exit = 1, RemoveIOWinAndExit = 2, RemoveIOWin = 3 }; - CIOWin(std::string_view name) : x4_name(name) { m_nameHash = std::hash()(name); } + explicit CIOWin(std::string_view name) : x4_name(name) { m_nameHash = std::hash()(name); } virtual ~CIOWin() = default; virtual EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&) = 0; virtual bool GetIsContinueDraw() const { return true; } - virtual void Draw() const {} - virtual void PreDraw() const {} + virtual void Draw() {} + virtual void PreDraw() {} std::string_view GetName() const { return x4_name; } size_t GetNameHash() const { return m_nameHash; } diff --git a/Runtime/CMFGameBase.hpp b/Runtime/CMFGameBase.hpp index c99416549..b73d1c71c 100644 --- a/Runtime/CMFGameBase.hpp +++ b/Runtime/CMFGameBase.hpp @@ -6,12 +6,12 @@ namespace urde { class CMFGameBase : public CIOWin { public: - CMFGameBase(const char* name) : CIOWin(name) {} + explicit CMFGameBase(const char* name) : CIOWin(name) {} }; class CMFGameLoaderBase : public CIOWin { public: - CMFGameLoaderBase(const char* name) : CIOWin(name) {} + explicit CMFGameLoaderBase(const char* name) : CIOWin(name) {} }; } // namespace urde diff --git a/Runtime/CMainFlowBase.hpp b/Runtime/CMainFlowBase.hpp index 22a17f39f..f16ad0fbe 100644 --- a/Runtime/CMainFlowBase.hpp +++ b/Runtime/CMainFlowBase.hpp @@ -11,7 +11,7 @@ protected: EClientFlowStates x14_gameState = EClientFlowStates::Unspecified; public: - CMainFlowBase(const char* name) : CIOWin(name) {} + explicit CMainFlowBase(const char* name) : CIOWin(name) {} EMessageReturn OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) override; virtual void AdvanceGameState(CArchitectureQueue& queue) = 0; virtual void SetGameState(EClientFlowStates state, CArchitectureQueue& queue) = 0; diff --git a/Runtime/CPlayMovieBase.hpp b/Runtime/CPlayMovieBase.hpp index 068ef615a..0c86a81f4 100644 --- a/Runtime/CPlayMovieBase.hpp +++ b/Runtime/CPlayMovieBase.hpp @@ -11,7 +11,7 @@ class CPlayMovieBase : public CIOWin { public: CPlayMovieBase(const char* iowName, const char* path) : CIOWin(iowName), x18_moviePlayer(path, 0.0, false, false) {} EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&) override { return EMessageReturn::Normal; } - void Draw() const override {} + void Draw() override {} }; } // namespace urde diff --git a/Runtime/CPlayerState.hpp b/Runtime/CPlayerState.hpp index c249836dc..22134070d 100644 --- a/Runtime/CPlayerState.hpp +++ b/Runtime/CPlayerState.hpp @@ -170,7 +170,7 @@ public: CStaticInterference& GetStaticInterference() { return x188_staticIntf; } const std::vector>& GetScanTimes() const { return x170_scanTimes; } CPlayerState(); - CPlayerState(CBitStreamReader& stream); + explicit CPlayerState(CBitStreamReader& stream); void PutTo(CBitStreamWriter& stream); static u32 GetPowerUpMaxValue(EItemType type); static EItemType ItemNameToType(std::string_view name); diff --git a/Runtime/CSaveWorld.hpp b/Runtime/CSaveWorld.hpp index 75403fd74..097ed3522 100644 --- a/Runtime/CSaveWorld.hpp +++ b/Runtime/CSaveWorld.hpp @@ -31,7 +31,7 @@ private: std::vector x44_scans; public: - CSaveWorld(CInputStream& in); + explicit CSaveWorld(CInputStream& in); u32 GetAreaCount() const; u32 GetCinematicCount() const; s32 GetCinematicIndex(const TEditorId& id) const; diff --git a/Runtime/CSortedLists.cpp b/Runtime/CSortedLists.cpp index e22c0166e..2a9ecbb99 100644 --- a/Runtime/CSortedLists.cpp +++ b/Runtime/CSortedLists.cpp @@ -30,17 +30,19 @@ void CSortedListManager::Reset() { } } -void CSortedListManager::AddToLinkedList(s16 nodeId, s16& headId, s16& tailId) const { +void CSortedListManager::AddToLinkedList(s16 nodeId, s16& headId, s16& tailId) { if (headId == -1) { - const_cast(AccessElement(x0_nodes, nodeId)).x28_next = headId; + AccessElement(x0_nodes, nodeId).x28_next = headId; headId = nodeId; tailId = nodeId; } else { - if (AccessElement(x0_nodes, nodeId).x28_next != -1) + if (AccessElement(x0_nodes, nodeId).x28_next != -1) { return; - if (tailId == nodeId) + } + if (tailId == nodeId) { return; - const_cast(AccessElement(x0_nodes, nodeId)).x28_next = headId; + } + AccessElement(x0_nodes, nodeId).x28_next = headId; headId = nodeId; } } @@ -114,19 +116,19 @@ void CSortedListManager::InsertInList(ESortedList list, SNode& node) { ++sl.x800_size; } -s16 CSortedListManager::FindInListUpper(ESortedList list, float val) const { +s16 CSortedListManager::FindInListUpper(ESortedList list, float value) const { const auto listIndex = static_cast(list); const SSortedList& sl = xb000_sortedLists[listIndex]; int idx = 0; for (int i = sl.x800_size; i > 0;) { - /* Binary search cycle to find index */ - if (!(val < AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + i / 2)).x4_box[listIndex])) { - /* Upper */ + // Binary search cycle to find index + if (!(value < AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + i / 2)).x4_box[listIndex])) { + // Upper idx = idx + i / 2 + 1; i = i - i / 2 - 1; } else { - /* Lower */ + // Lower i /= 2; } } @@ -134,19 +136,19 @@ s16 CSortedListManager::FindInListUpper(ESortedList list, float val) const { return idx; } -s16 CSortedListManager::FindInListLower(ESortedList list, float val) const { +s16 CSortedListManager::FindInListLower(ESortedList list, float value) const { const auto listIndex = static_cast(list); const SSortedList& sl = xb000_sortedLists[listIndex]; int idx = 0; for (int i = sl.x800_size; i > 0;) { - /* Binary search cycle to find index */ - if (AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + i / 2)).x4_box[listIndex] < val) { - /* Upper */ + // Binary search cycle to find index + if (AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + i / 2)).x4_box[listIndex] < value) { + // Upper idx = idx + i / 2 + 1; i = i - i / 2 - 1; } else { - /* Lower */ + // Lower i /= 2; } } @@ -233,48 +235,52 @@ s16 CSortedListManager::CalculateIntersections(ESortedList la, ESortedList lb, s void CSortedListManager::BuildNearList(rstl::reserved_vector& out, const zeus::CVector3f& pos, const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter, - const CActor* actor) const { - if (mag == 0.f) + const CActor* actor) { + if (mag == 0.f) { mag = 8000.f; + } const zeus::CVector3f ray = dir * mag; const zeus::CVector3f sum = ray + pos; - zeus::CVector3f maxs(std::max(pos.x(), sum.x()), std::max(pos.y(), sum.y()), std::max(pos.z(), sum.z())); - zeus::CVector3f mins(std::min(sum.x(), pos.x()), std::min(sum.y(), pos.y()), std::min(sum.z(), pos.z())); + const zeus::CVector3f maxs(std::max(pos.x(), sum.x()), std::max(pos.y(), sum.y()), std::max(pos.z(), sum.z())); + const zeus::CVector3f mins(std::min(sum.x(), pos.x()), std::min(sum.y(), pos.y()), std::min(sum.z(), pos.z())); BuildNearList(out, zeus::CAABox(mins, maxs), filter, actor); } void CSortedListManager::BuildNearList(rstl::reserved_vector& out, const CActor& actor, - const zeus::CAABox& aabb) const { + const zeus::CAABox& aabb) { const CMaterialFilter& filter = actor.GetMaterialFilter(); - s16 id = const_cast(*this).ConstructIntersectionArray(aabb); + s16 id = ConstructIntersectionArray(aabb); while (id != -1) { - const SNode& node = AccessElement(x0_nodes, id); + SNode& node = AccessElement(x0_nodes, id); if (&actor != node.x0_actor && filter.Passes(node.x0_actor->GetMaterialList()) && - node.x0_actor->GetMaterialFilter().Passes(actor.GetMaterialList())) + node.x0_actor->GetMaterialFilter().Passes(actor.GetMaterialList())) { out.push_back(node.x0_actor->GetUniqueId()); + } id = node.x28_next; - const_cast(node).x28_next = -1; + node.x28_next = -1; } } void CSortedListManager::BuildNearList(rstl::reserved_vector& out, const zeus::CAABox& aabb, - const CMaterialFilter& filter, const CActor* actor) const { - s16 id = const_cast(*this).ConstructIntersectionArray(aabb); + const CMaterialFilter& filter, const CActor* actor) { + s16 id = ConstructIntersectionArray(aabb); while (id != -1) { - const SNode& node = AccessElement(x0_nodes, id); - if (actor != node.x0_actor && filter.Passes(node.x0_actor->GetMaterialList())) + SNode& node = AccessElement(x0_nodes, id); + if (actor != node.x0_actor && filter.Passes(node.x0_actor->GetMaterialList())) { out.push_back(node.x0_actor->GetUniqueId()); + } id = node.x28_next; - const_cast(node).x28_next = -1; + node.x28_next = -1; } } -void CSortedListManager::Remove(const CActor* act) { - SNode& node = AccessElement(x0_nodes, act->GetUniqueId().Value()); - if (!node.x2a_populated) +void CSortedListManager::Remove(const CActor* actor) { + SNode& node = AccessElement(x0_nodes, actor->GetUniqueId().Value()); + if (!node.x2a_populated) { return; + } RemoveFromList(ESortedList::MinX, node.x1c_selfIdxs[0]); RemoveFromList(ESortedList::MaxX, node.x1c_selfIdxs[3]); @@ -285,8 +291,8 @@ void CSortedListManager::Remove(const CActor* act) { node.x2a_populated = false; } -void CSortedListManager::Move(const CActor* act, const zeus::CAABox& aabb) { - SNode& node = AccessElement(x0_nodes, act->GetUniqueId().Value()); +void CSortedListManager::Move(const CActor* actor, const zeus::CAABox& aabb) { + SNode& node = AccessElement(x0_nodes, actor->GetUniqueId().Value()); node.x4_box = aabb; MoveInList(ESortedList::MinX, node.x1c_selfIdxs[0]); @@ -297,14 +303,14 @@ void CSortedListManager::Move(const CActor* act, const zeus::CAABox& aabb) { MoveInList(ESortedList::MaxZ, node.x1c_selfIdxs[5]); } -void CSortedListManager::Insert(const CActor* act, const zeus::CAABox& aabb) { - SNode& node = AccessElement(x0_nodes, act->GetUniqueId().Value()); +void CSortedListManager::Insert(const CActor* actor, const zeus::CAABox& aabb) { + SNode& node = AccessElement(x0_nodes, actor->GetUniqueId().Value()); if (node.x2a_populated) { - Move(act, aabb); + Move(actor, aabb); return; } - SNode newNode(act, aabb); + SNode newNode(actor, aabb); InsertInList(ESortedList::MinX, newNode); InsertInList(ESortedList::MaxX, newNode); InsertInList(ESortedList::MinY, newNode); @@ -314,10 +320,11 @@ void CSortedListManager::Insert(const CActor* act, const zeus::CAABox& aabb) { node = newNode; } -bool CSortedListManager::ActorInLists(const CActor* act) const { - if (!act) +bool CSortedListManager::ActorInLists(const CActor* actor) const { + if (!actor) { return false; - const SNode& node = AccessElement(x0_nodes, act->GetUniqueId().Value()); + } + const SNode& node = AccessElement(x0_nodes, actor->GetUniqueId().Value()); return node.x2a_populated; } diff --git a/Runtime/CSortedLists.hpp b/Runtime/CSortedLists.hpp index f251ff662..ce7d49e4a 100644 --- a/Runtime/CSortedLists.hpp +++ b/Runtime/CSortedLists.hpp @@ -31,27 +31,27 @@ class CSortedListManager { std::array x0_nodes; std::array xb000_sortedLists; void Reset(); - void AddToLinkedList(s16 a, s16& b, s16& c) const; - void RemoveFromList(ESortedList, s16); - void MoveInList(ESortedList, s16); - void InsertInList(ESortedList, SNode& node); - s16 FindInListUpper(ESortedList, float) const; - s16 FindInListLower(ESortedList, float) const; - s16 ConstructIntersectionArray(const zeus::CAABox&); - s16 CalculateIntersections(ESortedList, ESortedList, s16, s16, s16, s16, ESortedList, ESortedList, ESortedList, - ESortedList, const zeus::CAABox&); + void AddToLinkedList(s16 nodeId, s16& headId, s16& tailId); + void RemoveFromList(ESortedList list, s16 idx); + void MoveInList(ESortedList list, s16 idx); + void InsertInList(ESortedList list, SNode& node); + s16 FindInListUpper(ESortedList list, float value) const; + s16 FindInListLower(ESortedList list, float value) const; + s16 ConstructIntersectionArray(const zeus::CAABox& aabb); + s16 CalculateIntersections(ESortedList la, ESortedList lb, s16 a, s16 b, s16 c, s16 d, ESortedList slA, + ESortedList slB, ESortedList slC, ESortedList slD, const zeus::CAABox& aabb); public: CSortedListManager(); - void BuildNearList(rstl::reserved_vector&, const zeus::CVector3f&, const zeus::CVector3f&, float, - const CMaterialFilter&, const CActor*) const; - void BuildNearList(rstl::reserved_vector&, const CActor&, const zeus::CAABox&) const; - void BuildNearList(rstl::reserved_vector&, const zeus::CAABox&, const CMaterialFilter&, - const CActor*) const; - void Remove(const CActor*); - void Move(const CActor* act, const zeus::CAABox& aabb); - void Insert(const CActor* act, const zeus::CAABox& aabb); - bool ActorInLists(const CActor* act) const; + void BuildNearList(rstl::reserved_vector& out, const zeus::CVector3f& pos, + const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter, const CActor* actor); + void BuildNearList(rstl::reserved_vector& out, const CActor& actor, const zeus::CAABox& aabb); + void BuildNearList(rstl::reserved_vector& out, const zeus::CAABox& aabb, + const CMaterialFilter& filter, const CActor* actor); + void Remove(const CActor* actor); + void Move(const CActor* actor, const zeus::CAABox& aabb); + void Insert(const CActor* actor, const zeus::CAABox& aabb); + bool ActorInLists(const CActor* actor) const; }; } // namespace urde diff --git a/Runtime/CStateManager.hpp b/Runtime/CStateManager.hpp index 69717cd90..565a08efa 100644 --- a/Runtime/CStateManager.hpp +++ b/Runtime/CStateManager.hpp @@ -216,8 +216,8 @@ private: u32 xf94_ = 0; }; - CColoredQuadFilter m_deathWhiteout = {EFilterType::Add}; - CColoredQuadFilter m_escapeWhiteout = {EFilterType::Add}; + CColoredQuadFilter m_deathWhiteout{EFilterType::Add}; + CColoredQuadFilter m_escapeWhiteout{EFilterType::Add}; bool m_warping = false; void UpdateThermalVisor(); diff --git a/Runtime/CStaticInterference.hpp b/Runtime/CStaticInterference.hpp index 9e2718912..2018165f9 100644 --- a/Runtime/CStaticInterference.hpp +++ b/Runtime/CStaticInterference.hpp @@ -16,7 +16,7 @@ class CStaticInterference { std::vector m_sources; public: - CStaticInterference(int sourceCount); + explicit CStaticInterference(int sourceCount); void RemoveSource(TUniqueId id); void Update(CStateManager&, float dt); float GetTotalInterference() const; diff --git a/Runtime/CTextureCache.hpp b/Runtime/CTextureCache.hpp index 70364d691..220e0ba5c 100644 --- a/Runtime/CTextureCache.hpp +++ b/Runtime/CTextureCache.hpp @@ -8,7 +8,7 @@ class CPaletteInfo { u64 m_dolphinHash; public: - CPaletteInfo(CInputStream& in) + explicit CPaletteInfo(CInputStream& in) : m_format(in.readUint32Big()), m_elementCount(in.readUint32Big()), m_dolphinHash(in.readUint64Big()) {} }; class CTextureInfo { @@ -20,7 +20,7 @@ class CTextureInfo { std::optional m_paletteInfo; public: - CTextureInfo(CInputStream& in) + explicit CTextureInfo(CInputStream& in) : m_format(ETexelFormat(in.readUint32Big())) , m_mipCount(in.readUint32Big()) , m_width(in.readUint16Big()) @@ -36,7 +36,7 @@ public: std::map m_textureInfo; public: - CTextureCache(CInputStream& in); + explicit CTextureCache(CInputStream& in); const CTextureInfo* GetTextureInfo(CAssetId id) const; diff --git a/Runtime/CToken.cpp b/Runtime/CToken.cpp index e30daf34f..38bfa24ed 100644 --- a/Runtime/CToken.cpp +++ b/Runtime/CToken.cpp @@ -112,7 +112,7 @@ CToken& CToken::operator=(const CToken& other) { } return *this; } -CToken& CToken::operator=(CToken&& other) { +CToken& CToken::operator=(CToken&& other) noexcept { Unlock(); RemoveRef(); x0_objRef = other.x0_objRef; diff --git a/Runtime/CToken.hpp b/Runtime/CToken.hpp index ba8722d2b..1fec4bbd5 100644 --- a/Runtime/CToken.hpp +++ b/Runtime/CToken.hpp @@ -84,7 +84,7 @@ public: IObj* GetObj(); const IObj* GetObj() const { return const_cast(this)->GetObj(); } CToken& operator=(const CToken& other); - CToken& operator=(CToken&& other); + CToken& operator=(CToken&& other) noexcept; CToken() = default; CToken(const CToken& other); CToken(CToken&& other) noexcept; @@ -137,13 +137,13 @@ public: TCachedToken() = default; TCachedToken(const CToken& other) : TToken(other) {} TCachedToken(CToken&& other) : TToken(std::move(other)) {} - T* GetObj() { + T* GetObj() override { if (!m_obj) m_obj = TToken::GetObj(); return m_obj; } - const T* GetObj() const { return const_cast*>(this)->GetObj(); } - void Unlock() { + const T* GetObj() const override { return const_cast*>(this)->GetObj(); } + void Unlock() override { TToken::Unlock(); m_obj = nullptr; } @@ -153,7 +153,7 @@ public: m_obj = nullptr; return *this; } - TCachedToken& operator=(const CToken& other) { + TCachedToken& operator=(const CToken& other) override { TToken::operator=(other); m_obj = nullptr; return *this; @@ -172,7 +172,7 @@ public: return *this; } TLockedToken(const CToken& other) : TCachedToken(other) { CToken::Lock(); } - TLockedToken& operator=(const CToken& other) { + TLockedToken& operator=(const CToken& other) override { CToken oldTok = std::move(*this); TCachedToken::operator=(other); CToken::Lock(); diff --git a/Runtime/Camera/CCameraManager.hpp b/Runtime/Camera/CCameraManager.hpp index 0bcf5c4c4..d3c2f2204 100644 --- a/Runtime/Camera/CCameraManager.hpp +++ b/Runtime/Camera/CCameraManager.hpp @@ -80,7 +80,7 @@ class CCameraManager { void EnterCinematic(CStateManager& mgr); public: - CCameraManager(TUniqueId curCameraId = kInvalidUniqueId); + explicit CCameraManager(TUniqueId curCameraId = kInvalidUniqueId); static float Aspect() { return 1.42f; } static float FarPlane() { return 750.0f; } diff --git a/Runtime/Camera/CCameraShakeData.hpp b/Runtime/Camera/CCameraShakeData.hpp index e425fa913..94e22cdbe 100644 --- a/Runtime/Camera/CCameraShakeData.hpp +++ b/Runtime/Camera/CCameraShakeData.hpp @@ -61,7 +61,7 @@ public: const CCameraShakerComponent& shaker1, const CCameraShakerComponent& shaker2, const CCameraShakerComponent& shaker3); CCameraShakeData(float duration, float magnitude); - CCameraShakeData(CInputStream&); + explicit CCameraShakeData(CInputStream&); static CCameraShakeData BuildLandingCameraShakeData(float duration, float magnitude); static CCameraShakeData BuildProjectileCameraShake(float duration, float magnitude); static CCameraShakeData BuildMissileCameraShake(float duration, float magnitude, float sfxDistance, diff --git a/Runtime/Camera/CCinematicCamera.cpp b/Runtime/Camera/CCinematicCamera.cpp index 505f2218e..fc98ad994 100644 --- a/Runtime/Camera/CCinematicCamera.cpp +++ b/Runtime/Camera/CCinematicCamera.cpp @@ -296,11 +296,11 @@ void CCinematicCamera::GenerateMoveOutofIntoPoints(bool outOfEye, CStateManager& behindDelta = -behindDelta; } for (int i = 0; i < 2; ++i) { - x188_viewPoints.push_back(behindPos); - x198_viewOrientations.push_back(q); - x1a8_viewPointArrivals.push_back(mgr.GetPlayer().GetUniqueId()); - x1b8_targets.push_back(eyePos); - x1c8_targetArrivals.push_back(kInvalidUniqueId); + x188_viewPoints.emplace_back(behindPos); + x198_viewOrientations.emplace_back(q); + x1a8_viewPointArrivals.emplace_back(mgr.GetPlayer().GetUniqueId()); + x1b8_targets.emplace_back(eyePos); + x1c8_targetArrivals.emplace_back(kInvalidUniqueId); behindPos += behindDelta; } CalculateMoveOutofIntoEyePosition(outOfEye, mgr); diff --git a/Runtime/Camera/CInterpolationCamera.hpp b/Runtime/Camera/CInterpolationCamera.hpp index 260b47203..395efe605 100644 --- a/Runtime/Camera/CInterpolationCamera.hpp +++ b/Runtime/Camera/CInterpolationCamera.hpp @@ -26,7 +26,7 @@ class CInterpolationCamera : public CGameCamera { float maxTime, float curTime); public: - CInterpolationCamera(TUniqueId uid, const zeus::CTransform& xf); + explicit CInterpolationCamera(TUniqueId uid, const zeus::CTransform& xf); void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) override; void ProcessInput(const CFinalInput&, CStateManager& mgr) override; diff --git a/Runtime/Character/CAdditiveAnimPlayback.hpp b/Runtime/Character/CAdditiveAnimPlayback.hpp index 582bbeb48..637a287d8 100644 --- a/Runtime/Character/CAdditiveAnimPlayback.hpp +++ b/Runtime/Character/CAdditiveAnimPlayback.hpp @@ -20,7 +20,7 @@ public: x4_fadeOutDur = in.readFloatBig(); } CAdditiveAnimationInfo() = default; - CAdditiveAnimationInfo(CInputStream& in) { read(in); } + explicit CAdditiveAnimationInfo(CInputStream& in) { read(in); } float GetFadeInDuration() const { return x0_fadeInDur; } float GetFadeOutDuration() const { return x4_fadeOutDur; } }; diff --git a/Runtime/Character/CAllFormatsAnimSource.hpp b/Runtime/Character/CAllFormatsAnimSource.hpp index 862c7bd4f..b8a60f9e8 100644 --- a/Runtime/Character/CAllFormatsAnimSource.hpp +++ b/Runtime/Character/CAllFormatsAnimSource.hpp @@ -26,7 +26,7 @@ class CAnimFormatUnion { static void SubConstruct(u8* storage, EAnimFormat fmt, CInputStream& in, IObjectStore& store); public: - CAnimFormatUnion(CInputStream& in, IObjectStore& store); + explicit CAnimFormatUnion(CInputStream& in, IObjectStore& store); ~CAnimFormatUnion(); EAnimFormat GetFormat() const { return x0_format; } CAnimSource& GetAsCAnimSource() { return *reinterpret_cast(x4_storage); } @@ -40,7 +40,7 @@ class CAllFormatsAnimSource : public CAnimFormatUnion { SObjectTag x74_tag; public: - CAllFormatsAnimSource(CInputStream& in, IObjectStore& store, const SObjectTag& tag); + explicit CAllFormatsAnimSource(CInputStream& in, IObjectStore& store, const SObjectTag& tag); static std::shared_ptr GetNewReader(const TLockedToken& tok, const CCharAnimTime& startTime); }; diff --git a/Runtime/Character/CAnimCharacterSet.hpp b/Runtime/Character/CAnimCharacterSet.hpp index 749abeb31..94bba47cf 100644 --- a/Runtime/Character/CAnimCharacterSet.hpp +++ b/Runtime/Character/CAnimCharacterSet.hpp @@ -12,7 +12,7 @@ class CAnimCharacterSet { CAnimationSet x1c_animationSet; public: - CAnimCharacterSet(CInputStream& in); + explicit CAnimCharacterSet(CInputStream& in); const CCharacterSet& GetCharacterSet() const { return x4_characterSet; } const CAnimationSet& GetAnimationSet() const { return x1c_animationSet; } }; diff --git a/Runtime/Character/CAnimData.cpp b/Runtime/Character/CAnimData.cpp index c621ed647..f201b064b 100644 --- a/Runtime/Character/CAnimData.cpp +++ b/Runtime/Character/CAnimData.cpp @@ -56,7 +56,7 @@ CAnimData::CAnimData(CAssetId id, const CCharacterInfo& character, int defaultAn , x204_charIdx(charIdx) , x208_defaultAnim(defaultAnim) , x224_pose(layout->GetSegIdList().GetList().size()) -, x2fc_poseBuilder(layout) +, x2fc_poseBuilder(CLayoutDescription{layout}) , m_drawInstCount(drawInstCount) { x220_25_loop = loop; @@ -72,7 +72,7 @@ CAnimData::CAnimData(CAssetId id, const CCharacterInfo& character, int defaultAn x108_aabb = xd8_modelData->GetModel()->GetAABB(); x120_particleDB.CacheParticleDesc(xc_charInfo.GetParticleResData()); - CHierarchyPoseBuilder pb(xcc_layoutData); + CHierarchyPoseBuilder pb(CLayoutDescription{xcc_layoutData}); pb.BuildNoScale(x224_pose); x220_30_poseBuilt = true; diff --git a/Runtime/Character/CAnimData.hpp b/Runtime/Character/CAnimData.hpp index e32385c14..2ea18709b 100644 --- a/Runtime/Character/CAnimData.hpp +++ b/Runtime/Character/CAnimData.hpp @@ -10,11 +10,13 @@ #include "Runtime/Character/CAdditiveAnimPlayback.hpp" #include "Runtime/Character/CAnimPlaybackParms.hpp" #include "Runtime/Character/CCharLayoutInfo.hpp" +#include "Runtime/Character/CCharacterFactory.hpp" #include "Runtime/Character/CCharacterInfo.hpp" #include "Runtime/Character/CHierarchyPoseBuilder.hpp" #include "Runtime/Character/CParticleDatabase.hpp" #include "Runtime/Character/CPoseAsTransforms.hpp" #include "Runtime/Character/IAnimReader.hpp" +#include "Runtime/Graphics/CSkinnedModel.hpp" #include #include @@ -64,7 +66,6 @@ class CAnimationManager; class CBoolPOINode; class CCharAnimTime; class CCharLayoutInfo; -class CCharacterFactory; class CInt32POINode; class CModel; class CMorphableSkinnedModel; @@ -74,7 +75,6 @@ class CRandom16; class CSegIdList; class CSegStatementSet; class CSkinRules; -class CSkinnedModel; class CSoundPOINode; class CStateManager; class CTransitionManager; @@ -251,7 +251,7 @@ public: s32 GetCharacterIndex() const { return x204_charIdx; } u16 GetDefaultAnimation() const { return x208_defaultAnim; } - TLockedToken& IceModel() { return xe4_iceModelData; } + TLockedToken& GetIceModel() { return xe4_iceModelData; } const TLockedToken& GetIceModel() const { return xe4_iceModelData; } void SetParticleLightIdx(s32 idx) { x21c_particleLightIdx = idx; } diff --git a/Runtime/Character/CAnimPOIData.hpp b/Runtime/Character/CAnimPOIData.hpp index 84514f503..577bc688c 100644 --- a/Runtime/Character/CAnimPOIData.hpp +++ b/Runtime/Character/CAnimPOIData.hpp @@ -19,7 +19,7 @@ class CAnimPOIData { std::vector x34_soundNodes; public: - CAnimPOIData(CInputStream& in); + explicit CAnimPOIData(CInputStream& in); const std::vector& GetBoolPOIStream() const { return x4_boolNodes; } const std::vector& GetInt32POIStream() const { return x14_int32Nodes; } diff --git a/Runtime/Character/CAnimSource.hpp b/Runtime/Character/CAnimSource.hpp index 7e093c747..26dc312cb 100644 --- a/Runtime/Character/CAnimSource.hpp +++ b/Runtime/Character/CAnimSource.hpp @@ -39,7 +39,7 @@ public: struct CRotationAndOffsetVectors { std::vector x0_rotations; std::vector x10_offsets; - CRotationAndOffsetVectors(CInputStream& in); + explicit CRotationAndOffsetVectors(CInputStream& in); }; u32 GetFrameSizeInBytes() const; RotationAndOffsetStorage(const CRotationAndOffsetVectors& vectors, u32 frameCount); @@ -61,7 +61,7 @@ class CAnimSource { void CalcAverageVelocity(); public: - CAnimSource(CInputStream& in, IObjectStore& store); + explicit CAnimSource(CInputStream& in, IObjectStore& store); void GetSegStatementSet(const CSegIdList& list, CSegStatementSet& set, const CCharAnimTime& time) const; diff --git a/Runtime/Character/CAnimSourceReader.cpp b/Runtime/Character/CAnimSourceReader.cpp index e9c194da7..29c01fb9e 100644 --- a/Runtime/Character/CAnimSourceReader.cpp +++ b/Runtime/Character/CAnimSourceReader.cpp @@ -172,7 +172,7 @@ u32 CAnimSourceReaderBase::VGetSoundPOIList(const CCharAnimTime& time, CSoundPOI return 0; } -bool CAnimSourceReaderBase::VGetBoolPOIState(const char* name) const { +bool CAnimSourceReaderBase::VGetBoolPOIState(std::string_view name) const { const auto iter = std::find_if(x24_boolStates.cbegin(), x24_boolStates.cend(), [name](const auto& entry) { return entry.first == name; }); @@ -183,7 +183,7 @@ bool CAnimSourceReaderBase::VGetBoolPOIState(const char* name) const { return iter->second; } -s32 CAnimSourceReaderBase::VGetInt32POIState(const char* name) const { +s32 CAnimSourceReaderBase::VGetInt32POIState(std::string_view name) const { const auto iter = std::find_if(x34_int32States.cbegin(), x34_int32States.cend(), [name](const auto& entry) { return entry.first == name; }); @@ -194,7 +194,7 @@ s32 CAnimSourceReaderBase::VGetInt32POIState(const char* name) const { return iter->second; } -CParticleData::EParentedMode CAnimSourceReaderBase::VGetParticlePOIState(const char* name) const { +CParticleData::EParentedMode CAnimSourceReaderBase::VGetParticlePOIState(std::string_view name) const { const auto iter = std::find_if(x44_particleStates.cbegin(), x44_particleStates.cend(), [name](const auto& entry) { return entry.first == name; }); diff --git a/Runtime/Character/CAnimSourceReader.hpp b/Runtime/Character/CAnimSourceReader.hpp index 5b55e5fb7..2628f3655 100644 --- a/Runtime/Character/CAnimSourceReader.hpp +++ b/Runtime/Character/CAnimSourceReader.hpp @@ -68,9 +68,9 @@ public: u32) const override; u32 VGetSoundPOIList(const CCharAnimTime& time, CSoundPOINode* listOut, u32 capacity, u32 iterator, u32) const override; - bool VGetBoolPOIState(const char* name) const override; - s32 VGetInt32POIState(const char* name) const override; - CParticleData::EParentedMode VGetParticlePOIState(const char* name) const override; + bool VGetBoolPOIState(std::string_view name) const override; + s32 VGetInt32POIState(std::string_view name) const override; + CParticleData::EParentedMode VGetParticlePOIState(std::string_view name) const override; using IAnimReader::VGetOffset; virtual zeus::CVector3f VGetOffset(const CSegId& seg, const CCharAnimTime& b) const = 0; diff --git a/Runtime/Character/CAnimTreeAnimReaderContainer.cpp b/Runtime/Character/CAnimTreeAnimReaderContainer.cpp index a7105b6ab..f508095a8 100644 --- a/Runtime/Character/CAnimTreeAnimReaderContainer.cpp +++ b/Runtime/Character/CAnimTreeAnimReaderContainer.cpp @@ -58,15 +58,15 @@ u32 CAnimTreeAnimReaderContainer::VGetSoundPOIList(const CCharAnimTime& time, CS return x14_reader->GetSoundPOIList(time, listOut, capacity, iterator, unk); } -bool CAnimTreeAnimReaderContainer::VGetBoolPOIState(const char* name) const { +bool CAnimTreeAnimReaderContainer::VGetBoolPOIState(std::string_view name) const { return x14_reader->VGetBoolPOIState(name); } -s32 CAnimTreeAnimReaderContainer::VGetInt32POIState(const char* name) const { - return x14_reader->VGetBoolPOIState(name); +s32 CAnimTreeAnimReaderContainer::VGetInt32POIState(std::string_view name) const { + return x14_reader->VGetInt32POIState(name); } -CParticleData::EParentedMode CAnimTreeAnimReaderContainer::VGetParticlePOIState(const char* name) const { +CParticleData::EParentedMode CAnimTreeAnimReaderContainer::VGetParticlePOIState(std::string_view name) const { return x14_reader->VGetParticlePOIState(name); } diff --git a/Runtime/Character/CAnimTreeAnimReaderContainer.hpp b/Runtime/Character/CAnimTreeAnimReaderContainer.hpp index aec904573..5df66319e 100644 --- a/Runtime/Character/CAnimTreeAnimReaderContainer.hpp +++ b/Runtime/Character/CAnimTreeAnimReaderContainer.hpp @@ -37,9 +37,9 @@ public: u32) const override; u32 VGetSoundPOIList(const CCharAnimTime& time, CSoundPOINode* listOut, u32 capacity, u32 iterator, u32) const override; - bool VGetBoolPOIState(const char*) const override; - s32 VGetInt32POIState(const char*) const override; - CParticleData::EParentedMode VGetParticlePOIState(const char*) const override; + bool VGetBoolPOIState(std::string_view name) const override; + s32 VGetInt32POIState(std::string_view name) const override; + CParticleData::EParentedMode VGetParticlePOIState(std::string_view name) const override; void VGetSegStatementSet(const CSegIdList& list, CSegStatementSet& setOut) const override; void VGetSegStatementSet(const CSegIdList& list, CSegStatementSet& setOut, const CCharAnimTime& time) const override; std::unique_ptr VClone() const override; diff --git a/Runtime/Character/CAnimTreeDoubleChild.cpp b/Runtime/Character/CAnimTreeDoubleChild.cpp index 5c3b1e69f..bd401390a 100644 --- a/Runtime/Character/CAnimTreeDoubleChild.cpp +++ b/Runtime/Character/CAnimTreeDoubleChild.cpp @@ -101,11 +101,11 @@ u32 CAnimTreeDoubleChild::VGetSoundPOIList(const CCharAnimTime& time, CSoundPOIN return newCapacity; } -bool CAnimTreeDoubleChild::VGetBoolPOIState(const char* name) const { return x18_b->VGetBoolPOIState(name); } +bool CAnimTreeDoubleChild::VGetBoolPOIState(std::string_view name) const { return x18_b->VGetBoolPOIState(name); } -s32 CAnimTreeDoubleChild::VGetInt32POIState(const char* name) const { return x18_b->VGetBoolPOIState(name); } +s32 CAnimTreeDoubleChild::VGetInt32POIState(std::string_view name) const { return x18_b->VGetInt32POIState(name); } -CParticleData::EParentedMode CAnimTreeDoubleChild::VGetParticlePOIState(const char* name) const { +CParticleData::EParentedMode CAnimTreeDoubleChild::VGetParticlePOIState(std::string_view name) const { return x18_b->VGetParticlePOIState(name); } diff --git a/Runtime/Character/CAnimTreeDoubleChild.hpp b/Runtime/Character/CAnimTreeDoubleChild.hpp index 22c4b36e2..aa54957c9 100644 --- a/Runtime/Character/CAnimTreeDoubleChild.hpp +++ b/Runtime/Character/CAnimTreeDoubleChild.hpp @@ -41,9 +41,9 @@ public: u32) const override; u32 VGetSoundPOIList(const CCharAnimTime& time, CSoundPOINode* listOut, u32 capacity, u32 iterator, u32) const override; - bool VGetBoolPOIState(const char* name) const override; - s32 VGetInt32POIState(const char* name) const override; - CParticleData::EParentedMode VGetParticlePOIState(const char* name) const override; + bool VGetBoolPOIState(std::string_view name) const override; + s32 VGetInt32POIState(std::string_view name) const override; + CParticleData::EParentedMode VGetParticlePOIState(std::string_view name) const override; void VSetPhase(float) override; SAdvancementResults VGetAdvancementResults(const CCharAnimTime& a, const CCharAnimTime& b) const override; u32 Depth() const override; diff --git a/Runtime/Character/CAnimTreeNode.hpp b/Runtime/Character/CAnimTreeNode.hpp index 61906c067..d18b94eb9 100644 --- a/Runtime/Character/CAnimTreeNode.hpp +++ b/Runtime/Character/CAnimTreeNode.hpp @@ -14,7 +14,7 @@ protected: std::string x4_name; public: - CAnimTreeNode(std::string_view name) : x4_name(name) {} + explicit CAnimTreeNode(std::string_view name) : x4_name(name) {} bool IsCAnimTreeNode() const override { return true; } static std::shared_ptr Cast(std::unique_ptr&& ptr) { if (ptr->IsCAnimTreeNode()) diff --git a/Runtime/Character/CAnimTreeSingleChild.cpp b/Runtime/Character/CAnimTreeSingleChild.cpp index a7c9bf851..258225459 100644 --- a/Runtime/Character/CAnimTreeSingleChild.cpp +++ b/Runtime/Character/CAnimTreeSingleChild.cpp @@ -35,11 +35,11 @@ u32 CAnimTreeSingleChild::VGetSoundPOIList(const CCharAnimTime& time, CSoundPOIN return x14_child->GetSoundPOIList(time, listOut, capacity, iterator, unk); } -bool CAnimTreeSingleChild::VGetBoolPOIState(const char* name) const { return x14_child->VGetBoolPOIState(name); } +bool CAnimTreeSingleChild::VGetBoolPOIState(std::string_view name) const { return x14_child->VGetBoolPOIState(name); } -s32 CAnimTreeSingleChild::VGetInt32POIState(const char* name) const { return x14_child->VGetInt32POIState(name); } +s32 CAnimTreeSingleChild::VGetInt32POIState(std::string_view name) const { return x14_child->VGetInt32POIState(name); } -CParticleData::EParentedMode CAnimTreeSingleChild::VGetParticlePOIState(const char* name) const { +CParticleData::EParentedMode CAnimTreeSingleChild::VGetParticlePOIState(std::string_view name) const { return x14_child->VGetParticlePOIState(name); } diff --git a/Runtime/Character/CAnimTreeSingleChild.hpp b/Runtime/Character/CAnimTreeSingleChild.hpp index 1158de80e..801ef9e97 100644 --- a/Runtime/Character/CAnimTreeSingleChild.hpp +++ b/Runtime/Character/CAnimTreeSingleChild.hpp @@ -27,9 +27,9 @@ public: u32) const override; u32 VGetSoundPOIList(const CCharAnimTime& time, CSoundPOINode* listOut, u32 capacity, u32 iterator, u32) const override; - bool VGetBoolPOIState(const char* name) const override; - s32 VGetInt32POIState(const char* name) const override; - CParticleData::EParentedMode VGetParticlePOIState(const char* name) const override; + bool VGetBoolPOIState(std::string_view name) const override; + s32 VGetInt32POIState(std::string_view name) const override; + CParticleData::EParentedMode VGetParticlePOIState(std::string_view name) const override; void VGetSegStatementSet(const CSegIdList& list, CSegStatementSet& setOut) const override; void VGetSegStatementSet(const CSegIdList& list, CSegStatementSet& setOut, const CCharAnimTime& time) const override; void VSetPhase(float) override; diff --git a/Runtime/Character/CAnimTreeTimeScale.cpp b/Runtime/Character/CAnimTreeTimeScale.cpp index dbf5a754f..c1651e289 100644 --- a/Runtime/Character/CAnimTreeTimeScale.cpp +++ b/Runtime/Character/CAnimTreeTimeScale.cpp @@ -99,11 +99,11 @@ u32 CAnimTreeTimeScale::VGetSoundPOIList(const CCharAnimTime& time, CSoundPOINod return ret; } -bool CAnimTreeTimeScale::VGetBoolPOIState(const char* name) const { return x14_child->VGetBoolPOIState(name); } +bool CAnimTreeTimeScale::VGetBoolPOIState(std::string_view name) const { return x14_child->VGetBoolPOIState(name); } -s32 CAnimTreeTimeScale::VGetInt32POIState(const char* name) const { return x14_child->VGetInt32POIState(name); } +s32 CAnimTreeTimeScale::VGetInt32POIState(std::string_view name) const { return x14_child->VGetInt32POIState(name); } -CParticleData::EParentedMode CAnimTreeTimeScale::VGetParticlePOIState(const char* name) const { +CParticleData::EParentedMode CAnimTreeTimeScale::VGetParticlePOIState(std::string_view name) const { return x14_child->VGetParticlePOIState(name); } diff --git a/Runtime/Character/CAnimTreeTimeScale.hpp b/Runtime/Character/CAnimTreeTimeScale.hpp index a4ba6d016..7439b55de 100644 --- a/Runtime/Character/CAnimTreeTimeScale.hpp +++ b/Runtime/Character/CAnimTreeTimeScale.hpp @@ -34,9 +34,9 @@ public: u32) const override; u32 VGetSoundPOIList(const CCharAnimTime& time, CSoundPOINode* listOut, u32 capacity, u32 iterator, u32) const override; - bool VGetBoolPOIState(const char* name) const override; - s32 VGetInt32POIState(const char* name) const override; - CParticleData::EParentedMode VGetParticlePOIState(const char* name) const override; + bool VGetBoolPOIState(std::string_view name) const override; + s32 VGetInt32POIState(std::string_view name) const override; + CParticleData::EParentedMode VGetParticlePOIState(std::string_view name) const override; CAnimTreeEffectiveContribution VGetContributionOfHighestInfluence() const override; std::shared_ptr VGetBestUnblendedChild() const override; diff --git a/Runtime/Character/CAnimation.hpp b/Runtime/Character/CAnimation.hpp index 228284130..be592bbb4 100644 --- a/Runtime/Character/CAnimation.hpp +++ b/Runtime/Character/CAnimation.hpp @@ -14,7 +14,7 @@ class CAnimation { std::shared_ptr x10_anim; public: - CAnimation(CInputStream& in); + explicit CAnimation(CInputStream& in); const std::shared_ptr& GetMetaAnim() const { return x10_anim; } std::string_view GetMetaAnimName() const { return x0_name; } }; diff --git a/Runtime/Character/CAnimationDatabaseGame.hpp b/Runtime/Character/CAnimationDatabaseGame.hpp index 9d28a708c..f4051b01a 100644 --- a/Runtime/Character/CAnimationDatabaseGame.hpp +++ b/Runtime/Character/CAnimationDatabaseGame.hpp @@ -12,7 +12,7 @@ class CAnimationDatabaseGame final : public CAnimationDatabase { std::vector> x10_anims; public: - CAnimationDatabaseGame(const std::vector& anims); + explicit CAnimationDatabaseGame(const std::vector& anims); const std::shared_ptr& GetMetaAnim(s32 idx) const override; u32 GetNumMetaAnims() const override; const char* GetMetaAnimName(s32 idx) const override; diff --git a/Runtime/Character/CAnimationSet.hpp b/Runtime/Character/CAnimationSet.hpp index c7b58929b..55ae41fba 100644 --- a/Runtime/Character/CAnimationSet.hpp +++ b/Runtime/Character/CAnimationSet.hpp @@ -24,7 +24,7 @@ class CAnimationSet { std::vector> x50_animRes; public: - CAnimationSet(CInputStream& in); + explicit CAnimationSet(CInputStream& in); const std::vector& GetAnimations() const { return x4_animations; } const std::vector& GetTransitions() const { return x14_transitions; } diff --git a/Runtime/Character/CBodyState.hpp b/Runtime/Character/CBodyState.hpp index ed8a97ace..24f74799f 100644 --- a/Runtime/Character/CBodyState.hpp +++ b/Runtime/Character/CBodyState.hpp @@ -105,7 +105,7 @@ class CBSLieOnGround : public CBodyState { pas::EAnimationState GetBodyStateTransition(float dt, CBodyController& bc) const; public: - CBSLieOnGround(CActor& actor); + explicit CBSLieOnGround(CActor& actor); void Start(CBodyController& bc, CStateManager& mgr) override; pas::EAnimationState UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) override; void Shutdown(CBodyController& bc) override; @@ -371,7 +371,7 @@ protected: } public: - CBSBiPedLocomotion(CActor& actor); + explicit CBSBiPedLocomotion(CActor& actor); bool IsMoving() const override { return x3c4_anim != pas::ELocomotionAnim::Idle; } void Start(CBodyController& bc, CStateManager& mgr) override; pas::EAnimationState UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) override; @@ -384,7 +384,7 @@ class CBSFlyerLocomotion : public CBSBiPedLocomotion { bool x3cc_pitchable; public: - CBSFlyerLocomotion(CActor& actor, bool pitchable); + explicit CBSFlyerLocomotion(CActor& actor, bool pitchable); bool IsPitchable() const override { return x3cc_pitchable; } float ApplyLocomotionPhysics(float dt, CBodyController& bc) override; virtual bool IsBackPedal(CBodyController& bc) const { return false; } @@ -392,13 +392,13 @@ public: class CBSWallWalkerLocomotion : public CBSBiPedLocomotion { public: - CBSWallWalkerLocomotion(CActor& actor); + explicit CBSWallWalkerLocomotion(CActor& actor); float ApplyLocomotionPhysics(float dt, CBodyController& bc) override; }; class CBSNewFlyerLocomotion : public CBSBiPedLocomotion { public: - CBSNewFlyerLocomotion(CActor& actor); + explicit CBSNewFlyerLocomotion(CActor& actor); float ApplyLocomotionPhysics(float dt, CBodyController& bc) override; float UpdateLocomotionAnimation(float dt, float velMag, CBodyController& bc, bool init) override; }; @@ -408,7 +408,7 @@ class CBSRestrictedLocomotion : public CBSLocomotion { pas::ELocomotionAnim x44_anim = pas::ELocomotionAnim::Invalid; public: - CBSRestrictedLocomotion(CActor& actor); + explicit CBSRestrictedLocomotion(CActor& actor); bool IsMoving() const override { return false; } float GetLocomotionSpeed(pas::ELocomotionType type, pas::ELocomotionAnim anim) const override { return 0.f; } float UpdateLocomotionAnimation(float dt, float velMag, CBodyController& bc, bool init) override; @@ -416,7 +416,7 @@ public: class CBSRestrictedFlyerLocomotion : public CBSRestrictedLocomotion { public: - CBSRestrictedFlyerLocomotion(CActor& actor); + explicit CBSRestrictedFlyerLocomotion(CActor& actor); float ApplyLocomotionPhysics(float dt, CBodyController& bc) override; }; } // namespace urde diff --git a/Runtime/Character/CBodyStateCmdMgr.hpp b/Runtime/Character/CBodyStateCmdMgr.hpp index 717c686cd..a6ba84eef 100644 --- a/Runtime/Character/CBodyStateCmdMgr.hpp +++ b/Runtime/Character/CBodyStateCmdMgr.hpp @@ -13,7 +13,7 @@ class CBodyStateCmd { public: virtual ~CBodyStateCmd() = default; - CBodyStateCmd(EBodyStateCmd cmd) : x4_cmd(cmd) {} + explicit CBodyStateCmd(EBodyStateCmd cmd) : x4_cmd(cmd) {} EBodyStateCmd GetCommandId() const { return x4_cmd; } }; @@ -23,10 +23,11 @@ class CBCMeleeAttackCmd : public CBodyStateCmd { bool x18_hasTargetPos = false; public: - CBCMeleeAttackCmd() : CBodyStateCmd(EBodyStateCmd::MeleeAttack) {} - CBCMeleeAttackCmd(pas::ESeverity severity) : CBodyStateCmd(EBodyStateCmd::MeleeAttack), x8_severity(severity) {} - CBCMeleeAttackCmd(pas::ESeverity severity, const zeus::CVector3f& target) : CBodyStateCmd(EBodyStateCmd::MeleeAttack) - , x8_severity(severity), xc_targetPos(target), x18_hasTargetPos(true) {} + explicit CBCMeleeAttackCmd() : CBodyStateCmd(EBodyStateCmd::MeleeAttack) {} + explicit CBCMeleeAttackCmd(pas::ESeverity severity) + : CBodyStateCmd(EBodyStateCmd::MeleeAttack), x8_severity(severity) {} + explicit CBCMeleeAttackCmd(pas::ESeverity severity, const zeus::CVector3f& target) + : CBodyStateCmd(EBodyStateCmd::MeleeAttack), x8_severity(severity), xc_targetPos(target), x18_hasTargetPos(true) {} pas::ESeverity GetAttackSeverity() const { return x8_severity; } bool HasAttackTargetPos() const { return x18_hasTargetPos; } const zeus::CVector3f& GetAttackTargetPos() const { return xc_targetPos; } @@ -38,8 +39,8 @@ class CBCProjectileAttackCmd : public CBodyStateCmd { bool x18_blendAnims = false; public: - CBCProjectileAttackCmd() : CBodyStateCmd(EBodyStateCmd::ProjectileAttack) {} - CBCProjectileAttackCmd(pas::ESeverity severity, const zeus::CVector3f& vec, bool b) + explicit CBCProjectileAttackCmd() : CBodyStateCmd(EBodyStateCmd::ProjectileAttack) {} + explicit CBCProjectileAttackCmd(pas::ESeverity severity, const zeus::CVector3f& vec, bool b) : CBodyStateCmd(EBodyStateCmd::ProjectileAttack), x8_severity(severity), xc_target(vec), x18_blendAnims(b) {} pas::ESeverity GetAttackSeverity() const { return x8_severity; } const zeus::CVector3f& GetTargetPosition() const { return xc_target; } @@ -51,8 +52,8 @@ class CBCStepCmd : public CBodyStateCmd { pas::EStepType xc_type = pas::EStepType::Normal; public: - CBCStepCmd() : CBodyStateCmd(EBodyStateCmd::Step) {} - CBCStepCmd(pas::EStepDirection dir, pas::EStepType type) + explicit CBCStepCmd() : CBodyStateCmd(EBodyStateCmd::Step) {} + explicit CBCStepCmd(pas::EStepDirection dir, pas::EStepType type) : CBodyStateCmd(EBodyStateCmd::Step), x8_dir(dir), xc_type(type) {} pas::EStepDirection GetStepDirection() const { return x8_dir; } pas::EStepType GetStepType() const { return xc_type; } @@ -66,16 +67,16 @@ class CBCJumpCmd : public CBodyStateCmd { bool x24_25_startInJumpLoop : 1; public: - CBCJumpCmd() : CBodyStateCmd(EBodyStateCmd::Jump) { + explicit CBCJumpCmd() : CBodyStateCmd(EBodyStateCmd::Jump) { x24_24_wallJump = false; x24_25_startInJumpLoop = false; } - CBCJumpCmd(const zeus::CVector3f& wp1, pas::EJumpType type, bool startInLoop = false) + explicit CBCJumpCmd(const zeus::CVector3f& wp1, pas::EJumpType type, bool startInLoop = false) : CBodyStateCmd(EBodyStateCmd::Jump), x8_type(type), xc_waypoint1(wp1) { x24_24_wallJump = false; x24_25_startInJumpLoop = startInLoop; } - CBCJumpCmd(const zeus::CVector3f& wp1, const zeus::CVector3f& wp2, pas::EJumpType type) + explicit CBCJumpCmd(const zeus::CVector3f& wp1, const zeus::CVector3f& wp2, pas::EJumpType type) : CBodyStateCmd(EBodyStateCmd::Jump), x8_type(type), xc_waypoint1(wp1), x18_waypoint2(wp2) { x24_24_wallJump = true; x24_25_startInJumpLoop = false; @@ -95,22 +96,22 @@ class CBCGenerateCmd : public CBodyStateCmd { bool x1c_25_overrideAnim : 1; public: - CBCGenerateCmd() : CBodyStateCmd(EBodyStateCmd::Generate) { + explicit CBCGenerateCmd() : CBodyStateCmd(EBodyStateCmd::Generate) { x1c_24_targetTransform = false; x1c_25_overrideAnim = false; } - CBCGenerateCmd(pas::EGenerateType type) + explicit CBCGenerateCmd(pas::EGenerateType type) : CBodyStateCmd(EBodyStateCmd::Generate), x8_type(type) { x1c_24_targetTransform = false; x1c_25_overrideAnim = false; } - CBCGenerateCmd(pas::EGenerateType type, s32 animId) + explicit CBCGenerateCmd(pas::EGenerateType type, s32 animId) : CBodyStateCmd(EBodyStateCmd::Generate), x8_type(type), x18_animId(animId) { x1c_24_targetTransform = false; x1c_25_overrideAnim = animId != -1; } - CBCGenerateCmd(pas::EGenerateType type, const zeus::CVector3f& vec, bool targetTransform = false, - bool overrideAnim = false) + explicit CBCGenerateCmd(pas::EGenerateType type, const zeus::CVector3f& vec, bool targetTransform = false, + bool overrideAnim = false) : CBodyStateCmd(EBodyStateCmd::Generate), x8_type(type), xc_targetPos(vec) { x1c_24_targetTransform = targetTransform; x1c_25_overrideAnim = overrideAnim; @@ -127,8 +128,8 @@ class CBCKnockBackCmd : public CBodyStateCmd { pas::ESeverity x14_severity = pas::ESeverity::Invalid; public: - CBCKnockBackCmd() : CBodyStateCmd(EBodyStateCmd::KnockBack) {} - CBCKnockBackCmd(const zeus::CVector3f& vec, pas::ESeverity severity) + explicit CBCKnockBackCmd() : CBodyStateCmd(EBodyStateCmd::KnockBack) {} + explicit CBCKnockBackCmd(const zeus::CVector3f& vec, pas::ESeverity severity) : CBodyStateCmd(EBodyStateCmd::KnockBack), x8_dir(vec), x14_severity(severity) {} const zeus::CVector3f& GetHitDirection() const { return x8_dir; } pas::ESeverity GetHitSeverity() const { return x14_severity; } @@ -140,8 +141,8 @@ class CBCHurledCmd : public CBodyStateCmd { bool x20_startInKnockLoop = false; public: - CBCHurledCmd() : CBodyStateCmd(EBodyStateCmd::Hurled) {} - CBCHurledCmd(const zeus::CVector3f& dir, const zeus::CVector3f& launchVel, bool startInLoop = false) + explicit CBCHurledCmd() : CBodyStateCmd(EBodyStateCmd::Hurled) {} + explicit CBCHurledCmd(const zeus::CVector3f& dir, const zeus::CVector3f& launchVel, bool startInLoop = false) : CBodyStateCmd(EBodyStateCmd::Hurled) , x8_direction(dir) , x14_launchVel(launchVel) @@ -156,8 +157,8 @@ class CBCGetupCmd : public CBodyStateCmd { pas::EGetupType x8_type = pas::EGetupType::Invalid; public: - CBCGetupCmd() : CBodyStateCmd(EBodyStateCmd::Getup) {} - CBCGetupCmd(pas::EGetupType type) : CBodyStateCmd(EBodyStateCmd::Getup), x8_type(type) {} + explicit CBCGetupCmd() : CBodyStateCmd(EBodyStateCmd::Getup) {} + explicit CBCGetupCmd(pas::EGetupType type) : CBodyStateCmd(EBodyStateCmd::Getup), x8_type(type) {} pas::EGetupType GetGetupType() const { return x8_type; } }; @@ -165,8 +166,8 @@ class CBCLoopReactionCmd : public CBodyStateCmd { pas::EReactionType x8_type = pas::EReactionType::Invalid; public: - CBCLoopReactionCmd() : CBodyStateCmd(EBodyStateCmd::LoopReaction) {} - CBCLoopReactionCmd(pas::EReactionType type) : CBodyStateCmd(EBodyStateCmd::LoopReaction), x8_type(type) {} + explicit CBCLoopReactionCmd() : CBodyStateCmd(EBodyStateCmd::LoopReaction) {} + explicit CBCLoopReactionCmd(pas::EReactionType type) : CBodyStateCmd(EBodyStateCmd::LoopReaction), x8_type(type) {} pas::EReactionType GetReactionType() const { return x8_type; } }; @@ -174,8 +175,8 @@ class CBCLoopHitReactionCmd : public CBodyStateCmd { pas::EReactionType x8_type = pas::EReactionType::Invalid; public: - CBCLoopHitReactionCmd() : CBodyStateCmd(EBodyStateCmd::LoopHitReaction) {} - CBCLoopHitReactionCmd(pas::EReactionType type) : CBodyStateCmd(EBodyStateCmd::LoopHitReaction), x8_type(type) {} + explicit CBCLoopHitReactionCmd() : CBodyStateCmd(EBodyStateCmd::LoopHitReaction) {} + explicit CBCLoopHitReactionCmd(pas::EReactionType type) : CBodyStateCmd(EBodyStateCmd::LoopHitReaction), x8_type(type) {} pas::EReactionType GetReactionType() const { return x8_type; } }; @@ -184,8 +185,8 @@ class CBCKnockDownCmd : public CBodyStateCmd { pas::ESeverity x14_severity = pas::ESeverity::Invalid; public: - CBCKnockDownCmd() : CBodyStateCmd(EBodyStateCmd::KnockDown) {} - CBCKnockDownCmd(const zeus::CVector3f& vec, pas::ESeverity severity) + explicit CBCKnockDownCmd() : CBodyStateCmd(EBodyStateCmd::KnockDown) {} + explicit CBCKnockDownCmd(const zeus::CVector3f& vec, pas::ESeverity severity) : CBodyStateCmd(EBodyStateCmd::KnockDown), x8_dir(vec), x14_severity(severity) {} const zeus::CVector3f& GetHitDirection() const { return x8_dir; } pas::ESeverity GetHitSeverity() const { return x14_severity; } @@ -196,8 +197,8 @@ class CBCSlideCmd : public CBodyStateCmd { zeus::CVector3f xc_dir; public: - CBCSlideCmd() : CBodyStateCmd(EBodyStateCmd::Slide) {} - CBCSlideCmd(pas::ESlideType type, const zeus::CVector3f& dir) + explicit CBCSlideCmd() : CBodyStateCmd(EBodyStateCmd::Slide) {} + explicit CBCSlideCmd(pas::ESlideType type, const zeus::CVector3f& dir) : CBodyStateCmd(EBodyStateCmd::Slide), x8_type(type), xc_dir(dir) {} pas::ESlideType GetSlideType() const { return x8_type; } const zeus::CVector3f& GetSlideDirection() const { return xc_dir; } @@ -210,11 +211,11 @@ class CBCScriptedCmd : public CBodyStateCmd { float x10_loopDur = 0.f; public: - CBCScriptedCmd() : CBodyStateCmd(EBodyStateCmd::Scripted) { + explicit CBCScriptedCmd() : CBodyStateCmd(EBodyStateCmd::Scripted) { xc_24_loopAnim = false; xc_25_timedLoop = false; } - CBCScriptedCmd(int i, bool b1, bool b2, float f) + explicit CBCScriptedCmd(int i, bool b1, bool b2, float f) : CBodyStateCmd(EBodyStateCmd::Scripted), x8_anim(i), x10_loopDur(f) { xc_24_loopAnim = b1; xc_25_timedLoop = b2; @@ -231,8 +232,8 @@ class CBCCoverCmd : public CBodyStateCmd { zeus::CVector3f x18_alignDir; public: - CBCCoverCmd() : CBodyStateCmd(EBodyStateCmd::Cover) {} - CBCCoverCmd(pas::ECoverDirection dir, const zeus::CVector3f& v1, const zeus::CVector3f& v2) + explicit CBCCoverCmd() : CBodyStateCmd(EBodyStateCmd::Cover) {} + explicit CBCCoverCmd(pas::ECoverDirection dir, const zeus::CVector3f& v1, const zeus::CVector3f& v2) : CBodyStateCmd(EBodyStateCmd::Cover), x8_dir(dir), xc_targetPos(v1), x18_alignDir(v2) {} pas::ECoverDirection GetDirection() const { return x8_dir; } const zeus::CVector3f& GetTarget() const { return xc_targetPos; } @@ -243,22 +244,22 @@ class CBCWallHangCmd : public CBodyStateCmd { TUniqueId x8_wpId = kInvalidUniqueId; public: - CBCWallHangCmd() : CBodyStateCmd(EBodyStateCmd::WallHang) {} - CBCWallHangCmd(TUniqueId uid) : CBodyStateCmd(EBodyStateCmd::WallHang), x8_wpId(uid) {} + explicit CBCWallHangCmd() : CBodyStateCmd(EBodyStateCmd::WallHang) {} + explicit CBCWallHangCmd(TUniqueId uid) : CBodyStateCmd(EBodyStateCmd::WallHang), x8_wpId(uid) {} TUniqueId GetTarget() const { return x8_wpId; } }; class CBCAdditiveAimCmd : public CBodyStateCmd { public: - CBCAdditiveAimCmd() : CBodyStateCmd(EBodyStateCmd::AdditiveAim) {} + explicit CBCAdditiveAimCmd() : CBodyStateCmd(EBodyStateCmd::AdditiveAim) {} }; class CBCAdditiveFlinchCmd : public CBodyStateCmd { float x8_weight = 1.f; public: - CBCAdditiveFlinchCmd() : CBodyStateCmd(EBodyStateCmd::AdditiveFlinch) {} - CBCAdditiveFlinchCmd(float f) : CBodyStateCmd(EBodyStateCmd::AdditiveFlinch), x8_weight(f) {} + explicit CBCAdditiveFlinchCmd() : CBodyStateCmd(EBodyStateCmd::AdditiveFlinch) {} + explicit CBCAdditiveFlinchCmd(float f) : CBodyStateCmd(EBodyStateCmd::AdditiveFlinch), x8_weight(f) {} float GetWeight() const { return x8_weight; } }; @@ -268,9 +269,9 @@ class CBCAdditiveReactionCmd : public CBodyStateCmd { bool x10_active = false; public: - CBCAdditiveReactionCmd() : CBodyStateCmd(EBodyStateCmd::AdditiveReaction) {} - CBCAdditiveReactionCmd(pas::EAdditiveReactionType type, float f, bool active) - : CBodyStateCmd(EBodyStateCmd::AdditiveReaction), x8_weight(f), xc_type(type), x10_active(active) {} + explicit CBCAdditiveReactionCmd() : CBodyStateCmd(EBodyStateCmd::AdditiveReaction) {} + explicit CBCAdditiveReactionCmd(pas::EAdditiveReactionType type, float weight, bool active) + : CBodyStateCmd(EBodyStateCmd::AdditiveReaction), x8_weight(weight), xc_type(type), x10_active(active) {} pas::EAdditiveReactionType GetType() const { return xc_type; } float GetWeight() const { return x8_weight; } bool GetIsActive() const { return x10_active; } @@ -281,8 +282,8 @@ class CBCLoopAttackCmd : public CBodyStateCmd { u32 xc_waitForAnimOver = 0; public: - CBCLoopAttackCmd() : CBodyStateCmd(EBodyStateCmd::LoopAttack) {} - CBCLoopAttackCmd(pas::ELoopAttackType type) : CBodyStateCmd(EBodyStateCmd::LoopAttack), x8_type(type) {} + explicit CBCLoopAttackCmd() : CBodyStateCmd(EBodyStateCmd::LoopAttack) {} + explicit CBCLoopAttackCmd(pas::ELoopAttackType type) : CBodyStateCmd(EBodyStateCmd::LoopAttack), x8_type(type) {} pas::ELoopAttackType GetAttackType() const { return x8_type; } bool WaitForAnimOver() const { return xc_waitForAnimOver == 1; } }; @@ -291,8 +292,8 @@ class CBCTauntCmd : public CBodyStateCmd { pas::ETauntType x8_type = pas::ETauntType::Invalid; public: - CBCTauntCmd() : CBodyStateCmd(EBodyStateCmd::Taunt) {} - CBCTauntCmd(pas::ETauntType type) : CBodyStateCmd(EBodyStateCmd::Taunt), x8_type(type) {} + explicit CBCTauntCmd() : CBodyStateCmd(EBodyStateCmd::Taunt) {} + explicit CBCTauntCmd(pas::ETauntType type) : CBodyStateCmd(EBodyStateCmd::Taunt), x8_type(type) {} pas::ETauntType GetTauntType() const { return x8_type; } }; @@ -302,7 +303,7 @@ class CBCLocomotionCmd { float x18_weight; public: - CBCLocomotionCmd(const zeus::CVector3f& move, const zeus::CVector3f& face, float weight) + explicit CBCLocomotionCmd(const zeus::CVector3f& move, const zeus::CVector3f& face, float weight) : x0_move(move), xc_face(face), x18_weight(weight) {} const zeus::CVector3f& GetMoveVector() const { return x0_move; } const zeus::CVector3f& GetFaceVector() const { return xc_face; } @@ -324,7 +325,7 @@ class CBodyStateCmdMgr { u32 xb4_deliveredCmdMask = 0; CBCGetupCmd xb8_getup; CBCStepCmd xc4_step; - CBodyStateCmd xd4_die = {EBodyStateCmd::Die}; + CBodyStateCmd xd4_die{EBodyStateCmd::Die}; CBCKnockDownCmd xdc_knockDown; CBCKnockBackCmd xf4_knockBack; CBCMeleeAttackCmd x10c_meleeAttack; @@ -332,10 +333,10 @@ class CBodyStateCmdMgr { CBCLoopAttackCmd x144_loopAttack; CBCLoopReactionCmd x154_loopReaction; CBCLoopHitReactionCmd x160_loopHitReaction; - CBodyStateCmd x16c_exitState = {EBodyStateCmd::ExitState}; - CBodyStateCmd x174_leanFromCover = {EBodyStateCmd::LeanFromCover}; - CBodyStateCmd x17c_nextState = {EBodyStateCmd::NextState}; - CBodyStateCmd x184_maintainVelocity = {EBodyStateCmd::MaintainVelocity}; + CBodyStateCmd x16c_exitState{EBodyStateCmd::ExitState}; + CBodyStateCmd x174_leanFromCover{EBodyStateCmd::LeanFromCover}; + CBodyStateCmd x17c_nextState{EBodyStateCmd::NextState}; + CBodyStateCmd x184_maintainVelocity{EBodyStateCmd::MaintainVelocity}; CBCGenerateCmd x18c_generate; CBCHurledCmd x1ac_hurled; CBCJumpCmd x1d0_jump; @@ -344,12 +345,12 @@ class CBodyStateCmdMgr { CBCScriptedCmd x21c_scripted; CBCCoverCmd x230_cover; CBCWallHangCmd x254_wallHang; - CBodyStateCmd x260_locomotion = {EBodyStateCmd::Locomotion}; - CBodyStateCmd x268_additiveIdle = {EBodyStateCmd::AdditiveIdle}; + CBodyStateCmd x260_locomotion{EBodyStateCmd::Locomotion}; + CBodyStateCmd x268_additiveIdle{EBodyStateCmd::AdditiveIdle}; CBCAdditiveAimCmd x270_additiveAim; CBCAdditiveFlinchCmd x278_additiveFlinch; CBCAdditiveReactionCmd x284_additiveReaction; - CBodyStateCmd x298_stopReaction = {EBodyStateCmd::StopReaction}; + CBodyStateCmd x298_stopReaction{EBodyStateCmd::StopReaction}; void DeliverCmd(EBodyStateCmd cmd) { xb4_deliveredCmdMask |= (1 << int(cmd)); } public: diff --git a/Runtime/Character/CBodyStateInfo.cpp b/Runtime/Character/CBodyStateInfo.cpp index 027a5891b..09325a628 100644 --- a/Runtime/Character/CBodyStateInfo.cpp +++ b/Runtime/Character/CBodyStateInfo.cpp @@ -42,10 +42,10 @@ CBodyStateInfo::CBodyStateInfo(CActor& actor, EBodyType type) { } x1c_additiveStates.reserve(4); - x1c_additiveStates.push_back({pas::EAnimationState::AdditiveIdle, std::make_unique()}); - x1c_additiveStates.push_back({pas::EAnimationState::AdditiveAim, std::make_unique()}); - x1c_additiveStates.push_back({pas::EAnimationState::AdditiveFlinch, std::make_unique()}); - x1c_additiveStates.push_back({pas::EAnimationState::AdditiveReaction, std::make_unique()}); + x1c_additiveStates.emplace_back(pas::EAnimationState::AdditiveIdle, std::make_unique()); + x1c_additiveStates.emplace_back(pas::EAnimationState::AdditiveAim, std::make_unique()); + x1c_additiveStates.emplace_back(pas::EAnimationState::AdditiveFlinch, std::make_unique()); + x1c_additiveStates.emplace_back(pas::EAnimationState::AdditiveReaction, std::make_unique()); } std::unique_ptr CBodyStateInfo::SetupRestrictedFlyerBodyStates(int stateId, CActor& actor) const { diff --git a/Runtime/Character/CBoolPOINode.hpp b/Runtime/Character/CBoolPOINode.hpp index 9dae11934..c64468da7 100644 --- a/Runtime/Character/CBoolPOINode.hpp +++ b/Runtime/Character/CBoolPOINode.hpp @@ -9,8 +9,8 @@ class CBoolPOINode : public CPOINode { bool x38_val = false; public: - CBoolPOINode(); - CBoolPOINode(CInputStream& in); + explicit CBoolPOINode(); + explicit CBoolPOINode(CInputStream& in); bool GetValue() const { return x38_val; } static CBoolPOINode CopyNodeMinusStartTime(const CBoolPOINode& node, const CCharAnimTime& startTime); }; diff --git a/Runtime/Character/CCharacterInfo.hpp b/Runtime/Character/CCharacterInfo.hpp index b5e5a8d22..9f57b57d9 100644 --- a/Runtime/Character/CCharacterInfo.hpp +++ b/Runtime/Character/CCharacterInfo.hpp @@ -47,7 +47,7 @@ private: std::vector xb0_animIdxs; public: - CCharacterInfo(CInputStream& in); + explicit CCharacterInfo(CInputStream& in); std::string_view GetCharacterName() const { return x4_name; } CAssetId GetModelId() const { return x14_cmdl; } diff --git a/Runtime/Character/CCharacterSet.hpp b/Runtime/Character/CCharacterSet.hpp index 9bb0fcdba..f3c8e46f7 100644 --- a/Runtime/Character/CCharacterSet.hpp +++ b/Runtime/Character/CCharacterSet.hpp @@ -13,7 +13,7 @@ class CCharacterSet { std::map x4_characters; public: - CCharacterSet(CInputStream& in); + explicit CCharacterSet(CInputStream& in); const std::map& GetCharacterInfoMap() const { return x4_characters; } }; diff --git a/Runtime/Character/CEffectComponent.hpp b/Runtime/Character/CEffectComponent.hpp index ab290af75..f0a8a688c 100644 --- a/Runtime/Character/CEffectComponent.hpp +++ b/Runtime/Character/CEffectComponent.hpp @@ -18,7 +18,7 @@ class CEffectComponent { static SObjectTag GetSObjectTagFromStream(CInputStream& in); public: - CEffectComponent(CInputStream& in); + explicit CEffectComponent(CInputStream& in); std::string_view GetComponentName() const { return x0_name; } const SObjectTag& GetParticleTag() const { return x10_tag; } diff --git a/Runtime/Character/CFBStreamedAnimReader.hpp b/Runtime/Character/CFBStreamedAnimReader.hpp index 15af8800d..aa892f081 100644 --- a/Runtime/Character/CFBStreamedAnimReader.hpp +++ b/Runtime/Character/CFBStreamedAnimReader.hpp @@ -42,7 +42,7 @@ class CFBStreamedAnimReaderTotals { void Allocate(u32 chanCount); public: - CFBStreamedAnimReaderTotals(const CFBStreamedCompression& source); + explicit CFBStreamedAnimReaderTotals(const CFBStreamedCompression& source); void Initialize(const CFBStreamedCompression& source); void IncrementInto(CBitLevelLoader& loader, const CFBStreamedCompression& source, CFBStreamedAnimReaderTotals& dest); void CalculateDown(); @@ -61,7 +61,7 @@ class CFBStreamedPairOfTotals { float x78_t = 0.f; public: - CFBStreamedPairOfTotals(const TSubAnimTypeToken& source); + explicit CFBStreamedPairOfTotals(const TSubAnimTypeToken& source); void SetTime(CBitLevelLoader& loader, const CCharAnimTime& time); void DoIncrement(CBitLevelLoader& loader); float GetT() const { return x78_t; } @@ -76,7 +76,7 @@ class CBitLevelLoader { size_t m_bitIdx = 0; public: - CBitLevelLoader(const void* data) : m_data(reinterpret_cast(data)) {} + explicit CBitLevelLoader(const void* data) : m_data(reinterpret_cast(data)) {} void Reset() { m_bitIdx = 0; } u32 LoadUnsigned(u8 q); s32 LoadSigned(u8 q); @@ -88,7 +88,7 @@ class CSegIdToIndexConverter { std::array x0_indices; public: - CSegIdToIndexConverter(const CFBStreamedAnimReaderTotals& totals); + explicit CSegIdToIndexConverter(const CFBStreamedAnimReaderTotals& totals); s32 SegIdToIndex(const CSegId& id) const { return x0_indices[id]; } }; @@ -104,7 +104,7 @@ class CFBStreamedAnimReader : public CAnimSourceReaderBase { zeus::CQuaternion GetRotation(const CSegId& seg) const; public: - CFBStreamedAnimReader(const TSubAnimTypeToken& source, const CCharAnimTime& time); + explicit CFBStreamedAnimReader(const TSubAnimTypeToken& source, const CCharAnimTime& time); SAdvancementResults VGetAdvancementResults(const CCharAnimTime& a, const CCharAnimTime& b) const override; bool VSupportsReverseView() const override { return false; } diff --git a/Runtime/Character/CFBStreamedCompression.hpp b/Runtime/Character/CFBStreamedCompression.hpp index 0c37c0fd6..5c519280f 100644 --- a/Runtime/Character/CFBStreamedCompression.hpp +++ b/Runtime/Character/CFBStreamedCompression.hpp @@ -66,7 +66,7 @@ private: float CalculateAverageVelocity(const u8* chans) const; public: - CFBStreamedCompression(CInputStream& in, IObjectStore& objStore, bool pc); + explicit CFBStreamedCompression(CInputStream& in, IObjectStore& objStore, bool pc); const Header& MainHeader() const { return *reinterpret_cast(xc_rotsAndOffs.get()); } const u32* GetTimes() const; const u8* GetPerChannelHeaders() const; diff --git a/Runtime/Character/CHalfTransition.hpp b/Runtime/Character/CHalfTransition.hpp index ad6ab9397..76d5a58bb 100644 --- a/Runtime/Character/CHalfTransition.hpp +++ b/Runtime/Character/CHalfTransition.hpp @@ -13,7 +13,7 @@ class CHalfTransition { std::shared_ptr x4_trans; public: - CHalfTransition(CInputStream& in); + explicit CHalfTransition(CInputStream& in); u32 GetId() const { return x0_id; } const std::shared_ptr& GetMetaTrans() const { return x4_trans; } }; diff --git a/Runtime/Character/CHierarchyPoseBuilder.hpp b/Runtime/Character/CHierarchyPoseBuilder.hpp index 24e196543..abe1f13e2 100644 --- a/Runtime/Character/CHierarchyPoseBuilder.hpp +++ b/Runtime/Character/CHierarchyPoseBuilder.hpp @@ -36,7 +36,7 @@ private: const zeus::CVector3f& offset) const; public: - CHierarchyPoseBuilder(const CLayoutDescription& layout); + explicit CHierarchyPoseBuilder(const CLayoutDescription& layout); const TLockedToken& CharLayoutInfo() const { return x0_layoutDesc.ScaledLayout(); } bool HasRoot() const { return x34_hasRoot; } diff --git a/Runtime/Character/CInt32POINode.hpp b/Runtime/Character/CInt32POINode.hpp index 898fff078..2ca709b42 100644 --- a/Runtime/Character/CInt32POINode.hpp +++ b/Runtime/Character/CInt32POINode.hpp @@ -15,7 +15,7 @@ class CInt32POINode : public CPOINode { public: CInt32POINode(); CInt32POINode(std::string_view, EPOIType, const CCharAnimTime&, s32, bool, float, s32, s32, s32, std::string_view); - CInt32POINode(CInputStream& in); + explicit CInt32POINode(CInputStream& in); s32 GetValue() const { return x38_val; } std::string_view GetLocatorName() const { return x3c_locatorName; } diff --git a/Runtime/Character/CLayoutDescription.hpp b/Runtime/Character/CLayoutDescription.hpp index 248f57486..05c2e041b 100644 --- a/Runtime/Character/CLayoutDescription.hpp +++ b/Runtime/Character/CLayoutDescription.hpp @@ -27,7 +27,7 @@ private: std::optional xc_scaled; public: - CLayoutDescription(const TLockedToken& token) : x0_layoutToken(token) {} + explicit CLayoutDescription(const TLockedToken& token) : x0_layoutToken(token) {} const std::optional& GetScaledLayoutDescription() const { return xc_scaled; } diff --git a/Runtime/Character/CMetaAnimBlend.hpp b/Runtime/Character/CMetaAnimBlend.hpp index a2be465be..52bee1aa7 100644 --- a/Runtime/Character/CMetaAnimBlend.hpp +++ b/Runtime/Character/CMetaAnimBlend.hpp @@ -14,7 +14,7 @@ class CMetaAnimBlend : public IMetaAnim { bool x10_; public: - CMetaAnimBlend(CInputStream& in); + explicit CMetaAnimBlend(CInputStream& in); EMetaAnimType GetType() const override { return EMetaAnimType::Blend; } void GetUniquePrimitives(std::set& primsOut) const override; diff --git a/Runtime/Character/CMetaAnimPhaseBlend.hpp b/Runtime/Character/CMetaAnimPhaseBlend.hpp index 81686f5c7..c8131ff59 100644 --- a/Runtime/Character/CMetaAnimPhaseBlend.hpp +++ b/Runtime/Character/CMetaAnimPhaseBlend.hpp @@ -14,7 +14,7 @@ class CMetaAnimPhaseBlend : public IMetaAnim { bool x10_; public: - CMetaAnimPhaseBlend(CInputStream& in); + explicit CMetaAnimPhaseBlend(CInputStream& in); EMetaAnimType GetType() const override { return EMetaAnimType::PhaseBlend; } void GetUniquePrimitives(std::set& primsOut) const override; diff --git a/Runtime/Character/CMetaAnimPlay.hpp b/Runtime/Character/CMetaAnimPlay.hpp index 4f056eeb0..2939fc24a 100644 --- a/Runtime/Character/CMetaAnimPlay.hpp +++ b/Runtime/Character/CMetaAnimPlay.hpp @@ -11,7 +11,7 @@ class CMetaAnimPlay : public IMetaAnim { CCharAnimTime x1c_startTime; public: - CMetaAnimPlay(CInputStream& in); + explicit CMetaAnimPlay(CInputStream& in); EMetaAnimType GetType() const override { return EMetaAnimType::Play; } void GetUniquePrimitives(std::set& primsOut) const override; diff --git a/Runtime/Character/CMetaAnimRandom.hpp b/Runtime/Character/CMetaAnimRandom.hpp index 9abb4e8a2..8ee2a6b29 100644 --- a/Runtime/Character/CMetaAnimRandom.hpp +++ b/Runtime/Character/CMetaAnimRandom.hpp @@ -15,7 +15,7 @@ class CMetaAnimRandom : public IMetaAnim { static RandomData CreateRandomData(CInputStream& in); public: - CMetaAnimRandom(CInputStream& in); + explicit CMetaAnimRandom(CInputStream& in); EMetaAnimType GetType() const override { return EMetaAnimType::Random; } void GetUniquePrimitives(std::set& primsOut) const override; diff --git a/Runtime/Character/CMetaAnimSequence.hpp b/Runtime/Character/CMetaAnimSequence.hpp index 57d68bf6d..bc644b3e9 100644 --- a/Runtime/Character/CMetaAnimSequence.hpp +++ b/Runtime/Character/CMetaAnimSequence.hpp @@ -13,7 +13,7 @@ class CMetaAnimSequence : public IMetaAnim { std::vector> CreateSequence(CInputStream& in); public: - CMetaAnimSequence(CInputStream& in); + explicit CMetaAnimSequence(CInputStream& in); EMetaAnimType GetType() const override { return EMetaAnimType::Sequence; } void GetUniquePrimitives(std::set& primsOut) const override; diff --git a/Runtime/Character/CMetaTransMetaAnim.hpp b/Runtime/Character/CMetaTransMetaAnim.hpp index 03f459254..21e193015 100644 --- a/Runtime/Character/CMetaTransMetaAnim.hpp +++ b/Runtime/Character/CMetaTransMetaAnim.hpp @@ -12,7 +12,7 @@ class CMetaTransMetaAnim : public IMetaTrans { std::shared_ptr x4_metaAnim; public: - CMetaTransMetaAnim(CInputStream& in); + explicit CMetaTransMetaAnim(CInputStream& in); EMetaTransType GetType() const override { return EMetaTransType::MetaAnim; } std::shared_ptr VGetTransitionTree(const std::weak_ptr& a, diff --git a/Runtime/Character/CMetaTransPhaseTrans.hpp b/Runtime/Character/CMetaTransPhaseTrans.hpp index b9e5c9e5e..49005655c 100644 --- a/Runtime/Character/CMetaTransPhaseTrans.hpp +++ b/Runtime/Character/CMetaTransPhaseTrans.hpp @@ -13,7 +13,7 @@ class CMetaTransPhaseTrans : public IMetaTrans { u32 x10_flags; public: - CMetaTransPhaseTrans(CInputStream& in); + explicit CMetaTransPhaseTrans(CInputStream& in); EMetaTransType GetType() const override { return EMetaTransType::PhaseTrans; } std::shared_ptr VGetTransitionTree(const std::weak_ptr& a, diff --git a/Runtime/Character/CMetaTransTrans.hpp b/Runtime/Character/CMetaTransTrans.hpp index b3cf33efd..f1f259975 100644 --- a/Runtime/Character/CMetaTransTrans.hpp +++ b/Runtime/Character/CMetaTransTrans.hpp @@ -13,7 +13,7 @@ class CMetaTransTrans : public IMetaTrans { u32 x10_flags; public: - CMetaTransTrans(CInputStream& in); + explicit CMetaTransTrans(CInputStream& in); EMetaTransType GetType() const override { return EMetaTransType::Trans; } std::shared_ptr VGetTransitionTree(const std::weak_ptr& a, diff --git a/Runtime/Character/CModelData.cpp b/Runtime/Character/CModelData.cpp index 1ac59a504..b035a378b 100644 --- a/Runtime/Character/CModelData.cpp +++ b/Runtime/Character/CModelData.cpp @@ -20,7 +20,7 @@ namespace urde { static logvisor::Module Log("urde::CModelData"); -CModelData::~CModelData() {} +CModelData::~CModelData() = default; CModelData::CModelData() {} CModelData CModelData::CModelDataNull() { return CModelData(); } diff --git a/Runtime/Character/CModelData.hpp b/Runtime/Character/CModelData.hpp index 917d45ab8..d11d8f36d 100644 --- a/Runtime/Character/CModelData.hpp +++ b/Runtime/Character/CModelData.hpp @@ -79,7 +79,7 @@ class CModelData { std::unique_ptr m_xrayModelInst; std::unique_ptr m_infraModelInst; - int m_drawInstCount; + int m_drawInstCount = 0; public: enum class EWhichModel { Normal, XRay, Thermal, ThermalHot }; @@ -88,8 +88,8 @@ public: bool GetSortThermal() const { return x14_25_sortThermal; } ~CModelData(); - CModelData(const CStaticRes& res, int instCount = 1); - CModelData(const CAnimRes& res, int instCount = 1); + explicit CModelData(const CStaticRes& res, int instCount = 1); + explicit CModelData(const CAnimRes& res, int instCount = 1); CModelData(CModelData&&) = default; CModelData& operator=(CModelData&&) = default; CModelData(); diff --git a/Runtime/Character/CPASAnimInfo.hpp b/Runtime/Character/CPASAnimInfo.hpp index 1a86d22b9..186f9afed 100644 --- a/Runtime/Character/CPASAnimInfo.hpp +++ b/Runtime/Character/CPASAnimInfo.hpp @@ -11,8 +11,8 @@ class CPASAnimInfo { rstl::reserved_vector x4_parms; public: - CPASAnimInfo(u32 id) : x0_id(id) {} - CPASAnimInfo(u32 id, rstl::reserved_vector&& parms); + explicit CPASAnimInfo(u32 id) : x0_id(id) {} + explicit CPASAnimInfo(u32 id, rstl::reserved_vector&& parms); u32 GetAnimId() const { return x0_id; } CPASAnimParm::UParmValue GetAnimParmValue(u32 idx) const; CPASAnimParm GetAnimParmData(u32, CPASAnimParm::EParmType) const; diff --git a/Runtime/Character/CPASAnimParmData.hpp b/Runtime/Character/CPASAnimParmData.hpp index b985f0682..41ad3521f 100644 --- a/Runtime/Character/CPASAnimParmData.hpp +++ b/Runtime/Character/CPASAnimParmData.hpp @@ -12,28 +12,18 @@ class CPASAnimParmData { public: CPASAnimParmData() = default; - CPASAnimParmData(s32 stateId, const CPASAnimParm& parm1 = CPASAnimParm::NoParameter(), - const CPASAnimParm& parm2 = CPASAnimParm::NoParameter(), - const CPASAnimParm& parm3 = CPASAnimParm::NoParameter(), - const CPASAnimParm& parm4 = CPASAnimParm::NoParameter(), - const CPASAnimParm& parm5 = CPASAnimParm::NoParameter(), - const CPASAnimParm& parm6 = CPASAnimParm::NoParameter(), - const CPASAnimParm& parm7 = CPASAnimParm::NoParameter(), - const CPASAnimParm& parm8 = CPASAnimParm::NoParameter()); + explicit CPASAnimParmData(s32 stateId, const CPASAnimParm& parm1 = CPASAnimParm::NoParameter(), + const CPASAnimParm& parm2 = CPASAnimParm::NoParameter(), + const CPASAnimParm& parm3 = CPASAnimParm::NoParameter(), + const CPASAnimParm& parm4 = CPASAnimParm::NoParameter(), + const CPASAnimParm& parm5 = CPASAnimParm::NoParameter(), + const CPASAnimParm& parm6 = CPASAnimParm::NoParameter(), + const CPASAnimParm& parm7 = CPASAnimParm::NoParameter(), + const CPASAnimParm& parm8 = CPASAnimParm::NoParameter()); s32 GetStateId() const { return x0_stateId; } const rstl::reserved_vector& GetAnimParmData() const { return x4_parms; } - static CPASAnimParmData NoParameters(s32 stateId) { - return {stateId, - CPASAnimParm::NoParameter(), - CPASAnimParm::NoParameter(), - CPASAnimParm::NoParameter(), - CPASAnimParm::NoParameter(), - CPASAnimParm::NoParameter(), - CPASAnimParm::NoParameter(), - CPASAnimParm::NoParameter(), - CPASAnimParm::NoParameter()}; - } + static auto NoParameters(s32 stateId) { return CPASAnimParmData(stateId); } }; } // namespace urde diff --git a/Runtime/Character/CPOINode.hpp b/Runtime/Character/CPOINode.hpp index a5777a3bd..3cc4c89b3 100644 --- a/Runtime/Character/CPOINode.hpp +++ b/Runtime/Character/CPOINode.hpp @@ -33,9 +33,9 @@ protected: s32 x34_flags; public: - CPOINode(std::string_view name, EPOIType type, const CCharAnimTime& time, s32 index, bool unique, float weight, - s32 charIdx, s32 flags); - CPOINode(CInputStream& in); + explicit CPOINode(std::string_view name, EPOIType type, const CCharAnimTime& time, s32 index, bool unique, + float weight, s32 charIdx, s32 flags); + explicit CPOINode(CInputStream& in); virtual ~CPOINode() = default; std::string_view GetString() const { return x8_name; } diff --git a/Runtime/Character/CParticleData.hpp b/Runtime/Character/CParticleData.hpp index 907f406d4..98428e200 100644 --- a/Runtime/Character/CParticleData.hpp +++ b/Runtime/Character/CParticleData.hpp @@ -22,7 +22,7 @@ private: public: CParticleData() = default; - CParticleData(CInputStream& in); + explicit CParticleData(CInputStream& in); u32 GetDuration() const { return x0_duration; } const SObjectTag& GetTag() const { return x4_particle; } std::string_view GetSegmentName() const { return xc_boneName; } diff --git a/Runtime/Character/CParticlePOINode.hpp b/Runtime/Character/CParticlePOINode.hpp index 065ad773c..33180a624 100644 --- a/Runtime/Character/CParticlePOINode.hpp +++ b/Runtime/Character/CParticlePOINode.hpp @@ -10,8 +10,8 @@ class CParticlePOINode : public CPOINode { CParticleData x38_data; public: - CParticlePOINode(); - CParticlePOINode(CInputStream& in); + explicit CParticlePOINode(); + explicit CParticlePOINode(CInputStream& in); const CParticleData& GetParticleData() const { return x38_data; } static CParticlePOINode CopyNodeMinusStartTime(const CParticlePOINode& node, const CCharAnimTime& startTime); diff --git a/Runtime/Character/CPrimitive.hpp b/Runtime/Character/CPrimitive.hpp index 16e7236cd..db9a44c8f 100644 --- a/Runtime/Character/CPrimitive.hpp +++ b/Runtime/Character/CPrimitive.hpp @@ -13,7 +13,7 @@ class CPrimitive { std::string x8_animName; public: - CPrimitive(CInputStream& in); + explicit CPrimitive(CInputStream& in); CAssetId GetAnimResId() const { return x0_animId; } u32 GetAnimDbIdx() const { return x4_animIdx; } std::string_view GetName() const { return x8_animName; } diff --git a/Runtime/Character/CSegIdList.hpp b/Runtime/Character/CSegIdList.hpp index 65f456371..37eceb21c 100644 --- a/Runtime/Character/CSegIdList.hpp +++ b/Runtime/Character/CSegIdList.hpp @@ -11,7 +11,7 @@ class CSegIdList { std::vector x0_list; public: - CSegIdList(CInputStream& in); + explicit CSegIdList(CInputStream& in); const std::vector& GetList() const { return x0_list; } }; diff --git a/Runtime/Character/CSkinBank.hpp b/Runtime/Character/CSkinBank.hpp index cce5921f0..604d19b17 100644 --- a/Runtime/Character/CSkinBank.hpp +++ b/Runtime/Character/CSkinBank.hpp @@ -12,7 +12,7 @@ class CSkinBank { std::vector x0_segments; public: - CSkinBank(CInputStream& in); + explicit CSkinBank(CInputStream& in); void GetBankTransforms(std::vector& out, const CPoseAsTransforms& pose) const; }; diff --git a/Runtime/Character/CSoundPOINode.hpp b/Runtime/Character/CSoundPOINode.hpp index 0f46bae1e..4e243fd5c 100644 --- a/Runtime/Character/CSoundPOINode.hpp +++ b/Runtime/Character/CSoundPOINode.hpp @@ -12,10 +12,10 @@ class CSoundPOINode : public CPOINode { float x40_maxDist; public: - CSoundPOINode(); - CSoundPOINode(CInputStream& in); - CSoundPOINode(std::string_view name, EPOIType type, const CCharAnimTime& time, u32 b, bool c, float d, u32 e, u32 f, - u32 sfxId, float falloff, float maxDist); + explicit CSoundPOINode(); + explicit CSoundPOINode(CInputStream& in); + explicit CSoundPOINode(std::string_view name, EPOIType type, const CCharAnimTime& time, u32 b, bool c, float d, u32 e, + u32 f, u32 sfxId, float falloff, float maxDist); static CSoundPOINode CopyNodeMinusStartTime(const CSoundPOINode& node, const CCharAnimTime& startTime); u32 GetSfxId() const { return x38_sfxId; } diff --git a/Runtime/Character/CTimeScaleFunctions.hpp b/Runtime/Character/CTimeScaleFunctions.hpp index e6bc159dc..0829b96e3 100644 --- a/Runtime/Character/CTimeScaleFunctions.hpp +++ b/Runtime/Character/CTimeScaleFunctions.hpp @@ -25,7 +25,7 @@ private: float x4_scale; public: - CConstantAnimationTimeScale(float scale) : x4_scale(scale) {} + explicit CConstantAnimationTimeScale(float scale) : x4_scale(scale) {} EVaryingAnimationTimeScaleType GetType() const override { return EVaryingAnimationTimeScaleType::Constant; } float VTimeScaleIntegral(float lowerLimit, float upperLimit) const override; @@ -46,7 +46,7 @@ class CLinearAnimationTimeScale : public IVaryingAnimationTimeScale { static float TimeScaleIntegralWithSortedLimits(const CFunctionDescription& desc, float lowerLimit, float upperLimit); public: - CLinearAnimationTimeScale(const CCharAnimTime& t1, float y1, const CCharAnimTime& t2, float y2); + explicit CLinearAnimationTimeScale(const CCharAnimTime& t1, float y1, const CCharAnimTime& t2, float y2); EVaryingAnimationTimeScaleType GetType() const override { return EVaryingAnimationTimeScaleType::Linear; } float VTimeScaleIntegral(float lowerLimit, float upperLimit) const override; diff --git a/Runtime/Character/CTransition.hpp b/Runtime/Character/CTransition.hpp index b7d7a0266..80f74ab70 100644 --- a/Runtime/Character/CTransition.hpp +++ b/Runtime/Character/CTransition.hpp @@ -15,7 +15,7 @@ class CTransition { std::shared_ptr xc_trans; public: - CTransition(CInputStream& in); + explicit CTransition(CInputStream& in); u32 GetAnimA() const { return x4_animA; } u32 GetAnimB() const { return x8_animB; } std::pair GetAnimPair() const { return {x4_animA, x8_animB}; } diff --git a/Runtime/Character/IAnimReader.hpp b/Runtime/Character/IAnimReader.hpp index 1f4962182..59f7e1df9 100644 --- a/Runtime/Character/IAnimReader.hpp +++ b/Runtime/Character/IAnimReader.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "Runtime/CToken.hpp" #include "Runtime/RetroTypes.hpp" @@ -73,14 +74,15 @@ class TSubAnimTypeToken : public TLockedToken {}; template <> class TSubAnimTypeToken : public TLockedToken { public: - TSubAnimTypeToken(const TLockedToken& token) : TLockedToken(token) {} + // Converting constructor + TSubAnimTypeToken(const TLockedToken& token) : TLockedToken(token) {} - CAnimSource* GetObj() { + CAnimSource* GetObj() override { CAllFormatsAnimSource* source = reinterpret_cast(TLockedToken::GetObj()); return &source->GetAsCAnimSource(); } - const CAnimSource* GetObj() const { + const CAnimSource* GetObj() const override { return const_cast*>(this)->GetObj(); } }; @@ -88,16 +90,16 @@ public: template <> class TSubAnimTypeToken : public TLockedToken { public: - TSubAnimTypeToken(const TLockedToken& token) - : TLockedToken(token) {} + // Converting constructor + TSubAnimTypeToken(const TLockedToken& token) : TLockedToken(token) {} - CFBStreamedCompression* GetObj() { + CFBStreamedCompression* GetObj() override { CAllFormatsAnimSource* source = reinterpret_cast(TLockedToken::GetObj()); return &source->GetAsCFBStreamedCompression(); } - const CFBStreamedCompression* GetObj() const { + const CFBStreamedCompression* GetObj() const override { return const_cast*>(this)->GetObj(); } }; @@ -120,9 +122,9 @@ public: u32) const = 0; virtual u32 VGetSoundPOIList(const CCharAnimTime& time, CSoundPOINode* listOut, u32 capacity, u32 iterator, u32) const = 0; - virtual bool VGetBoolPOIState(const char*) const = 0; - virtual s32 VGetInt32POIState(const char*) const = 0; - virtual CParticleData::EParentedMode VGetParticlePOIState(const char*) const = 0; + virtual bool VGetBoolPOIState(std::string_view name) const = 0; + virtual s32 VGetInt32POIState(std::string_view name) const = 0; + virtual CParticleData::EParentedMode VGetParticlePOIState(std::string_view name) const = 0; virtual void VGetSegStatementSet(const CSegIdList& list, CSegStatementSet& setOut) const = 0; virtual void VGetSegStatementSet(const CSegIdList& list, CSegStatementSet& setOut, const CCharAnimTime& time) const = 0; diff --git a/Runtime/Character/IMetaAnim.hpp b/Runtime/Character/IMetaAnim.hpp index 71b3fc77a..c941dafc5 100644 --- a/Runtime/Character/IMetaAnim.hpp +++ b/Runtime/Character/IMetaAnim.hpp @@ -35,8 +35,8 @@ class CPreAdvanceIndicator { u16 x3c_; */ public: - CPreAdvanceIndicator(const CCharAnimTime& time) : x0_isTime(true), x4_time(time) {} - CPreAdvanceIndicator(const char* string) : x0_isTime(false), xc_string(string) {} + explicit CPreAdvanceIndicator(const CCharAnimTime& time) : x0_isTime(true), x4_time(time) {} + explicit CPreAdvanceIndicator(const char* string) : x0_isTime(false), xc_string(string) {} const char* GetString() const { return xc_string; } bool IsString() const { return !x0_isTime; } const CCharAnimTime& GetTime() const { return x4_time; } diff --git a/Runtime/Character/IVaryingAnimationTimeScale.hpp b/Runtime/Character/IVaryingAnimationTimeScale.hpp index 1d577e57f..aea324e67 100644 --- a/Runtime/Character/IVaryingAnimationTimeScale.hpp +++ b/Runtime/Character/IVaryingAnimationTimeScale.hpp @@ -7,6 +7,7 @@ namespace urde { class IVaryingAnimationTimeScale { public: + virtual ~IVaryingAnimationTimeScale() = default; virtual u32 GetType() const = 0; virtual float VTimeScaleIntegral(const float&, const float&) const = 0; virtual float VFindUpperLimit(const float&, const float&) const = 0; diff --git a/Runtime/Character/TSegIdMap.hpp b/Runtime/Character/TSegIdMap.hpp index bcef067be..304590769 100644 --- a/Runtime/Character/TSegIdMap.hpp +++ b/Runtime/Character/TSegIdMap.hpp @@ -18,7 +18,7 @@ class TSegIdMap { CSegId xd4_curPrevBone = 0; public: - TSegIdMap(const CSegId& capacity) : x1_capacity(capacity), xd0_bones(new T[capacity]) {} + explicit TSegIdMap(const CSegId& capacity) : x1_capacity(capacity), xd0_bones(new T[capacity]) {} T& operator[](const CSegId& id) { return SetElement(id); } const T& operator[](const CSegId& id) const { return xd0_bones[x8_indirectionMap[id].second]; } diff --git a/Runtime/Collision/CAABoxFilter.hpp b/Runtime/Collision/CAABoxFilter.hpp index de28e207a..59e5c92c6 100644 --- a/Runtime/Collision/CAABoxFilter.hpp +++ b/Runtime/Collision/CAABoxFilter.hpp @@ -7,7 +7,7 @@ class CCollisionInfoList; class CAABoxFilter : public ICollisionFilter { public: - CAABoxFilter(CActor& actor) : ICollisionFilter(actor) {} + explicit CAABoxFilter(CActor& actor) : ICollisionFilter(actor) {} void Filter(const CCollisionInfoList& in, CCollisionInfoList& out) const override; static void FilterBoxFloorCollisions(const CCollisionInfoList& in, CCollisionInfoList& out); }; diff --git a/Runtime/Collision/CAreaOctTree.hpp b/Runtime/Collision/CAreaOctTree.hpp index fec3b9455..a1c2b57ea 100644 --- a/Runtime/Collision/CAreaOctTree.hpp +++ b/Runtime/Collision/CAreaOctTree.hpp @@ -27,7 +27,7 @@ public: const u16* m_ptr; public: - TriListReference(const u16* ptr) : m_ptr(ptr) {} + explicit TriListReference(const u16* ptr) : m_ptr(ptr) {} u16 GetAt(int idx) const { return m_ptr[idx + 1]; } u16 GetSize() const { return m_ptr[0]; } }; diff --git a/Runtime/Collision/CBallFilter.hpp b/Runtime/Collision/CBallFilter.hpp index 803a72337..7ba532a03 100644 --- a/Runtime/Collision/CBallFilter.hpp +++ b/Runtime/Collision/CBallFilter.hpp @@ -8,7 +8,7 @@ class CPhysicsActor; class CBallFilter : public ICollisionFilter { public: - CBallFilter(CActor& actor) : ICollisionFilter(actor) {} + explicit CBallFilter(CActor& actor) : ICollisionFilter(actor) {} void Filter(const CCollisionInfoList& in, CCollisionInfoList& out) const override; }; diff --git a/Runtime/Collision/CCollidableOBBTreeGroup.hpp b/Runtime/Collision/CCollidableOBBTreeGroup.hpp index 9957a9a47..e48aafc77 100644 --- a/Runtime/Collision/CCollidableOBBTreeGroup.hpp +++ b/Runtime/Collision/CCollidableOBBTreeGroup.hpp @@ -19,7 +19,7 @@ class CCollidableOBBTreeGroupContainer { zeus::CAABox x20_aabox; public: - CCollidableOBBTreeGroupContainer(CInputStream& in); + explicit CCollidableOBBTreeGroupContainer(CInputStream& in); CCollidableOBBTreeGroupContainer(const zeus::CVector3f&, const zeus::CVector3f&); }; diff --git a/Runtime/Collision/CCollisionEdge.hpp b/Runtime/Collision/CCollisionEdge.hpp index 2b4a5db83..d60a37dc6 100644 --- a/Runtime/Collision/CCollisionEdge.hpp +++ b/Runtime/Collision/CCollisionEdge.hpp @@ -9,7 +9,7 @@ class CCollisionEdge { public: CCollisionEdge() = default; - CCollisionEdge(CInputStream&); + explicit CCollisionEdge(CInputStream&); CCollisionEdge(u16 v0, u16 v1) : x0_index1(v0), x2_index2(v1) {} u16 GetVertIndex1() const { return x0_index1; } diff --git a/Runtime/Collision/CCollisionPrimitive.hpp b/Runtime/Collision/CCollisionPrimitive.hpp index 79db8fbdc..bbe619908 100644 --- a/Runtime/Collision/CCollisionPrimitive.hpp +++ b/Runtime/Collision/CCollisionPrimitive.hpp @@ -134,7 +134,7 @@ private: public: CCollisionPrimitive() = default; - CCollisionPrimitive(const CMaterialList& list); + explicit CCollisionPrimitive(const CMaterialList& list); virtual u32 GetTableIndex() const = 0; virtual void SetMaterial(const CMaterialList&); virtual const CMaterialList& GetMaterial() const; diff --git a/Runtime/Collision/CCollisionResponseData.hpp b/Runtime/Collision/CCollisionResponseData.hpp index 019426945..4b61ca6d4 100644 --- a/Runtime/Collision/CCollisionResponseData.hpp +++ b/Runtime/Collision/CCollisionResponseData.hpp @@ -9,9 +9,9 @@ #include "Runtime/IObj.hpp" #include "Runtime/RetroTypes.hpp" #include "Runtime/Collision/CMaterialList.hpp" +#include "Runtime/Particle/CDecalDescription.hpp" namespace urde { -class CDecalDescription; class CGenDescription; class CSimplePool; @@ -126,7 +126,7 @@ class CCollisionResponseData { bool CheckAndAddResourceToResponse(FourCC clsId, CInputStream& in, CSimplePool* resPool); public: - CCollisionResponseData(CInputStream& in, CSimplePool* resPool); + explicit CCollisionResponseData(CInputStream& in, CSimplePool* resPool); const std::optional>& GetParticleDescription(EWeaponCollisionResponseTypes type) const; const std::optional>& GetDecalDescription(EWeaponCollisionResponseTypes type) const; s32 GetSoundEffectId(EWeaponCollisionResponseTypes type) const; diff --git a/Runtime/Collision/CMetroidAreaCollider.hpp b/Runtime/Collision/CMetroidAreaCollider.hpp index 621c02e1a..5c39b56fb 100644 --- a/Runtime/Collision/CMetroidAreaCollider.hpp +++ b/Runtime/Collision/CMetroidAreaCollider.hpp @@ -121,7 +121,7 @@ public: bool x908_24_overflow : 1; public: - COctreeLeafCache(const CAreaOctTree& octTree); + explicit COctreeLeafCache(const CAreaOctTree& octTree); void AddLeaf(const CAreaOctTree::Node& node); u32 GetNumLeaves() const { return x4_nodeCache.size(); } bool HasCacheOverflowed() const { return x908_24_overflow; } @@ -179,7 +179,7 @@ class CAreaCollisionCache { }; public: - CAreaCollisionCache(const zeus::CAABox& aabb) : x0_aabb(aabb) {} + explicit CAreaCollisionCache(const zeus::CAABox& aabb) : x0_aabb(aabb) {} void ClearCache(); const zeus::CAABox& GetCacheBounds() const { return x0_aabb; } void SetCacheBounds(const zeus::CAABox& aabb) { x0_aabb = aabb; } diff --git a/Runtime/Collision/COBBTree.cpp b/Runtime/Collision/COBBTree.cpp index d543e8300..89d8bf84e 100644 --- a/Runtime/Collision/COBBTree.cpp +++ b/Runtime/Collision/COBBTree.cpp @@ -130,30 +130,37 @@ zeus::CAABox COBBTree::CalculateAABox(const zeus::CTransform& xf) const { COBBTree::SIndexData::SIndexData(CInputStream& in) { u32 count = in.readUint32Big(); x0_materials.reserve(count); - for (u32 i = 0; i < count; i++) - x0_materials.push_back(in.readUint32Big()); + for (u32 i = 0; i < count; i++) { + x0_materials.emplace_back(in.readUint32Big()); + } count = in.readUint32Big(); - for (u32 i = 0; i < count; i++) - x10_vertMaterials.push_back(in.readUByte()); + for (u32 i = 0; i < count; i++) { + x10_vertMaterials.emplace_back(in.readUByte()); + } count = in.readUint32Big(); - for (u32 i = 0; i < count; i++) - x20_edgeMaterials.push_back(in.readUByte()); + for (u32 i = 0; i < count; i++) { + x20_edgeMaterials.emplace_back(in.readUByte()); + } count = in.readUint32Big(); - for (u32 i = 0; i < count; i++) - x30_surfaceMaterials.push_back(in.readUByte()); + for (u32 i = 0; i < count; i++) { + x30_surfaceMaterials.emplace_back(in.readUByte()); + } count = in.readUint32Big(); - for (u32 i = 0; i < count; i++) - x40_edges.push_back(in); + for (u32 i = 0; i < count; i++) { + x40_edges.emplace_back(in); + } count = in.readUint32Big(); - for (u32 i = 0; i < count; i++) - x50_surfaceIndices.push_back(in.readUint16Big()); + for (u32 i = 0; i < count; i++) { + x50_surfaceIndices.emplace_back(in.readUint16Big()); + } count = in.readUint32Big(); - for (u32 i = 0; i < count; i++) - x60_vertices.push_back(zeus::CVector3f::ReadBig(in)); + for (u32 i = 0; i < count; i++) { + x60_vertices.emplace_back(zeus::CVector3f::ReadBig(in)); + } } COBBTree::CNode::CNode(const zeus::CTransform& xf, const zeus::CVector3f& point, @@ -195,14 +202,15 @@ COBBTree::CLeafData::CLeafData(std::vector&& surface) : x0_surface(std::mov const std::vector& COBBTree::CLeafData::GetSurfaceVector() const { return x0_surface; } size_t COBBTree::CLeafData::GetMemoryUsage() const { - size_t ret = (x0_surface.size() * 2) + /*sizeof(CLeafData)*/ 16; + const size_t ret = (x0_surface.size() * 2) + /*sizeof(CLeafData)*/ 16; return (ret + 3) & ~3; } COBBTree::CLeafData::CLeafData(CInputStream& in) { - u32 edgeCount = in.readUint32Big(); - for (u32 i = 0; i < edgeCount; i++) - x0_surface.push_back(in.readUint16Big()); + const u32 edgeCount = in.readUint32Big(); + for (u32 i = 0; i < edgeCount; i++) { + x0_surface.emplace_back(in.readUint16Big()); + } } } // namespace urde diff --git a/Runtime/Collision/COBBTree.hpp b/Runtime/Collision/COBBTree.hpp index 480bcf790..9ddd38acb 100644 --- a/Runtime/Collision/COBBTree.hpp +++ b/Runtime/Collision/COBBTree.hpp @@ -24,7 +24,7 @@ public: std::vector x50_surfaceIndices; std::vector x60_vertices; SIndexData() = default; - SIndexData(CInputStream&); + explicit SIndexData(CInputStream&); }; class CLeafData { @@ -32,8 +32,8 @@ public: public: CLeafData() = default; - CLeafData(std::vector&& surface); - CLeafData(CInputStream&); + explicit CLeafData(std::vector&& surface); + explicit CLeafData(CInputStream&); const std::vector& GetSurfaceVector() const; size_t GetMemoryUsage() const; @@ -51,7 +51,7 @@ public: CNode() = default; CNode(const zeus::CTransform&, const zeus::CVector3f&, std::unique_ptr&&, std::unique_ptr&&, std::unique_ptr&&); - CNode(CInputStream&); + explicit CNode(CInputStream&); bool WasHit() const { return x4c_hit; } void SetHit(bool h) { x4c_hit = h; } @@ -73,7 +73,7 @@ private: public: COBBTree() = default; - COBBTree(CInputStream&); + explicit COBBTree(CInputStream&); static std::unique_ptr BuildOrientedBoundingBoxTree(const zeus::CVector3f&, const zeus::CVector3f&); diff --git a/Runtime/Collision/ICollisionFilter.hpp b/Runtime/Collision/ICollisionFilter.hpp index 3c09e7fa3..c21f26b75 100644 --- a/Runtime/Collision/ICollisionFilter.hpp +++ b/Runtime/Collision/ICollisionFilter.hpp @@ -8,7 +8,7 @@ class ICollisionFilter { CActor& x4_actor; protected: - ICollisionFilter(CActor& actor) : x4_actor(actor) {} + explicit ICollisionFilter(CActor& actor) : x4_actor(actor) {} public: virtual void Filter(const CCollisionInfoList& in, CCollisionInfoList& out) const = 0; diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index 04ec2080f..8c07d64a7 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -220,7 +220,7 @@ CBooRenderer::CAreaListItem::CAreaListItem(const std::vector thisLights; @@ -1056,9 +1056,9 @@ std::pair CBooRenderer::SetViewportOrtho(bool void CBooRenderer::SetClippingPlanes(const zeus::CFrustum& frustum) { x44_frustumPlanes = frustum; } -void CBooRenderer::SetViewport(int l, int b, int w, int h) { - CGraphics::SetViewport(l, b, w, h); - CGraphics::SetScissor(l, b, w, h); +void CBooRenderer::SetViewport(int left, int bottom, int width, int height) { + CGraphics::SetViewport(left, bottom, width, height); + CGraphics::SetScissor(left, bottom, width, height); } void CBooRenderer::SetDebugOption(EDebugOption, int) {} diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index 321d8be4c..92ef59938 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -198,9 +198,9 @@ public: void AddWorldSurfaces(CBooModel& model); std::list::iterator FindStaticGeometry(const std::vector*); - void AddStaticGeometry(const std::vector*, const CAreaRenderOctTree*, int areaIdx, - const SShader* shaderSet) override; - void EnablePVS(const CPVSVisSet&, u32) override; + void AddStaticGeometry(const std::vector* geometry, const CAreaRenderOctTree* octTree, + int areaIdx, const SShader* shaderSet) override; + void EnablePVS(const CPVSVisSet& set, u32 areaIdx) override; void DisablePVS() override; void UpdateAreaUniforms(int areaIdx, EWorldShadowMode shadowMode = EWorldShadowMode::None, bool activateLights = true, int cubeFace = -1, const CModelFlags* ballShadowFlags = nullptr); @@ -212,17 +212,18 @@ public: void DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly) override; void PostRenderFogs() override; void SetModelMatrix(const zeus::CTransform& xf) override; - void AddParticleGen(const CParticleGen&) override; - void AddParticleGen(const CParticleGen&, const zeus::CVector3f&, const zeus::CAABox&) override; - void AddPlaneObject(const void*, const zeus::CAABox&, const zeus::CPlane&, int) override; - void AddDrawable(void const*, const zeus::CVector3f&, const zeus::CAABox&, int, EDrawableSorting) override; - void SetDrawableCallback(TDrawableCallback, const void*) override; - void SetWorldViewpoint(const zeus::CTransform&) override; - void SetPerspective(float, float, float, float, float) override; - void SetPerspective(float, float, float, float) override; - std::pair SetViewportOrtho(bool, float, float) override; + void AddParticleGen(const CParticleGen& gen) override; + void AddParticleGen(const CParticleGen& gen, const zeus::CVector3f& pos, const zeus::CAABox& bounds) override; + void AddPlaneObject(const void* obj, const zeus::CAABox& aabb, const zeus::CPlane& plane, int type) override; + void AddDrawable(const void* obj, const zeus::CVector3f& pos, const zeus::CAABox& aabb, int mode, + EDrawableSorting sorting) override; + void SetDrawableCallback(TDrawableCallback cb, const void* ctx) override; + void SetWorldViewpoint(const zeus::CTransform& xf) override; + void SetPerspective(float fovy, float width, float height, float znear, float zfar) override; + void SetPerspective(float fovy, float aspect, float znear, float zfar) override; + std::pair SetViewportOrtho(bool centered, float znear, float zfar) override; void SetClippingPlanes(const zeus::CFrustum& frustum) override; - void SetViewport(int, int, int, int) override; + void SetViewport(int left, int bottom, int width, int height) override; // void SetDepthReadWrite(bool, bool); // void SetBlendMode_AdditiveAlpha(); // void SetBlendMode_AlphaBlended(); @@ -246,18 +247,18 @@ public: // void PrimColor(float, float, float, float); // void PrimColor(const zeus::CColor&); // void EndPrimitive(); - void SetAmbientColor(const zeus::CColor&) override; - void DrawString(const char*, int, int) override; + void SetAmbientColor(const zeus::CColor& color) override; + void DrawString(const char* string, int, int) override; u32 GetFPS() override; - void CacheReflection(TReflectionCallback, void*, bool) override; - void DrawSpaceWarp(const zeus::CVector3f&, float) override; + void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) override; + void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) override; void DrawThermalModel(const CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol) override; void DrawXRayOutline(const zeus::CAABox&) override; - void SetWireframeFlags(int) override; - void SetWorldFog(ERglFogMode, float, float, const zeus::CColor&) override; - void RenderFogVolume(const zeus::CColor&, const zeus::CAABox&, const TLockedToken*, - const CSkinnedModel*) override; - void SetThermal(bool, float, const zeus::CColor&) override; + void SetWireframeFlags(int flags) override; + void SetWorldFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color) override; + void RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const TLockedToken* model, + const CSkinnedModel* sModel) override; + void SetThermal(bool thermal, float level, const zeus::CColor& color) override; void SetThermalColdScale(float scale) override; void DoThermalBlendCold() override; void DoThermalBlendHot() override; diff --git a/Runtime/Graphics/CGraphicsPalette.hpp b/Runtime/Graphics/CGraphicsPalette.hpp index 72e78b8b7..6c7b7e25b 100644 --- a/Runtime/Graphics/CGraphicsPalette.hpp +++ b/Runtime/Graphics/CGraphicsPalette.hpp @@ -21,8 +21,9 @@ class CGraphicsPalette { bool x1c_ = false; public: - CGraphicsPalette(EPaletteFormat fmt, int count) : x0_fmt(fmt), x8_entryCount(count), xc_entries(new u16[count]) {} - CGraphicsPalette(CInputStream& in) : x0_fmt(EPaletteFormat(in.readUint32Big())) { + explicit CGraphicsPalette(EPaletteFormat fmt, int count) + : x0_fmt(fmt), x8_entryCount(count), xc_entries(new u16[count]) {} + explicit CGraphicsPalette(CInputStream& in) : x0_fmt(EPaletteFormat(in.readUint32Big())) { u16 w = in.readUint16Big(); u16 h = in.readUint16Big(); x8_entryCount = w * h; diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index 62a79969f..9460599f3 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -106,7 +106,7 @@ struct SShader { MaterialSet m_matSet; std::optional m_geomLayout; int m_matSetIdx; - SShader(int idx) : m_matSetIdx(idx) { + explicit SShader(int idx) : m_matSetIdx(idx) { x0_textures.clear(); m_shaders.clear(); } diff --git a/Runtime/Graphics/CPVSAreaSet.hpp b/Runtime/Graphics/CPVSAreaSet.hpp index 732ca0e0e..fcd1ee99c 100644 --- a/Runtime/Graphics/CPVSAreaSet.hpp +++ b/Runtime/Graphics/CPVSAreaSet.hpp @@ -25,7 +25,7 @@ class CPVSAreaSet { } public: - CPVSAreaSet(const u8* data, u32 len); + explicit CPVSAreaSet(const u8* data, u32 len); u32 GetNumFeatures() const { return x0_numFeatures; } u32 GetNumActors() const { return xc_numActors; } u32 Get1stLightIndex(u32 lightIdx) const { return x0_numFeatures + x8_num2ndLights + lightIdx; } diff --git a/Runtime/Graphics/CRainSplashGenerator.cpp b/Runtime/Graphics/CRainSplashGenerator.cpp index b43c43654..dd91613c3 100644 --- a/Runtime/Graphics/CRainSplashGenerator.cpp +++ b/Runtime/Graphics/CRainSplashGenerator.cpp @@ -75,8 +75,9 @@ CRainSplashGenerator::SSplashLine::SSplashLine(boo::IGraphicsDataFactory::Contex : m_renderer(ctx, CLineRenderer::EPrimitiveMode::LineStrip, 3, nullptr, false) {} CRainSplashGenerator::SRainSplash::SRainSplash(boo::IGraphicsDataFactory::Context& ctx) { - for (int i = 0; i < 4; ++i) + for (size_t i = 0; i < x0_lines.capacity(); ++i) { x0_lines.emplace_back(ctx); + } } void CRainSplashGenerator::SSplashLine::Update(float dt, CStateManager& mgr) { diff --git a/Runtime/Graphics/CSkinnedModel.hpp b/Runtime/Graphics/CSkinnedModel.hpp index cffc1a074..82dbdf89b 100644 --- a/Runtime/Graphics/CSkinnedModel.hpp +++ b/Runtime/Graphics/CSkinnedModel.hpp @@ -6,6 +6,7 @@ #include #include "Runtime/CToken.hpp" +#include "Runtime/Character/CSkinRules.hpp" #include "Runtime/Graphics/CModel.hpp" #include @@ -14,7 +15,6 @@ namespace urde { class CCharLayoutInfo; class CModel; class CPoseAsTransforms; -class CSkinRules; class CVertexMorphEffect; class IObjectStore; @@ -47,7 +47,7 @@ public: const std::optional& morphEffect, const float* morphMagnitudes); void Draw(const CModelFlags& drawFlags) const; - typedef void (*FPointGenerator)(void* item, const std::vector>& vn); + using FPointGenerator = void (*)(void* item, const std::vector>& vn); static void SetPointGeneratorFunc(void* ctx, FPointGenerator func) { g_PointGenFunc = func; g_PointGenCtx = ctx; diff --git a/Runtime/Graphics/IRenderer.hpp b/Runtime/Graphics/IRenderer.hpp index 83c2e9aef..0d6bfae8c 100644 --- a/Runtime/Graphics/IRenderer.hpp +++ b/Runtime/Graphics/IRenderer.hpp @@ -27,7 +27,7 @@ struct SShader; class IRenderer { public: - typedef void (*TDrawableCallback)(const void*, const void*, int); + using TDrawableCallback = void (*)(const void*, const void*, int); using TReflectionCallback = std::function; enum class EDrawableSorting { SortedCallback, UnsortedCallback }; @@ -35,11 +35,11 @@ public: enum class EPrimitiveType {}; virtual ~IRenderer() = default; - virtual void AddStaticGeometry(const std::vector*, const CAreaRenderOctTree*, int, - const SShader*) = 0; - virtual void EnablePVS(const CPVSVisSet&, u32) = 0; + virtual void AddStaticGeometry(const std::vector* geometry, const CAreaRenderOctTree* octTree, + int areaIdx, const SShader* shaderSet) = 0; + virtual void EnablePVS(const CPVSVisSet& set, u32 areaIdx) = 0; virtual void DisablePVS() = 0; - virtual void RemoveStaticGeometry(const std::vector*) = 0; + virtual void RemoveStaticGeometry(const std::vector* geometry) = 0; virtual void DrawAreaGeometry(int areaIdx, int mask, int targetMask) = 0; virtual void DrawUnsortedGeometry(int areaIdx, int mask, int targetMask, bool shadowRender = false) = 0; virtual void DrawSortedGeometry(int areaIdx, int mask, int targetMask) = 0; @@ -47,17 +47,18 @@ public: virtual void DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly) = 0; virtual void PostRenderFogs() = 0; virtual void SetModelMatrix(const zeus::CTransform& xf) = 0; - virtual void AddParticleGen(const CParticleGen&) = 0; - virtual void AddParticleGen(const CParticleGen&, const zeus::CVector3f&, const zeus::CAABox&) = 0; - virtual void AddPlaneObject(const void*, const zeus::CAABox&, const zeus::CPlane&, int) = 0; - virtual void AddDrawable(void const*, const zeus::CVector3f&, const zeus::CAABox&, int, EDrawableSorting) = 0; - virtual void SetDrawableCallback(TDrawableCallback, const void*) = 0; - virtual void SetWorldViewpoint(const zeus::CTransform&) = 0; - virtual void SetPerspective(float, float, float, float, float) = 0; - virtual void SetPerspective(float, float, float, float) = 0; - virtual std::pair SetViewportOrtho(bool, float, float) = 0; - virtual void SetClippingPlanes(const zeus::CFrustum&) = 0; - virtual void SetViewport(int, int, int, int) = 0; + virtual void AddParticleGen(const CParticleGen& gen) = 0; + virtual void AddParticleGen(const CParticleGen& gen, const zeus::CVector3f& pos, const zeus::CAABox& bounds) = 0; + virtual void AddPlaneObject(const void* obj, const zeus::CAABox& aabb, const zeus::CPlane& plane, int type) = 0; + virtual void AddDrawable(const void* obj, const zeus::CVector3f& pos, const zeus::CAABox& aabb, int mode, + EDrawableSorting sorting) = 0; + virtual void SetDrawableCallback(TDrawableCallback cb, const void* ctx) = 0; + virtual void SetWorldViewpoint(const zeus::CTransform& xf) = 0; + virtual void SetPerspective(float fovy, float width, float height, float znear, float zfar) = 0; + virtual void SetPerspective(float fovy, float aspect, float znear, float zfar) = 0; + virtual std::pair SetViewportOrtho(bool centered, float znear, float zfar) = 0; + virtual void SetClippingPlanes(const zeus::CFrustum& frustum) = 0; + virtual void SetViewport(int left, int bottom, int width, int height) = 0; // virtual void SetDepthReadWrite(bool, bool)=0; // virtual void SetBlendMode_AdditiveAlpha()=0; // virtual void SetBlendMode_AlphaBlended()=0; @@ -81,18 +82,18 @@ public: // virtual void PrimColor(float, float, float, float)=0; // virtual void PrimColor(const zeus::CColor&)=0; // virtual void EndPrimitive()=0; - virtual void SetAmbientColor(const zeus::CColor&) = 0; - virtual void DrawString(const char*, int, int) = 0; + virtual void SetAmbientColor(const zeus::CColor& color) = 0; + virtual void DrawString(const char* string, int, int) = 0; virtual u32 GetFPS() = 0; - virtual void CacheReflection(TReflectionCallback, void*, bool) = 0; - virtual void DrawSpaceWarp(const zeus::CVector3f&, float) = 0; - virtual void DrawThermalModel(const CModel&, const zeus::CColor&, const zeus::CColor&) = 0; - virtual void DrawXRayOutline(const zeus::CAABox&) = 0; - virtual void SetWireframeFlags(int) = 0; - virtual void SetWorldFog(ERglFogMode, float, float, const zeus::CColor&) = 0; - virtual void RenderFogVolume(const zeus::CColor&, const zeus::CAABox&, const TLockedToken*, - const CSkinnedModel*) = 0; - virtual void SetThermal(bool, float, const zeus::CColor&) = 0; + virtual void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) = 0; + virtual void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) = 0; + virtual void DrawThermalModel(const CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol) = 0; + virtual void DrawXRayOutline(const zeus::CAABox& aabb) = 0; + virtual void SetWireframeFlags(int flags) = 0; + virtual void SetWorldFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color) = 0; + virtual void RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const TLockedToken* model, + const CSkinnedModel* sModel) = 0; + virtual void SetThermal(bool thermal, float level, const zeus::CColor& color) = 0; virtual void SetThermalColdScale(float scale) = 0; virtual void DoThermalBlendCold() = 0; virtual void DoThermalBlendHot() = 0; diff --git a/Runtime/Graphics/Shaders/CAABoxShader.hpp b/Runtime/Graphics/Shaders/CAABoxShader.hpp index 26b6e3096..ff3785fd0 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.hpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.hpp @@ -24,7 +24,7 @@ class CAABoxShader { public: static void Initialize(); static void Shutdown(); - CAABoxShader(bool zOnly = false); + explicit CAABoxShader(bool zOnly = false); void setAABB(const zeus::CAABox& aabb); void draw(const zeus::CColor& color); }; diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp index e6a61e281..631a4ee68 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp @@ -28,8 +28,8 @@ public: static void Initialize(); static void Shutdown(); static const zeus::CRectangle DefaultRect; - CColoredQuadFilter(EFilterType type); - CColoredQuadFilter(EFilterType type, const TLockedToken&) : CColoredQuadFilter(type) {} + explicit CColoredQuadFilter(EFilterType type); + explicit CColoredQuadFilter(EFilterType type, const TLockedToken&) : CColoredQuadFilter(type) {} void draw(const zeus::CColor& color, const zeus::CRectangle& rect = DefaultRect); void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t) { draw(color); } }; @@ -39,8 +39,8 @@ class CWideScreenFilter { CColoredQuadFilter m_bottom; public: - CWideScreenFilter(EFilterType type) : m_top(type), m_bottom(type) {} - CWideScreenFilter(EFilterType type, const TLockedToken&) : CWideScreenFilter(type) {} + explicit CWideScreenFilter(EFilterType type) : m_top(type), m_bottom(type) {} + explicit CWideScreenFilter(EFilterType type, const TLockedToken&) : CWideScreenFilter(type) {} void draw(const zeus::CColor& color, float t); void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t); diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp b/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp index b48b224c8..858afe2b9 100644 --- a/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp +++ b/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp @@ -26,16 +26,16 @@ class CRandomStaticFilter { public: static void Initialize(); static void Shutdown(); - CRandomStaticFilter(EFilterType type, bool cookieCutter = false); - CRandomStaticFilter(EFilterType type, const TLockedToken&) : CRandomStaticFilter(type) {} + explicit CRandomStaticFilter(EFilterType type, bool cookieCutter = false); + explicit CRandomStaticFilter(EFilterType type, const TLockedToken&) : CRandomStaticFilter(type) {} void draw(const zeus::CColor& color, float t); void DrawFilter(EFilterShape, const zeus::CColor& color, float t) { draw(color, t); } }; class CCookieCutterDepthRandomStaticFilter : public CRandomStaticFilter { public: - CCookieCutterDepthRandomStaticFilter(EFilterType type) : CRandomStaticFilter(type, true) {} - CCookieCutterDepthRandomStaticFilter(EFilterType type, const TLockedToken&) + explicit CCookieCutterDepthRandomStaticFilter(EFilterType type) : CRandomStaticFilter(type, true) {} + explicit CCookieCutterDepthRandomStaticFilter(EFilterType type, const TLockedToken&) : CCookieCutterDepthRandomStaticFilter(type) {} }; diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp index a789d957a..fd20fc785 100644 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp +++ b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp @@ -23,21 +23,21 @@ class CScanLinesFilter { public: static void Initialize(); static void Shutdown(); - CScanLinesFilter(EFilterType type, bool even); + explicit CScanLinesFilter(EFilterType type, bool even); void draw(const zeus::CColor& color); void DrawFilter(EFilterShape, const zeus::CColor& color, float) { draw(color); } }; class CScanLinesFilterEven : public CScanLinesFilter { public: - CScanLinesFilterEven(EFilterType type) : CScanLinesFilter(type, true) {} - CScanLinesFilterEven(EFilterType type, const TLockedToken&) : CScanLinesFilterEven(type) {} + explicit CScanLinesFilterEven(EFilterType type) : CScanLinesFilter(type, true) {} + explicit CScanLinesFilterEven(EFilterType type, const TLockedToken&) : CScanLinesFilterEven(type) {} }; class CScanLinesFilterOdd : public CScanLinesFilter { public: - CScanLinesFilterOdd(EFilterType type) : CScanLinesFilter(type, false) {} - CScanLinesFilterOdd(EFilterType type, const TLockedToken&) : CScanLinesFilterOdd(type) {} + explicit CScanLinesFilterOdd(EFilterType type) : CScanLinesFilter(type, false) {} + explicit CScanLinesFilterOdd(EFilterType type, const TLockedToken&) : CScanLinesFilterOdd(type) {} }; } // namespace urde diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp index 9a96f973d..a035394e5 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp @@ -35,7 +35,7 @@ protected: ZTest m_zTest; bool m_flipRect = false; - CTexturedQuadFilter(const boo::ObjToken& tex); + explicit CTexturedQuadFilter(const boo::ObjToken& tex); public: struct Vert { @@ -45,8 +45,8 @@ public: static void Initialize(); static void Shutdown(); static const zeus::CRectangle DefaultRect; - CTexturedQuadFilter(EFilterType type, TLockedToken tex, ZTest zTest = ZTest::None); - CTexturedQuadFilter(EFilterType type, const boo::ObjToken& tex, ZTest zTest = ZTest::None); + explicit CTexturedQuadFilter(EFilterType type, TLockedToken tex, ZTest zTest = ZTest::None); + explicit CTexturedQuadFilter(EFilterType type, const boo::ObjToken& tex, ZTest zTest = ZTest::None); CTexturedQuadFilter(const CTexturedQuadFilter&) = delete; CTexturedQuadFilter& operator=(const CTexturedQuadFilter&) = delete; CTexturedQuadFilter(CTexturedQuadFilter&&) = default; @@ -63,8 +63,8 @@ class CTexturedQuadFilterAlpha : public CTexturedQuadFilter { public: static void Initialize(); static void Shutdown(); - CTexturedQuadFilterAlpha(EFilterType type, TLockedToken tex); - CTexturedQuadFilterAlpha(EFilterType type, const boo::ObjToken& tex); + explicit CTexturedQuadFilterAlpha(EFilterType type, TLockedToken tex); + explicit CTexturedQuadFilterAlpha(EFilterType type, const boo::ObjToken& tex); }; } // namespace urde diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp index 0e0c189b6..b63708481 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp @@ -30,7 +30,7 @@ class CWorldShadowShader { public: static void Initialize(); static void Shutdown(); - CWorldShadowShader(u32 w, u32 h); + explicit CWorldShadowShader(u32 w, u32 h); void bindRenderTarget(); void drawBase(float extent); void lightenShadow(); diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp index 35b08d986..704f9b235 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp @@ -24,7 +24,7 @@ class CXRayBlurFilter { public: static void Initialize(); static void Shutdown(); - CXRayBlurFilter(TLockedToken& tex); + explicit CXRayBlurFilter(TLockedToken& tex); void draw(float amount); }; diff --git a/Runtime/GuiSys/CAuiImagePane.cpp b/Runtime/GuiSys/CAuiImagePane.cpp index e73db407f..996e1ad4f 100644 --- a/Runtime/GuiSys/CAuiImagePane.cpp +++ b/Runtime/GuiSys/CAuiImagePane.cpp @@ -54,9 +54,9 @@ void CAuiImagePane::Update(float dt) { CAuiImagePane::Filters::Filters(TLockedToken& tex) : m_texId(tex.GetObjectTag()->id) , m_darkenerQuad(EFilterType::Blend, tex) -, m_flashQuad{{{EFilterType::Add, tex}, {EFilterType::Add, tex}}} -, m_alphaQuad{{{EFilterType::Blend, tex}, {EFilterType::Blend, tex}}} -, m_addQuad{{{EFilterType::Add, tex}, {EFilterType::Add, tex}}} {} +, m_flashQuad{{CTexturedQuadFilterAlpha{EFilterType::Add, tex}, CTexturedQuadFilterAlpha{EFilterType::Add, tex}}} +, m_alphaQuad{{CTexturedQuadFilterAlpha{EFilterType::Blend, tex}, CTexturedQuadFilterAlpha{EFilterType::Blend, tex}}} +, m_addQuad{{CTexturedQuadFilterAlpha{EFilterType::Add, tex}, CTexturedQuadFilterAlpha{EFilterType::Add, tex}}} {} void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& tex, int frame, float alpha, bool noBlur, CTexturedQuadFilterAlpha& quad) const { diff --git a/Runtime/GuiSys/CCompoundTargetReticle.hpp b/Runtime/GuiSys/CCompoundTargetReticle.hpp index 06a6987a5..e1df8b7e0 100644 --- a/Runtime/GuiSys/CCompoundTargetReticle.hpp +++ b/Runtime/GuiSys/CCompoundTargetReticle.hpp @@ -59,7 +59,7 @@ public: float x10_rotAng = 0.f; float x14_baseAngle = 0.f; float x18_offshootAngleDelta = 0.f; - SOuterItemInfo(std::string_view); + explicit SOuterItemInfo(std::string_view); }; private: @@ -135,7 +135,7 @@ private: bool zEqual) const; public: - CCompoundTargetReticle(const CStateManager&); + explicit CCompoundTargetReticle(const CStateManager&); void SetLeadingOrientation(const zeus::CQuaternion& o) { x0_leadingOrientation = o; } bool CheckLoadComplete() { return true; } diff --git a/Runtime/GuiSys/CConsoleOutputWindow.cpp b/Runtime/GuiSys/CConsoleOutputWindow.cpp index 6348d0efe..f010c5de3 100644 --- a/Runtime/GuiSys/CConsoleOutputWindow.cpp +++ b/Runtime/GuiSys/CConsoleOutputWindow.cpp @@ -9,7 +9,7 @@ CIOWin::EMessageReturn CConsoleOutputWindow::OnMessage(const CArchitectureMessag return EMessageReturn::Normal; } -void CConsoleOutputWindow::Draw() const { +void CConsoleOutputWindow::Draw() { //SCOPED_GRAPHICS_DEBUG_GROUP("CConsoleOutputWindow::Draw", zeus::skGreen); } diff --git a/Runtime/GuiSys/CConsoleOutputWindow.hpp b/Runtime/GuiSys/CConsoleOutputWindow.hpp index 65fc0f862..40a8bb69f 100644 --- a/Runtime/GuiSys/CConsoleOutputWindow.hpp +++ b/Runtime/GuiSys/CConsoleOutputWindow.hpp @@ -8,7 +8,7 @@ class CConsoleOutputWindow : public CIOWin { public: CConsoleOutputWindow(int, float, float); EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&) override; - void Draw() const override; + void Draw() override; }; } // namespace urde diff --git a/Runtime/GuiSys/CErrorOutputWindow.cpp b/Runtime/GuiSys/CErrorOutputWindow.cpp index 4877135c7..04596dd20 100644 --- a/Runtime/GuiSys/CErrorOutputWindow.cpp +++ b/Runtime/GuiSys/CErrorOutputWindow.cpp @@ -15,7 +15,7 @@ CIOWin::EMessageReturn CErrorOutputWindow::OnMessage(const CArchitectureMessage& return EMessageReturn::Normal; } -void CErrorOutputWindow::Draw() const { +void CErrorOutputWindow::Draw() { //SCOPED_GRAPHICS_DEBUG_GROUP("CErrorOutputWindow::Draw", zeus::skGreen); } diff --git a/Runtime/GuiSys/CErrorOutputWindow.hpp b/Runtime/GuiSys/CErrorOutputWindow.hpp index 2189d77d2..85b2231d6 100644 --- a/Runtime/GuiSys/CErrorOutputWindow.hpp +++ b/Runtime/GuiSys/CErrorOutputWindow.hpp @@ -24,10 +24,10 @@ private: const wchar_t* x1c_msg; public: - CErrorOutputWindow(bool); + explicit CErrorOutputWindow(bool); EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&) override; bool GetIsContinueDraw() const override { return int(x14_state) < 2; } - void Draw() const override; + void Draw() override; }; } // namespace urde diff --git a/Runtime/GuiSys/CGuiCompoundWidget.hpp b/Runtime/GuiSys/CGuiCompoundWidget.hpp index 9eaac99c4..97752f7fe 100644 --- a/Runtime/GuiSys/CGuiCompoundWidget.hpp +++ b/Runtime/GuiSys/CGuiCompoundWidget.hpp @@ -6,7 +6,7 @@ namespace urde { class CGuiCompoundWidget : public CGuiWidget { public: - CGuiCompoundWidget(const CGuiWidgetParms& parms); + explicit CGuiCompoundWidget(const CGuiWidgetParms& parms); FourCC GetWidgetTypeID() const override { return FourCC(-1); } void OnVisibleChange() override; diff --git a/Runtime/GuiSys/CGuiHeadWidget.hpp b/Runtime/GuiSys/CGuiHeadWidget.hpp index 46abbac73..cd710fe2c 100644 --- a/Runtime/GuiSys/CGuiHeadWidget.hpp +++ b/Runtime/GuiSys/CGuiHeadWidget.hpp @@ -7,7 +7,7 @@ namespace urde { class CGuiHeadWidget : public CGuiWidget { public: FourCC GetWidgetTypeID() const override { return FOURCC('HWIG'); } - CGuiHeadWidget(const CGuiWidgetParms& parms); + explicit CGuiHeadWidget(const CGuiWidgetParms& parms); static std::shared_ptr Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp); std::shared_ptr shared_from_this() { diff --git a/Runtime/GuiSys/CGuiTextPane.cpp b/Runtime/GuiSys/CGuiTextPane.cpp index 592bcdf3a..681b89cf7 100644 --- a/Runtime/GuiSys/CGuiTextPane.cpp +++ b/Runtime/GuiSys/CGuiTextPane.cpp @@ -1,5 +1,7 @@ #include "Runtime/GuiSys/CGuiTextPane.hpp" +#include + #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CGraphicsPalette.hpp" #include "Runtime/GuiSys/CFontImageDef.hpp" @@ -8,6 +10,19 @@ #include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp" namespace urde { +namespace { +constexpr std::array NormalPoints{{ + {0.f, 0.f, -1.f}, + {1.f, 0.f, -1.f}, + {1.f, 0.f, 0.f}, + {0.f, 0.f, 0.f}, +}}; + +bool testProjectedLine(const zeus::CVector2f& a, const zeus::CVector2f& b, const zeus::CVector2f& point) { + const zeus::CVector2f normal = (b - a).perpendicularVector().normalized(); + return point.dot(normal) >= a.dot(normal); +} +} // Anonymous namespace CGuiTextPane::CGuiTextPane(const CGuiWidgetParms& parms, CSimplePool* sp, const zeus::CVector2f& dim, const zeus::CVector3f& vec, CAssetId fontId, const CGuiTextProperties& props, @@ -85,8 +100,7 @@ void CGuiTextPane::Draw(const CGuiWidgetDrawParms& parms) { CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear); xd4_textSupport.Render(); - const_cast(this)->xd4_textSupport.SetGeometryColor - (geomCol * zeus::CColor(geomCol.a, geomCol.a, geomCol.a, 1.f)); + xd4_textSupport.SetGeometryColor(geomCol * zeus::CColor(geomCol.a, geomCol.a, geomCol.a, 1.f)); CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::One, ERglBlendFactor::One, ERglLogicOp::Clear); xd4_textSupport.Render(); @@ -97,32 +111,22 @@ void CGuiTextPane::Draw(const CGuiWidgetDrawParms& parms) { #endif } -static const zeus::CVector3f NormalPoints[] = { - {0.f, 0.f, -1.f}, - {1.f, 0.f, -1.f}, - {1.f, 0.f, 0.f}, - {0.f, 0.f, 0.f} -}; - -static bool testProjectedLine(const zeus::CVector2f& a, const zeus::CVector2f& b, const zeus::CVector2f& point) { - zeus::CVector2f normal = (b - a).perpendicularVector().normalized(); - return point.dot(normal) >= a.dot(normal); -} - bool CGuiTextPane::TestCursorHit(const zeus::CMatrix4f& vp, const zeus::CVector2f& point) const { - zeus::CVector2f dims = GetDimensions(); - zeus::CTransform local = zeus::CTransform::Translate(xc0_verts.front().m_pos + xc8_scaleCenter) * - zeus::CTransform::Scale(dims.x(), 1.f, dims.y()); - zeus::CMatrix4f mvp = vp * (x34_worldXF * local).toMatrix4f(); + const zeus::CVector2f dims = GetDimensions(); + const zeus::CTransform local = zeus::CTransform::Translate(xc0_verts.front().m_pos + xc8_scaleCenter) * + zeus::CTransform::Scale(dims.x(), 1.f, dims.y()); + const zeus::CMatrix4f mvp = vp * (x34_worldXF * local).toMatrix4f(); - zeus::CVector2f projPoints[4]; - for (int i = 0; i < 4; ++i) + std::array projPoints; + for (size_t i = 0; i < projPoints.size(); ++i) { projPoints[i] = mvp.multiplyOneOverW(NormalPoints[i]).toVec2f(); + } - int j; + size_t j; for (j = 0; j < 3; ++j) { - if (!testProjectedLine(projPoints[j], projPoints[j + 1], point)) + if (!testProjectedLine(projPoints[j], projPoints[j + 1], point)) { break; + } } return j == 3 && testProjectedLine(projPoints[3], projPoints[0], point); } diff --git a/Runtime/GuiSys/CGuiTextSupport.cpp b/Runtime/GuiSys/CGuiTextSupport.cpp index e343d35a6..a2a6cb993 100644 --- a/Runtime/GuiSys/CGuiTextSupport.cpp +++ b/Runtime/GuiSys/CGuiTextSupport.cpp @@ -25,21 +25,47 @@ CGuiTextSupport::CGuiTextSupport(CAssetId fontId, const CGuiTextProperties& prop x2cc_font = store->GetObj({SBIG('FONT'), fontId}); } -CTextRenderBuffer* CGuiTextSupport::GetCurrentPageRenderBuffer() const { - if (x60_renderBuf && !x308_multipageFlag) - return const_cast(&*x60_renderBuf); - if (!x308_multipageFlag || x2ec_renderBufferPages.size() <= x304_pageCounter) +CTextRenderBuffer* CGuiTextSupport::GetCurrentPageRenderBuffer() { + if (x60_renderBuf && !x308_multipageFlag) { + return &*x60_renderBuf; + } + + if (!x308_multipageFlag || x2ec_renderBufferPages.size() <= x304_pageCounter) { return nullptr; + } + int idx = 0; - for (const CTextRenderBuffer& buf : x2ec_renderBufferPages) - if (idx++ == x304_pageCounter) - return const_cast(&buf); + for (CTextRenderBuffer& buf : x2ec_renderBufferPages) { + if (idx++ == x304_pageCounter) { + return &buf; + } + } + + return nullptr; +} + +const CTextRenderBuffer* CGuiTextSupport::GetCurrentPageRenderBuffer() const { + if (x60_renderBuf && !x308_multipageFlag) { + return &*x60_renderBuf; + } + + if (!x308_multipageFlag || x2ec_renderBufferPages.size() <= x304_pageCounter) { + return nullptr; + } + + int idx = 0; + for (const CTextRenderBuffer& buf : x2ec_renderBufferPages) { + if (idx++ == x304_pageCounter) { + return &buf; + } + } + return nullptr; } float CGuiTextSupport::GetCurrentAnimationOverAge() const { float ret = 0.f; - if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) { + if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) { if (x50_typeEnable) { if (x40_primStartTimes.size()) { auto& lastTime = x40_primStartTimes.back(); @@ -53,16 +79,18 @@ float CGuiTextSupport::GetCurrentAnimationOverAge() const { } float CGuiTextSupport::GetNumCharsTotal() const { - if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) - if (x50_typeEnable) + if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) { + if (x50_typeEnable) { return buf->GetPrimitiveCount(); + } + } return 0.f; } float CGuiTextSupport::GetNumCharsPrinted() const { - if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) { + if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) { if (x50_typeEnable) { - float charsPrinted = x3c_curTime * x58_chRate; + const float charsPrinted = x3c_curTime * x58_chRate; return std::min(charsPrinted, float(buf->GetPrimitiveCount())); } } @@ -70,9 +98,11 @@ float CGuiTextSupport::GetNumCharsPrinted() const { } float CGuiTextSupport::GetTotalAnimationTime() const { - if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) - if (x50_typeEnable) + if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) { + if (x50_typeEnable) { return buf->GetPrimitiveCount() / x58_chRate; + } + } return 0.f; } @@ -186,8 +216,8 @@ void CGuiTextSupport::AutoSetExtent() { x38_extentY = bounds.second.y; } -void CGuiTextSupport::Render() const { - const_cast(this)->CheckAndRebuildRenderBuffer(); +void CGuiTextSupport::Render() { + CheckAndRebuildRenderBuffer(); if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) { SCOPED_GRAPHICS_DEBUG_GROUP("CGuiTextSupport::Draw", zeus::skBlue); zeus::CTransform oldModel = CGraphics::g_GXModelMatrix; @@ -235,16 +265,23 @@ void CGuiTextSupport::SetText(std::u16string_view str, bool multipage) { void CGuiTextSupport::SetText(std::string_view str, bool multipage) { SetText(hecl::UTF8ToChar16(str), multipage); } -bool CGuiTextSupport::_GetIsTextSupportFinishedLoading() const { - for (const CToken& tok : x2bc_assets) { - const_cast(tok).Lock(); - if (!tok.IsLoaded()) +bool CGuiTextSupport::_GetIsTextSupportFinishedLoading() { + for (CToken& tok : x2bc_assets) { + tok.Lock(); + + if (!tok.IsLoaded()) { return false; + } } - if (!x2cc_font) + + if (!x2cc_font) { return true; - if (x2cc_font.IsLoaded()) + } + + if (x2cc_font.IsLoaded()) { return x2cc_font->IsFinishedLoading(); + } + return false; } @@ -269,8 +306,8 @@ void CGuiTextSupport::SetImageBaseline(bool b) { } } -bool CGuiTextSupport::GetIsTextSupportFinishedLoading() const { - const_cast(this)->CheckAndRebuildRenderBuffer(); +bool CGuiTextSupport::GetIsTextSupportFinishedLoading() { + CheckAndRebuildRenderBuffer(); return _GetIsTextSupportFinishedLoading(); } diff --git a/Runtime/GuiSys/CGuiTextSupport.hpp b/Runtime/GuiSys/CGuiTextSupport.hpp index fa7ecd1b6..6cc9c833f 100644 --- a/Runtime/GuiSys/CGuiTextSupport.hpp +++ b/Runtime/GuiSys/CGuiTextSupport.hpp @@ -84,8 +84,10 @@ class CGuiTextSupport { int x304_pageCounter = 0; bool x308_multipageFlag = false; - CTextRenderBuffer* GetCurrentPageRenderBuffer() const; - bool _GetIsTextSupportFinishedLoading() const; + CTextRenderBuffer* GetCurrentPageRenderBuffer(); + const CTextRenderBuffer* GetCurrentPageRenderBuffer() const; + + bool _GetIsTextSupportFinishedLoading(); public: CGuiTextSupport(CAssetId fontId, const CGuiTextProperties& props, const zeus::CColor& fontCol, @@ -104,7 +106,7 @@ public: const std::pair& GetBounds(); void AutoSetExtent(); - void Render() const; + void Render(); void SetGeometryColor(const zeus::CColor& col); void SetOutlineColor(const zeus::CColor& col); void SetFontColor(const zeus::CColor& col); @@ -114,7 +116,7 @@ public: void SetJustification(EJustification j); void SetVerticalJustification(EVerticalJustification j); void SetImageBaseline(bool b); - bool GetIsTextSupportFinishedLoading() const; + bool GetIsTextSupportFinishedLoading(); float GetCurTime() const { return x3c_curTime; } void SetCurTime(float t) { x3c_curTime = t; } std::u16string_view GetString() const { return x0_string; } diff --git a/Runtime/GuiSys/CGuiWidget.cpp b/Runtime/GuiSys/CGuiWidget.cpp index 7b115e938..9d398a4f9 100644 --- a/Runtime/GuiSys/CGuiWidget.cpp +++ b/Runtime/GuiSys/CGuiWidget.cpp @@ -161,27 +161,30 @@ void CGuiWidget::AddChildWidget(CGuiWidget* widget, bool makeWorldLocal, bool at bool CGuiWidget::AddWorkerWidget(CGuiWidget* worker) { return false; } -void CGuiWidget::SetVisibility(bool vis, ETraversalMode mode) { +void CGuiWidget::SetVisibility(bool visible, ETraversalMode mode) { switch (mode) { case ETraversalMode::Children: { - CGuiWidget* child = static_cast(GetChildObject()); - if (child) - child->SetVisibility(vis, ETraversalMode::ChildrenAndSiblings); + auto* child = static_cast(GetChildObject()); + if (child) { + child->SetVisibility(visible, ETraversalMode::ChildrenAndSiblings); + } break; } case ETraversalMode::ChildrenAndSiblings: { - CGuiWidget* child = static_cast(GetChildObject()); - if (child) - child->SetVisibility(vis, ETraversalMode::ChildrenAndSiblings); - CGuiWidget* nextSib = static_cast(GetNextSibling()); - if (nextSib) - nextSib->SetVisibility(vis, ETraversalMode::ChildrenAndSiblings); + auto* child = static_cast(GetChildObject()); + if (child) { + child->SetVisibility(visible, ETraversalMode::ChildrenAndSiblings); + } + auto* nextSib = static_cast(GetNextSibling()); + if (nextSib) { + nextSib->SetVisibility(visible, ETraversalMode::ChildrenAndSiblings); + } break; } default: break; } - SetIsVisible(vis); + SetIsVisible(visible); } void CGuiWidget::RecalcWidgetColor(ETraversalMode mode) { @@ -247,16 +250,18 @@ void CGuiWidget::SetColor(const zeus::CColor& color) { void CGuiWidget::OnActiveChange() {} void CGuiWidget::OnVisibleChange() {} -void CGuiWidget::SetIsVisible(bool vis) { - xb6_25_isVisible = vis; +void CGuiWidget::SetIsVisible(bool visible) { + xb6_25_isVisible = visible; OnVisibleChange(); } -void CGuiWidget::SetIsActive(bool a) { - if (a != xb6_26_isActive) { - xb6_26_isActive = a; - OnActiveChange(); +void CGuiWidget::SetIsActive(bool active) { + if (active == xb6_26_isActive) { + return; } + + xb6_26_isActive = active; + OnActiveChange(); } } // namespace urde diff --git a/Runtime/GuiSys/CGuiWidget.hpp b/Runtime/GuiSys/CGuiWidget.hpp index f1e2c0f6b..08bd22c5a 100644 --- a/Runtime/GuiSys/CGuiWidget.hpp +++ b/Runtime/GuiSys/CGuiWidget.hpp @@ -90,7 +90,7 @@ protected: std::string m_name; public: - CGuiWidget(const CGuiWidgetParms& parms); + explicit CGuiWidget(const CGuiWidgetParms& parms); static CGuiWidgetParms ReadWidgetHeader(CGuiFrame* frame, CInputStream& in); static std::shared_ptr Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp); @@ -122,24 +122,24 @@ public: const zeus::CColor& GetGeometryColor() const { return xa8_color2; } void SetIdlePosition(const zeus::CVector3f& pos, bool reapply); void ReapplyXform(); - virtual void SetIsVisible(bool); - void SetIsActive(bool); + virtual void SetIsVisible(bool visible); + void SetIsActive(bool active); bool GetIsSelectable() const { return xb6_27_isSelectable; } - void SetIsSelectable(bool v) { xb6_27_isSelectable = v; } - void SetMouseActive(bool v) { m_mouseActive = v; } + void SetIsSelectable(bool selectable) { xb6_27_isSelectable = selectable; } + void SetMouseActive(bool mouseActive) { m_mouseActive = mouseActive; } void ParseBaseInfo(CGuiFrame* frame, CInputStream& in, const CGuiWidgetParms& parms); void AddChildWidget(CGuiWidget* widget, bool makeWorldLocal, bool atEnd); - void SetVisibility(bool, ETraversalMode); - void RecalcWidgetColor(ETraversalMode); + void SetVisibility(bool visible, ETraversalMode mode); + void RecalcWidgetColor(ETraversalMode mode); void SetColor(const zeus::CColor& color); void InitializeRGBAFactor(); CGuiWidget* FindWidget(s16 id); bool GetIsFinishedLoading(); void DispatchInitialize(); - void SetDepthGreater(bool v) { xb6_30_depthGreater = v; } - void SetDepthTest(bool v) { xb6_31_depthTest = v; } - void SetDepthWrite(bool v) { xb7_24_depthWrite = v; } + void SetDepthGreater(bool depthGreater) { xb6_30_depthGreater = depthGreater; } + void SetDepthTest(bool depthTest) { xb6_31_depthTest = depthTest; } + void SetDepthWrite(bool depthWrite) { xb7_24_depthWrite = depthWrite; } CGuiFrame* GetGuiFrame() const { return xb0_frame; } }; diff --git a/Runtime/GuiSys/CGuiWidgetIdDB.cpp b/Runtime/GuiSys/CGuiWidgetIdDB.cpp index 162ee1351..075534f9b 100644 --- a/Runtime/GuiSys/CGuiWidgetIdDB.cpp +++ b/Runtime/GuiSys/CGuiWidgetIdDB.cpp @@ -21,7 +21,7 @@ s16 CGuiWidgetIdDB::AddWidget(std::string_view name, s16 id) { if (findId == -1) { if (id >= x14_lastPoolId) x14_lastPoolId = id; - x0_dbMap.emplace(std::make_pair(name, id)); + x0_dbMap.emplace(name, id); findId = id; } return findId; @@ -31,7 +31,7 @@ s16 CGuiWidgetIdDB::AddWidget(std::string_view name) { s16 findId = FindWidgetID(name); if (findId == -1) { ++x14_lastPoolId; - x0_dbMap.emplace(std::make_pair(name, x14_lastPoolId)); + x0_dbMap.emplace(name, x14_lastPoolId); findId = x14_lastPoolId; } return findId; diff --git a/Runtime/GuiSys/CHudBossEnergyInterface.hpp b/Runtime/GuiSys/CHudBossEnergyInterface.hpp index 1736f2935..71263c16f 100644 --- a/Runtime/GuiSys/CHudBossEnergyInterface.hpp +++ b/Runtime/GuiSys/CHudBossEnergyInterface.hpp @@ -20,7 +20,7 @@ class CHudBossEnergyInterface { CGuiTextPane* x1c_textpane_boss; public: - CHudBossEnergyInterface(CGuiFrame& selHud); + explicit CHudBossEnergyInterface(CGuiFrame& selHud); void Update(float dt); void SetAlpha(float a) { x0_alpha = a; } void SetBossParams(bool visible, std::u16string_view name, float curEnergy, float maxEnergy); diff --git a/Runtime/GuiSys/CHudDecoInterface.cpp b/Runtime/GuiSys/CHudDecoInterface.cpp index 5a7156584..d85df6618 100644 --- a/Runtime/GuiSys/CHudDecoInterface.cpp +++ b/Runtime/GuiSys/CHudDecoInterface.cpp @@ -17,7 +17,7 @@ namespace urde { void IHudDecoInterface::SetReticuleTransform(const zeus::CMatrix3f& xf) {} void IHudDecoInterface::SetDecoRotation(float angle) {} void IHudDecoInterface::SetFrameColorValue(float v) {} -void IHudDecoInterface::Draw() const {} +void IHudDecoInterface::Draw() {} void IHudDecoInterface::ProcessInput(const CFinalInput& input) {} float IHudDecoInterface::GetHudTextAlpha() const { return 1.f; } @@ -325,10 +325,11 @@ void CHudDecoInterfaceScan::Update(float dt, const CStateManager& stateMgr) { UpdateScanDisplay(stateMgr, dt); } -void CHudDecoInterfaceScan::Draw() const { +void CHudDecoInterfaceScan::Draw() { x18_scanDisplay.Draw(); - if (x10_loadedScanHudFlat) + if (x10_loadedScanHudFlat) { x10_loadedScanHudFlat->Draw(CGuiWidgetDrawParms::Default); + } } void CHudDecoInterfaceScan::ProcessInput(const CFinalInput& input) { x18_scanDisplay.ProcessInput(input); } diff --git a/Runtime/GuiSys/CHudDecoInterface.hpp b/Runtime/GuiSys/CHudDecoInterface.hpp index ab4ab5c83..e6e8f301e 100644 --- a/Runtime/GuiSys/CHudDecoInterface.hpp +++ b/Runtime/GuiSys/CHudDecoInterface.hpp @@ -28,7 +28,7 @@ public: virtual void SetDamageTransform(const zeus::CMatrix3f& rotation, const zeus::CVector3f& position) = 0; virtual void SetFrameColorValue(float v); virtual void Update(float dt, const CStateManager& stateMgr) = 0; - virtual void Draw() const; + virtual void Draw(); virtual void ProcessInput(const CFinalInput& input); virtual void UpdateCameraDebugSettings(float fov, float y, float z) = 0; virtual void UpdateHudAlpha() = 0; @@ -53,7 +53,7 @@ class CHudDecoInterfaceCombat : public IHudDecoInterface { void UpdateVisibility(); public: - CHudDecoInterfaceCombat(CGuiFrame& selHud); + explicit CHudDecoInterfaceCombat(CGuiFrame& selHud); void SetIsVisibleDebug(bool v) override; void SetIsVisibleGame(bool v) override; void SetHudRotation(const zeus::CQuaternion& rot) override; @@ -104,7 +104,7 @@ class CHudDecoInterfaceScan : public IHudDecoInterface { void UpdateVisibility(); public: - CHudDecoInterfaceScan(CGuiFrame& selHud); + explicit CHudDecoInterfaceScan(CGuiFrame& selHud); void SetIsVisibleDebug(bool v) override; void SetIsVisibleGame(bool v) override; void SetHudRotation(const zeus::CQuaternion& rot) override; @@ -116,7 +116,7 @@ public: const CScannableObjectInfo* GetCurrScanInfo(const CStateManager& stateMgr) const; void UpdateScanDisplay(const CStateManager& stateMgr, float dt); void Update(float dt, const CStateManager& stateMgr) override; - void Draw() const override; + void Draw() override; void ProcessInput(const CFinalInput& input) override; void UpdateCameraDebugSettings(float fov, float y, float z) override; void UpdateHudAlpha() override; @@ -142,7 +142,7 @@ class CHudDecoInterfaceXRay : public IHudDecoInterface { void UpdateVisibility(); public: - CHudDecoInterfaceXRay(CGuiFrame& selHud); + explicit CHudDecoInterfaceXRay(CGuiFrame& selHud); void SetIsVisibleDebug(bool v) override; void SetIsVisibleGame(bool v) override; void SetHudRotation(const zeus::CQuaternion& rot) override; @@ -175,7 +175,7 @@ class CHudDecoInterfaceThermal : public IHudDecoInterface { void UpdateVisibility(); public: - CHudDecoInterfaceThermal(CGuiFrame& selHud); + explicit CHudDecoInterfaceThermal(CGuiFrame& selHud); void SetIsVisibleDebug(bool v) override; void SetIsVisibleGame(bool v) override; void SetHudRotation(const zeus::CQuaternion& rot) override; diff --git a/Runtime/GuiSys/CHudFreeLookInterface.cpp b/Runtime/GuiSys/CHudFreeLookInterface.cpp index 1fc050c4c..75d86e18b 100644 --- a/Runtime/GuiSys/CHudFreeLookInterface.cpp +++ b/Runtime/GuiSys/CHudFreeLookInterface.cpp @@ -84,13 +84,9 @@ void CHudFreeLookInterface::SetFreeLookState(bool inFreeLook, bool lookControlHe x8c_basewidget_outlinesb->SetColor(color); } - if (totalInterp == 0.f) { - x74_basewidget_freelookleft->SetVisibility(false, ETraversalMode::Children); - x80_basewidget_freelookright->SetVisibility(false, ETraversalMode::Children); - } else { - x74_basewidget_freelookleft->SetVisibility(true, ETraversalMode::Children); - x80_basewidget_freelookright->SetVisibility(true, ETraversalMode::Children); - } + const bool visible = totalInterp != 0.0f; + x74_basewidget_freelookleft->SetVisibility(visible, ETraversalMode::Children); + x80_basewidget_freelookright->SetVisibility(visible, ETraversalMode::Children); } CHudFreeLookInterfaceXRay::CHudFreeLookInterfaceXRay(CGuiFrame& selHud, bool inFreeLook, bool lookControlHeld, @@ -137,6 +133,9 @@ void CHudFreeLookInterfaceXRay::SetIsVisibleGame(bool v) { void CHudFreeLookInterfaceXRay::SetFreeLookState(bool inFreeLook, bool lookControlHeld, bool lockedOnObj, float vertLookAngle) { + x20_inFreeLook = inFreeLook; + x21_lookControlHeld = lookControlHeld; + x2c_model_freelookleft->SetLocalTransform( zeus::CTransform(zeus::CMatrix3f::RotateY(vertLookAngle), x4_freeLookLeftPos)); x30_model_freelookright->SetLocalTransform( @@ -146,10 +145,8 @@ void CHudFreeLookInterfaceXRay::SetFreeLookState(bool inFreeLook, bool lookContr color.a() = x1c_freeLookInterp; x24_basewidget_freelook->SetColor(color); - if (x1c_freeLookInterp == 0.f) - x24_basewidget_freelook->SetVisibility(false, ETraversalMode::Children); - else - x24_basewidget_freelook->SetVisibility(true, ETraversalMode::Children); + const bool visible = x1c_freeLookInterp != 0.0f; + x24_basewidget_freelook->SetVisibility(visible, ETraversalMode::Children); } } // namespace urde diff --git a/Runtime/GuiSys/CHudHelmetInterface.hpp b/Runtime/GuiSys/CHudHelmetInterface.hpp index fc987a420..534f02fce 100644 --- a/Runtime/GuiSys/CHudHelmetInterface.hpp +++ b/Runtime/GuiSys/CHudHelmetInterface.hpp @@ -30,7 +30,7 @@ class CHudHelmetInterface { void UpdateVisibility(); public: - CHudHelmetInterface(CGuiFrame& helmetFrame); + explicit CHudHelmetInterface(CGuiFrame& helmetFrame); void Update(float dt); void SetHudLagOffset(const zeus::CVector3f& off); void SetHudLagRotation(const zeus::CMatrix3f& rot); diff --git a/Runtime/GuiSys/CHudVisorBeamMenu.cpp b/Runtime/GuiSys/CHudVisorBeamMenu.cpp index 843dd9367..3153cf848 100644 --- a/Runtime/GuiSys/CHudVisorBeamMenu.cpp +++ b/Runtime/GuiSys/CHudVisorBeamMenu.cpp @@ -98,7 +98,7 @@ CHudVisorBeamMenu::CHudVisorBeamMenu(CGuiFrame& baseHud, EHudVisorBeamMenu type, x20_textpane_menu->TextSupport().SetText( g_MainStringTable->GetString(MenuStringIdx[size_t(x4_type)][x8_selectedItem])); - for (int i = 0; i < 4; ++i) { + for (size_t i = 0; i < x28_menuItems.size(); ++i) { SMenuItem& item = x28_menuItems[i]; item.x0_model_loz->SetColor(g_tweakGuiColors->GetVisorBeamMenuLozColor()); UpdateMenuWidgetTransform(i, *item.x0_model_loz, 1.f); @@ -107,20 +107,22 @@ CHudVisorBeamMenu::CHudVisorBeamMenu(CGuiFrame& baseHud, EHudVisorBeamMenu type, Update(0.f, true); } -void CHudVisorBeamMenu::UpdateMenuWidgetTransform(int idx, CGuiWidget& w, float t) { - float translate = t * g_tweakGui->GetVisorBeamMenuItemTranslate(); - float scale = +void CHudVisorBeamMenu::UpdateMenuWidgetTransform(size_t idx, CGuiWidget& w, float t) { + const float translate = t * g_tweakGui->GetVisorBeamMenuItemTranslate(); + const float scale = t * g_tweakGui->GetVisorBeamMenuItemInactiveScale() + (1.f - t) * g_tweakGui->GetVisorBeamMenuItemActiveScale(); if (x4_type == EHudVisorBeamMenu::Visor) { - if (idx == 2) + if (idx == 2) { idx = 3; - else if (idx == 3) + } else if (idx == 3) { idx = 2; + } } else { - if (idx == 1) + if (idx == 1) { idx = 2; - else if (idx == 2) + } else if (idx == 2) { idx = 1; + } } switch (idx) { @@ -159,13 +161,13 @@ void CHudVisorBeamMenu::Update(float dt, bool init) { x20_textpane_menu = static_cast(x0_baseHud.FindWidget(TextNames[size_t(swappedType)])); x1c_basewidget_menutitle = x0_baseHud.FindWidget(BaseTitleNames[size_t(swappedType)]); - for (int i = 0; i < 4; ++i) { + for (size_t i = 0; i < x28_menuItems.size(); ++i) { SMenuItem& item = x28_menuItems[i]; UpdateMenuWidgetTransform(i, *item.x4_model_icon, item.x8_positioner); UpdateMenuWidgetTransform(i, *item.x0_model_loz, 1.f); } - UpdateMenuWidgetTransform(x8_selectedItem, *x24_model_ghost, x28_menuItems[x8_selectedItem].x8_positioner); + UpdateMenuWidgetTransform(size_t(x8_selectedItem), *x24_model_ghost, x28_menuItems[x8_selectedItem].x8_positioner); } zeus::CColor activeColor = g_tweakGuiColors->GetVisorBeamMenuItemActive(); @@ -173,24 +175,30 @@ void CHudVisorBeamMenu::Update(float dt, bool init) { zeus::CColor lozColor = g_tweakGuiColors->GetVisorBeamMenuLozColor(); std::array tmpColors; - for (int i = 0; i < 4; ++i) { + for (size_t i = 0; i < x28_menuItems.size(); ++i) { SMenuItem& item = x28_menuItems[i]; - if (item.xc_opacity > 0.f) + if (item.xc_opacity > 0.f) { item.xc_opacity = std::min(item.xc_opacity + dt, 1.f); + } tmpColors[i] = zeus::CColor::lerp(activeColor, zeus::skClear, item.xc_opacity); } switch (x6c_animPhase) { case EAnimPhase::Steady: - for (int i = 0; i < 4; ++i) { + for (size_t i = 0; i < x28_menuItems.size(); ++i) { SMenuItem& item = x28_menuItems[i]; - zeus::CColor& color0 = (x8_selectedItem == i) ? activeColor : inactiveColor; - zeus::CColor& color1 = (x8_selectedItem == i) ? lozColor : inactiveColor; - zeus::CColor iconColor = (item.xc_opacity == 0.f) ? zeus::skClear : color0 + tmpColors[i]; - zeus::CColor lColor = (item.xc_opacity == 0.f) ? lozColor : color1 + tmpColors[i]; + + const bool isSelectedItem = x8_selectedItem == int(i); + const bool isClear = item.xc_opacity == 0.0f; + + const zeus::CColor& color0 = isSelectedItem ? activeColor : inactiveColor; + const zeus::CColor& color1 = isSelectedItem ? lozColor : inactiveColor; + const zeus::CColor iconColor = isClear ? zeus::skClear : color0 + tmpColors[i]; + const zeus::CColor lColor = isClear ? lozColor : color1 + tmpColors[i]; + item.x4_model_icon->SetColor(iconColor); item.x0_model_loz->SetColor(lColor); - item.x8_positioner = (x8_selectedItem == i) ? 0.f : 1.f; + item.x8_positioner = isSelectedItem ? 0.f : 1.f; } x24_model_ghost->SetColor(activeColor); break; @@ -210,20 +218,25 @@ void CHudVisorBeamMenu::Update(float dt, bool init) { item1.x4_model_icon->SetColor(color); item1.x0_model_loz->SetColor(lozColor); - for (int i = 0; i < 4; ++i) - x28_menuItems[i].x8_positioner = (x8_selectedItem == i) ? 1.f - x10_interp : 1.f; + for (size_t i = 0; i < x28_menuItems.size(); ++i) { + const bool isSelectedItem = x8_selectedItem == int(i); + x28_menuItems[i].x8_positioner = isSelectedItem ? 1.f - x10_interp : 1.f; + } x24_model_ghost->SetColor(zeus::CColor::lerp(activeColor, inactiveColor, item1.x8_positioner)); break; } case EAnimPhase::Animate: - for (int i = 0; i < 4; ++i) { + for (size_t i = 0; i < x28_menuItems.size(); ++i) { SMenuItem& item = x28_menuItems[i]; - zeus::CColor& color0 = (x8_selectedItem == i) ? activeColor : inactiveColor; - zeus::CColor iconColor = (item.xc_opacity == 0.f) ? zeus::skClear : color0 + tmpColors[i]; + const bool isSelectedItem = x8_selectedItem == int(i); + const bool isClear = item.xc_opacity == 0.f; + const zeus::CColor& color0 = isSelectedItem ? activeColor : inactiveColor; + const zeus::CColor iconColor = isClear ? zeus::skClear : color0 + tmpColors[i]; + item.x4_model_icon->SetColor(iconColor); - item.x0_model_loz->SetColor((item.xc_opacity == 0.f || x8_selectedItem == i) ? lozColor : inactiveColor); - item.x8_positioner = (x8_selectedItem == i) ? 1.f - x10_interp : 1.f; + item.x0_model_loz->SetColor((isClear || isSelectedItem) ? lozColor : inactiveColor); + item.x8_positioner = isSelectedItem ? 1.f - x10_interp : 1.f; } x24_model_ghost->SetColor( zeus::CColor::lerp(activeColor, inactiveColor, x28_menuItems[x8_selectedItem].x8_positioner)); @@ -241,11 +254,11 @@ void CHudVisorBeamMenu::Update(float dt, bool init) { if (x14_26_dirty || init) { x14_26_dirty = false; - for (int i = 0; i < 4; ++i) { + for (size_t i = 0; i < x28_menuItems.size(); ++i) { SMenuItem& item = x28_menuItems[i]; UpdateMenuWidgetTransform(i, *item.x4_model_icon, item.x8_positioner); } - UpdateMenuWidgetTransform(x8_selectedItem, *x24_model_ghost, x28_menuItems[x8_selectedItem].x8_positioner); + UpdateMenuWidgetTransform(size_t(x8_selectedItem), *x24_model_ghost, x28_menuItems[x8_selectedItem].x8_positioner); } if (!x14_24_visibleDebug || !x14_25_visibleGame) @@ -254,8 +267,7 @@ void CHudVisorBeamMenu::Update(float dt, bool init) { x1c_basewidget_menutitle->SetVisibility(x1c_basewidget_menutitle->GetGeometryColor().a() != 0.f, ETraversalMode::Children); - for (int i = 0; i < 4; ++i) { - SMenuItem& item = x28_menuItems[i]; + for (SMenuItem& item : x28_menuItems) { item.x4_model_icon->SetIsVisible(item.x4_model_icon->GetGeometryColor().a() != 0.f); } } @@ -275,10 +287,11 @@ void CHudVisorBeamMenu::SetIsVisibleGame(bool v) { } void CHudVisorBeamMenu::SetPlayerHas(const rstl::reserved_vector& enables) { - for (int i = 0; i < 4; ++i) { + for (size_t i = 0; i < x28_menuItems.size(); ++i) { SMenuItem& item = x28_menuItems[i]; - if (item.xc_opacity == 0.f && enables[i]) + if (item.xc_opacity == 0.f && enables[i]) { item.xc_opacity = FLT_EPSILON; + } } } diff --git a/Runtime/GuiSys/CHudVisorBeamMenu.hpp b/Runtime/GuiSys/CHudVisorBeamMenu.hpp index 3cf9b45a9..6306fd19f 100644 --- a/Runtime/GuiSys/CHudVisorBeamMenu.hpp +++ b/Runtime/GuiSys/CHudVisorBeamMenu.hpp @@ -45,7 +45,7 @@ private: float x7c_animDur; bool x80_24_swapBeamControls : 1; - void UpdateMenuWidgetTransform(int, CGuiWidget& w, float); + void UpdateMenuWidgetTransform(size_t idx, CGuiWidget& w, float t); public: CHudVisorBeamMenu(CGuiFrame& baseHud, EHudVisorBeamMenu type, const rstl::reserved_vector& enables); @@ -53,7 +53,7 @@ public: void UpdateHudAlpha(float alpha); void SetIsVisibleGame(bool v); void SetPlayerHas(const rstl::reserved_vector& enables); - void SetSelection(int, int, float); + void SetSelection(int selection, int pending, float interp); }; } // namespace urde diff --git a/Runtime/GuiSys/CInstruction.hpp b/Runtime/GuiSys/CInstruction.hpp index 9f8ecb589..79eb5c2f0 100644 --- a/Runtime/GuiSys/CInstruction.hpp +++ b/Runtime/GuiSys/CInstruction.hpp @@ -44,7 +44,7 @@ class CFontInstruction : public CInstruction { TLockedToken x4_font; public: - CFontInstruction(const TToken& font) : x4_font(font) {} + explicit CFontInstruction(const TToken& font) : x4_font(font) {} void Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const override; void PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const override; void GetAssets(std::vector& assetsOut) const override; @@ -55,7 +55,7 @@ class CLineExtraSpaceInstruction : public CInstruction { s32 x4_extraSpace; public: - CLineExtraSpaceInstruction(s32 extraSpace) : x4_extraSpace(extraSpace) {} + explicit CLineExtraSpaceInstruction(s32 extraSpace) : x4_extraSpace(extraSpace) {} void Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const override; void PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const override; }; @@ -107,7 +107,7 @@ class CLineSpacingInstruction : public CInstruction { float x4_lineSpacing; public: - CLineSpacingInstruction(float spacing) : x4_lineSpacing(spacing) {} + explicit CLineSpacingInstruction(float spacing) : x4_lineSpacing(spacing) {} void Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const override; void PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const override; }; @@ -128,7 +128,7 @@ class CRemoveColorOverrideInstruction : public CInstruction { int x4_idx; public: - CRemoveColorOverrideInstruction(int idx) : x4_idx(idx) {} + explicit CRemoveColorOverrideInstruction(int idx) : x4_idx(idx) {} void Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const override; void PageInvoke(CFontRenderState& state, CTextRenderBuffer* buf) const override; }; @@ -137,7 +137,7 @@ class CImageInstruction : public CInstruction { CFontImageDef x4_image; public: - CImageInstruction(const CFontImageDef& image) : x4_image(image) {} + explicit CImageInstruction(const CFontImageDef& image) : x4_image(image) {} void Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const override; void GetAssets(std::vector& assetsOut) const override; size_t GetAssetCount() const override; diff --git a/Runtime/GuiSys/CRasterFont.cpp b/Runtime/GuiSys/CRasterFont.cpp index 4f2c5f894..0808b848f 100644 --- a/Runtime/GuiSys/CRasterFont.cpp +++ b/Runtime/GuiSys/CRasterFont.cpp @@ -97,8 +97,10 @@ void CRasterFont::SinglePassDrawString(const CDrawStringOptions& opts, int x, in if (opts.x0_direction == ETextDirection::Horizontal) { x += glyph->GetLeftPadding(); - if (prevGlyph != 0) + if (prevGlyph != nullptr) { x += KernLookup(x1c_kerning, prevGlyph->GetKernStart(), *chr); + } + int left = 0; int top = 0; diff --git a/Runtime/GuiSys/CScanDisplay.cpp b/Runtime/GuiSys/CScanDisplay.cpp index 12dba9f4c..471f6ee18 100644 --- a/Runtime/GuiSys/CScanDisplay.cpp +++ b/Runtime/GuiSys/CScanDisplay.cpp @@ -35,20 +35,23 @@ void CScanDisplay::CDataDot::Update(float dt) { } } -void CScanDisplay::CDataDot::Draw(const zeus::CColor& col, float radius) const { - if (x24_alpha == 0.f) +void CScanDisplay::CDataDot::Draw(const zeus::CColor& col, float radius) { + if (x24_alpha == 0.f) { return; + } if (x0_dotState != EDotState::Hidden) { - zeus::CTransform xf = zeus::CTransform::Translate(xc_curPos.x(), 0.f, xc_curPos.y()); + const zeus::CTransform xf = zeus::CTransform::Translate(xc_curPos.x(), 0.f, xc_curPos.y()); CGraphics::SetModelMatrix(xf); zeus::CColor useColor = col; useColor.a() *= x24_alpha; - CTexturedQuadFilter::Vert verts[4] = {{{-radius, 0.f, radius}, {0.f, 1.f}}, - {{-radius, 0.f, -radius}, {0.f, 0.f}}, - {{radius, 0.f, radius}, {1.f, 1.f}}, - {{radius, 0.f, -radius}, {1.f, 0.f}}}; - const_cast(m_quad).drawVerts(useColor, verts); + const CTexturedQuadFilter::Vert verts[4] = { + {{-radius, 0.f, radius}, {0.f, 1.f}}, + {{-radius, 0.f, -radius}, {0.f, 0.f}}, + {{radius, 0.f, radius}, {1.f, 1.f}}, + {{radius, 0.f, -radius}, {1.f, 0.f}}, + }; + m_quad.drawVerts(useColor, verts); } } @@ -418,16 +421,18 @@ void CScanDisplay::Update(float dt, float scanningTime) { } } -void CScanDisplay::Draw() const { - if (!x0_dataDot.IsLoaded()) +void CScanDisplay::Draw() { + if (!x0_dataDot.IsLoaded()) { return; + } // No Z-test or write g_Renderer->SetViewportOrtho(true, -4096.f, 4096.f); // Additive alpha - float vpRatio = g_Viewport.xc_height / 480.f; - for (const CDataDot& dot : xbc_dataDots) + const float vpRatio = g_Viewport.xc_height / 480.f; + for (CDataDot& dot : xbc_dataDots) { dot.Draw(g_tweakGuiColors->GetScanDataDotColor(), g_tweakGui->GetScanDataDotRadius() * vpRatio); + } } } // namespace urde diff --git a/Runtime/GuiSys/CScanDisplay.hpp b/Runtime/GuiSys/CScanDisplay.hpp index b879767f6..7b9c60d83 100644 --- a/Runtime/GuiSys/CScanDisplay.hpp +++ b/Runtime/GuiSys/CScanDisplay.hpp @@ -43,9 +43,9 @@ public: CTexturedQuadFilter m_quad; public: - CDataDot(const TLockedToken& dataDotTex) : m_quad(EFilterType::Add, dataDotTex) {} + explicit CDataDot(const TLockedToken& dataDotTex) : m_quad(EFilterType::Add, dataDotTex) {} void Update(float dt); - void Draw(const zeus::CColor& color, float radius) const; + void Draw(const zeus::CColor& color, float radius); float GetTransitionFactor() const { return x1c_transDur > 0.f ? x20_remTime / x1c_transDur : 0.f; } void StartTransitionTo(const zeus::CVector2f&, float); void SetDestPosition(const zeus::CVector2f&); @@ -84,13 +84,13 @@ private: static void SetScanMessageTypeEffect(CGuiTextPane* pane, bool type); public: - CScanDisplay(const CGuiFrame& selHud); + explicit CScanDisplay(const CGuiFrame& selHud); void ProcessInput(const CFinalInput& input); void StartScan(TUniqueId id, const CScannableObjectInfo& scanInfo, CGuiTextPane* message, CGuiTextPane* scrollMessage, CGuiWidget* textGroup, CGuiModel* xmark, CGuiModel* abutton, CGuiModel* dash, float scanTime); void StopScan(); void Update(float dt, float scanningTime); - void Draw() const; + void Draw(); EScanState GetScanState() const { return xc_state; } TUniqueId ScanTarget() const { return x10_objId; } }; diff --git a/Runtime/GuiSys/CSplashScreen.cpp b/Runtime/GuiSys/CSplashScreen.cpp index 94938a13b..9c36cd163 100644 --- a/Runtime/GuiSys/CSplashScreen.cpp +++ b/Runtime/GuiSys/CSplashScreen.cpp @@ -48,19 +48,22 @@ CIOWin::EMessageReturn CSplashScreen::OnMessage(const CArchitectureMessage& msg, return EMessageReturn::Exit; } -void CSplashScreen::Draw() const { - if (!x25_textureLoaded) +void CSplashScreen::Draw() { + if (!x25_textureLoaded) { return; + } SCOPED_GRAPHICS_DEBUG_GROUP("CSplashScreen::Draw", zeus::skGreen); zeus::CColor color; - if (x14_which == ESplashScreen::Nintendo) + if (x14_which == ESplashScreen::Nintendo) { color = zeus::CColor{0.86f, 0.f, 0.f, 1.f}; + } - if (x18_splashTimeout > 1.5f) + if (x18_splashTimeout > 1.5f) { color.a() = 1.f - (x18_splashTimeout - 1.5f) * 2.f; - else if (x18_splashTimeout < 0.5f) + } else if (x18_splashTimeout < 0.5f) { color.a() = x18_splashTimeout * 2.f; + } zeus::CRectangle rect; rect.size.x() = m_quad.GetTex()->GetWidth() / (480.f * g_Viewport.aspect); @@ -68,7 +71,7 @@ void CSplashScreen::Draw() const { rect.position.x() = 0.5f - rect.size.x() / 2.f; rect.position.y() = 0.5f - rect.size.y() / 2.f; - const_cast(m_quad).draw(color, 1.f, rect); + m_quad.draw(color, 1.f, rect); } } // namespace urde diff --git a/Runtime/GuiSys/CSplashScreen.hpp b/Runtime/GuiSys/CSplashScreen.hpp index db4fd2e86..4737ea26b 100644 --- a/Runtime/GuiSys/CSplashScreen.hpp +++ b/Runtime/GuiSys/CSplashScreen.hpp @@ -22,9 +22,9 @@ private: CTexturedQuadFilterAlpha m_quad; public: - CSplashScreen(ESplashScreen); + explicit CSplashScreen(ESplashScreen); EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&) override; - void Draw() const override; + void Draw() override; }; } // namespace urde diff --git a/Runtime/GuiSys/CStringTable.hpp b/Runtime/GuiSys/CStringTable.hpp index 0e8461e5e..88d574b78 100644 --- a/Runtime/GuiSys/CStringTable.hpp +++ b/Runtime/GuiSys/CStringTable.hpp @@ -13,7 +13,7 @@ class CStringTable { u32 m_bufLen; public: - CStringTable(CInputStream& in); + explicit CStringTable(CInputStream& in); void LoadStringTable(CInputStream& in); const char16_t* GetString(s32) const; diff --git a/Runtime/GuiSys/CTargetingManager.hpp b/Runtime/GuiSys/CTargetingManager.hpp index 3f9a62ec0..58d383930 100644 --- a/Runtime/GuiSys/CTargetingManager.hpp +++ b/Runtime/GuiSys/CTargetingManager.hpp @@ -10,7 +10,7 @@ class CTargetingManager { COrbitPointMarker x21c_orbitPointMarker; public: - CTargetingManager(const CStateManager& stateMgr); + explicit CTargetingManager(const CStateManager& stateMgr); bool CheckLoadComplete(); void Update(float, const CStateManager& stateMgr); void Draw(const CStateManager& stateMgr, bool hideLockon) const; diff --git a/Runtime/GuiSys/CTextParser.hpp b/Runtime/GuiSys/CTextParser.hpp index 6cf4370cc..39d574b70 100644 --- a/Runtime/GuiSys/CTextParser.hpp +++ b/Runtime/GuiSys/CTextParser.hpp @@ -27,7 +27,7 @@ class CTextParser { TToken GetFont(const char16_t* str, int len); public: - CTextParser(IObjectStore& store) : x0_store(store) {} + explicit CTextParser(IObjectStore& store) : x0_store(store) {} void ParseText(CTextExecuteBuffer& out, const char16_t* str, int len, const std::vector>* txtrMap); }; diff --git a/Runtime/GuiSys/CTextRenderBuffer.cpp b/Runtime/GuiSys/CTextRenderBuffer.cpp index 2888b5867..c389ca7fa 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.cpp +++ b/Runtime/GuiSys/CTextRenderBuffer.cpp @@ -12,31 +12,64 @@ namespace urde { +struct CTextRenderBuffer::BooFontCharacters { + TLockedToken m_font; + hecl::VertexBufferPool::Token m_instBuf; + boo::ObjToken m_dataBinding; + boo::ObjToken m_dataBinding2; + std::vector m_charData; + u32 m_charCount = 0; + bool m_dirty = true; + + BooFontCharacters(const CToken& token) : m_font(token) {} +}; + +struct CTextRenderBuffer::BooImage { + CFontImageDef m_imageDef; + hecl::VertexBufferPool::Token m_instBuf; + std::vector> m_dataBinding; + std::vector> m_dataBinding2; + CTextSupportShader::ImageInstance m_imageData; + bool m_dirty = true; + + BooImage(const CFontImageDef& imgDef, const zeus::CVector2i& offset) : m_imageDef(imgDef) { + m_imageData.SetMetrics(imgDef, offset); + } +}; + +struct CTextRenderBuffer::BooPrimitiveMark { + Command m_cmd; + u32 m_bindIdx; + u32 m_instIdx; + + void SetOpacity(CTextRenderBuffer& rb, float opacity) { + switch (m_cmd) { + case Command::CharacterRender: { + BooFontCharacters& fc = rb.m_fontCharacters[m_bindIdx]; + CTextSupportShader::CharacterInstance& inst = fc.m_charData[m_instIdx]; + inst.m_mulColor.a() = opacity; + fc.m_dirty = true; + break; + } + case Command::ImageRender: { + BooImage& img = rb.m_images[m_bindIdx]; + img.m_imageData.m_color.a() = opacity; + img.m_dirty = true; + break; + } + default: + break; + } + } +}; + +CTextRenderBuffer::CTextRenderBuffer(CTextRenderBuffer&&) noexcept = default; + CTextRenderBuffer::CTextRenderBuffer(EMode mode, CGuiWidget::EGuiModelDrawFlags df) : x0_mode(mode), m_drawFlags(df) {} -CTextRenderBuffer::BooImage::BooImage(const CFontImageDef& imgDef, const zeus::CVector2i& offset) : m_imageDef(imgDef) { - m_imageData.SetMetrics(imgDef, offset); -} +CTextRenderBuffer::~CTextRenderBuffer() = default; -void CTextRenderBuffer::BooPrimitiveMark::SetOpacity(CTextRenderBuffer& rb, float opacity) { - switch (m_cmd) { - case Command::CharacterRender: { - BooFontCharacters& fc = rb.m_fontCharacters[m_bindIdx]; - CTextSupportShader::CharacterInstance& inst = fc.m_charData[m_instIdx]; - inst.m_mulColor.a() = opacity; - fc.m_dirty = true; - break; - } - case Command::ImageRender: { - BooImage& img = rb.m_images[m_bindIdx]; - img.m_imageData.m_color.a() = opacity; - img.m_dirty = true; - break; - } - default: - break; - } -} +CTextRenderBuffer& CTextRenderBuffer::operator=(CTextRenderBuffer&&) noexcept = default; void CTextRenderBuffer::CommitResources() { if (m_committed) @@ -125,26 +158,28 @@ void CTextRenderBuffer::SetPrimitiveOpacity(int idx, float opacity) { m_primitiveMarks[idx].SetOpacity(*this, opacity); } -void CTextRenderBuffer::Render(const zeus::CColor& col, float time) const { - const_cast(this)->CommitResources(); +u32 CTextRenderBuffer::GetPrimitiveCount() const { return m_primitiveMarks.size(); } - zeus::CMatrix4f mv = CGraphics::g_GXModelView.toMatrix4f(); - zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(true); - zeus::CMatrix4f mat = proj * mv; +void CTextRenderBuffer::Render(const zeus::CColor& col, float time) { + CommitResources(); - const_cast(this)->m_uniBuf.access() = CTextSupportShader::Uniform{mat, col}; + const zeus::CMatrix4f mv = CGraphics::g_GXModelView.toMatrix4f(); + const zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(true); + const zeus::CMatrix4f mat = proj * mv; + + m_uniBuf.access() = CTextSupportShader::Uniform{mat, col}; if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { zeus::CColor colPremul = col * col.a(); colPremul.a() = col.a(); - const_cast(this)->m_uniBuf2.access() = CTextSupportShader::Uniform{mat, colPremul}; + m_uniBuf2.access() = CTextSupportShader::Uniform{mat, colPremul}; } - for (const BooFontCharacters& chs : m_fontCharacters) { + for (BooFontCharacters& chs : m_fontCharacters) { if (chs.m_charData.size()) { if (chs.m_dirty) { - memmove(const_cast(chs).m_instBuf.access(), chs.m_charData.data(), - sizeof(CTextSupportShader::CharacterInstance) * chs.m_charData.size()); - const_cast(chs).m_dirty = false; + std::memmove(chs.m_instBuf.access(), chs.m_charData.data(), + sizeof(CTextSupportShader::CharacterInstance) * chs.m_charData.size()); + chs.m_dirty = false; } CGraphics::SetShaderDataBinding(chs.m_dataBinding); CGraphics::DrawInstances(0, 4, chs.m_charData.size()); @@ -155,12 +190,12 @@ void CTextRenderBuffer::Render(const zeus::CColor& col, float time) const { } } - for (const BooImage& img : m_images) { + for (BooImage& img : m_images) { if (img.m_dirty) { - *const_cast(img).m_instBuf.access() = img.m_imageData; - const_cast(img).m_dirty = false; + *img.m_instBuf.access() = img.m_imageData; + img.m_dirty = false; } - int idx = int(img.m_imageDef.x0_fps * time) % img.m_dataBinding.size(); + const int idx = int(img.m_imageDef.x0_fps * time) % img.m_dataBinding.size(); CGraphics::SetShaderDataBinding(img.m_dataBinding[idx]); CGraphics::DrawInstances(0, 4, 1); if (m_drawFlags == CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw) { diff --git a/Runtime/GuiSys/CTextRenderBuffer.hpp b/Runtime/GuiSys/CTextRenderBuffer.hpp index b3ad6806b..12d1caa71 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.hpp +++ b/Runtime/GuiSys/CTextRenderBuffer.hpp @@ -65,35 +65,13 @@ private: hecl::UniformBufferPool::Token m_uniBuf; hecl::UniformBufferPool::Token m_uniBuf2; - struct BooFontCharacters { - TLockedToken m_font; - hecl::VertexBufferPool::Token m_instBuf; - boo::ObjToken m_dataBinding; - boo::ObjToken m_dataBinding2; - std::vector m_charData; - u32 m_charCount = 0; - bool m_dirty = true; - BooFontCharacters(const CToken& token) : m_font(token) {} - }; + struct BooFontCharacters; std::vector m_fontCharacters; - struct BooImage { - CFontImageDef m_imageDef; - hecl::VertexBufferPool::Token m_instBuf; - std::vector> m_dataBinding; - std::vector> m_dataBinding2; - CTextSupportShader::ImageInstance m_imageData; - bool m_dirty = true; - BooImage(const CFontImageDef& imgDef, const zeus::CVector2i& offset); - }; + struct BooImage; std::vector m_images; - struct BooPrimitiveMark { - Command m_cmd; - u32 m_bindIdx; - u32 m_instIdx; - void SetOpacity(CTextRenderBuffer& rb, float opacity); - }; + struct BooPrimitiveMark; std::vector m_primitiveMarks; u32 m_imagesCount = 0; u32 m_activeFontCh = UINT32_MAX; @@ -108,7 +86,12 @@ private: #endif public: + CTextRenderBuffer(CTextRenderBuffer&& other) noexcept; CTextRenderBuffer(EMode mode, CGuiWidget::EGuiModelDrawFlags df); + ~CTextRenderBuffer(); + + CTextRenderBuffer& operator=(CTextRenderBuffer&& other) noexcept; + #if 0 void SetPrimitive(const Primitive&, int); Primitive GetPrimitive(int) const; @@ -119,10 +102,10 @@ public: void AddPaletteChange(const CGraphicsPalette& palette); #else void SetPrimitiveOpacity(int idx, float opacity); - u32 GetPrimitiveCount() const { return m_primitiveMarks.size(); } + u32 GetPrimitiveCount() const; #endif void SetMode(EMode mode); - void Render(const zeus::CColor& col, float) const; + void Render(const zeus::CColor& col, float time); void AddImage(const zeus::CVector2i& offset, const CFontImageDef& image); void AddCharacter(const zeus::CVector2i& offset, char16_t ch, const zeus::CColor& color); void AddPaletteChange(const zeus::CColor& main, const zeus::CColor& outline); diff --git a/Runtime/ITweak.hpp b/Runtime/ITweak.hpp index feb72aa9c..05aff8296 100644 --- a/Runtime/ITweak.hpp +++ b/Runtime/ITweak.hpp @@ -3,6 +3,6 @@ namespace urde { class ITweak { public: - virtual ~ITweak() {} + virtual ~ITweak() = default; }; } // namespace urde diff --git a/Runtime/MP1/CCredits.cpp b/Runtime/MP1/CCredits.cpp index 72e4e73fa..1c229dbc7 100644 --- a/Runtime/MP1/CCredits.cpp +++ b/Runtime/MP1/CCredits.cpp @@ -10,7 +10,7 @@ CIOWin::EMessageReturn CCredits::OnMessage(const CArchitectureMessage& msg, CArc return EMessageReturn::Normal; } -void CCredits::Draw() const { +void CCredits::Draw() { SCOPED_GRAPHICS_DEBUG_GROUP("CCredits::Draw", zeus::skGreen); } diff --git a/Runtime/MP1/CCredits.hpp b/Runtime/MP1/CCredits.hpp index 624b00ee7..6648a8a83 100644 --- a/Runtime/MP1/CCredits.hpp +++ b/Runtime/MP1/CCredits.hpp @@ -9,7 +9,7 @@ public: CCredits(); EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&) override; bool GetIsContinueDraw() const override { return false; } - void Draw() const override; + void Draw() override; }; } // namespace urde::MP1 diff --git a/Runtime/MP1/CFaceplateDecoration.hpp b/Runtime/MP1/CFaceplateDecoration.hpp index 76518afd1..94891bfaa 100644 --- a/Runtime/MP1/CFaceplateDecoration.hpp +++ b/Runtime/MP1/CFaceplateDecoration.hpp @@ -18,7 +18,7 @@ class CFaceplateDecoration { std::optional m_texFilter; public: - CFaceplateDecoration(CStateManager& stateMgr); + explicit CFaceplateDecoration(CStateManager& stateMgr); void Update(float dt, CStateManager& stateMgr); void Draw(CStateManager& stateMgr); }; diff --git a/Runtime/MP1/CFrontEndUI.cpp b/Runtime/MP1/CFrontEndUI.cpp index 69aa28b0a..d63175e44 100644 --- a/Runtime/MP1/CFrontEndUI.cpp +++ b/Runtime/MP1/CFrontEndUI.cpp @@ -1906,9 +1906,10 @@ void CFrontEndUI::CompleteStateTransition() { void CFrontEndUI::HandleDebugMenuReturnValue(CGameDebug::EReturnValue val, CArchitectureQueue& queue) {} -void CFrontEndUI::Draw() const { - if (x14_phase < EPhase::DisplayFrontEnd) +void CFrontEndUI::Draw() { + if (x14_phase < EPhase::DisplayFrontEnd) { return; + } SCOPED_GRAPHICS_DEBUG_GROUP("CFrontEndUI::Draw", zeus::skGreen); if (xec_emuFrme) { diff --git a/Runtime/MP1/CFrontEndUI.hpp b/Runtime/MP1/CFrontEndUI.hpp index 8bbc37798..b1c2aac75 100644 --- a/Runtime/MP1/CFrontEndUI.hpp +++ b/Runtime/MP1/CFrontEndUI.hpp @@ -203,7 +203,7 @@ public: bool m_gbaOverride = false; - SFusionBonusFrame(CFrontEndUITouchBar& touchBar); + explicit SFusionBonusFrame(CFrontEndUITouchBar& touchBar); void FinishedLoading(); bool PumpLoad(); void SetTableColors(CGuiTableGroup* tbgp) const; @@ -354,7 +354,7 @@ private: std::unique_ptr xf0_optionsFrme; CStaticAudioPlayer* xf4_curAudio = nullptr; - CColoredQuadFilter m_fadeToBlack = {EFilterType::Blend}; + CColoredQuadFilter m_fadeToBlack{EFilterType::Blend}; std::optional m_pressStartQuad; std::unique_ptr m_touchBar; @@ -385,7 +385,7 @@ public: void StartStateTransition(EScreen screen); void CompleteStateTransition(); void HandleDebugMenuReturnValue(CGameDebug::EReturnValue val, CArchitectureQueue& queue); - void Draw() const override; + void Draw() override; void UpdateMovies(float dt); bool PumpMovieLoad(); void ProcessUserInput(const CFinalInput& input, CArchitectureQueue& queue); diff --git a/Runtime/MP1/CFrontEndUITouchBar.cpp b/Runtime/MP1/CFrontEndUITouchBar.cpp index ccc5ccf2f..6afb30f10 100644 --- a/Runtime/MP1/CFrontEndUITouchBar.cpp +++ b/Runtime/MP1/CFrontEndUITouchBar.cpp @@ -2,7 +2,7 @@ namespace urde { -CFrontEndUITouchBar::~CFrontEndUITouchBar() {} +CFrontEndUITouchBar::~CFrontEndUITouchBar() = default; void CFrontEndUITouchBar::SetPhase(EPhase ph) { m_phase = ph; } CFrontEndUITouchBar::EPhase CFrontEndUITouchBar::GetPhase() { return m_phase; } void CFrontEndUITouchBar::SetFileSelectPhase(const SFileSelectDetail details[3], bool eraseGame, bool galleryActive) { diff --git a/Runtime/MP1/CInGameGuiManager.hpp b/Runtime/MP1/CInGameGuiManager.hpp index 367c0e8e4..d59fb335e 100644 --- a/Runtime/MP1/CInGameGuiManager.hpp +++ b/Runtime/MP1/CInGameGuiManager.hpp @@ -98,9 +98,9 @@ private: std::optional m_deathRenderTexQuad; std::optional m_deathDotQuad; - CRandomStaticFilter m_randomStatic = {EFilterType::Blend}; - CColoredQuadFilter m_deathWhiteout = {EFilterType::Blend}; - CColoredQuadFilter m_deathBlackout = {EFilterType::Blend}; + CRandomStaticFilter m_randomStatic{EFilterType::Blend}; + CColoredQuadFilter m_deathWhiteout{EFilterType::Blend}; + CColoredQuadFilter m_deathBlackout{EFilterType::Blend}; union { struct { @@ -126,7 +126,7 @@ private: void RefreshHudOptions(); public: - CInGameGuiManager(CStateManager& stateMgr, CArchitectureQueue& archQueue); + explicit CInGameGuiManager(CStateManager& stateMgr, CArchitectureQueue& archQueue); bool CheckLoadComplete(CStateManager& stateMgr); void Update(CStateManager& stateMgr, float dt, CArchitectureQueue& archQueue, bool useHud); void ProcessControllerInput(CStateManager& stateMgr, const CFinalInput& input, CArchitectureQueue& archQueue); diff --git a/Runtime/MP1/CMFGame.cpp b/Runtime/MP1/CMFGame.cpp index 5bfa54a36..3b05488a0 100644 --- a/Runtime/MP1/CMFGame.cpp +++ b/Runtime/MP1/CMFGame.cpp @@ -193,9 +193,10 @@ void CMFGame::Touch() { player.GetMorphBall()->TouchModel(*x14_stateManager); } -void CMFGame::Draw() const { - if (!x2a_24_initialized) +void CMFGame::Draw() { + if (!x2a_24_initialized) { return; + } SCOPED_GRAPHICS_DEBUG_GROUP("CMFGame::Draw", zeus::skGreen); const_cast(*this).Touch(); @@ -210,8 +211,8 @@ void CMFGame::Draw() const { x18_guiManager->Draw(*x14_stateManager); if (x1c_flowState == EGameFlowState::CinematicSkip) { - float c = std::min(1.f, 1.f - x20_cineSkipTime); - const_cast(m_fadeToBlack).draw(zeus::CColor{c, c, c, c}); + const float c = std::min(1.f, 1.f - x20_cineSkipTime); + m_fadeToBlack.draw(zeus::CColor{c, c, c, c}); } } @@ -279,7 +280,7 @@ CMFGameLoader::CMFGameLoader() : CMFGameLoaderBase("CMFGameLoader") { } } -CMFGameLoader::~CMFGameLoader() {} +CMFGameLoader::~CMFGameLoader() = default; static const char* LoadDepPAKs[] = {"TestAnim", "SamusGun", "SamGunFx", nullptr}; @@ -364,7 +365,7 @@ CIOWin::EMessageReturn CMFGameLoader::OnMessage(const CArchitectureMessage& msg, return EMessageReturn::Exit; } -void CMFGameLoader::Draw() const { +void CMFGameLoader::Draw() { SCOPED_GRAPHICS_DEBUG_GROUP("CMFGameLoader::Draw", zeus::skGreen); g_GameState->GetWorldTransitionManager()->Draw(); } diff --git a/Runtime/MP1/CMFGame.hpp b/Runtime/MP1/CMFGame.hpp index 261bbba37..fe7d70ca3 100644 --- a/Runtime/MP1/CMFGame.hpp +++ b/Runtime/MP1/CMFGame.hpp @@ -31,7 +31,7 @@ class CMFGame : public CMFGameBase { u8 _dummy = 0; }; - CColoredQuadFilter m_fadeToBlack = {EFilterType::Multiply}; + CColoredQuadFilter m_fadeToBlack{EFilterType::Multiply}; bool IsCameraActiveFlow() const { return (x1c_flowState == EGameFlowState::InGame || x1c_flowState == EGameFlowState::SamusDied); @@ -43,7 +43,7 @@ public: ~CMFGame() override; CIOWin::EMessageReturn OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) override; void Touch(); - void Draw() const override; + void Draw() override; void PlayerDied(); void UnpauseGame(); void EnterMessageScreen(float time); @@ -72,7 +72,7 @@ public: CMFGameLoader(); ~CMFGameLoader() override; EMessageReturn OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) override; - void Draw() const override; + void Draw() override; }; } // namespace MP1 diff --git a/Runtime/MP1/CMainFlow.hpp b/Runtime/MP1/CMainFlow.hpp index ec2a5df57..04c0f0da1 100644 --- a/Runtime/MP1/CMainFlow.hpp +++ b/Runtime/MP1/CMainFlow.hpp @@ -14,7 +14,7 @@ public: void AdvanceGameState(CArchitectureQueue& queue) override; void SetGameState(EClientFlowStates state, CArchitectureQueue& queue) override; bool GetIsContinueDraw() const override { return false; } - void Draw() const override {} + void Draw() override {} }; } // namespace MP1 diff --git a/Runtime/MP1/CMemoryCardDriver.hpp b/Runtime/MP1/CMemoryCardDriver.hpp index 2e89cdd2d..59a161e75 100644 --- a/Runtime/MP1/CMemoryCardDriver.hpp +++ b/Runtime/MP1/CMemoryCardDriver.hpp @@ -99,7 +99,7 @@ private: u8 x0_saveBuffer[940] = {}; CGameState::GameFileStateInfo x944_fileInfo; SGameFileSlot(); - SGameFileSlot(CMemoryInStream& in); + explicit SGameFileSlot(CMemoryInStream& in); void InitializeFromGameState(); void LoadGameState(u32 idx); void DoPut(CMemoryOutStream& w) const { w.writeBytes(x0_saveBuffer, 940); } diff --git a/Runtime/MP1/CMessageScreen.hpp b/Runtime/MP1/CMessageScreen.hpp index ea0b77b7e..8998cb06f 100644 --- a/Runtime/MP1/CMessageScreen.hpp +++ b/Runtime/MP1/CMessageScreen.hpp @@ -39,7 +39,7 @@ class CMessageScreen { bool x78_24_exit : 1; public: - CMessageScreen(CAssetId msg, float time); + explicit CMessageScreen(CAssetId msg, float time); void ProcessControllerInput(const CFinalInput& input); bool Update(float dt, float blurAmt); void Draw() const; diff --git a/Runtime/MP1/CPauseScreenBlur.hpp b/Runtime/MP1/CPauseScreenBlur.hpp index 7ea1e5080..e96b2eafc 100644 --- a/Runtime/MP1/CPauseScreenBlur.hpp +++ b/Runtime/MP1/CPauseScreenBlur.hpp @@ -20,8 +20,8 @@ class CPauseScreenBlur { EState x14_nextState = EState::InGame; float x18_blurAmt = 0.f; CCameraBlurPass x1c_camBlur; - CTexturedQuadFilter m_quarterFilter = {EFilterType::Multiply, x4_mapLightQuarter}; - CScanLinesFilterEven m_linesFilter = {EFilterType::Multiply}; + CTexturedQuadFilter m_quarterFilter{EFilterType::Multiply, x4_mapLightQuarter}; + CScanLinesFilterEven m_linesFilter{EFilterType::Multiply}; union { struct { diff --git a/Runtime/MP1/CPlayMovie.hpp b/Runtime/MP1/CPlayMovie.hpp index cb1d7199e..f881461e1 100644 --- a/Runtime/MP1/CPlayMovie.hpp +++ b/Runtime/MP1/CPlayMovie.hpp @@ -32,7 +32,7 @@ private: static bool IsResultsScreen(EWhichMovie which); public: - CPlayMovie(EWhichMovie which); + explicit CPlayMovie(EWhichMovie which); }; } // namespace urde::MP1 diff --git a/Runtime/MP1/CPlayerVisor.hpp b/Runtime/MP1/CPlayerVisor.hpp index 46b19da3a..0d2077777 100644 --- a/Runtime/MP1/CPlayerVisor.hpp +++ b/Runtime/MP1/CPlayerVisor.hpp @@ -82,7 +82,7 @@ class CPlayerVisor { void BeginTransitionOut(); public: - CPlayerVisor(CStateManager& stateMgr); + explicit CPlayerVisor(CStateManager& stateMgr); ~CPlayerVisor(); void Update(float dt, const CStateManager& stateMgr); void Draw(const CStateManager& stateMgr, const CTargetingManager* tgtManager) const; diff --git a/Runtime/MP1/CQuitGameScreen.hpp b/Runtime/MP1/CQuitGameScreen.hpp index c0c5424f0..ea339d06a 100644 --- a/Runtime/MP1/CQuitGameScreen.hpp +++ b/Runtime/MP1/CQuitGameScreen.hpp @@ -36,7 +36,7 @@ public: EQuitAction Update(float dt); void Draw(); void ProcessUserInput(const CFinalInput& input); - CQuitGameScreen(EQuitType type); + explicit CQuitGameScreen(EQuitType type); }; } // namespace MP1 diff --git a/Runtime/MP1/CSamusFaceReflection.hpp b/Runtime/MP1/CSamusFaceReflection.hpp index 76193664e..23674de17 100644 --- a/Runtime/MP1/CSamusFaceReflection.hpp +++ b/Runtime/MP1/CSamusFaceReflection.hpp @@ -19,7 +19,7 @@ class CSamusFaceReflection { bool x70_hidden = true; public: - CSamusFaceReflection(CStateManager& stateMgr); + explicit CSamusFaceReflection(CStateManager& stateMgr); void PreDraw(const CStateManager& stateMgr); void Draw(const CStateManager& stateMgr) const; void Update(float dt, const CStateManager& stateMgr, CRandom16& rand); diff --git a/Runtime/MP1/CSamusHud.hpp b/Runtime/MP1/CSamusHud.hpp index 25c76597e..a89fd8d08 100644 --- a/Runtime/MP1/CSamusHud.hpp +++ b/Runtime/MP1/CSamusHud.hpp @@ -173,7 +173,7 @@ class CSamusHud { rstl::reserved_vector x7ac_; CColoredQuadFilter m_energyDrainFilter; - CCookieCutterDepthRandomStaticFilter m_cookieCutterStatic = {EFilterType::NoColor}; + CCookieCutterDepthRandomStaticFilter m_cookieCutterStatic{EFilterType::NoColor}; static CSamusHud* g_SamusHud; static rstl::reserved_vector BuildPlayerHasVisors(const CStateManager& mgr); @@ -211,7 +211,7 @@ class CSamusHud { static EHudState GetDesiredHudState(const CStateManager& mgr); public: - CSamusHud(CStateManager& stateMgr); + explicit CSamusHud(CStateManager& stateMgr); ~CSamusHud(); void Update(float dt, const CStateManager& mgr, CInGameGuiManager::EHelmetVisMode helmetVis, bool hudVis, bool targetingManager); diff --git a/Runtime/MP1/CSaveGameScreen.hpp b/Runtime/MP1/CSaveGameScreen.hpp index b37fab7e0..ee5735383 100644 --- a/Runtime/MP1/CSaveGameScreen.hpp +++ b/Runtime/MP1/CSaveGameScreen.hpp @@ -108,7 +108,7 @@ public: const CGameState::GameFileStateInfo* GetGameData(int idx) const; EUIType GetUIType() const { return x10_uiType; } bool IsSavingDisabled() const { return x92_savingDisabled; } - CSaveGameScreen(ESaveContext saveCtx, u64 serial); + explicit CSaveGameScreen(ESaveContext saveCtx, u64 serial); }; } // namespace MP1 diff --git a/Runtime/MP1/CSlideShow.cpp b/Runtime/MP1/CSlideShow.cpp index 60a3c6e6d..40b0d9571 100644 --- a/Runtime/MP1/CSlideShow.cpp +++ b/Runtime/MP1/CSlideShow.cpp @@ -124,18 +124,19 @@ CIOWin::EMessageReturn CSlideShow::OnMessage(const CArchitectureMessage& msg, CA return EMessageReturn::Exit; } -void CSlideShow::SSlideData::Draw() const { - if (!IsLoaded()) +void CSlideShow::SSlideData::Draw() { + if (!IsLoaded()) { return; + } - zeus::CRectangle rect; - const_cast(*m_texQuad).draw(x30_mulColor, 1.f, rect); + const zeus::CRectangle rect; + m_texQuad->draw(x30_mulColor, 1.f, rect); - zeus::CVector2f centeredOffset((x28_canvasSize.x() - m_texQuad->GetTex()->GetWidth()) * 0.5f, - (x28_canvasSize.y() - m_texQuad->GetTex()->GetHeight()) * 0.5f); + const zeus::CVector2f centeredOffset((x28_canvasSize.x() - m_texQuad->GetTex()->GetWidth()) * 0.5f, + (x28_canvasSize.y() - m_texQuad->GetTex()->GetHeight()) * 0.5f); } -void CSlideShow::Draw() const { +void CSlideShow::Draw() { SCOPED_GRAPHICS_DEBUG_GROUP("CSlideShow::Draw", zeus::skGreen); if (x14_phase == Phase::Five) { x5c_slideA.Draw(); diff --git a/Runtime/MP1/CSlideShow.hpp b/Runtime/MP1/CSlideShow.hpp index ceed2212e..11087684f 100644 --- a/Runtime/MP1/CSlideShow.hpp +++ b/Runtime/MP1/CSlideShow.hpp @@ -33,11 +33,11 @@ public: zeus::CVector2f x28_canvasSize; zeus::CColor x30_mulColor = zeus::skWhite; - SSlideData(CSlideShow& parent) : x0_parent(parent) { x30_mulColor.a() = 0.f; } + explicit SSlideData(CSlideShow& parent) : x0_parent(parent) { x30_mulColor.a() = 0.f; } void SetTexture(const TLockedToken& tex) { m_texQuad.emplace(EFilterType::Blend, tex); } bool IsLoaded() const { return m_texQuad && m_texQuad->GetTex().IsLoaded(); } - void Draw() const; + void Draw(); }; private: @@ -110,7 +110,7 @@ public: CSlideShow(); EMessageReturn OnMessage(const CArchitectureMessage&, CArchitectureQueue&) override; bool GetIsContinueDraw() const override { return false; } - void Draw() const override; + void Draw() override; static u32 SlideShowGalleryFlags(); }; diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 44e360e05..3e59e411e 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -1,5 +1,7 @@ #include "Runtime/MP1/MP1.hpp" +#include + #include "NESEmulator/CNESShader.hpp" #include "Runtime/Graphics/Shaders/CAABoxShader.hpp" @@ -74,8 +76,21 @@ extern CVar* com_developer; extern CVar* com_cubemaps; }; // namespace hecl -namespace urde { -namespace MP1 { +namespace urde::MP1 { +namespace { +struct AudioGroupInfo { + const char* name; + u32 id; +}; + +constexpr std::array StaticAudioGroups{{ + {"Misc_AGSC", GRPmisc}, + {"MiscSamus_AGSC", GRPmiscSamus}, + {"UI_AGSC", GRPui}, + {"Weapons_AGSC", GRPweapons}, + {"ZZZ_AGSC", GRPzzz}, +}}; +} // Anonymous namespace CGameArchitectureSupport::CGameArchitectureSupport(CMain& parent, boo::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& backend) @@ -128,17 +143,6 @@ void CGameArchitectureSupport::Update(float dt) { x58_ioWinManager.PumpMessages(x4_archQueue); } -struct AudioGroupInfo { - const char* name; - u32 id; -}; - -static const AudioGroupInfo StaticAudioGroups[] = {{"Misc_AGSC", GRPmisc}, - {"MiscSamus_AGSC", GRPmiscSamus}, - {"UI_AGSC", GRPui}, - {"Weapons_AGSC", GRPweapons}, - {"ZZZ_AGSC", GRPzzz}}; - bool CGameArchitectureSupport::LoadAudio() { if (x88_audioLoadStatus == EAudioLoadStatus::Loaded) return true; @@ -170,26 +174,30 @@ bool CGameArchitectureSupport::LoadAudio() { } void CGameArchitectureSupport::PreloadAudio() { - if (x88_audioLoadStatus != EAudioLoadStatus::Uninitialized) + if (x88_audioLoadStatus != EAudioLoadStatus::Uninitialized) { return; + } + x8c_pendingAudioGroups.clear(); x8c_pendingAudioGroups.reserve(5); - for (int i = 0; i < 5; ++i) { + for (size_t i = 0; i < StaticAudioGroups.size(); ++i) { const AudioGroupInfo& info = StaticAudioGroups[i]; CToken grp = g_SimplePool->GetObj(info.name); - if (i == 0) /* Lock first group in sequence */ + + // Lock first group in sequence + if (i == 0) { grp.Lock(); - x8c_pendingAudioGroups.push_back(std::move(grp)); + } + + x8c_pendingAudioGroups.emplace_back(std::move(grp)); } x88_audioLoadStatus = EAudioLoadStatus::Loading; } void CGameArchitectureSupport::UnloadAudio() { - - for (int i = 0; i < 5; ++i) { - const AudioGroupInfo& info = StaticAudioGroups[i]; + for (const AudioGroupInfo& info : StaticAudioGroups) { const SObjectTag* tag = g_ResFactory->GetResourceIdByName(info.name); auto name = CAudioSys::SysGetGroupSetName(tag->id); CAudioSys::SysRemoveGroupFromAmuse(name); @@ -984,5 +992,4 @@ int CMain::appMain(boo::IApplication* app) { #endif -} // namespace MP1 -} // namespace urde +} // namespace urde::MP1 diff --git a/Runtime/MP1/World/CBabygoth.hpp b/Runtime/MP1/World/CBabygoth.hpp index 634c77d33..706f0be2e 100644 --- a/Runtime/MP1/World/CBabygoth.hpp +++ b/Runtime/MP1/World/CBabygoth.hpp @@ -45,7 +45,7 @@ struct CBabygothData { CAssetId x174_flamePlayerIceTxtr; public: - CBabygothData(CInputStream&); + explicit CBabygothData(CInputStream&); const CDamageInfo& GetFireballDamage() const { return xc_fireballDamage; } CAssetId GetFireballResID() const { return x8_fireballWeapon; } float GetFireballAttackVariance() const { return x4_fireballAttackTimeVariance; } diff --git a/Runtime/MP1/World/CChozoGhost.hpp b/Runtime/MP1/World/CChozoGhost.hpp index 410e69c4d..82fb3f002 100644 --- a/Runtime/MP1/World/CChozoGhost.hpp +++ b/Runtime/MP1/World/CChozoGhost.hpp @@ -25,7 +25,7 @@ public: u32 x1c_numBolts; public: - CBehaveChance(CInputStream&); + explicit CBehaveChance(CInputStream&); EBehaveType GetBehave(EBehaveType type, CStateManager& mgr) const; float GetLurk() const { return x4_lurk; } diff --git a/Runtime/MP1/World/CFlaahgra.hpp b/Runtime/MP1/World/CFlaahgra.hpp index 37c95062c..46a01e1f1 100644 --- a/Runtime/MP1/World/CFlaahgra.hpp +++ b/Runtime/MP1/World/CFlaahgra.hpp @@ -4,6 +4,7 @@ #include #include +#include "Runtime/CDependencyGroup.hpp" #include "Runtime/rstl.hpp" #include "Runtime/Collision/CJointCollisionDescription.hpp" #include "Runtime/Weapon/CProjectileInfo.hpp" @@ -47,7 +48,7 @@ class CFlaahgraData { public: static constexpr u32 GetNumProperties() { return 23; } - CFlaahgraData(CInputStream&); + explicit CFlaahgraData(CInputStream&); const CAnimationParameters& GetAnimationParameters() const { return x14c_animationParameters; } }; diff --git a/Runtime/MP1/World/CFlyingPirate.cpp b/Runtime/MP1/World/CFlyingPirate.cpp index 563666e5a..ba5aa6359 100644 --- a/Runtime/MP1/World/CFlyingPirate.cpp +++ b/Runtime/MP1/World/CFlyingPirate.cpp @@ -341,8 +341,8 @@ CFlyingPirate::CFlyingPirate(TUniqueId uid, std::string_view name, const CEntity x7e0_gunSegId = animData->GetLocatorSegId("L_gun_LCTR"sv); x864_missileSegments.push_back(animData->GetLocatorSegId("L_Missile_LCTR"sv)); x864_missileSegments.push_back(animData->GetLocatorSegId("R_Missile_LCTR"sv)); - x850_height = - modelData->GetScale().x() * GetAnimationDistance({3, CPASAnimParm::FromEnum(3), CPASAnimParm::FromEnum(1)}); + x850_height = modelData->GetScale().x() * + GetAnimationDistance(CPASAnimParmData{3, CPASAnimParm::FromEnum(3), CPASAnimParm::FromEnum(1)}); if (x568_data.xd8_particleGen1.IsValid() && x568_data.xdc_particleGen2.IsValid() && x568_data.xe0_particleGen3.IsValid()) { x65c_particleGenDescs.push_back(g_SimplePool->GetObj({SBIG('PART'), x568_data.xd8_particleGen1})); @@ -767,7 +767,7 @@ void CFlyingPirate::FireProjectile(CStateManager& mgr, float dt) { } if (projectileFired) { const std::pair& anim = x450_bodyController->GetPASDatabase().FindBestAnimation( - {24, CPASAnimParm::FromEnum(2)}, *mgr.GetActiveRandom(), -1); + CPASAnimParmData{24, CPASAnimParm::FromEnum(2)}, *mgr.GetActiveRandom(), -1); if (anim.first > 0.f) { GetModelData()->GetAnimationData()->AddAdditiveAnimation(anim.second, 1.f, false, true); } diff --git a/Runtime/MP1/World/CMagdolite.hpp b/Runtime/MP1/World/CMagdolite.hpp index 5c61935ab..9346e6027 100644 --- a/Runtime/MP1/World/CMagdolite.hpp +++ b/Runtime/MP1/World/CMagdolite.hpp @@ -16,7 +16,7 @@ public: float x1c_; public: - CMagdoliteData(CInputStream&); + explicit CMagdoliteData(CInputStream&); }; private: diff --git a/Runtime/MP1/World/CMetroid.hpp b/Runtime/MP1/World/CMetroid.hpp index d9018c6a6..1a547f75c 100644 --- a/Runtime/MP1/World/CMetroid.hpp +++ b/Runtime/MP1/World/CMetroid.hpp @@ -25,7 +25,7 @@ class CMetroidData { bool x128_24_ : 1; public: - CMetroidData(CInputStream& in); + explicit CMetroidData(CInputStream& in); static u32 GetNumProperties() { return skNumProperties; } }; diff --git a/Runtime/MP1/World/CMetroidBeta.hpp b/Runtime/MP1/World/CMetroidBeta.hpp index 17386ab6e..2b09987cc 100644 --- a/Runtime/MP1/World/CMetroidBeta.hpp +++ b/Runtime/MP1/World/CMetroidBeta.hpp @@ -38,7 +38,7 @@ class CMetroidBetaData { bool x108_24_ : 1; public: - CMetroidBetaData(CInputStream&); + explicit CMetroidBetaData(CInputStream&); }; class CMetroidBeta : public CPatterned { s32 x568_progState = -1; diff --git a/Runtime/MP1/World/CSpacePirate.cpp b/Runtime/MP1/World/CSpacePirate.cpp index 92a857060..3e8d59d30 100644 --- a/Runtime/MP1/World/CSpacePirate.cpp +++ b/Runtime/MP1/World/CSpacePirate.cpp @@ -618,10 +618,11 @@ bool CSpacePirate::FireProjectile(float dt, CStateManager& mgr) { } } if (ret) { - auto bestAnim = x450_bodyController->GetPASDatabase().FindBestAnimation({24, CPASAnimParm::FromEnum(2)}, - *mgr.GetActiveRandom(), -1); - if (bestAnim.first > 0.f) + const auto bestAnim = x450_bodyController->GetPASDatabase().FindBestAnimation( + CPASAnimParmData{24, CPASAnimParm::FromEnum(2)}, *mgr.GetActiveRandom(), -1); + if (bestAnim.first > 0.f) { x64_modelData->GetAnimationData()->AddAdditiveAnimation(bestAnim.second, 1.f, false, true); + } CSfxManager::AddEmitter(x568_pirateData.x48_Sound_Projectile, GetTranslation(), zeus::skZero3f, true, false, 0x7f, kInvalidAreaId); } @@ -1876,8 +1877,8 @@ void CSpacePirate::Taunt(CStateManager& mgr, EStateMsg msg, float dt) { if (!x635_27_shadowPirate) { bool withOtherPirate = true; if (x634_27_melee) { - auto bestAnim = x450_bodyController->GetPASDatabase().FindBestAnimation({16, CPASAnimParm::FromEnum(2)}, - *mgr.GetActiveRandom(), -1); + const auto bestAnim = x450_bodyController->GetPASDatabase().FindBestAnimation( + CPASAnimParmData{16, CPASAnimParm::FromEnum(2)}, *mgr.GetActiveRandom(), -1); if (bestAnim.first > 0.f) { withOtherPirate = false; x760_taunt = pas::ETauntType::Two; diff --git a/Runtime/Particle/CColorElement.hpp b/Runtime/Particle/CColorElement.hpp index 6939f5b01..1323aceef 100644 --- a/Runtime/Particle/CColorElement.hpp +++ b/Runtime/Particle/CColorElement.hpp @@ -20,7 +20,7 @@ class CCEKeyframeEmitter : public CColorElement { std::vector x18_keys; public: - CCEKeyframeEmitter(CInputStream& in); + explicit CCEKeyframeEmitter(CInputStream& in); bool GetValue(int frame, zeus::CColor& colorOut) const override; }; diff --git a/Runtime/Particle/CElementGen.hpp b/Runtime/Particle/CElementGen.hpp index 893211428..26ec47598 100644 --- a/Runtime/Particle/CElementGen.hpp +++ b/Runtime/Particle/CElementGen.hpp @@ -43,7 +43,7 @@ public: zeus::CVector3f x4_viewPoint; public: - CParticleListItem(s16 idx) : x0_partIdx(idx) {} + explicit CParticleListItem(s16 idx) : x0_partIdx(idx) {} }; static CParticle* g_currentParticle; diff --git a/Runtime/Particle/CFlameWarp.cpp b/Runtime/Particle/CFlameWarp.cpp index f87d44b76..9cf18a04e 100644 --- a/Runtime/Particle/CFlameWarp.cpp +++ b/Runtime/Particle/CFlameWarp.cpp @@ -5,8 +5,9 @@ namespace urde { void CFlameWarp::ModifyParticles(std::vector& particles) { - if (x9c_stateMgr == 0 || particles.size() < 9) + if (x9c_stateMgr == nullptr || particles.size() < 9) { return; + } std::vector> vec; vec.reserve(particles.size()); diff --git a/Runtime/Particle/CIntElement.hpp b/Runtime/Particle/CIntElement.hpp index 671c506ef..f2a8a4267 100644 --- a/Runtime/Particle/CIntElement.hpp +++ b/Runtime/Particle/CIntElement.hpp @@ -19,7 +19,7 @@ class CIEKeyframeEmitter : public CIntElement { std::vector x18_keys; public: - CIEKeyframeEmitter(CInputStream& in); + explicit CIEKeyframeEmitter(CInputStream& in); bool GetValue(int frame, int& valOut) const override; int GetMaxValue() const override; }; @@ -73,7 +73,7 @@ class CIEConstant : public CIntElement { int x4_val; public: - CIEConstant(int val) : x4_val(val) {} + explicit CIEConstant(int val) : x4_val(val) {} bool GetValue(int frame, int& valOut) const override; int GetMaxValue() const override; }; @@ -82,7 +82,7 @@ class CIEImpulse : public CIntElement { std::unique_ptr x4_a; public: - CIEImpulse(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CIEImpulse(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, int& valOut) const override; int GetMaxValue() const override; }; @@ -91,7 +91,7 @@ class CIELifetimePercent : public CIntElement { std::unique_ptr x4_percentVal; public: - CIELifetimePercent(std::unique_ptr&& a) : x4_percentVal(std::move(a)) {} + explicit CIELifetimePercent(std::unique_ptr&& a) : x4_percentVal(std::move(a)) {} bool GetValue(int frame, int& valOut) const override; int GetMaxValue() const override; }; @@ -161,7 +161,7 @@ class CIETimeScale : public CIntElement { std::unique_ptr x4_a; public: - CIETimeScale(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CIETimeScale(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, int& valOut) const override; int GetMaxValue() const override; }; diff --git a/Runtime/Particle/CModVectorElement.hpp b/Runtime/Particle/CModVectorElement.hpp index d73dc0849..f4270aedc 100644 --- a/Runtime/Particle/CModVectorElement.hpp +++ b/Runtime/Particle/CModVectorElement.hpp @@ -112,7 +112,7 @@ class CMVEGravity : public CModVectorElement { std::unique_ptr x4_a; public: - CMVEGravity(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CMVEGravity(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, zeus::CVector3f& pVel, zeus::CVector3f& pPos) const override; }; @@ -130,7 +130,7 @@ class CMVESetPosition : public CModVectorElement { std::unique_ptr x4_a; public: - CMVESetPosition(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CMVESetPosition(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, zeus::CVector3f& pVel, zeus::CVector3f& pPos) const override; }; diff --git a/Runtime/Particle/CParticleElectric.hpp b/Runtime/Particle/CParticleElectric.hpp index 9bfb94319..880ec2be3 100644 --- a/Runtime/Particle/CParticleElectric.hpp +++ b/Runtime/Particle/CParticleElectric.hpp @@ -115,7 +115,7 @@ private: void BuildBounds(); public: - CParticleElectric(const TToken& desc); + explicit CParticleElectric(const TToken& desc); bool Update(double) override; void Render(const CActorLights* lights = nullptr) override; diff --git a/Runtime/Particle/CRealElement.hpp b/Runtime/Particle/CRealElement.hpp index 635d6c4db..034bc8447 100644 --- a/Runtime/Particle/CRealElement.hpp +++ b/Runtime/Particle/CRealElement.hpp @@ -20,7 +20,7 @@ class CREKeyframeEmitter : public CRealElement { std::vector x18_keys; public: - CREKeyframeEmitter(CInputStream& in); + explicit CREKeyframeEmitter(CInputStream& in); bool GetValue(int frame, float& valOut) const override; }; @@ -38,7 +38,7 @@ class CREConstant : public CRealElement { float x4_val; public: - CREConstant(float val) : x4_val(val) {} + explicit CREConstant(float val) : x4_val(val) {} bool GetValue(int frame, float& valOut) const override; bool IsConstant() const override { return true; } }; @@ -133,7 +133,7 @@ class CRETimeScale : public CRealElement { std::unique_ptr x4_a; public: - CRETimeScale(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CRETimeScale(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; @@ -141,7 +141,7 @@ class CRELifetimePercent : public CRealElement { std::unique_ptr x4_percentVal; public: - CRELifetimePercent(std::unique_ptr&& a) : x4_percentVal(std::move(a)) {} + explicit CRELifetimePercent(std::unique_ptr&& a) : x4_percentVal(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; @@ -256,7 +256,7 @@ class CREVectorMagnitude : public CRealElement { std::unique_ptr x4_a; public: - CREVectorMagnitude(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CREVectorMagnitude(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; @@ -264,7 +264,7 @@ class CREVectorXToReal : public CRealElement { std::unique_ptr x4_a; public: - CREVectorXToReal(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CREVectorXToReal(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; @@ -272,7 +272,7 @@ class CREVectorYToReal : public CRealElement { std::unique_ptr x4_a; public: - CREVectorYToReal(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CREVectorYToReal(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; @@ -280,7 +280,7 @@ class CREVectorZToReal : public CRealElement { std::unique_ptr x4_a; public: - CREVectorZToReal(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CREVectorZToReal(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; @@ -288,7 +288,7 @@ class CREExternalVar : public CRealElement { std::unique_ptr x4_a; public: - CREExternalVar(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CREExternalVar(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; @@ -326,7 +326,7 @@ class CREGetComponentRed : public CRealElement { std::unique_ptr x4_a; public: - CREGetComponentRed(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CREGetComponentRed(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; @@ -335,7 +335,7 @@ class CREGetComponentGreen : public CRealElement { std::unique_ptr x4_a; public: - CREGetComponentGreen(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CREGetComponentGreen(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; @@ -344,7 +344,7 @@ class CREGetComponentBlue : public CRealElement { std::unique_ptr x4_a; public: - CREGetComponentBlue(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CREGetComponentBlue(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; @@ -353,7 +353,7 @@ class CREGetComponentAlpha : public CRealElement { std::unique_ptr x4_a; public: - CREGetComponentAlpha(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CREGetComponentAlpha(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, float& valOut) const override; }; diff --git a/Runtime/Particle/CSpawnSystemKeyframeData.hpp b/Runtime/Particle/CSpawnSystemKeyframeData.hpp index f30d580e7..d254e14ad 100644 --- a/Runtime/Particle/CSpawnSystemKeyframeData.hpp +++ b/Runtime/Particle/CSpawnSystemKeyframeData.hpp @@ -24,7 +24,7 @@ public: void LoadToken(CSimplePool* pool); public: - CSpawnSystemKeyframeInfo(CInputStream& in); + explicit CSpawnSystemKeyframeInfo(CInputStream& in); TLockedToken& GetToken() { return x10_token; } }; @@ -36,7 +36,7 @@ private: std::vector>> x10_spawns; public: - CSpawnSystemKeyframeData(CInputStream& in); + explicit CSpawnSystemKeyframeData(CInputStream& in); void LoadAllSpawnedSystemTokens(CSimplePool* pool); std::vector& GetSpawnedSystemsAtFrame(u32 frame); }; diff --git a/Runtime/Particle/CUVElement.hpp b/Runtime/Particle/CUVElement.hpp index 1abb52e0b..8aa6fc566 100644 --- a/Runtime/Particle/CUVElement.hpp +++ b/Runtime/Particle/CUVElement.hpp @@ -29,7 +29,7 @@ struct CUVEConstant : public CUVElement { TLockedToken x4_tex; public: - CUVEConstant(TToken&& tex) : x4_tex(std::move(tex)) {} + explicit CUVEConstant(TToken&& tex) : x4_tex(std::move(tex)) {} TLockedToken GetValueTexture(int frame) const override { return TLockedToken(x4_tex); } void GetValueUV(int frame, SUVElementSet& valOut) const override { valOut = {0.f, 0.f, 1.f, 1.f}; } bool HasConstantTexture() const override { return true; } diff --git a/Runtime/Particle/CVectorElement.hpp b/Runtime/Particle/CVectorElement.hpp index b0682a773..940326a10 100644 --- a/Runtime/Particle/CVectorElement.hpp +++ b/Runtime/Particle/CVectorElement.hpp @@ -22,7 +22,7 @@ class CVEKeyframeEmitter : public CVectorElement { std::vector x18_keys; public: - CVEKeyframeEmitter(CInputStream& in); + explicit CVEKeyframeEmitter(CInputStream& in); bool GetValue(int frame, zeus::CVector3f& valOut) const override; }; @@ -138,7 +138,7 @@ class CVERealToVector : public CVectorElement { std::unique_ptr x4_a; public: - CVERealToVector(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CVERealToVector(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, zeus::CVector3f& valOut) const override; }; @@ -204,7 +204,7 @@ class CVEColorToVector : public CVectorElement { std::unique_ptr x4_a; public: - CVEColorToVector(std::unique_ptr&& a) : x4_a(std::move(a)) {} + explicit CVEColorToVector(std::unique_ptr&& a) : x4_a(std::move(a)) {} bool GetValue(int frame, zeus::CVector3f& valOut) const override; }; diff --git a/Runtime/RetroTypes.hpp b/Runtime/RetroTypes.hpp index bc46c2c5e..6c0c70628 100644 --- a/Runtime/RetroTypes.hpp +++ b/Runtime/RetroTypes.hpp @@ -55,7 +55,7 @@ struct SObjectTag { [[nodiscard]] constexpr bool operator<(const SObjectTag& other) const noexcept { return id < other.id; } constexpr SObjectTag() noexcept = default; constexpr SObjectTag(FourCC tp, CAssetId rid) noexcept : type(tp), id(rid) {} - SObjectTag(CInputStream& in) { + explicit SObjectTag(CInputStream& in) { in.readBytesToBuf(&type, 4); id = CAssetId(in); } diff --git a/Runtime/Weapon/CBeamInfo.hpp b/Runtime/Weapon/CBeamInfo.hpp index d87971799..8df00f49b 100644 --- a/Runtime/Weapon/CBeamInfo.hpp +++ b/Runtime/Weapon/CBeamInfo.hpp @@ -31,7 +31,7 @@ class CBeamInfo { zeus::CColor x40_outerColor; public: - CBeamInfo(CInputStream& in) + explicit CBeamInfo(CInputStream& in) : x0_(in.readUint32Big()) , x4_beamAttributes(in.readUint32Big()) , x8_contactFxId(in.readUint32Big()) diff --git a/Runtime/Weapon/CGunController.hpp b/Runtime/Weapon/CGunController.hpp index 35f23dcec..85a7b24e0 100644 --- a/Runtime/Weapon/CGunController.hpp +++ b/Runtime/Weapon/CGunController.hpp @@ -19,7 +19,7 @@ class CGunController { bool x58_25_enteredComboFire : 1; public: - CGunController(CModelData& modelData) : x0_modelData(modelData) { + explicit CGunController(CModelData& modelData) : x0_modelData(modelData) { x58_24_animDone = true; x58_25_enteredComboFire = false; } diff --git a/Runtime/Weapon/CPhazonBeam.hpp b/Runtime/Weapon/CPhazonBeam.hpp index 8de5486ab..5b63feb0a 100644 --- a/Runtime/Weapon/CPhazonBeam.hpp +++ b/Runtime/Weapon/CPhazonBeam.hpp @@ -22,8 +22,8 @@ class CPhazonBeam final : public CGunWeapon { bool x274_26_veinsAlphaActive : 1; bool x274_27_phazonVeinsIdx : 1; float x278_fireTime = 1.f / 3.f; - mutable CAABoxShader m_aaboxShaderScale = {true}; - mutable CAABoxShader m_aaboxShaderTranslate = {true}; + mutable CAABoxShader m_aaboxShaderScale{true}; + mutable CAABoxShader m_aaboxShaderTranslate{true}; void ReInitVariables(); void DrawClipScaleCube() const; void DrawClipTranslateCube() const; diff --git a/Runtime/Weapon/CPlayerGun.cpp b/Runtime/Weapon/CPlayerGun.cpp index f122ab73f..d13a0f51a 100644 --- a/Runtime/Weapon/CPlayerGun.cpp +++ b/Runtime/Weapon/CPlayerGun.cpp @@ -1785,36 +1785,35 @@ void CPlayerGun::UpdateGunIdle(bool inStrikeCooldown, float camBobT, float dt, C void CPlayerGun::Update(float grappleSwingT, float cameraBobT, float dt, CStateManager& mgr) { CPlayer& player = mgr.GetPlayer(); CPlayerState& playerState = *mgr.GetPlayerState(); - bool isUnmorphed = player.GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Unmorphed; + const bool isUnmorphed = player.GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Unmorphed; - bool becameFrozen; - if (isUnmorphed) + bool becameFrozen = false; + if (isUnmorphed) { becameFrozen = !x834_29_frozen && player.GetFrozenState(); - else - becameFrozen = false; + } - bool becameThawed; - if (isUnmorphed) + bool becameThawed = false; + if (isUnmorphed) { becameThawed = x834_29_frozen && !player.GetFrozenState(); - else - becameThawed = false; + } x834_29_frozen = isUnmorphed && player.GetFrozenState(); - float advDt; - if (x834_29_frozen) + float advDt = dt; + if (x834_29_frozen) { advDt = 0.f; - else - advDt = dt; + } - bool r23 = x678_morph.GetGunState() != CGunMorph::EGunState::OutWipeDone; - if (mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::XRay || r23) + const bool r23 = x678_morph.GetGunState() != CGunMorph::EGunState::OutWipeDone; + if (mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::XRay || r23) { x6e0_rightHandModel.AdvanceAnimation(advDt, mgr, kInvalidAreaId, true); - if (r23 && x734_loadingBeam != 0 && x734_loadingBeam != x72c_currentBeam) { + } + if (r23 && x734_loadingBeam != nullptr && x734_loadingBeam != x72c_currentBeam) { x744_auxWeapon->LoadIdle(); x734_loadingBeam->Update(advDt, mgr); } - if (!x744_auxWeapon->IsLoaded()) + if (!x744_auxWeapon->IsLoaded()) { x744_auxWeapon->LoadIdle(); + } if (becameFrozen) { x72c_currentBeam->EnableSecondaryFx(CGunWeapon::ESecondaryFxType::None); @@ -2267,12 +2266,12 @@ void CPlayerGun::DropBomb(EBWeapon weapon, CStateManager& mgr) { if (x308_bombCount <= 0) return; - zeus::CVector3f plPos = mgr.GetPlayer().GetTranslation(); - zeus::CTransform xf = + const zeus::CVector3f plPos = mgr.GetPlayer().GetTranslation(); + const zeus::CTransform xf = zeus::CTransform::Translate({plPos.x(), plPos.y(), plPos.z() + g_tweakPlayer->GetPlayerBallHalfExtent()}); - CBomb* bomb = - new CBomb(x784_bombEffects[u32(weapon)][0], x784_bombEffects[u32(weapon)][1], mgr.AllocateUniqueId(), - mgr.GetPlayer().GetAreaId(), x538_playerId, x354_bombFuseTime, xf, g_tweakPlayerGun->GetBombInfo()); + CBomb* bomb = new CBomb(x784_bombEffects[u32(weapon)][0], x784_bombEffects[u32(weapon)][1], mgr.AllocateUniqueId(), + mgr.GetPlayer().GetAreaId(), x538_playerId, x354_bombFuseTime, xf, + CDamageInfo{g_tweakPlayerGun->GetBombInfo()}); mgr.AddObject(bomb); if (x308_bombCount == 3) @@ -2288,8 +2287,8 @@ void CPlayerGun::DropBomb(EBWeapon weapon, CStateManager& mgr) { } TUniqueId CPlayerGun::DropPowerBomb(CStateManager& mgr) { - CDamageInfo dInfo = (mgr.GetPlayer().GetDeathTime() <= 0.f ? g_tweakPlayerGun->GetPowerBombInfo() - : CDamageInfo(CWeaponMode::PowerBomb(), 0.f, 0.f, 0.f)); + const auto dInfo = mgr.GetPlayer().GetDeathTime() <= 0.f ? CDamageInfo{g_tweakPlayerGun->GetPowerBombInfo()} + : CDamageInfo{CWeaponMode::PowerBomb(), 0.f, 0.f, 0.f}; TUniqueId uid = mgr.AllocateUniqueId(); zeus::CVector3f plVec = mgr.GetPlayer().GetTranslation(); diff --git a/Runtime/Weapon/CPlayerGun.hpp b/Runtime/Weapon/CPlayerGun.hpp index 8ecefbd63..171b64131 100644 --- a/Runtime/Weapon/CPlayerGun.hpp +++ b/Runtime/Weapon/CPlayerGun.hpp @@ -198,7 +198,7 @@ private: float x664_ = 0.f; float x668_aimVerticalSpeed; float x66c_aimHorizontalSpeed; - std::pair x670_animSfx = {0xffff, {}}; + std::pair x670_animSfx{0xffff, {}}; CGunMorph x678_morph; CMotionState x6a0_motionState; zeus::CAABox x6c8_hologramClipCube; @@ -266,9 +266,9 @@ private: u32 _dummy = 0; }; - mutable CTexturedQuadFilter m_screenQuad = {EFilterType::Blend, CGraphics::g_SpareTexture.get(), - CTexturedQuadFilter::ZTest::GEqualZWrite}; - mutable CAABoxShader m_aaboxShader = {true}; + mutable CTexturedQuadFilter m_screenQuad{EFilterType::Blend, CGraphics::g_SpareTexture.get(), + CTexturedQuadFilter::ZTest::GEqualZWrite}; + mutable CAABoxShader m_aaboxShader{true}; void InitBeamData(); void InitBombData(); diff --git a/Runtime/Weapon/CProjectileInfo.hpp b/Runtime/Weapon/CProjectileInfo.hpp index 8906aaf07..7f388c359 100644 --- a/Runtime/Weapon/CProjectileInfo.hpp +++ b/Runtime/Weapon/CProjectileInfo.hpp @@ -13,7 +13,7 @@ class CProjectileInfo { CDamageInfo xc_damageInfo; public: - CProjectileInfo(CInputStream&); + explicit CProjectileInfo(CInputStream&); CProjectileInfo(CAssetId, const CDamageInfo&); float GetProjectileSpeed() const; diff --git a/Runtime/World/CAnimationParameters.hpp b/Runtime/World/CAnimationParameters.hpp index bb66c7247..7cb29aedc 100644 --- a/Runtime/World/CAnimationParameters.hpp +++ b/Runtime/World/CAnimationParameters.hpp @@ -13,7 +13,7 @@ public: CAnimationParameters() = default; CAnimationParameters(CAssetId ancs, u32 charIdx, u32 defaultAnim) : x0_ancs(ancs), x4_charIdx(charIdx), x8_defaultAnim(defaultAnim) {} - CAnimationParameters(CInputStream& in) + explicit CAnimationParameters(CInputStream& in) : x0_ancs(in.readUint32Big()), x4_charIdx(in.readUint32Big()), x8_defaultAnim(in.readUint32Big()) {} CAssetId GetACSFile() const { return x0_ancs; } diff --git a/Runtime/World/CDamageInfo.hpp b/Runtime/World/CDamageInfo.hpp index d2591e92b..0e800520f 100644 --- a/Runtime/World/CDamageInfo.hpp +++ b/Runtime/World/CDamageInfo.hpp @@ -20,7 +20,7 @@ class CDamageInfo { public: constexpr CDamageInfo() = default; - CDamageInfo(CInputStream& in) { + explicit CDamageInfo(CInputStream& in) { in.readUint32Big(); x0_weaponMode = CWeaponMode(EWeaponType(in.readUint32Big())); x8_damage = in.readFloatBig(); @@ -38,7 +38,7 @@ public: constexpr CDamageInfo& operator=(CDamageInfo&&) = default; CDamageInfo(const CDamageInfo&, float); - CDamageInfo(const DataSpec::SShotParam& other); + explicit CDamageInfo(const DataSpec::SShotParam& other); CDamageInfo& operator=(const DataSpec::SShotParam& other); const CWeaponMode& GetWeaponMode() const { return x0_weaponMode; } diff --git a/Runtime/World/CDamageVulnerability.hpp b/Runtime/World/CDamageVulnerability.hpp index af83e8e03..b66f23ab5 100644 --- a/Runtime/World/CDamageVulnerability.hpp +++ b/Runtime/World/CDamageVulnerability.hpp @@ -47,7 +47,7 @@ class CDamageVulnerability { static const CDamageVulnerability sPassThroughVulnerability; public: - CDamageVulnerability(CInputStream& in); + explicit CDamageVulnerability(CInputStream& in); CDamageVulnerability(EVulnerability power, EVulnerability ice, EVulnerability wave, EVulnerability plasma, EVulnerability bomb, EVulnerability powerBomb, EVulnerability missile, EVulnerability boostBall, EVulnerability phazon, EVulnerability enemyWp1, EVulnerability wnemyWp2, EVulnerability enemyWp3, diff --git a/Runtime/World/CEnvFxManager.cpp b/Runtime/World/CEnvFxManager.cpp index 443cef1bd..0ec4437a2 100644 --- a/Runtime/World/CEnvFxManager.cpp +++ b/Runtime/World/CEnvFxManager.cpp @@ -23,11 +23,11 @@ namespace urde { static rstl::reserved_vector g_SnowForces; CEnvFxManagerGrid::CEnvFxManagerGrid(const zeus::CVector2i& position, const zeus::CVector2i& extent, - const std::vector& initialParticles, int reserve, - CEnvFxManager& parent, boo::IGraphicsDataFactory::Context& ctx) + std::vector initialParticles, int reserve, CEnvFxManager& parent, + boo::IGraphicsDataFactory::Context& ctx) : x4_position(position) , xc_extent(extent) -, x1c_particles(initialParticles) +, x1c_particles(std::move(initialParticles)) , m_instBuf(parent.m_instPool.allocateBlock(CGraphics::g_BooFactory, reserve)) , m_uniformBuf(parent.m_uniformPool.allocateBlock(CGraphics::g_BooFactory)) , m_lineRenderer(ctx, CLineRenderer::EPrimitiveMode::Lines, reserve * 2, parent.x40_txtrEnvGradient->GetBooTexture(), diff --git a/Runtime/World/CEnvFxManager.hpp b/Runtime/World/CEnvFxManager.hpp index 8fe12fc1d..02bc1f4e3 100644 --- a/Runtime/World/CEnvFxManager.hpp +++ b/Runtime/World/CEnvFxManager.hpp @@ -79,7 +79,7 @@ class CEnvFxManagerGrid { public: CEnvFxManagerGrid(const zeus::CVector2i& position, const zeus::CVector2i& extent, - const std::vector& initialParticles, int reserve, CEnvFxManager& parent, + std::vector initialParticles, int reserve, CEnvFxManager& parent, boo::IGraphicsDataFactory::Context& ctx); void Render(const zeus::CTransform& xf, const zeus::CTransform& invXf, const zeus::CTransform& camXf, float fxDensity, EEnvFxType fxType, const CEnvFxManager& parent) const; diff --git a/Runtime/World/CExplosion.cpp b/Runtime/World/CExplosion.cpp index 075a3b18a..06d3ce62b 100644 --- a/Runtime/World/CExplosion.cpp +++ b/Runtime/World/CExplosion.cpp @@ -95,7 +95,7 @@ void CExplosion::AddToRenderer(const zeus::CFrustum& frustum, const CStateManage if (!(xf4_24_renderThermalHot && mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot) && !(xf4_26_renderXray && mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay)) { - g_Renderer->AddParticleGen(*xe8_particleGen.get()); + g_Renderer->AddParticleGen(*xe8_particleGen); return; } diff --git a/Runtime/World/CGameArea.hpp b/Runtime/World/CGameArea.hpp index 30de66de8..31623d90b 100644 --- a/Runtime/World/CGameArea.hpp +++ b/Runtime/World/CGameArea.hpp @@ -86,7 +86,7 @@ struct CAreaRenderOctTree { const u32* x34_indirectionTable; const u8* x38_entries; - CAreaRenderOctTree(const u8* buf); + explicit CAreaRenderOctTree(const u8* buf); void FindOverlappingModels(std::vector& out, const zeus::CAABox& testAABB) const; void FindOverlappingModels(u32* out, const zeus::CAABox& testAABB) const; @@ -131,10 +131,11 @@ class CGameArea final : public IGameArea { public: class CChainIterator { - CGameArea* m_area; + CGameArea* m_area = nullptr; public: - CChainIterator(CGameArea* area) : m_area(area) {} + constexpr CChainIterator() = default; + explicit constexpr CChainIterator(CGameArea* area) : m_area(area) {} CGameArea& operator*() const { return *m_area; } CGameArea* operator->() const { return m_area; } CChainIterator& operator++() { @@ -146,10 +147,11 @@ public: }; class CConstChainIterator { - const CGameArea* m_area; + const CGameArea* m_area = nullptr; public: - CConstChainIterator(const CGameArea* area) : m_area(area) {} + constexpr CConstChainIterator() = default; + explicit constexpr CConstChainIterator(const CGameArea* area) : m_area(area) {} const CGameArea& operator*() const { return *m_area; } const CGameArea* operator->() const { return m_area; } CConstChainIterator& operator++() { @@ -165,7 +167,7 @@ public: TAreaId x200c_areaIdx = 0; public: - CAreaObjectList(TAreaId areaIdx) : CObjectList(EGameObjectList::Invalid), x200c_areaIdx(areaIdx) {} + explicit CAreaObjectList(TAreaId areaIdx) : CObjectList(EGameObjectList::Invalid), x200c_areaIdx(areaIdx) {} bool IsQualified(const CEntity& ent) const override; }; @@ -197,7 +199,7 @@ public: u32 x8_collisionSize = 0; std::optional xc_octTree; std::vector x4c_insts; - SShader m_materialSet = {0}; + SShader m_materialSet{0}; // std::unique_ptr x5c_; std::vector x60_lightsA; std::vector x70_gfxLightsA; @@ -267,8 +269,8 @@ private: void UpdateWeaponWorldLighting(float dt); public: - CGameArea(CInputStream& in, int idx, int mlvlVersion); - CGameArea(CAssetId mreaId); // Warmup constructor + explicit CGameArea(CInputStream& in, int idx, int mlvlVersion); + explicit CGameArea(CAssetId mreaId); // Warmup constructor ~CGameArea(); bool IsFinishedOccluding() const; diff --git a/Runtime/World/CHUDMemoParms.hpp b/Runtime/World/CHUDMemoParms.hpp index 61e3b678a..761f8a00b 100644 --- a/Runtime/World/CHUDMemoParms.hpp +++ b/Runtime/World/CHUDMemoParms.hpp @@ -14,7 +14,7 @@ public: CHUDMemoParms() = default; CHUDMemoParms(float dispTime, bool clearMemoWindow, bool fadeOutOnly, bool hintMemo) : x0_dispTime(dispTime), x4_clearMemoWindow(clearMemoWindow), x5_fadeOutOnly(fadeOutOnly), x6_hintMemo(hintMemo) {} - CHUDMemoParms(CInputStream& in) { + explicit CHUDMemoParms(CInputStream& in) { x0_dispTime = in.readFloatBig(); x4_clearMemoWindow = in.readBool(); } diff --git a/Runtime/World/CHealthInfo.hpp b/Runtime/World/CHealthInfo.hpp index c8d890a58..a69b52035 100644 --- a/Runtime/World/CHealthInfo.hpp +++ b/Runtime/World/CHealthInfo.hpp @@ -9,11 +9,11 @@ class CHealthInfo { float x4_knockbackResistance; public: - CHealthInfo(float hp) : x0_health(hp), x4_knockbackResistance(0.f) {} + explicit CHealthInfo(float hp) : x0_health(hp), x4_knockbackResistance(0.f) {} CHealthInfo(float hp, float resist) : x0_health(hp), x4_knockbackResistance(resist) {} - CHealthInfo(CInputStream& in); + explicit CHealthInfo(CInputStream& in); void SetHP(float hp) { x0_health = hp; } float GetHP() const { return x0_health; } float GetKnockbackResistance() const { return x4_knockbackResistance; } diff --git a/Runtime/World/CMorphBall.hpp b/Runtime/World/CMorphBall.hpp index c0f7e8b90..bc52fcc17 100644 --- a/Runtime/World/CMorphBall.hpp +++ b/Runtime/World/CMorphBall.hpp @@ -233,7 +233,7 @@ public: void RenderMorphBallTransitionFlash(const CStateManager&) const; void UpdateIceBreakEffect(float dt); void RenderIceBreakEffect(const CStateManager& mgr) const; - bool IsMorphBallTransitionFlashValid() const { return x19dc_morphBallTransitionFlashGen != 0; } + bool IsMorphBallTransitionFlashValid() const { return x19dc_morphBallTransitionFlashGen != nullptr; } void RenderDamageEffects(const CStateManager& mgr, const zeus::CTransform& xf) const; void UpdateHalfPipeStatus(CStateManager& mgr, float dt); bool GetIsInHalfPipeMode() const { return x1df8_24_inHalfPipeMode; } diff --git a/Runtime/World/CPathFindRegion.hpp b/Runtime/World/CPathFindRegion.hpp index b126f230e..a0cc8509e 100644 --- a/Runtime/World/CPathFindRegion.hpp +++ b/Runtime/World/CPathFindRegion.hpp @@ -17,7 +17,7 @@ class CPFNode { zeus::CVector3f xc_normal; public: - CPFNode(CMemoryInStream& in); + explicit CPFNode(CMemoryInStream& in); const zeus::CVector3f& GetPos() const { return x0_position; } const zeus::CVector3f& GetNormal() const { return xc_normal; } }; @@ -29,7 +29,7 @@ class CPFLink { float xc_oo2dWidth; public: - CPFLink(CMemoryInStream& in); + explicit CPFLink(CMemoryInStream& in); u32 GetNode() const { return x0_node; } u32 GetRegion() const { return x4_region; } float Get2dWidth() const { return x8_2dWidth; } @@ -51,7 +51,7 @@ class CPFRegion { public: CPFRegion() = default; - CPFRegion(CMemoryInStream& in); + explicit CPFRegion(CMemoryInStream& in); void SetData(CPFRegionData* data) { x4c_regionData = data; } CPFRegionData* Data() const { return x4c_regionData; } u32 GetIndex() const { return x24_regionIdx; } diff --git a/Runtime/World/CPatterned.cpp b/Runtime/World/CPatterned.cpp index 100fc1b27..3bfbbb3ee 100644 --- a/Runtime/World/CPatterned.cpp +++ b/Runtime/World/CPatterned.cpp @@ -1586,7 +1586,7 @@ void CPatterned::RenderIceModelWithFlags(const CModelFlags& flags) const { CModelFlags useFlags = flags; useFlags.x1_matSetIdx = 0; CAnimData* animData = x64_modelData->GetAnimationData(); - if (CMorphableSkinnedModel* iceModel = animData->IceModel().GetObj()) + if (CMorphableSkinnedModel* iceModel = animData->GetIceModel().GetObj()) animData->Render(*iceModel, useFlags, {*x510_vertexMorph}, iceModel->GetMorphMagnitudes()); } diff --git a/Runtime/World/CPatterned.hpp b/Runtime/World/CPatterned.hpp index 5ad14341d..2190af4e5 100644 --- a/Runtime/World/CPatterned.hpp +++ b/Runtime/World/CPatterned.hpp @@ -26,6 +26,7 @@ namespace urde { class CPatternedInfo; class CProjectileInfo; class CPathFindSearch; + using CPatternedTryFunc = void (CPatterned::*)(CStateManager&, int); class CPatterned : public CAi { diff --git a/Runtime/World/CPhysicsActor.hpp b/Runtime/World/CPhysicsActor.hpp index fab806ccf..905aadc5f 100644 --- a/Runtime/World/CPhysicsActor.hpp +++ b/Runtime/World/CPhysicsActor.hpp @@ -21,7 +21,7 @@ struct SMoverData { zeus::CAxisAngle x24_; float x30_mass; - SMoverData(float mass) : x30_mass(mass) {} + explicit SMoverData(float mass) : x30_mass(mass) {} }; struct CMotionState { diff --git a/Runtime/World/CPlayer.cpp b/Runtime/World/CPlayer.cpp index 668ddb2e4..cdc104b0a 100644 --- a/Runtime/World/CPlayer.cpp +++ b/Runtime/World/CPlayer.cpp @@ -185,7 +185,7 @@ constexpr std::array #include "Runtime/CToken.hpp" +#include "Runtime/GuiSys/CStringTable.hpp" #include "Runtime/World/CEntity.hpp" #include "Runtime/World/CHUDMemoParms.hpp" namespace urde { -class CStringTable; class CScriptHUDMemo : public CEntity { public: diff --git a/Runtime/World/CScriptSpecialFunction.cpp b/Runtime/World/CScriptSpecialFunction.cpp index 84d4aae21..3739d03c2 100644 --- a/Runtime/World/CScriptSpecialFunction.cpp +++ b/Runtime/World/CScriptSpecialFunction.cpp @@ -191,7 +191,7 @@ void CScriptSpecialFunction::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId } case ESpecialFunction::MissileStation: { if (msg == EScriptObjectMessage::Action) { - CPlayerState& pState = *mgr.GetPlayerState().get(); + CPlayerState& pState = *mgr.GetPlayerState(); pState.ResetAndIncrPickUp(CPlayerState::EItemType::Missiles, pState.GetItemCapacity(CPlayerState::EItemType::Missiles)); } @@ -199,7 +199,7 @@ void CScriptSpecialFunction::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId } case ESpecialFunction::PowerBombStation: { if (msg == EScriptObjectMessage::Action) { - CPlayerState& pState = *mgr.GetPlayerState().get(); + CPlayerState& pState = *mgr.GetPlayerState(); pState.ResetAndIncrPickUp(CPlayerState::EItemType::PowerBombs, pState.GetItemCapacity(CPlayerState::EItemType::PowerBombs)); } diff --git a/Runtime/World/CScriptSpindleCamera.hpp b/Runtime/World/CScriptSpindleCamera.hpp index 8a494b7a0..8d1a8f1b3 100644 --- a/Runtime/World/CScriptSpindleCamera.hpp +++ b/Runtime/World/CScriptSpindleCamera.hpp @@ -29,7 +29,7 @@ struct SSpindleProperty { float x10_lowIn; float x14_highIn; - SSpindleProperty(CInputStream& in); + explicit SSpindleProperty(CInputStream& in); void FixupAngles() { x8_lowOut = zeus::degToRad(x8_lowOut); xc_highOut = zeus::degToRad(xc_highOut); diff --git a/Runtime/World/CScriptTrigger.cpp b/Runtime/World/CScriptTrigger.cpp index cdb7d8af9..666c990ec 100644 --- a/Runtime/World/CScriptTrigger.cpp +++ b/Runtime/World/CScriptTrigger.cpp @@ -61,11 +61,13 @@ void CScriptTrigger::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CS CScriptTrigger::CObjectTracker* CScriptTrigger::FindObject(TUniqueId id) { auto& inhabitants = GetInhabitants(); - const auto& iter = std::find(inhabitants.begin(), inhabitants.end(), id); + const auto iter = std::find(inhabitants.begin(), inhabitants.end(), CObjectTracker{id}); - if (iter != inhabitants.end()) - return &(*iter); - return nullptr; + if (iter == inhabitants.end()) { + return nullptr; + } + + return &*iter; } void CScriptTrigger::UpdateInhabitants(float dt, CStateManager& mgr) { diff --git a/Runtime/World/CScriptTrigger.hpp b/Runtime/World/CScriptTrigger.hpp index 3fe57b9ac..038ab41f0 100644 --- a/Runtime/World/CScriptTrigger.hpp +++ b/Runtime/World/CScriptTrigger.hpp @@ -41,7 +41,7 @@ public: TUniqueId x0_id; public: - CObjectTracker(TUniqueId id) : x0_id(id) {} + explicit CObjectTracker(TUniqueId id) : x0_id(id) {} TUniqueId GetObjectId() const { return x0_id; } bool operator==(const CObjectTracker& other) const { return x0_id == other.x0_id; } diff --git a/Runtime/World/CScriptVisorFlare.cpp b/Runtime/World/CScriptVisorFlare.cpp index a71b6df82..895d6afcc 100644 --- a/Runtime/World/CScriptVisorFlare.cpp +++ b/Runtime/World/CScriptVisorFlare.cpp @@ -11,11 +11,10 @@ namespace urde { CScriptVisorFlare::CScriptVisorFlare(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, const zeus::CVector3f& pos, CVisorFlare::EBlendMode blendMode, bool b1, float f1, - float f2, float f3, u32 w1, u32 w2, - const std::vector& flares) + float f2, float f3, u32 w1, u32 w2, std::vector flares) : CActor(uid, active, name, info, zeus::CTransform::Translate(pos), CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::NoStepLogic), CActorParameters::None(), kInvalidUniqueId) -, xe8_flare(blendMode, b1, f1, f2, f3, w1, w2, flares) { +, xe8_flare(blendMode, b1, f1, f2, f3, w1, w2, std::move(flares)) { xe6_27_thermalVisorFlags = 2; } diff --git a/Runtime/World/CScriptVisorFlare.hpp b/Runtime/World/CScriptVisorFlare.hpp index 718ccb7d4..f5a6883b1 100644 --- a/Runtime/World/CScriptVisorFlare.hpp +++ b/Runtime/World/CScriptVisorFlare.hpp @@ -12,9 +12,9 @@ class CScriptVisorFlare : public CActor { bool x11c_notInRenderLast = true; public: - CScriptVisorFlare(TUniqueId, std::string_view name, const CEntityInfo& info, bool, const zeus::CVector3f&, - CVisorFlare::EBlendMode blendMode, bool, float, float, float, u32, u32, - const std::vector& flares); + CScriptVisorFlare(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, + const zeus::CVector3f& pos, CVisorFlare::EBlendMode blendMode, bool, float, float, float, u32, u32, + std::vector flares); void Accept(IVisitor& visitor) override; void Think(float, CStateManager& stateMgr) override; diff --git a/Runtime/World/CSnakeWeedSwarm.cpp b/Runtime/World/CSnakeWeedSwarm.cpp index 69630023f..0f5038380 100644 --- a/Runtime/World/CSnakeWeedSwarm.cpp +++ b/Runtime/World/CSnakeWeedSwarm.cpp @@ -276,14 +276,14 @@ void CSnakeWeedSwarm::Think(float dt, CStateManager& mgr) { x140_26_playerTouching = false; } -zeus::CAABox CSnakeWeedSwarm::GetBoidBox() { - const auto& scale = xe8_scale * 0.75f; +zeus::CAABox CSnakeWeedSwarm::GetBoidBox() const { + const auto scale = xe8_scale * 0.75f; return {GetTransform().origin - scale, GetTransform().origin + scale}; } void CSnakeWeedSwarm::FindGround(const CStateManager& mgr) { - const auto& box = GetBoidBox(); - const auto& result = + const auto box = GetBoidBox(); + const auto result = mgr.RayStaticIntersection(box.center(), zeus::skDown, box.max.z() - box.min.z(), skMaterialFilter); if (result.IsValid()) { int ct = GetNumBoidsX() * GetNumBoidsY(); @@ -295,13 +295,13 @@ void CSnakeWeedSwarm::FindGround(const CStateManager& mgr) { } } -int CSnakeWeedSwarm::GetNumBoidsY() { - const auto& box = GetBoidBox(); +int CSnakeWeedSwarm::GetNumBoidsY() const { + const auto box = GetBoidBox(); return static_cast((box.max.y() - box.min.y()) / xf4_boidSpacing) + 1; } -int CSnakeWeedSwarm::GetNumBoidsX() { - const auto& box = GetBoidBox(); +int CSnakeWeedSwarm::GetNumBoidsX() const { + const auto box = GetBoidBox(); return static_cast((box.max.x() - box.min.x()) / xf4_boidSpacing) + 1; } @@ -330,31 +330,31 @@ void CSnakeWeedSwarm::CreateBoids(CStateManager& mgr, int num) { } } -zeus::CVector2i CSnakeWeedSwarm::GetBoidIndex(const zeus::CVector3f& pos) { - const auto& box = GetBoidBox(); +zeus::CVector2i CSnakeWeedSwarm::GetBoidIndex(const zeus::CVector3f& pos) const { + const auto box = GetBoidBox(); return {static_cast((pos.x() - box.min.x()) / xf4_boidSpacing), static_cast((pos.y() - box.min.y()) / xf4_boidSpacing)}; } bool CSnakeWeedSwarm::CreateBoid(const zeus::CVector3f& vec, CStateManager& mgr) { - const auto& pos = vec + zeus::CVector3f(GetBoidOffsetX(vec), GetBoidOffsetY(vec), xf8_height); - const auto& result = mgr.RayStaticIntersection(pos, zeus::skDown, 2.f * xf8_height, skMaterialFilter); + const auto pos = vec + zeus::CVector3f(GetBoidOffsetX(vec), GetBoidOffsetY(vec), xf8_height); + const auto result = mgr.RayStaticIntersection(pos, zeus::skDown, 2.f * xf8_height, skMaterialFilter); if (result.IsValid() && result.GetPlane().normal().dot(zeus::skUp) > x11c_) { - const auto& boidPosition = result.GetPoint() - zeus::CVector3f(0.f, 0.f, x128_distanceBelowGround); - x134_boids.push_back({boidPosition, x110_maxZOffset, x114_speed + x118_speedVariation, - (x124_scaleMax - x120_scaleMin) * mgr.GetActiveRandom()->Float() + x120_scaleMin}); + const auto boidPosition = result.GetPoint() - zeus::CVector3f(0.f, 0.f, x128_distanceBelowGround); + x134_boids.emplace_back(boidPosition, x110_maxZOffset, x114_speed + x118_speedVariation, + (x124_scaleMax - x120_scaleMin) * mgr.GetActiveRandom()->Float() + x120_scaleMin); return true; } return false; } -float CSnakeWeedSwarm::GetBoidOffsetY(const zeus::CVector3f& pos) { - float f = 2.4729404f * pos.y() + 0.3478602f * pos.x() * pos.x(); +float CSnakeWeedSwarm::GetBoidOffsetY(const zeus::CVector3f& pos) const { + const float f = 2.4729404f * pos.y() + 0.3478602f * pos.x() * pos.x(); return xfc_ * (2.f * std::abs(f - std::trunc(f)) - 1.f); } -float CSnakeWeedSwarm::GetBoidOffsetX(const zeus::CVector3f& pos) { - float f = 8.21395f * pos.x() + 0.112869f * pos.y() * pos.y(); +float CSnakeWeedSwarm::GetBoidOffsetX(const zeus::CVector3f& pos) const { + const float f = 8.21395f * pos.x() + 0.112869f * pos.y() * pos.y(); return xfc_ * (2.f * std::abs(f - std::trunc(f)) - 1.f); } diff --git a/Runtime/World/CSnakeWeedSwarm.hpp b/Runtime/World/CSnakeWeedSwarm.hpp index 495187f95..def7ca182 100644 --- a/Runtime/World/CSnakeWeedSwarm.hpp +++ b/Runtime/World/CSnakeWeedSwarm.hpp @@ -80,7 +80,7 @@ private: u16 x1d0_sfx1; u16 x1d2_sfx2; u16 x1d4_sfx3; - CSfxHandle x1d8_sfxHandle = 0; + CSfxHandle x1d8_sfxHandle; TLockedToken x1dc_particleGenDesc; // TLockedToken x1e4_; both assign to x1dc_ std::unique_ptr x1ec_particleGen1; @@ -111,14 +111,14 @@ private: void AllocateSkinnedModels(CStateManager& mgr, CModelData::EWhichModel which); void HandleRadiusDamage(float radius, CStateManager& mgr, const zeus::CVector3f& pos); void FindGround(const CStateManager& mgr); - zeus::CAABox GetBoidBox(); - int GetNumBoidsY(); - int GetNumBoidsX(); + zeus::CAABox GetBoidBox() const; + int GetNumBoidsY() const; + int GetNumBoidsX() const; void CreateBoids(CStateManager& mgr, int num); - zeus::CVector2i GetBoidIndex(const zeus::CVector3f& pos); + zeus::CVector2i GetBoidIndex(const zeus::CVector3f& pos) const; bool CreateBoid(const zeus::CVector3f& vec, CStateManager& mgr); - float GetBoidOffsetY(const zeus::CVector3f& pos); - float GetBoidOffsetX(const zeus::CVector3f& pos); + float GetBoidOffsetY(const zeus::CVector3f& pos) const; + float GetBoidOffsetX(const zeus::CVector3f& pos) const; void AddBoidPosition(const zeus::CVector3f& pos); void CalculateTouchBounds(); void EmitParticles1(const zeus::CVector3f& pos); diff --git a/Runtime/World/CStateMachine.hpp b/Runtime/World/CStateMachine.hpp index 1c2ee71a5..0ddecca84 100644 --- a/Runtime/World/CStateMachine.hpp +++ b/Runtime/World/CStateMachine.hpp @@ -75,7 +75,7 @@ class CStateMachine { std::vector x10_triggers; public: - CStateMachine(CInputStream& in); + explicit CStateMachine(CInputStream& in); s32 GetStateIndex(std::string_view state) const; const std::vector& GetStateVector() const { return x0_states; } diff --git a/Runtime/World/CVisorFlare.cpp b/Runtime/World/CVisorFlare.cpp index 06c7bd13e..1be3c4a63 100644 --- a/Runtime/World/CVisorFlare.cpp +++ b/Runtime/World/CVisorFlare.cpp @@ -27,9 +27,9 @@ std::optional CVisorFlare::LoadFlareDef(CInputStream& in } CVisorFlare::CVisorFlare(EBlendMode blendMode, bool b1, float f1, float f2, float f3, u32 w1, u32 w2, - const std::vector& flares) + std::vector flares) : x0_blendMode(blendMode) -, x4_flareDefs(flares) +, x4_flareDefs(std::move(flares)) , x14_b1(b1) , x18_f1(std::max(f1, FLT_EPSILON)) , x1c_f2(f2) diff --git a/Runtime/World/CVisorFlare.hpp b/Runtime/World/CVisorFlare.hpp index ff70aff6e..b1c084de2 100644 --- a/Runtime/World/CVisorFlare.hpp +++ b/Runtime/World/CVisorFlare.hpp @@ -49,7 +49,7 @@ private: u32 x30_w2; public: - CVisorFlare(EBlendMode blendMode, bool, float, float, float, u32, u32, const std::vector& flares); + CVisorFlare(EBlendMode blendMode, bool, float, float, float, u32, u32, std::vector flares); void Update(float dt, const zeus::CVector3f& pos, const CActor* act, CStateManager& mgr); void Render(const zeus::CVector3f& pos, const CStateManager& mgr) const; static std::optional LoadFlareDef(CInputStream& in); diff --git a/Runtime/World/CWallCrawlerSwarm.cpp b/Runtime/World/CWallCrawlerSwarm.cpp index 5063552a0..033630722 100644 --- a/Runtime/World/CWallCrawlerSwarm.cpp +++ b/Runtime/World/CWallCrawlerSwarm.cpp @@ -1,5 +1,7 @@ #include "Runtime/World/CWallCrawlerSwarm.hpp" +#include + #include "Runtime/CSimplePool.hpp" #include "Runtime/CStateManager.hpp" #include "Runtime/GameGlobalObjects.hpp" @@ -91,23 +93,29 @@ CWallCrawlerSwarm::CWallCrawlerSwarm(TUniqueId uid, bool active, std::string_vie x4b0_modelDatas.emplace_back(std::make_unique(launchAnimRes)); x4b0_modelDatas.emplace_back(std::make_unique(animRes)); if (aParams.GetXRayAssets().first.IsValid()) { - for (int i = 0; i < 9; ++i) + for (size_t i = 0; i < 9; ++i) { x4b0_modelDatas[i]->SetXRayModel(aParams.GetXRayAssets()); + } x560_26_modelAssetDirty = true; } if (aParams.GetThermalAssets().first.IsValid()) { - for (int i = 0; i < 9; ++i) + for (size_t i = 0; i < 9; ++i) { x4b0_modelDatas[i]->SetInfraModel(aParams.GetThermalAssets()); + } x560_26_modelAssetDirty = true; } - if (part1.IsValid()) + if (part1.IsValid()) { x4f0_particleDescs.push_back(g_SimplePool->GetObj({FOURCC('PART'), part1})); - if (part2.IsValid()) + } + if (part2.IsValid()) { x4f0_particleDescs.push_back(g_SimplePool->GetObj({FOURCC('PART'), part2})); - if (part3.IsValid()) + } + if (part3.IsValid()) { x4f0_particleDescs.push_back(g_SimplePool->GetObj({FOURCC('PART'), part3})); - if (part4.IsValid()) + } + if (part4.IsValid()) { x4f0_particleDescs.push_back(g_SimplePool->GetObj({FOURCC('PART'), part4})); + } for (const auto& t : x4f0_particleDescs) { x524_particleGens.emplace_back(new CElementGen(t)); x524_particleGens.back()->SetParticleEmission(false); @@ -118,12 +126,12 @@ void CWallCrawlerSwarm::Accept(IVisitor& visitor) { visitor.Visit(this); } void CWallCrawlerSwarm::AllocateSkinnedModels(CStateManager& mgr, CModelData::EWhichModel which) { //x430_.clear(); - for (int i = 0; i < 9; ++i) { + for (size_t i = 0; i < 9; ++i) { //x430_.push_back(x4b0_[i]->PickAnimatedModel(which).Clone()); x4b0_modelDatas[i]->EnableLooping(true); - x4b0_modelDatas[i]->AdvanceAnimation( - x4b0_modelDatas[i]->GetAnimationData()->GetAnimTimeRemaining("Whole Body"sv) * (i * 0.0625f), - mgr, x4_areaId, true); + x4b0_modelDatas[i]->AdvanceAnimation(x4b0_modelDatas[i]->GetAnimationData()->GetAnimTimeRemaining("Whole Body"sv) * + (float(i) * 0.0625f), + mgr, x4_areaId, true); } //x430_.push_back(x4b0_.back()->PickAnimatedModel(which).Clone()); x4dc_whichModel = which; @@ -131,17 +139,22 @@ void CWallCrawlerSwarm::AllocateSkinnedModels(CStateManager& mgr, CModelData::EW void CWallCrawlerSwarm::AddDoorRepulsors(CStateManager& mgr) { size_t doorCount = 0; - for (CEntity* ent : mgr.GetPhysicsActorObjectList()) { - if (TCastToPtr door = ent) - if (door->GetAreaIdAlways() == x4_areaId) - ++doorCount; - } - x4e0_doorRepulsors.reserve(doorCount); - for (CEntity* ent : mgr.GetPhysicsActorObjectList()) { - if (TCastToPtr door = ent) { + for (const CEntity* ent : mgr.GetPhysicsActorObjectList()) { + if (const TCastToConstPtr door = ent) { if (door->GetAreaIdAlways() == x4_areaId) { - if (auto tb = door->GetTouchBounds()) + ++doorCount; + } + } + } + + x4e0_doorRepulsors.reserve(doorCount); + + for (const CEntity* ent : mgr.GetPhysicsActorObjectList()) { + if (const TCastToConstPtr door = ent) { + if (door->GetAreaIdAlways() == x4_areaId) { + if (const auto tb = door->GetTouchBounds()) { x4e0_doorRepulsors.emplace_back(tb->center(), (tb->min - tb->max).magnitude() * 0.75f); + } } } } @@ -152,8 +165,9 @@ void CWallCrawlerSwarm::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId send switch (msg) { case EScriptObjectMessage::Registered: x108_boids.reserve(size_t(x548_numBoids)); - for (int i = 0; i < x548_numBoids; ++i) + for (int i = 0; i < x548_numBoids; ++i) { x108_boids.emplace_back(zeus::CTransform(), i); + } AllocateSkinnedModels(mgr, CModelData::EWhichModel::Normal); AddDoorRepulsors(mgr); CreateShadow(false); @@ -164,41 +178,44 @@ void CWallCrawlerSwarm::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId send } void CWallCrawlerSwarm::UpdateParticles(float dt) { - for (auto& p : x524_particleGens) + for (auto& p : x524_particleGens) { p->Update(dt); + } } int CWallCrawlerSwarm::SelectLockOnIdx(CStateManager& mgr) const { - zeus::CTransform fpCamXf = mgr.GetCameraManager()->GetFirstPersonCamera()->GetTransform(); + const zeus::CTransform fpCamXf = mgr.GetCameraManager()->GetFirstPersonCamera()->GetTransform(); if (x42c_lockOnIdx != -1) { const CBoid& b = x108_boids[x42c_lockOnIdx]; if (b.GetActive()) { zeus::CVector3f dir = b.GetTranslation() - fpCamXf.origin; - float mag = dir.magnitude(); + const float mag = dir.magnitude(); dir = dir / mag; if (fpCamXf.basis[1].dot(dir) > 0.92388f) { - if (mgr.RayStaticIntersection(fpCamXf.origin, dir, mag, - CMaterialFilter::MakeInclude(EMaterialTypes::Solid)).IsInvalid()) + if (mgr.RayStaticIntersection(fpCamXf.origin, dir, mag, CMaterialFilter::MakeInclude(EMaterialTypes::Solid)) + .IsInvalid()) { return x42c_lockOnIdx; + } } } return -1; } int ret = -1; - float omtd = mgr.GetPlayer().GetOrbitMaxTargetDistance(mgr); - float omtdSq = omtd * omtd; + const float omtd = mgr.GetPlayer().GetOrbitMaxTargetDistance(mgr); + const float omtdSq = omtd * omtd; float maxDot = 0.5f; - for (int i = 0; i < x108_boids.size(); ++i) { + for (size_t i = 0; i < x108_boids.size(); ++i) { const CBoid& b = x108_boids[i]; if (b.GetActive()) { zeus::CVector3f delta = b.GetTranslation() - fpCamXf.origin; - if (delta.magSquared() > omtdSq) + if (delta.magSquared() > omtdSq) { continue; + } if (delta.canBeNormalized()) { - float thisDot = fpCamXf.basis[1].dot(delta.normalized()); + const float thisDot = fpCamXf.basis[1].dot(delta.normalized()); if (thisDot > maxDot) { - ret = i; + ret = static_cast(i); maxDot = thisDot; } } @@ -208,24 +225,26 @@ int CWallCrawlerSwarm::SelectLockOnIdx(CStateManager& mgr) const { } zeus::CAABox CWallCrawlerSwarm::GetBoundingBox() const { - zeus::CVector3f he = x118_boundingBoxExtent * 0.75f; + const zeus::CVector3f he = x118_boundingBoxExtent * 0.75f; return zeus::CAABox(-he, he).getTransformedAABox(x34_transform); } TUniqueId CWallCrawlerSwarm::GetWaypointForState(EScriptObjectState state, CStateManager& mgr) const { for (const auto& c : GetConnectionList()) { - if (c.x0_state == state && c.x4_msg == EScriptObjectMessage::Follow) + if (c.x0_state == state && c.x4_msg == EScriptObjectMessage::Follow) { return mgr.GetIdForScript(c.x8_objId); + } } return kInvalidUniqueId; } bool CWallCrawlerSwarm::PointOnSurface(const CCollisionSurface& surf, const zeus::CVector3f& pos, const zeus::CPlane& plane) const { - zeus::CVector3f projPt = ProjectPointToPlane(pos, surf.GetVert(0), plane.normal()); + const zeus::CVector3f projPt = ProjectPointToPlane(pos, surf.GetVert(0), plane.normal()); for (int i = 0; i < 3; ++i) { - if (plane.normal().dot((projPt - surf.GetVert(i)).cross(surf.GetVert((i + 2) % 3) - surf.GetVert(i))) < 0.f) + if (plane.normal().dot((projPt - surf.GetVert(i)).cross(surf.GetVert((i + 2) % 3) - surf.GetVert(i))) < 0.f) { return false; + } } return true; } @@ -233,20 +252,21 @@ bool CWallCrawlerSwarm::PointOnSurface(const CCollisionSurface& surf, const zeus bool CWallCrawlerSwarm::FindBestSurface(const CAreaCollisionCache& ccache, const zeus::CVector3f& pos, float radius, CCollisionSurface& out) const { bool ret = false; - float radiusSq = radius * radius; + const float radiusSq = radius * radius; zeus::CSphere sphere(pos, radius); for (const auto& c : ccache) { for (const auto& n : c) { if (CCollidableSphere::Sphere_AABox_Bool(sphere, n.GetBoundingBox())) { - auto triList = n.GetTriangleArray(); + const auto triList = n.GetTriangleArray(); for (int i = 0; i < triList.GetSize(); ++i) { CCollisionSurface surf = n.GetOwner().GetMasterListTriangle(triList.GetAt(i)); - zeus::CPlane plane = surf.GetPlane(); - float distSq = std::fabs(plane.pointToPlaneDist(pos)); + const zeus::CPlane plane = surf.GetPlane(); + const float distSq = std::fabs(plane.pointToPlaneDist(pos)); if (distSq < radiusSq && PointOnSurface(surf, pos, plane)) { float dist = 0.f; - if (distSq != 0.f) + if (distSq != 0.f) { dist = std::sqrt(distSq); + } sphere.radius = dist; out = surf; ret = true; @@ -260,40 +280,45 @@ bool CWallCrawlerSwarm::FindBestSurface(const CAreaCollisionCache& ccache, const CCollisionSurface CWallCrawlerSwarm::FindBestCollisionInBox(CStateManager& mgr, const zeus::CVector3f& wpPos) const { CCollisionSurface ret(zeus::skRight, zeus::skForward, zeus::skUp, 0xffffffff); - zeus::CVector3f aabbExtents = GetBoundingBox().extents(); + const zeus::CVector3f aabbExtents = GetBoundingBox().extents(); float f25 = 0.1f; while (f25 < 1.f) { - zeus::CVector3f scaledExtents = aabbExtents * f25; + const zeus::CVector3f scaledExtents = aabbExtents * f25; CAreaCollisionCache ccache(zeus::CAABox(wpPos - scaledExtents, wpPos + scaledExtents)); CGameCollision::BuildAreaCollisionCache(mgr, ccache); - if (FindBestSurface(ccache, wpPos, 2.f * scaledExtents.magnitude(), ret)) + if (FindBestSurface(ccache, wpPos, 2.f * scaledExtents.magnitude(), ret)) { return ret; + } f25 += 0.1f; } return ret; } static zeus::CTransform LookAt(const zeus::CUnitVector3f& a, const zeus::CUnitVector3f& b, const zeus::CRelAngle& ang) { - float dot = a.dot(b); - if (zeus::close_enough(dot, 1.f)) + const float dot = a.dot(b); + if (zeus::close_enough(dot, 1.f)) { return zeus::CTransform(); - if (dot > -0.99981f) + } + if (dot > -0.99981f) { return zeus::CQuaternion::clampedRotateTo(a, b, ang).toTransform(); - if (a != zeus::skRight && b != zeus::skRight) + } + if (a != zeus::skRight && b != zeus::skRight) { return zeus::CQuaternion::fromAxisAngle(a.cross(zeus::skRight), ang).toTransform(); + } return zeus::CQuaternion::fromAxisAngle(a.cross(zeus::skUp), ang).toTransform(); } void CWallCrawlerSwarm::CreateBoid(CStateManager& mgr, int idx) { //zeus::CAABox aabb = GetBoundingBox(); - TUniqueId wpId = GetWaypointForState(EScriptObjectState::Patrol, mgr); + const TUniqueId wpId = GetWaypointForState(EScriptObjectState::Patrol, mgr); if (TCastToConstPtr wp = mgr.GetObjectById(wpId)) { - CCollisionSurface surf = FindBestCollisionInBox(mgr, wp->GetTranslation()); - x108_boids[idx].Transform() = zeus::CTransform::Translate( - ProjectPointToPlane(wp->GetTranslation(), surf.GetVert(0), surf.GetNormal()) + surf.GetNormal() * x374_boidRadius); + const CCollisionSurface surf = FindBestCollisionInBox(mgr, wp->GetTranslation()); + x108_boids[idx].Transform() = + zeus::CTransform::Translate(ProjectPointToPlane(wp->GetTranslation(), surf.GetVert(0), surf.GetNormal()) + + surf.GetNormal() * x374_boidRadius); if (zeus::close_enough(zeus::skUp.dot(surf.GetNormal()), -1.f)) { - x108_boids[idx].Transform().setRotation(zeus::CTransform( - zeus::skRight, zeus::skBack, zeus::skDown, zeus::skZero3f)); + x108_boids[idx].Transform().setRotation( + zeus::CTransform(zeus::skRight, zeus::skBack, zeus::skDown, zeus::skZero3f)); } else { x108_boids[idx].Transform().setRotation(LookAt(zeus::skUp, surf.GetNormal(), M_PIF)); } @@ -310,30 +335,33 @@ void CWallCrawlerSwarm::CreateBoid(CStateManager& mgr, int idx) { void CWallCrawlerSwarm::ExplodeBoid(CBoid& boid, CStateManager& mgr) { KillBoid(boid, mgr, 0.f, 1.f); mgr.ApplyDamageToWorld(GetUniqueId(), *this, boid.GetTranslation(), x3a0_scarabExplodeDamage, - CMaterialFilter::MakeInclude({EMaterialTypes::Player})); + CMaterialFilter::MakeInclude({EMaterialTypes::Player})); } void CWallCrawlerSwarm::SetExplodeTimers(const zeus::CVector3f& pos, float radius, float minTime, float maxTime) { - float radiusSq = radius * radius; - float range = maxTime - minTime; + const float radiusSq = radius * radius; + const float range = maxTime - minTime; + for (auto& b : x108_boids) { if (b.GetActive() && b.x48_timeToDie <= 0.f) { - float dist = (b.GetTranslation() - pos).magSquared(); + const float dist = (b.GetTranslation() - pos).magSquared(); if (dist < radiusSq) { - float fac = dist / radiusSq * range + minTime; - if (b.x4c_timeToExplode > fac || b.x4c_timeToExplode == 0.f) + const float fac = dist / radiusSq * range + minTime; + if (b.x4c_timeToExplode > fac || b.x4c_timeToExplode == 0.f) { b.x4c_timeToExplode = fac; + } } } } } CWallCrawlerSwarm::CBoid* CWallCrawlerSwarm::GetListAt(const zeus::CVector3f& pos) { - zeus::CAABox aabb = GetBoundingBox(); - zeus::CVector3f ints = (pos - aabb.min) / ((aabb.max - aabb.min) / 5.f); - int idx = int(ints.x()) + int(ints.y()) * 5 + int(ints.z()) * 25; - if (idx < 0 || idx >= 125) + const zeus::CAABox aabb = GetBoundingBox(); + const zeus::CVector3f ints = (pos - aabb.min) / ((aabb.max - aabb.min) / 5.f); + const int idx = int(ints.x()) + int(ints.y()) * 5 + int(ints.z()) * 25; + if (idx < 0 || idx >= 125) { return x360_outlierBoidList; + } return x168_partitionedBoidLists[idx]; } @@ -341,48 +369,54 @@ void CWallCrawlerSwarm::BuildBoidNearList(const CBoid& boid, float radius, rstl::reserved_vector& nearList) { CBoid* b = GetListAt(boid.GetTranslation()); while (b && nearList.size() < 50) { - float distSq = (b->GetTranslation() - boid.GetTranslation()).magSquared(); - if (distSq != 0.f && distSq < radius) + const float distSq = (b->GetTranslation() - boid.GetTranslation()).magSquared(); + if (distSq != 0.f && distSq < radius) { nearList.push_back(b); + } b = b->x44_next; } } void CWallCrawlerSwarm::ApplySeparation(const CBoid& boid, const rstl::reserved_vector& nearList, zeus::CVector3f& aheadVec) const { - if (nearList.empty()) + if (nearList.empty()) { return; + } + float minDist = FLT_MAX; zeus::CVector3f pos; - for (CBoid* b : nearList) { - float dist = (boid.GetTranslation() - b->GetTranslation()).magSquared(); + for (const CBoid* b : nearList) { + const float dist = (boid.GetTranslation() - b->GetTranslation()).magSquared(); if (dist != 0.f && dist < minDist) { minDist = dist; pos = b->GetTranslation(); } } + ApplySeparation(boid, pos, x13c_separationRadius, x148_separationMagnitude, aheadVec); } -void CWallCrawlerSwarm::ApplySeparation(const CBoid& boid, const zeus::CVector3f& separateFrom, - float separationRadius, float separationMagnitude, - zeus::CVector3f& aheadVec) const { - zeus::CVector3f delta = boid.GetTranslation() - separateFrom; - if (delta.canBeNormalized()) { - float deltaDistSq = delta.magSquared(); - float capDeltaDistSq = separationRadius * separationRadius; - if (deltaDistSq < capDeltaDistSq) - aheadVec += (1.f - deltaDistSq / capDeltaDistSq) * delta.normalized() * separationMagnitude; +void CWallCrawlerSwarm::ApplySeparation(const CBoid& boid, const zeus::CVector3f& separateFrom, float separationRadius, + float separationMagnitude, zeus::CVector3f& aheadVec) const { + const zeus::CVector3f delta = boid.GetTranslation() - separateFrom; + if (!delta.canBeNormalized()) { + return; + } + + const float deltaDistSq = delta.magSquared(); + const float capDeltaDistSq = separationRadius * separationRadius; + if (deltaDistSq < capDeltaDistSq) { + aheadVec += (1.f - deltaDistSq / capDeltaDistSq) * delta.normalized() * separationMagnitude; } } void CWallCrawlerSwarm::ScatterScarabBoid(CBoid& boid, CStateManager& mgr) const { - zeus::CVector3f oldDir = boid.Transform().basis[1]; + const zeus::CVector3f oldDir = boid.GetTransform().basis[1]; boid.Transform().setRotation(zeus::CTransform()); - boid.Transform() = LookAt(boid.Transform().basis[1], oldDir, M_PIF).multiplyIgnoreTranslation(boid.Transform()); + boid.Transform() = LookAt(boid.GetTransform().basis[1], oldDir, M_PIF).multiplyIgnoreTranslation(boid.GetTransform()); boid.x30_velocity = zeus::skZero3f; - float angle = mgr.GetActiveRandom()->Float() * (2.f * M_PIF); - float mag = mgr.GetActiveRandom()->Float() * x158_scarabScatterXYVelocity; + const float angle = mgr.GetActiveRandom()->Float() * (2.f * M_PIF); + const float mag = mgr.GetActiveRandom()->Float() * x158_scarabScatterXYVelocity; boid.x30_velocity.x() = mag * std::cos(angle); boid.x30_velocity.y() = mag * std::sin(angle); boid.x80_26_launched = true; @@ -391,8 +425,8 @@ void CWallCrawlerSwarm::ScatterScarabBoid(CBoid& boid, CStateManager& mgr) const } void CWallCrawlerSwarm::MoveToWayPoint(CBoid& boid, CStateManager& mgr, zeus::CVector3f& aheadVec) const { - if (TCastToPtr wp = mgr.ObjectById(boid.x3c_targetWaypoint)) { - CScriptWaypoint* useWp = wp.GetPtr(); + if (const TCastToConstPtr wp = mgr.ObjectById(boid.x3c_targetWaypoint)) { + const CScriptWaypoint* useWp = wp.GetPtr(); if ((useWp->GetTranslation() - boid.GetTranslation()).magSquared() < x164_waypointGoalRadius * x164_waypointGoalRadius) { boid.x3c_targetWaypoint = useWp->NextWaypoint(mgr); @@ -404,7 +438,7 @@ void CWallCrawlerSwarm::MoveToWayPoint(CBoid& boid, CStateManager& mgr, zeus::CV return; } } else { - useWp = TCastToPtr(mgr.ObjectById(boid.x3c_targetWaypoint)).GetPtr(); + useWp = TCastToConstPtr(mgr.ObjectById(boid.x3c_targetWaypoint)).GetPtr(); } } aheadVec += (useWp->GetTranslation() - boid.GetTranslation()).normalized() * x14c_moveToWaypointWeight; @@ -413,60 +447,71 @@ void CWallCrawlerSwarm::MoveToWayPoint(CBoid& boid, CStateManager& mgr, zeus::CV void CWallCrawlerSwarm::ApplyCohesion(const CBoid& boid, const rstl::reserved_vector& nearList, zeus::CVector3f& aheadVec) const { - if (nearList.empty()) + if (nearList.empty()) { return; + } + zeus::CVector3f avg; - for (CBoid* b : nearList) + for (const CBoid* b : nearList) { avg += b->GetTranslation(); + } + avg = avg / float(nearList.size()); ApplyCohesion(boid, avg, x13c_separationRadius, x140_cohesionMagnitude, aheadVec); } -void CWallCrawlerSwarm::ApplyCohesion(const CBoid& boid, const zeus::CVector3f& cohesionFrom, - float cohesionRadius, float cohesionMagnitude, - zeus::CVector3f& aheadVec) const { - zeus::CVector3f delta = cohesionFrom - boid.GetTranslation(); - if (delta.canBeNormalized()) { - float distSq = delta.magSquared(); - float capDistSq = cohesionRadius * cohesionRadius; - aheadVec += ((distSq > capDistSq) ? 1.f : distSq / capDistSq) * delta.normalized() * cohesionMagnitude; +void CWallCrawlerSwarm::ApplyCohesion(const CBoid& boid, const zeus::CVector3f& cohesionFrom, float cohesionRadius, + float cohesionMagnitude, zeus::CVector3f& aheadVec) const { + const zeus::CVector3f delta = cohesionFrom - boid.GetTranslation(); + if (!delta.canBeNormalized()) { + return; } + + const float distSq = delta.magSquared(); + const float capDistSq = cohesionRadius * cohesionRadius; + aheadVec += ((distSq > capDistSq) ? 1.f : distSq / capDistSq) * delta.normalized() * cohesionMagnitude; } void CWallCrawlerSwarm::ApplyAlignment(const CBoid& boid, const rstl::reserved_vector& nearList, zeus::CVector3f& aheadVec) const { - if (nearList.empty()) + if (nearList.empty()) { return; + } + zeus::CVector3f avg; - for (CBoid* b : nearList) - avg += b->Transform().basis[1]; + for (const CBoid* b : nearList) { + avg += b->GetTransform().basis[1]; + } + avg = avg / float(nearList.size()); aheadVec += zeus::CVector3f::getAngleDiff(boid.GetTransform().basis[1], avg) / M_PIF * (avg * x144_alignmentWeight); } -void CWallCrawlerSwarm::ApplyAttraction(const CBoid& boid, const zeus::CVector3f& attractTo, - float attractionRadius, float attractionMagnitude, - zeus::CVector3f& aheadVec) const { - zeus::CVector3f delta = attractTo - boid.GetTranslation(); - if (delta.canBeNormalized()) { - float distSq = delta.magSquared(); - float capDistSq = attractionRadius * attractionRadius; - aheadVec += ((distSq > capDistSq) ? 0.f : (1.f - distSq / capDistSq)) * delta.normalized() * attractionMagnitude; +void CWallCrawlerSwarm::ApplyAttraction(const CBoid& boid, const zeus::CVector3f& attractTo, float attractionRadius, + float attractionMagnitude, zeus::CVector3f& aheadVec) const { + const zeus::CVector3f delta = attractTo - boid.GetTranslation(); + if (!delta.canBeNormalized()) { + return; } + + const float distSq = delta.magSquared(); + const float capDistSq = attractionRadius * attractionRadius; + aheadVec += ((distSq > capDistSq) ? 0.f : (1.f - distSq / capDistSq)) * delta.normalized() * attractionMagnitude; } void CWallCrawlerSwarm::UpdateBoid(const CAreaCollisionCache& ccache, CStateManager& mgr, float dt, CBoid& boid) { if (boid.x80_27_scarabExplodeTimerEnabled) { if (x558_flavor == EFlavor::Scarab && boid.x4c_timeToExplode > 0.f) { boid.x4c_timeToExplode -= 2.f * dt; - if (boid.x4c_timeToExplode <= 0.f) + if (boid.x4c_timeToExplode <= 0.f) { ExplodeBoid(boid, mgr); + } } } else if (boid.x80_26_launched) { - float radius = 2.f * x374_boidRadius; - float boidMag = boid.x30_velocity.magnitude(); + const float radius = 2.f * x374_boidRadius; + const float boidMag = boid.x30_velocity.magnitude(); float f20 = boidMag * dt; - zeus::CVector3f f25 = (-boid.x30_velocity / boidMag) * x374_boidRadius; + const zeus::CVector3f f25 = (-boid.x30_velocity / boidMag) * x374_boidRadius; zeus::CVector3f f28 = boid.GetTranslation(); bool found = false; while (f20 >= 0.f && !found) { @@ -474,12 +519,12 @@ void CWallCrawlerSwarm::UpdateBoid(const CAreaCollisionCache& ccache, CStateMana if (FindBestSurface(ccache, boid.x30_velocity * dt * 1.5f + f28, radius, surf) && boid.x7c_remainingLaunchNotOnSurfaceFrames == 0) { if (x558_flavor != EFlavor::Scarab) { - boid.Transform() = - LookAt(boid.Transform().basis[2], surf.GetNormal(), M_PIF).multiplyIgnoreTranslation(boid.Transform()); + boid.Transform() = LookAt(boid.GetTransform().basis[2], surf.GetNormal(), M_PIF) + .multiplyIgnoreTranslation(boid.GetTransform()); } - auto plane = surf.GetPlane(); + const auto plane = surf.GetPlane(); boid.Translation() += - -(plane.pointToPlaneDist(boid.GetTranslation()) - x374_boidRadius - 0.01f) * plane.normal(); + -(plane.pointToPlaneDist(boid.GetTranslation()) - x374_boidRadius - 0.01f) * plane.normal(); boid.x7c_framesNotOnSurface = 0; boid.x80_26_launched = false; if (x558_flavor == EFlavor::Scarab) { @@ -493,23 +538,26 @@ void CWallCrawlerSwarm::UpdateBoid(const CAreaCollisionCache& ccache, CStateMana f28 += f25; } if (!found) { - boid.x30_velocity += zeus::CVector3f(0.f, 0.f, -(x558_flavor == EFlavor::Scarab ? 3.f * CPhysicsActor::GravityConstant() : CPhysicsActor::GravityConstant())) * dt; - if (boid.x7c_remainingLaunchNotOnSurfaceFrames) + boid.x30_velocity += zeus::CVector3f(0.f, 0.f, + -(x558_flavor == EFlavor::Scarab ? 3.f * CPhysicsActor::GravityConstant() + : CPhysicsActor::GravityConstant())) * + dt; + if (boid.x7c_remainingLaunchNotOnSurfaceFrames) { boid.x7c_remainingLaunchNotOnSurfaceFrames -= 1; + } } } else if (boid.x7c_framesNotOnSurface >= 30) { boid.x80_24_active = false; } else { - float radius = 2.f * x374_boidRadius; + const float radius = 2.f * x374_boidRadius; bool found = false; CCollisionSurface surf(zeus::skRight, zeus::skForward, zeus::skUp, 0xffffffff); if (FindBestSurface(ccache, boid.GetTranslation() + boid.x30_velocity * dt * 1.5f, radius, surf)) { boid.x50_surface = surf; - boid.Transform() = - LookAt(boid.Transform().basis[2], surf.GetNormal(), zeus::degToRad(180.f * dt)). - multiplyIgnoreTranslation(boid.Transform()); - auto plane = surf.GetPlane(); - float dist = plane.pointToPlaneDist(boid.GetTranslation()); + boid.Transform() = LookAt(boid.GetTransform().basis[2], surf.GetNormal(), zeus::degToRad(180.f * dt)) + .multiplyIgnoreTranslation(boid.GetTransform()); + const auto plane = surf.GetPlane(); + const float dist = plane.pointToPlaneDist(boid.GetTranslation()); if (dist <= 1.5f * x374_boidRadius) { boid.Translation() += -(dist - x374_boidRadius - 0.01f) * plane.normal(); boid.x7c_framesNotOnSurface = 0; @@ -517,21 +565,21 @@ void CWallCrawlerSwarm::UpdateBoid(const CAreaCollisionCache& ccache, CStateMana } } if (!found) { - boid.Transform() = - LookAt(boid.Transform().basis[2], boid.Transform().basis[1], - boid.x30_velocity.magnitude() / x374_boidRadius * dt). - multiplyIgnoreTranslation(boid.Transform()); + boid.Transform() = LookAt(boid.GetTransform().basis[2], boid.GetTransform().basis[1], + boid.x30_velocity.magnitude() / x374_boidRadius * dt) + .multiplyIgnoreTranslation(boid.GetTransform()); boid.x7c_framesNotOnSurface += 1; } rstl::reserved_vector nearList; BuildBoidNearList(boid, x13c_separationRadius, nearList); - zeus::CVector3f aheadVec = boid.Transform().basis[1] * 0.3f; + zeus::CVector3f aheadVec = boid.GetTransform().basis[1] * 0.3f; for (int r26 = 0; r26 < 8; ++r26) { switch (r26) { case 0: - for (auto& rep : x4e0_doorRepulsors) { - if ((rep.x0_center - boid.GetTranslation()).magSquared() < rep.xc_mag * rep.xc_mag) + for (const auto& rep : x4e0_doorRepulsors) { + if ((rep.x0_center - boid.GetTranslation()).magSquared() < rep.xc_mag * rep.xc_mag) { ApplySeparation(boid, rep.x0_center, rep.xc_mag, 4.5f, aheadVec); + } } break; case 4: @@ -553,38 +601,41 @@ void CWallCrawlerSwarm::UpdateBoid(const CAreaCollisionCache& ccache, CStateMana default: break; } - if (aheadVec.magSquared() >= 9.f) + if (aheadVec.magSquared() >= 9.f) { break; + } } - boid.Transform() = LookAt(boid.Transform().basis[1], - ProjectVectorToPlane(aheadVec, boid.Transform().basis[2]).normalized(), M_PIF * dt). - multiplyIgnoreTranslation(boid.Transform()); + boid.Transform() = LookAt(boid.GetTransform().basis[1], + ProjectVectorToPlane(aheadVec, boid.GetTransform().basis[2]).normalized(), M_PIF * dt) + .multiplyIgnoreTranslation(boid.GetTransform()); } } void CWallCrawlerSwarm::LaunchBoid(CBoid& boid, const zeus::CVector3f& dir) { - zeus::CVector3f pos = boid.GetTranslation(); + const zeus::CVector3f pos = boid.GetTranslation(); static float skAttackTime = std::sqrt(2.5f / CPhysicsActor::GravityConstant()) * 2.f; static float skAttackVelocity = 15.f / skAttackTime; zeus::CVector3f deltaFlat = dir - pos; - float deltaZ = deltaFlat.z(); + const float deltaZ = deltaFlat.z(); deltaFlat.z() = 0.f; - float deltaMag = deltaFlat.magnitude(); + const float deltaMag = deltaFlat.magnitude(); boid.Transform().setRotation(zeus::CTransform()); - boid.Transform() = - LookAt(boid.Transform().basis[1], deltaFlat.normalized(), M_PIF).multiplyIgnoreTranslation(boid.Transform()); - zeus::CVector3f vec(skAttackVelocity * boid.Transform().basis[1].toVec2f(), 0.5f * skAttackVelocity); + boid.Transform() = LookAt(boid.GetTransform().basis[1], deltaFlat.normalized(), M_PIF) + .multiplyIgnoreTranslation(boid.GetTransform()); + zeus::CVector3f vec(skAttackVelocity * boid.GetTransform().basis[1].toVec2f(), 0.5f * skAttackVelocity); if (deltaMag > FLT_EPSILON) { deltaFlat = deltaFlat / deltaMag; - float dot = deltaFlat.dot(vec); + const float dot = deltaFlat.dot(vec); if (dot > FLT_EPSILON) { - bool r29 = deltaZ < 0.f; + const bool r29 = deltaZ < 0.f; float _12c, _130; float f25 = 0.f; - if (CSteeringBehaviors::SolveQuadratic(-CPhysicsActor::GravityConstant(), vec.z(), -deltaZ, _12c, _130)) + if (CSteeringBehaviors::SolveQuadratic(-CPhysicsActor::GravityConstant(), vec.z(), -deltaZ, _12c, _130)) { f25 = r29 ? _130 : _12c; - if (!r29) + } + if (!r29) { f25 += deltaMag / dot; + } if (f25 < 10.f) { vec.x() = deltaMag / f25 * deltaFlat.x() * 0.6f; vec.y() = deltaMag / f25 * deltaFlat.y() * 0.6f; @@ -598,14 +649,14 @@ void CWallCrawlerSwarm::LaunchBoid(CBoid& boid, const zeus::CVector3f& dir) { CSfxManager::AddEmitter(x55c_launchSfx, pos, zeus::skZero3f, true, false, 0x7f, x4_areaId); } -static const int kParticleCounts[] = {8, 2, 0, 0}; - void CWallCrawlerSwarm::AddParticle(const zeus::CTransform& xf) { - int i = 0; + static constexpr std::array particleCounts{8, 2, 0, 0}; + + size_t i = 0; for (auto& p : x524_particleGens) { p->SetParticleEmission(true); p->SetTranslation(xf.origin); - p->ForceParticleCreation(kParticleCounts[i]); + p->ForceParticleCreation(particleCounts[i]); p->SetParticleEmission(false); ++i; } @@ -613,29 +664,33 @@ void CWallCrawlerSwarm::AddParticle(const zeus::CTransform& xf) { void CWallCrawlerSwarm::KillBoid(CBoid& boid, CStateManager& mgr, float deathRattleChance, float deadChance) { x130_lastKilledOffset = boid.GetTranslation(); - AddParticle(boid.Transform()); + AddParticle(boid.GetTransform()); boid.x80_24_active = false; - float sendDeadRoll = mgr.GetActiveRandom()->Float(); - float sendDeathRattleRoll = mgr.GetActiveRandom()->Float(); - if (sendDeathRattleRoll < deathRattleChance) + + const float sendDeadRoll = mgr.GetActiveRandom()->Float(); + const float sendDeathRattleRoll = mgr.GetActiveRandom()->Float(); + if (sendDeathRattleRoll < deathRattleChance) { SendScriptMsgs(EScriptObjectState::DeathRattle, mgr, EScriptObjectMessage::None); - if (sendDeadRoll < deadChance) + } + if (sendDeadRoll < deadChance) { SendScriptMsgs(EScriptObjectState::Dead, mgr, EScriptObjectMessage::None); + } } void CWallCrawlerSwarm::UpdatePartition() { x168_partitionedBoidLists.clear(); x168_partitionedBoidLists.resize(125); x360_outlierBoidList = nullptr; - zeus::CAABox aabb = GetBoundingBox(); - zeus::CVector3f vec = (aabb.max - aabb.min) / 5.f; + + const zeus::CAABox aabb = GetBoundingBox(); + const zeus::CVector3f vec = (aabb.max - aabb.min) / 5.f; for (auto& b : x108_boids) { if (b.GetActive()) { - zeus::CVector3f divVec = (b.Translation() - aabb.min) / vec; - int xIdx = int(divVec.x()); - int yIdx = int(divVec.y()); - int zIdx = int(divVec.z()); - int idx = xIdx + yIdx * 5 + zIdx * 25; + const zeus::CVector3f divVec = (b.GetTranslation() - aabb.min) / vec; + const int xIdx = int(divVec.x()); + const int yIdx = int(divVec.y()); + const int zIdx = int(divVec.z()); + const int idx = xIdx + yIdx * 5 + zIdx * 25; if (idx < 0 || idx >= 125 || xIdx < 0 || xIdx >= 5 || yIdx < 0 || yIdx >= 5 || zIdx < 0 || zIdx >= 5) { b.x44_next = x360_outlierBoidList; x360_outlierBoidList = &b; @@ -653,8 +708,8 @@ zeus::CVector3f CWallCrawlerSwarm::FindClosestCell(const zeus::CVector3f& pos) c for (int r28 = 0; r28 < 5; ++r28) { for (int r29 = 0; r29 < 5; ++r29) { for (int r25 = 0; r25 < 5; ++r25) { - zeus::CAABox aabb = BoxForPosition(r28, r29, r25, 0.1f); - float dist = (aabb.center() - pos).magSquared(); + const zeus::CAABox aabb = BoxForPosition(r28, r29, r25, 0.1f); + const float dist = (aabb.center() - pos).magSquared(); if (dist < minDist) { minDist = dist; ret = aabb.center(); @@ -666,48 +721,56 @@ zeus::CVector3f CWallCrawlerSwarm::FindClosestCell(const zeus::CVector3f& pos) c } void CWallCrawlerSwarm::UpdateEffects(CStateManager& mgr, CAnimData& aData, int vol) { - if (aData.GetPassedSoundPOICount() > 0 && !CAnimData::g_SoundPOINodes.empty()) { - for (int i = 0; i < aData.GetPassedSoundPOICount(); ++i) { - const CSoundPOINode& n = CAnimData::g_SoundPOINodes[i]; - if (n.GetPoiType() == EPOIType::Sound && - (n.GetCharacterIndex() == -1 || n.GetCharacterIndex() == aData.GetCharacterIndex())) { - u16 sfx = CSfxManager::TranslateSFXID(u16(n.GetSfxId() & 0xffff)); - bool loop = bool(n.GetSfxId() >> 31); - if (!loop) { - CAudioSys::C3DEmitterParmData parmData; - parmData.x0_pos = FindClosestCell(mgr.GetPlayer().GetTranslation()); - static float maxDist = n.GetMaxDist(); - static float falloff = n.GetFalloff(); - parmData.x18_maxDist = maxDist; - parmData.x1c_distComp = falloff; - parmData.x20_flags = 0x1; - parmData.x24_sfxId = sfx; - parmData.x26_maxVol = zeus::clamp(0, vol, 127) / 127.f; - parmData.x27_minVol = 20.f / 127.f; - parmData.x28_important = false; - parmData.x29_prio = 0x7f; - CSfxManager::AddEmitter(parmData, true, 0x7f, false, x4_areaId); - } - } + if (aData.GetPassedSoundPOICount() == 0 || CAnimData::g_SoundPOINodes.empty()) { + return; + } + + for (size_t i = 0; i < aData.GetPassedSoundPOICount(); ++i) { + const CSoundPOINode& n = CAnimData::g_SoundPOINodes[i]; + if (n.GetPoiType() != EPOIType::Sound || + (n.GetCharacterIndex() != -1 && n.GetCharacterIndex() != aData.GetCharacterIndex())) { + continue; } + + const u16 sfx = CSfxManager::TranslateSFXID(u16(n.GetSfxId() & 0xffff)); + const bool loop = bool(n.GetSfxId() >> 31); + if (loop) { + continue; + } + + CAudioSys::C3DEmitterParmData parmData; + parmData.x0_pos = FindClosestCell(mgr.GetPlayer().GetTranslation()); + static float maxDist = n.GetMaxDist(); + static float falloff = n.GetFalloff(); + parmData.x18_maxDist = maxDist; + parmData.x1c_distComp = falloff; + parmData.x20_flags = 0x1; + parmData.x24_sfxId = sfx; + parmData.x26_maxVol = zeus::clamp(0, vol, 127) / 127.f; + parmData.x27_minVol = 20.f / 127.f; + parmData.x28_important = false; + parmData.x29_prio = 0x7f; + CSfxManager::AddEmitter(parmData, true, 0x7f, false, x4_areaId); } } zeus::CAABox CWallCrawlerSwarm::BoxForPosition(int x, int y, int z, float f) const { - zeus::CAABox aabb = GetBoundingBox(); - zeus::CVector3f vec = (aabb.max - aabb.min) / 5.f; + const zeus::CAABox aabb = GetBoundingBox(); + const zeus::CVector3f vec = (aabb.max - aabb.min) / 5.f; return zeus::CAABox(zeus::CVector3f(x, y, z) * vec + aabb.min - f, zeus::CVector3f(x + 1, y + 1, z + 1) * vec + aabb.min + f); } void CWallCrawlerSwarm::Think(float dt, CStateManager& mgr) { - if (!GetActive()) + if (!GetActive()) { return; + } if (x560_26_modelAssetDirty && CModelData::GetRenderingModel(mgr) != x4dc_whichModel) { - auto which = CModelData::GetRenderingModel(mgr); - if (which != x4dc_whichModel) + const auto which = CModelData::GetRenderingModel(mgr); + if (which != x4dc_whichModel) { AllocateSkinnedModels(mgr, which); + } } xe4_27_notInSortedLists = true; @@ -715,15 +778,18 @@ void CWallCrawlerSwarm::Think(float dt, CStateManager& mgr) { x36c_crabDamageCooldownTimer -= dt; ++x100_thinkCounter; const CGameArea* area = mgr.GetWorld()->GetAreaAlways(x4_areaId); - auto occState = + const auto occState = area->IsPostConstructed() ? area->GetOcclusionState() : CGameArea::EOcclusionState::Occluded; if (occState != CGameArea::EOcclusionState::Visible) { - if (x104_occludedTimer > 0.f) + if (x104_occludedTimer > 0.f) { x104_occludedTimer -= dt; - if (x104_occludedTimer <= 0.f) + } + if (x104_occludedTimer <= 0.f) { return; - if (x100_thinkCounter & 0x2) + } + if (x100_thinkCounter & 0x2) { return; + } } else { x104_occludedTimer = 7.f; } @@ -732,15 +798,17 @@ void CWallCrawlerSwarm::Think(float dt, CStateManager& mgr) { x42c_lockOnIdx = SelectLockOnIdx(mgr); xe7_31_targetable = x42c_lockOnIdx != -1; - if (x42c_lockOnIdx == -1) + if (x42c_lockOnIdx == -1) { RemoveMaterial(EMaterialTypes::Target, EMaterialTypes::Orbit, mgr); - else + } else { AddMaterial(EMaterialTypes::Target, EMaterialTypes::Orbit, mgr); + } + while ((x54c_maxCreatedBoids == 0 || x550_createdBoids < x54c_maxCreatedBoids) && x368_boidGenCooldownTimer <= 0.f) { int idx = 0; bool madeBoid = false; - for (auto& b : x108_boids) { + for (const auto& b : x108_boids) { if (!b.GetActive()) { CreateBoid(mgr, idx); x550_createdBoids += 1; @@ -762,24 +830,25 @@ void CWallCrawlerSwarm::Think(float dt, CStateManager& mgr) { for (int r26 = 0; r26 < 5; ++r26) { for (int r27 = 0; r27 < 5; ++r27) { for (int r20 = 0; r20 < 5; ++r20) { - int idx = r20 * 25 + r27 * 5 + r26; + const int idx = r20 * 25 + r27 * 5 + r26; if (CBoid* boid = x168_partitionedBoidLists[idx]) { - zeus::CAABox aabb = BoxForPosition(r26, r27, r20, x374_boidRadius + 0.5f); + const zeus::CAABox aabb = BoxForPosition(r26, r27, r20, x374_boidRadius + 0.5f); CAreaCollisionCache ccache(aabb); CGameCollision::BuildAreaCollisionCache(mgr, ccache); while (boid) { r21 += 1; if (boid->GetActive()) { if (x558_flavor == EFlavor::Scarab) { - xe8_aabox.accumulateBounds(boid->Translation() + x37c_scarabBoxMargin); - xe8_aabox.accumulateBounds(boid->Translation() - x37c_scarabBoxMargin); + xe8_aabox.accumulateBounds(boid->GetTranslation() + x37c_scarabBoxMargin); + xe8_aabox.accumulateBounds(boid->GetTranslation() - x37c_scarabBoxMargin); } else { - xe8_aabox.accumulateBounds(boid->Translation()); + xe8_aabox.accumulateBounds(boid->GetTranslation()); } } if (((x100_thinkCounter & 0x1) == (r21 & 0x1) && boid->GetActive() && boid->x48_timeToDie < 0.1f) || - boid->x80_26_launched) + boid->x80_26_launched) { UpdateBoid(ccache, mgr, dt, *boid); + } boid = boid->x44_next; } } @@ -789,12 +858,13 @@ void CWallCrawlerSwarm::Think(float dt, CStateManager& mgr) { for (CBoid* boid = x360_outlierBoidList; boid; boid = boid->x44_next) { r21 += 1; - if (boid->GetActive()) - xe8_aabox.accumulateBounds(boid->Translation()); + if (boid->GetActive()) { + xe8_aabox.accumulateBounds(boid->GetTranslation()); + } if (((x100_thinkCounter & 0x1) == (r21 & 0x1) && boid->GetActive() && boid->x48_timeToDie < 0.1f) || boid->x80_26_launched) { - float margin = 1.5f + x374_boidRadius + 0.5f; - zeus::CAABox aabb(boid->Translation() - margin, boid->Translation() + margin); + const float margin = 1.5f + x374_boidRadius + 0.5f; + const zeus::CAABox aabb(boid->GetTranslation() - margin, boid->GetTranslation() + margin); CAreaCollisionCache ccache(aabb); CGameCollision::BuildAreaCollisionCache(mgr, ccache); UpdateBoid(ccache, mgr, dt, *boid); @@ -809,8 +879,8 @@ void CWallCrawlerSwarm::Think(float dt, CStateManager& mgr) { int r9 = 0; int r3 = 0; int r8 = 0; - bool _38F8[4] = {}; - bool _38F4[4] = {}; + std::array _38F8{}; + std::array _38F4{}; for (const auto& b : x108_boids) { if (b.GetActive() && !b.x80_26_launched) { if (b.x80_27_scarabExplodeTimerEnabled || b.x80_28_nearPlayer) { @@ -824,29 +894,32 @@ void CWallCrawlerSwarm::Think(float dt, CStateManager& mgr) { ++r9; } - for (int i = 0; i < 4; ++i) { + for (size_t i = 0; i < _38F4.size(); ++i) { x4b0_modelDatas[i]->GetAnimationData()->SetPlaybackRate(x160_animPlaybackSpeed); deltas1 = x4b0_modelDatas[i]->AdvanceAnimation(dt, mgr, x4_areaId, true); - x4b0_modelDatas[i+4]->GetAnimationData()->SetPlaybackRate(x160_animPlaybackSpeed); - deltas2 = x4b0_modelDatas[i+4]->AdvanceAnimation(dt, mgr, x4_areaId, true); - if (x4b0_modelDatas[i]->HasAnimData() && _38F4[i]) + x4b0_modelDatas[i + 4]->GetAnimationData()->SetPlaybackRate(x160_animPlaybackSpeed); + deltas2 = x4b0_modelDatas[i + 4]->AdvanceAnimation(dt, mgr, x4_areaId, true); + if (x4b0_modelDatas[i]->HasAnimData() && _38F4[i]) { UpdateEffects(mgr, *x4b0_modelDatas[i]->GetAnimationData(), r8 * 44 / x548_numBoids + 0x53); - if (x4b0_modelDatas[i+4]->HasAnimData() && _38F8[i]) - UpdateEffects(mgr, *x4b0_modelDatas[i+4]->GetAnimationData(), r3 * 44 / x548_numBoids + 0x53); - for (int r20 = i; r20 < x108_boids.size(); r20 += 4) { + } + if (x4b0_modelDatas[i + 4]->HasAnimData() && _38F8[i]) { + UpdateEffects(mgr, *x4b0_modelDatas[i + 4]->GetAnimationData(), r3 * 44 / x548_numBoids + 0x53); + } + for (size_t r20 = i; r20 < x108_boids.size(); r20 += 4) { CBoid& b = x108_boids[r20]; if (b.GetActive()) { if (b.x80_26_launched) { b.Translation() += b.x30_velocity * dt; } else if (b.x48_timeToDie > 0.f) { b.x48_timeToDie -= dt; - if (b.x48_timeToDie < 0.7f * mgr.GetActiveRandom()->Float()) + if (b.x48_timeToDie < 0.7f * mgr.GetActiveRandom()->Float()) { KillBoid(b, mgr, 1.f, 0.05f); + } } else if (b.x80_27_scarabExplodeTimerEnabled || b.x80_28_nearPlayer) { - b.x30_velocity = b.Transform().rotate(deltas2.x0_posDelta) * 1.5f / dt; + b.x30_velocity = b.GetTransform().rotate(deltas2.x0_posDelta) * 1.5f / dt; b.Translation() += b.x30_velocity * dt; } else { - b.x30_velocity = b.Transform().rotate(deltas1.x0_posDelta) * 1.5f / dt; + b.x30_velocity = b.GetTransform().rotate(deltas1.x0_posDelta) * 1.5f / dt; b.Translation() += b.x30_velocity * dt; } } @@ -854,29 +927,32 @@ void CWallCrawlerSwarm::Think(float dt, CStateManager& mgr) { } if (x558_flavor == EFlavor::Crab) { - zeus::CVector3f playerPos = mgr.GetPlayer().GetTranslation(); + const zeus::CVector3f playerPos = mgr.GetPlayer().GetTranslation(); for (auto& b : x108_boids) { - if (b.GetActive() && zeus::close_enough(b.x48_timeToDie, 0.f) && !b.x80_26_launched) - b.x80_28_nearPlayer = (playerPos - b.Translation()).magnitude() < x154_attractionRadius; + if (b.GetActive() && zeus::close_enough(b.x48_timeToDie, 0.f) && !b.x80_26_launched) { + b.x80_28_nearPlayer = (playerPos - b.GetTranslation()).magnitude() < x154_attractionRadius; + } } } if (x558_flavor == EFlavor::Parasite && x554_maxLaunches > 0) { - zeus::CVector3f _383c = mgr.GetPlayer().GetTranslation() + zeus::skUp; - static const CMaterialFilter filter = CMaterialFilter::MakeInclude(EMaterialTypes::Solid); + const zeus::CVector3f _383c = mgr.GetPlayer().GetTranslation() + zeus::skUp; + static constexpr auto filter = CMaterialFilter::MakeInclude(EMaterialTypes::Solid); int numLaunched = 0; - for (auto& b : x108_boids) { - if (b.GetActive() && b.x80_26_launched) + for (const auto& b : x108_boids) { + if (b.GetActive() && b.x80_26_launched) { ++numLaunched; + } } + for (auto it = x108_boids.begin(); it != x108_boids.end() && numLaunched < x554_maxLaunches; ++it) { CBoid& b = *it; if (b.GetActive() && zeus::close_enough(b.x48_timeToDie, 0.f) && !b.x80_26_launched && - (b.Translation() - _383c).magSquared() < 18.f * 18.f && mgr.GetActiveRandom()->Float() <= 0.02f) { - zeus::CVector3f dir = _383c - b.Translation(); - float mag = dir.magnitude(); + (b.GetTranslation() - _383c).magSquared() < 18.f * 18.f && mgr.GetActiveRandom()->Float() <= 0.02f) { + zeus::CVector3f dir = _383c - b.GetTranslation(); + const float mag = dir.magnitude(); dir = dir / mag; - if (mgr.RayStaticIntersection(b.Translation(), dir, mag, filter).IsInvalid()) { + if (mgr.RayStaticIntersection(b.GetTranslation(), dir, mag, filter).IsInvalid()) { LaunchBoid(b, _383c); ++numLaunched; } @@ -886,8 +962,9 @@ void CWallCrawlerSwarm::Think(float dt, CStateManager& mgr) { } void CWallCrawlerSwarm::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) { - for (int i = 0; i < 5; ++i) + for (size_t i = 0; i < 5; ++i) { x4b0_modelDatas[i]->GetAnimationData()->PreRender(); + } bool activeBoid = false; for (auto& b : x108_boids) { if (b.GetActive()) { @@ -901,19 +978,26 @@ void CWallCrawlerSwarm::PreRender(CStateManager& mgr, const zeus::CFrustum& frus } void CWallCrawlerSwarm::RenderParticles() const { - for (const auto& p : x524_particleGens) + for (const auto& p : x524_particleGens) { g_Renderer->AddParticleGen(*p); + } } void CWallCrawlerSwarm::AddToRenderer(const zeus::CFrustum&, const CStateManager& mgr) const { - if (GetActive()) { - RenderParticles(); - if (!xe4_30_outOfFrustum) { - if (CanRenderUnsorted(mgr)) - Render(mgr); - else - EnsureRendered(mgr); - } + if (!GetActive()) { + return; + } + + RenderParticles(); + + if (xe4_30_outOfFrustum) { + return; + } + + if (CanRenderUnsorted(mgr)) { + Render(mgr); + } else { + EnsureRendered(mgr); } } @@ -926,14 +1010,13 @@ zeus::CColor CWallCrawlerSwarm::SoftwareLight(const CStateManager& mgr, const ze lights.BuildDynamicLightList(mgr, aabb); zeus::CColor ret = lights.GetAmbientColor(); ret.a() = 1.f; - zeus::CVector3f center = aabb.center(); - u32 lightCount = lights.GetActiveLightCount(); + const zeus::CVector3f center = aabb.center(); + const u32 lightCount = lights.GetActiveLightCount(); for (u32 i = 0; i < lightCount; ++i) { const CLight& light = lights.GetLight(i); - float dist = (light.GetPosition() - center).magnitude(); - float att = 1.f / (dist * dist * light.GetAttenuationQuadratic() + - dist * light.GetAttenuationLinear() + - light.GetAttenuationConstant()); + const float dist = (light.GetPosition() - center).magnitude(); + const float att = 1.f / (dist * dist * light.GetAttenuationQuadratic() + dist * light.GetAttenuationLinear() + + light.GetAttenuationConstant()); ret += zeus::CColor::lerp(zeus::skBlack, light.GetColor(), 0.8f * std::min(att, 1.f)); } return ret; @@ -946,46 +1029,53 @@ void CWallCrawlerSwarm::HardwareLight(const CStateManager& mgr, const zeus::CAAB lights.SetFindShadowLight(false); lights.BuildAreaLightList(mgr, *mgr.GetWorld()->GetAreaAlways(x4_areaId), aabb); lights.BuildDynamicLightList(mgr, aabb); - for (auto& m : x4b0_modelDatas) { + for (const auto& m : x4b0_modelDatas) { lights.ActivateLights(*m->PickAnimatedModel(x4dc_whichModel).GetModelInst()); - if (auto iceModel = m->GetAnimationData()->GetIceModel()) + if (const auto iceModel = m->GetAnimationData()->GetIceModel()) { lights.ActivateLights(*iceModel->GetModelInst()); + } } } void CWallCrawlerSwarm::RenderBoid(const CBoid* boid, u32& drawMask, bool thermalHot, const CModelFlags& flags) const { u32 modelIndex = 0x0; - if (boid->x80_26_launched) + if (boid->x80_26_launched) { modelIndex = 0x8; - else if (boid->x48_timeToDie > 0.f) + } else if (boid->x48_timeToDie > 0.f) { modelIndex = 0x9; - else if (boid->x80_27_scarabExplodeTimerEnabled || boid->x80_28_nearPlayer) + } else if (boid->x80_27_scarabExplodeTimerEnabled || boid->x80_28_nearPlayer) { modelIndex += 0x4; + } + CModelData& mData = *x4b0_modelDatas[modelIndex]; CSkinnedModel& model = mData.PickAnimatedModel(x4dc_whichModel); - if (!model.GetModelInst()->TryLockTextures()) + if (!model.GetModelInst()->TryLockTextures()) { return; - u32 thisDrawMask = 1u << modelIndex; + } + + const u32 thisDrawMask = 1u << modelIndex; if (drawMask & thisDrawMask) { drawMask &= ~thisDrawMask; mData.GetAnimationData()->BuildPose(); } + model.GetModelInst()->SetAmbientColor(boid->x40_ambientLighting); CGraphics::SetModelMatrix(boid->GetTransform()); if (boid->x48_timeToDie > 0.f && !thermalHot) { - CModelFlags useFlags(0, 0, 3, zeus::skWhite); + const CModelFlags useFlags(0, 0, 3, zeus::skWhite); mData.GetAnimationData()->Render(model, useFlags, {}, nullptr); if (auto iceModel = mData.GetAnimationData()->GetIceModel()) { - if (!iceModel->GetModelInst()->TryLockTextures()) + if (!iceModel->GetModelInst()->TryLockTextures()) { return; + } iceModel->GetModelInst()->SetAmbientColor(zeus::skWhite); - float alpha = 1.f - boid->x48_timeToDie; - zeus::CColor color(1.f, alpha > 0.f ? boid->x48_timeToDie : 1.f); - CModelFlags iceFlags(5, 0, 3, color); + const float alpha = 1.f - boid->x48_timeToDie; + const zeus::CColor color(1.f, alpha > 0.f ? boid->x48_timeToDie : 1.f); + const CModelFlags iceFlags(5, 0, 3, color); mData.GetAnimationData()->Render(*iceModel, iceFlags, {}, nullptr); } } else if (thermalHot) { - CModelFlags thermFlags(5, 0, 3, zeus::skWhite); + const CModelFlags thermFlags(5, 0, 3, zeus::skWhite); mData.RenderThermal(zeus::skWhite, zeus::CColor(0.f, 0.25f), thermFlags); } else { mData.GetAnimationData()->Render(model, flags, {}, nullptr); @@ -996,28 +1086,32 @@ void CWallCrawlerSwarm::Render(const CStateManager& mgr) const { SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(fmt("CWallCrawlerSwarm::Render {} {} {}"), x8_uid, xc_editorId, x10_name).c_str(), zeus::skOrange); u32 drawMask = 0xffffffff; - bool r24 = x560_24_enableLighting; - bool r23 = x560_25_useSoftwareLight; + const bool r24 = x560_24_enableLighting; + const bool r23 = x560_25_useSoftwareLight; if (!r24) { // Ambient 50% grey } - bool thermalHot = mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot; + + const bool thermalHot = mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot; CModelFlags flags(0, 0, 3, zeus::skWhite); - if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay) + if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay) { flags = CModelFlags(5, 0, 3, zeus::CColor(1.f, 0.3f)); + } + for (int r27 = 0; r27 < 5; ++r27) { for (int r28 = 0; r28 < 5; ++r28) { for (int r21 = 0; r21 < 5; ++r21) { - int idx = r21 * 25 + r28 * 5 + r27; + const int idx = r21 * 25 + r28 * 5 + r27; if (CBoid* b = x168_partitionedBoidLists[idx]) { if (r24) { - zeus::CAABox aabb = BoxForPosition(r27, r28, r21, 0.f); + const zeus::CAABox aabb = BoxForPosition(r27, r28, r21, 0.f); if (r23) { if ((idx & 0x3) == (x100_thinkCounter & 0x3)) { - zeus::CColor color = SoftwareLight(mgr, aabb); + const zeus::CColor color = SoftwareLight(mgr, aabb); for (CBoid* b2 = b; b2; b2 = b2->x44_next) { - if (b2->GetActive()) + if (b2->GetActive()) { b2->x40_ambientLighting = zeus::CColor::lerp(b2->x40_ambientLighting, color, 0.3f); + } } } } else { @@ -1025,23 +1119,26 @@ void CWallCrawlerSwarm::Render(const CStateManager& mgr) const { } } for (CBoid* b2 = b; b2; b2 = b2->x44_next) { - if (b2->x80_25_inFrustum && b2->GetActive()) + if (b2->x80_25_inFrustum && b2->GetActive()) { RenderBoid(b2, drawMask, thermalHot, flags); + } } } } } } + CBoid* b = x360_outlierBoidList; for (int i = 1; b; ++i, b = b->x44_next) { if (b->x80_25_inFrustum && b->GetActive()) { if (r24) { - zeus::CAABox aabb(b->GetTranslation() - x374_boidRadius, b->GetTranslation() + x374_boidRadius); + const zeus::CAABox aabb(b->GetTranslation() - x374_boidRadius, b->GetTranslation() + x374_boidRadius); if (r23) { if ((i & 0x3) == (x100_thinkCounter & 0x3)) { zeus::CColor color = SoftwareLight(mgr, aabb); - if (b->GetActive()) + if (b->GetActive()) { b->x40_ambientLighting = zeus::CColor::lerp(b->x40_ambientLighting, color, 0.3f); + } } } else { HardwareLight(mgr, aabb); @@ -1067,37 +1164,40 @@ std::optional CWallCrawlerSwarm::GetTouchBounds() const { void CWallCrawlerSwarm::Touch(CActor& other, CStateManager& mgr) { CActor::Touch(other, mgr); - if (TCastToPtr proj = other) { + if (TCastToConstPtr proj = other) { if (x3c4_dVuln.WeaponHurts(proj->GetDamageInfo().GetWeaponMode(), false)) { if (auto projTb = proj->GetTouchBounds()) { - float f0 = 0.1f + x378_touchRadius; - float f30 = f0 * f0; + const float f0 = 0.1f + x378_touchRadius; + const float f30 = f0 * f0; for (auto& b : x108_boids) { if (b.GetActive()) { - zeus::CAABox aabb(b.GetTranslation() - f30, b.GetTranslation() + f30); + const zeus::CAABox aabb(b.GetTranslation() - f30, b.GetTranslation() + f30); if (aabb.intersects(*projTb)) { b.x78_health -= proj->GetDamageInfo().GetDamage(x3c4_dVuln); - if (b.x78_health <= 0.f) + if (b.x78_health <= 0.f) { KillBoid(b, mgr, 1.f, 0.1f); + } } } } } } } - if (TCastToPtr player = other) { - float radius = zeus::close_enough(x380_playerTouchRadius, 0.f) ? x378_touchRadius : x380_playerTouchRadius; + + if (TCastToConstPtr player = other) { + const float radius = zeus::close_enough(x380_playerTouchRadius, 0.f) ? x378_touchRadius : x380_playerTouchRadius; if (auto playerTb = player->GetTouchBounds()) { for (auto& b : x108_boids) { if (b.GetActive() && b.x48_timeToDie <= 0.f) { if (x558_flavor == EFlavor::Scarab && b.x80_27_scarabExplodeTimerEnabled) { - zeus::CAABox aabb(b.GetTranslation() - x37c_scarabBoxMargin, b.GetTranslation() + x37c_scarabBoxMargin); + const zeus::CAABox aabb(b.GetTranslation() - x37c_scarabBoxMargin, + b.GetTranslation() + x37c_scarabBoxMargin); if (playerTb->intersects(aabb)) { ExplodeBoid(b, mgr); SetExplodeTimers(b.GetTranslation(), 0.5f, 0.5f, 2.5f); } } - zeus::CAABox aabb(b.GetTranslation() - radius, b.GetTranslation() + radius); + const zeus::CAABox aabb(b.GetTranslation() - radius, b.GetTranslation() + radius); if (playerTb->intersects(aabb)) { if (b.GetActive() && x558_flavor == EFlavor::Parasite) { constexpr CDamageInfo dInfo(CWeaponMode(EWeaponType::AI), 2.0e-05f, 0.f, 0.f); @@ -1120,15 +1220,19 @@ void CWallCrawlerSwarm::Touch(CActor& other, CStateManager& mgr) { } zeus::CVector3f CWallCrawlerSwarm::GetOrbitPosition(const CStateManager&) const { - if (x42c_lockOnIdx == -1) + if (x42c_lockOnIdx == -1) { return x124_lastOrbitPosition; + } + x124_lastOrbitPosition = x108_boids[x42c_lockOnIdx].GetTranslation(); return x124_lastOrbitPosition; } zeus::CVector3f CWallCrawlerSwarm::GetAimPosition(const CStateManager&, float dt) const { - if (x42c_lockOnIdx == -1) + if (x42c_lockOnIdx == -1) { return x124_lastOrbitPosition; + } + return x108_boids[x42c_lockOnIdx].x30_velocity * dt + x124_lastOrbitPosition; } diff --git a/Runtime/World/CWorld.cpp b/Runtime/World/CWorld.cpp index 124f4ca33..f2499f3ca 100644 --- a/Runtime/World/CWorld.cpp +++ b/Runtime/World/CWorld.cpp @@ -233,15 +233,18 @@ TAreaId CWorld::IGetAreaId(CAssetId id) const { } void CWorld::MoveToChain(CGameArea* area, EChain chain) { - if (area->x138_curChain == chain) + if (area->x138_curChain == chain) { return; + } - if (area->x138_curChain != EChain::Invalid) - if (x4c_chainHeads[int(area->x138_curChain)] == area) - x4c_chainHeads[int(area->x138_curChain)] = area->x130_next; + if (area->x138_curChain != EChain::Invalid) { + if (x4c_chainHeads[size_t(area->x138_curChain)] == area) { + x4c_chainHeads[size_t(area->x138_curChain)] = area->x130_next; + } + } - area->SetChain(x4c_chainHeads[int(chain)], chain); - x4c_chainHeads[int(chain)] = area; + area->SetChain(x4c_chainHeads[size_t(chain)], chain); + x4c_chainHeads[size_t(chain)] = area; } void CWorld::MoveAreaToAliveChain(TAreaId aid) { MoveToChain(x18_areas[aid].get(), EChain::Alive); } @@ -307,13 +310,15 @@ bool CWorld::CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId) r.readUint32Big(); x18_areas.reserve(areaCount); - for (u32 i = 0; i < areaCount; ++i) + for (u32 i = 0; i < areaCount; ++i) { x18_areas.push_back(std::make_unique(r, i, version)); + } - if (x48_chainCount < 5) { - for (int i = x48_chainCount; i < 5; ++i) + if (x48_chainCount < x4c_chainHeads.size()) { + for (size_t i = x48_chainCount; i < x4c_chainHeads.size(); ++i) { x4c_chainHeads[i] = nullptr; - x48_chainCount = 5; + } + x48_chainCount = x4c_chainHeads.size(); } for (std::unique_ptr& area : x18_areas) @@ -567,7 +572,7 @@ void CWorld::Update(float dt) { u32 areaCount = 0; - for (CGameArea* head = x4c_chainHeads[3]; head != skGlobalNonConstEnd; head = head->x130_next, ++areaCount) { + for (auto head = GetChainHead(EChain::Alive); head != AliveAreasEnd(); ++head, ++areaCount) { head->AliveUpdate(dt); if (head->DoesAreaNeedSkyNow()) { @@ -625,7 +630,7 @@ void CWorld::Update(float dt) { } void CWorld::PreRender() { - for (CGameArea* head = x4c_chainHeads[3]; head != skGlobalNonConstEnd; head = head->x130_next) { + for (auto head = GetChainHead(EChain::Alive); head != AliveAreasEnd(); ++head) { head->PreRender(); } } diff --git a/Runtime/World/CWorld.hpp b/Runtime/World/CWorld.hpp index e3473051e..2e2065d21 100644 --- a/Runtime/World/CWorld.hpp +++ b/Runtime/World/CWorld.hpp @@ -1,11 +1,13 @@ #pragma once +#include #include #include #include #include "Runtime/RetroTypes.hpp" #include "Runtime/rstl.hpp" +#include "Runtime/Audio/CAudioGroupSet.hpp" #include "Runtime/Audio/CSfxManager.hpp" #include "Runtime/AutoMapper/CMapWorld.hpp" #include "Runtime/Graphics/CModel.hpp" @@ -14,7 +16,6 @@ #include "Runtime/World/ScriptObjectSupport.hpp" namespace urde { -class CAudioGroupSet; class CGameArea; class CResFactory; class IGameArea; @@ -83,7 +84,7 @@ public: public: CRelay() = default; - CRelay(CInputStream& in); + explicit CRelay(CInputStream& in); TEditorId GetRelayId() const { return x0_relay; } TEditorId GetTargetId() const { return x4_target; } @@ -104,8 +105,6 @@ public: }; private: - static constexpr CGameArea* skGlobalEnd = nullptr; - static constexpr CGameArea* skGlobalNonConstEnd = nullptr; enum class Phase { Loading, LoadingMap, @@ -125,7 +124,7 @@ private: std::unique_ptr x40_loadBuf; u32 x44_bufSz; u32 x48_chainCount = 0; - CGameArea* x4c_chainHeads[5] = {}; + std::array x4c_chainHeads{}; IObjectStore& x60_objectStore; IFactory& x64_resFactory; @@ -158,12 +157,16 @@ public: void MoveToChain(CGameArea* area, EChain chain); void MoveAreaToAliveChain(TAreaId aid); bool CheckWorldComplete(CStateManager* mgr, TAreaId id, CAssetId mreaId); - CGameArea::CChainIterator GetChainHead(EChain chain) { return {x4c_chainHeads[int(chain)]}; } - CGameArea::CConstChainIterator GetChainHead(EChain chain) const { return {x4c_chainHeads[int(chain)]}; } - CGameArea::CChainIterator begin() { return GetChainHead(EChain::Alive); } - CGameArea::CChainIterator end() { return AliveAreasEnd(); } - CGameArea::CConstChainIterator begin() const { return GetChainHead(EChain::Alive); } - CGameArea::CConstChainIterator end() const { return GetAliveAreasEnd(); } + + [[nodiscard]] auto GetChainHead(EChain chain) { return CGameArea::CChainIterator{x4c_chainHeads[size_t(chain)]}; } + [[nodiscard]] auto GetChainHead(EChain chain) const { + return CGameArea::CConstChainIterator{x4c_chainHeads[size_t(chain)]}; + } + [[nodiscard]] auto begin() { return GetChainHead(EChain::Alive); } + [[nodiscard]] auto end() { return AliveAreasEnd(); } + [[nodiscard]] auto begin() const { return GetChainHead(EChain::Alive); } + [[nodiscard]] auto end() const { return GetAliveAreasEnd(); } + bool ScheduleAreaToLoad(CGameArea* area, CStateManager& mgr); void TravelToArea(TAreaId aid, CStateManager& mgr, bool skipLoadOther); void SetLoadPauseState(bool paused); @@ -195,8 +198,8 @@ public: int IGetAreaCount() const override; static void PropogateAreaChain(CGameArea::EOcclusionState occlusionState, CGameArea* area, CWorld* world); - static CGameArea::CConstChainIterator GetAliveAreasEnd() { return {skGlobalEnd}; } - static CGameArea::CChainIterator AliveAreasEnd() { return {skGlobalNonConstEnd}; } + static constexpr CGameArea::CConstChainIterator GetAliveAreasEnd() { return CGameArea::CConstChainIterator{}; } + static constexpr CGameArea::CChainIterator AliveAreasEnd() { return CGameArea::CChainIterator{}; } void Update(float dt); void PreRender(); diff --git a/Runtime/World/CWorldLight.hpp b/Runtime/World/CWorldLight.hpp index eccf6ffab..055d02a39 100644 --- a/Runtime/World/CWorldLight.hpp +++ b/Runtime/World/CWorldLight.hpp @@ -30,7 +30,7 @@ private: public: CWorldLight(const CWorldLight&) = default; - CWorldLight(CInputStream& in); + explicit CWorldLight(CInputStream& in); EWorldLightType GetLightType() const { return x0_type; } const zeus::CVector3f& GetDirection() const { return x1c_direction; } const zeus::CVector3f& GetPosition() const { return x10_position; } diff --git a/Runtime/World/CWorldTransManager.cpp b/Runtime/World/CWorldTransManager.cpp index 68127594a..43091ff55 100644 --- a/Runtime/World/CWorldTransManager.cpp +++ b/Runtime/World/CWorldTransManager.cpp @@ -349,7 +349,7 @@ void CWorldTransManager::TouchModels() { if (x4_modelData->x68_beamModelData.IsNull() && x4_modelData->x14c_beamModel.IsLoaded() && x4_modelData->x14c_beamModel.GetObj()) { - x4_modelData->x68_beamModelData = { + x4_modelData->x68_beamModelData = CModelData{ CStaticRes(x4_modelData->x14c_beamModel.GetObjectTag()->id, x4_modelData->x0_samusRes.GetScale()), 2}; } @@ -358,7 +358,7 @@ void CWorldTransManager::TouchModels() { x4_modelData->x164_suitSkin.GetObj()) { CAnimRes animRes(x4_modelData->x0_samusRes.GetId(), GetSuitCharIdx(), x4_modelData->x0_samusRes.GetScale(), x4_modelData->x0_samusRes.GetDefaultAnim(), true); - x4_modelData->x1c_samusModelData = {animRes, 2}; + x4_modelData->x1c_samusModelData = CModelData{animRes, 2}; CAnimPlaybackParms aData(animRes.GetDefaultAnim(), -1, 1.f, true); x4_modelData->x1c_samusModelData.GetAnimationData()->SetAnimation(aData, false); @@ -408,22 +408,23 @@ void CWorldTransManager::EnableTransition(const CAnimRes& samusRes, CAssetId pla x4_modelData->x164_suitSkin = g_SimplePool->GetObj(SObjectTag{FOURCC('CSKR'), info.GetSkinRulesId()}); if (platRes.IsValid()) { - x4_modelData->xb4_platformModelData = {CStaticRes(platRes, platScale), 2}; + x4_modelData->xb4_platformModelData = CModelData{CStaticRes(platRes, platScale), 2}; x4_modelData->xb4_platformModelData.Touch(CModelData::EWhichModel::Normal, 0); } if (bgRes.IsValid()) { - CStaticRes bg(bgRes, bgScale); - x4_modelData->x100_bgModelData[0] = bg; + const CStaticRes bg(bgRes, bgScale); + x4_modelData->x100_bgModelData[0] = CModelData{bg}; x4_modelData->x100_bgModelData[0].Touch(CModelData::EWhichModel::Normal, 0); - x4_modelData->x100_bgModelData[1] = bg; + x4_modelData->x100_bgModelData[1] = CModelData{bg}; x4_modelData->x100_bgModelData[1].Touch(CModelData::EWhichModel::Normal, 0); - x4_modelData->x100_bgModelData[2] = bg; + x4_modelData->x100_bgModelData[2] = CModelData{bg}; x4_modelData->x100_bgModelData[2].Touch(CModelData::EWhichModel::Normal, 0); - zeus::CAABox bounds = x4_modelData->x100_bgModelData[0].GetBounds(); + const zeus::CAABox bounds = x4_modelData->x100_bgModelData[0].GetBounds(); x1c_bgHeight = (bounds.max.z() - bounds.min.z()) * bgScale.z(); - } else + } else { x1c_bgHeight = 0.f; + } StartTransition(); TouchModels(); diff --git a/Runtime/World/CWorldTransManager.hpp b/Runtime/World/CWorldTransManager.hpp index 5cc678eff..978d0f447 100644 --- a/Runtime/World/CWorldTransManager.hpp +++ b/Runtime/World/CWorldTransManager.hpp @@ -48,7 +48,7 @@ public: float x1d8_transCompleteTime = 99999.f; bool x1dc_dissolveStarted = false; - SModelDatas(const CAnimRes& samusRes); + explicit SModelDatas(const CAnimRes& samusRes); }; private: @@ -80,9 +80,9 @@ private: u8 dummy = 0; }; - CColoredQuadFilter m_fadeToBlack = {EFilterType::Blend}; - CTexturedQuadFilter m_dissolve = {EFilterType::Blend, CGraphics::g_SpareTexture.get()}; - CWideScreenFilter m_widescreen = {EFilterType::Blend}; + CColoredQuadFilter m_fadeToBlack{EFilterType::Blend}; + CTexturedQuadFilter m_dissolve{EFilterType::Blend, CGraphics::g_SpareTexture.get()}; + CWideScreenFilter m_widescreen{EFilterType::Blend}; CCameraBlurFilter m_camblur; boo::ObjToken m_reflectionCube[2]; diff --git a/Runtime/World/IGameArea.hpp b/Runtime/World/IGameArea.hpp index 2a4cce25a..9eb2c870b 100644 --- a/Runtime/World/IGameArea.hpp +++ b/Runtime/World/IGameArea.hpp @@ -58,6 +58,13 @@ public: virtual const zeus::CTransform& IGetTM() const = 0; }; -enum class EChain { Invalid = -1, ToDeallocate, Deallocated, Loading, Alive, AliveJudgement }; +enum class EChain { + Invalid = -1, + ToDeallocate, + Deallocated, + Loading, + Alive, + AliveJudgement, +}; } // namespace urde diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index 463435c9b..1d2a3707e 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -437,10 +437,12 @@ CEntity* ScriptLoader::LoadActor(CStateManager& mgr, CInputStream& in, int propC list.Add(EMaterialTypes::CameraPassthrough); CModelData data; - if (animType == SBIG('ANCS')) - data = CAnimRes(aParms.GetACSFile(), aParms.GetCharacter(), head.x40_scale, aParms.GetInitialAnimation(), false); - else - data = CStaticRes(staticId, head.x40_scale); + if (animType == SBIG('ANCS')) { + data = CModelData{ + CAnimRes(aParms.GetACSFile(), aParms.GetCharacter(), head.x40_scale, aParms.GetInitialAnimation(), false)}; + } else { + data = CModelData{CStaticRes(staticId, head.x40_scale)}; + } if ((collisionExtent.x() < 0.f || collisionExtent.y() < 0.f || collisionExtent.z() < 0.f) || collisionExtent.isZero()) aabb = data.GetBounds(head.x10_transform.getRotation()); @@ -497,7 +499,7 @@ CEntity* ScriptLoader::LoadDoor(CStateManager& mgr, CInputStream& in, int propCo if (!g_ResFactory->GetResourceTypeById(aParms.GetACSFile()).IsValid()) return nullptr; - CModelData mData = CAnimRes(aParms.GetACSFile(), aParms.GetCharacter(), head.x40_scale, 0, false); + CModelData mData{CAnimRes(aParms.GetACSFile(), aParms.GetCharacter(), head.x40_scale, 0, false)}; if (collisionExtent.isZero()) aabb = mData.GetBounds(head.x10_transform.getRotation()); @@ -657,10 +659,12 @@ CEntity* ScriptLoader::LoadPlatform(CStateManager& mgr, CInputStream& in, int pr } CModelData data; - if (animType == SBIG('ANCS')) - data = CAnimRes(aParms.GetACSFile(), aParms.GetCharacter(), head.x40_scale, aParms.GetInitialAnimation(), true); - else - data = CStaticRes(staticId, head.x40_scale); + if (animType == SBIG('ANCS')) { + data = CModelData{ + CAnimRes(aParms.GetACSFile(), aParms.GetCharacter(), head.x40_scale, aParms.GetInitialAnimation(), true)}; + } else { + data = CModelData{CStaticRes(staticId, head.x40_scale)}; + } if (extent.isZero()) aabb = data.GetBounds(head.x10_transform.getRotation()); @@ -816,9 +820,9 @@ CEntity* ScriptLoader::LoadNewIntroBoss(CStateManager& mgr, CInputStream& in, in CAnimRes res(aParms.GetACSFile(), aParms.GetCharacter(), head.x40_scale, aParms.GetInitialAnimation(), true); - return new MP1::CNewIntroBoss(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, res, pInfo, actParms, - minTurnAngle, projectile, dInfo, beamContactFxId, beamPulseFxId, beamTextureId, - beamGlowTextureId); + return new MP1::CNewIntroBoss(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, CModelData{res}, pInfo, + actParms, minTurnAngle, projectile, dInfo, beamContactFxId, beamPulseFxId, + beamTextureId, beamGlowTextureId); } CEntity* ScriptLoader::LoadSpawnPoint(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { @@ -924,14 +928,16 @@ CEntity* ScriptLoader::LoadPickup(CStateManager& mgr, CInputStream& in, int prop CModelData data; - if (acsType == SBIG('ANCS')) - data = CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), head.x40_scale, animParms.GetInitialAnimation(), - true); - else - data = CStaticRes(staticModel, head.x40_scale); + if (acsType == SBIG('ANCS')) { + data = CModelData{CAnimRes(animParms.GetACSFile(), animParms.GetCharacter(), head.x40_scale, + animParms.GetInitialAnimation(), true)}; + } else { + data = CModelData{CStaticRes(staticModel, head.x40_scale)}; + } - if (extent.isZero()) + if (extent.isZero()) { aabb = data.GetBounds(head.x10_transform.getRotation()); + } return new CScriptPickup(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, std::move(data), actorParms, aabb, itemType, amount, capacity, pickupEffect, possibility, lifeTime, fadeInTime, @@ -1010,21 +1016,24 @@ CEntity* ScriptLoader::LoadBeetle(CStateManager& mgr, CInputStream& in, int prop const CAnimationParameters& animParams = pInfo.GetAnimationParameters(); CAnimRes animRes(animParams.GetACSFile(), animParams.GetCharacter(), scale, animParams.GetInitialAnimation(), true); - return new MP1::CBeetle(mgr.AllocateUniqueId(), name, info, xfrm, animRes, pInfo, flavor, entranceType, touchDamage, - platingVuln, tailAimReference, initialAttackDelay, retreatTime, unused, tailVuln, aParams, - tailRes); + return new MP1::CBeetle(mgr.AllocateUniqueId(), name, info, xfrm, CModelData{animRes}, pInfo, flavor, entranceType, + touchDamage, platingVuln, tailAimReference, initialAttackDelay, retreatTime, unused, tailVuln, + aParams, tailRes); } CEntity* ScriptLoader::LoadHUDMemo(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { - if (propCount != 5 && !EnsurePropertyCount(propCount, 6, "HUDMemo")) - return 0; - std::string name = mgr.HashInstanceName(in); - CHUDMemoParms hParms(in); - CScriptHUDMemo::EDisplayType displayType = CScriptHUDMemo::EDisplayType::MessageBox; - if (propCount == 6) + if (propCount != 5 && !EnsurePropertyCount(propCount, 6, "HUDMemo")) { + return nullptr; + } + + const std::string name = mgr.HashInstanceName(in); + const CHUDMemoParms hParms(in); + auto displayType = CScriptHUDMemo::EDisplayType::MessageBox; + if (propCount == 6) { displayType = CScriptHUDMemo::EDisplayType(in.readUint32Big()); - CAssetId message = in.readUint32Big(); - bool active = in.readBool(); + } + const CAssetId message = in.readUint32Big(); + const bool active = in.readBool(); return new CScriptHUDMemo(mgr.AllocateUniqueId(), name, info, hParms, displayType, message, active); } @@ -1128,28 +1137,30 @@ CEntity* ScriptLoader::LoadDebris(CStateManager& mgr, CInputStream& in, int prop if (!EnsurePropertyCount(propCount, 18, "Debris")) return nullptr; - SScaledActorHead head = LoadScaledActorHead(in, mgr); - float zImpulse = in.readFloatBig(); - zeus::CVector3f velocity = zeus::CVector3f::ReadBig(in); + const SScaledActorHead head = LoadScaledActorHead(in, mgr); + const float zImpulse = in.readFloatBig(); + const zeus::CVector3f velocity = zeus::CVector3f::ReadBig(in); zeus::CColor endsColor; endsColor.readRGBABig(in); - float mass = in.readFloatBig(); - float restitution = in.readFloatBig(); - float duration = in.readFloatBig(); - CScriptDebris::EScaleType scaleType = CScriptDebris::EScaleType(in.readUint32Big()); - bool randomAngImpulse = in.readBool(); - CAssetId model = in.readUint32Big(); - CActorParameters aParams = LoadActorParameters(in); - CAssetId particleId = in.readUint32Big(); - zeus::CVector3f particleScale = zeus::CVector3f::ReadBig(in); - bool b1 = in.readBool(); - bool active = in.readBool(); + const float mass = in.readFloatBig(); + const float restitution = in.readFloatBig(); + const float duration = in.readFloatBig(); + const auto scaleType = CScriptDebris::EScaleType(in.readUint32Big()); + const bool randomAngImpulse = in.readBool(); + const CAssetId model = in.readUint32Big(); + const CActorParameters aParams = LoadActorParameters(in); + const CAssetId particleId = in.readUint32Big(); + const zeus::CVector3f particleScale = zeus::CVector3f::ReadBig(in); + const bool b1 = in.readBool(); + const bool active = in.readBool(); - if (!g_ResFactory->GetResourceTypeById(model).IsValid()) + if (!g_ResFactory->GetResourceTypeById(model).IsValid()) { return nullptr; + } + return new CScriptDebris(mgr.AllocateUniqueId(), head.x0_name, info, head.x10_transform, - CStaticRes(model, head.x40_scale), aParams, particleId, particleScale, zImpulse, velocity, - endsColor, mass, restitution, duration, scaleType, b1, randomAngImpulse, active); + CModelData{CStaticRes(model, head.x40_scale)}, aParams, particleId, particleScale, zImpulse, + velocity, endsColor, mass, restitution, duration, scaleType, b1, randomAngImpulse, active); } CEntity* ScriptLoader::LoadCameraShaker(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { @@ -2342,25 +2353,30 @@ CEntity* ScriptLoader::LoadFishCloudModifier(CStateManager& mgr, CInputStream& i } CEntity* ScriptLoader::LoadVisorFlare(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { - if (!EnsurePropertyCount(propCount, 14, "VisorFlare")) + if (!EnsurePropertyCount(propCount, 14, "VisorFlare")) { return nullptr; + } + + const std::string name = mgr.HashInstanceName(in); + const zeus::CVector3f pos = zeus::CVector3f::ReadBig(in); + const bool b1 = in.readBool(); + const auto w1 = CVisorFlare::EBlendMode(in.readUint32Big()); + const bool b2 = in.readBool(); + const float f1 = in.readFloatBig(); + const float f2 = in.readFloatBig(); + const float f3 = in.readFloatBig(); + const u32 w2 = in.readUint32Big(); - std::string name = mgr.HashInstanceName(in); - zeus::CVector3f pos = zeus::CVector3f::ReadBig(in); - bool b1 = in.readBool(); - CVisorFlare::EBlendMode w1 = CVisorFlare::EBlendMode(in.readUint32Big()); - bool b2 = in.readBool(); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - u32 w2 = in.readUint32Big(); std::vector flares; flares.reserve(5); - for (int i = 0; i < 5; ++i) - if (auto flare = CVisorFlare::LoadFlareDef(in)) + for (size_t i = 0; i < flares.capacity(); ++i) { + if (auto flare = CVisorFlare::LoadFlareDef(in)) { flares.push_back(*flare); + } + } - return new CScriptVisorFlare(mgr.AllocateUniqueId(), name, info, b1, pos, w1, b2, f1, f2, f3, 2, w2, flares); + return new CScriptVisorFlare(mgr.AllocateUniqueId(), name, info, b1, pos, w1, b2, f1, f2, f3, 2, w2, + std::move(flares)); } CEntity* ScriptLoader::LoadWorldTeleporter(CStateManager& mgr, CInputStream& in, int propCount, diff --git a/Runtime/World/ScriptLoader.hpp b/Runtime/World/ScriptLoader.hpp index e0a84d55e..86d6cea48 100644 --- a/Runtime/World/ScriptLoader.hpp +++ b/Runtime/World/ScriptLoader.hpp @@ -18,7 +18,7 @@ class CScannableParameters; class CStateManager; class CVisorParameters; -typedef CEntity* (*FScriptLoader)(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); +using FScriptLoader = CEntity* (*)(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info); class ScriptLoader { public: diff --git a/Runtime/rstl.hpp b/Runtime/rstl.hpp index c7f6135f1..eaf42903e 100644 --- a/Runtime/rstl.hpp +++ b/Runtime/rstl.hpp @@ -522,32 +522,36 @@ public: x0_size = 0; } - size_t size() const noexcept { return x0_size; } - bool empty() const noexcept { return x0_size == 0; } - constexpr size_t capacity() const noexcept { return N; } - const T* data() const noexcept { return std::addressof(_value(0)); } - T* data() noexcept { return std::addressof(_value(0)); } + [[nodiscard]] size_t size() const noexcept { return x0_size; } + [[nodiscard]] bool empty() const noexcept { return x0_size == 0; } + [[nodiscard]] constexpr size_t capacity() const noexcept { return N; } + [[nodiscard]] const T* data() const noexcept { return std::addressof(_value(0)); } + [[nodiscard]] T* data() noexcept { return std::addressof(_value(0)); } - T& back() { return _value(x0_size - 1); } - T& front() { return _value(0); } - const T& back() const { return _value(x0_size - 1); } - const T& front() const { return _value(0); } + [[nodiscard]] T& back() { return _value(x0_size - 1); } + [[nodiscard]] T& front() { return _value(0); } + [[nodiscard]] const T& back() const { return _value(x0_size - 1); } + [[nodiscard]] const T& front() const { return _value(0); } - const_iterator begin() const noexcept { return const_iterator(std::addressof(_value(0))); } - const_iterator end() const noexcept { return const_iterator(std::addressof(_value(x0_size))); } - iterator begin() noexcept { return iterator(std::addressof(_value(0))); } - iterator end() noexcept { return iterator(std::addressof(_value(x0_size))); } - const_iterator cbegin() const noexcept { return begin(); } - const_iterator cend() const noexcept { return end(); } + [[nodiscard]] const_iterator begin() const noexcept { return const_iterator(std::addressof(_value(0))); } + [[nodiscard]] const_iterator end() const noexcept { return const_iterator(std::addressof(_value(x0_size))); } + [[nodiscard]] iterator begin() noexcept { return iterator(std::addressof(_value(0))); } + [[nodiscard]] iterator end() noexcept { return iterator(std::addressof(_value(x0_size))); } + [[nodiscard]] const_iterator cbegin() const noexcept { return begin(); } + [[nodiscard]] const_iterator cend() const noexcept { return end(); } - const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(std::addressof(_value(x0_size - 1))); } - const_reverse_iterator rend() const noexcept { return const_reverse_iterator(std::addressof(_value(-1))); } - reverse_iterator rbegin() noexcept { return reverse_iterator(std::addressof(_value(x0_size - 1))); } - reverse_iterator rend() noexcept { return reverse_iterator(std::addressof(_value(-1))); } - const_reverse_iterator crbegin() const noexcept { return rbegin(); } - const_reverse_iterator crend() const noexcept { return rend(); } + [[nodiscard]] const_reverse_iterator rbegin() const noexcept { + return const_reverse_iterator(std::addressof(_value(x0_size - 1))); + } + [[nodiscard]] const_reverse_iterator rend() const noexcept { + return const_reverse_iterator(std::addressof(_value(-1))); + } + [[nodiscard]] reverse_iterator rbegin() noexcept { return reverse_iterator(std::addressof(_value(x0_size - 1))); } + [[nodiscard]] reverse_iterator rend() noexcept { return reverse_iterator(std::addressof(_value(-1))); } + [[nodiscard]] const_reverse_iterator crbegin() const noexcept { return rbegin(); } + [[nodiscard]] const_reverse_iterator crend() const noexcept { return rend(); } - T& operator[](size_t idx) { + [[nodiscard]] T& operator[](size_t idx) { #ifndef NDEBUG if (idx >= x0_size) { Log.report(logvisor::Fatal, fmt("out of bounds access on reserved_vector.")); @@ -555,7 +559,7 @@ public: #endif return _value(idx); } - const T& operator[](size_t idx) const { + [[nodiscard]] const T& operator[](size_t idx) const { #ifndef NDEBUG if (idx >= x0_size) { Log.report(logvisor::Fatal, fmt("out of bounds access on reserved_vector.")); @@ -587,32 +591,36 @@ public: void set_size(size_t n) { x0_size = n; } void set_data(T* data) { x4_data = data; } - size_t size() const noexcept { return x0_size; } - bool empty() const noexcept { return x0_size == 0; } - const T* data() const noexcept { return x4_data; } - T* data() noexcept { return x4_data; } + [[nodiscard]] size_t size() const noexcept { return x0_size; } + [[nodiscard]] bool empty() const noexcept { return x0_size == 0; } + [[nodiscard]] const T* data() const noexcept { return x4_data; } + [[nodiscard]] T* data() noexcept { return x4_data; } - T& back() { return _value(x0_size - 1); } - T& front() { return _value(0); } - const T& back() const { return _value(x0_size - 1); } - const T& front() const { return _value(0); } + [[nodiscard]] T& back() { return _value(x0_size - 1); } + [[nodiscard]] T& front() { return _value(0); } + [[nodiscard]] const T& back() const { return _value(x0_size - 1); } + [[nodiscard]] const T& front() const { return _value(0); } - const_iterator begin() const noexcept { return const_iterator(std::addressof(_value(0))); } - const_iterator end() const noexcept { return const_iterator(std::addressof(_value(x0_size))); } - iterator begin() noexcept { return iterator(std::addressof(_value(0))); } - iterator end() noexcept { return iterator(std::addressof(_value(x0_size))); } - const_iterator cbegin() const noexcept { return begin(); } - const_iterator cend() const noexcept { return end(); } + [[nodiscard]] const_iterator begin() const noexcept { return const_iterator(std::addressof(_value(0))); } + [[nodiscard]] const_iterator end() const noexcept { return const_iterator(std::addressof(_value(x0_size))); } + [[nodiscard]] iterator begin() noexcept { return iterator(std::addressof(_value(0))); } + [[nodiscard]] iterator end() noexcept { return iterator(std::addressof(_value(x0_size))); } + [[nodiscard]] const_iterator cbegin() const noexcept { return begin(); } + [[nodiscard]] const_iterator cend() const noexcept { return end(); } - const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(std::addressof(_value(x0_size - 1))); } - const_reverse_iterator rend() const noexcept { return const_reverse_iterator(std::addressof(_value(-1))); } - reverse_iterator rbegin() noexcept { return reverse_iterator(std::addressof(_value(x0_size - 1))); } - reverse_iterator rend() noexcept { return reverse_iterator(std::addressof(_value(-1))); } - const_reverse_iterator crbegin() const noexcept { return rbegin(); } - const_reverse_iterator crend() const noexcept { return rend(); } + [[nodiscard]] const_reverse_iterator rbegin() const noexcept { + return const_reverse_iterator(std::addressof(_value(x0_size - 1))); + } + [[nodiscard]] const_reverse_iterator rend() const noexcept { + return const_reverse_iterator(std::addressof(_value(-1))); + } + [[nodiscard]] reverse_iterator rbegin() noexcept { return reverse_iterator(std::addressof(_value(x0_size - 1))); } + [[nodiscard]] reverse_iterator rend() noexcept { return reverse_iterator(std::addressof(_value(-1))); } + [[nodiscard]] const_reverse_iterator crbegin() const noexcept { return rbegin(); } + [[nodiscard]] const_reverse_iterator crend() const noexcept { return rend(); } - T& operator[](size_t idx) { return _value(idx); } - const T& operator[](size_t idx) const { return _value(idx); } + [[nodiscard]] T& operator[](size_t idx) { return _value(idx); } + [[nodiscard]] const T& operator[](size_t idx) const { return _value(idx); } }; template diff --git a/hecl b/hecl index db10f0c2c..0b42de34d 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit db10f0c2ca2ea4ab4b779798b041b3bae0d79937 +Subproject commit 0b42de34d0439ed46e393e0bb6de1b02641399a1