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

Migrated some remaining floats in simulation to integers (and decimals) #10972

Merged
merged 7 commits into from Mar 28, 2016

Conversation

reaperrr
Copy link
Contributor

Partially adresses #10845.

@@ -82,8 +82,8 @@ public static WVec LerpQuadratic(WVec a, WVec b, WAngle pitch, int mul, int div)
return ret;

// Add an additional quadratic variation to height
// Uses fp to avoid integer overflow
var offset = (int)((float)(b - a).Length * pitch.Tan() * mul * (div - mul) / (1024 * div * div));
// Uses long to avoid integer overflow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a hot path, so we could probably get away with using decimal here (there's another similar line somewhere using long that could also change) and remove the risk of overflow completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I saw WPos use long in a similar case, should that change to decimal as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that is the line I was referring to.

@reaperrr reaperrr force-pushed the fp-to-int1 branch 2 times, most recently from 3d8b773 to 6340ca9 Compare March 24, 2016 15:16
@reaperrr
Copy link
Contributor Author

Updated.

@reaperrr reaperrr changed the title Migrated some remaining floats in simulation to integers Migrated some remaining floats in simulation to integers (and decimals) Mar 24, 2016
@@ -65,7 +65,7 @@ public static WPos LerpQuadratic(WPos a, WPos b, WAngle pitch, int mul, int div)

// Add an additional quadratic variation to height
// Attempts to avoid integer overflow by keeping the intermediate variables reasonably sized
var offset = (int)(((((((long)(b - a).Length * mul) / div) * (div - mul)) / div) * pitch.Tan()) / 1024);
var offset = (int)(((((((decimal)(b - a).Length * mul) / div) * (div - mul)) / div) * pitch.Tan()) / 1024);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can now drop most of the nested parenthesis, and the comment above will need to be updated (or just remove it).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare with the calculation in WVec.

@pchote
Copy link
Member

pchote commented Mar 26, 2016

Looks good otherwise 👍

@reaperrr
Copy link
Contributor Author

Updated.

@Mailaender
Copy link
Member

Needs a rebase.

…ntages

Additionally, MinHpPercent should now actually have the desired effect (previously there was not logic attached).
141 / PI ~= 44.88, so 45 should be accurate enough. This should reduce desync risk while improving performance of this calculation.
To reduce desync risk (without introducing overflow risk).
@reaperrr
Copy link
Contributor Author

Rebased.
Also added one last commit that moves all upgrade rules from both PRs to the same engineVersion.

@Mailaender Mailaender merged commit 77d4154 into OpenRA:bleed Mar 28, 2016
@Mailaender
Copy link
Member

Thanks!

@Mailaender
Copy link
Member

Changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants