initial atdna run

This commit is contained in:
Jack Andersen 2015-07-05 16:07:57 -10:00
parent 6c0b9785d0
commit 8cc3c014e6
7 changed files with 256 additions and 24 deletions

View File

@ -23,6 +23,7 @@ public:
inline bool operator!=(const UniqueID32& other) const {return m_id != other.m_id;}
inline bool operator==(const UniqueID32& other) const {return m_id == other.m_id;}
inline uint32_t toUint32() const {return m_id;}
inline std::string toString() const
{
char buf[9];
@ -44,10 +45,11 @@ public:
inline bool operator!=(const UniqueID64& other) const {return m_id != other.m_id;}
inline bool operator==(const UniqueID64& other) const {return m_id == other.m_id;}
inline uint64_t toUint64() const {return m_id;}
inline std::string toString() const
{
char buf[17];
snprintf(buf, 17, "%16X", m_id);
snprintf(buf, 17, "%16lX", m_id);
return std::string(buf);
}
};
@ -78,7 +80,9 @@ public:
inline bool operator!=(const UniqueID128& other) const
{
#if __SSE__
return m_id128 != other.m_id128;
__m128i vcmp = _mm_cmpeq_epi32(m_id128, other.m_id128);
int vmask = _mm_movemask_epi8(vcmp);
return vmask != 0xffff;
#else
return (m_id[0] != other.m_id[0]) || (m_id[1] != other.m_id[1]);
#endif
@ -86,15 +90,19 @@ public:
inline bool operator==(const UniqueID128& other) const
{
#if __SSE__
return m_id128 == other.m_id128;
__m128i vcmp = _mm_cmpeq_epi32(m_id128, other.m_id128);
int vmask = _mm_movemask_epi8(vcmp);
return vmask == 0xffff;
#else
return (m_id[0] == other.m_id[0]) && (m_id[1] == other.m_id[1]);
#endif
}
inline uint64_t toHighUint64() const {return m_id[0];}
inline uint64_t toLowUint64() const {return m_id[1];}
inline std::string toString() const
{
char buf[33];
snprintf(buf, 33, "%16X%16X", m_id[0], m_id[1]);
snprintf(buf, 33, "%16lX%16lX", m_id[0], m_id[1]);
return std::string(buf);
}
};
@ -108,21 +116,21 @@ template<>
struct hash<Retro::UniqueID32>
{
inline size_t operator()(const Retro::UniqueID32& id) const
{return id.m_id;}
{return id.toUint32();}
};
template<>
struct hash<Retro::UniqueID64>
{
inline size_t operator()(const Retro::UniqueID64& id) const
{return id.m_id;}
{return id.toUint64();}
};
template<>
struct hash<Retro::UniqueID128>
{
inline size_t operator()(const Retro::UniqueID128& id) const
{return id.m_id[0] ^ id.m_id[1];}
{return id.toHighUint64() ^ id.toLowUint64();}
};
}

View File

@ -1,3 +1,6 @@
HEADERS += \
$$PWD/PAK.hpp \
$$PWD/MLVL.hpp
SOURCES += \
$$PWD/PAK.cpp

65
DataSpec/DNAMP1/PAK.cpp Normal file
View File

@ -0,0 +1,65 @@
/* Auto generated atdna implementation */
#include <Athena/Global.hpp>
#include <Athena/IStreamReader.hpp>
#include <Athena/IStreamWriter.hpp>
#include "PAK.hpp"
void Retro::DNAMP1::PAK::NameEntry::read(Athena::io::IStreamReader& __dna_reader)
{
/* type */
type.read(__dna_reader);
/* id */
id.read(__dna_reader);
__dna_reader.setEndian(Athena::BigEndian);
/* nameLen */
nameLen = __dna_reader.readUint32();
/* name */
name = __dna_reader.readString(nameLen);
}
void Retro::DNAMP1::PAK::NameEntry::write(Athena::io::IStreamWriter& __dna_writer) const
{
/* type */
type.write(__dna_writer);
/* id */
id.write(__dna_writer);
__dna_writer.setEndian(Athena::BigEndian);
/* nameLen */
__dna_writer.writeUint32(nameLen);
/* name */
__dna_writer.writeString(name, nameLen);
}
void Retro::DNAMP1::PAK::Entry::read(Athena::io::IStreamReader& __dna_reader)
{
__dna_reader.setEndian(Athena::BigEndian);
/* compressed */
compressed = __dna_reader.readUint32();
/* type */
type.read(__dna_reader);
/* id */
id.read(__dna_reader);
__dna_reader.setEndian(Athena::BigEndian);
/* size */
size = __dna_reader.readUint32();
/* offset */
offset = __dna_reader.readUint32();
}
void Retro::DNAMP1::PAK::Entry::write(Athena::io::IStreamWriter& __dna_writer) const
{
__dna_writer.setEndian(Athena::BigEndian);
/* compressed */
__dna_writer.writeUint32(compressed);
/* type */
type.write(__dna_writer);
/* id */
id.write(__dna_writer);
__dna_writer.setEndian(Athena::BigEndian);
/* size */
__dna_writer.writeUint32(size);
/* offset */
__dna_writer.writeUint32(offset);
}

