Permalink
Browse files

GetFlexNum/GetFlexName => GetFlexIDByName

Use GetFlexIDByName instead of GetFlexNum/GetFlexName in
GM:MouthMoveAnimation (much fewer Lua string allocations)
1 parent 222de89 commit 143b18a0e5afcc1a11dbd210829b9d5f045c54d6 @willox willox committed Nov 30, 2016
Showing with 10 additions and 12 deletions.
  1. +10 −12 garrysmod/gamemodes/base/gamemode/animations.lua
@@ -266,21 +266,19 @@ end
--
function GM:MouthMoveAnimation( ply )
- local FlexNum = ply:GetFlexNum() - 1
- if ( FlexNum <= 0 ) then return end
+ local flexes = {
+ ply:GetFlexIDByName( "jaw_drop" ),
+ ply:GetFlexIDByName( "left_part" ),
+ ply:GetFlexIDByName( "right_part" ),
+ ply:GetFlexIDByName( "left_mouth_drop" ),
+ ply:GetFlexIDByName( "right_mouth_drop" )
+ }
- for i = 0, FlexNum - 1 do
-
- local Name = ply:GetFlexName( i )
+ local weight = ply:IsSpeaking() and math.Clamp( ply:VoiceVolume() * 2, 0, 2 ) or 0
- if ( Name == "jaw_drop" || Name == "right_part" || Name == "left_part" || Name == "right_mouth_drop" || Name == "left_mouth_drop" ) then
+ for k, v in pairs( flexes ) do
- if ( ply:IsSpeaking() ) then
- ply:SetFlexWeight( i, math.Clamp( ply:VoiceVolume() * 2, 0, 2 ) )
- else
- ply:SetFlexWeight( i, 0 )
- end
- end
+ ply:SetFlexWeight( v, weight )
end

1 comment on commit 143b18a

@thegrb93
Contributor

@willox Why not use #1230 ? It has better performance than this.

Please sign in to comment.