Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lua/weapons/gmod_tool/stools/wire_adv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ if SERVER then

for i=1,#wirings do
local wiring = wirings[i]
if not istable(wiring) then continue end

local nodes = wiring[4]
if not istable(nodes) or #nodes > 64 then continue end

local inputentity = wiring[3]
local outputentity = wiring[5]
Expand All @@ -161,9 +165,11 @@ if SERVER then
local inputname = wiring[1]
local inputpos = wiring[2]
if WireLib.Link_Start( uid, inputentity, inputpos, inputname, material, color, width ) then
for i=1,#wiring[4] do
local node = wiring[4][i]
WireLib.Link_Node( uid, node[1], node[2] )
for j=1,#nodes do
local node = nodes[j]
if istable(node) and isvector(node[2]) then
WireLib.Link_Node( uid, node[1], node[2] )
end
end
local outputpos = wiring[6]
local outputname = wiring[7]
Expand Down
26 changes: 20 additions & 6 deletions lua/wire/wire_paths.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ if CLIENT then
end

WireLib.Paths = {}
local transmit_queues = WireLib.RegisterPlayerTable(setmetatable({}, { __index = function(t,p) t[p] = {} return t[p] end }))
util.AddNetworkString("WireLib.Paths.RequestPaths")
util.AddNetworkString("WireLib.Paths.TransmitPath")

Expand Down Expand Up @@ -78,17 +77,31 @@ local function TransmitPath(input, ply)
net.Send(ply)
end

local transmit_queues = WireLib.RegisterPlayerTable(setmetatable({}, { __index = function(t, p) t[p] = {} return t[p] end }))
local queued = WireLib.RegisterPlayerTable(setmetatable({}, { __index = function(t, p) t[p] = {} return t[p] end }))

local function Enqueue(ply, input)
local set = queued[ply]
if set[input] then return end

set[input] = true
table.insert(transmit_queues[ply], input)
end

local function ProcessQueue()
for ply, queue in pairs(transmit_queues) do
if ply:IsValid() then
local nextinqueue = table.remove(queue, 1)
if nextinqueue then
queued[ply][nextinqueue] = nil
TransmitPath(nextinqueue, ply)
else
transmit_queues[ply] = nil
queued[ply] = nil
end
else
transmit_queues[ply] = nil
queued[ply] = nil
end
end
if not next(transmit_queues) then
Expand All @@ -97,14 +110,15 @@ local function ProcessQueue()
end

-- Add a path to every player's transmit queue
function WireLib.Paths.Add(input, ply)
if ply then
table.insert(transmit_queues[ply], input)
function WireLib.Paths.Add(input, add_ply)
if add_ply then
Enqueue(add_ply, input)
else
for _, player in player.Iterator() do
table.insert(transmit_queues[player], input)
for _, ply in player.Iterator() do
Enqueue(ply, input)
end
end

if not timer.Exists("WireLib.Paths.ProcessQueue") then
timer.Create("WireLib.Paths.ProcessQueue", 0, 0, ProcessQueue)
end
Expand Down
Loading