mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Add /emergeblocks command and core.emerge_area() Lua API
This commit is contained in:
parent
596484da4f
commit
f062bbd7a1
9 changed files with 162 additions and 49 deletions
|
@ -235,11 +235,13 @@ void EmergeManager::stopThreads()
|
|||
}
|
||||
|
||||
|
||||
bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate)
|
||||
bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p,
|
||||
bool allow_generate, bool force_queue_block)
|
||||
{
|
||||
std::map<v3s16, BlockEmergeData *>::const_iterator iter;
|
||||
BlockEmergeData *bedata;
|
||||
u16 count;
|
||||
u16 count_global = 0;
|
||||
u16 count_peer = 0;
|
||||
u8 flags = 0;
|
||||
int idx = 0;
|
||||
|
||||
|
@ -249,14 +251,17 @@ bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate
|
|||
{
|
||||
MutexAutoLock queuelock(queuemutex);
|
||||
|
||||
count = blocks_enqueued.size();
|
||||
if (count >= qlimit_total)
|
||||
return false;
|
||||
count_global = blocks_enqueued.size();
|
||||
count_peer = peer_queue_count[peer_id];
|
||||
|
||||
count = peer_queue_count[peer_id];
|
||||
u16 qlimit_peer = allow_generate ? qlimit_generate : qlimit_diskonly;
|
||||
if (count >= qlimit_peer)
|
||||
return false;
|
||||
if (!force_queue_block) {
|
||||
if (count_global >= qlimit_total)
|
||||
return false;
|
||||
|
||||
u16 qlimit_peer = allow_generate ? qlimit_generate : qlimit_diskonly;
|
||||
if (count_peer >= qlimit_peer)
|
||||
return false;
|
||||
}
|
||||
|
||||
iter = blocks_enqueued.find(p);
|
||||
if (iter != blocks_enqueued.end()) {
|
||||
|
@ -270,7 +275,7 @@ bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate
|
|||
bedata->peer_requested = peer_id;
|
||||
blocks_enqueued.insert(std::make_pair(p, bedata));
|
||||
|
||||
peer_queue_count[peer_id] = count + 1;
|
||||
peer_queue_count[peer_id] = count_peer + 1;
|
||||
|
||||
// insert into the EmergeThread queue with the least items
|
||||
int lowestitems = emergethread[0]->blockqueue.size();
|
||||
|
@ -289,6 +294,21 @@ bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate
|
|||
return true;
|
||||
}
|
||||
|
||||
v3s16 EmergeManager::getContainingChunk(v3s16 blockpos)
|
||||
{
|
||||
return getContainingChunk(blockpos, params.chunksize);
|
||||
}
|
||||
|
||||
|
||||
v3s16 EmergeManager::getContainingChunk(v3s16 blockpos, s16 chunksize)
|
||||
{
|
||||
s16 coff = -chunksize / 2;
|
||||
v3s16 chunk_offset(coff, coff, coff);
|
||||
|
||||
return getContainerPos(blockpos - chunk_offset, chunksize)
|
||||
* chunksize + chunk_offset;
|
||||
}
|
||||
|
||||
|
||||
int EmergeManager::getGroundLevelAtPoint(v2s16 p)
|
||||
{
|
||||
|
|
|
@ -109,9 +109,13 @@ public:
|
|||
static void getMapgenNames(std::list<const char *> &mgnames);
|
||||
void startThreads();
|
||||
void stopThreads();
|
||||
bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
|
||||
bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate,
|
||||
bool force_queue_block=false);
|
||||
|
||||
//mapgen helper methods
|
||||
v3s16 getContainingChunk(v3s16 blockpos);
|
||||
static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize);
|
||||
|
||||
// mapgen helper methods
|
||||
Biome *getBiomeAtPoint(v3s16 p);
|
||||
int getGroundLevelAtPoint(v2s16 p);
|
||||
bool isBlockUnderground(v3s16 blockpos);
|
||||
|
|
11
src/map.cpp
11
src/map.cpp
|
@ -2259,14 +2259,9 @@ bool ServerMap::initBlockMake(BlockMakeData *data, v3s16 blockpos)
|
|||
bool enable_mapgen_debug_info = m_emerge->mapgen_debug_info;
|
||||
EMERGE_DBG_OUT("initBlockMake(): " PP(blockpos) " - " PP(blockpos));
|
||||
|
||||
s16 chunksize = m_emerge->params.chunksize;
|
||||
s16 coffset = -chunksize / 2;
|
||||
v3s16 chunk_offset(coffset, coffset, coffset);
|
||||
v3s16 blockpos_div = getContainerPos(blockpos - chunk_offset, chunksize);
|
||||
v3s16 blockpos_min = blockpos_div * chunksize;
|
||||
v3s16 blockpos_max = blockpos_div * chunksize + v3s16(1,1,1)*(chunksize-1);
|
||||
blockpos_min += chunk_offset;
|
||||
blockpos_max += chunk_offset;
|
||||
s16 csize = m_emerge->params.chunksize;
|
||||
v3s16 blockpos_min = EmergeManager::getContainingChunk(blockpos, csize);
|
||||
v3s16 blockpos_max = blockpos_min + v3s16(1, 1, 1) * (csize - 1);
|
||||
|
||||
v3s16 extra_borders(1,1,1);
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "util/pointedthing.h"
|
||||
#include "content_sao.h"
|
||||
#include "treegen.h"
|
||||
#include "emerge.h"
|
||||
#include "pathfinder.h"
|
||||
|
||||
#define GET_ENV_PTR ServerEnvironment* env = \
|
||||
|
@ -751,6 +752,29 @@ int ModApiEnvMod::l_line_of_sight(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// emerge_area(p1, p2)
|
||||
// emerge mapblocks in area p1..p2
|
||||
int ModApiEnvMod::l_emerge_area(lua_State *L)
|
||||
{
|
||||
GET_ENV_PTR;
|
||||
|
||||
EmergeManager *emerge = getServer(L)->getEmergeManager();
|
||||
|
||||
v3s16 bpmin = getNodeBlockPos(read_v3s16(L, 1));
|
||||
v3s16 bpmax = getNodeBlockPos(read_v3s16(L, 2));
|
||||
sortBoxVerticies(bpmin, bpmax);
|
||||
|
||||
for (s16 z = bpmin.Z; z <= bpmax.Z; z++)
|
||||
for (s16 y = bpmin.Y; y <= bpmax.Y; y++)
|
||||
for (s16 x = bpmin.X; x <= bpmax.X; x++) {
|
||||
v3s16 chunkpos(x, y, z);
|
||||
emerge->enqueueBlockEmerge(PEER_ID_INEXISTENT, chunkpos, false, true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// delete_area(p1, p2)
|
||||
// delete mapblocks in area p1..p2
|
||||
int ModApiEnvMod::l_delete_area(lua_State *L)
|
||||
|
@ -954,6 +978,7 @@ void ModApiEnvMod::Initialize(lua_State *L, int top)
|
|||
API_FCT(find_node_near);
|
||||
API_FCT(find_nodes_in_area);
|
||||
API_FCT(find_nodes_in_area_under_air);
|
||||
API_FCT(emerge_area);
|
||||
API_FCT(delete_area);
|
||||
API_FCT(get_perlin);
|
||||
API_FCT(get_perlin_map);
|
||||
|
|
|
@ -125,6 +125,9 @@ private:
|
|||
// nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
|
||||
static int l_find_nodes_in_area_under_air(lua_State *L);
|
||||
|
||||
// emerge_area(p1, p2)
|
||||
static int l_emerge_area(lua_State *L);
|
||||
|
||||
// delete_area(p1, p2) -> true/false
|
||||
static int l_delete_area(lua_State *L);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue