D
D
Drottarutarnum2020-11-30 06:02:00
Game development
Drottarutarnum, 2020-11-30 06:02:00

How to generate a 2D world on the fly?

In general, out of idleness, I wanted to write a simple digger like teraria.

Now my world is flat, and I generate caves with a cellular automaton, I had to improve it a little so that it connects closed cavities into a single cave

. But then I got into a survey that I didn’t even think about. When I changed the size of the world from test 500x500 blocks to 10000x50000, the generation began to take .. well .. I don’t know how much, after half an hour I stopped the application

Immediately I thought about generating the world in a certain radius from the player, but the fact is that if the cellular automaton is restarted to generate a new portion of the world, then there will be an ugly stitching of two locations

What are the algorithms for solving? Perhaps a cellular automaton can be taught to do this? At the request "caves generation" I found the same cellular automaton that is generally not suitable for large worlds

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dollar, 2020-11-30
@dollar

First, generate a certain "skeleton", that is, a frame, the structure of the world, on which everything else will already be mounted (according to other laws). For example, a hill can be marked with a dot in its conditional center, but not generated immediately. And as the player moves to this point, you can already form it in more detail, with all the bumps and small minor features.
But it is difficult. And this generation on the fly can then go sideways when the game starts to slow down the player due to the generation. The same Terraria first generates the map completely, although it takes a decent amount of time, but then it simply works according to its own laws of physics, regardless of how it was generated.
And even when generating on the fly, it is difficult to do phased generation. For example, first relief, then filling with water. After the second stage, no matter how the water is located, in the third stage it can be drained (landed in the recesses). But how to do it all on the fly? Very difficult. So for a beautiful well-thought-out world, pre-generation is better, or in the case of the first option, you will need to think through a lot of details and how they will be connected to each other.
In the first version, the algorithm reminds: "What could be at this point that would look logical and consistent?" (despite the fact that the player could already "inherit" in the world). And in the second option - this is a certain plan, and each tile is a part of this plan, that is, it is connected with neighboring ones, and is created at a certain stage.

M
Makssof, 2020-11-30
@makssof

https://gamedevelopment.tutsplus.com/tutorials/gen...
https://www.researchgate.net/publication/228919622...
https://www.youtube.com/c/SebastianLague/playlists...

M
mayton2019, 2020-11-30
@mayton2019

The first thought is code profiling. What is slow there. Maybe it's 1 cycle. Well, that is, without this information, we did not investigate the problem to the end. And this is unprofessional. Need to study.
The second is "divide and conquer". The map must be cut into tiles. And render only what is needed at the moment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question