Skip to content

Fix multiple issues with screenshake code#812

Merged
Crystalwarrior merged 5 commits intomasterfrom
screenshake-math
Jul 23, 2022
Merged

Fix multiple issues with screenshake code#812
Crystalwarrior merged 5 commits intomasterfrom
screenshake-math

Conversation

@in1tiate
Copy link
Member

While working on an independent project, I found multiple issues with the screenshake function:

  • Maximum deviation from origin did not work as expected (values frequently exceeded this so-called maximum)
  • Random deviation was heavily biased toward positive values, resulting in screenshakes being visibly directed downwards and to the right
  • X and Y deviation were calculated using the same randomly generated value, resulting in screenshakes being visibly locked into a linear set of positions
  • Screenshake intensity was not scaled to the viewport - A larger viewport would have less intense shaking

I have ported my corrected version. Here are some example videos, so you can see the difference (viewport size 512x384)

Current screenshake:
https://user-images.githubusercontent.com/32779090/179497853-4b789143-2f11-4a61-9af6-f2002f1fd5cb.mp4

My screenshake:
https://user-images.githubusercontent.com/32779090/179497933-7da6037e-2640-4866-8d9d-573f935a71da.mp4

@in1tiate in1tiate requested review from Salanto and oldmud0 July 18, 2022 11:02
Salanto
Salanto previously approved these changes Jul 18, 2022
Copy link
Contributor

@Salanto Salanto left a comment

Choose a reason for hiding this comment

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

Looks goot to me, might cause troubles when using older distros, but eh, that can be done later. CI passes and your demo shows the noticable improvement to the old system.

// Maximum deviation from the origin position. This is 7 pixels for a 256x192 viewport,
// so we scale that value in accordance with the current viewport height so the shake
// is roughly the same intensity regardless of viewport size. Done as a float operation for maximum accuracy.
int max_deviation = 7 * (float(ui_viewport->height()) / 192);
Copy link
Contributor

@Salanto Salanto Jul 18, 2022

Choose a reason for hiding this comment

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

We are probably gonna loose some precision during your implicit conversion from float to int, but the effect will likely be negligible.

Copy link
Member Author

@in1tiate in1tiate Jul 18, 2022

Choose a reason for hiding this comment

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

This is purposeful, actually - this is used as the bounds for QRandomGenerator, which does not generate floating point numbers. Additionally, since this is a deviation from the origin in pixels, the maximum applicable precision is integer precision anyway.

Also the implicit conversion only happens to the end value, which means the loss of precision is negligible (and doing these calculations with integers noticeably affects the final value - a 480p viewport will have a max deviation of 14 when done with integer math, while using floats will bump it up to 17).

@in1tiate in1tiate requested a review from Salanto July 18, 2022 12:22
Salanto
Salanto previously approved these changes Jul 18, 2022
@in1tiate
Copy link
Member Author

image

@in1tiate in1tiate requested a review from Salanto July 18, 2022 12:48
Salanto
Salanto previously approved these changes Jul 18, 2022
Copy link
Contributor

@Salanto Salanto left a comment

Choose a reason for hiding this comment

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

I'm gonna need a stapler at this point to keep it approved.
The surprise tool looks like ass, but hoenstly, it seems to work a bit better.

stonedDiscord
stonedDiscord previously approved these changes Jul 19, 2022
Copy link
Member

@stonedDiscord stonedDiscord left a comment

Choose a reason for hiding this comment

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

i hate mickey mouse

Copy link
Contributor

@Salanto Salanto left a comment

Choose a reason for hiding this comment

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

staple noises

Copy link
Member

@stonedDiscord stonedDiscord left a comment

Choose a reason for hiding this comment

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

you made me look at mickey mouse again 😭

@Crystalwarrior Crystalwarrior added this to the 2.10 milestone Jul 22, 2022
@TrickyLeifa TrickyLeifa added bug Confirmed bug engine/viewport Issues related to viewport positioning and layering labels Jul 22, 2022
@Crystalwarrior Crystalwarrior merged commit 0519aba into master Jul 23, 2022
@oldmud0
Copy link
Member

oldmud0 commented Jul 23, 2022

Making the shake scale to viewport size is a welcome addition.

@in1tiate in1tiate deleted the screenshake-math branch June 18, 2024 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Confirmed bug engine/viewport Issues related to viewport positioning and layering

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants