forked from Mirrorlandia_minetest/minetest
Add global and per-peer queue limits
This commit is contained in:
parent
b9d8e59bbf
commit
3b7a445cd7
@ -88,7 +88,10 @@ Mapgen *EmergeManager::getMapgen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate) { ///return false if adding failed, or queue full!
|
bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate) {
|
||||||
|
std::map<v3s16, BlockEmergeData *>::const_iterator iter;
|
||||||
|
BlockEmergeData *bedata;
|
||||||
|
u16 count;
|
||||||
u8 flags = 0;
|
u8 flags = 0;
|
||||||
|
|
||||||
if (allow_generate)
|
if (allow_generate)
|
||||||
@ -103,14 +106,30 @@ bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate
|
|||||||
{
|
{
|
||||||
JMutexAutoLock queuelock(queuemutex);
|
JMutexAutoLock queuelock(queuemutex);
|
||||||
|
|
||||||
std::map<v3s16, u8>::const_iterator iter = blocks_enqueued.find(p);
|
count = blocks_enqueued.size();
|
||||||
|
u16 queuelimit_total = 256;
|
||||||
|
if (count >= queuelimit_total)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
count = peer_queue_count[peer_id];
|
||||||
|
u16 queuelimit_peer = allow_generate ? 1 : 5;
|
||||||
|
if (count >= queuelimit_peer)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
iter = blocks_enqueued.find(p);
|
||||||
if (iter != blocks_enqueued.end()) {
|
if (iter != blocks_enqueued.end()) {
|
||||||
flags |= iter->second;
|
bedata = iter->second;
|
||||||
blocks_enqueued[p] = flags;
|
bedata->flags |= flags;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks_enqueued.insert(std::make_pair(p, flags));
|
bedata = new BlockEmergeData;
|
||||||
|
bedata->flags = flags;
|
||||||
|
bedata->peer_requested = peer_id;
|
||||||
|
blocks_enqueued.insert(std::make_pair(p, bedata));
|
||||||
|
|
||||||
|
peer_queue_count[peer_id] = count + 1;
|
||||||
|
|
||||||
emergethread->blockqueue.push(p);
|
emergethread->blockqueue.push(p);
|
||||||
}
|
}
|
||||||
emergethread->qevent.signal();
|
emergethread->qevent.signal();
|
||||||
@ -120,6 +139,7 @@ bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate
|
|||||||
|
|
||||||
|
|
||||||
bool EmergeManager::popBlockEmerge(v3s16 *pos, u8 *flags) {
|
bool EmergeManager::popBlockEmerge(v3s16 *pos, u8 *flags) {
|
||||||
|
std::map<v3s16, BlockEmergeData *>::iterator iter;
|
||||||
JMutexAutoLock queuelock(queuemutex);
|
JMutexAutoLock queuelock(queuemutex);
|
||||||
|
|
||||||
if (emergethread->blockqueue.empty())
|
if (emergethread->blockqueue.empty())
|
||||||
@ -129,11 +149,16 @@ bool EmergeManager::popBlockEmerge(v3s16 *pos, u8 *flags) {
|
|||||||
|
|
||||||
*pos = p;
|
*pos = p;
|
||||||
|
|
||||||
std::map<v3s16, u8>::iterator iter = blocks_enqueued.find(p);
|
iter = blocks_enqueued.find(p);
|
||||||
if (iter == blocks_enqueued.end()) //uh oh, this isn't right!!!!!!!!!!!!!!!!!!
|
if (iter == blocks_enqueued.end())
|
||||||
return false;
|
return false; //uh oh, queue and map out of sync!!
|
||||||
|
|
||||||
*flags = iter->second;
|
BlockEmergeData *bedata = iter->second;
|
||||||
|
*flags = bedata->flags;
|
||||||
|
|
||||||
|
peer_queue_count[bedata->peer_requested]--;
|
||||||
|
|
||||||
|
delete bedata;
|
||||||
blocks_enqueued.erase(iter);
|
blocks_enqueued.erase(iter);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
18
src/emerge.h
18
src/emerge.h
@ -14,8 +14,6 @@ class Biome;
|
|||||||
class BiomeDefManager;
|
class BiomeDefManager;
|
||||||
class EmergeThread;
|
class EmergeThread;
|
||||||
class ManualMapVoxelManipulator;
|
class ManualMapVoxelManipulator;
|
||||||
//class ServerMap;
|
|
||||||
//class MapBlock;
|
|
||||||
|
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
@ -29,9 +27,6 @@ struct BlockMakeData {
|
|||||||
UniqueQueue<v3s16> transforming_liquid;
|
UniqueQueue<v3s16> transforming_liquid;
|
||||||
INodeDefManager *nodedef;
|
INodeDefManager *nodedef;
|
||||||
|
|
||||||
// BlockMakeData();
|
|
||||||
// ~BlockMakeData();
|
|
||||||
|
|
||||||
BlockMakeData():
|
BlockMakeData():
|
||||||
no_op(false),
|
no_op(false),
|
||||||
vmanip(NULL),
|
vmanip(NULL),
|
||||||
@ -39,10 +34,12 @@ BlockMakeData():
|
|||||||
nodedef(NULL)
|
nodedef(NULL)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~BlockMakeData()
|
~BlockMakeData() { delete vmanip; }
|
||||||
{
|
};
|
||||||
delete vmanip;
|
|
||||||
}
|
struct BlockEmergeData {
|
||||||
|
u16 peer_requested;
|
||||||
|
u8 flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EmergeManager {
|
class EmergeManager {
|
||||||
@ -53,7 +50,8 @@ public:
|
|||||||
MapgenParams *params;
|
MapgenParams *params;
|
||||||
|
|
||||||
JMutex queuemutex;
|
JMutex queuemutex;
|
||||||
std::map<v3s16, u8> blocks_enqueued; //change to a hashtable later
|
std::map<v3s16, BlockEmergeData *> blocks_enqueued;
|
||||||
|
std::map<u16, u16> peer_queue_count;
|
||||||
Mapgen *mapgen;
|
Mapgen *mapgen;
|
||||||
EmergeThread *emergethread;
|
EmergeThread *emergethread;
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "mapnode.h"
|
#include "mapnode.h"
|
||||||
#include "noise.h"
|
#include "noise.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
//#include "emerge.h"
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
/////////////////// Mapgen flags
|
/////////////////// Mapgen flags
|
||||||
|
Loading…
Reference in New Issue
Block a user