mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-22 05:27:19 +00:00
Lower memory usage of Behavior Parameter Table by 10MB (#627)
* Added caching for table Added caching for table Add more caching Update MasterServer.cpp grds Update CDBehaviorParameterTable.cpp Update CDBehaviorParameterTable.h Update CDBehaviorTemplateTable.cpp Update Behavior.cpp Update Behavior.cpp change to map Remove redundant query * Remove include * change to enum * Update Behavior.cpp * Use already cached table * Update Behavior.cpp * Reduce memory usage Reduces the memory usage for the BehaviorParameter table by 10MB in memory. * Update CDBehaviorTemplateTable.cpp
This commit is contained in:
parent
06217ad5e3
commit
b7497a47e4
@ -9,14 +9,20 @@ CDBehaviorParameterTable::CDBehaviorParameterTable(void) {
|
|||||||
hash = 0;
|
hash = 0;
|
||||||
CDBehaviorParameter entry;
|
CDBehaviorParameter entry;
|
||||||
entry.behaviorID = tableData.getIntField(0, -1);
|
entry.behaviorID = tableData.getIntField(0, -1);
|
||||||
entry.parameterID = tableData.getStringField(1, "");
|
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;
|
||||||
|
}
|
||||||
entry.value = tableData.getFloatField(2, -1.0f);
|
entry.value = tableData.getFloatField(2, -1.0f);
|
||||||
|
|
||||||
GeneralUtils::hash_combine(hash, entry.behaviorID);
|
GeneralUtils::hash_combine(hash, entry.behaviorID);
|
||||||
GeneralUtils::hash_combine(hash, entry.parameterID);
|
GeneralUtils::hash_combine(hash, *entry.parameterID);
|
||||||
|
|
||||||
auto it = m_Entries.find(entry.behaviorID);
|
auto it = m_Entries.find(entry.behaviorID);
|
||||||
m_ParametersList.insert(entry.parameterID);
|
m_ParametersList.insert(*entry.parameterID);
|
||||||
m_Entries.insert(std::make_pair(hash, entry));
|
m_Entries.insert(std::make_pair(hash, entry));
|
||||||
|
|
||||||
tableData.nextRow();
|
tableData.nextRow();
|
||||||
@ -36,7 +42,7 @@ CDBehaviorParameter CDBehaviorParameterTable::GetEntry(const uint32_t behaviorID
|
|||||||
{
|
{
|
||||||
CDBehaviorParameter returnValue;
|
CDBehaviorParameter returnValue;
|
||||||
returnValue.behaviorID = 0;
|
returnValue.behaviorID = 0;
|
||||||
returnValue.parameterID = "";
|
returnValue.parameterID = m_ParametersList.end();
|
||||||
returnValue.value = defaultValue;
|
returnValue.value = defaultValue;
|
||||||
|
|
||||||
size_t hash = 0;
|
size_t hash = 0;
|
||||||
@ -57,7 +63,7 @@ std::map<std::string, float> CDBehaviorParameterTable::GetParametersByBehaviorID
|
|||||||
GeneralUtils::hash_combine(hash, parameterCandidate);
|
GeneralUtils::hash_combine(hash, parameterCandidate);
|
||||||
auto infoCandidate = m_Entries.find(hash);
|
auto infoCandidate = m_Entries.find(hash);
|
||||||
if (infoCandidate != m_Entries.end()) {
|
if (infoCandidate != m_Entries.end()) {
|
||||||
returnInfo.insert(std::make_pair(infoCandidate->second.parameterID, infoCandidate->second.value));
|
returnInfo.insert(std::make_pair(*(infoCandidate->second.parameterID), infoCandidate->second.value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnInfo;
|
return returnInfo;
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
|
|
||||||
//! BehaviorParameter Entry Struct
|
//! BehaviorParameter Entry Struct
|
||||||
struct CDBehaviorParameter {
|
struct CDBehaviorParameter {
|
||||||
unsigned int behaviorID; //!< The Behavior ID
|
unsigned int behaviorID; //!< The Behavior ID
|
||||||
std::string parameterID; //!< The Parameter ID
|
std::unordered_set<std::string>::iterator parameterID; //!< The Parameter ID
|
||||||
float value; //!< The value of the behavior template
|
float value; //!< The value of the behavior template
|
||||||
};
|
};
|
||||||
|
|
||||||
//! BehaviorParameter table
|
//! BehaviorParameter table
|
||||||
|
@ -24,7 +24,13 @@ CDBehaviorTemplateTable::CDBehaviorTemplateTable(void) {
|
|||||||
entry.behaviorID = tableData.getIntField(0, -1);
|
entry.behaviorID = tableData.getIntField(0, -1);
|
||||||
entry.templateID = tableData.getIntField(1, -1);
|
entry.templateID = tableData.getIntField(1, -1);
|
||||||
entry.effectID = tableData.getIntField(2, -1);
|
entry.effectID = tableData.getIntField(2, -1);
|
||||||
entry.effectHandle = tableData.getStringField(3, "");
|
auto candidateToAdd = tableData.getStringField(3, "");
|
||||||
|
auto parameter = m_EffectHandles.find(candidateToAdd);
|
||||||
|
if (parameter != m_EffectHandles.end()) {
|
||||||
|
entry.effectHandle = parameter;
|
||||||
|
} else {
|
||||||
|
entry.effectHandle = m_EffectHandles.insert(candidateToAdd).first;
|
||||||
|
}
|
||||||
|
|
||||||
this->entries.push_back(entry);
|
this->entries.push_back(entry);
|
||||||
this->entriesMappedByBehaviorID.insert(std::make_pair(entry.behaviorID, entry));
|
this->entriesMappedByBehaviorID.insert(std::make_pair(entry.behaviorID, entry));
|
||||||
@ -62,7 +68,8 @@ const CDBehaviorTemplate CDBehaviorTemplateTable::GetByBehaviorID(uint32_t behav
|
|||||||
if (entry == this->entriesMappedByBehaviorID.end()) {
|
if (entry == this->entriesMappedByBehaviorID.end()) {
|
||||||
CDBehaviorTemplate entryToReturn;
|
CDBehaviorTemplate entryToReturn;
|
||||||
entryToReturn.behaviorID = 0;
|
entryToReturn.behaviorID = 0;
|
||||||
entryToReturn.effectHandle = "";
|
entryToReturn.effectHandle = m_EffectHandles.end();
|
||||||
|
entryToReturn.effectID = 0;
|
||||||
return entryToReturn;
|
return entryToReturn;
|
||||||
} else {
|
} else {
|
||||||
return entry->second;
|
return entry->second;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
// Custom Classes
|
// Custom Classes
|
||||||
#include "CDTable.h"
|
#include "CDTable.h"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\file CDBehaviorTemplateTable.hpp
|
\file CDBehaviorTemplateTable.hpp
|
||||||
@ -11,10 +12,10 @@
|
|||||||
|
|
||||||
//! BehaviorTemplate Entry Struct
|
//! BehaviorTemplate Entry Struct
|
||||||
struct CDBehaviorTemplate {
|
struct CDBehaviorTemplate {
|
||||||
unsigned int behaviorID; //!< The Behavior ID
|
unsigned int behaviorID; //!< The Behavior ID
|
||||||
unsigned int templateID; //!< The Template ID (LOT)
|
unsigned int templateID; //!< The Template ID (LOT)
|
||||||
unsigned int effectID; //!< The Effect ID attached
|
unsigned int effectID; //!< The Effect ID attached
|
||||||
std::string effectHandle; //!< The effect handle
|
std::unordered_set<std::string>::iterator effectHandle; //!< The effect handle
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ class CDBehaviorTemplateTable : public CDTable {
|
|||||||
private:
|
private:
|
||||||
std::vector<CDBehaviorTemplate> entries;
|
std::vector<CDBehaviorTemplate> entries;
|
||||||
std::unordered_map<uint32_t, CDBehaviorTemplate> entriesMappedByBehaviorID;
|
std::unordered_map<uint32_t, CDBehaviorTemplate> entriesMappedByBehaviorID;
|
||||||
|
std::unordered_set<std::string> m_EffectHandles;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
|
@ -445,7 +445,7 @@ Behavior::Behavior(const uint32_t behaviorId)
|
|||||||
|
|
||||||
this->m_effectId = templateInDatabase.effectID;
|
this->m_effectId = templateInDatabase.effectID;
|
||||||
|
|
||||||
this->m_effectHandle = templateInDatabase.effectHandle != "" ? new std::string(templateInDatabase.effectHandle) : nullptr;
|
this->m_effectHandle = *templateInDatabase.effectHandle != "" ? new std::string(*templateInDatabase.effectHandle) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user