Added MREA index to dir name

This commit is contained in:
Jack Andersen 2015-09-28 20:09:22 -10:00
parent b0f907ee51
commit e6fb4f36cf
3 changed files with 19 additions and 104 deletions

View File

@ -88,27 +88,8 @@ void PAKBridge::build()
level.areas.reserve(mlvl.areaCount); level.areas.reserve(mlvl.areaCount);
unsigned layerIdx = 0; unsigned layerIdx = 0;
/* Pre-pass: find duplicate area names */ /* Index areas */
std::unordered_map<HECL::SystemString, std::pair<atUint32, atUint32>> dupeTracker; unsigned ai = 0;
dupeTracker.reserve(mlvl.areas.size());
for (const MLVL::Area& area : mlvl.areas)
{
const PAK::Entry* areaNameEnt = m_pak.lookupEntry(area.areaNameId);
if (areaNameEnt)
{
STRG areaName;
PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node);
areaName.read(rs);
HECL::SystemString name = areaName.getSystemString(FOURCC('ENGL'), 0);
auto search = dupeTracker.find(name);
if (search != dupeTracker.end())
++search->second.first;
else
dupeTracker[name] = std::make_pair(1, 1);
}
}
/* Main-pass: index areas */
for (const MLVL::Area& area : mlvl.areas) for (const MLVL::Area& area : mlvl.areas)
{ {
Level::Area& areaDeps = level.areas[area.areaMREAId]; Level::Area& areaDeps = level.areas[area.areaMREAId];
@ -119,13 +100,6 @@ void PAKBridge::build()
PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node); PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node);
areaName.read(rs); areaName.read(rs);
areaDeps.name = areaName.getSystemString(FOURCC('ENGL'), 0); areaDeps.name = areaName.getSystemString(FOURCC('ENGL'), 0);
auto search = dupeTracker.find(areaDeps.name);
if (search != dupeTracker.end() && search->second.first > 1)
{
HECL::SystemChar num[16];
HECL::SNPrintf(num, 16, _S(" (%d)"), search->second.second++);
areaDeps.name += num;
}
/* Trim possible trailing whitespace */ /* Trim possible trailing whitespace */
#if HECL_UCS2 #if HECL_UCS2
@ -144,6 +118,9 @@ void PAKBridge::build()
areaDeps.name = "MREA_" + area.areaMREAId.toString(); areaDeps.name = "MREA_" + area.areaMREAId.toString();
#endif #endif
} }
HECL::SystemChar num[16];
HECL::SNPrintf(num, 16, _S("%02u "), ai++);
areaDeps.name = num + areaDeps.name;
areaDeps.layers.reserve(area.depLayerCount-1); areaDeps.layers.reserve(area.depLayerCount-1);
unsigned r=0; unsigned r=0;

View File

@ -85,27 +85,8 @@ void PAKBridge::build()
level.areas.reserve(mlvl.areaCount); level.areas.reserve(mlvl.areaCount);
unsigned layerIdx = 0; unsigned layerIdx = 0;
/* Pre-pass: find duplicate area names */ /* Index areas */
std::unordered_map<HECL::SystemString, std::pair<atUint32, atUint32>> dupeTracker; unsigned ai = 0;
dupeTracker.reserve(mlvl.areas.size());
for (const MLVL::Area& area : mlvl.areas)
{
const DNAMP1::PAK::Entry* areaNameEnt = m_pak.lookupEntry(area.areaNameId);
if (areaNameEnt)
{
STRG areaName;
PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node);
areaName.read(rs);
HECL::SystemString name = areaName.getSystemString(FOURCC('ENGL'), 0);
auto search = dupeTracker.find(name);
if (search != dupeTracker.end())
++search->second.first;
else
dupeTracker[name] = std::make_pair(1, 1);
}
}
/* Main-pass: index areas */
for (const MLVL::Area& area : mlvl.areas) for (const MLVL::Area& area : mlvl.areas)
{ {
Level::Area& areaDeps = level.areas[area.areaMREAId]; Level::Area& areaDeps = level.areas[area.areaMREAId];
@ -116,13 +97,6 @@ void PAKBridge::build()
PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node); PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node);
areaName.read(rs); areaName.read(rs);
areaDeps.name = areaName.getSystemString(FOURCC('ENGL'), 0); areaDeps.name = areaName.getSystemString(FOURCC('ENGL'), 0);
auto search = dupeTracker.find(areaDeps.name);
if (search != dupeTracker.end() && search->second.first > 1)
{
HECL::SystemChar num[16];
HECL::SNPrintf(num, 16, _S(" (%d)"), search->second.second++);
areaDeps.name += num;
}
/* Trim possible trailing whitespace */ /* Trim possible trailing whitespace */
#if HECL_UCS2 #if HECL_UCS2
@ -135,20 +109,15 @@ void PAKBridge::build()
} }
if (areaDeps.name.empty()) if (areaDeps.name.empty())
{ {
#if HECL_UCS2
areaDeps.name = HECL::UTF8ToWide(area.internalAreaName);
#else
areaDeps.name = area.internalAreaName;
#endif
if (areaDeps.name.empty())
{
#if HECL_UCS2 #if HECL_UCS2
areaDeps.name = _S("MREA_") + HECL::UTF8ToWide(area.areaMREAId.toString()); areaDeps.name = _S("MREA_") + HECL::UTF8ToWide(area.areaMREAId.toString());
#else #else
areaDeps.name = "MREA_" + area.areaMREAId.toString(); areaDeps.name = "MREA_" + area.areaMREAId.toString();
#endif #endif
} }
} HECL::SystemChar num[16];
HECL::SNPrintf(num, 16, _S("%02u "), ai++);
areaDeps.name = num + areaDeps.name;
areaDeps.layers.reserve(area.depLayerCount-1); areaDeps.layers.reserve(area.depLayerCount-1);
unsigned r=0; unsigned r=0;

