database-dummy.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. /*
  17. Dummy "database" class
  18. */
  19. #include "database-dummy.h"
  20. #include "map.h"
  21. #include "mapsector.h"
  22. #include "mapblock.h"
  23. #include "serialization.h"
  24. #include "main.h"
  25. #include "settings.h"
  26. #include "log.h"
  27. Database_Dummy::Database_Dummy(ServerMap *map)
  28. {
  29. srvmap = map;
  30. }
  31. int Database_Dummy::Initialized(void)
  32. {
  33. return 1;
  34. }
  35. void Database_Dummy::beginSave() {}
  36. void Database_Dummy::endSave() {}
  37. bool Database_Dummy::saveBlock(v3s16 blockpos, std::string &data)
  38. {
  39. m_database[getBlockAsInteger(blockpos)] = data;
  40. return true;
  41. }
  42. std::string Database_Dummy::loadBlock(v3s16 blockpos)
  43. {
  44. if (m_database.count(getBlockAsInteger(blockpos)))
  45. return m_database[getBlockAsInteger(blockpos)];
  46. else
  47. return "";
  48. }
  49. void Database_Dummy::listAllLoadableBlocks(std::list<v3s16> &dst)
  50. {
  51. for(std::map<u64, std::string>::iterator x = m_database.begin(); x != m_database.end(); ++x)
  52. {
  53. v3s16 p = getIntegerAsBlock(x->first);
  54. //dstream<<"block_i="<<block_i<<" p="<<PP(p)<<std::endl;
  55. dst.push_back(p);
  56. }
  57. }
  58. Database_Dummy::~Database_Dummy()
  59. {
  60. m_database.clear();
  61. }