Esempio n. 1
0
bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b,
									BlockMakeData *data, bool allow_gen) {
	v2s16 p2d(p.X, p.Z);
	//envlock: usually takes <=1ms, sometimes 90ms or ~400ms to acquire
	JMutexAutoLock envlock(m_server->m_env_mutex);

	// Load sector if it isn't loaded
	if (map->getSectorNoGenerateNoEx(p2d) == NULL)
		map->loadSectorMeta(p2d);

	// Attempt to load block
	MapBlock *block = map->getBlockNoCreateNoEx(p);
	if (!block || block->isDummy() || !block->isGenerated()) {
		EMERGE_DBG_OUT("not in memory, attempting to load from disk");
		block = map->loadBlock(p);
		if (block && block->isGenerated())
			map->prepareBlock(block);
	}

	// If could not load and allowed to generate,
	// start generation inside this same envlock
	if (allow_gen && (block == NULL || !block->isGenerated())) {
		EMERGE_DBG_OUT("generating");
		*b = block;
		return map->initBlockMake(data, p);
	}

	*b = block;
	return false;
}
Esempio n. 2
0
bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b,
	BlockMakeData *data, bool allow_gen)
{
#if !ENABLE_THREADS
	auto lock = map->m_nothread_locker.lock_unique_rec();
#endif

	MapBlock *block;
	{

	//envlock: usually takes <=1ms, sometimes 90ms or ~400ms to acquire
	//JMutexAutoLock envlock(m_server->m_env_mutex);


	// Attempt to load block
	block = map->getBlockNoCreateNoEx(p);
	if (!block || block->isDummy()) {
		EMERGE_DBG_OUT("not in memory, attempting to load from disk ag="<<allow_gen<<" block="<<block<<" p="<<p);
		block = map->loadBlock(p);
		if (block && block->isGenerated())
			map->prepareBlock(block);
	}
	}

	// If could not load and allowed to generate,
	// start generation inside this same envlock
	if (allow_gen && (!block)) {
		EMERGE_DBG_OUT("generating b="<<block);
		*b = block;
		return map->initBlockMake(data, p);
	}

	*b = block;
	return false;
}
Esempio n. 3
0
bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b,
									BlockMakeData *data, bool allow_gen) {
	//envlock: usually takes <=1ms, sometimes 90ms or ~400ms to acquire
	//JMutexAutoLock envlock(m_server->m_env_mutex);

	// Attempt to load block
	MapBlock *block = map->getBlockNoCreateNoEx(p);
	if (!block || block->isDummy()) {
		EMERGE_DBG_OUT("not in memory, attempting to load from disk ag="<<allow_gen<<" block="<<block<<" p="<<p);
		block = map->loadBlock(p);
		if(block)
		{
// 			block->pushElementsToCircuit(m_circuit);
// 			m_circuit->processElementsQueue(*map, map->getNodeDefManager());
		}
		if (block && block->isGenerated())
			map->prepareBlock(block);
	}

	// If could not load and allowed to generate,
	// start generation inside this same envlock
	if (allow_gen && (!block)) {
		EMERGE_DBG_OUT("generating b="<<block);
		*b = block;
		return map->initBlockMake(data, p);
	}

	*b = block;
	return false;
}
Esempio n. 4
0
EmergeAction EmergeThread::getBlockOrStartGen(
	v3s16 pos, bool allow_gen, MapBlock **block, BlockMakeData *bmdata)
{
	//MutexAutoLock envlock(m_server->m_env_mutex);

	{
	MAP_NOTHREAD_LOCK(m_map);
	// 1). Attempt to fetch block from memory
	*block = m_map->getBlockNoCreateNoEx(pos, false, true);
	}
	if (*block && !(*block)->isDummy() && (*block)->isGenerated())
		return EMERGE_FROM_MEMORY;

	{
	MAP_NOTHREAD_LOCK(m_map);
	// 2). Attempt to load block from disk
	*block = m_map->loadBlock(pos);
	}

	if (*block && (*block)->isGenerated())
	{
		MAP_NOTHREAD_LOCK(m_map);
		m_map->prepareBlock(*block);
		return EMERGE_FROM_DISK;
	}

	{
	MAP_NOTHREAD_LOCK(m_map);
	// 3). Attempt to start generation
	if (allow_gen && m_map->initBlockMake(pos, bmdata))
		return EMERGE_GENERATED;
	}

/*
	verbosestream << "EmergeThread::getBlockOrStartGen : cancel pos=" << pos << " block="<< *block;
	if (*block)
		verbosestream << "dummy=" << (*block)->isDummy() << " generated="<< (*block)->isGenerated();
	verbosestream << std::endl;
*/

	// All attempts failed; cancel this block emerge
	return EMERGE_CANCELLED;
}