Clean up Mapgen

master
kwolekr 2013-03-11 21:32:52 -04:00
parent eb90c3d92d
commit d10223254a
6 changed files with 798 additions and 3234 deletions

File diff suppressed because it is too large Load Diff

View File

@ -72,6 +72,11 @@ public:
int water_level; int water_level;
bool generating; bool generating;
int id; int id;
ManualMapVoxelManipulator *vm;
INodeDefManager *ndef;
void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
void updateLighting(v3s16 nmin, v3s16 nmax);
virtual void makeChunk(BlockMakeData *data) {}; virtual void makeChunk(BlockMakeData *data) {};
virtual int getGroundLevelAtPoint(v2s16 p) = 0; virtual int getGroundLevelAtPoint(v2s16 p) = 0;

File diff suppressed because it is too large Load Diff

View File

@ -20,10 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef MAPGENV6_HEADER #ifndef MAPGENV6_HEADER
#define MAPGENV6_HEADER #define MAPGENV6_HEADER
#include "dungeongen.h"
#include "mapgen.h" #include "mapgen.h"
#define AVERAGE_MUD_AMOUNT 4 #define AVERAGE_MUD_AMOUNT 4
#define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
enum BiomeType enum BiomeType
{ {
@ -74,13 +74,17 @@ struct MapgenV6Params : public MapgenParams {
class MapgenV6 : public Mapgen { class MapgenV6 : public Mapgen {
public: public:
//ManualMapVoxelManipulator &vmanip;
int ystride; int ystride;
v3s16 csize; v3s16 csize;
u32 flags;
u32 blockseed;
v3s16 node_min; v3s16 node_min;
v3s16 node_max; v3s16 node_max;
v3s16 full_node_min;
v3s16 full_node_max;
v3s16 central_area_size;
int volume_nodes;
Noise *noise_terrain_base; Noise *noise_terrain_base;
Noise *noise_terrain_higher; Noise *noise_terrain_higher;
@ -90,21 +94,20 @@ public:
Noise *noise_mud; Noise *noise_mud;
Noise *noise_beach; Noise *noise_beach;
Noise *noise_biome; Noise *noise_biome;
float *map_terrain_base;
float *map_terrain_higher;
float *map_steepness;
float *map_height_select;
float *map_trees;
float *map_mud;
float *map_beach;
float *map_biome;
NoiseParams *np_cave; NoiseParams *np_cave;
u32 flags;
float freq_desert; float freq_desert;
float freq_beach; float freq_beach;
content_t c_stone;
content_t c_dirt;
content_t c_dirt_with_grass;
content_t c_sand;
content_t c_water_source;
content_t c_lava_source;
content_t c_gravel;
content_t c_cobble;
content_t c_desert_sand;
content_t c_desert_stone;
MapgenV6(int mapgenid, MapgenV6Params *params); MapgenV6(int mapgenid, MapgenV6Params *params);
~MapgenV6(); ~MapgenV6();
@ -112,21 +115,37 @@ public:
void makeChunk(BlockMakeData *data); void makeChunk(BlockMakeData *data);
int getGroundLevelAtPoint(v2s16 p); int getGroundLevelAtPoint(v2s16 p);
double baseRockLevelFromNoise(v2s16 p); float baseTerrainLevel(float terrain_base, float terrain_higher,
static s16 find_ground_level(VoxelManipulator &vmanip, float steepness, float height_select);
v2s16 p2d, INodeDefManager *ndef); float baseTerrainLevelFromNoise(v2s16 p);
static s16 find_stone_level(VoxelManipulator &vmanip, float baseTerrainLevelFromMap(v2s16 p);
v2s16 p2d, INodeDefManager *ndef); float baseTerrainLevelFromMap(int index);
void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
bool is_apple_tree, INodeDefManager *ndef); s16 find_ground_level(v2s16 p2d);
double tree_amount_2d(u64 seed, v2s16 p); s16 find_stone_level(v2s16 p2d);
bool block_is_underground(u64 seed, v3s16 blockpos); bool block_is_underground(u64 seed, v3s16 blockpos);
double base_rock_level_2d(u64 seed, v2s16 p);
s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision); s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
double get_mud_add_amount(u64 seed, v2s16 p);
bool get_have_beach(u64 seed, v2s16 p2d); float getTreeAmount(v2s16 p);
BiomeType get_biome(u64 seed, v2s16 p2d); float getTreeAmount(int index);
float getMudAmount(v2s16 p);
float getMudAmount(int index);
bool getHaveBeach(v2s16 p);
bool getHaveBeach(int index);
BiomeType getBiome(v2s16 p);
BiomeType getBiome(int index, v2s16 p);
u32 get_blockseed(u64 seed, v3s16 p); u32 get_blockseed(u64 seed, v3s16 p);
void calculateNoise();
int generateGround();
void addMud();
void flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos);
void addDirtGravelBlobs();
void growGrass();
void placeTrees();
void generateCaves(int max_stone_y);
}; };
struct MapgenFactoryV6 : public MapgenFactory { struct MapgenFactoryV6 : public MapgenFactory {

View File

@ -28,15 +28,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
namespace treegen namespace treegen
{ {
void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
bool is_apple_tree, INodeDefManager *ndef,int seed) bool is_apple_tree, INodeDefManager *ndef, int seed)
{ {
MapNode treenode(ndef->getId("mapgen_tree")); MapNode treenode(ndef->getId("mapgen_tree"));
MapNode leavesnode(ndef->getId("mapgen_leaves")); MapNode leavesnode(ndef->getId("mapgen_leaves"));
MapNode applenode(ndef->getId("mapgen_apple")); MapNode applenode(ndef->getId("mapgen_apple"));
PseudoRandom ps(seed); PseudoRandom pr(seed);
s16 trunk_h = ps.range(4, 5); s16 trunk_h = pr.range(4, 5);
v3s16 p1 = p0; v3s16 p1 = p0;
for(s16 ii=0; ii<trunk_h; ii++) for(s16 ii=0; ii<trunk_h; ii++)
{ {
@ -72,9 +73,9 @@ void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
s16 d = 1; s16 d = 1;
v3s16 p( v3s16 p(
ps.range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X-d), pr.range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X-d),
ps.range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y-d), pr.range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y-d),
ps.range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z-d) pr.range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z-d)
); );
for(s16 z=0; z<=d; z++) for(s16 z=0; z<=d; z++)
@ -100,7 +101,7 @@ void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
continue; continue;
u32 i = leaves_a.index(x,y,z); u32 i = leaves_a.index(x,y,z);
if(leaves_d[i] == 1) { if(leaves_d[i] == 1) {
bool is_apple = ps.range(0,99) < 10; bool is_apple = pr.range(0,99) < 10;
if(is_apple_tree && is_apple) { if(is_apple_tree && is_apple) {
vmanip.m_data[vi] = applenode; vmanip.m_data[vi] = applenode;
} else { } else {
@ -111,7 +112,7 @@ void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
} }
// L-System tree LUA spawner // L-System tree LUA spawner
void spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef, TreeDef tree_definition) void spawn_ltree(ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef, TreeDef tree_definition)
{ {
ServerMap *map = &env->getServerMap(); ServerMap *map = &env->getServerMap();
std::map<v3s16, MapBlock*> modified_blocks; std::map<v3s16, MapBlock*> modified_blocks;
@ -506,17 +507,17 @@ v3f transposeMatrix(irr::core::matrix4 M, v3f v)
return translated; return translated;
} }
#if 0 void make_jungletree(VoxelManipulator &vmanip, v3s16 p0,
static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef, int seed)
INodeDefManager *ndef)
{ {
MapNode treenode(ndef->getId("mapgen_jungletree")); MapNode treenode(ndef->getId("mapgen_jungletree"));
MapNode leavesnode(ndef->getId("mapgen_leaves")); MapNode leavesnode(ndef->getId("mapgen_leaves"));
PseudoRandom pr(seed);
for(s16 x=-1; x<=1; x++) for(s16 x=-1; x<=1; x++)
for(s16 z=-1; z<=1; z++) for(s16 z=-1; z<=1; z++)
{ {
if(myrand_range(0, 2) == 0) if(pr.range(0, 2) == 0)
continue; continue;
v3s16 p1 = p0 + v3s16(x,0,z); v3s16 p1 = p0 + v3s16(x,0,z);
v3s16 p2 = p0 + v3s16(x,-1,z); v3s16 p2 = p0 + v3s16(x,-1,z);
@ -527,7 +528,7 @@ static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0,
vmanip.m_data[vmanip.m_area.index(p1)] = treenode; vmanip.m_data[vmanip.m_area.index(p1)] = treenode;
} }
s16 trunk_h = myrand_range(8, 12); s16 trunk_h = pr.range(8, 12);
v3s16 p1 = p0; v3s16 p1 = p0;
for(s16 ii=0; ii<trunk_h; ii++) for(s16 ii=0; ii<trunk_h; ii++)
{ {
@ -562,9 +563,9 @@ static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0,
s16 d = 1; s16 d = 1;
v3s16 p( v3s16 p(
myrand_range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X-d), pr.range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X-d),
myrand_range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y-d), pr.range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y-d),
myrand_range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z-d) pr.range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z-d)
); );
for(s16 z=0; z<=d; z++) for(s16 z=0; z<=d; z++)
@ -593,6 +594,5 @@ static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0,
vmanip.m_data[vi] = leavesnode; vmanip.m_data[vi] = leavesnode;
} }
} }
#endif
}; // namespace treegen }; // namespace treegen

