2021-12-05 17:54:36 +00:00
|
|
|
#include "CDComponentsRegistryTable.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-08-11 04:27:40 +00:00
|
|
|
void CDComponentsRegistryTable::LoadValuesFromDatabase() {
|
2021-12-05 17:54:36 +00:00
|
|
|
// Now get the data
|
|
|
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ComponentsRegistry");
|
|
|
|
while (!tableData.eof()) {
|
|
|
|
CDComponentsRegistry entry;
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.id = tableData.getIntField("id", -1);
|
2023-03-04 07:16:37 +00:00
|
|
|
entry.component_type = static_cast<eReplicaComponentType>(tableData.getIntField("component_type", 0));
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.component_id = tableData.getIntField("component_id", -1);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-12-28 04:18:20 +00:00
|
|
|
this->mappedEntries.insert_or_assign(static_cast<uint64_t>(entry.component_type) << 32 | static_cast<uint64_t>(entry.id), entry.component_id);
|
2023-08-11 04:27:40 +00:00
|
|
|
this->mappedEntries.insert_or_assign(entry.id, 0);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
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-08-11 04:27:40 +00:00
|
|
|
auto exists = mappedEntries.find(id);
|
|
|
|
if (exists != mappedEntries.end()) {
|
2023-12-28 04:18:20 +00:00
|
|
|
auto iter = mappedEntries.find(static_cast<uint64_t>(componentType) << 32 | static_cast<uint64_t>(id));
|
2023-08-11 04:27:40 +00:00
|
|
|
return iter == mappedEntries.end() ? defaultValue : iter->second;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2023-08-11 04:27:40 +00:00
|
|
|
// Now get the data. Get all components of this entity so we dont do a query for each component
|
|
|
|
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM ComponentsRegistry WHERE id = ?;");
|
|
|
|
query.bind(1, static_cast<int32_t>(id));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-08-11 04:27:40 +00:00
|
|
|
auto tableData = query.execQuery();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
while (!tableData.eof()) {
|
|
|
|
CDComponentsRegistry entry;
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.id = tableData.getIntField("id", -1);
|
2023-08-11 04:27:40 +00:00
|
|
|
entry.component_type = static_cast<eReplicaComponentType>(tableData.getIntField("component_type", 0));
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.component_id = tableData.getIntField("component_id", -1);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-12-28 04:18:20 +00:00
|
|
|
this->mappedEntries.insert_or_assign(static_cast<uint64_t>(entry.component_type) << 32 | static_cast<uint64_t>(entry.id), entry.component_id);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
tableData.nextRow();
|
|
|
|
}
|
|
|
|
|
2023-08-11 04:27:40 +00:00
|
|
|
mappedEntries.insert_or_assign(id, 0);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-12-28 04:18:20 +00:00
|
|
|
auto iter = this->mappedEntries.find(static_cast<uint64_t>(componentType) << 32 | static_cast<uint64_t>(id));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-08-11 04:27:40 +00:00
|
|
|
return iter == this->mappedEntries.end() ? defaultValue : iter->second;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|