wheybags / freeablo

[ARCHIVED] Modern reimplementation of the Diablo 1 game engine
GNU General Public License v3.0
2.16k stars 195 forks source link

Fix/45/fixed point #419

Closed grantramsay closed 5 years ago

grantramsay commented 5 years ago

As mentioned in #45. If someone can find some decent FixedPoint trig approximations feel free to update

tilkinsc commented 5 years ago

By the way, because of the fact that floats have a mantissa, you can emulate perfectly a fixed point number with performance gains. You just got to directly edit the memory by force because compilers aren't very forgiving.

grantramsay commented 5 years ago

Sounds like a neat way to do it. Might not be that great for portability though :/. Also sounds like gcc has native fixed point support and might be in the c standard soon too

tilkinsc commented 5 years ago

It's portable. Floats aren't effected by endieness.

grantramsay commented 5 years ago

From linked article above:

the widespread IEEE 754 floating-point standard does not specify endianness

However, on modern standard computers (i.e., implementing IEEE 754), one may in practice safely assume that the endianness is the same for floating-point numbers as for integers

wheybags commented 5 years ago

Derp, I just implemented a fixed point version of atan2 based on a LUT, without noticing you'd already added an implementation here. Mine is at https://github.com/wheybags/freeablo/tree/lut_atan2, I'll let you decide which is better. I did try implementing code from the same source you used, but I got pretty shitty accuracy from it, so unless you somehow just did it better (entirely possible, lol), it might be better to go with a LUT.

grantramsay commented 5 years ago

Oh hahaha. Under the section "QUICK NOTE FOR BETTER ACCURACY" they give the formula for increasing from 1st order (a straight line) to 3rd order approximation which gives a pretty good fit. Umm what I've got in there works pretty well with a bunch less LOC, only issue may be speed, those 128 bit (multiply/divide) operations are probably quite slow. Maybe we run it like this and change to a LUT later if we find it's too slow?

wheybags commented 5 years ago

Aaah, ok. I just gave up when I saw I was getting awful results, I didn't bother with the "slightly better" version. Thanks for all the work! The other misc improvements to FixedPoints are really great to have too.