Home Game Development procedural era – How to put in writing Perlin Noise generated information to a vector in Rust?

procedural era – How to put in writing Perlin Noise generated information to a vector in Rust?

0
procedural era – How to put in writing Perlin Noise generated information to a vector in Rust?

[ad_1]

Perlin Noise

You ought to be capable of question the Perlin noise with some 2D coordinates.

If you might be utilizing this Peril: noise::Perlin, then you possibly can name get with a Point2. If you might be utilizing this Perlin: perlin_rust::PerlinNoise then you possibly can name perlin2 with x and y values. Most Perlin implementations have a strategy to do it.

So you possibly can question for the coordinates of a given place on the tilemap, and from the outcome resolve what shall be there in that tile, and add it to the tilemap information. You try this for each tile you need to generate. You would, after all, have some logic to resolve whether it is water or not, and so forth, based mostly on the outcome type the perlin noise.


Presumably the contents of a tile don’t come from a single variable. Consider utilizing an additional dimension so you possibly can question the perlin noise on the identical 2D coordinantes of the tile, however at completely different positions alongside the additional dimension. So you will have a number of values you should utilize to resolve what’s within the tile. For instance, one could possibly be elevation, one other could possibly be vegetation, one other could possibly be temperature, and so forth.


Storing to file

If you aren’t going to control the tilemap, then storing the seed for the perlin noise is sufficient to retailer the tilemap. Because it ought to generate the identical approach from the identical seed.

Thus, if you’ll want to serialize the tilemap, I presume that both you want it in a specific format for an additional software program to learn, or you’ll manipulate it additional after you generated it from perlin noise. For instance, you may be selecting spawn factors or producing buildings. Keep in thoughts that this will likely not solely require modifying the tiles, but additionally including metadata to the tiles, which you’d additionally must serialize.


Perhaps serializing the tilemap requires no manipulation in any respect, and you’ll merely write the reminiscence illustration to a file.

Otherwise, maybe you need to begin with some header with the tilemap measurement firstly of the file. So you can begin including that to the info that you’ll write. Although in case you are going for human readable maybe you merely use newlines. I’m attempting to indicate you various situations of how the serialization would possibly go.

Then we now have the identical query for the person tiles. If the reminiscence illustration of the tile is identical because the file illustration, you possibly can simply copy them to the info you’ll write.

Otherwise, you will want to iterate over every tile, work out how the tile shall be represented within the file, and including that to the info you’ll write.

And that’s assuming right here that it will likely be saved as a single compact blob. However, you could need to break it into chunks, or have another construction that helps to question close by tiles for a given place. And then might need to additionally retailer an index for that construction. Yes, I’m saying you could need to serialize with that construction, so you do not have to expend additional time producing it while you load the tilemap.

Then you may manipulate the info you’ll write, for instance you could need to compress it. And lastly write it to a file.


Storing to file doesn’t need to take care of perlin noise. However, if writing on to file is a requirement, you may have a single loop that queries the perlin noise, decides what the tile shall be, and the way it’s encoded, and writes it to file. Then you would need to learn it to show it. And I remind that this is able to indicate you aren’t manipulating the tilemap after you generated it from the perlin noise, so you may be writing the seed as a substitute, except you want the tilemap in some specific format.

Otherwise, you could need to show the outcome with out storing it to file, and for that you just higher have a illustration of the tilemap information in reminiscence which you’ll both serialize to a file, or show, or no matter.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here