-
Notifications
You must be signed in to change notification settings - Fork 46
Use fixed point math for position, endurance, health #1044
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
base: master
Are you sure you want to change the base?
Conversation
|
This is more precise, but it's also probably less accurate. The original game retains values as integers, where positions are pixel coords multiplied by 256. That is probably what openomf also needs to do to remain as close to omf2097 as possible. |
I believe you have the exact same misconception I had at first glance, that is precisely what is being described with the fixed point type, it's just not the name we had for it |
Ah. I see. I assumed a standard fixed point library. |
ac1def9 to
ae32b4a
Compare
|
|
This is the latest version available from their Mercurial Repo on Sourceforge: https://sourceforge.net/p/fixedptc/code/ci/57887bd8c046c0c0394c22adc806d67bd5a71eaa/tree/
24.8 format gives us 256 subpixels, which the original game seems to like.
8d15229 to
d8c7b6d
Compare
Left shifting a negative number is undefined behavior. https://learn.microsoft.com/en-us/cpp/code-quality/c26453
) * Try to improve the fixedpt_str function and add unit tests for it * Fix overflow in fixedpt_fracpart macro * Futher clarify the function * Clarify fixed point string printing test suite name * Clearer handling of negative numbers * Apply suggestions from code review --------- Co-authored-by: Magnus Larsen <[email protected]>
NOTICE
Outdated
| @@ -0,0 +1,25 @@ | |||
| This software contains fixedptc, whose license follows: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be combined with the LICENSE file?
| #define ARENA_RIGHT_WALL 300 | ||
| #define ARENA_FLOOR 190 | ||
|
|
||
| // fixed point versions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably we should remove the non fixed point versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ARENA_FLOOR is important for object rendering, and we render in pixels-- not fixedpt fractions of pixels.
The arena walls can be fixedpt only, sure.
src/utils/random.c
Outdated
| } | ||
| fixedpt rand_fixedpt(fixedpt max) { | ||
| return random_fixedpt(&rand_state, max); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a newline at end of this file
| printf("%d\n", af->health); | ||
| break; | ||
| case 5: | ||
| printf("%f\n", af->forward_speed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably we could print these as fixedpt_strs
src/game/scenes/arena.c
Outdated
| if(info) { // Only Power Plant has the electric overlay effect | ||
| object *obj2 = omf_calloc(1, sizeof(object)); | ||
| object_create(obj2, scene->gs, vec2i_create(o_har->pos.x, o_har->pos.y), vec2f_create(0, 0)); | ||
| object_create(obj2, scene->gs, vec2f_to_i(o_har->pos), vec2f_createf(0, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we should create objects in the fixed point space?
This PR hopes to improve netplay and rec compatibility & determinism across platforms.
Positions and velocities (vec2f) are now stored as 24.8 fixed point numbers, which means there are 24 bits for the whole part and 8 for the fractional part.
This PR has the annoying quirk of taking an existing name and appending 'f' to mark it as fixedpoint, some of these should be un-renamed before merging-- this was done to ensure non-updated code would compiler error while writing the PR.