mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-14 03:58:26 +00:00
Abstracted the CDClient tables
There is now an option to utilize shared memory for some CDClient tables by adding `CD_PROVIDER_MEMORY=1` to the CMakeVariables.txt file. Allows masterconfig.ini to specify another run command for the world server, to allow for easier debugging through `valgrind`.
This commit is contained in:
70
dDatabase/Tables/CDTable.cpp
Normal file
70
dDatabase/Tables/CDTable.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "CDTable.h"
|
||||
|
||||
#if defined(CD_PROVIDER_MEMORY)
|
||||
|
||||
#include "CDAbstractSharedMemoryMap.h"
|
||||
|
||||
typedef boost::interprocess::allocator<char, boost::interprocess::managed_shared_memory::segment_manager> CharAllocator;
|
||||
typedef boost::interprocess::basic_string<char, std::char_traits<char>, CharAllocator> my_string;
|
||||
|
||||
CDAbstractSharedMemoryMap<size_t, boost::interprocess::string>* CDStringMap;
|
||||
|
||||
void CDTable::InitalizeHost()
|
||||
{
|
||||
CDStringMap->LoadHost();
|
||||
}
|
||||
|
||||
void CDTable::Initalize()
|
||||
{
|
||||
CDStringMap = new CDAbstractSharedMemoryMap<size_t, boost::interprocess::string>("CDStringMap", 10 * 1000 * 1000);
|
||||
}
|
||||
|
||||
std::string CDTable::GetString(size_t handle)
|
||||
{
|
||||
std::string str = std::string(CDStringMap->GetEntry(handle, "").c_str());
|
||||
|
||||
Game::logger->Log("CDTable", "GetString: %s\n", str.c_str());
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
size_t CDTable::SetString(std::string value)
|
||||
{
|
||||
size_t hash = 0;
|
||||
|
||||
GeneralUtils::hash_combine(hash, value);
|
||||
|
||||
CDStringMap->SetEntry(hash, boost::interprocess::string(value.c_str()));
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
std::unordered_map<size_t, std::string> CDStringMap;
|
||||
|
||||
void CDTable::InitalizeHost()
|
||||
{
|
||||
}
|
||||
|
||||
void CDTable::Initalize()
|
||||
{
|
||||
}
|
||||
|
||||
std::string CDTable::GetString(size_t handle)
|
||||
{
|
||||
return CDStringMap[handle];
|
||||
}
|
||||
|
||||
size_t CDTable::SetString(std::string value)
|
||||
{
|
||||
size_t hash = 0;
|
||||
|
||||
GeneralUtils::hash_combine(hash, value);
|
||||
|
||||
CDStringMap[hash] = value;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user