2021-12-05 17:54:36 +00:00
|
|
|
#include "CDComponentsRegistryTable.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2023-03-20 13:10:52 +00:00
|
|
|
#include "dLogger.h"
|
|
|
|
#include "Game.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-20 13:10:52 +00:00
|
|
|
uint64_t CalculateId(uint64_t lhs, uint64_t rhs) {
|
|
|
|
return (lhs << 32) | rhs;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-03-20 13:10:52 +00:00
|
|
|
void CDComponentsRegistryTable::ReadRow(CppSQLite3Query& rowData) {
|
|
|
|
uint32_t id = rowData.getIntField("id", -1);
|
|
|
|
eReplicaComponentType component_type = static_cast<eReplicaComponentType>(rowData.getIntField("component_type", 0));
|
|
|
|
uint32_t component_id = rowData.getIntField("component_id", -1);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-03-20 13:10:52 +00:00
|
|
|
auto insertedEntry = this->mappedEntries.insert_or_assign(CalculateId(id, static_cast<uint64_t>(component_type)), component_id);
|
|
|
|
DluAssert(insertedEntry.second == true);
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-03-20 13:10:52 +00:00
|
|
|
CDComponentsRegistryTable::CDComponentsRegistryTable() {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ComponentsRegistry");
|
|
|
|
while (!tableData.eof()) {
|
2023-03-20 13:10:52 +00:00
|
|
|
ReadRow(tableData);
|
2021-12-05 17:54:36 +00:00
|
|
|
tableData.nextRow();
|
|
|
|
}
|
|
|
|
tableData.finalize();
|
|
|
|
}
|
|
|
|
|
2023-03-04 07:16:37 +00:00
|
|
|
int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, eReplicaComponentType componentType, int32_t defaultValue) {
|
2023-03-20 13:10:52 +00:00
|
|
|
const auto iter = this->mappedEntries.find(CalculateId(id, static_cast<uint64_t>(componentType)));
|
|
|
|
return iter != this->mappedEntries.end() ? iter->second : defaultValue;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|