2021-12-05 17:54:36 +00:00
|
|
|
#include "CDBehaviorParameterTable.h"
|
|
|
|
#include "GeneralUtils.h"
|
|
|
|
|
|
|
|
//! Constructor
|
|
|
|
CDBehaviorParameterTable::CDBehaviorParameterTable(void) {
|
2022-01-15 18:37:43 +00:00
|
|
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM BehaviorParameter");
|
2022-12-29 09:43:52 +00:00
|
|
|
uint32_t uniqueParameterId = 0;
|
|
|
|
uint64_t hash = 0;
|
2022-01-15 18:37:43 +00:00
|
|
|
while (!tableData.eof()) {
|
|
|
|
CDBehaviorParameter entry;
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.behaviorID = tableData.getIntField("behaviorID", -1);
|
|
|
|
auto candidateStringToAdd = std::string(tableData.getStringField("parameterID", ""));
|
2022-07-12 03:43:09 +00:00
|
|
|
auto parameter = m_ParametersList.find(candidateStringToAdd);
|
|
|
|
if (parameter != m_ParametersList.end()) {
|
|
|
|
entry.parameterID = parameter;
|
|
|
|
} else {
|
2022-12-29 09:43:52 +00:00
|
|
|
entry.parameterID = m_ParametersList.insert(std::make_pair(candidateStringToAdd, uniqueParameterId)).first;
|
|
|
|
uniqueParameterId++;
|
2022-07-12 03:43:09 +00:00
|
|
|
}
|
2022-12-29 09:43:52 +00:00
|
|
|
hash = entry.behaviorID;
|
|
|
|
hash = (hash << 31U) | entry.parameterID->second;
|
2023-01-07 09:48:59 +00:00
|
|
|
entry.value = tableData.getFloatField("value", -1.0f);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-09 06:07:52 +00:00
|
|
|
m_Entries.insert(std::make_pair(hash, entry));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-01-15 18:37:43 +00:00
|
|
|
tableData.nextRow();
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
tableData.finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Destructor
|
2022-07-28 13:39:57 +00:00
|
|
|
CDBehaviorParameterTable::~CDBehaviorParameterTable(void) {}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//! Returns the table's name
|
|
|
|
std::string CDBehaviorParameterTable::GetName(void) const {
|
2022-01-15 18:37:43 +00:00
|
|
|
return "BehaviorParameter";
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 09:43:52 +00:00
|
|
|
float CDBehaviorParameterTable::GetValue(const uint32_t behaviorID, const std::string& name, const float defaultValue) {
|
|
|
|
auto parameterID = this->m_ParametersList.find(name);
|
|
|
|
if (parameterID == this->m_ParametersList.end()) return defaultValue;
|
|
|
|
|
|
|
|
uint64_t hash = behaviorID;
|
2022-07-09 06:07:52 +00:00
|
|
|
|
2022-12-29 09:43:52 +00:00
|
|
|
hash = (hash << 31U) | parameterID->second;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-01-24 22:02:56 +00:00
|
|
|
// Search for specific parameter
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto& it = m_Entries.find(hash);
|
2022-12-29 09:43:52 +00:00
|
|
|
return it != m_Entries.end() ? it->second.value : defaultValue;
|
2022-07-09 06:07:52 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-09 06:07:52 +00:00
|
|
|
std::map<std::string, float> CDBehaviorParameterTable::GetParametersByBehaviorID(uint32_t behaviorID) {
|
2022-12-29 09:43:52 +00:00
|
|
|
uint64_t hashBase = behaviorID;
|
2022-07-09 06:07:52 +00:00
|
|
|
std::map<std::string, float> returnInfo;
|
2022-12-29 09:43:52 +00:00
|
|
|
uint64_t hash;
|
|
|
|
for (auto& parameterCandidate : m_ParametersList) {
|
|
|
|
hash = (hashBase << 31U) | parameterCandidate.second;
|
2022-07-09 06:07:52 +00:00
|
|
|
auto infoCandidate = m_Entries.find(hash);
|
|
|
|
if (infoCandidate != m_Entries.end()) {
|
2022-12-29 09:43:52 +00:00
|
|
|
returnInfo.insert(std::make_pair(infoCandidate->second.parameterID->first, infoCandidate->second.value));
|
2022-07-09 06:07:52 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-09 06:07:52 +00:00
|
|
|
return returnInfo;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2023-01-07 09:48:59 +00:00
|
|
|
|