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.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2013-02-14 04:43:15 +01:00
|
|
|
|
|
|
|
#include <map>
|
2017-06-06 16:29:28 +02:00
|
|
|
#include <mutex>
|
2017-09-27 19:47:36 +02:00
|
|
|
#include "network/networkprotocol.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "irr_v3d.h"
|
|
|
|
#include "util/container.h"
|
2017-11-08 23:56:20 +01:00
|
|
|
#include "mapgen/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
|
|
|
|
2017-08-20 13:30:50 +02:00
|
|
|
#define EMERGE_DBG_OUT(x) { \
|
2015-10-04 08:54:25 +02:00
|
|
|
if (enable_mapgen_debug_info) \
|
|
|
|
infostream << "EmergeThread: " x << std::endl; \
|
2017-08-20 13:30:50 +02:00
|
|
|
}
|
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;
|
2017-01-09 20:39:22 +01:00
|
|
|
class Server;
|
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 {
|
2017-06-16 11:25:52 +02:00
|
|
|
MMVManip *vmanip = nullptr;
|
|
|
|
u64 seed = 0;
|
2013-02-14 04:43:15 +01:00
|
|
|
v3s16 blockpos_min;
|
|
|
|
v3s16 blockpos_max;
|
|
|
|
v3s16 blockpos_requested;
|
|
|
|
UniqueQueue<v3s16> transforming_liquid;
|
2017-06-16 11:25:52 +02:00
|
|
|
INodeDefManager *nodedef = nullptr;
|
2013-02-14 04:43:15 +01:00
|
|
|
|
2017-08-17 23:02:50 +02:00
|
|
|
BlockMakeData() = default;
|
|
|
|
|
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
|
2017-06-16 11:25:52 +02:00
|
|
|
u32 gen_notify_on = 0;
|
2014-12-06 10:18:04 +01:00
|
|
|
std::set<u32> gen_notify_on_deco_ids;
|
2013-12-14 07:52:06 +01:00
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
// Parameters passed to mapgens owned by ServerMap
|
|
|
|
// TODO(hmmmm): Remove this after mapgen helper methods using them
|
|
|
|
// are moved to ServerMap
|
|
|
|
MapgenParams *mgparams;
|
|
|
|
|
|
|
|
// Hackish workaround:
|
|
|
|
// For now, EmergeManager must hold onto a ptr to the Map's setting manager
|
|
|
|
// since the Map can only be accessed through the Environment, and the
|
|
|
|
// Environment is not created until after script initialization.
|
|
|
|
MapSettingsManager *map_settings_mgr;
|
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
|
2017-01-09 20:39:22 +01:00
|
|
|
EmergeManager(Server *server);
|
2013-02-14 04:43:15 +01:00
|
|
|
~EmergeManager();
|
2017-06-10 13:49:15 +02:00
|
|
|
DISABLE_CLASS_COPY(EmergeManager);
|
2013-02-14 04:43:15 +01:00
|
|
|
|
2016-06-25 00:15:56 +02:00
|
|
|
bool initMapgens(MapgenParams *mgparams);
|
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(
|
2017-09-27 19:47:36 +02:00
|
|
|
session_t peer_id,
|
2015-10-04 08:54:25 +02:00
|
|
|
v3s16 blockpos,
|
|
|
|
bool allow_generate,
|
|
|
|
bool ignore_queue_limits=false);
|
|
|
|
|
|
|
|
bool enqueueBlockEmergeEx(
|
|
|
|
v3s16 blockpos,
|
2017-09-27 19:47:36 +02:00
|
|
|
session_t peer_id,
|
2015-10-04 08:54:25 +02:00
|
|
|
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
|
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;
|
2017-06-16 11:25:52 +02:00
|
|
|
bool m_threads_active = false;
|
2015-10-04 08:54:25 +02:00
|
|
|
|
2017-06-06 16:29:28 +02:00
|
|
|
std::mutex m_queue_mutex;
|
2015-10-04 08:54:25 +02:00
|
|
|
std::map<v3s16, BlockEmergeData> m_blocks_enqueued;
|
2017-06-04 21:00:04 +02:00
|
|
|
std::unordered_map<u16, u16> m_peer_queue_count;
|
2015-10-04 08:54:25 +02:00
|
|
|
|
|
|
|
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;
|
2013-02-14 04:43:15 +01:00
|
|
|
};
|