Another PAK indexing fix

This commit is contained in:
Jack Andersen 2015-09-23 17:57:45 -10:00
parent d6ce7559b9
commit cf1c7e4781
8 changed files with 113 additions and 296 deletions

View File

@ -59,35 +59,132 @@ struct UniqueResult
UNIQUE_LEVEL, UNIQUE_LEVEL,
UNIQUE_AREA, UNIQUE_AREA,
UNIQUE_LAYER UNIQUE_LAYER
} type = UNIQUE_NOTFOUND; } m_type = UNIQUE_NOTFOUND;
const HECL::SystemString* levelName = nullptr; const HECL::SystemString* m_levelName = nullptr;
const HECL::SystemString* areaName = nullptr; const HECL::SystemString* m_areaName = nullptr;
const HECL::SystemString* layerName = nullptr; const HECL::SystemString* m_layerName = nullptr;
UniqueResult() = default; UniqueResult() = default;
UniqueResult(Type tp) : type(tp) {} UniqueResult(Type tp) : m_type(tp) {}
template<class PAKBRIDGE>
void checkEntry(const PAKBRIDGE& pakBridge, const typename PAKBRIDGE::PAKType::Entry& entry)
{
UniqueResult::Type resultType = UniqueResult::UNIQUE_NOTFOUND;
bool foundOneLayer = false;
const HECL::SystemString* levelName = nullptr;
typename PAKBRIDGE::PAKType::IDType levelId;
typename PAKBRIDGE::PAKType::IDType areaId;
unsigned layerIdx;
for (const auto& lpair : pakBridge.m_levelDeps)
{
if (entry.id == lpair.first)
{
levelName = &lpair.second.name;
resultType = UniqueResult::UNIQUE_LEVEL;
break;
}
for (const auto& pair : lpair.second.areas)
{
unsigned l=0;
for (const auto& layer : pair.second.layers)
{
if (layer.resources.find(entry.id) != layer.resources.end())
{
if (foundOneLayer)
{
if (areaId == pair.first)
{
resultType = UniqueResult::UNIQUE_AREA;
}
else if (levelId == lpair.first)
{
resultType = UniqueResult::UNIQUE_LEVEL;
break;
}
else
{
m_type = UniqueResult::UNIQUE_PAK;
return;
}
continue;
}
else
resultType = UniqueResult::UNIQUE_LAYER;
levelName = &lpair.second.name;
levelId = lpair.first;
areaId = pair.first;
layerIdx = l;
foundOneLayer = true;
}
++l;
}
if (pair.second.resources.find(entry.id) != pair.second.resources.end())
{
if (foundOneLayer)
{
if (areaId == pair.first)
{
resultType = UniqueResult::UNIQUE_AREA;
}
else if (levelId == lpair.first)
{
resultType = UniqueResult::UNIQUE_LEVEL;
break;
}
else
{
m_type = UniqueResult::UNIQUE_PAK;
return;
}
continue;
}
else
resultType = UniqueResult::UNIQUE_AREA;
levelName = &lpair.second.name;
levelId = lpair.first;
areaId = pair.first;
foundOneLayer = true;
}
}
}
m_type = resultType;
m_levelName = levelName;
if (resultType == UniqueResult::UNIQUE_LAYER || resultType == UniqueResult::UNIQUE_AREA)
{
const typename PAKBRIDGE::Level::Area& area = pakBridge.m_levelDeps.at(levelId).areas.at(areaId);
m_areaName = &area.name;
if (resultType == UniqueResult::UNIQUE_LAYER)
{
const typename PAKBRIDGE::Level::Area::Layer& layer = area.layers[layerIdx];
m_layerName = &layer.name;
}
}
}
HECL::ProjectPath uniquePath(const HECL::ProjectPath& pakPath) const HECL::ProjectPath uniquePath(const HECL::ProjectPath& pakPath) const
{ {
if (type == UNIQUE_PAK) if (m_type == UNIQUE_PAK)
return pakPath; return pakPath;
HECL::ProjectPath levelDir; HECL::ProjectPath levelDir;
if (levelName) if (m_levelName)
levelDir.assign(pakPath, *levelName); levelDir.assign(pakPath, *m_levelName);
else else
levelDir = pakPath; levelDir = pakPath;
levelDir.makeDir(); levelDir.makeDir();
if (type == UNIQUE_AREA) if (m_type == UNIQUE_AREA)
{ {
HECL::ProjectPath areaDir(levelDir, *areaName); HECL::ProjectPath areaDir(levelDir, *m_areaName);
areaDir.makeDir(); areaDir.makeDir();
return areaDir; return areaDir;
} }
else if (type == UNIQUE_LAYER) else if (m_type == UNIQUE_LAYER)
{ {
HECL::ProjectPath areaDir(levelDir, *areaName); HECL::ProjectPath areaDir(levelDir, *m_areaName);
areaDir.makeDir(); areaDir.makeDir();
HECL::ProjectPath layerDir(areaDir, *layerName); HECL::ProjectPath layerDir(areaDir, *m_layerName);
layerDir.makeDir(); layerDir.makeDir();
return layerDir; return layerDir;
} }

View File

@ -52,98 +52,6 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar
} }
} }
UniqueResult PAKBridge::uniqueCheck(const PAK::Entry& entry)
{
UniqueResult::Type result = UniqueResult::UNIQUE_NOTFOUND;
bool foundOneLayer = false;
const HECL::SystemString* levelName = nullptr;
UniqueID32 levelId;
UniqueID32 areaId;
unsigned layerIdx;
for (const auto& lpair : m_levelDeps)
{
levelName = &lpair.second.name;
if (entry.id == lpair.first)
{
result = UniqueResult::UNIQUE_LEVEL;
break;
}
for (const auto& pair : lpair.second.areas)
{
unsigned l=0;
for (const auto& layer : pair.second.layers)
{
if (layer.resources.find(entry.id) != layer.resources.end())
{
if (foundOneLayer)
{
if (areaId == pair.first)
{
result = UniqueResult::UNIQUE_AREA;
}
else if (levelId == lpair.first)
{
result = UniqueResult::UNIQUE_LEVEL;
break;
}
else
{
return {UniqueResult::UNIQUE_PAK};
}
continue;
}
else
result = UniqueResult::UNIQUE_LAYER;
levelId = lpair.first;
areaId = pair.first;
layerIdx = l;
foundOneLayer = true;
}
++l;
}
if (pair.second.resources.find(entry.id) != pair.second.resources.end())
{
if (foundOneLayer)
{
if (areaId == pair.first)
{
result = UniqueResult::UNIQUE_AREA;
}
else if (levelId == lpair.first)
{
result = UniqueResult::UNIQUE_LEVEL;
break;
}
else
{
return {UniqueResult::UNIQUE_PAK};
}
continue;
}
else
result = UniqueResult::UNIQUE_AREA;
levelId = lpair.first;
areaId = pair.first;
foundOneLayer = true;
}
}
}
UniqueResult retval = {result};
retval.levelName = levelName;
if (result == UniqueResult::UNIQUE_LAYER || result == UniqueResult::UNIQUE_AREA)
{
const PAKBridge::Level::Area& area = m_levelDeps[levelId].areas[areaId];
retval.areaName = &area.name;
if (result == UniqueResult::UNIQUE_LAYER)
{
const PAKBridge::Level::Area::Layer& layer = area.layers[layerIdx];
retval.layerName = &layer.name;
}
}
return retval;
}
static HECL::SystemString LayerName(const std::string& name) static HECL::SystemString LayerName(const std::string& name)
{ {
#if HECL_UCS2 #if HECL_UCS2
@ -265,7 +173,7 @@ void PAKBridge::build()
/* Second pass: cross-compare uniqueness */ /* Second pass: cross-compare uniqueness */
for (PAK::Entry& entry : m_pak.m_entries) for (PAK::Entry& entry : m_pak.m_entries)
{ {
entry.unique = uniqueCheck(entry); entry.unique.checkEntry(*this, entry);
} }
} }

