2013-04-06 17:19:59 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2013-02-14 04:43:15 +01:00
|
|
|
#ifndef EMERGE_HEADER
|
|
|
|
#define EMERGE_HEADER
|
|
|
|
|
|
|
|
#include <map>
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "irr_v3d.h"
|
|
|
|
#include "util/container.h"
|
2014-02-04 04:42:10 +01:00
|
|
|
#include "mapgen.h" // for MapgenParams
|
2014-11-13 05:01:13 +01:00
|
|
|
#include "map.h"
|
2013-02-14 04:43:15 +01:00
|
|
|
|
2015-10-04 08:54:25 +02:00
|
|
|
#define BLOCK_EMERGE_ALLOW_GEN (1 << 0)
|
|
|
|
#define BLOCK_EMERGE_FORCE_QUEUE (1 << 1)
|
2013-02-14 04:43:15 +01:00
|
|
|
|
2015-10-04 08:54:25 +02:00
|
|
|
#define EMERGE_DBG_OUT(x) do { \
|
|
|
|
if (enable_mapgen_debug_info) \
|
|
|
|
infostream << "EmergeThread: " x << std::endl; \
|
|
|
|
} while (0)
|
2013-02-17 08:46:08 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
class EmergeThread;
|
|
|
|
class INodeDefManager;
|
|
|
|
class Settings;
|
2014-11-13 05:01:13 +01:00
|
|
|
|
|
|
|
class BiomeManager;
|
|
|
|
class OreManager;
|
|
|
|
class DecorationManager;
|
|
|
|
class SchematicManager;
|
2013-02-14 04:43:15 +01:00
|
|
|
|
2015-10-04 08:54:25 +02:00
|
|
|
// Structure containing inputs/outputs for chunk generation
|
2013-02-14 04:43:15 +01:00
|
|
|
struct BlockMakeData {
|
2015-01-05 08:42:27 +01:00
|
|
|
MMVManip *vmanip;
|
2013-02-14 04:43:15 +01:00
|
|
|
u64 seed;
|
|
|
|
v3s16 blockpos_min;
|
|
|
|
v3s16 blockpos_max;
|
|
|
|
v3s16 blockpos_requested;
|
|
|
|
UniqueQueue<v3s16> transforming_liquid;
|
|
|
|
INodeDefManager *nodedef;
|
|
|
|
|
2013-02-15 00:32:56 +01:00
|
|
|
BlockMakeData():
|
|
|
|
vmanip(NULL),
|
|
|
|
seed(0),
|
|
|
|
nodedef(NULL)
|
|
|
|
{}
|
2013-02-14 04:43:15 +01:00
|
|
|
|
2013-02-15 00:32:56 +01:00
|
|
|
~BlockMakeData() { delete vmanip; }
|
|
|
|
};
|
|
|
|
|
2015-10-04 08:54:25 +02:00
|
|
|
// Result from processing an item on the emerge queue
|
|
|
|
enum EmergeAction {
|
|
|
|
EMERGE_CANCELLED,
|
|
|
|
EMERGE_ERRORED,
|
|
|
|
EMERGE_FROM_MEMORY,
|
|
|
|
EMERGE_FROM_DISK,
|
|
|
|
EMERGE_GENERATED,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Callback
|
|
|
|
typedef void (*EmergeCompletionCallback)(
|
|
|
|
v3s16 blockpos, EmergeAction action, void *param);
|
|
|
|
|
|
|
|
typedef std::vector<
|
|
|
|
std::pair<
|
|
|
|
EmergeCompletionCallback,
|
|
|
|
void *
|
|
|
|
>
|
|
|
|
> EmergeCallbackList;
|
|
|
|
|
2013-02-15 00:32:56 +01:00
|
|
|
struct BlockEmergeData {
|
|
|
|
u16 peer_requested;
|
2015-10-04 08:54:25 +02:00
|
|
|
u16 flags;
|
|
|
|
EmergeCallbackList callbacks;
|
2013-02-14 04:43:15 +01:00
|
|
|
};
|
|
|
|
|
2014-02-09 22:36:30 +01:00
|
|
|
class EmergeManager {
|
2013-02-14 04:43:15 +01:00
|
|
|
public:
|
2013-04-06 17:19:59 +02:00
|
|
|
INodeDefManager *ndef;
|
2015-10-04 08:54:25 +02:00
|
|
|
bool enable_mapgen_debug_info;
|
2013-04-06 17:19:59 +02:00
|
|
|
|
2015-10-04 08:54:25 +02:00
|
|
|
// Generation Notify
|
2014-12-06 10:18:04 +01:00
|
|
|
u32 gen_notify_on;
|
|
|
|
std::set<u32> gen_notify_on_deco_ids;
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2015-10-04 08:54:25 +02:00
|
|
|
// Map generation parameters
|
|
|
|
MapgenParams params;
|
2013-02-14 04:43:15 +01:00
|
|
|
|
2015-10-04 08:54:25 +02:00
|
|
|
// Managers of various map generation-related components
|
2014-11-13 05:01:13 +01:00
|
|
|
BiomeManager *biomemgr;
|
|
|
|
OreManager *oremgr;
|
|
|
|
DecorationManager *decomgr;
|
|
|
|
SchematicManager *schemmgr;
|
2013-02-14 04:43:15 +01:00
|
|
|
|
2015-10-04 08:54:25 +02:00
|
|
|
// Methods
|
2013-04-06 17:19:59 +02:00
|
|
|
EmergeManager(IGameDef *gamedef);
|
2013-02-14 04:43:15 +01:00
|
|
|
~EmergeManager();
|
|
|
|
|
2014-02-16 00:20:15 +01:00
|
|
|
void loadMapgenParams();
|
2014-02-04 04:42:10 +01:00
|
|
|
void initMapgens();
|
2015-10-04 08:54:25 +02:00
|
|
|
|
2014-01-26 07:12:18 +01:00
|
|
|
void startThreads();
|
|
|
|
void stopThreads();
|
2015-10-04 23:26:08 +02:00
|
|
|
bool isRunning();
|
2015-10-04 08:54:25 +02:00
|
|
|
|
|
|
|
bool enqueueBlockEmerge(
|
|
|
|
u16 peer_id,
|
|
|
|
v3s16 blockpos,
|
|
|
|
bool allow_generate,
|
|
|
|
bool ignore_queue_limits=false);
|
|
|
|
|
|
|
|
bool enqueueBlockEmergeEx(
|
|
|
|
v3s16 blockpos,
|
|
|
|
u16 peer_id,
|
|
|
|
u16 flags,
|
|
|
|
EmergeCompletionCallback callback,
|
|
|
|
void *callback_param);
|
2013-12-08 05:43:46 +01:00
|
|
|
|
2015-09-23 06:31:45 +02:00
|
|
|
v3s16 getContainingChunk(v3s16 blockpos);
|
|
|
|
|
2015-10-04 08:54:25 +02:00
|
|
|
Mapgen *getCurrentMapgen();
|
|
|
|
|
|
|
|
// Mapgen helpers methods
|
2013-02-14 04:43:15 +01:00
|
|
|
Biome *getBiomeAtPoint(v3s16 p);
|
2016-02-04 02:03:31 +01:00
|
|
|
int getSpawnLevelAtPoint(v2s16 p);
|
2013-02-14 04:43:15 +01:00
|
|
|
int getGroundLevelAtPoint(v2s16 p);
|
|
|
|
bool isBlockUnderground(v3s16 blockpos);
|
2015-10-04 08:54:25 +02:00
|
|
|
|
|
|
|
static v3s16 getContainingChunk(v3s16 blockpos, s16 chunksize);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Mapgen *> m_mapgens;
|
|
|
|
std::vector<EmergeThread *> m_threads;
|
|
|
|
bool m_threads_active;
|
|
|
|
|
|
|
|
Mutex m_queue_mutex;
|
|
|
|
std::map<v3s16, BlockEmergeData> m_blocks_enqueued;
|
|
|
|
std::map<u16, u16> m_peer_queue_count;
|
|
|
|
|
|
|
|
u16 m_qlimit_total;
|
|
|
|
u16 m_qlimit_diskonly;
|
|
|
|
u16 m_qlimit_generate;
|
|
|
|
|
|
|
|
// Requires m_queue_mutex held
|
|
|
|
EmergeThread *getOptimalThread();
|
2015-11-14 09:07:21 +01:00
|
|
|
|
|
|
|
bool pushBlockEmergeData(
|
|
|
|
v3s16 pos,
|
|
|
|
u16 peer_requested,
|
|
|
|
u16 flags,
|
|
|
|
EmergeCompletionCallback callback,
|
|
|
|
void *callback_param,
|
|
|
|
bool *entry_already_exists);
|
|
|
|
|
2015-10-04 08:54:25 +02:00
|
|
|
bool popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata);
|
|
|
|
|
|
|
|
friend class EmergeThread;
|
2015-10-27 07:51:43 +01:00
|
|
|
|
|
|
|
DISABLE_CLASS_COPY(EmergeManager);
|
2013-02-14 04:43:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|