emerge.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
  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. #ifndef EMERGE_HEADER
  17. #define EMERGE_HEADER
  18. #include <map>
  19. #include "irr_v3d.h"
  20. #include "util/container.h"
  21. #include "map.h" // for ManualMapVoxelManipulator
  22. #include "mapgen.h" // for MapgenParams
  23. #define MGPARAMS_SET_MGNAME 1
  24. #define MGPARAMS_SET_SEED 2
  25. #define MGPARAMS_SET_WATER_LEVEL 4
  26. #define MGPARAMS_SET_FLAGS 8
  27. #define BLOCK_EMERGE_ALLOWGEN (1<<0)
  28. #define EMERGE_DBG_OUT(x) \
  29. { if (enable_mapgen_debug_info) \
  30. infostream << "EmergeThread: " x << std::endl; }
  31. class EmergeThread;
  32. //class Mapgen;
  33. //struct MapgenFactory;
  34. class Biome;
  35. class BiomeDefManager;
  36. class Decoration;
  37. class Ore;
  38. class INodeDefManager;
  39. class Settings;
  40. struct BlockMakeData {
  41. ManualMapVoxelManipulator *vmanip;
  42. u64 seed;
  43. v3s16 blockpos_min;
  44. v3s16 blockpos_max;
  45. v3s16 blockpos_requested;
  46. UniqueQueue<v3s16> transforming_liquid;
  47. INodeDefManager *nodedef;
  48. BlockMakeData():
  49. vmanip(NULL),
  50. seed(0),
  51. nodedef(NULL)
  52. {}
  53. ~BlockMakeData() { delete vmanip; }
  54. };
  55. struct BlockEmergeData {
  56. u16 peer_requested;
  57. u8 flags;
  58. };
  59. class EmergeManager {
  60. public:
  61. INodeDefManager *ndef;
  62. std::map<std::string, MapgenFactory *> mglist;
  63. std::vector<Mapgen *> mapgen;
  64. std::vector<EmergeThread *> emergethread;
  65. bool threads_active;
  66. //settings
  67. MapgenParams params;
  68. bool mapgen_debug_info;
  69. u16 qlimit_total;
  70. u16 qlimit_diskonly;
  71. u16 qlimit_generate;
  72. u32 gennotify;
  73. //block emerge queue data structures
  74. JMutex queuemutex;
  75. std::map<v3s16, BlockEmergeData *> blocks_enqueued;
  76. std::map<u16, u16> peer_queue_count;
  77. //Mapgen-related structures
  78. BiomeDefManager *biomedef;
  79. std::vector<Ore *> ores;
  80. std::vector<Decoration *> decorations;
  81. EmergeManager(IGameDef *gamedef);
  82. ~EmergeManager();
  83. void loadMapgenParams();
  84. void initMapgens();
  85. Mapgen *getCurrentMapgen();
  86. Mapgen *createMapgen(std::string mgname, int mgid,
  87. MapgenParams *mgparams);
  88. MapgenSpecificParams *createMapgenParams(std::string mgname);
  89. void startThreads();
  90. void stopThreads();
  91. bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
  92. void registerMapgen(std::string name, MapgenFactory *mgfactory);
  93. void loadParamsFromSettings(Settings *settings);
  94. void saveParamsToSettings(Settings *settings);
  95. //mapgen helper methods
  96. Biome *getBiomeAtPoint(v3s16 p);
  97. int getGroundLevelAtPoint(v2s16 p);
  98. bool isBlockUnderground(v3s16 blockpos);
  99. u32 getBlockSeed(v3s16 p);
  100. };
  101. #endif