Skip to content

Commit

Permalink
Use regular networking for turret info
Browse files Browse the repository at this point in the history
This sends a much smaller amount of data compared to packing everything into a JSON string
  • Loading branch information
thecraftianman committed Feb 14, 2025
1 parent aaebd23 commit 0acc973
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 8 additions & 1 deletion lua/entities/acf_turret/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ do -- NET SURFER
net.Receive("ACF_RequestTurretInfo", function()
local Entity = net.ReadEntity()
local Rotator = net.ReadEntity()
local Data = util.JSONToTable(net.ReadString())
local Data = {
LocalCoM = net.ReadVector(),
Mass = net.ReadFloat(),
MinDeg = net.ReadFloat(),
MaxDeg = net.ReadFloat(),
CoMDist = net.ReadFloat(),
Type = net.ReadString()
}

if not IsValid(Entity) then return end

Expand Down
9 changes: 6 additions & 3 deletions lua/entities/acf_turret/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,15 @@ do -- Spawn and Update funcs
Type = Entity.Turret
}

local DataString = util.TableToJSON(Data)

net.Start("ACF_RequestTurretInfo")
net.WriteEntity(Entity)
net.WriteEntity(Entity.Rotator)
net.WriteString(DataString)
net.WriteVector(Data.LocalCoM)
net.WriteFloat(Data.Mass)
net.WriteFloat(Data.MinDeg)
net.WriteFloat(Data.MaxDeg)
net.WriteFloat(Data.CoMDist)
net.WriteString(Data.Type)
net.Send(Player)
end
end)
Expand Down

0 comments on commit 0acc973

Please sign in to comment.