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-07-09 06:07:52 +00:00
|
|
|
size_t hash = 0;
|
2022-01-15 18:37:43 +00:00
|
|
|
while (!tableData.eof()) {
|
2022-07-09 06:07:52 +00:00
|
|
|
hash = 0;
|
2022-01-15 18:37:43 +00:00
|
|
|
CDBehaviorParameter entry;
|
|
|
|
entry.behaviorID = tableData.getIntField(0, -1);
|
2022-07-12 03:43:09 +00:00
|
|
|
auto candidateStringToAdd = std::string(tableData.getStringField(1, ""));
|
|
|
|
auto parameter = m_ParametersList.find(candidateStringToAdd);
|
|
|
|
if (parameter != m_ParametersList.end()) {
|
|
|
|
entry.parameterID = parameter;
|
|
|
|
} else {
|
|
|
|
entry.parameterID = m_ParametersList.insert(candidateStringToAdd).first;
|
|
|
|
}
|
2022-01-15 18:37:43 +00:00
|
|
|
entry.value = tableData.getFloatField(2, -1.0f);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-09 06:07:52 +00:00
|
|
|
GeneralUtils::hash_combine(hash, entry.behaviorID);
|
2022-07-12 03:43:09 +00:00
|
|
|
GeneralUtils::hash_combine(hash, *entry.parameterID);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-09 06:07:52 +00:00
|
|
|
auto it = m_Entries.find(entry.behaviorID);
|
2022-07-12 03:43:09 +00:00
|
|
|
m_ParametersList.insert(*entry.parameterID);
|
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
|
|
|
|
CDBehaviorParameterTable::~CDBehaviorParameterTable(void) {}
|
|
|
|
|
|
|
|
//! 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-07-09 06:07:52 +00:00
|
|
|
CDBehaviorParameter CDBehaviorParameterTable::GetEntry(const uint32_t behaviorID, const std::string& name, const float defaultValue) {
|
|
|
|
CDBehaviorParameter returnValue;
|
|
|
|
returnValue.behaviorID = 0;
|
2022-07-12 03:43:09 +00:00
|
|
|
returnValue.parameterID = m_ParametersList.end();
|
2022-07-09 06:07:52 +00:00
|
|
|
returnValue.value = defaultValue;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
size_t hash = 0;
|
|
|
|
GeneralUtils::hash_combine(hash, behaviorID);
|
|
|
|
GeneralUtils::hash_combine(hash, name);
|
|
|
|
|
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-07-09 06:07:52 +00:00
|
|
|
return it != m_Entries.end() ? it->second : returnValue;
|
|
|
|
}
|
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) {
|
|
|
|
size_t hash;
|
|
|
|
std::map<std::string, float> returnInfo;
|
|
|
|
for (auto parameterCandidate : m_ParametersList) {
|
|
|
|
hash = 0;
|
|
|
|
GeneralUtils::hash_combine(hash, behaviorID);
|
|
|
|
GeneralUtils::hash_combine(hash, parameterCandidate);
|
|
|
|
auto infoCandidate = m_Entries.find(hash);
|
|
|
|
if (infoCandidate != m_Entries.end()) {
|
2022-07-12 03:43:09 +00:00
|
|
|
returnInfo.insert(std::make_pair(*(infoCandidate->second.parameterID), 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
|
|
|
}
|