View Full Version : sprite/entity 'fix' usage

01-30-2017, 02:03 AM
I was looking over everywhere fix is used for sprites. It *looks* to me like it's questionable whether replacing it at some point later on will cause any issues. What happens is there are a lot of double-int32 conversions for remainders, and most of the time position values are truncated to integers anyway. 'delta' values certainly never exceed any kind of float threshold at all, meaning that usage of 'fix' is just something that's in there. :/ I can't find a single good reason why except that in 1998 maybe FPUs were not as widespread across hardware.

I can see why from a perspective of drawing to bitmaps, since it's all ints, but that just means it's like that because it's tied to allegro. Am I missing something?

01-31-2017, 03:00 AM
If there's no place where the fixed-point semantics are truly needed (i.e., where the code assumes that one hundred "+= 0.01"s will yield 1.0 exactly) then we should get rid of them. I agree that they're most likely due to performance concerns that were dubious even in the late 90s.

05-03-2017, 03:08 AM
So after some investigation the main issue I see with getting rid of "fix" entirely (and replacing them with true doubles) is in the sprite movement code. Sprites currently have step sizes that are fractions of the tile width, and due to rounding errors replacing the fixed-point position variables with floating point will alter the movement behavior.

But I don't think that's actually a major issue, since sprites can store their positions in units of pixels instead of tiles; current movement code will only increment the position by integer number of pixels and since sufficiently small integers are exactly represented in floating-point, as long as the calculation of pixel->tile is rounded carefully there should be no functional change in the movement behavior.