Skip to content

Commit

Permalink
Reduce sound message sizes a bit further
Browse files Browse the repository at this point in the history
  • Loading branch information
thecraftianman committed Jan 25, 2024
1 parent 0a2a7af commit 1cb2770
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lua/acf/core/utilities/sounds/sounds_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ do -- Playing regular sounds
local Path = net.ReadString()
local Level = net.ReadUInt(7)
local Pitch = net.ReadUInt(8)
local Volume = net.ReadFloat()
local Volume = net.ReadUInt(7) / 100

if not Sounds.IsValidSound(Path) then return end

Expand Down Expand Up @@ -97,7 +97,7 @@ do -- Processing adjustable sounds (for example, engine noises)
Sounds.DestroyAdjustableSound(Origin)
else
local Pitch = net.ReadUInt(8)
local Volume = net.ReadFloat()
local Volume = net.ReadUInt(7) / 100

Sounds.UpdateAdjustableSound(Origin, Pitch, Volume)
end
Expand Down
6 changes: 4 additions & 2 deletions lua/acf/core/utilities/sounds/sounds_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Sounds.SendSound(Origin, Path, Level, Pitch, Volume)
net.WriteString(Path)
net.WriteUInt(Level, 7)
net.WriteUInt(Pitch, 8)
net.WriteFloat(Volume)
net.WriteUInt(Volume * 100, 7)
net.SendPAS(Pos)
end

Expand Down Expand Up @@ -55,7 +55,9 @@ function Sounds.SendAdjustableSound(Origin, ShouldStop, Pitch, Volume)
net.WriteBool(ShouldStop)
if not ShouldStop then
net.WriteUInt(Pitch, 8)
net.WriteFloat(Volume)

Volume = Volume * 100 -- Sending the approximate volume as an int to reduce message size
net.WriteUInt(Volume, 7)
end
net.SendPAS(Origin:GetPos())
Origin.ACF.SoundTimer = Time + 0.1
Expand Down
29 changes: 14 additions & 15 deletions lua/entities/acf_engine/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -365,17 +365,18 @@ do -- Spawn and Update functions
Player:AddCleanup("acf_engine", Entity)
Player:AddCount(Limit, Entity)

Entity.Owner = Player -- MUST be stored on ent for PP
Entity.Active = false
Entity.Gearboxes = {}
Entity.FuelTanks = {}
Entity.LastThink = 0
Entity.MassRatio = 1
Entity.FuelUsage = 0
Entity.Throttle = 0
Entity.FlyRPM = 0
Entity.SoundPath = Engine.Sound
Entity.DataStore = Entities.GetArguments("acf_engine")
Entity.Owner = Player -- MUST be stored on ent for PP
Entity.Active = false
Entity.Gearboxes = {}
Entity.FuelTanks = {}
Entity.LastThink = 0
Entity.MassRatio = 1
Entity.FuelUsage = 0
Entity.Throttle = 0
Entity.FlyRPM = 0
Entity.SoundPath = Engine.Sound
Entity.LastPitch = 0
Entity.DataStore = Entities.GetArguments("acf_engine")
Entity.revLimiterEnabled = true

UpdateEngine(Entity, Data, Class, Engine, Type)
Expand Down Expand Up @@ -599,10 +600,9 @@ function ENT:UpdateSound()

local Pitch, Volume = GetPitchVolume(self)

if Pitch == self.LastPitch or Volume == self.LastVolume then return end
if math.abs(Pitch - self.LastPitch) < 1 then return end -- Don't bother updating if the pitch difference is too small to notice

self.LastPitch = Pitch
self.LastVolume = Volume

if self.Sound then
Sounds.SendAdjustableSound(self, false, Pitch, Volume)
Expand All @@ -616,8 +616,7 @@ function ENT:DestroySound()
Sounds.SendAdjustableSound(self, true)

self.LastSound = nil
self.LastPitch = nil
self.LastVolume = nil
self.LastPitch = 0
self.Sound = nil
end

Expand Down

0 comments on commit 1cb2770

Please sign in to comment.