[IMaterial] Find sortkey by comparing techsets

This commit is contained in:
momo5502 2017-05-30 10:52:22 +02:00
parent 3f9a3db442
commit 350c451de8

View File

@ -169,61 +169,40 @@ namespace Assets
} }
}, false, false); }, false, false);
for (int i = 0; i < ARRAYSIZE(techsetSuffix) && !replacementFound && asset->techniqueSet; ++i) if (!replacementFound)
{ {
const char* _name = asset->techniqueSet->name; auto techsetMatches = [](Game::Material* m1, Game::Material* m2)
if (_name[0] == ',') ++_name; {
std::string modifiedTechsetName = _name; Game::MaterialTechniqueSet* t1 = m1->techniqueSet;
Game::MaterialTechniqueSet* t2 = m2->techniqueSet;
if (!t1 || !t2) return false;
if (t1->remappedTechniques && t2->remappedTechniques && std::string(t1->remappedTechniques->name) == t2->remappedTechniques->name) return true;
if (!Utils::String::EndsWith(modifiedTechsetName, techsetSuffix[i])) continue; for (int i = 0; i < ARRAYSIZE(t1->techniques); ++i)
modifiedTechsetName = modifiedTechsetName.substr(0, modifiedTechsetName.size() - strlen(techsetSuffix[i])); {
if (!t1->techniques[i] && !t2->techniques[i]) continue;;
if (!t1->techniques[i] || !t2->techniques[i]) return false;
Game::DB_EnumXAssetEntries(Game::XAssetType::ASSET_TYPE_MATERIAL, [asset, modifiedTechsetName](Game::XAssetEntry* entry) if (t1->techniques[i]->flags != t1->techniques[i]->flags) return false;
}
return true;
};
Game::DB_EnumXAssetEntries(Game::XAssetType::ASSET_TYPE_MATERIAL, [asset, techsetMatches](Game::XAssetEntry* entry)
{ {
if (!replacementFound) if (!replacementFound)
{ {
Game::XAssetHeader header = entry->asset.header; Game::XAssetHeader header = entry->asset.header;
if (modifiedTechsetName == header.material->techniqueSet->name) if (techsetMatches(header.material, asset))
{ {
Components::Logger::Print("Material %s with techset %s has been mapped to %s\n", asset->name, asset->techniqueSet->name, header.material->techniqueSet->name);
asset->sortKey = header.material->sortKey; asset->sortKey = header.material->sortKey;
// This is temp, as nobody has time to fix materials
// asset->stateBitsCount = header.material->stateBitsCount;
// asset->stateBitTable = header.material->stateBitTable;
// std::memcpy(asset->stateBitsEntry, header.material->stateBitsEntry, 48);
// asset->constantCount = header.material->constantCount;
// asset->constantTable = header.material->constantTable;
replacementFound = true; replacementFound = true;
} }
} }
}, false, false); }, false, false);
if (!replacementFound)
{
Game::DB_EnumXAssetEntries(Game::XAssetType::ASSET_TYPE_MATERIAL, [asset, modifiedTechsetName](Game::XAssetEntry* entry)
{
if (!replacementFound)
{
Game::XAssetHeader header = entry->asset.header;
if (Utils::String::StartsWith(header.material->techniqueSet->name, modifiedTechsetName))
{
asset->sortKey = header.material->sortKey;
// This is temp, as nobody has time to fix materials
// asset->stateBitsCount = header.material->stateBitsCount;
// asset->stateBitTable = header.material->stateBitTable;
// std::memcpy(asset->stateBitsEntry, header.material->stateBitsEntry, 48);
// asset->constantCount = header.material->constantCount;
// asset->constantTable = header.material->constantTable;
replacementFound = true;
}
}
}, false, false);
}
} }
if (!replacementFound && asset->techniqueSet) if (!replacementFound && asset->techniqueSet)