emerge_internal.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #pragma once
  17. /******************************************************************/
  18. /* may only be included by emerge.cpp or emerge scripting related */
  19. /******************************************************************/
  20. #include "emerge.h"
  21. #include <queue>
  22. #include "util/thread.h"
  23. #include "threading/event.h"
  24. class Server;
  25. class ServerMap;
  26. class Mapgen;
  27. class EmergeManager;
  28. class EmergeScripting;
  29. class EmergeThread : public Thread {
  30. public:
  31. bool enable_mapgen_debug_info;
  32. int id;
  33. EmergeThread(Server *server, int ethreadid);
  34. ~EmergeThread() = default;
  35. void *run();
  36. void signal();
  37. // Requires queue mutex held
  38. bool pushBlock(const v3s16 &pos);
  39. void cancelPendingItems();
  40. EmergeManager *getEmergeManager() { return m_emerge; }
  41. Mapgen *getMapgen() { return m_mapgen; }
  42. protected:
  43. void runCompletionCallbacks(
  44. const v3s16 &pos, EmergeAction action,
  45. const EmergeCallbackList &callbacks);
  46. private:
  47. Server *m_server;
  48. ServerMap *m_map;
  49. EmergeManager *m_emerge;
  50. Mapgen *m_mapgen;
  51. std::unique_ptr<EmergeScripting> m_script;
  52. // read from scripting:
  53. UniqueQueue<v3s16> *m_trans_liquid; //< non-null only when generating a mapblock
  54. Event m_queue_event;
  55. std::queue<v3s16> m_block_queue;
  56. bool initScripting();
  57. bool popBlockEmerge(v3s16 *pos, BlockEmergeData *bedata);
  58. EmergeAction getBlockOrStartGen(
  59. const v3s16 &pos, bool allow_gen, MapBlock **block, BlockMakeData *data);
  60. MapBlock *finishGen(v3s16 pos, BlockMakeData *bmdata,
  61. std::map<v3s16, MapBlock *> *modified_blocks);
  62. friend class EmergeManager;
  63. friend class EmergeScripting;
  64. friend class ModApiMapgen;
  65. };
  66. // Scoped helper to set Server::m_ignore_map_edit_events_area
  67. class MapEditEventAreaIgnorer
  68. {
  69. public:
  70. MapEditEventAreaIgnorer(VoxelArea *ignorevariable, const VoxelArea &a):
  71. m_ignorevariable(ignorevariable)
  72. {
  73. if (m_ignorevariable->getVolume() == 0)
  74. *m_ignorevariable = a;
  75. else
  76. m_ignorevariable = nullptr;
  77. }
  78. ~MapEditEventAreaIgnorer()
  79. {
  80. if (m_ignorevariable) {
  81. assert(m_ignorevariable->getVolume() != 0);
  82. *m_ignorevariable = VoxelArea();
  83. }
  84. }
  85. private:
  86. VoxelArea *m_ignorevariable;
  87. };