Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atan2 table #1327

wants to merge 2 commits into from


None yet
3 participants
Copy link

dafioram commented Sep 8, 2018

  1. Add a float lookup table for atan2, similar to star trek's atan2 lookup, except that one is for a fixed size table and uses ints. This lookup is faster than atan2().
  2. Use the table in titanic star control. I tested it as well.

Making a atan2 table based only on ints may also be useful to add.

dafioram added some commits Sep 8, 2018

COMMON: Add common atan2 lookup table
It is a float based lookup table for atan2.

Even for a small table size the lookup can be more than 50% faster
than atan2(). While still being relatively accurate.
TITANIC: Use atan2 lookup table
The space control game functions the game after this change.

There wouldn't be a noticeable speed up after this change.

This atan2 is used when locking onto the stars. If the nPoints
parameter for the atan2 is lowered below 128 then there is a noticeable
bias when locking onto the stars. I have selected a large enough
value so that this is not the case.

I made the atan2 table be static so that all fvectors could share the
same one.

@digitall digitall requested a review from dreammaster Sep 14, 2018


This comment has been minimized.

Copy link

foobar13372 commented Sep 17, 2018

Does this improve anything? How much faster is "faster"? LUT's are great on limited hardware that is needing the calculation very often - this isn't the case here. For now I only see increased code complexity that doesn't add anything.

But maybe I'm just not seeing the intention here, that's why I'm asking.


This comment has been minimized.

Copy link

lskovlun commented Sep 17, 2018

One problem with this is that in cases where LUTs are actually useful they can easily contain little idiosyncrasies on a per-engine basis (round-off errors, edge cases and the like). So you end up having to have one for each engine anyway.


This comment has been minimized.

Copy link
Member Author

dafioram commented Sep 17, 2018

@foobar13372 it is 65% faster than the float atan2 call. While titanic may not speed up that much since the atan2 is not used much something like bladerunner does a lot more atan2 so it would benefit more.

@lskovlun I'm not sure I understand, how can an engine do an atan2 function correctly, but not be replaced by a more general atan2 call? I'm thinking of star trek here. We can always select a lower number of points/bits to model less precision to stay true to an engine.

@dafioram dafioram closed this Oct 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.