EDITOR’S NOTE: This is part of a series, start here.

I had to get that journal entry title out of the way sooner or later, now seemed as good a time as any.

Since I started this I’ve been kind of going back and forth on what units of measure I was going to use. For the “macro” view parsecs seemed obvious. Stellar density in the range where you’ll primarily play is about 1.4 stars per cubic parsec. I would locate stars inside of a given cube by looping through every x, y and z point at the parsec level and running a function using my hasher to determine if there’s a star at that location. I do this by saying, “Using the hash function on this three dimensional point, give me a random number between 1 and 100. If that number is less than the stellar density percentage, there’s a star here.”

This works but means you can only have one star per parsec and that they always fall on grid points. This isn’t really what I wanted so I called the main grid point my “rough location” then ran another function to turn the hash into a pseudorandom fractional parsec coordinate somewhere offset from that main point. This increases the “organic” feel of the star field but still limits you to no more than one star per cubic parsec.

It then dawned on me that I could use a smaller unit of measure. I considered light years, which would maybe have been better, but still not great as that’s only roughly a third the size of a parsec. Astronomical Units (AU) are too small and too earth-centric. (Not that parsecs aren’t, but whatever.) I ultimately settled on having the base unit of measure be the centiparsec, or one hundredth of a parsec. (Thanks, metric system!) This unit works well for distances between stars at the level of granularity I wanted.

Changing units pretty much required I change how I determine if there’s a star at a given point, because now I’m looping through exponentially larger numbers of points to find out which ones have stars. At the parsec level this is manageable because checking a 32 x 32 x 32 grid only means testing 32,768 points. Sure, that’s a lot, but it goes really quickly on a modern computer. Going to centiparsecs, checking every point in 32 parsecs means looping through a grid that’s 3200 x 3200 x 3200, which out to checking 32,768,000,000 points, which is way too many.

Instead I realized I could do it the other way around. I divided the galaxy up into a grid of 10 parsec squares. Then when you ask for a cube of stars starting at a given point, I just figure out what the nearest 10 parsec grid point is and hash that, then use that to determine the stars inside that 10 parsec cube. If your requested cube bridges more than one 10 parsec cube, then I grab the additional cubes I need and then run the whole thing into a list. Then I can just throw out anything that has coordinates outside your requested volume. Sure, this could be a few thousand stars at a time, but it’s way more efficient than looping through 32,768 points and it’s waaaaaaaay more efficient than looping through 32,768,000,000 points.

I still need to play with the density a bit to make it such that there’s more stars near the galactic core and fewer at the edges, but that’s another show.

← Xoth Devlog Pt. 5 Xoth Devlog Pt. 7 →