mirror of https://github.com/minetest/minetest.git
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:
parent
8979a3dd99
commit
03b1ed53db
|
@ -2130,7 +2130,7 @@ treedef={
|
||||||
thin_branches, - boolean true -> use thin (1 node) branches
|
thin_branches, - boolean true -> use thin (1 node) branches
|
||||||
fruit, - string fruit node name
|
fruit, - string fruit node name
|
||||||
fruit_chance, - num chance (0-100) to replace leaves with fruit node
|
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
|
Key for Special L-System Symbols used in Axioms
|
||||||
|
|
|
@ -757,7 +757,7 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L)
|
||||||
tree_def.fruitnode=ndef->getId(fruit);
|
tree_def.fruitnode=ndef->getId(fruit);
|
||||||
getintfield(L, 2, "fruit_chance",tree_def.fruit_chance);
|
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
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -149,8 +149,17 @@ void make_ltree(ManualMapVoxelManipulator &vmanip, v3s16 p0, INodeDefManager *nd
|
||||||
TreeDef tree_definition)
|
TreeDef tree_definition)
|
||||||
{
|
{
|
||||||
MapNode dirtnode(ndef->getId("mapgen_dirt"));
|
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
|
// chance of inserting abcd rules
|
||||||
double prop_a = 9;
|
double prop_a = 9;
|
||||||
double prop_b = 8;
|
double prop_b = 8;
|
||||||
|
|
|
@ -50,6 +50,7 @@ namespace treegen {
|
||||||
MapNode fruitnode;
|
MapNode fruitnode;
|
||||||
int fruit_chance;
|
int fruit_chance;
|
||||||
int seed;
|
int seed;
|
||||||
|
bool explicit_seed;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add default tree
|
// Add default tree
|
||||||
|
|
Loading…
Reference in New Issue