I\'m going to make a space/trading/combat game that is completely procedurally generated. But, I know that storing all of the details of the whole galaxy in memory is unfeas
Mathematically, you want to randomly / pseudo-randomly generate an Undirected, Connected Graph. In this graph, each node would be a solar system and each edge would be a jump gate.
1) Create N nodes and randomly assign each a spatial coordinate. These nodes will eventually become your solar systems.
2) Generate edges using Deluanay triangulation algorithm. I suggest Deluanay triangulation because it will create a fairly nice looking map without any gates intersecting each other, but you can actually use any algorithm you want. I don't really know what you're looking for.
3) If you used Deluanay triangulation, I suggest that you eliminate a certain number of edges to create "sparseness". This will make the map more interesting as certain locations will become transport hubs, while others are simply pit stops.
4) Save this graph. This is your universe. Do not misplace or throw out your universe. Store it as efficiently as you want, but do not delete any information.
5) Assign each node a seed, and use this seed to generate each solar system.
6) Congratulations, you now have a universe with an arbitrary number of Solar Systems and Jump Gates.
If you use a pseudo random number generator, you can guarantee that each random number you generate will appear in the same order from a given seed. The code to generate a system seeded by a given number will appear the same each time you generate it.
Use the first number from the pseudo random number stream to generate the number of "gates". Go through each gate and get a value from the number stream to assign to and seed each target system.
Generate the featurs of each system based on that seed.
There are several known algorithms for generating random seeds.
Give the Mersenne twister a crack
I don't think there is really all that much information in a "galaxy" that you couldn't store it on today's computers. Let's assume a galaxy has 100 stars, and that each star has 10 planets, and that each planet has 3 moons. That's 100 stars + 1,000 planets + 3,000 moons you have to keep track of, which is 4,100 bodies.
Here's the things we may want to keep track of for a planet.
Mass X,Y,Z position Length of day (time to rotate on it's own axis) Length of year Population Amount of resources for 50 different resources
Assuming each value requires a double to store it, and we have 57 values to store (lets round it up and say 100), then we have 100 values * 8 bytes * 4100 bodies = 3,280,000 bytes. Now, thats 3 megs of data. That may seem like a lot but it's really not that much. Also, I don't think that you'd really want to have so many stars in a single galaxy. The game would really be just too big to explore, and would probably get unmanageable large to try to actually simulate all the stuff that's going on in a given galaxy.
Look at it this way. If you take a game like SimCity, and look at each square on the city grid as a potential planet, and then you realize just how much information can be stored in a small file, so that you don't have to randomly generate anything.
Here's what I have come up with. Dunno if it will be the final version though.
Imagine a hexagonal grid, and at each vertex, a solar system. Since, we're on a hexagonal grid, there are only three lines going from any vertex. One is always horizontal, and the other two are diagonals. If we give the starting seed a value of n, we can give the solar system that is horizontally connected to the starting point a value of n+1, the others get values of n+2 and n-2.
Oh crap. We wont necessarily get a grid. Damnit. Lets try again.
This is my second, improved solution. The player will start out in a randomly generated solar system. Each system is connected to between 1 and 4 other systems. Think of them as north, south, east and west systems. If a player were to move through the north jumpgate, he will be taken to a system whose seed is one more than the system before. If he goes south, the seed for that system will be one less. 2+ and 2- for east and west respectively. The distances to those systems (in parsecs or lightyears or whatever) are calculated with the systems' seed and the direction from which you are arriving. This way, the size of the galaxy is only limited by the max and min of the number used to hold the seeds.
Warp holes to go to other galaxies will be placed a certain distance from the starting system. The next galaxy will just be like a continuation of this galaxy in that the seed numbers will be incremented in the same way and that the system that is on the other end of the galactic warp hole will just be an "east" or a "north" connection from the starting system.
By the way, this use of incrementing seeds leads to a web, unlike the above solution. Also, you can see that this method uses quadrilaterals while the above solution used hexagons, which made it impossible to create a web.
Of course, all of this is based on the assumption that all of the seeds will generate a random sequence of numbers that is different from any other sequence. This makes it so that each system is unique.
Can't you just SHA1 the galaxy ID, EG:
Sha1(1) = 356a192b7913b04c54574d18c28d46e6395428ab
Sha1(2) = da4b9237bacccdf19c0760cab7aec4a8359010b0
Sha1(3) = 77de68daecd823babbb58edb1c8e14d7106e83bb
You can then segment the code, IE:
356a
da4b
77de
You would need some sort of string to number algorithm, one simple one would be to take the ASCII code of every non numeric character, and then multiply them all together or something.
So now we know how many planets are in our galaxy, how about galaxy x,y,z dimensions?
Same principle as above, turn the code into a large number. Have some sensibility checks as well, you don't want a galaxy thats 10milesx10milesx10miles with 20 million planets in it. Have some sort of weighted algorithm, like minimum size is # of planets * 10000. You will need to play with the numbers to make sure the ranges are all compatible and the selected chars from the hash actually give you a reasonable range.
Or, instead of this, you can have a random number pick a number between the min and max size of the galaxy, but use a constant RNG seed, such as the galaxy ID! This way the galaxy sizes are essentially 'random' for the observer, but they will be the same every time.
That's one way of getting properties of your Universe, but what about planet properties? Like population and other stuff?
If you have Galaxy 1 with 20,000 planets, you can do:
Sha1('1:340') = bc02ab36f163baee2a04cebaed8b141505cc26b5
That is, galaxy one, planet 340. You can then just splice up that code however you want. The benefit of using a hash is that every planet should have a totally unique code.