New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Layer optimizations #3358
Layer optimizations #3358
Conversation
Each time a unit changes layer the new layer is stored inside the unit. In my own investigations this appeared to be a reliable change to GetCurrentLayer as it always returned the right values. It prevents an engine call in some of the most called functions (such as OnMotionHorzEventChange) - which is a significant improvement in comparison to retrieving a table value.
@@ -5,7 +5,7 @@ | |||
--#** | |||
--#** Summary : Seraphim Hydrocarbon Power Plant Script | |||
--#** | |||
--#** Copyright � 2007 Gas Powered Games, Inc. All rights reserved. | |||
--#** Copyright � 2007 Gas Powered Games, Inc. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha seems like there might be an unintentional encoding change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you are correct.
@@ -130,7 +130,8 @@ end | |||
function Unit:GetConsumptionPerSecondMass() | |||
end | |||
|
|||
--- Return the name of the layer the unit is currently in. | |||
--- Return the name of the layer the unit is currently in. This value is cached inside | |||
-- unit.Layer each time a layer changes (when OnLayerChanged is called). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OnLayerChange
There is no inherited call OnLayerChange in defaultunits.lua 2145... |
I think you are referring to https://github.com/FAForever/fa/blob/deploy/fafdevelop/lua/defaultunits.lua#L2225 . You are right, missed that one. |
Closed in favor of #3366 - which is essentially the same but because of my git setup the previous one was on FAForever and this one is coming from a fork. Also easily fixes the encoding problem Sheikah pointed out. |
This caches the GetCurrentLayer() outcome each time when OnLayerChange() is called by the engine. In turn, we save on engine calls while at the same time not breaking compatibility with mods and / or unchanged code.