Actually implement AssetNameMap in DNAMP1

This commit is contained in:
Phillip Stephens 2020-04-22 03:37:34 -07:00
parent 535717fbd8
commit 59f979db67
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
7 changed files with 30 additions and 18 deletions

View File

@ -66,7 +66,7 @@ void InitAssetNameMap() {
}
const std::string* TranslateIdToName(const UniqueID32& id) {
if (g_AssetNameMap.find(id.toUint64()) == g_AssetNameMap.end())
if (g_AssetNameMap.find(id.toUint64()) == g_AssetNameMap.cend())
return nullptr;
return &g_AssetNameMap[id.toUint64()].name;

View File

@ -145,14 +145,14 @@ public:
atUint32 addedVerts = 0;
atUint32 nextVert = 1;
while (nextVert < m_nextOverPos) {
for (const std::pair<atUint16, std::vector<std::pair<atInt16, atUint16>>>& ev : m_extraVerts) {
for (const std::pair<atInt16, atUint16>& se : ev.second) {
for (const auto& [ev, evVec] : m_extraVerts) {
for (const std::pair<atInt16, atUint16>& se : evVec) {
if (se.second == nextVert) {
os.format(FMT_STRING(
"bm.verts.ensure_lookup_table()\n"
"orig_vert = bm.verts[{}]\n"
"vert = bm.verts.new(orig_vert.co)\n"),
ev.first + baseVert);
ev + baseVert);
rp.first.second->weightVertex(os, *rp.second.second, se.first);
++nextVert;
++addedVerts;

View File

@ -3,6 +3,7 @@
#include "DNAMP1.hpp"
#include "PAK.hpp"
#include "AGSC.hpp"
#include "DataSpec/AssetNameMap.hpp"
namespace DataSpec::DNAMP1 {
@ -31,6 +32,7 @@ void PAK::Enumerate<BigDNA::Read>(typename Read::StreamT& reader) {
for (atUint32 e = 0; e < count; ++e) {
entries.emplace_back();
entries.back().read(reader);
const auto& ent = entries.back();
}
for (atUint32 e = 0; e < count; ++e) {
Entry& entry = entries[e];
@ -176,6 +178,11 @@ std::string PAK::bestEntryName(const nod::Node& pakNode, const Entry& entry, std
}
}
/* Prefer asset name map second */
if (const auto* name = AssetNameMap::TranslateIdToName(entry.id)) {
return fmt::format(FMT_STRING("{}_{}"), *name, entry.id);
}
/* Otherwise return ID format string */
return fmt::format(FMT_STRING("{}_{}"), entry.type, entry.id);
}

View File

@ -36,7 +36,7 @@ CSpankWeed::CSpankWeed(TUniqueId uid, std::string_view name, const CEntityInfo&
SetCallTouch(false);
CreateShadow(false);
zeus::CVector3f modelScale = GetModelData()->GetScale();
const zeus::CVector3f modelScale = GetModelData()->GetScale();
if (modelScale.x() != modelScale.y() || modelScale.x() != modelScale.z()) {
float scale = modelScale.magnitude() / std::sqrt(3.f);

View File

@ -140,7 +140,7 @@ void CScriptPickupGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
float r = stateMgr.GetActiveRandom()->Range(0.f, totalProb);
float f2 = 0.f;
size_t count = 0;
for (const auto id : pickupTemplates) {
for (const auto& id : pickupTemplates) {
if (r >= f2 && r <= f2 + id.first)
break;
f2 += id.first;

View File

@ -190,9 +190,9 @@ int main(int argc, const char* argv[])
tinyxml2::XMLDocument doc;
std::vector<SAsset> assets;
FILE* docF = Fopen(inPath.c_str(), _SYS_STR("rb"));
if (!doc.LoadFile(docF)) {
if (doc.LoadFile(docF) == tinyxml2::XML_SUCCESS) {
const tinyxml2::XMLElement* elm = doc.RootElement();
if (strcmp(elm->Name(), "AssetNameMap")) {
if (strcmp(elm->Name(), "AssetNameMap") != 0) {
Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Invalid database supplied")));
return 1;
}
@ -205,11 +205,11 @@ int main(int argc, const char* argv[])
elm = elm->FirstChildElement("Asset");
while (elm) {
while (elm != nullptr ) {
const tinyxml2::XMLElement* keyElm = elm->FirstChildElement("Key");
const tinyxml2::XMLElement* valueElm = elm->FirstChildElement("Value");
if (!keyElm || !valueElm) {
if (keyElm == nullptr || valueElm == nullptr) {
Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Malformed Asset entry, [Key,Value] required")));
return 0;
}
@ -217,22 +217,27 @@ int main(int argc, const char* argv[])
const tinyxml2::XMLElement* nameElm = valueElm->FirstChildElement("Name");
const tinyxml2::XMLElement* dirElm = valueElm->FirstChildElement("Directory");
const tinyxml2::XMLElement* typeElm = valueElm->FirstChildElement("Type");
const tinyxml2::XMLElement* autoGenNameElm = valueElm->FirstChildElement("AutoGenName");
const tinyxml2::XMLElement* autoGenDirElm = valueElm->FirstChildElement("AutoGenDir");
if (!nameElm || !dirElm || !typeElm) {
if (nameElm == nullptr || dirElm == nullptr || typeElm == nullptr) {
Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Malformed Value entry, [Name,Directory,Type] required")));
return 0;
}
assets.emplace_back();
SAsset& asset = assets.back();
asset.type = typeElm->GetText();
asset.id = strtoull(keyElm->GetText(), nullptr, 16);
asset.name = nameElm->GetText();
asset.dir = dirElm->GetText();
bool autoGen = strncasecmp(autoGenNameElm->GetText(), "true", 4) == 0 && strncasecmp(autoGenDirElm->GetText(), "true", 4) == 0;
if (!autoGen) {
SAsset& asset = assets.back();
asset.type = typeElm->GetText();
asset.id = strtoull(keyElm->GetText(), nullptr, 16);
asset.name = nameElm->GetText();
asset.dir = dirElm->GetText();
}
elm = elm->NextSiblingElement("Asset");
}
FILE* f = Fopen(outPath.c_str(), _SYS_STR("wb"));
if (!f) {
if (f == nullptr) {
Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("Unable to open destination")));
return 0;
}

2
hecl

@ -1 +1 @@
Subproject commit d1ed2b5d4d4ef1a56097492fe8a57c6911adf708
Subproject commit 19fbe8c588cedae1083f986a866e641654d1c1e0