lolslayer
Member
Video game worlds are getting big. But it can even be bigger.
With random generation you can make incredibly big worlds. Randomly generating a world is really easy. You just need to put random objects at random locations and you're done.
But there comes the problem.
Computers can only handle a limited amount of objects. So if you want to go on "infinitely" finding new objects, you need to only generate the objects that are close to you, and get rid of the ones that fall behind.
So what you of course want to do, is to generate new objects whenever you enter an area. As simple as that.
But now we got another problem.
If you go back to a place you visited before, and you randomly place objects, they of course don't share the same location as the objects did when you visited that place the first time.
You can't fix this by saving all objects you generated before, and loading them in when you get in the area where they are present. Because the memory is limited aswell.
For these problems we need to find a way to combine infinite generation, but every object being persistant in locations and properties when you generate them and every time you regenerate them.
One simple solution I created was by dividing the world in equally-sized chuncks. Every chunck gets an unique number based on his location, because the location is the only property you can find out without storing any data of the chunck.
When you generate the objects of one chunck, you'll set the random generation seed to the unique number of the chunck. This way every chunck will generate excactly the same content whenever you enter and re-enter it.
The script I used create an unique number for every chunck based on it's location, goes like this:
This script uses rounded numbers as input. They can be positive or negative.
The way it calculates it seed is fairly abstract. But you can see the chuncks as having a middle chunck, and around that middle chunck there are an infinite amount of layers, as you can see in this picture (with the first 3 layers shown):
Layer 0 is the middle chunck.
I think the best way to explain the seed distribution, is by giving an example. In the example I include the middle chunck and the 2 layers of chuncks around it. The middle chunck has the seed 0:
For every layer you get farther away from the middle, the bigger the seed number will get. The seed number will grow exponentially because every new layer contains more chuncks than the last.
Of course, variables also have a limited lenght, so you can't get an infinite big number. But because of that the biggest seed numbers are at the most outer layers of chuncks, you won't surpass the maximum variable length soon.
(My tests went as far as layer 1.000.000.000.000, and even when I reached that number the limit wasn't reached so you can bet that your worlds will be big with this system).
There are a few things that are worth discussing with this topic:
-How can you create an infinite room where you generate and destroy objects dynamically?
-Can the system I've shown here be improved by making the chunck layers circular instead of rectangular (if that's a word)? And how can you implement such a system?
-Is this system fast enough, or should it be optimized? (@Misu probably has something to say here)
Here is an example project of my system in use, you can switch chuncks by pressing the up, down, left and right keys:
http://www.mediafire.com/file/jam7vr1ta0a2qai/infinitite_persistant_generation.gmz
With random generation you can make incredibly big worlds. Randomly generating a world is really easy. You just need to put random objects at random locations and you're done.
But there comes the problem.
Computers can only handle a limited amount of objects. So if you want to go on "infinitely" finding new objects, you need to only generate the objects that are close to you, and get rid of the ones that fall behind.
So what you of course want to do, is to generate new objects whenever you enter an area. As simple as that.
But now we got another problem.
If you go back to a place you visited before, and you randomly place objects, they of course don't share the same location as the objects did when you visited that place the first time.
You can't fix this by saving all objects you generated before, and loading them in when you get in the area where they are present. Because the memory is limited aswell.
For these problems we need to find a way to combine infinite generation, but every object being persistant in locations and properties when you generate them and every time you regenerate them.
One simple solution I created was by dividing the world in equally-sized chuncks. Every chunck gets an unique number based on his location, because the location is the only property you can find out without storing any data of the chunck.
When you generate the objects of one chunck, you'll set the random generation seed to the unique number of the chunck. This way every chunck will generate excactly the same content whenever you enter and re-enter it.
The script I used create an unique number for every chunck based on it's location, goes like this:
Code:
///position_to_seed(chunckx,chuncky);
//creates a seed based on a position, every position gives an unique seed
var cx = argument[0];
var cy = argument[1];
if (cx == 0 && cy == 0){
return 0;
}
else{
var maxc = max(abs(cx),abs(cy));
var minseed = sqr((maxc-1)*2+1);
if cy == maxc*-1{//top
return (minseed + cx+maxc);
}
else{
if cy == maxc{//bottom
return (minseed + maxc*2+1 + (maxc*2-1)*2 + cx+maxc);
}
else{
if cx == maxc*-1{//left side
return (minseed + maxc*2+1 + (cy+maxc-1)*2);
}
else{//right side
return (minseed + maxc*2+1 + (cy+maxc-1)*2 + 1);
}
}
}
}
The way it calculates it seed is fairly abstract. But you can see the chuncks as having a middle chunck, and around that middle chunck there are an infinite amount of layers, as you can see in this picture (with the first 3 layers shown):
Layer 0 is the middle chunck.
I think the best way to explain the seed distribution, is by giving an example. In the example I include the middle chunck and the 2 layers of chuncks around it. The middle chunck has the seed 0:
Code:
09 10 11 12 13
14 01 02 03 15
16 04 00 05 17
18 06 07 08 19
20 21 22 23 24
Of course, variables also have a limited lenght, so you can't get an infinite big number. But because of that the biggest seed numbers are at the most outer layers of chuncks, you won't surpass the maximum variable length soon.
(My tests went as far as layer 1.000.000.000.000, and even when I reached that number the limit wasn't reached so you can bet that your worlds will be big with this system).
There are a few things that are worth discussing with this topic:
-How can you create an infinite room where you generate and destroy objects dynamically?
-Can the system I've shown here be improved by making the chunck layers circular instead of rectangular (if that's a word)? And how can you implement such a system?
-Is this system fast enough, or should it be optimized? (@Misu probably has something to say here)
Here is an example project of my system in use, you can switch chuncks by pressing the up, down, left and right keys:
http://www.mediafire.com/file/jam7vr1ta0a2qai/infinitite_persistant_generation.gmz
Last edited: