Hi guys. I’m making an open-world space game. The first step for me is making a procedural universe generator (infinite galaxies, filled with around 1 million stars each which have planet systems). I am definitely not going to create content for everything. So I want to use procedural generation.
I know some of the theory - only loading stars within a certain range and unloading when further away, using a pattern such as the Fibonacci sequence with seeds for the first number and using data from that to generate details such as position, type and name.
What I have currently:
System that generates positions and names for the galaxies and puts them in an array (will change to lists)
That’s it, really. I have set a galaxy count variable as I am unsure on how to do it infinitely like I want - so it often crashes or gives an out of memory exception when I set something like 1,000,000+.
Please can you suggest how I would only generate when closer without storing it in an array/list and how to make it infinite?
PS: I would also like suggestions/tips on how to make it work with multiplayer
OK. I specifically want pseudo-random - it is going to be multiplayer, so it must generate the same thing every time.
I am working on a number generation extension where you provide it with multiple integers for different things.
You can’t have non-pseudo-random number generation on a computer, so you’re set there
Only use the Mersenne Twister if you absolutely want to be sure that the numbers are uniformly distributed, as it’s slower.
If it’s multiplayer and you want to make absolutely sure the numbers generated are identical, I’d probably sync it, somehow. Depending on the amount of numbers you’re looking at generating, you could make a very long array of random numbers and send that to the client. Then, just check once in a while that you’re on the same index.
Just remember that the experts at Kerbal Space Program only added the local solar system(and while they are doing full simulation, and I assume you will not be), it was quite a feat. How about trying to get one solar system working right now?
The syncing was more in the context of generating millions of random numbers, and always being on the same index on client and server. If you play for an hour or something, there’s probably a chance that they’ll get out of sync, which would be “a bad thing”.
thats the point you dont need to sync it every client will generate the same “galaxy” you just need to sync the position what can be 2 int values i added a small image
Exactly. I will probably make it so the server only stores things like currency, positions, ships etc. - not even starports (unless I add player-made ones)
I did try to generate a list of galaxies… I crashed Unity.
First comes Galaxies/Stars. Then planets
First I will make the galaxy map, then use similar methods for the planets. In-game, the player will only get to see/visit the contents of their current star system unless they Hyperspace to the next system.
By the way, I did some calculations. I want at least 5000 galaxies, at least 1 million stars each. An Int32 is 4 bytes AFAIK, so 5,000*1,000,000=5,000,000,000. Which means the total size is 5,000,000,000 * 4 bytes or 20,000,000,000 bytes. If we minimize the numbers (divide by 1024 multiple times) we find out that it would mean 18 gigabytes of just Int32s. On top of that, I need space for HD starship models, player avatars, textures, starport attachments, landing pads, space elevators and so on. If I did that, it could easily become over 50gb in size. I do not want that.
EDIT: I realise that 18gb would be on a server, but currently I do not have a server to do that with. I want server interactions to be kept minimal
EDIT EDIT: It cannot possibly get “out of sync”. It is generating a number pseudo-randomly based on the same seed. There is no updating the galaxy server-side. The only parts that will be saved will be custom overrides I set (which I probably will)
So I’m thinking for the chunks, I run them through my number generator to get positions for stars and multiply/divide based on the distance to the galactic bulge. I am not entirely sure about spirals for the galaxies, but I can think something out
(yellow squares demonstrate chunks on a larger scale)
Something like this I think:
int x1 = 0;
int y1 = 0;
int current_rotation = 0;
int arm_length = 100;
GameObject arm_point;
for (int i = 0; i < arm_length; i+=10) {
x1 += Mathf.Sin(current_rotation);
y1 += Mathf.Cos(current_rotation);
Instantiate(armpoint, new Vector3(x1,y1,0), new Quaternion(0,0,0,0));
current_rotation += 50;
}
And then the generator will go from point A to point B, scattering the stars left and right of the arm.
Good idea?
I thought you were going to continually generate the universe over time when playing. Then it would have been a good idea to sync up sometimes, because of race conditions and stuff like that.