Move Card Animations to the EDT#14819
Conversation
Also remove the busy-loop that waits for card alpha values and make waiting for animations to finish possible. The UI is responsive during running animations.
dfc6e3d to
3e0dace
Compare
|
Tested this change over > 10 real games - no crashes (anymore), worked smooth. |
|
Whats crashes are you talking about? P.S. Also run debugger or visualvm and make sure no timer threads spamming on closed/disconnected games (it must be closed and cleaned on game end). |
Currently xmage crashes a lot during gameplay. From time to time it freezes and never comes back because of some threading/UI access issues. See the linked issue for example. |
Will do. |
|
Also it’s better stability test with 3 players game (play with x2 ai, concede and view ai only play). |
|
I played 1vs1 and Commander online (> 10 games in total). |
|
Will check lots of AI games :) |
|
Are you positive about this PR overall? I would like to see it getting merged soon if everything works fine! I think it would improve stability a lot. |
|
Yes, it’s looks fine and legit, only static to local timer change raise the question. |
That is no problem, as the (new) swing Thread does not spawn any real-thread but uses a shared timer thread and runs on the EDT. See https://docs.oracle.com/javase/8/docs/api/javax/swing/Timer.html. I've added tracking of animations by game-id and source(-card), so if a lot of animations get scheduled for the same object, all old ones get canceled so they don't “fight” each other. Tested with a lot of 8 player AI games + some temporary logging. |
|
There are two problems: no fully finished animation (you must call update(1.0f) on cancel to make sure alpha return to normal value). Non-concurrent hash maps and other animation refs. It's ok to make it concurrent as fast fix, but the real fix (maybe as another PR-task) will be in:
|
|
efda01d to
2c72330
Compare
2c72330 to
6ed0e93
Compare
|
Update: I moved the changes to run |
JayDi85
left a comment
There was a problem hiding this comment.
Also make two lists in issue description:
- fixed bugs and added features like massive animations support;
- farther improvements and left bugs;
| * when finish() gets called. | ||
| */ | ||
| private static final Map<UUID, Set<Animation>> activeByGameId = new HashMap<>(); | ||
| private static final Map<Object, Animation> activeByTarget = new HashMap<>(); |
There was a problem hiding this comment.
Concurrent problem still active - it’s can fail on multiple games/calls. Make it ConcurrentMap or call ensureGUIThread on any create/start/finish animation methods (that can change static lists)
There was a problem hiding this comment.
Client and server allow to start multiple tables/games/ai - it’s can be a good use case for stability testing (start two parallel tables/games with ai, concede and keep active to view/switch between it by main menu).
There was a problem hiding this comment.
Concurrent problem still active - it’s can fail on multiple games/calls. Make it ConcurrentMap or call ensureGUIThread on any create/start/finish animation methods (that can change static lists)
Done. I opted for the ConcurentMap – although, I checked that the code never gets called from non-EDT; but you are right, it is safer that way.
There was a problem hiding this comment.
Client and server allow to start multiple tables/games/ai - it’s can be a good use case for stability testing (start two parallel tables/games with ai, concede and keep active to view/switch between it by main menu).
I already did a lot of testing with parallel AI games and did a litte re-test now – all fine.
There was a problem hiding this comment.
One thing that is noticeable: Since we can now run animations truly async the speed at which AI player play the game against each other can lead to stuttering and a slow client. This is not a problem with human controlled games, as no one untaps and taps like 20+ permanents per second ;).
I guess, since we know the total number of animations per game, we could cancel animations to make sure we are not running more then n animations per game at a time.
There was a problem hiding this comment.
as no one untaps and taps like 20+ permanents per second
But that's a normal use case, e.g. cancel on massive mana payment, start/cancel all attack button or some tap/untap effects with a big battlefield. Make sure it's fine and do not freeze the client.
There was a problem hiding this comment.
You can use test mode to generate big battlefields:
https://github.com/magefree/mage/wiki/Development-Testing-Tools#server-test-mode
There was a problem hiding this comment.
Thank your, I will try that.
There was a problem hiding this comment.
as no one untaps and taps like 20+ permanents per second
But that's a normal use case, e.g. cancel on massive mana payment, start/cancel all attack button or some tap/untap effects with a big battlefield. Make sure it's fine and do not freeze the client.
You are right. And I am very unhappy with the performance of this PR when tapping 25+ permanents at once. I will switch back to the old raw Timer but make sure we do UI stuff on the UI thread + keep the new API.
3feb2b6 to
c9eb1dc
Compare
I changed the PR description to a list. |
| // extra space for animation and other drawing | ||
| // WTF, I'm tired with render calcs, so make BIG draw spaces for any needs | ||
| MageCardSpace outerSpace = new MageCardSpace(width * 2, width * 2, height * 2, height * 2); | ||
| MageCardSpace outerSpace = getAnimationOuterSpace(width, height); |
There was a problem hiding this comment.
For info: there are card icons over card panel like commander icon -- it must have outer space for good drawing/repaint and rotation. Use "main menu - debug - render" to test it without real game.
There was a problem hiding this comment.
For info: there are card icons over card panel like commander icon -- it must have outer space for good drawing/repaint and rotation. Use "main menu - debug - render" to test it without real game.
I will look into this 👍, should be no problem adding some border margin for the icons. This gives better performance as far as I noticed, as the old update-rects are huge.
Marked this PR as a draft, I will ping you if it is ready again.
With the latest change back to a single timer that handles all animation ticks in one go performance is on-par with the old implementation, even on huge boards (it stutters, but so did the old one).
2562974 to
f47bdac
Compare
77a96ad to
8c37d1b
Compare
8c37d1b to
bc33cb6
Compare
|
Issues Solved
refreshGUIAndCardson the EDTFurther Changes
CompletableFutureto schedule actions after animations complete (see use inBattlefieldPanel.java)Future Plans