mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Clean up database API and save the local map on an interval
This commit is contained in:
parent
c7454d4732
commit
708337dfc2
16 changed files with 391 additions and 519 deletions
|
@ -18,64 +18,38 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
|
||||
/*
|
||||
Dummy "database" class
|
||||
Dummy database class
|
||||
*/
|
||||
|
||||
|
||||
#include "database-dummy.h"
|
||||
|
||||
#include "map.h"
|
||||
#include "mapsector.h"
|
||||
#include "mapblock.h"
|
||||
#include "serialization.h"
|
||||
#include "main.h"
|
||||
#include "settings.h"
|
||||
#include "log.h"
|
||||
|
||||
Database_Dummy::Database_Dummy(ServerMap *map)
|
||||
bool Database_Dummy::saveBlock(const v3s16 &pos, const std::string &data)
|
||||
{
|
||||
srvmap = map;
|
||||
}
|
||||
|
||||
int Database_Dummy::Initialized(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Database_Dummy::beginSave() {}
|
||||
void Database_Dummy::endSave() {}
|
||||
|
||||
bool Database_Dummy::saveBlock(v3s16 blockpos, std::string &data)
|
||||
{
|
||||
m_database[getBlockAsInteger(blockpos)] = data;
|
||||
m_database[getBlockAsInteger(pos)] = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Database_Dummy::loadBlock(v3s16 blockpos)
|
||||
std::string Database_Dummy::loadBlock(const v3s16 &pos)
|
||||
{
|
||||
if (m_database.count(getBlockAsInteger(blockpos)))
|
||||
return m_database[getBlockAsInteger(blockpos)];
|
||||
s64 i = getBlockAsInteger(pos);
|
||||
if (m_database.count(i))
|
||||
return m_database[i];
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
bool Database_Dummy::deleteBlock(v3s16 blockpos)
|
||||
bool Database_Dummy::deleteBlock(const v3s16 &pos)
|
||||
{
|
||||
m_database.erase(getBlockAsInteger(blockpos));
|
||||
m_database.erase(getBlockAsInteger(pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
void Database_Dummy::listAllLoadableBlocks(std::vector<v3s16> &dst)
|
||||
{
|
||||
for(std::map<u64, std::string>::iterator x = m_database.begin(); x != m_database.end(); ++x)
|
||||
{
|
||||
v3s16 p = getIntegerAsBlock(x->first);
|
||||
//dstream<<"block_i="<<block_i<<" p="<<PP(p)<<std::endl;
|
||||
dst.push_back(p);
|
||||
for (std::map<s64, std::string>::const_iterator x = m_database.begin();
|
||||
x != m_database.end(); ++x) {
|
||||
dst.push_back(getIntegerAsBlock(x->first));
|
||||
}
|
||||
}
|
||||
|
||||
Database_Dummy::~Database_Dummy()
|
||||
{
|
||||
m_database.clear();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue