mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-13 16:28:31 -05:00
chore: use generic loaders for iw4,iw5,t5,t6 instead of duplicating implementations
This commit is contained in:
@ -86,4 +86,60 @@ namespace string_table
|
||||
cell = content;
|
||||
}
|
||||
};
|
||||
|
||||
// =================================
|
||||
// V2: IW4, IW5
|
||||
// - Cells are a struct and have a hash
|
||||
// =================================
|
||||
template<typename StringTableType, int (*HashFunc)(const char*)>
|
||||
class StringTableLoaderV2 final : public AbstractStringTableLoader<StringTableType, std::remove_pointer_t<decltype(StringTableType::values)>>
|
||||
{
|
||||
using CellType_t = decltype(*StringTableType::values);
|
||||
|
||||
protected:
|
||||
void SetCellContent(CellType_t& cell, const char* content) override
|
||||
{
|
||||
cell.string = content;
|
||||
cell.hash = HashFunc(content);
|
||||
}
|
||||
};
|
||||
|
||||
// =================================
|
||||
// V3: T5, T6
|
||||
// - Cells are a struct and have a hash
|
||||
// - StringTable has an index array for binary search
|
||||
// =================================
|
||||
template<typename StringTableType, int (*HashFunc)(const char*)>
|
||||
class StringTableLoaderV3 final : public AbstractStringTableLoader<StringTableType, std::remove_pointer_t<decltype(StringTableType::values)>>
|
||||
{
|
||||
using CellType_t = decltype(*StringTableType::values);
|
||||
|
||||
protected:
|
||||
void SetCellContent(CellType_t& cell, const char* content) override
|
||||
{
|
||||
cell.string = content;
|
||||
cell.hash = HashFunc(content);
|
||||
}
|
||||
|
||||
void PostProcessStringTable(StringTableType* stringTable, const unsigned cellCount, MemoryManager& memory) override
|
||||
{
|
||||
if (!cellCount)
|
||||
{
|
||||
stringTable->cellIndex = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
stringTable->cellIndex = static_cast<int16_t*>(memory.Alloc(sizeof(int16_t) * cellCount));
|
||||
|
||||
std::sort(&stringTable->cellIndex[0],
|
||||
&stringTable->cellIndex[cellCount - 1],
|
||||
[stringTable](const int16_t a, const int16_t b)
|
||||
{
|
||||
auto compareResult = stringTable->values[a].hash - stringTable->values[b].hash;
|
||||
if (compareResult == 0)
|
||||
compareResult = (a % stringTable->columnCount) - (b % stringTable->columnCount);
|
||||
return compareResult < 0;
|
||||
});
|
||||
}
|
||||
};
|
||||
} // namespace string_table
|
||||
|
Reference in New Issue
Block a user