L-Systems fix randomness

Unless a random seed is provided (via Lua treedef) seed the PRNG with a different seed for each tree
Resolves: https://github.com/minetest/minetest/issues/1469
This commit is contained in:
Craig Robbins 2014-08-06 13:02:36 +10:00
parent 8979a3dd99
commit 03b1ed53db
4 changed files with 13 additions and 3 deletions

View File

@ -2130,7 +2130,7 @@ treedef={
thin_branches, - boolean true -> use thin (1 node) branches
fruit, - string fruit node name
fruit_chance, - num chance (0-100) to replace leaves with fruit node
seed, - num random seed
seed, - num random seed; if no seed is provided, the engine will create one
}
Key for Special L-System Symbols used in Axioms

View File

@ -757,7 +757,7 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L)
tree_def.fruitnode=ndef->getId(fruit);
getintfield(L, 2, "fruit_chance",tree_def.fruit_chance);
}
getintfield(L, 2, "seed", tree_def.seed);
tree_def.explicit_seed = getintfield(L, 2, "seed", tree_def.seed);
}
else
return 0;

View File

@ -149,8 +149,17 @@ void make_ltree(ManualMapVoxelManipulator &vmanip, v3s16 p0, INodeDefManager *nd
TreeDef tree_definition)
{
MapNode dirtnode(ndef->getId("mapgen_dirt"));
int seed;
if (tree_definition.explicit_seed)
{
seed = tree_definition.seed+14002;
}
else
{
seed = p0.X*2 + p0.Y*4 + p0.Z; // use the tree position to seed PRNG
}
PseudoRandom ps(seed);
PseudoRandom ps(tree_definition.seed+14002);
// chance of inserting abcd rules
double prop_a = 9;
double prop_b = 8;

View File

@ -50,6 +50,7 @@ namespace treegen {
MapNode fruitnode;
int fruit_chance;
int seed;
bool explicit_seed;
};
// Add default tree