View File

@ -17,7 +17,6 @@ class PAKBridge
HECL::Database::Project& m_project; HECL::Database::Project& m_project;
const NOD::DiscBase::IPartition::Node& m_node; const NOD::DiscBase::IPartition::Node& m_node;
PAK m_pak; PAK m_pak;
UniqueResult uniqueCheck(const PAK::Entry& entry);
public: public:
struct Level struct Level
{ {

View File

@ -50,98 +50,6 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar
} }
} }
UniqueResult PAKBridge::uniqueCheck(const DNAMP1::PAK::Entry& entry)
{
UniqueResult::Type result = UniqueResult::UNIQUE_NOTFOUND;
bool foundOneLayer = false;
const HECL::SystemString* levelName = nullptr;
UniqueID32 levelId;
UniqueID32 areaId;
unsigned layerIdx;
for (const auto& lpair : m_levelDeps)
{
levelName = &lpair.second.name;
if (entry.id == lpair.first)
{
result = UniqueResult::UNIQUE_LEVEL;
break;
}
for (const auto& pair : lpair.second.areas)
{
unsigned l=0;
for (const auto& layer : pair.second.layers)
{
if (layer.resources.find(entry.id) != layer.resources.end())
{
if (foundOneLayer)
{
if (areaId == pair.first)
{
result = UniqueResult::UNIQUE_AREA;
}
else if (levelId == lpair.first)
{
result = UniqueResult::UNIQUE_LEVEL;
break;
}
else
{
return {UniqueResult::UNIQUE_PAK};
}
continue;
}
else
result = UniqueResult::UNIQUE_LAYER;
levelId = lpair.first;
areaId = pair.first;
layerIdx = l;
foundOneLayer = true;
}
++l;
}
if (pair.second.resources.find(entry.id) != pair.second.resources.end())
{
if (foundOneLayer)
{
if (areaId == pair.first)
{
result = UniqueResult::UNIQUE_AREA;
}
else if (levelId == lpair.first)
{
result = UniqueResult::UNIQUE_LEVEL;
break;
}
else
{
return {UniqueResult::UNIQUE_PAK};
}
continue;
}
else
result = UniqueResult::UNIQUE_AREA;
levelId = lpair.first;
areaId = pair.first;
foundOneLayer = true;
}
}
}
UniqueResult retval = {result};
retval.levelName = levelName;
if (result == UniqueResult::UNIQUE_LAYER || result == UniqueResult::UNIQUE_AREA)
{
const PAKBridge::Level::Area& area = m_levelDeps[levelId].areas[areaId];
retval.areaName = &area.name;
if (result == UniqueResult::UNIQUE_LAYER)
{
const PAKBridge::Level::Area::Layer& layer = area.layers[layerIdx];
retval.layerName = &layer.name;
}
}
return retval;
}
static HECL::SystemString LayerName(const std::string& name) static HECL::SystemString LayerName(const std::string& name)
{ {
#if HECL_UCS2 #if HECL_UCS2
@ -271,7 +179,7 @@ void PAKBridge::build()
/* Second pass: cross-compare uniqueness */ /* Second pass: cross-compare uniqueness */
for (DNAMP1::PAK::Entry& entry : m_pak.m_entries) for (DNAMP1::PAK::Entry& entry : m_pak.m_entries)
{ {
entry.unique = uniqueCheck(entry); entry.unique.checkEntry(*this, entry);
} }
} }

