From c24f3b0a65afc7654a8377fde29dec0709b1fc49 Mon Sep 17 00:00:00 2001
From: paramat <mat.gregory@virginmedia.com>
Date: Sat, 21 Nov 2015 20:22:45 +0000
Subject: [PATCH] Mgfractal: Move julia set selection into formula parameter

Improve default parameters
Update and improve documentation
Unhide mapgen, but is still unstable
---
 builtin/settingtypes.txt | 36 ++++++++++++++++-------------
 minetest.conf.example    | 49 ++++++++++++++++++++++++++--------------
 src/emerge.cpp           |  2 +-
 src/mapgen_fractal.cpp   | 25 ++++++++++----------
 src/mapgen_fractal.h     |  3 ---
 5 files changed, 65 insertions(+), 50 deletions(-)

diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt
index cb38ec118..2929b860b 100644
--- a/builtin/settingtypes.txt
+++ b/builtin/settingtypes.txt
@@ -970,29 +970,33 @@ mgflat_np_cave2 (Mapgen flat cave2 noise parameters) noise_params 0, 12, (128, 1
 
 [***Mapgen fractal]
 
-#    Map generation attributes specific to Mapgen fractal.
-#    The 'julia' flag results in the corresponding julia set being generated.
-#    Flags that are not specified in the flag string are not modified from the default.
-#    Flags starting with "no" are used to explicitly disable them.
-mgfractal_spflags (Mapgen fractal flags) flags nojulia julia,nojulia
-
-#    Choice of 4 mandelbrot set variations.
-#    1 = 4D "Roundy" mandelbrot set, 2 = 4D "Squarry" mandelbrot set,
-#    3 = 4D "Mandy Cousin" mandelbrot set, 4 = 4D mandelbrot set variation.
-mgfractal_formula (Mapgen fractal formula) int 1 1 4
+#    Choice of 8 4-dimensional fractals.
+#    1 = "Roundy" mandelbrot set.
+#    2 = "Roundy" julia set.
+#    3 = "Squarry" mandelbrot set.
+#    4 = "Squarry" julia set.
+#    5 = "Mandy Cousin" mandelbrot set.
+#    6 = "Mandy Cousin" julia set.
+#    7 = "Variation" mandelbrot set.
+#    8 = "Variation" julia set.
+mgfractal_formula (Mapgen fractal formula) int 1 1 8
 
 #    Iterations of the recursive function.
 #    Controls scale of finest detail.
-mgfractal_iterations (Mapgen fractal iterations) int 9
+mgfractal_iterations (Mapgen fractal iterations) int 11
 
-#    Approximate (X,Y,Z) scales in nodes.
-mgfractal_scale (Mapgen fractal scale) v3f (1024.0, 256.0, 1024.0)
+#    Approximate (X,Y,Z) scale of fractal in nodes.
+mgfractal_scale (Mapgen fractal scale) v3f (4096.0, 1024.0, 4096.0)
 
-#    (X,Y,Z) offsets from world centre.
-#    Range roughly -2 to 2, multiply by 'scale' for offsets in nodes.
-mgfractal_offset (Mapgen fractal offset) v3f (1.75, 0.0, 0.0)
+#    (X,Y,Z) offset of fractal from world centre.
+#    Used to move a suitable spawn area of low land close to (0, 0).
+#    The default is suitable for mandelbrot sets, it needs to be edited for julia sets,
+#    do this by greatly reducing 'scale' and setting 'offset' initially to (0, 0, 0).
+#    Range roughly -2 to 2. Multiply by 'scale' for offset in nodes.
+mgfractal_offset (Mapgen fractal offset) v3f (1.79, 0.0, 0.0)
 
 #    W co-ordinate of the generated 3D slice of the 4D shape.
+#    Alters the generated 3D shape.
 #    Range roughly -2 to 2.
 mgfractal_slice_w (Mapgen fractal slice w) float 0.0
 
diff --git a/minetest.conf.example b/minetest.conf.example
index d8534a0f5..37d622d3d 100644
--- a/minetest.conf.example
+++ b/minetest.conf.example
@@ -1234,44 +1234,59 @@
 
 #### Mapgen fractal
 
-#    Map generation attributes specific to Mapgen fractal.
-#    The 'julia' flag results in the corresponding julia set being generated.
-#    Flags that are not specified in the flag string are not modified from the default.
-#    Flags starting with "no" are used to explicitly disable them.
-#    type: flags possible values: julia, nojulia
-# mgfractal_spflags = nojulia
-
-#    Choice of 4 mandelbrot set variations.
-#    1 = 4D "Roundy" mandelbrot set, 2 = 4D "Squarry" mandelbrot set,
-#    3 = 4D "Mandy Cousin" mandelbrot set, 4 = 4D mandelbrot set variation.
+#    Choice of 8 4-dimensional fractals.
+#    1 = "Roundy" mandelbrot set.
+#    2 = "Roundy" julia set.
+#    3 = "Squarry" mandelbrot set.
+#    4 = "Squarry" julia set.
+#    5 = "Mandy Cousin" mandelbrot set.
+#    6 = "Mandy Cousin" julia set.
+#    7 = "Variation" mandelbrot set.
+#    8 = "Variation" julia set.
 #    type: int
 # mgfractal_formula = 1
 
 #    Iterations of the recursive function.
 #    Controls scale of finest detail.
 #    type: int
-# mgfractal_iterations = 9
+# mgfractal_iterations = 11
 
-#    Approximate (X,Y,Z) scales in nodes.
+#    Approximate (X,Y,Z) scale of fractal in nodes.
 #    type: v3f
-# mgfractal_scale = (1024.0, 256.0, 1024.0)
+# mgfractal_scale = (4096.0, 1024.0, 4096.0)
 
-#    (X,Y,Z) offsets from world centre.
-#    Range roughly -2 to 2, multiply by 'scale' for offsets in nodes.
+#    (X,Y,Z) offset of fractal from world centre.
+#    Used to move a suitable spawn area of low land close to (0, 0).
+#    The default is suitable for mandelbrot sets, it needs to be edited for julia sets,
+#    do this by greatly reducing 'scale' and setting 'offset' initially to (0, 0, 0).
+#    Range roughly -2 to 2. Multiply by 'scale' for offset in nodes.
 #    type: v3f
-# mgfractal_offset = (1.75, 0.0, 0.0)
+# mgfractal_offset = (1.79, 0.0, 0.0)
 
 #    W co-ordinate of the generated 3D slice of the 4D shape.
+#    Alters the generated 3D shape.
 #    Range roughly -2 to 2.
 #    type: float
 # mgfractal_slice_w = 0.0
 
-#    Julia set only: 4 values determining the 4D shape.
+#    Julia set only: X value determining the 4D shape.
 #    Range roughly -2 to 2.
 #    type: float
 # mgfractal_julia_x = 0.33
+
+#    Julia set only: Y value determining the 4D shape.
+#    Range roughly -2 to 2.
+#    type: float
 # mgfractal_julia_y = 0.33
+
+#    Julia set only: Z value determining the 4D shape.
+#    Range roughly -2 to 2.
+#    type: float
 # mgfractal_julia_z = 0.33
+
+#    Julia set only: W value determining the 4D shape.
+#    Range roughly -2 to 2.
+#    type: float
 # mgfractal_julia_w = 0.33
 
 #    type: noise_params
diff --git a/src/emerge.cpp b/src/emerge.cpp
index a60f67ac5..6d4d84d7f 100644
--- a/src/emerge.cpp
+++ b/src/emerge.cpp
@@ -107,7 +107,7 @@ MapgenDesc g_reg_mapgens[] = {
 	{"v6",         new MapgenFactoryV6,         true},
 	{"v7",         new MapgenFactoryV7,         true},
 	{"flat",       new MapgenFactoryFlat,       false},
-	{"fractal",    new MapgenFactoryFractal,    false},
+	{"fractal",    new MapgenFactoryFractal,    true},
 	{"singlenode", new MapgenFactorySinglenode, false},
 };
 
diff --git a/src/mapgen_fractal.cpp b/src/mapgen_fractal.cpp
index 26ebec353..676e2f446 100644
--- a/src/mapgen_fractal.cpp
+++ b/src/mapgen_fractal.cpp
@@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "content_sao.h"
 #include "nodedef.h"
 #include "voxelalgorithms.h"
-#include "profiler.h" // For TimeTaker
+//#include "profiler.h" // For TimeTaker
 #include "settings.h" // For g_settings
 #include "emerge.h"
 #include "dungeongen.h"
@@ -41,7 +41,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 
 FlagDesc flagdesc_mapgen_fractal[] = {
-	{"julia", MGFRACTAL_JULIA},
 	{NULL,    0}
 };
 
@@ -143,9 +142,9 @@ MapgenFractalParams::MapgenFractalParams()
 	spflags = 0;
 
 	formula = 1;
-	iterations = 9;
-	scale = v3f(1024.0, 256.0, 1024.0);
-	offset = v3f(1.75, 0.0, 0.0);
+	iterations = 11;
+	scale = v3f(4096.0, 1024.0, 4096.0);
+	offset = v3f(1.79, 0.0, 0.0);
 	slice_w = 0.0;
 
 	julia_x = 0.33;
@@ -236,7 +235,7 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
 	this->generating = true;
 	this->vm   = data->vmanip;
 	this->ndef = data->nodedef;
-	TimeTaker t("makeChunk");
+	//TimeTaker t("makeChunk");
 
 	v3s16 blockpos_min = data->blockpos_min;
 	v3s16 blockpos_max = data->blockpos_max;
@@ -319,7 +318,7 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
 	// Sprinkle some dust on top after everything else was generated
 	dustTopNodes();
 
-	printf("makeChunk: %dms\n", t.stop());
+	//printf("makeChunk: %dms\n", t.stop());
 
 	updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
 
@@ -369,7 +368,7 @@ bool MapgenFractal::getFractalAtPoint(s16 x, s16 y, s16 z)
 {
 	float cx, cy, cz, cw, ox, oy, oz, ow;
 
-	if (spflags & MGFRACTAL_JULIA) {  // Julia set
+	if (formula % 2 == 0) {  // Julia sets, formula = 2, 4, 6, 8
 		cx = julia_x;
 		cy = julia_y;
 		cz = julia_z;
@@ -378,7 +377,7 @@ bool MapgenFractal::getFractalAtPoint(s16 x, s16 y, s16 z)
 		oy = (float)y / scale.Y - offset.Y;
 		oz = (float)z / scale.Z - offset.Z;
 		ow = slice_w;
-	} else {  // Mandelbrot set
+	} else {  // Mandelbrot sets, formula = 1, 3, 5, 7
 		cx = (float)x / scale.X - offset.X;
 		cy = (float)y / scale.Y - offset.Y;
 		cz = (float)z / scale.Z - offset.Z;
@@ -395,22 +394,22 @@ bool MapgenFractal::getFractalAtPoint(s16 x, s16 y, s16 z)
 		float nz = 0.0f;
 		float nw = 0.0f;
 
-		if (formula == 1) {  // 4D "Roundy" Mandelbrot Set
+		if (formula == 1 || formula == 2) {  // 4D "Roundy" Mandelbrot/Julia Set
 			nx = ox * ox - oy * oy - oz * oz - ow * ow + cx;
 			ny = 2.0f * (ox * oy + oz * ow) + cy;
 			nz = 2.0f * (ox * oz + oy * ow) + cz;
 			nw = 2.0f * (ox * ow + oy * oz) + cw;
-		} else if (formula == 2) {  // 4D "Squarry" Mandelbrot Set
+		} else if (formula == 3 || formula == 4) {  // 4D "Squarry" Mandelbrot/Julia Set
 			nx = ox * ox - oy * oy - oz * oz - ow * ow + cx;
 			ny = 2.0f * (ox * oy + oz * ow) + cy;
 			nz = 2.0f * (ox * oz + oy * ow) + cz;
 			nw = 2.0f * (ox * ow - oy * oz) + cw;
-		} else if (formula == 3) {  // 4D "Mandy Cousin" Mandelbrot Set
+		} else if (formula == 5 || formula == 6) {  // 4D "Mandy Cousin" Mandelbrot/Julia Set
 			nx = ox * ox - oy * oy - oz * oz + ow * ow + cx;
 			ny = 2.0f * (ox * oy + oz * ow) + cy;
 			nz = 2.0f * (ox * oz + oy * ow) + cz;
 			nw = 2.0f * (ox * ow + oy * oz) + cw;
-		} else if (formula == 4) {  // 4D Mandelbrot Set Variation
+		} else if (formula == 7 || formula == 8) {  // 4D "Variation" Mandelbrot/Julia Set
 			nx = ox * ox - oy * oy - oz * oz - ow * ow + cx;
 			ny = 2.0f * (ox * oy + oz * ow) + cy;
 			nz = 2.0f * (ox * oz - oy * ow) + cz;
diff --git a/src/mapgen_fractal.h b/src/mapgen_fractal.h
index 5800ae20d..7d31a43b8 100644
--- a/src/mapgen_fractal.h
+++ b/src/mapgen_fractal.h
@@ -25,9 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #define MGFRACTAL_LARGE_CAVE_DEPTH -33
 
-/////////////////// Mapgen Fractal flags
-#define MGFRACTAL_JULIA 0x01
-
 class BiomeManager;
 
 extern FlagDesc flagdesc_mapgen_fractal[];
-- 
GitLab