jpab wrote:DraQ wrote:What if instead of fixed point values we used plain ints for most of the stuff?
"Fixed point" and "plain ints with carefully selected units" are the same thing.
I can't help but notice that our fixedf<int> template is quite a bit more involved than just a plain int64_t.
The tricky part, of course, is working out what units are sensible for each value. You also need to remember that in the galaxy code we have several non-trivial calculations that relate different values, and for fixed point you don't just have to choose the units for the input and output values, you also have to choose the units for every intermediate value in the calculation.
That is true, though intermediate values are only a problem if we're doing something that's bad for the range, like exponentiation.
We do have some such nasty formulas like Stefan-Boltzman, but since we're usually caring only about what comes out the other end, we can always just normalize to whatever makes sense in the context (like I did with planetary temperature calculations using Earth's respective values), and denormalize the output.
OTOH from what I've seen (and IIRC) the code is peppered with conversions between different units for the same type of values - for example jumping between Earth's, Jupiter's and Sol's masses.
That's nasty, bug-prone, convoluted, mess to maintain (as we have seen) and ultimately unnecessary. I think that as long as we can help it we should be using single unit for given value type and as long as we can help it it should be plain int or at least keep the other types contained.
Conversion to human readable units should be the job of the player's interface, and handling weird units in formulas, as long as we don't overflow due to exponentiation, should mostly amount to recalculating the constants - because that's what physical constants ARE, after all.
It would be good to see what different types of units we need, let's start with:
- Astronomical body mass (generates gravity, isn't subjected to dynamic physics).
- Dynamic object mass (doesn't generate relevant amounts of gravity, is used in physical and gameplay calculations)
- Temperature (we probably don't need or want to separate temperature for emitting bodies)
- In-system distances and coords (could probably be trimmed to plain non-float manageable range if we split highly separate multiples into their constituents and split off very distant planets into rogues - we have quite a few in-system distances that are impractical to cross using conventional drive, bodies separated in such way are effectively unreachable from each other anyway).
- Interstellar distances - game can be oblivious to their relationship with in-system ones
The advantage of floating point is that it dynamically selects the "best" units (ie, the exponent) to represent each value. The disadvantage is that by making that choice dynamically it will have, in some sense, different behaviour for different values, which can be problematic. It also trades off some bits which could be used to represent values more precisely in order to instead represent the exponent, so for a given number of total bits you get a much greater range of representable values, but less precision.
Yes. We also trade precision we could use for ability to represent values we won't need. For example if we're far enough from a point of reference, floats will give us considerable lack of precision with objects jumping around and choppiness, which is bad, OTOH we will be able to represent distances the size of an atom which is... come to think of it, not really useful.
I think fixed precision is really much better if we can afford it and given galaxy partitioned into individual systems we should be able to, so we even should try to use ints in actual gameplay in place of floats in many cases, if it's possible - for example if we represented actual in-game coordinates for in-system objects as ordinary int64_t-s we should be able to cover a 1000x1000x1000AU cube (which is a sensible size for a playable system) with around 1cm precision which should be enough when dealing with spaceships.
Lack of cross-platform consistency should be the least of our worries as it only helps with bug replication and multiplayer, and I don't think Pioneer is ever going to have the latter (if only due to time compression).