1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Mapgen: Refactor mapgen creation and management

- Move mapgen creation logic out of EmergeManager and into Mapgen
- Internally represent mapgen type as an enum value, instead of a string
- Remove the need for a MapgenFactory per mapgen
This commit is contained in:
kwolekr 2016-06-14 00:10:55 -04:00
parent 70e2c1c7d4
commit 92705306bf
12 changed files with 160 additions and 164 deletions

View file

@ -26,7 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/string.h"
#include "util/container.h"
#define DEFAULT_MAPGEN "v6"
#define MAPGEN_DEFAULT MAPGEN_V6
#define MAPGEN_DEFAULT_NAME "v6"
/////////////////// Mapgen flags
#define MG_TREES 0x01
@ -107,6 +108,17 @@ private:
std::list<GenNotifyEvent> m_notify_events;
};
enum MapgenType {
MAPGEN_V5,
MAPGEN_V6,
MAPGEN_V7,
MAPGEN_FLAT,
MAPGEN_FRACTAL,
MAPGEN_VALLEYS,
MAPGEN_SINGLENODE,
MAPGEN_INVALID,
};
struct MapgenSpecificParams {
virtual void readParams(const Settings *settings) = 0;
virtual void writeParams(Settings *settings) const = 0;
@ -124,7 +136,7 @@ struct MapgenParams {
MapgenSpecificParams *sparams;
MapgenParams() :
mg_name(DEFAULT_MAPGEN),
mg_name(MAPGEN_DEFAULT_NAME),
chunksize(5),
seed(0),
water_level(1),
@ -173,6 +185,8 @@ public:
Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge);
virtual ~Mapgen();
virtual MapgenType getType() const { return MAPGEN_INVALID; }
static u32 getBlockSeed(v3s16 p, s32 seed);
static u32 getBlockSeed2(v3s16 p, s32 seed);
s16 findGroundLevelFull(v2s16 p2d);
@ -198,6 +212,14 @@ public:
// signify this and to cause Server::findSpawnPos() to try another (X, Z).
virtual int getSpawnLevelAtPoint(v2s16 p) { return 0; }
// Mapgen management functions
static MapgenType getMapgenType(const std::string &mgname);
static const char *getMapgenName(MapgenType mgtype);
static Mapgen *createMapgen(MapgenType mgtype, int mgid,
MapgenParams *params, EmergeManager *emerge);
static MapgenSpecificParams *createMapgenParams(MapgenType mgtype);
static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
private:
// isLiquidHorizontallyFlowable() is a helper function for updateLiquid()
// that checks whether there are floodable nodes without liquid beneath
@ -267,11 +289,4 @@ protected:
float cave_width;
};
struct MapgenFactory {
virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
EmergeManager *emerge) = 0;
virtual MapgenSpecificParams *createMapgenParams() = 0;
virtual ~MapgenFactory() {}
};
#endif