View File

@ -94,27 +94,8 @@ void PAKBridge::build()
level.areas.reserve(mlvl.areaCount); level.areas.reserve(mlvl.areaCount);
unsigned layerIdx = 0; unsigned layerIdx = 0;
/* Pre-pass: find duplicate area names */ /* Index areas */
std::unordered_map<HECL::SystemString, std::pair<atUint32, atUint32>> dupeTracker; unsigned ai = 0;
dupeTracker.reserve(mlvl.areas.size());
for (const MLVL::Area& area : mlvl.areas)
{
const PAK::Entry* areaNameEnt = m_pak.lookupEntry(area.areaNameId);
if (areaNameEnt)
{
STRG areaName;
PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node);
areaName.read(rs);
HECL::SystemString name = areaName.getSystemString(FOURCC('ENGL'), 0);
auto search = dupeTracker.find(name);
if (search != dupeTracker.end())
++search->second.first;
else
dupeTracker[name] = std::make_pair(1, 1);
}
}
/* Main-pass: index areas */
auto layerFlagsIt = mlvl.layerFlags.begin(); auto layerFlagsIt = mlvl.layerFlags.begin();
for (const MLVL::Area& area : mlvl.areas) for (const MLVL::Area& area : mlvl.areas)
{ {
@ -126,13 +107,6 @@ void PAKBridge::build()
PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node); PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node);
areaName.read(rs); areaName.read(rs);
areaDeps.name = areaName.getSystemString(FOURCC('ENGL'), 0); areaDeps.name = areaName.getSystemString(FOURCC('ENGL'), 0);
auto search = dupeTracker.find(areaDeps.name);
if (search != dupeTracker.end() && search->second.first > 1)
{
HECL::SystemChar num[16];
HECL::SNPrintf(num, 16, _S(" (%d)"), search->second.second++);
areaDeps.name += num;
}
/* Trim possible trailing whitespace */ /* Trim possible trailing whitespace */
#if HECL_UCS2 #if HECL_UCS2
@ -145,20 +119,15 @@ void PAKBridge::build()
} }
if (areaDeps.name.empty()) if (areaDeps.name.empty())
{ {
#if HECL_UCS2
areaDeps.name = HECL::UTF8ToWide(area.internalAreaName);
#else
areaDeps.name = area.internalAreaName;
#endif
if (areaDeps.name.empty())
{
#if HECL_UCS2 #if HECL_UCS2
areaDeps.name = _S("MREA_") + HECL::UTF8ToWide(area.areaMREAId.toString()); areaDeps.name = _S("MREA_") + HECL::UTF8ToWide(area.areaMREAId.toString());
#else #else
areaDeps.name = "MREA_" + area.areaMREAId.toString(); areaDeps.name = "MREA_" + area.areaMREAId.toString();
#endif #endif
} }
} HECL::SystemChar num[16];
HECL::SNPrintf(num, 16, _S("%02u "), ai++);
areaDeps.name = num + areaDeps.name;
const MLVL::LayerFlags& areaLayers = *layerFlagsIt++; const MLVL::LayerFlags& areaLayers = *layerFlagsIt++;
if (areaLayers.layerCount) if (areaLayers.layerCount)