aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen.h
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2016-06-14 00:10:55 -0400
committerkwolekr <kwolekr@minetest.net>2016-07-03 14:04:11 -0400
commit92705306bfb4994107a43514f29997cea15d48dc (patch)
treed1919cc2b5091ef6e31cdd312f5cd92ba058e76e /src/mapgen.h
parent70e2c1c7d413d20757f571e3f1e02b05c95418f1 (diff)
downloadminetest-92705306bfb4994107a43514f29997cea15d48dc.tar.gz
minetest-92705306bfb4994107a43514f29997cea15d48dc.tar.bz2
minetest-92705306bfb4994107a43514f29997cea15d48dc.zip
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
Diffstat (limited to 'src/mapgen.h')
-rw-r--r--src/mapgen.h33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/mapgen.h b/src/mapgen.h
index 90ac84bd8..618a2f6b8 100644
--- a/src/mapgen.h
+++ b/src/mapgen.h
@@ -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