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
10 changes: 5 additions & 5 deletions lua/weapons/gmod_tool/stools/wire_adv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
76 changes: 44 additions & 32 deletions lua/wire/client/cl_wirelib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
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



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
Expand All @@ -25,6 +24,7 @@ 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_WorldToLocal = EntityMeta.WorldToLocal
local ent_LocalToWorld = EntityMeta.LocalToWorld
local Vector = Vector
Expand All @@ -33,10 +33,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)
Expand All @@ -50,54 +46,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

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)
local wires = ent_tbl.WirePaths

local wires = ent.WirePaths
if not wires then
ent.WirePaths = {}
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
Comment thread
thegrb93 marked this conversation as resolved.

local blink = shouldblink and ent:GetNWString("BlinkWire")
--CREATING (Not assigning a value) local variables OUTSIDE of cycle a bit faster
-- CREATING (Not assigning a value) local variables OUTSIDE of cycle a bit faster
local blink = ent_tbl.WireBlinkWire
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
if width > 0 and (blink ~= net_name or (CurTime() % WIRE_SECONDS_PER_BLINK) / WIRE_SECONDS_PER_BLINK < 0.5) then
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)
Expand All @@ -112,8 +118,15 @@ function Wire_Render(ent)
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()
Expand Down Expand Up @@ -162,7 +175,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)
Expand Down
Loading