My universe generation efforts have reached the point where I have to start concerning myself with specifics. The first steps in the generator deal with the very top level constructs like star systems, jump gates, planets, and stations. These were relatively easy to construct but needed a lot of tweaking, and probably need more tweaking still, but as those records do not require a not a lot of detail at this point, and there are only between 1,000 and 3,000 records per data table that are being generated; hardly a sweat-inducing situation for the database.
The first area of concern beyond these simple records is the genesis of commodity distribution. I have 71 base commodity items currently. Each planet is generating some quantity of those 71 items, which means that if I have 2,000 planets, that’s 142,000 “produce records” that I need to record. A “planet commodity” record stores the commodity reference code, the planet reference code, the quantity generated, and the percent reserve. The quantity generated is calculated by taking the population (which was generated when the planet was created) and multiplying it by a random percent between 5 and 80 — for now. The precent reserve is also a percent between 5 and 80, but we just store the percent, not the calculated reserve amount. Later, I will need to go back to the well and adjust these values so that terrestrial planets generate more of everything, while inner planets and outer gas and ice planets are limited in the types of commodities they can contribute if they contribute at all. As all of these values roll up in some form to the commodity inventory for stations in the system, there’ll be a lot of massaging of these calculations in the future.
Since I’m creating this as a web app, and web apps aren’t the most efficient means of dealing with the back-and-forth of large amounts of data, I had to take all of these 142,000 records and chunk them into groups of 10,000 before sending them to the database. Before I did this the operation would send one. record. at. a. time to be stored and I never had the patience to let it finish. Now, it still takes some time, but pushing 10,000 records in bulk at least keeps the process moving. Since I will only trigger this process once at the start of the game, or maybe if I opt to generate a “seasons” style reset on occasion, the amount of time isn’t of paramount concern, so long as I can verify that it will work flawlessly every time. There are other options as well, such as transferring the generation into stored procedures, or figuring out a way to divide the data generation responsibilities into discreet blocks, and then creating a multi-threaded console app to handle the Big Bang duties. Really, that’s much further down the road; I need to get the data concepts in there, and the gameplay working before I can nitpick this specific process.