Fix multiple issues with screenshake code#812
Conversation
Salanto
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
We are probably gonna loose some precision during your implicit conversion from float to int, but the effect will likely be negligible.
There was a problem hiding this comment.
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).
Salanto
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
you made me look at mickey mouse again 😭
|
Making the shake scale to viewport size is a welcome addition. |

While working on an independent project, I found multiple issues with the screenshake function:
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