Skip to content

Commit 90b16be

Browse files
committed
Only update projtext when needed
1 parent a5f5829 commit 90b16be

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

lua/entities/gmod_wire_lamp.lua

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ function ENT:SetupDataTables()
1515
self:NetworkVar("Int", "Brightness")
1616
self:NetworkVar("String", "Texture")
1717

18-
self:NetworkVarNotify( "FOV", self.OnVarChanged )
19-
self:NetworkVarNotify( "Red", self.OnVarChanged )
20-
self:NetworkVarNotify( "Green", self.OnVarChanged )
21-
self:NetworkVarNotify( "Blue", self.OnVarChanged )
22-
self:NetworkVarNotify( "Distance", self.OnVarChanged )
23-
self:NetworkVarNotify( "Brightness", self.OnVarChanged )
24-
self:NetworkVarNotify( "Texture", self.OnVarChanged )
18+
if CLIENT then
19+
local function callOnVarChanged( _, ... ) -- Fixes autorefresh
20+
self:OnVarChanged( ... )
21+
end
22+
self:NetworkVarNotify( "FOV", callOnVarChanged )
23+
self:NetworkVarNotify( "Red", callOnVarChanged )
24+
self:NetworkVarNotify( "Green", callOnVarChanged )
25+
self:NetworkVarNotify( "Blue", callOnVarChanged )
26+
self:NetworkVarNotify( "Distance", callOnVarChanged )
27+
self:NetworkVarNotify( "Brightness", callOnVarChanged )
28+
self:NetworkVarNotify( "Texture", callOnVarChanged )
29+
end
2530
end
2631

2732
function ENT:GetEntityDriveMode()
@@ -87,6 +92,19 @@ if CLIENT then
8792
self:DrawEffects()
8893
end
8994

95+
function ENT:UpdateProjTex()
96+
local projtex = self.ProjTex
97+
if not IsValid(projtex) then return end
98+
99+
projtex:SetEnableShadows( false )
100+
projtex:SetTexture( self:GetTexture() )
101+
projtex:SetFOV( self:GetFOV() )
102+
projtex:SetFarZ( self:GetDistance() )
103+
projtex:SetBrightness( self:GetBrightness() / 255 )
104+
projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) )
105+
projtex:Update()
106+
end
107+
90108
function ENT:Think()
91109
if not self:GetOn() then
92110
if IsValid( self.ProjTex ) then
@@ -100,6 +118,7 @@ if CLIENT then
100118
-- Projected texture
101119
if not IsValid( self.ProjTex ) then
102120
self.ProjTex = ProjectedTexture()
121+
self:UpdateProjTex()
103122
end
104123

105124
local light_info = self:GetLightInfo()
@@ -109,14 +128,8 @@ if CLIENT then
109128
local lastLampMatrix = self.LastLampMatrix or 0
110129
if lastLampMatrix ~= lampMatrix then
111130
local projtex = self.ProjTex
112-
projtex:SetTexture( self:GetTexture() )
113-
projtex:SetFOV( self:GetFOV() )
114-
projtex:SetFarZ( self:GetDistance() )
115-
projtex:SetBrightness( self:GetBrightness() / 255 )
116-
projtex:SetColor( Color( self:GetRed(), self:GetGreen(), self:GetBlue() ) )
117131
projtex:SetPos( lightpos )
118132
projtex:SetAngles( self:LocalToWorldAngles( light_info.Angle or angle_zero ) )
119-
projtex:SetEnableShadows( false )
120133
projtex:Update()
121134
end
122135
self.LastLampMatrix = lampMatrix
@@ -129,7 +142,11 @@ if CLIENT then
129142
end
130143

131144
function ENT:OnVarChanged( varname, oldvalue, newvalue )
132-
self.LastLampMatrix = nil
145+
timer.Simple( 0, function()
146+
if not IsValid( self ) then return end
147+
if not IsValid( self.ProjTex ) then return end
148+
self:UpdateProjTex()
149+
end )
133150
end
134151
end
135152

0 commit comments

Comments
 (0)