Opened 8 years ago

Last modified 5 years ago

#3748 new defect

[PATCH] Idle units undetected for one second

Reported by: elexis Owned by:
Priority: Nice to Have Milestone: Backlog
Component: Simulation Keywords: patch
Cc: Patch:

Description

If a unit becomes idle, it will immediately enter "INDIVIDUAL.IDLE" and update the animation. Meanwhile "isIdle" is still false and only updated exactly one second later on Timer (see r8891). This results in the idle-worker button not finding the unit for one second while it is blatantly idling.

This issue is recognizable in particular if one reduces the gamespeed (replay-speed) to 0.1x.

In order to solve this issue, isIdle must be set true when entering INDIVIDUAL.IDLE instead of waiting one second for the timer to catch it.

But it must be done at the end of the function, since the unit might decide to do things like healing or attacking enemies when entering idle.

Attachments (2)

UnitAI_set_isIdle_on_INDIVIDUAL.IDLE.enter_v1.patch (2.4 KB ) - added by elexis 8 years ago.
UnitAI_set_isIdle_on_INDIVIDUAL.IDLE.enter_v2.patch (3.5 KB ) - added by elexis 8 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by mimo, 8 years ago

I think this timer was used in the past because units in between two orders would go in the IDLE state. But that was causing some errors (for example units in between orders looking for new target), and lines 1447-1448 were added, so that all the code in IDLE state is bypassed in that case. So i think removing this timer now fine.

Concerning the patch itself:

  • you should remove all tracks of the timer: the stopTimer in the leave function and the (now empty) Timer body function.
  • these temporary idle units won't have the this.idle flag set, so the test in the leave function line 1489 is needed (and maybe add a comment about that), but the test in the enter function line 1470 could be removed (although it does not hurt).

comment:2 by elexis, 8 years ago

Observation After testing more (with sheep, units with an without formations, garrisoning, rallypoints and queued orders), I found apparently dead code in three places: (1) this.isIdle is always false in INDIVIDUAL.IDLE.enter (as mentioned by mimo) (2) this.isIdle is always true in INDIVIDUAL.IDLE.leave (contrary to mimo's statement) (3) INDIVIDUAL.IDLE.enter is not triggered while this.orderQueue.length > 0 && !this.IsGarrisoned()

Theory The explanation for (1) is this.isIdle being set to

  • false only by UnitAI.prototype.Init and INDIVIDUAL.IDLE.leave
  • true only by UnitAI.prototype.OnCreate and INDIVIDUAL.IDLE.Timer (i.e. 1 second after INDIVIDUAL.IDLE.enter)

The explanation for (2) is that we return true in INDIVIDUAL.IDLE.enter in case we decide to switch to another task (f.e. going to the guarded object when entering idle, or finding a new enemy in LoS to attack).

The explanation for (3) is that the UnitAI.prototype.FinishOrder doesn't SetNextState("IDLE") if this.orderQueue is empty.

Patch The updated patch removes the dead code, but triggers a warning in case the code (future revisions?) would do one of those unfortunate state-changes.

Refs:

comment:3 by mimo, 8 years ago

I'm convinced your tests are not enough as these were very rare bugs. These lines (test on this.orderQueue.length > 0 && !this.IsGarrisoned()) were added in r17304, so you should go there and it says that it fixes #3630 which had the same origin as #3466. Both were fixed by this commit, and if you want to test it back, you should use one of the commands.txt given in these tickets (and the corresponding revision).

comment:4 by Itms, 8 years ago

Milestone: Alpha 20Alpha 21

comment:5 by sanderd17, 8 years ago

Keywords: review removed

Removing the review tag until the regressions mentioned by mimo are tested.

comment:6 by elexis, 8 years ago

Milestone: Alpha 21Alpha 22

comment:7 by elexis, 7 years ago

Milestone: Alpha 22Backlog
Summary: Idle units undetected for one second[PATCH] Idle units undetected for one second

Guess we don't care.

comment:8 by Imarok, 5 years ago

Component: UI & SimulationSimulation

Move tickets to Simulation as UI & Simulation got some sub components.

Note: See TracTickets for help on using tickets.