@@ -190,30 +190,47 @@ function ENT:OnModelSetup()
190190end
191191
192192function ENT :GetWallTraceParamenters ()
193- if not self .WallTraceParamenters then
194- self .WallTraceParamenters = {
195- mask = MASK_SHOT_PORTAL ,
196- filter = function (ent )
197- if not IsValid (ent ) then return false end
198- if not IsValid (self ) then return false end
199-
200- if ent == self then return false end
201- if ent .__IsRadio then return false end
202- if ent :IsPlayer () then return false end
203- if ent :IsVehicle () then return false end
204- if ent :IsNPC () then return false end
205-
206- local camera = StreamRadioLib .GetCameraEnt ()
207- if IsValid (camera ) and ent == camera then return false end
208-
209- return true
210- end
211- }
193+ local wallTraceParamenters = self .WallTraceParamenters
194+
195+ if not wallTraceParamenters then
196+ self .WallTraceParamenters = {}
197+
198+ wallTraceParamenters = self .WallTraceParamenters
199+ wallTraceParamenters .mask = MASK_SHOT_PORTAL
200+ wallTraceParamenters .filter = {}
212201 end
213202
214- self .WallTraceParamenters .output = self .WallTraceParamenters .output or {}
203+ wallTraceParamenters .output = wallTraceParamenters .output or {}
204+
205+ local camera = StreamRadioLib .GetCameraEnt (ent )
206+ local cameraVehicle = false
207+
208+ if IsValid (camera ) then
209+ cameraVehicle = camera .GetVehicle and camera :GetVehicle () or false
210+ else
211+ camera = false
212+ end
213+
214+ local tmp = {}
215+
216+ tmp [self ] = self
217+ tmp [camera ] = camera
218+ tmp [cameraVehicle ] = cameraVehicle
215219
216- return self .WallTraceParamenters
220+ local filter = wallTraceParamenters .filter
221+ table .Empty (filter )
222+
223+ for _ , filterEnt in pairs (tmp ) do
224+ if not IsValid (filterEnt ) then continue end
225+ table.insert (filter , filterEnt )
226+ end
227+
228+ for _ , filterEnt in pairs (StreamRadioLib .SpawnedRadios ) do
229+ table.insert (filter , filterEnt )
230+ end
231+
232+ wallTraceParamenters .filter = filter
233+ return wallTraceParamenters
217234end
218235
219236function ENT :TraceToCamera (frompos )
@@ -228,18 +245,13 @@ function ENT:TraceToCamera(frompos)
228245 local result = traceparams .output
229246
230247 -- Tracers Debug
231- -- debugoverlay.Line(frompos, result.HitPos or endpos, 0.1 , color_white, false)
232- -- debugoverlay.Line(result.HitPos or endpos, endpos, 0.1 , color_black, false)
248+ -- debugoverlay.Line(frompos, result.HitPos or endpos, 0.5 , color_white, false)
249+ -- debugoverlay.Line(result.HitPos or endpos, endpos, 0.5 , color_black, false)
233250
234251 return result
235252end
236253
237254function ENT :TraceWalls (radius )
238- local coveredvol = StreamRadioLib .GetCoveredVolume ()
239- if coveredvol >= 1 then
240- return 1
241- end
242-
243255 local startpos = self .SoundPos
244256
245257 local camtrace = self :TraceToCamera (startpos )
@@ -251,7 +263,7 @@ function ENT:TraceWalls(radius)
251263
252264 traceparams .start = startpos
253265
254- local traces = StreamRadioLib .StarTrace (traceparams , radius , 16 , 16 )
266+ local traces = StreamRadioLib .StarTrace (traceparams , radius )
255267
256268 local blockcount = 0
257269 local wallcount = 0
@@ -285,7 +297,9 @@ function ENT:TraceWalls(radius)
285297
286298 local f = blockcount / wallcount
287299
288- local volfactor = math .Clamp ((1 - f ) * 2 , coveredvol , 1 )
300+ f = (1 - f ) * 2
301+
302+ local volfactor = math .Clamp (f , 0 , 1 )
289303 return volfactor
290304end
291305
@@ -300,24 +314,53 @@ function ENT:GetWallVolumeFactor()
300314 return 0
301315 end
302316
303- if StreamRadioLib .GetCoveredVolume () >= 1 then
317+ local coveredvol = StreamRadioLib .GetCoveredVolume ()
318+
319+ if coveredvol >= 1 then
320+ self .wallvolcache = nil
321+ return 1
322+ end
323+
324+ local streamingRadioCount = StreamRadioLib .GetStreamingRadioCount ()
325+ if streamingRadioCount <= 0 then
304326 self .wallvolcache = nil
305327 return 1
306328 end
307329
308330 local now = RealTime ()
309331
310332 self .wallvolcache = self .wallvolcache or {}
311- if (self .wallvolcache .nexttime or 0 ) >= now then
312- return self .wallvolcache .value or 0
333+ local cache = self .wallvolcache
334+ local oldvalue = cache .value or 0
335+
336+ if cache .nexttime and cache .nexttime > now then
337+ return math.max (oldvalue , coveredvol )
338+ end
339+
340+ local startTime = SysTime ()
341+
342+ local value = self :TraceWalls (self .Radius ) or 1
343+
344+ local endTime = SysTime ()
345+ local runtime = endTime - startTime
346+
347+ local mintime = math.max (RealFrameTime () * 30 , runtime * streamingRadioCount * 50 , 0.1 )
348+
349+ if oldvalue <= 0 and value <= 0 then
350+ -- already quiet radios should retest less often
351+ mintime = math.max (mintime * 3 , 0.5 )
352+ elseif oldvalue >= 1 and value >= 1 then
353+ -- already clear radios should retest less often
354+ mintime = math.max (mintime * 3 , 0.5 )
313355 end
314356
315- local mintime = math.max (FrameTime () * 3 , 0.075 )
357+ mintime = math .Rand (mintime , mintime * 2 )
358+ mintime = math.min (mintime , 3 )
316359
317- self .wallvolcache .value = self :TraceWalls (self .Radius )
318- self .wallvolcache .nexttime = now + math .Rand (mintime , mintime * 4 )
360+ cache .nexttime = now + mintime
319361
320- return self .wallvolcache .value or 1
362+ cache .value = value
363+ return math.max (value , coveredvol )
321364end
322365
323366function ENT :GetWallVolumeFactorSmoothed ()
@@ -635,9 +678,9 @@ function ENT:OnMasterradioChange(masterradio, oldmasterradio)
635678 end
636679end
637680
638- function ENT :DrawTranslucent ()
639- BaseClass .DrawTranslucent (self )
640- self :CallModelFunction (" Draw" )
681+ function ENT :DrawTranslucent (... )
682+ BaseClass .DrawTranslucent (self , ... )
683+ self :CallModelFunction (" Draw" , ... )
641684end
642685
643686function ENT :PostFakeRemove ()
0 commit comments