Replies: 1 comment 1 reply
-
Out of curiosity, I wonder why a fixed seed isn't always being used in the first place. Exposing a way to use custom seeds or RNG functions would come later. cc @groud |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The TileMapLayer / TileSet terrains mechanism allows for randomization of the tiles actually picked for any given terrain, both when painting and when programmatically setting the terrain of cells via
set_cells_terrain_connect()
orset_cells_terrain_path()
, by defining multiple tiles with the same combination of terrain and peering bits.I want to make use of this feature from GDScript to build levels programmatically, but with the added constraint that while the levels should use some randomness in the choice of the actual tiles, this randomness should still be deterministic, i.e. whenever I re-build a level, it should look exactly the same.
I think this could be implemented by taking the random value not from a sequential PRNG (currently
Math::random()
) inget_random_tile_from_terrains_pattern()
), but rather - either always or as an option - from a function (to be called byset_cells_terrain_connect()
orset_cells_terrain_path()
respectively) taking as parameters the cell coordinates and, for good measure, some (optional) user-supplied new parameter to both methods.The function to generate the pseudorandom number could be as simple as a hash of the three parameters or a lookup into precomputed blue noise, or as sophisticated as a user-supplied functor. The latter would enable the user to have even more control over the distribution of tiles: A Perlin noise function would cause rare tiles to have a higher chance to appear in clusters, while a blue noise function would cause rare tiles to be spread more randomly; and if so desired, in this manner even geometric patterns would be possible to auto-generate.
The purpose of the third parameter, to be supplied by the user, would be to effectively choose between different distribution patterns; by default, a constant value would be used, yielding the same distribution pattern for all map layers (presuming identical probability settings) and terrains; setting the value to a hash of the terrain set and terrain ID would ensure different distribution patterns for different terrains; setting the value to the current level ID would give a different pattern for each level, and so forth.
Beta Was this translation helpful? Give feedback.
All reactions