mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Rewrite advanced noise generators to use new modular format.
This commit is contained in:
parent
6d523469ec
commit
a610763680
@ -22,6 +22,7 @@ using System.Net;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using MCGalaxy.Games;
|
using MCGalaxy.Games;
|
||||||
using MCGalaxy.Commands.World;
|
using MCGalaxy.Commands.World;
|
||||||
|
using MCGalaxy.Generator;
|
||||||
|
|
||||||
namespace MCGalaxy.Commands {
|
namespace MCGalaxy.Commands {
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using MCGalaxy.Generator;
|
||||||
|
|
||||||
namespace MCGalaxy.Commands.World {
|
namespace MCGalaxy.Commands.World {
|
||||||
public sealed class CmdNewLvl : Command {
|
public sealed class CmdNewLvl : Command {
|
||||||
|
@ -16,8 +16,7 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using MCGalaxy.Generator;
|
||||||
using MCGalaxy.SQL;
|
|
||||||
using MCGalaxy.Levels.IO;
|
using MCGalaxy.Levels.IO;
|
||||||
|
|
||||||
namespace MCGalaxy.Commands.World {
|
namespace MCGalaxy.Commands.World {
|
||||||
|
@ -19,6 +19,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using MCGalaxy.Generator;
|
||||||
using MCGalaxy.SQL;
|
using MCGalaxy.SQL;
|
||||||
|
|
||||||
namespace MCGalaxy.Eco {
|
namespace MCGalaxy.Eco {
|
||||||
|
@ -16,51 +16,87 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using LibNoise;
|
using LibNoise;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy.Generator {
|
||||||
public static class AdvNoiseGen {
|
public static class AdvNoiseGen {
|
||||||
|
|
||||||
public unsafe static void Generate(Level lvl, string type, bool useSeed, int seed) {
|
static Dictionary<string, Action<MapGenArgs>> generators
|
||||||
switch (type) {
|
= new Dictionary<string, Action<MapGenArgs>>{
|
||||||
case "billow":
|
{ "billow", GenBillow2D }, { "ridgedmultifractal", GenRidged2D },
|
||||||
Billow billow2D = new Billow();
|
{ "perlin", GenPerlin2D }, { "checkerboard", GenCheckerboard },
|
||||||
billow2D.Seed = useSeed ? seed : new Random().Next();
|
{ "spheres", GenSpheres }, { "cylinders", GenCylinders },
|
||||||
Generate2D(lvl, billow2D); break;
|
{ "voronoi", GenVoronoi }, { "perlin3d", GenPerlin3D },
|
||||||
case "ridgedmultifractal":
|
{ "perlin3dyadjust", GenPerlin3DYAdjust }, { "billow3d", GenBillow3D }
|
||||||
RidgedMultifractal ridged2D = new RidgedMultifractal();
|
};
|
||||||
ridged2D.Seed = useSeed ? seed : new Random().Next();
|
|
||||||
Generate2D(lvl, ridged2D); break;
|
public static void Generate(MapGenArgs args) {
|
||||||
case "perlin":
|
Action<MapGenArgs> generator;
|
||||||
Perlin perlin2D = new Perlin();
|
generators.TryGetValue(args.Type, out generator);
|
||||||
perlin2D.Seed = useSeed ? seed : new Random().Next();
|
if (generator != null) generator(args);
|
||||||
Generate2D(lvl, perlin2D); break;
|
|
||||||
case "checkerboard":
|
|
||||||
Generate2D(lvl, new Checkerboard()); break;
|
|
||||||
case "spheres":
|
|
||||||
Generate2D(lvl, new Spheres()); break;
|
|
||||||
case "cylinders":
|
|
||||||
Generate2D(lvl, new Cylinders()); break;
|
|
||||||
case "voronoi":
|
|
||||||
Voronoi voronoi2D = new Voronoi();
|
|
||||||
voronoi2D.Seed = useSeed ? seed : new Random().Next();
|
|
||||||
Generate2D(lvl, voronoi2D); break;
|
|
||||||
case "perlin3d":
|
|
||||||
Perlin perlin3D = new Perlin();
|
|
||||||
perlin3D.Seed = useSeed ? seed : new Random().Next();
|
|
||||||
Generate3D(lvl, perlin3D); break;
|
|
||||||
case "perlin3dyadjust":
|
|
||||||
Perlin adjNoise = new Perlin();
|
|
||||||
adjNoise.Seed = useSeed ? seed : new Random().Next();
|
|
||||||
Generate3DYAdjust(lvl, adjNoise); break;
|
|
||||||
case "billow3d":
|
|
||||||
Billow billow3D = new Billow();
|
|
||||||
billow3D.Seed = useSeed ? seed : new Random().Next();
|
|
||||||
Generate3D(lvl, billow3D); break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Generate2D(Level lvl, IModule module) {
|
#region Implementations
|
||||||
|
|
||||||
|
static void GenBillow2D(MapGenArgs args) {
|
||||||
|
Billow billow2D = new Billow();
|
||||||
|
billow2D.Seed = args.UseSeed ? args.Seed : new Random().Next();
|
||||||
|
Gen2D(args, billow2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenRidged2D(MapGenArgs args) {
|
||||||
|
RidgedMultifractal ridged2D = new RidgedMultifractal();
|
||||||
|
ridged2D.Seed = args.UseSeed ? args.Seed : new Random().Next();
|
||||||
|
Gen2D(args, ridged2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenPerlin2D(MapGenArgs args) {
|
||||||
|
Perlin perlin2D = new Perlin();
|
||||||
|
perlin2D.Seed = args.UseSeed ? args.Seed : new Random().Next();
|
||||||
|
Gen2D(args, perlin2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenCheckerboard(MapGenArgs args) {
|
||||||
|
Gen2D(args, new Checkerboard());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenSpheres(MapGenArgs args) {
|
||||||
|
Gen2D(args, new Spheres());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenCylinders(MapGenArgs args) {
|
||||||
|
Gen2D(args, new Cylinders());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenVoronoi(MapGenArgs args) {
|
||||||
|
Voronoi voronoi2D = new Voronoi();
|
||||||
|
voronoi2D.Seed = args.UseSeed ? args.Seed : new Random().Next();
|
||||||
|
Gen2D(args, voronoi2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenPerlin3D(MapGenArgs args) {
|
||||||
|
Perlin perlin3D = new Perlin();
|
||||||
|
perlin3D.Seed = args.UseSeed ? args.Seed : new Random().Next();
|
||||||
|
Gen3D(args, perlin3D);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenPerlin3DYAdjust(MapGenArgs args) {
|
||||||
|
Perlin adjNoise = new Perlin();
|
||||||
|
adjNoise.Seed = args.UseSeed ? args.Seed : new Random().Next();
|
||||||
|
Gen3DYAdjust(args, adjNoise);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GenBillow3D(MapGenArgs args) {
|
||||||
|
Billow billow3D = new Billow();
|
||||||
|
billow3D.Seed = args.UseSeed ? args.Seed : new Random().Next();
|
||||||
|
Gen3D(args, billow3D);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
static void Gen2D(MapGenArgs args, IModule module) {
|
||||||
|
Level lvl = args.Level;
|
||||||
int width = lvl.Width, length = lvl.Length, half = lvl.Height / 2;
|
int width = lvl.Width, length = lvl.Length, half = lvl.Height / 2;
|
||||||
int waterHeight = half - 1;
|
int waterHeight = half - 1;
|
||||||
|
|
||||||
@ -84,7 +120,8 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Generate3D(Level lvl, IModule module) {
|
static void Gen3D(MapGenArgs args, IModule module) {
|
||||||
|
Level lvl = args.Level;
|
||||||
int width = lvl.Width, height = lvl.Height, length = lvl.Length;
|
int width = lvl.Width, height = lvl.Height, length = lvl.Length;
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
for (int z = 0; z < length; ++z)
|
for (int z = 0; z < length; ++z)
|
||||||
@ -96,7 +133,8 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Generate3DYAdjust(Level lvl, IModule module) {
|
static void Gen3DYAdjust(MapGenArgs args, IModule module) {
|
||||||
|
Level lvl = args.Level;
|
||||||
int width = lvl.Width, height = lvl.Height, length = lvl.Length;
|
int width = lvl.Width, height = lvl.Height, length = lvl.Length;
|
||||||
for (int y = 0; y < height; y++)
|
for (int y = 0; y < height; y++)
|
||||||
for (int z = 0; z < length; ++z)
|
for (int z = 0; z < length; ++z)
|
||||||
|
@ -16,8 +16,9 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy.Generator {
|
||||||
public static class MapGen {
|
public static class MapGen {
|
||||||
public static bool IsRecognisedTheme(string s) {
|
public static bool IsRecognisedTheme(string s) {
|
||||||
s = s.ToLower();
|
s = s.ToLower();
|
||||||
@ -55,6 +56,11 @@ namespace MCGalaxy {
|
|||||||
if (useSeed && !int.TryParse(args, out seed))
|
if (useSeed && !int.TryParse(args, out seed))
|
||||||
seed = args.GetHashCode();
|
seed = args.GetHashCode();
|
||||||
|
|
||||||
|
MapGenArgs genArgs = new MapGenArgs();
|
||||||
|
genArgs.Level = lvl; genArgs.Type = type;
|
||||||
|
genArgs.RawArgs = args;
|
||||||
|
genArgs.UseSeed = useSeed; genArgs.Seed = seed;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "flat":
|
case "flat":
|
||||||
int grassHeight = height / 2;
|
int grassHeight = height / 2;
|
||||||
@ -138,7 +144,15 @@ namespace MCGalaxy {
|
|||||||
case "desert":
|
case "desert":
|
||||||
generator.GenerateMap(lvl, type, seed, useSeed); return;
|
generator.GenerateMap(lvl, type, seed, useSeed); return;
|
||||||
}
|
}
|
||||||
AdvNoiseGen.Generate(lvl, type, useSeed, seed);
|
AdvNoiseGen.Generate(genArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct MapGenArgs {
|
||||||
|
public Level Level;
|
||||||
|
public string Type;
|
||||||
|
public string RawArgs;
|
||||||
|
public bool UseSeed;
|
||||||
|
public int Seed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ Ideas, concepts, and code were used from the following two sources:
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy.Generator {
|
||||||
public static class NoiseGen {
|
public static class NoiseGen {
|
||||||
public static void GenerateNormalized(float[] array, float persistence, int octaves, int width, int height, int seed, float zoom) {
|
public static void GenerateNormalized(float[] array, float persistence, int octaves, int width, int height, int seed, float zoom) {
|
||||||
float min = float.MaxValue, max = float.MinValue;
|
float min = float.MaxValue, max = float.MinValue;
|
||||||
|
@ -28,7 +28,7 @@ using System;
|
|||||||
using MCGalaxy.Drawing;
|
using MCGalaxy.Drawing;
|
||||||
using MCGalaxy.Drawing.Ops;
|
using MCGalaxy.Drawing.Ops;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy.Generator {
|
||||||
public sealed class RealisticMapGen {
|
public sealed class RealisticMapGen {
|
||||||
float[] terrain, overlay, overlay2;
|
float[] terrain, overlay, overlay2;
|
||||||
float treeDens;
|
float treeDens;
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy.Generator {
|
||||||
public sealed class RealisticGenParams {
|
public sealed class RealisticGenParams {
|
||||||
public float RangeLow = 0.2f;
|
public float RangeLow = 0.2f;
|
||||||
public float RangeHigh = 0.8f;
|
public float RangeHigh = 0.8f;
|
||||||
|
@ -17,21 +17,17 @@
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
|
||||||
using System.Data.Common;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using MCGalaxy.SQL;
|
|
||||||
using Timer = System.Timers.Timer;
|
|
||||||
using MCGalaxy.BlockPhysics;
|
using MCGalaxy.BlockPhysics;
|
||||||
using MCGalaxy.Config;
|
using MCGalaxy.Config;
|
||||||
using MCGalaxy.Games;
|
using MCGalaxy.Games;
|
||||||
|
using MCGalaxy.Generator;
|
||||||
using MCGalaxy.Levels.IO;
|
using MCGalaxy.Levels.IO;
|
||||||
using MCGalaxy.SQL.Native;
|
using Timer = System.Timers.Timer;
|
||||||
|
|
||||||
//WARNING! DO NOT CHANGE THE WAY THE LEVEL IS SAVED/LOADED!
|
//WARNING! DO NOT CHANGE THE WAY THE LEVEL IS SAVED/LOADED!
|
||||||
//You MUST make it able to save and load as a new version other wise you will make old levels incompatible!
|
//You MUST make it able to save and load as a new version other wise you will make old levels incompatible!
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user