diff options
author | kwolekr <kwolekr@minetest.net> | 2015-09-23 00:31:45 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-09-23 15:56:24 -0400 |
commit | f062bbd7a182233f96c61287d0397534811627d9 (patch) | |
tree | df3d2252f8bbb9975669c7920b57dce2fb3d3df6 /src/emerge.cpp | |
parent | 596484da4fcd301e597a851a9a54b6dc276a286a (diff) | |
download | minetest-f062bbd7a182233f96c61287d0397534811627d9.tar.gz minetest-f062bbd7a182233f96c61287d0397534811627d9.tar.bz2 minetest-f062bbd7a182233f96c61287d0397534811627d9.zip |
Add /emergeblocks command and core.emerge_area() Lua API
Diffstat (limited to 'src/emerge.cpp')
-rw-r--r-- | src/emerge.cpp | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/emerge.cpp b/src/emerge.cpp index 084470783..e6bd52659 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -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) { |