A Matter of Time
Hey Folks! Another mostly coding day today, slightly more productive than yesterday. Today's focus was mostly on time.
Initially, it was just some minor changes to make the player's life easier. I added code to make sure the plotter couldn't reverse time into the past, and it just "bottoms-out" at the star system's current time if you rewind.
I also added a timestamp to the orbit display's top right corner, which shows the current system time and the plotter's delta time into the future. However, this raised an interesting and (difficult!) question. How does time work in space, @2079? I decided that the time code is based on Universal Coordinated Time (UTC), and looks like this:
This is pretty familiar to most folks, but I made a slight change. Months always have 30 days in the game, and there are only 360 days in a year. This means that months still feel pretty much like Earth months, and there are still 12 months to a year, but we are no longer using the 365.25 days per year or variable days per month.
Part of this is to make record-keeping clearer and easier to work with, and part of this is to further establish the setting as having evolved from Earth's complex timescale. Technically, it's still a 24-hour day in the code, but we can all pretend it's been stretched to 24.35 hours per day in this setting, and a day per degree in a circle around the sun :)
However, that wasn't the end of my problems. Enter precision, stage left.
It turns out my simulation works fine for about 4 months, but soon, the clock stops ticking each second. And as months turn into years, we lose all clock activity. This is due to the way computers store numbers, which are limited to 7-digits of precision (for float numbers) and 15-digits for double precision numbers. Since Unity (and my game) were using floats to record seconds since game start, this meant that measuring things like years easily used up all the precision in the year/month/day end of the scale, and hour/min/sec changes were ignored.
Here's where I am now. One approach is to create a new class to handle each of these time units separately (rather like the Date class, except using this new calendar). Another approach might be to store all time as a double. I think a double would insulate us from enough precision trouble to exceed even the longest-lived ship crew. But that's math for tomorrow.
In minor news, I also found and fixed that UI scaling bug from yesterday. (Yay!) Turns out it was a simple flag I wasn't setting when creating those UIs. I also found and fixed a bug that caused planets to stay put on the plotter, while their future projections moved around. Again, simple omission in the code that I added.
Overall, a mostly productive day! Just not much to show yet. Hopefully soon!