Skip to content
Merged
Changes from 6 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
67 changes: 42 additions & 25 deletions lua/wire/client/cl_wirelib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand All @@ -50,54 +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

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 = shouldblink and ent_GetNWString(ent, "BlinkWire")
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)
Expand All @@ -112,8 +123,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 +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)
Expand Down
Loading