Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#1999 closed defect (fixed)

[PATCH] Cleaning of OnDestroy in UnitAI

Reported by: mimo Owned by: leper
Priority: Should Have Milestone: Alpha 14
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description (last modified by historic_bruno)

In UnitAI, when a unit is destroyed, the leave method of its current state is not called, thus forcing to dupplicate some code in the OnDestroy method. Presently, there are some code to clean timers or update some counters. But working on #1391 I would need to add more.These would become useless if we are sure the leave method is always called. Here is a patch to fix that.

Attachments (1)

destroy.diff (1.0 KB ) - added by mimo 11 years ago.

Download all attachments as: .zip

Change History (8)

by mimo, 11 years ago

Attachment: destroy.diff added

comment:1 by historic_bruno, 11 years ago

Milestone: BacklogAlpha 15

comment:2 by historic_bruno, 11 years ago

Description: modified (diff)

comment:3 by Markus, 11 years ago

Summary: [PATCH]Cleaning of OnDestroy in UnitAI[PATCH] Cleaning of OnDestroy in UnitAI

comment:4 by leper, 11 years ago

Component: Core engineUI & Simulation

Wouldn't introducing a new state (possibly named DESTROY) and switching to that be nicer? Apart from that I really like the change.

comment:5 by mimo, 11 years ago

Not sure the DESTROY state is really usefull. The idea of the patch is to switch to a "nostate" state to be sure to leave all previously entered states, so no need to enter a new state. But if people prefer the DESTROY state, let me know, I can modify the patch.

while we are at it, my first idea was to switch to a really empty state, i.e. SwitchToNextState(this, "") but this gave a crash because I think line 353 of simulation/helpers/FSM.js should be

if (obj.fsmReenter && equalPrefix === toState.length && equalPrefix != 0)

instead of

if (obj.fsmReenter && equalPrefix === toState.length)

comment:6 by leper, 11 years ago

Owner: set to leper
Resolution: fixed
Status: newclosed

In 13501:

Let states execute their leave handlers on OnDestroy. Fixes #1999. Patch by mimo.

comment:7 by leper, 11 years ago

Keywords: review removed
Milestone: Alpha 15Alpha 14

Good that the FSM has a "" state by default, as that is really the cleanest solution IMO. Thanks for the patch.

Note: See TracTickets for help on using tickets.