2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-09 21:47:59 +00:00

various implementation

This commit is contained in:
Jack Andersen
2015-08-22 20:42:29 -10:00
parent 6577d4ca13
commit f3b5b9f49a
45 changed files with 580 additions and 84 deletions

View File

@@ -18,15 +18,15 @@ typedef Athena::io::DNA<Athena::BigEndian> BigDNA;
typedef Athena::io::DNAYaml<Athena::BigEndian> BigYAML;
/* FourCC with DNA read/write */
class FourCC final : public BigYAML, public HECL::FourCC
class DNAFourCC final : public BigYAML, public HECL::FourCC
{
public:
FourCC() : HECL::FourCC() {}
FourCC(const HECL::FourCC& other)
DNAFourCC() : HECL::FourCC() {}
DNAFourCC(const HECL::FourCC& other)
: HECL::FourCC() {num = other.toUint32();}
FourCC(const char* name)
DNAFourCC(const char* name)
: HECL::FourCC(name) {}
FourCC(uint32_t n)
DNAFourCC(uint32_t n)
: HECL::FourCC(n) {}
Delete expl;
@@ -40,6 +40,8 @@ public:
{writer.writeString(nullptr, std::string(fcc, 4));}
};
using FourCC = HECL::FourCC;
/* PAK 32-bit Unique ID */
class UniqueID32 : public BigYAML
{
@@ -243,9 +245,9 @@ typedef std::function<bool(const HECL::ProjectPath&, const HECL::ProjectPath&)>
namespace std
{
template<>
struct hash<Retro::FourCC>
struct hash<Retro::DNAFourCC>
{
inline size_t operator()(const Retro::FourCC& fcc) const
inline size_t operator()(const Retro::DNAFourCC& fcc) const
{return fcc.toUint32();}
};

View File

@@ -130,7 +130,7 @@ struct ANCS : BigYAML
{
DECL_YAML
String<-1> name;
FourCC type;
DNAFourCC type;
UniqueID32 id;
String<-1> name2;
Value<float> unk1;

View File

@@ -23,7 +23,7 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar
/* Append Level String */
for (const PAK::Entry& entry : m_pak.m_entries)
{
if (entry.type == SBIG('MLVL'))
if (entry.type == FOURCC('MLVL'))
{
PAKEntryReadStream rs = entry.beginReadStream(m_node);
MLVL mlvl;
@@ -119,7 +119,7 @@ void PAKBridge::build()
/* First pass: build per-area/per-layer dependency map */
for (const PAK::Entry& entry : m_pak.m_entries)
{
if (entry.type == SBIG('MLVL'))
if (entry.type == FOURCC('MLVL'))
{
PAKEntryReadStream rs = entry.beginReadStream(m_node);
MLVL mlvl;

View File

@@ -48,7 +48,7 @@ struct EVNT : BigYAML
{
DECL_YAML
Value<atUint32> frameCount;
FourCC effectType;
DNAFourCC effectType;
UniqueID32 effectId;
String<-1> boneName;
Value<float> scale;

View File

@@ -48,7 +48,7 @@ struct MLVL : BigYAML
{
DECL_YAML
UniqueID32 id;
FourCC type;
DNAFourCC type;
};
Vector<Dependency, DNA_COUNT(depCount)> deps;

View File

@@ -20,7 +20,7 @@ struct PAK : BigDNA
struct NameEntry : BigDNA
{
DECL_DNA
FourCC type;
DNAFourCC type;
UniqueID32 id;
Value<atUint32> nameLen;
String<DNA_COUNT(nameLen)> name;
@@ -30,7 +30,7 @@ struct PAK : BigDNA
{
DECL_DNA
Value<atUint32> compressed;
FourCC type;
DNAFourCC type;
UniqueID32 id;
Value<atUint32> size;
Value<atUint32> offset;

View File

@@ -15,7 +15,7 @@ void STRG::_read(Athena::io::IStreamReader& reader)
readLangs.reserve(langCount);
for (atUint32 l=0 ; l<langCount ; ++l)
{
FourCC lang;
DNAFourCC lang;
lang.read(reader);
readLangs.emplace_back(lang);
reader.seek(4);
@@ -62,7 +62,7 @@ void STRG::write(Athena::io::IStreamWriter& writer) const
atUint32 offset = 0;
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
{
lang.first.write(writer);
DNAFourCC(lang.first).write(writer);
writer.writeUint32Big(offset);
offset += strCount * 4 + 4;
atUint32 langStrCount = lang.second.size();

View File

@@ -74,7 +74,7 @@ struct ANCS : BigYAML
{
DECL_YAML
String<-1> name;
FourCC type;
DNAFourCC type;
UniqueID32 id;
Value<atUint32> unkMP2;
Value<float> unk1;
@@ -162,7 +162,7 @@ struct ANCS : BigYAML
{
DECL_YAML
Value<atUint32> frameCount;
FourCC effectType;
DNAFourCC effectType;
UniqueID32 effectId;
Value<atUint32> boneId;
Value<float> scale;

View File

@@ -22,7 +22,7 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar
/* Append Level String */
for (const DNAMP1::PAK::Entry& entry : m_pak.m_entries)
{
if (entry.type == SBIG('MLVL'))
if (entry.type == FOURCC('MLVL'))
{
PAKEntryReadStream rs = entry.beginReadStream(m_node);
MLVL mlvl;
@@ -118,7 +118,7 @@ void PAKBridge::build()
/* First pass: build per-area/per-layer dependency map */
for (const DNAMP1::PAK::Entry& entry : m_pak.m_entries)
{
if (entry.type == SBIG('MLVL'))
if (entry.type == FOURCC('MLVL'))
{
PAKEntryReadStream rs = entry.beginReadStream(m_node);
MLVL mlvl;

View File

@@ -38,7 +38,7 @@ struct MLVL : BigDNA
{
DECL_DNA
UniqueID32 id;
FourCC type;
DNAFourCC type;
};
Vector<Dependency, DNA_COUNT(depCount)> deps;

View File

@@ -15,7 +15,7 @@ void STRG::_read(Athena::io::IStreamReader& reader)
readLangs.reserve(langCount);
for (atUint32 l=0 ; l<langCount ; ++l)
{
FourCC lang;
DNAFourCC lang;
lang.read(reader);
readLangs.emplace_back(lang);
reader.seek(8);
@@ -75,7 +75,7 @@ void STRG::write(Athena::io::IStreamWriter& writer) const
writer.writeUint32Big(strCount);
atUint32 offset = 0;
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
for (const std::pair<DNAFourCC, std::vector<std::wstring>>& lang : langs)
{
lang.first.write(writer);
writer.writeUint32Big(offset);
@@ -114,7 +114,7 @@ void STRG::write(Athena::io::IStreamWriter& writer) const
for (const std::pair<std::string, int32_t>& name : names)
writer.writeString(name.first);
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
for (const std::pair<DNAFourCC, std::vector<std::wstring>>& lang : langs)
{
offset = strCount * 4;
atUint32 langStrCount = lang.second.size();

View File

@@ -79,7 +79,7 @@ struct MaterialSet : BigDNA
XRAY = SBIG('XRAY'),
TOON = SBIG('TOON')
};
FourCC subtype;
DNAFourCC subtype;
struct Flags : BigDNA
{
DECL_DNA
@@ -106,7 +106,7 @@ struct MaterialSet : BigDNA
CLR = SBIG('CLR '),
DIFB = SBIG('DIFB')
};
FourCC subtype;
DNAFourCC subtype;
GX::Color color;
};
struct SectionINT : ISection
@@ -121,7 +121,7 @@ struct MaterialSet : BigDNA
BNIF = SBIG('BNIF'),
XRBR = SBIG('XRBR')
};
FourCC subtype;
DNAFourCC subtype;
Value<atUint32> value;
};
struct SectionFactory : BigDNA
@@ -130,7 +130,7 @@ struct MaterialSet : BigDNA
std::unique_ptr<ISection> section;
void read(Athena::io::IStreamReader& reader)
{
FourCC type;
DNAFourCC type;
type.read(reader);
switch (type)
{

View File

@@ -24,7 +24,7 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar
std::set<HECL::SystemString, CaseInsensitiveCompare> uniq;
for (const PAK::Entry& entry : m_pak.m_entries)
{
if (entry.type == SBIG('MLVL'))
if (entry.type == FOURCC('MLVL'))
{
PAKEntryReadStream rs = entry.beginReadStream(m_node);
MLVL mlvl;

View File

@@ -62,7 +62,7 @@ void PAK::write(Athena::io::IStreamWriter& writer) const
{
m_header.write(writer);
FourCC("STRG").write(writer);
DNAFourCC("STRG").write(writer);
atUint32 strgSz = 4;
for (const NameEntry& entry : m_nameEntries)
strgSz += (atUint32)entry.name.size() + 13;
@@ -70,14 +70,14 @@ void PAK::write(Athena::io::IStreamWriter& writer) const
strgSz += strgPad;
writer.writeUint32Big(strgSz);
FourCC("RSHD").write(writer);
DNAFourCC("RSHD").write(writer);
atUint32 rshdSz = 4 + 24 * m_entries.size();
atUint32 rshdPad = ((rshdSz + 63) & ~63) - rshdSz;
rshdSz += rshdPad;
writer.writeUint32Big(rshdSz);
atUint32 dataOffset = 128 + strgSz + rshdSz;
FourCC("DATA").write(writer);
DNAFourCC("DATA").write(writer);
atUint32 dataSz = 0;
for (const Entry& entry : m_entries)
dataSz += (entry.size + 63) & ~63;

View File

@@ -29,7 +29,7 @@ struct PAK : BigDNA
{
DECL_DNA
String<-1> name;
FourCC type;
DNAFourCC type;
UniqueID64 id;
};
@@ -37,7 +37,7 @@ struct PAK : BigDNA
{
DECL_DNA
Value<atUint32> compressed;
FourCC type;
DNAFourCC type;
UniqueID64 id;
Value<atUint32> size;
Value<atUint32> offset;

View File

@@ -29,11 +29,11 @@ void STRG::_read(Athena::io::IStreamReader& reader)
}
}
std::vector<FourCC> readLangs;
std::vector<DNAFourCC> readLangs;
readLangs.reserve(langCount);
for (atUint32 l=0 ; l<langCount ; ++l)
{
FourCC lang;
DNAFourCC lang;
lang.read(reader);
readLangs.emplace_back(lang);
}
@@ -62,7 +62,7 @@ void STRG::_read(Athena::io::IStreamReader& reader)
langMap.clear();
langMap.reserve(langCount);
for (std::pair<FourCC, std::vector<std::string>>& item : langs)
for (std::pair<DNAFourCC, std::vector<std::string>>& item : langs)
langMap.emplace(item.first, &item.second);
}
@@ -142,12 +142,12 @@ void STRG::fromYAML(Athena::io::YAMLDocReader& reader)
for (const auto& node : item.second->m_seqChildren)
if (node->m_type == YAML_SCALAR_NODE)
strs.emplace_back(node->m_scalarString);
langs.emplace_back(std::make_pair(FourCC(item.first.c_str()), std::move(strs)));
langs.emplace_back(std::make_pair(DNAFourCC(item.first.c_str()), std::move(strs)));
}
langMap.clear();
langMap.reserve(langs.size());
for (std::pair<FourCC, std::vector<std::string>>& item : langs)
for (std::pair<DNAFourCC, std::vector<std::string>>& item : langs)
langMap.emplace(item.first, &item.second);
}

View File

@@ -15,8 +15,8 @@ struct STRG : ISTRG
DECL_YAML
Delete expl;
void _read(Athena::io::IStreamReader& reader);
std::vector<std::pair<FourCC, std::vector<std::string>>> langs;
std::unordered_map<FourCC, std::vector<std::string>*> langMap;
std::vector<std::pair<DNAFourCC, std::vector<std::string>>> langs;
std::unordered_map<DNAFourCC, std::vector<std::string>*> langMap;
std::map<std::string, int32_t> names;
inline int32_t lookupIdx(const std::string& name) const