HomeWildfire Games

Fix UnitMotion calculation of time left to avoid units going back and forth…

Description

Fix UnitMotion calculation of time left to avoid units going back and forth between walking and running animations.

Because of the limited precision of our fixed-point numbers, the timeLeft calculation could sometimes return results above the actual time left, resulting in units moving a few fixed::epsilons farther than they should be, which makes them switch to the running animation. This was rather unstable however, so there was a constant 'flickering' between walking and running.
If we divide last instead of first in the operation, the errors get gobbled up by the division and we no longer have this issue.

Reported by: wowgetoffyourcellphone

Differential Revision: https://code.wildfiregames.com/D1856

Event Timeline

Stan raised a concern with this commit.May 6 2019, 12:52 AM
Stan added a subscriber: Stan.

Still seems like it doesn't fix it. Look at the camel's behavior when gathering from a deer.

This commit now has outstanding concerns.May 6 2019, 12:52 AM

Mpf, I'm guessing there's still some cases where that isn't enough.
I think the simplest fix here is adding a bit of leeway in Visual Actor to be honest.

The 'most correct' fix is probably to make the "speed at which the unit switches to the running animation" a template parameter instead of using the walk speed, since there is no real reason to switch to running when right above the walk speed. Might do that if it's easier.

Stan added a subscriber: Silier.May 6 2019, 9:56 AM

Maybe it's just the resetting state @Angen mentionned :)

The camel issue does appear to be only the thing Angen mentioned. Doesn't mean there aren't units for which things get wonky from rounding though.

elexis added a subscriber: elexis.May 15 2019, 1:54 PM

2010-11-22-QuakeNet-#0ad-dev.log

@Philip`: UnitAI is complex :-(

  • Philip` has decided that writing unit tests is probably a good way to deal with it

@Philip`: Yay, my test is now non-useless
@Philip`: and I only had to construct 14 components in order to test one part of one UnitAI properly
@Philip`: EmjeR: Because it finds the bug I was trying to test, and also it tells me that if I make the obvious fix then a different case breaks

(Just encountered this while reviewing, not intending to imply that this should be done)

Stan added a comment.May 15 2019, 2:00 PM

2010-11-22-QuakeNet-#0ad-dev.log

@Philip`: UnitAI is complex :-(

  • Philip` has decided that writing unit tests is probably a good way to deal with it

@Philip`: Yay, my test is now non-useless
@Philip`: and I only had to construct 14 components in order to test one part of one UnitAI properly
@Philip`: EmjeR: Because it finds the bug I was trying to test, and also it tells me that if I make the obvious fix then a different case breaks

(Just encountered this while reviewing, not intending to imply that this should be done)

Was that test ever added ?

svn log test_UnitAI.js

Stan resigned from this commit.Apr 25 2020, 12:12 AM
Stan removed an auditor: Stan.
Stan added a subscriber: wowgetoffyourcellphone.

@wowgetoffyourcellphone confirmed he didn't encounter this bug recently.

This commit no longer requires audit.Apr 25 2020, 12:12 AM