Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
emerge_internal.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
5#pragma once
6
7/******************************************************************/
8/* may only be included by emerge.cpp or emerge scripting related */
9/******************************************************************/
10
11#include "emerge.h"
12
13#include <queue>
14
15#include "util/thread.h"
16#include "threading/event.h"
17
18class Server;
19class ServerMap;
20class Mapgen;
21
22class EmergeManager;
23class EmergeScripting;
24
25class EmergeThread : public Thread {
26public:
28 const int id; // Index of this thread
29
30 EmergeThread(Server *server, int ethreadid);
31 ~EmergeThread() = default;
32
33 void *run();
34 void signal();
35
36 // Requires queue mutex held
37 bool pushBlock(v3s16 pos);
38
39 void cancelPendingItems();
40
42 Mapgen *getMapgen() { return m_mapgen; }
43
44protected:
45
47 v3s16 pos, EmergeAction action,
48 const EmergeCallbackList &callbacks);
49
50private:
55
56 std::unique_ptr<EmergeScripting> m_script;
57 // read from scripting:
58 UniqueQueue<v3s16> *m_trans_liquid; //< non-null only when generating a mapblock
59
61 std::queue<v3s16> m_block_queue;
62
63 bool initScripting();
64
65 bool popBlockEmerge(v3s16 *pos, BlockEmergeData *bedata);
66
78 EmergeAction getBlockOrStartGen(v3s16 pos, bool allow_gen,
79 const std::string *from_db, MapBlock **block, BlockMakeData *data);
80
82 std::map<v3s16, MapBlock *> *modified_blocks);
83
84 friend class EmergeManager;
85 friend class EmergeScripting;
86 friend class ModApiMapgen;
87};
88
89// Scoped helper to set Server::m_ignore_map_edit_events_area
91{
92public:
93 MapEditEventAreaIgnorer(VoxelArea *ignorevariable, const VoxelArea &a):
94 m_ignorevariable(ignorevariable)
95 {
96 if (m_ignorevariable->getVolume() == 0)
98 else
99 m_ignorevariable = nullptr;
100 }
101
103 {
104 if (m_ignorevariable) {
105 assert(m_ignorevariable->getVolume() != 0);
107 }
108 }
109
110private:
112};
Definition emerge.h:117
Definition scripting_emerge.h:16
Definition emerge_internal.h:25
bool enable_mapgen_debug_info
Definition emerge_internal.h:27
UniqueQueue< v3s16 > * m_trans_liquid
Definition emerge_internal.h:58
void signal()
Definition emerge.cpp:467
void cancelPendingItems()
Definition emerge.cpp:480
void * run()
Definition emerge.cpp:662
MapBlock * finishGen(v3s16 pos, BlockMakeData *bmdata, std::map< v3s16, MapBlock * > *modified_blocks)
Definition emerge.cpp:574
~EmergeThread()=default
Event m_queue_event
Definition emerge_internal.h:60
EmergeAction getBlockOrStartGen(v3s16 pos, bool allow_gen, const std::string *from_db, MapBlock **block, BlockMakeData *data)
Try to get a block from memory and decide what to do.
Definition emerge.cpp:531
const int id
Definition emerge_internal.h:28
Mapgen * getMapgen()
Definition emerge_internal.h:42
Mapgen * m_mapgen
Definition emerge_internal.h:54
std::queue< v3s16 > m_block_queue
Definition emerge_internal.h:61
EmergeThread(Server *server, int ethreadid)
Definition emerge.cpp:454
bool pushBlock(v3s16 pos)
Definition emerge.cpp:473
ServerMap * m_map
Definition emerge_internal.h:52
EmergeManager * getEmergeManager()
Definition emerge_internal.h:41
std::unique_ptr< EmergeScripting > m_script
Definition emerge_internal.h:56
bool initScripting()
Definition emerge.cpp:632
EmergeManager * m_emerge
Definition emerge_internal.h:53
void runCompletionCallbacks(v3s16 pos, EmergeAction action, const EmergeCallbackList &callbacks)
Definition emerge.cpp:498
Server * m_server
Definition emerge_internal.h:51
bool popBlockEmerge(v3s16 *pos, BlockEmergeData *bedata)
Definition emerge.cpp:515
A syncronization primitive that will wake up one waiting thread when signaled.
Definition event.h:37
Definition mapblock.h:58
Definition emerge_internal.h:91
MapEditEventAreaIgnorer(VoxelArea *ignorevariable, const VoxelArea &a)
Definition emerge_internal.h:93
~MapEditEventAreaIgnorer()
Definition emerge_internal.h:102
VoxelArea * m_ignorevariable
Definition emerge_internal.h:111
Definition mapgen.h:153
Definition l_mapgen.h:18
Definition servermap.h:44
Definition server.h:167
Definition thread.h:57
Definition container.h:26
Definition voxel.h:44
s32 getVolume() const
Definition voxel.h:124
std::vector< std::pair< EmergeCompletionCallback, void * > > EmergeCallbackList
Definition emerge.h:77
EmergeAction
Definition emerge.h:52
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
Definition activeobjectmgr.cpp:11
Definition emerge.h:79
Definition emerge.h:37