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

hero: calculate movements with fractional fixed point coordinates #90

Open
1 of 2 tasks
jorgegv opened this issue Aug 23, 2022 · 0 comments
Open
1 of 2 tasks

hero: calculate movements with fractional fixed point coordinates #90

jorgegv opened this issue Aug 23, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request ongoing
Milestone

Comments

@jorgegv
Copy link
Owner

jorgegv commented Aug 23, 2022

The current movement uses integer calculations for coords and increments. This if fine for Horiz or Vert movement, but when moving diagonally it moves much faster. E.g. for DX=1 and DY=1, if we move Horiz or Vert (only) X or Y are incremented by 1, speed is 1 pixel per time unit. But if we move diagonally, X and Y are simultaneously incremented by DX=1 and DY=1, and the speed is then 1.41 pixels per time unit, which is 41% faster.

This can be avoided if we keep the movement coordinates and increments as 16-bit fixed point values (8 bit integer + 8 bit decimal), and also increments according to directions are adjusted for the diagonal moves (e.g. DX = 1 if moving Horiz, but DX = DY = 0.71 if moving diagonally).

Fixed Point math should be done in base 256 for best precision.

Update:

  • Use Fixed Point coordinates for hero movement.
  • Add DX_BOTH and DY_BOTH increments, used when moving in H and V direction simultaneously. Calculate as DYsin(W) and DXcos(W), being W = arctan(DY/DX). Precalculate in DATAGEN and generate FP fractional values ready to use (no trig calculations in realtime!)
@jorgegv jorgegv added the enhancement New feature or request label Aug 23, 2022
@jorgegv jorgegv added this to the Release 0.6.0 milestone Aug 23, 2022
@jorgegv jorgegv self-assigned this Aug 23, 2022
@jorgegv jorgegv changed the title hero: calculate movements with fractional fixed point math coordinates hero: calculate movements with fractional fixed point coordinates Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ongoing
Projects
None yet
Development

No branches or pull requests

1 participant