Opened 11 years ago

Closed 10 years ago

Last modified 8 years ago

#2094 closed enhancement (fixed)

[PATCH] Optimize Move() in CcmpUnitMotion

Reported by: wraitii Owned by: wraitii
Priority: Nice to Have Milestone: Alpha 15
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

Here's a small patch to optimize the "Move()" function of CcmpUnitMotion, which is basically called every turn for every unit. There's a little logic change for detecting if we are nearing the end of our 'short path' (before it was an exact calculation, now it just gets the distance to the target and uses that, which is probably about as good). This needs to be tested for odd cases. It also rotates the unit only once whereas before it might happen several time in the "while" loop, and combines the moveTo and TurnTo into a single function to reduce the number of calls to AdvertisePositioChanges() CcmpPosition, because this is slow (broadcasts a positionchanged message).

I've changed WAYPOINT_ADVANCE_LOOKAHEAD_TURNS from 4 to 3 but I'm not sure what that changes.

This patch changes the simulation hash on replay.

(from quick testing it could be about 50% faster).

Attachments (3)

MoveOptimization.patch (6.0 KB ) - added by wraitii 11 years ago.
MoveOptimization.2.patch (6.3 KB ) - added by wraitii 10 years ago.
MoveOpt.patch (5.0 KB ) - added by wraitii 10 years ago.

Download all attachments as: .zip

Change History (8)

by wraitii, 11 years ago

Attachment: MoveOptimization.patch added

comment:1 by sanderd17, 10 years ago

Instead of calculating .Length() of a 2D vector, it's better to use .CompareLength(fixed). That method avoids a sqrt.

Apart from that, the code looks good I think.

by wraitii, 10 years ago

Attachment: MoveOptimization.2.patch added

comment:2 by wraitii, 10 years ago

Right. This new version should be adapted to use .CompareLength, no other differences.

I've prompted Philip on IRC for review of this patch since I'm not too sure about some of the logic changes.

by wraitii, 10 years ago

Attachment: MoveOpt.patch added

comment:3 by wraitii, 10 years ago

Last patch is a less ambitious ready-to-commit change after discussion with Philip. It should optimize the "Move" function a lot by reducing substantially the number of events sent.

There should not be any checksum difference on replay between this and the current implementation, unless I'm mistaken somewhere.

I'm not committing this directly because as I can't compile right now, I'd rather not break this function. If it works, commit it.

comment:4 by wraitii, 10 years ago

Resolution: fixed
Status: newclosed

In 14287:

Optimize the "Move()" function by removing unnecessary message broadcast. Fixes #2094

comment:5 by sanderd17, 8 years ago

Keywords: review removed
Note: See TracTickets for help on using tickets.