View File

@ -16,6 +16,7 @@ class PAK : public BigDNA
public:
struct NameEntry : public BigDNA
{
DECL_DNA
HECL::FourCC type;
UniqueID32 id;
Value<atUint32> nameLen;
@ -24,6 +25,7 @@ public:
struct Entry : public BigDNA
{
DECL_DNA
Value<atUint32> compressed;
HECL::FourCC type;
UniqueID32 id;
@ -72,12 +74,12 @@ public:
m_nameMap.reserve(nameCount);
for (NameEntry& entry : m_nameEntries)
{
Entry* found = m_idMap.find(entry.id);
std::unordered_map<UniqueID32, Entry*>::iterator found = m_idMap.find(entry.id);
if (found != m_idMap.end())
m_nameMap[entry.name] = found;
m_nameMap[entry.name] = found->second;
}
}
void write(Athena::io::IStreamWriter& writer) const
void write(Athena::io::IStreamWriter& writer)
{
writer.setEndian(Athena::BigEndian);
writer.writeUint32(0x00030005);
@ -85,26 +87,29 @@ public:
writer.writeUint32(m_nameEntries.size());
for (NameEntry& entry : m_nameEntries)
{
entry.nameLen = entry.name.size();
entry.write(writer);
}
writer.writeUint32(m_entries.size());
for (Entry& entry : m_entries)
for (const Entry& entry : m_entries)
entry.write(writer);
}
inline const Entry* lookupEntry(const UniqueID32& id) const
{
Entry* result = m_idMap.find(id);
std::unordered_map<UniqueID32, Entry*>::const_iterator result = m_idMap.find(id);
if (result != m_idMap.end())
return result;
return result->second;
return nullptr;
}
inline const Entry* lookupEntry(const std::string& name) const
{
Entry* result = m_nameMap.find(name);
std::unordered_map<std::string, Entry*>::const_iterator result = m_nameMap.find(name);
if (result != m_nameMap.end())
return result;
return result->second;
return nullptr;
}
};

View File

@ -1,2 +1,5 @@
HEADERS += \
$$PWD/PAK.hpp
SOURCES += \
$$PWD/PAK.cpp

145
DataSpec/DNAMP3/PAK.cpp Normal file
View File

