Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Layer optimizations #3358

wants to merge 3 commits into from

Conversation

Garanas
Copy link
Member

@Garanas Garanas commented Aug 17, 2021

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.

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.
@Garanas Garanas changed the title Layer optimalisation Layer optimizations Aug 17, 2021
@@ -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.
Copy link
Member

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

Copy link
Member Author

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).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnLayerChange

@KionX
Copy link
Collaborator

KionX commented Aug 17, 2021

There is no inherited call OnLayerChange in defaultunits.lua 2145...

@Garanas
Copy link
Member Author

Garanas commented Aug 17, 2021

I think you are referring to https://github.com/FAForever/fa/blob/deploy/fafdevelop/lua/defaultunits.lua#L2225 . You are right, missed that one.

@Garanas Garanas closed this Aug 20, 2021
@Garanas
Copy link
Member Author

Garanas commented Aug 20, 2021

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.

@Garanas Garanas deleted the layer-optimalisation branch August 25, 2021 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants