ihhub / fheroes2

fheroes2 is a recreation of Heroes of Might and Magic II game engine.
https://ihhub.github.io/fheroes2/
GNU General Public License v2.0
2.68k stars 373 forks source link

During battle, the moving animation is jerky #7176

Closed kazenoyouni closed 1 year ago

kazenoyouni commented 1 year ago

Preliminary checks

Platform

PlayStation Vita

Describe the bug

During battle, the moving animation is jerky, especially flying creatures. It was smooth until 1.0.2, but from 1.0.3 it became like this. And the latest 1.0.4 also has this problem.

Save file

This happens in all battles.

Additional info

No response

oleg-derevenetz commented 1 year ago

Hi @kazenoyouni could you please attach a video of these animations, if possible? Also, does this depend on the animation speed, and, if yes, on which speed it happens?

kazenoyouni commented 1 year ago

1.0.2 https://github.com/ihhub/fheroes2/assets/111102725/125b0479-0dab-499a-a6a6-ac658d2366d6

1.0.4 a https://github.com/ihhub/fheroes2/assets/111102725/6ae0dde6-781a-4ac6-9118-92265a565ad4

1.0.4 b https://github.com/ihhub/fheroes2/assets/111102725/7f65eb89-b145-4d9e-9f0b-ca6a1aefed53

Hi @oleg-derevenetz , It is more noticeable at speed 8-10. I usually play the game at speed 10. Speed 7 or less is difficult to understand because the animation itself is slow.

oleg-derevenetz commented 1 year ago

Hi @Districh-ru what do you think about this issue? You're more of a combat animation expert than I am. At least Cyclops in the third video really moves jerkily, it's quite noticeable.

Districh-ru commented 1 year ago

Hi @oleg-derevenetz and @kazenoyouni. Yes, the movement of creatures looks jerky on v. 1.0.4 videos. I tried to reproduce it on my Android devices, but could not. Also I could not find any changes in creatures moving animation after v. 1.0.2. Only just before the v. 1.0.2 release we made a change in animation delays for the "10" battle speed. I'll analyze the code of creatures movement animation for possible slowdowns.

Also at high battle speed the "background" actions animation (heroes' flags, idle animations) is also very high and it produces many extra renderings which loads the CPU. I'll also implement the suggestion of #7125 and limit the animation of "background" actions and it should reduce the CPU load on high battle speeds and, possibly, fix the jerky animation bug.

oleg-derevenetz commented 1 year ago

Also at high battle speed the "background" actions animation (heroes' flags, idle animations) is also very high and it produces many extra renderings which loads the CPU.

I believe this behavior was in 1.0.2 as well, therefore, this issue is unlikely because of this.

Districh-ru commented 1 year ago

I believe this behavior was in 1.0.2 as well, therefore, this issue is unlikely because of this.

Yes it was and it is not the real cause of animation lags. I'll try to find a source of animation lags. And lowering the animation speed of background animations should also have a positive impact. :)

ihhub commented 1 year ago

Hi @kazenoyouni , is it possible to provide CPU profiling during battles? It would help to confirm that this is CPU load impact.

kazenoyouni commented 1 year ago

Hi @ihhub, please see the following videos as per attached.

1.0.2 https://github.com/ihhub/fheroes2/assets/111102725/9def51a2-ba31-4be3-a5c2-63aeff70b620

1.0.4 https://github.com/ihhub/fheroes2/assets/111102725/7f9ee78a-90a6-4ac6-ab6d-7e3f75ebaf05

ihhub commented 1 year ago

Thank you @kazenoyouni ! It proves my assumption that we are hitting the CPU limit.

@Districh-ru , do you have ideas where exactly we are eating much more CPU? I assume this is because we are doing more animations in general.

Districh-ru commented 1 year ago

@kazenoyouni , thanks for videos!

@Districh-ru , do you have ideas where exactly we are eating much more CPU? I assume this is because we are doing more animations in general.

@ihhub , as we did not change the moving animations and battlefield rendering after 1.0.2 release and as the lags don't happen on every frame (the animation is jerky and not always slow) the CPU load may happen in other place (SDL audio or some other parallel process). I'll check it thoroughly at the weekend. And, yes, we need to reduce the CPU load while rendering the Battlefield, especially on high battle speeds. I'll try to optimize it.

Districh-ru commented 1 year ago

I reproduced this behavior with Vita3K emulator (with turned off "CPU optimizations"): on v. 1.0.2 all animations are smooth and on v.1.0.3 they are jerky.

v.1.0.3:

https://github.com/ihhub/fheroes2/assets/113276641/4bcda699-0b39-440c-b845-e22237e200d2

v.1.0.2:

https://github.com/ihhub/fheroes2/assets/113276641/d2b6df16-7972-45b5-afb8-cc61e52fd456

The whole animation in v.1.0.3 is slower and has lags when the creature ends a move for one cell and begins a move to the next cell. It is very noticeable on Golem moves. And we do no extra screen render during this lag. So the whole fheroes2 process eats more CPU in v.1.0.3 than in v.1.0.2. I'll try to find out how to compile a psVita port... to find when the engine became more CPU expensive.