View File

@ -27,33 +27,36 @@ class ManualMapVoxelManipulator;
class INodeDefManager; class INodeDefManager;
namespace treegen namespace treegen {
{
struct TreeDef struct TreeDef {
{ std::string initial_axiom;
std::string initial_axiom; std::string rules_a;
std::string rules_a; std::string rules_b;
std::string rules_b; std::string rules_c;
std::string rules_c; std::string rules_d;
std::string rules_d;
MapNode trunknode; MapNode trunknode;
MapNode leavesnode; MapNode leavesnode;
MapNode leaves2node; MapNode leaves2node;
int leaves2_chance;
int angle; int leaves2_chance;
int iterations; int angle;
int iterations_random_level; int iterations;
std::string trunk_type; int iterations_random_level;
bool thin_branches; std::string trunk_type;
MapNode fruitnode; bool thin_branches;
int fruit_chance; MapNode fruitnode;
int seed; int fruit_chance;
}; int seed;
};
// Add default tree // Add default tree
void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
bool is_apple_tree, INodeDefManager *ndef,int seed); bool is_apple_tree, INodeDefManager *ndef, int seed);
// Add jungle tree
void make_jungletree(VoxelManipulator &vmanip, v3s16 p0,
INodeDefManager *ndef, int seed);
// Add L-Systems tree (used by engine) // Add L-Systems tree (used by engine)
void make_ltree(ManualMapVoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef, void make_ltree(ManualMapVoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef,
@ -73,7 +76,7 @@ int seed;
PseudoRandom ps, TreeDef &tree_definition); PseudoRandom ps, TreeDef &tree_definition);
void tree_fruit_placement(ManualMapVoxelManipulator &vmanip, v3f p0, void tree_fruit_placement(ManualMapVoxelManipulator &vmanip, v3f p0,
TreeDef &tree_definition); TreeDef &tree_definition);
irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle,v3f axis); irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle, v3f axis);
v3f transposeMatrix(irr::core::matrix4 M ,v3f v); v3f transposeMatrix(irr::core::matrix4 M ,v3f v);