View File

@ -17,7 +17,6 @@ class PAKBridge
HECL::Database::Project& m_project; HECL::Database::Project& m_project;
const NOD::DiscBase::IPartition::Node& m_node; const NOD::DiscBase::IPartition::Node& m_node;
DNAMP1::PAK m_pak; DNAMP1::PAK m_pak;
UniqueResult uniqueCheck(const DNAMP1::PAK::Entry& entry);
public: public:
struct Level struct Level
{ {

View File

@ -59,98 +59,6 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar
} }
} }
UniqueResult PAKBridge::uniqueCheck(const PAK::Entry& entry)
{
UniqueResult::Type result = UniqueResult::UNIQUE_NOTFOUND;
bool foundOneLayer = false;
const HECL::SystemString* levelName = nullptr;
UniqueID64 levelId;
UniqueID64 areaId;
unsigned layerIdx;
for (const auto& lpair : m_levelDeps)
{
levelName = &lpair.second.name;
if (entry.id == lpair.first)
{
result = UniqueResult::UNIQUE_LEVEL;
break;
}
for (const auto& pair : lpair.second.areas)
{
unsigned l=0;
for (const auto& layer : pair.second.layers)
{
if (layer.resources.find(entry.id) != layer.resources.end())
{
if (foundOneLayer)
{
if (areaId == pair.first)
{
result = UniqueResult::UNIQUE_AREA;
}
else if (levelId == lpair.first)
{
result = UniqueResult::UNIQUE_LEVEL;
break;
}
else
{
return {UniqueResult::UNIQUE_PAK};
}
continue;
}
else
result = UniqueResult::UNIQUE_LAYER;
levelId = lpair.first;
areaId = pair.first;
layerIdx = l;
foundOneLayer = true;
}
++l;
}
if (pair.second.resources.find(entry.id) != pair.second.resources.end())
{
if (foundOneLayer)
{
if (areaId == pair.first)
{
result = UniqueResult::UNIQUE_AREA;
}
else if (levelId == lpair.first)
{
result = UniqueResult::UNIQUE_LEVEL;
break;
}
else
{
return {UniqueResult::UNIQUE_PAK};
}
continue;
}
else
result = UniqueResult::UNIQUE_AREA;
levelId = lpair.first;
areaId = pair.first;
foundOneLayer = true;
}
}
}
UniqueResult retval = {result};
retval.levelName = levelName;
if (result == UniqueResult::UNIQUE_LAYER || result == UniqueResult::UNIQUE_AREA)
{
const PAKBridge::Level::Area& area = m_levelDeps[levelId].areas[areaId];
retval.areaName = &area.name;
if (result == UniqueResult::UNIQUE_LAYER)
{
const PAKBridge::Level::Area::Layer& layer = area.layers[layerIdx];
retval.layerName = &layer.name;
}
}
return retval;
}
static HECL::SystemString LayerName(const std::string& name) static HECL::SystemString LayerName(const std::string& name)
{ {
#if HECL_UCS2 #if HECL_UCS2
@ -285,7 +193,7 @@ void PAKBridge::build()
/* Second pass: cross-compare uniqueness */ /* Second pass: cross-compare uniqueness */
for (PAK::Entry& entry : m_pak.m_entries) for (PAK::Entry& entry : m_pak.m_entries)
{ {
entry.unique = uniqueCheck(entry); entry.unique.checkEntry(*this, entry);
} }
} }

View File

@ -17,7 +17,6 @@ class PAKBridge
HECL::Database::Project& m_project; HECL::Database::Project& m_project;
const NOD::DiscBase::IPartition::Node& m_node; const NOD::DiscBase::IPartition::Node& m_node;
PAK m_pak; PAK m_pak;
UniqueResult uniqueCheck(const PAK::Entry& entry);
public: public:
struct Level struct Level
{ {

View File

@ -332,7 +332,6 @@ bool MREA::ExtractLayerDeps(PAKEntryReadStream& rs, PAKBridge::Level::Area& area
DEPS deps; DEPS deps;
deps.read(drs); deps.read(drs);
printf("%d\n", deps.depLayerCount);
unsigned r=0; unsigned r=0;
for (unsigned l=1 ; l<deps.depLayerCount ; ++l) for (unsigned l=1 ; l<deps.depLayerCount ; ++l)
{ {