#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)
Change History (8)
by , 11 years ago
Attachment: | MoveOptimization.patch added |
---|
comment:1 by , 10 years ago
by , 10 years ago
Attachment: | MoveOptimization.2.patch added |
---|
comment:2 by , 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 , 10 years ago
Attachment: | MoveOpt.patch added |
---|
comment:3 by , 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:5 by , 8 years ago
Keywords: | review removed |
---|
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.