aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen/mapgen_carpathian.cpp
Commit message (Collapse)AuthorAge
* Change mapgen order to ores > dungeons > decorations (#7656)Paramat2018-08-20
| | | | | | | | | | | Previously dungeons > decorations > ores. Decorations depend on the node they are placed on, and ore types are increasingly able to place large continuous volumes of nodes, such as strata. Decorations are increasingly being used underground. The new order avoids a node being changed by ore generation after a decoration has been placed on it. The new order also avoids ores appearing in the walls of a dungeon if the wall nodes match the local stone node.
* Mapgen flags: Add 'biomes' global mapgen flag (#7355)Paramat2018-06-08
| | | | | | | | | Previously the only way to disable biomes was to 'clear' the registered biomes in a mod, but this method causes large amounts of unnecessary processing: 1. Calculation of 4 2D noises. 2. Looping through all nodes of a mapchunk replacing nodes with identical nodes. The new flag disables those operations.
* Mapgen caves: Re-order generation to fix cavern bugParamat2018-04-29
| | | | | | | Previously, caverns confused tunnel generation causing biome top and filler nodes to appear in caverns. Split 'generateCaves()' into 2 functions to separate tunnel and large randomwalk cave generation. In each mapgen re-order cave generation to generate tunnels before caverns.
* Biome API / dungeons: Add biome-defined dungeon nodesParamat2018-04-07
| | | | | | | | | | Add new biome fields 'node_dungeon', 'node_dungeon_alt', 'node_dungeon_stair'. If 'node_dungeon' is not defined dungeons fall back to classic behaviour. Remove messy and imprecise dungeon material code from 'generateBiomes()'. Code deciding dungeon materials is now in 'generateDungeons()' and uses the biome at mapchunk centre for more precision. Remove hardcoded 'MG_STONE' types as long intended.
* Mgcarpathian: Fix spawn level calculation (#7212)Paramat2018-04-06
|
* Mgcarpathian: Remove insignificant 'base' noise variation (#7209)Paramat2018-04-05
| | | | Was only +-1 node over a scale of thousands of nodes. Replace with 'base_level' parameter value.
* Fix various clang-tidy reported performance-type-promotion-in-math-fnLoïc Blot2018-04-03
|
* Fix many issues reported by clang-tidy (#7189)Loïc Blot2018-04-02
| | | | | | | | | | | * Fix many issues reported by clang-tidy We have many issues in code related to some performance to float <-> double. Clang-tidy reported it in performance-type-promotion-in-math-fn I fixed many of them. It's not ready for a promote to blocking Also fix some value which should be const-ref
* Mgcarpathian: Mapgen loop optimisations. fabs() -> std::fabs()Paramat2018-03-29
| | | | | | | * Mgcarpathian: ZYX -> ZXY mapgen loop optimisation. * 'pow(n, 3)' to 'n * n * n' type optimisations. * fabs() -> std::fabs().
* Dungeons: Add Y limits in all mapgensparamat2018-02-20
| | | | Preserve the upper limit used in mgvalleys.
* Mapgen folder: Update and improve copyright information of filesparamat2018-01-15
|
* Move files to subdirectories (#6599)Vitaliy2017-11-08
* Move files around
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef UTIL_CONTAINER_HEADER
#define UTIL_CONTAINER_HEADER

#include "../irrlichttypes.h"
#include "../exceptions.h"
#include "../jthread/jmutex.h"
#include "../jthread/jmutexautolock.h"
#include "../jthread/jsemaphore.h"
#include <list>
#include <vector>
#include <map>

/*
	Queue with unique values with fast checking of value existence
*/

template<typename Value>
class UniqueQueue
{
public:
	
	/*
		Does nothing if value is already queued.
		Return value:
			true: value added
			false: value already exists
	*/
	bool push_back(Value value)
	{
		// Check if already exists
		if(m_map.find(value) != m_map.end())
			return false;

		// Add
		m_map[value] = 0;
		m_list.push_back(value);
		
		return true;
	}

	Value pop_front()
	{
		typename std::list<Value>::iterator i = m_list.begin();
		Value value = *i;
		m_map.erase(value);
		m_list.erase(i);
		return value;
	}

	u32 size()
	{
		return m_map.size();
	}

private:
	std::map<Value, u8> m_map;
	std::list<Value> m_list;
};

#if 1
template<typename Key, typename Value>
class MutexedMap
{
public:
	MutexedMap()
	{
	}
	
	void set(const Key &name, const Value &value)
	{
		JMutexAutoLock lock(m_mutex);

		m_values[name] = value;
	}
	
	bool get(const Key &name, Value *result)
	{
		JMutexAutoLock lock(m_mutex);

		typename std::map<Key, Value>::iterator n;
		n = m_values.find(name);

		if(n == m_values.end())
			return false;
		
		if(result != NULL)
			*result = n->second;
			
		return true;
	}

	std::list<Value> getValues()
	{
		std::list<Value> result;
		for(typename std::map<Key, Value>::iterator
				i = m_values.begin();
				i != m_values.end(); ++i){
			result.push_back(i->second);
		}
		return result;
	}
	
	void clear ()
	{
		m_values.clear();
	}

private:
	std::map<Key, Value> m_values;
	JMutex m_mutex;
};
#endif

/*
	Generates ids for comparable values.
	Id=0 is reserved for "no value".

	Is fast at:
	- Returning value by id (very fast)
	- Returning id by value
	- Generating a new id for a value

	Is not able to:
	- Remove an id/value pair (is possible to implement but slow)
*/
template<typename T>
class MutexedIdGenerator
{
public:
	MutexedIdGenerator()
	{
	}
	
	// Returns true if found
	bool getValue(u32 id, T &value)
	{
		if(id == 0)
			return false;
		JMutexAutoLock lock(m_mutex);
		if(m_id_to_value.size() < id)
			return false;
		value = m_id_to_value[id-1];
		return true;
	}
	
	// If id exists for value, returns the id.
	// Otherwise generates an id for the value.
	u32 getId(const T &value)
	{
		JMutexAutoLock lock(m_mutex);
		typename std::map<T, u32>::iterator n;
		n = m_value_to_id.find(value);
		if(n != m_value_to_id.end())
			return n->second;
		m_id_to_value.push_back(value);
		u32 new_id = m_id_to_value.size();
		m_value_to_id.insert(value, new_id);
		return new_id;
	}

private:
	JMutex m_mutex;
	// Values are stored here at id-1 position (id 1 = [0])
	std::vector<T> m_id_to_value;
	std::map<T, u32> m_value_to_id;
};

/*
	FIFO queue (well, actually a FILO also)
*/
template<typename T>
class Queue
{
public:
	Queue():
		m_list_size(0)
	{}

	void push_back(T t)
	{
		m_list.push_back(t);
		++m_list_size;
	}
	
	void push_front(T t)
	{
		m_list.push_front(t);
		++m_list_size;
	}

	T pop_front()
	{
		if(m_list.empty())
			throw ItemNotFoundException("Queue: queue is empty");

		typename std::list<T>::iterator begin = m_list.begin();
		T t = *begin;
		m_list.erase(begin);
		--m_list_size;
		return t;
	}
	T pop_back()
	{
		if(m_list.empty())
			throw ItemNotFoundException("Queue: queue is empty");

		typename std::list<T>::iterator last = m_list.back();
		T t = *last;
		m_list.erase(last);
		--m_list_size;
		return t;
	}

	u32 size()
	{
		return m_list_size;
	}

	bool empty()
	{
		return m_list.empty();
	}

protected:
	std::list<T> m_list;
	u32 m_list_size;
};

/*
	Thread-safe FIFO queue (well, actually a FILO also)
*/

template<typename T>
class MutexedQueue
{
public:
	template<typename Key, typename U, typename Caller, typename CallerData>
	friend class RequestQueue;

	MutexedQueue()
	{
	}
	bool empty()
	{
		JMutexAutoLock lock(m_mutex);
		return (m_size.GetValue() == 0);
	}
	void push_back(T t)
	{
		JMutexAutoLock lock(m_mutex);
		m_list.push_back(t);
		m_size.Post();
	}

	/* this version of pop_front returns a empty element of T on timeout.
	 * Make sure default constructor of T creates a recognizable "empty" element
	 */
	T pop_frontNoEx(u32 wait_time_max_ms)
	{
		if (m_size.Wait(wait_time_max_ms))
		{
			JMutexAutoLock lock(m_mutex);

			typename std::list<T>::iterator begin = m_list.begin();
			T t = *begin;
			m_list.erase(begin);
			return t;
		}
		else
		{
			return T();
		}
	}

	T pop_front(u32 wait_time_max_ms)
	{
		if (m_size.Wait(wait_time_max_ms))
		{
			JMutexAutoLock lock(m_mutex);

			typename std::list<T>::iterator begin = m_list.begin();
			T t = *begin;
			m_list.erase(begin);
			return t;
		}
		else
		{
			throw ItemNotFoundException("MutexedQueue: queue is empty");
		}
	}

	T pop_frontNoEx()
	{
		m_size.Wait();

		JMutexAutoLock lock(m_mutex);

		typename std::list<T>::iterator begin = m_list.begin();
		T t = *begin;
		m_list.erase(begin);
		return t;
	}

	T pop_back(u32 wait_time_max_ms=0)
	{
		if (m_size.Wait(wait_time_max_ms))
		{
			JMutexAutoLock lock(m_mutex);

			typename std::list<T>::iterator last = m_list.end();
			last--;
			T t = *last;
			m_list.erase(last);
			return t;
		}
		else
		{
			throw ItemNotFoundException("MutexedQueue: queue is empty");
		}
	}

	/* this version of pop_back returns a empty element of T on timeout.
	 * Make sure default constructor of T creates a recognizable "empty" element
	 */
	T pop_backNoEx(u32 wait_time_max_ms=0)
	{
		if (m_size.Wait(wait_time_max_ms))
		{
			JMutexAutoLock lock(m_mutex);

			typename std::list<T>::iterator last = m_list.end();
			last--;
			T t = *last;
			m_list.erase(last);
			return t;
		}
		else
		{
			return T();
		}
	}

	T pop_backNoEx()
	{
		m_size.Wait();

		JMutexAutoLock lock(m_mutex);

		typename std::list<T>::iterator last = m_list.end();
		last--;
		T t = *last;
		m_list.erase(last);
		return t;
	}

protected:
	JMutex & getMutex()
	{
		return m_mutex;
	}

	// NEVER EVER modify the >>list<< you got by using this function!
	// You may only modify it's content
	std::list<T> & getList()
	{
		return m_list;
	}

	JMutex m_mutex;
	std::list<T> m_list;
	JSemaphore m_size;
};

#endif