As you know, the goal of my game is to recreate a galaxy in which the players can have fun in. Although I’d love to have a galaxy that contains the average number of star in a galaxy, it’s simply not doable. Besides, int only go to 2.4 Billion. But, I do give the closest option (1% realist galaxy).
To give you a sample, here’s the rundown of star numbers per galaxy size.
[java]
/**
- This method generates the number of stars based on galaxy radius
- multiplied by the user’s choice in options screen.
/
protected void bigBang() {
galaxyRadius = FastMath.nextRandomInt(MIN_RADIUS, MAX_RADIUS);
// Calculate depending on user’s settings, for now force to 0/tiny
int mult = 0;
galaxySizeChoice = 0;
switch (galaxySizeChoice) {
case 8:
/ 709 436 520 to 2 147 483 520 /
mult = STARS_MULT_ONE_PERCENT_REALIST;
break;
case 7:
/ 234 367 398 to 709 436 448 /
mult = STARS_MULT_GIGANTIC;
break;
case 6:
/ 77 633 918 to 234 999 968 /
mult = STARS_MULT_HUGE;
break;
case 5:
/ 8 472 630 to 25 646 880 /
mult = STARS_MULT_ENORMOUS;
break;
case 4:
/ 2 798 976 to 8 472 576 /
mult = STARS_MULT_BIG;
break;
case 3:
/ 924 630 to 2 798 880 /
mult = STARS_MULT_MEDIUM;
break;
case 2:
/ 305 398 to 924 448 /
mult = STARS_MULT_LOW;
break;
case 1:
/ 100 862 to 305 312 /
mult = STARS_MULT_SMALL;
break;
case 0:
/ 33 300 to 100 800 */
mult = STARS_MULT_TINY;
break;
}
numberOfStars = galaxyRadius * mult;
}
[/java]
The main problem right now and I guess the hugest, is that even with a tiny galaxy with less than 100 800 stars, I’m getting into problems. When I generate close to that many stars including their planets and moons of each planet, the game is gobbling a chunk of memory and that’s when the generating doesn’t simply crash with a heap error.
The game will have 12 sentient races that will be randomly (more or less) placed around the galaxy. To “finish” the game, you have to interact with those races, do quests, etc. Now, what the game also is is a sandbox-type game. Meaning that life could evolve on some planets, even evolve into sentience and if they’re lucky, roam around their local space. Although those could potentially exist, it won’t be necessary to interact with them to succeed the game. But, the possibility is there to do stuff with them. You can see these as side quests.
So, all this to say that those secondary citizens need to be generated during the creation of the galaxy. Pretty much everything has to be generated and, honestly, with over 2 billion star systems that would include planets, moons, accretions disks, asteroid fields, races, ships… I probably wouldn’t be able to play my game with the 16 GB of ram in my computer.
I need a plan to manage this.
What I’m thinking right now is to compute only the stars in the galaxy.
Then, once I have the OcTree filled with stars and found where the player will “land”, I could build that leaf’s solar systems. That would amount to around 200-2000 stars depending on the machine on which the game runs.
As the player moves around and exit a leaf, I could build the next leaf.
But the above means I would need to save the information to disk and retrieve it as the player switch leaf. Something I wanted to avoid because of the input/output save/load time it takes. It’s not a very big deal, but I wanted it to be seamless.
I think that would be the best plan, but I’d love to hear what you guys have to say. I’ll admit my inexperience here is a big flaw. I have no idea how I could save what I generate on disk.
Thanks.