From 5653821e5fd151d5af5601c44dadab60b540cebe Mon Sep 17 00:00:00 2001 From: thegrb93 Date: Wed, 15 Apr 2026 14:08:09 -0400 Subject: [PATCH 01/10] Wire_Render performance improvement --- lua/wire/client/cl_wirelib.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index b4ead82cb1..4e5764e56a 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -10,7 +10,6 @@ local Wire_DisableWireRender = CreateClientConVar("cl_wire_disablewirerender", 0 WIRE_CLIENT_INSTALLED = 1 - BeamMat = Material("tripmine_laser") BeamMatHR = Material("Models/effects/comball_tape") @@ -25,6 +24,8 @@ local render_EndBeam = render.EndBeam local render_DrawBeam = render.DrawBeam local EntityMeta = FindMetaTable("Entity") local IsValid = EntityMeta.IsValid +local ent_GetTable = EntityMeta.GetTable +local ent_GetNWString = EntityMeta.GetNWString local ent_WorldToLocal = EntityMeta.WorldToLocal local ent_LocalToWorld = EntityMeta.LocalToWorld local Vector = Vector @@ -55,13 +56,13 @@ local function getmat( mat ) return mats_cache[ mat ] end -function Wire_Render(ent) - if Wire_DisableWireRender:GetBool() then return end --We shouldn't render anything - if not IsValid(ent) then return end +local function Wire_Render_Enabled(ent) + local ent_tbl = Ent_GetTable(ent) + if ent_tbl == nil then return end - local wires = ent.WirePaths + local wires = ent_tbl.WirePaths if not wires then - ent.WirePaths = {} + ent_tbl.WirePaths = {} net.Start("WireLib.Paths.RequestPaths") net.WriteEntity(ent) net.SendToServer() @@ -70,7 +71,7 @@ function Wire_Render(ent) if not next(wires) then return end - local blink = shouldblink and ent:GetNWString("BlinkWire") + local blink = shouldblink and ent_GetNWString(ent, "BlinkWire") --CREATING (Not assigning a value) local variables OUTSIDE of cycle a bit faster local start, color, nodes, len, endpos, node, node_ent, last_node_ent, vector_cache for net_name, wiretbl in pairs(wires) do @@ -111,6 +112,10 @@ function Wire_Render(ent) end end end +Wire_Render = Wire_Render_Enabled +cvars.AddChangeCallback("cl_wire_disablewirerender", function(_, _, new) + Wire_Render = tobool(new) and Wire_Render_Enabled or function() end +end) local function Wire_GetWireRenderBounds(ent) local tab = ent:GetTable() From c83c63c0d42b919f5dfde1f105915e98ed151995 Mon Sep 17 00:00:00 2001 From: thegrb93 Date: Wed, 15 Apr 2026 14:12:32 -0400 Subject: [PATCH 02/10] Fix initial setting of func --- lua/wire/client/cl_wirelib.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index 4e5764e56a..0ce2487c1a 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -112,10 +112,11 @@ local function Wire_Render_Enabled(ent) end end end -Wire_Render = Wire_Render_Enabled -cvars.AddChangeCallback("cl_wire_disablewirerender", function(_, _, new) - Wire_Render = tobool(new) and Wire_Render_Enabled or function() end -end) +local function Set_Disable_Wire_Render(_, _, val) + Wire_Render = tobool(val) and (function() end) or Wire_Render_Enabled +end +Set_Disable_Wire_Render(nil,nil,GetConvarNumber("cl_wire_disablewirerender")) +cvars.AddChangeCallback("cl_wire_disablewirerender", Set_Disable_Wire_Render) local function Wire_GetWireRenderBounds(ent) local tab = ent:GetTable() From 041c5f08ee1d66a458374b228e123bc97616af9d Mon Sep 17 00:00:00 2001 From: thegrb93 Date: Wed, 15 Apr 2026 14:18:20 -0400 Subject: [PATCH 03/10] Update cl_wirelib.lua --- lua/wire/client/cl_wirelib.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index 0ce2487c1a..809d06342d 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -58,7 +58,6 @@ end local function Wire_Render_Enabled(ent) local ent_tbl = Ent_GetTable(ent) - if ent_tbl == nil then return end local wires = ent_tbl.WirePaths if not wires then @@ -115,7 +114,7 @@ end local function Set_Disable_Wire_Render(_, _, val) Wire_Render = tobool(val) and (function() end) or Wire_Render_Enabled end -Set_Disable_Wire_Render(nil,nil,GetConvarNumber("cl_wire_disablewirerender")) +Set_Disable_Wire_Render(nil, nil, Wire_DisableWireRender:GetBool()) cvars.AddChangeCallback("cl_wire_disablewirerender", Set_Disable_Wire_Render) local function Wire_GetWireRenderBounds(ent) From 4944779cce3d2e7fdad1d0e15a791d3261f07e8d Mon Sep 17 00:00:00 2001 From: thegrb93 Date: Wed, 15 Apr 2026 14:52:50 -0400 Subject: [PATCH 04/10] Fix typo --- lua/wire/client/cl_wirelib.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index 809d06342d..c80eea164a 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -57,7 +57,7 @@ local function getmat( mat ) end local function Wire_Render_Enabled(ent) - local ent_tbl = Ent_GetTable(ent) + local ent_tbl = ent_GetTable(ent) local wires = ent_tbl.WirePaths if not wires then From 078a9484cbd1f0df74a7c2da51c222cf22e054be Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Wed, 15 Apr 2026 21:58:24 +0300 Subject: [PATCH 05/10] Some more additional optimizations + code styling --- lua/wire/client/cl_wirelib.lua | 50 +++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index c80eea164a..15100ea655 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -51,53 +51,64 @@ hook.Add("EntityRemoved", "WireLib_Node_Cache_Cleanup", function(ent) end) local mats_cache = {} -- nothing else uses this, it doesn't need to be global -local function getmat( mat ) - if not mats_cache[ mat ] then mats_cache[ mat ] = Material(mat) end --Just not to create a material every frame - return mats_cache[ mat ] + +local function getmat(mat) + local cached_mat = mats_cache[mat] + + if not cached_mat then + cached_mat = Material(mat) -- Just not to create a material every frame + mats_cache[mat] = cached_mat + end + + return cached_mat end local function Wire_Render_Enabled(ent) local ent_tbl = ent_GetTable(ent) - local wires = ent_tbl.WirePaths + if not wires then ent_tbl.WirePaths = {} + net.Start("WireLib.Paths.RequestPaths") - net.WriteEntity(ent) + net.WriteEntity(ent) net.SendToServer() + return end - if not next(wires) then return end - + -- CREATING (Not assigning a value) local variables OUTSIDE of cycle a bit faster local blink = shouldblink and ent_GetNWString(ent, "BlinkWire") - --CREATING (Not assigning a value) local variables OUTSIDE of cycle a bit faster local start, color, nodes, len, endpos, node, node_ent, last_node_ent, vector_cache - for net_name, wiretbl in pairs(wires) do + for net_name, wiretbl in pairs(wires) do width = wiretbl.Width if width > 0 and blink ~= net_name then - last_node_ent = ent - vector_cache = nodeTransformer(ent) - start = vector_cache[wiretbl.StartPos] - color = wiretbl.Color nodes = wiretbl.Path - scroll = scroll_offset len = #nodes + if len > 0 then - render_SetMaterial( getmat(wiretbl.Material) ) --Maybe every wire addon should precache it's materials on setup? + last_node_ent = ent + vector_cache = nodeTransformer(ent) + start = vector_cache[wiretbl.StartPos] + color = wiretbl.Color + scroll = scroll_offset + + render_SetMaterial(getmat(wiretbl.Material)) -- Maybe every wire addon should precache it's materials on setup? render_StartBeam(len * 2 + 1) render_AddBeam(start, width, scroll, color) - for j=1, len do + for j = 1, len do node = nodes[j] node_ent = node.Entity - if IsValid( node_ent ) then + + if IsValid(node_ent) then if node_ent ~= last_node_ent then last_node_ent = node_ent vector_cache = nodeTransformer(node_ent) end + endpos = vector_cache[node.Pos] scroll = scroll + endpos:Distance(start) / 10 render_AddBeam(endpos, width, scroll, color) @@ -111,14 +122,16 @@ local function Wire_Render_Enabled(ent) end end end + local function Set_Disable_Wire_Render(_, _, val) Wire_Render = tobool(val) and (function() end) or Wire_Render_Enabled end + Set_Disable_Wire_Render(nil, nil, Wire_DisableWireRender:GetBool()) cvars.AddChangeCallback("cl_wire_disablewirerender", Set_Disable_Wire_Render) local function Wire_GetWireRenderBounds(ent) - local tab = ent:GetTable() + local tab = ent_GetTable(ent) local bbmin, bbmax = ent:OBBMins(), ent:OBBMaxs() local minx, miny, minz = bbmin:Unpack() local maxx, maxy, maxz = bbmax:Unpack() @@ -167,7 +180,6 @@ function Wire_UpdateRenderBounds(ent) ent:SetRenderBounds(Wire_GetWireRenderBounds(ent)) end - function Wire_DrawTracerBeam( ent, beam_num, hilight, beam_length ) local entsTbl = EntityMeta.GetTable( ent ) local beam_length = beam_length or entsTbl.GetBeamLength(ent, beam_num) From 6ccd6d81eeee46ead546ecf02e94ee5e64e40b47 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Wed, 15 Apr 2026 22:00:15 +0300 Subject: [PATCH 06/10] Lint pass --- lua/wire/client/cl_wirelib.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index 15100ea655..b9290b0426 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -124,7 +124,7 @@ local function Wire_Render_Enabled(ent) end local function Set_Disable_Wire_Render(_, _, val) - Wire_Render = tobool(val) and (function() end) or Wire_Render_Enabled + Wire_Render = tobool(val) and function() end or Wire_Render_Enabled end Set_Disable_Wire_Render(nil, nil, Wire_DisableWireRender:GetBool()) From e7396938d8eec96df5534ceb2dfbfafaa9733c1f Mon Sep 17 00:00:00 2001 From: thegrb93 Date: Wed, 15 Apr 2026 15:16:46 -0400 Subject: [PATCH 07/10] Replace blink timer --- lua/wire/client/cl_wirelib.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index b9290b0426..2d6b2a2d7b 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -4,7 +4,7 @@ Renders beams --]]---------------------------------------------------------- local WIRE_SCROLL_SPEED = 0.5 -local WIRE_BLINKS_PER_SECOND = 2 +local WIRE_SECONDS_PER_BLINK = 0.5 local Wire_DisableWireRender = CreateClientConVar("cl_wire_disablewirerender", 0, true, false) WIRE_CLIENT_INSTALLED = 1 @@ -13,7 +13,7 @@ WIRE_CLIENT_INSTALLED = 1 BeamMat = Material("tripmine_laser") BeamMatHR = Material("Models/effects/comball_tape") -local scroll, scroll_offset, shouldblink = 0, 0, false +local scroll, scroll_offset = 0, 0 --Precache everything we're going to use local CurTime = CurTime @@ -34,10 +34,6 @@ hook.Add("Think", "Wire.WireScroll", function() scroll_offset = CurTime() * WIRE_SCROLL_SPEED end ) -timer.Create("Wire.WireBlink", 1 / WIRE_BLINKS_PER_SECOND, 0, function() -- there's no reason this needs to be in the render hook, no? - shouldblink = not shouldblink -end) - local nodeTransformer = WireLib.GetComputeIfEntityTransformDirty(function(ent) return setmetatable({}, {__index = function(t, k) local transformed = ent_LocalToWorld(ent, k) @@ -78,7 +74,7 @@ local function Wire_Render_Enabled(ent) end -- CREATING (Not assigning a value) local variables OUTSIDE of cycle a bit faster - local blink = shouldblink and ent_GetNWString(ent, "BlinkWire") + local blink = ent_GetNWString(ent, "BlinkWire") and (CurTime()%WIRE_SECONDS_PER_BLINK)/WIRE_SECONDS_PER_BLINK < 0.5 local start, color, nodes, len, endpos, node, node_ent, last_node_ent, vector_cache for net_name, wiretbl in pairs(wires) do From 29e5bf43a254a0db97bcf851c17a3691ad1fec81 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Wed, 15 Apr 2026 22:58:43 +0300 Subject: [PATCH 08/10] Don't use NW string for this --- lua/weapons/gmod_tool/stools/wire_adv.lua | 10 +++++----- lua/wire/client/cl_wirelib.lua | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_adv.lua b/lua/weapons/gmod_tool/stools/wire_adv.lua index 8b0cddf8db..1272cc31f7 100644 --- a/lua/weapons/gmod_tool/stools/wire_adv.lua +++ b/lua/weapons/gmod_tool/stools/wire_adv.lua @@ -346,8 +346,8 @@ elseif CLIENT then TOOL.ShowEntity = false -- bool for showing "Create Entity" output function TOOL:Holster() - if IsValid(self.CurrentEntity) then self.CurrentEntity:SetNWString("BlinkWire", "") end - if IsValid(self.AimingEnt) then self.AimingEnt:SetNWString("BlinkWire", "") end + if IsValid(self.CurrentEntity) then self.CurrentEntity.WireBlinkWire = nil end + if IsValid(self.AimingEnt) then self.AimingEnt.WireBlinkWire = nil end self.CurrentEntity = nil self.Wiring = {} self.WiringRender = {} @@ -761,7 +761,7 @@ elseif CLIENT then end if oldport ~= self.CurrentWireIndex then - ent:SetNWString("BlinkWire", check[self.CurrentWireIndex][1]) + ent.WireBlinkWire = check[self.CurrentWireIndex][1] self:GetOwner():EmitSound("weapons/pistol/pistol_empty.wav") end return true @@ -852,7 +852,7 @@ elseif CLIENT then -- Clear blinking wire if IsValid( self.AimingEnt ) then - self.AimingEnt:SetNWString("BlinkWire", "") + self.AimingEnt.WireBlinkWire = nil end if IsValid( ent ) then @@ -873,7 +873,7 @@ elseif CLIENT then -- Set blinking wire if check[self.CurrentWireIndex] then - ent:SetNWString("BlinkWire", check[self.CurrentWireIndex][1]) + ent.WireBlinkWire = check[self.CurrentWireIndex][1] end end end diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index 2d6b2a2d7b..f80b5d5fc7 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -25,7 +25,6 @@ local render_DrawBeam = render.DrawBeam local EntityMeta = FindMetaTable("Entity") local IsValid = EntityMeta.IsValid local ent_GetTable = EntityMeta.GetTable -local ent_GetNWString = EntityMeta.GetNWString local ent_WorldToLocal = EntityMeta.WorldToLocal local ent_LocalToWorld = EntityMeta.LocalToWorld local Vector = Vector @@ -74,7 +73,9 @@ local function Wire_Render_Enabled(ent) end -- CREATING (Not assigning a value) local variables OUTSIDE of cycle a bit faster - local blink = ent_GetNWString(ent, "BlinkWire") and (CurTime()%WIRE_SECONDS_PER_BLINK)/WIRE_SECONDS_PER_BLINK < 0.5 + local blink = ent_tbl.WireBlinkWire + if blink then blink = (CurTime() % WIRE_SECONDS_PER_BLINK) / WIRE_SECONDS_PER_BLINK < 0.5 and blink end + local start, color, nodes, len, endpos, node, node_ent, last_node_ent, vector_cache for net_name, wiretbl in pairs(wires) do From 48461555a14fd73fdf7d6318cc0c5bb210b88346 Mon Sep 17 00:00:00 2001 From: thegrb93 Date: Wed, 15 Apr 2026 16:01:46 -0400 Subject: [PATCH 09/10] Blink optimize --- lua/wire/client/cl_wirelib.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index f80b5d5fc7..c5066eab12 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -74,14 +74,12 @@ local function Wire_Render_Enabled(ent) -- CREATING (Not assigning a value) local variables OUTSIDE of cycle a bit faster local blink = ent_tbl.WireBlinkWire - if blink then blink = (CurTime() % WIRE_SECONDS_PER_BLINK) / WIRE_SECONDS_PER_BLINK < 0.5 and blink end - local start, color, nodes, len, endpos, node, node_ent, last_node_ent, vector_cache for net_name, wiretbl in pairs(wires) do width = wiretbl.Width - if width > 0 and blink ~= net_name then + if width > 0 and not (blink == net_name and (CurTime() % WIRE_SECONDS_PER_BLINK) / WIRE_SECONDS_PER_BLINK < 0.5) then nodes = wiretbl.Path len = #nodes From 1e72ed288a33963d993f0c9493d5d4a79dcef713 Mon Sep 17 00:00:00 2001 From: thegrb93 Date: Wed, 15 Apr 2026 16:05:10 -0400 Subject: [PATCH 10/10] Simplify --- lua/wire/client/cl_wirelib.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/wire/client/cl_wirelib.lua b/lua/wire/client/cl_wirelib.lua index c5066eab12..a8d6911841 100644 --- a/lua/wire/client/cl_wirelib.lua +++ b/lua/wire/client/cl_wirelib.lua @@ -79,7 +79,7 @@ local function Wire_Render_Enabled(ent) for net_name, wiretbl in pairs(wires) do width = wiretbl.Width - if width > 0 and not (blink == net_name and (CurTime() % WIRE_SECONDS_PER_BLINK) / WIRE_SECONDS_PER_BLINK < 0.5) then + if width > 0 and (blink ~= net_name or (CurTime() % WIRE_SECONDS_PER_BLINK) / WIRE_SECONDS_PER_BLINK < 0.5) then nodes = wiretbl.Path len = #nodes