@ -0,0 +1,145 @@
/* Auto generated atdna implementation */
#include <Athena/Global.hpp>
#include <Athena/IStreamReader.hpp>
#include <Athena/IStreamWriter.hpp>
#include "PAK.hpp"
void Retro::DNAMP3::PAK::Header::read(Athena::io::IStreamReader& __dna_reader)
{
__dna_reader.setEndian(Athena::BigEndian);
/* version */
version = __dna_reader.readUint32();
/* headSz */
headSz = __dna_reader.readUint32();
/* md5sum[0] */
md5sum[0] = __dna_reader.readUByte();
/* md5sum[1] */
md5sum[1] = __dna_reader.readUByte();
/* md5sum[2] */
md5sum[2] = __dna_reader.readUByte();
/* md5sum[3] */
md5sum[3] = __dna_reader.readUByte();
/* md5sum[4] */
md5sum[4] = __dna_reader.readUByte();
/* md5sum[5] */
md5sum[5] = __dna_reader.readUByte();
/* md5sum[6] */
md5sum[6] = __dna_reader.readUByte();
/* md5sum[7] */
md5sum[7] = __dna_reader.readUByte();
/* md5sum[8] */
md5sum[8] = __dna_reader.readUByte();
/* md5sum[9] */
md5sum[9] = __dna_reader.readUByte();
/* md5sum[10] */
md5sum[10] = __dna_reader.readUByte();
/* md5sum[11] */
md5sum[11] = __dna_reader.readUByte();
/* md5sum[12] */
md5sum[12] = __dna_reader.readUByte();
/* md5sum[13] */
md5sum[13] = __dna_reader.readUByte();
/* md5sum[14] */
md5sum[14] = __dna_reader.readUByte();
/* md5sum[15] */
md5sum[15] = __dna_reader.readUByte();
/* seek */
__dna_reader.seek(40, Athena::Current);
}
void Retro::DNAMP3::PAK::Header::write(Athena::io::IStreamWriter& __dna_writer) const
{
__dna_writer.setEndian(Athena::BigEndian);
/* version */
__dna_writer.writeUint32(version);
/* headSz */
__dna_writer.writeUint32(headSz);
/* md5sum[0] */
__dna_writer.writeUByte(md5sum[0]);
/* md5sum[1] */
__dna_writer.writeUByte(md5sum[1]);
/* md5sum[2] */
__dna_writer.writeUByte(md5sum[2]);
/* md5sum[3] */
__dna_writer.writeUByte(md5sum[3]);
/* md5sum[4] */
__dna_writer.writeUByte(md5sum[4]);
/* md5sum[5] */
__dna_writer.writeUByte(md5sum[5]);
/* md5sum[6] */
__dna_writer.writeUByte(md5sum[6]);
/* md5sum[7] */
__dna_writer.writeUByte(md5sum[7]);
/* md5sum[8] */
__dna_writer.writeUByte(md5sum[8]);
/* md5sum[9] */
__dna_writer.writeUByte(md5sum[9]);
/* md5sum[10] */
__dna_writer.writeUByte(md5sum[10]);
/* md5sum[11] */
__dna_writer.writeUByte(md5sum[11]);
/* md5sum[12] */
__dna_writer.writeUByte(md5sum[12]);
/* md5sum[13] */
__dna_writer.writeUByte(md5sum[13]);
/* md5sum[14] */
__dna_writer.writeUByte(md5sum[14]);
/* md5sum[15] */
__dna_writer.writeUByte(md5sum[15]);
/* seek */
__dna_writer.seek(40, Athena::Current);
}
void Retro::DNAMP3::PAK::NameEntry::read(Athena::io::IStreamReader& __dna_reader)
{
/* name */
name = __dna_reader.readString(-1);
/* type */
type.read(__dna_reader);
/* id */
id.read(__dna_reader);
}
void Retro::DNAMP3::PAK::NameEntry::write(Athena::io::IStreamWriter& __dna_writer) const
{
/* name */
__dna_writer.writeString(name, -1);
/* type */
type.write(__dna_writer);
/* id */
id.write(__dna_writer);
}
void Retro::DNAMP3::PAK::Entry::read(Athena::io::IStreamReader& __dna_reader)
{
__dna_reader.setEndian(Athena::BigEndian);
/* compressed */
compressed = __dna_reader.readUint32();
/* type */
type.read(__dna_reader);
/* id */
id.read(__dna_reader);
__dna_reader.setEndian(Athena::BigEndian);
/* size */
size = __dna_reader.readUint32();
/* offset */
offset = __dna_reader.readUint32();
}
void Retro::DNAMP3::PAK::Entry::write(Athena::io::IStreamWriter& __dna_writer) const
{
__dna_writer.setEndian(Athena::BigEndian);
/* compressed */
__dna_writer.writeUint32(compressed);
/* type */
type.write(__dna_writer);
/* id */
id.write(__dna_writer);
__dna_writer.setEndian(Athena::BigEndian);
/* size */
__dna_writer.writeUint32(size);
/* offset */
__dna_writer.writeUint32(offset);
}

View File

@ -16,6 +16,7 @@ class PAK : public BigDNA
public:
struct Header : public BigDNA
{
DECL_DNA
Value<atUint32> version;
Value<atUint32> headSz;
Value<atUint8> md5sum[16];
@ -24,6 +25,7 @@ public:
struct NameEntry : public BigDNA
{
DECL_DNA
String<-1> name;
HECL::FourCC type;
UniqueID64 id;
@ -31,11 +33,12 @@ public:
struct Entry : public BigDNA
{
atUint32 compressed;
DECL_DNA
Value<atUint32> compressed;
HECL::FourCC type;
UniqueID64 id;
atUint32 size;
atUint32 offset;
Value<atUint32> size;
Value<atUint32> offset;
};
private:
@ -87,9 +90,9 @@ public:
m_nameMap.reserve(nameCount);
for (NameEntry& entry : m_nameEntries)
{
Entry* found = m_idMap.find(entry.id);
std::unordered_map<UniqueID64, Entry*>::iterator found = m_idMap.find(entry.id);
if (found != m_idMap.end())
m_nameMap[entry.name] = found;
m_nameMap[entry.name] = found->second;
}
}
void write(Athena::io::IStreamWriter& writer)
@ -133,17 +136,17 @@ public:
inline const Entry* lookupEntry(const UniqueID64& id) const
{
Entry* result = m_idMap.find(id);
std::unordered_map<UniqueID64, Entry*>::const_iterator result = m_idMap.find(id);
if (result != m_idMap.end())
return result;
return result->second;
return nullptr;
}
inline const Entry* lookupEntry(const std::string& name) const
{
Entry* result = m_nameMap.find(name);
std::unordered_map<std::string, Entry*>::const_iterator result = m_nameMap.find(name);
if (result != m_nameMap.end())
return result;
return result->second;
return nullptr;
}