Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micro-optimizations for base_wire_entity #3192

Merged
merged 4 commits into from
Dec 3, 2024
Merged
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
50 changes: 29 additions & 21 deletions lua/entities/base_wire_entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ if CLIENT then
if pos == spos then -- if the position is right in your face, get a better position
pos = spos + localPly:GetAimVector() * 5
end

pos = pos:ToScreen()

pos.x = math.Round(pos.x)
Expand Down Expand Up @@ -117,14 +118,14 @@ if CLIENT then
}

render.CullMode(MATERIAL_CULLMODE_CCW)
surface.DrawPoly( poly )
surface.DrawPoly(poly)

surface.SetDrawColor(0, 0, 0, 255)

for i=1,#poly-1 do
for i = 1, 5 do
surface.DrawLine( poly[i].x, poly[i].y, poly[i+1].x, poly[i+1].y )
end
surface.DrawLine( poly[#poly].x, poly[#poly].y, poly[1].x, poly[1].y )
surface.DrawLine( poly[6].x, poly[6].y, poly[1].x, poly[1].y )
end

local function getWireName( ent )
Expand All @@ -142,7 +143,7 @@ if CLIENT then
-- This is overridable by other wire entities which want to customize the overlay
function ENT:DrawWorldTipBody( pos )
local data = self:GetOverlayData()
draw.DrawText( data.txt, "GModWorldtip", pos.center.x, pos.min.y + edgesize/2, Color(255,255,255,255), TEXT_ALIGN_CENTER )
draw.DrawText( data.txt, "GModWorldtip", pos.center.x, pos.min.y + edgesize/2, color_white, TEXT_ALIGN_CENTER )
end

-- This is overridable by other wire entities which want to customize the overlay
Expand Down Expand Up @@ -206,11 +207,11 @@ if CLIENT then
end

if info_requires_multiline then
draw.DrawText( class, "GModWorldtip", pos.center.x, offset + 8, Color(255,255,255,255), TEXT_ALIGN_CENTER )
draw.DrawText( name, "GModWorldtip", pos.center.x, offset + h_class + 16, Color(255,255,255,255), TEXT_ALIGN_CENTER )
draw.DrawText( class, "GModWorldtip", pos.center.x, offset + 8, color_white, TEXT_ALIGN_CENTER )
draw.DrawText( name, "GModWorldtip", pos.center.x, offset + h_class + 16, color_white, TEXT_ALIGN_CENTER )
else
draw.DrawText( class, "GModWorldtip", pos.min.x + edgesize, offset + 16, Color(255,255,255,255) )
draw.DrawText( name, "GModWorldtip", pos.min.x + pos.size.w - w_name - edgesize, offset + 16, Color(255,255,255,255) )
draw.DrawText( class, "GModWorldtip", pos.min.x + edgesize, offset + 16, color_white )
draw.DrawText( name, "GModWorldtip", pos.min.x + pos.size.w - w_name - edgesize, offset + 16, color_white )
end
end

Expand Down Expand Up @@ -282,12 +283,14 @@ if CLIENT then
end

function ENT:Think()
if (CurTime() >= (self.NextRBUpdate or 0)) then
local tab = self:GetTable()

if (CurTime() >= (tab.NextRBUpdate or 0)) then
-- We periodically update the render bounds every 10 seconds - the
-- reasons why are mostly anecdotal, but in some circumstances
-- entities might 'forget' their renderbounds. Nobody really knows
-- if this is still needed or not.
self.NextRBUpdate = CurTime() + 10
tab.NextRBUpdate = CurTime() + 10
Wire_UpdateRenderBounds(self)
end
end
Comment on lines 285 to 296
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to investigate if this is even needed code anymore

Expand All @@ -301,9 +304,11 @@ if CLIENT then
halos_inv[self] = true
end

local color_halo = Color(100, 100, 255)

hook.Add("PreDrawHalos", "Wiremod_overlay_halos", function()
if #halos == 0 then return end
halo.Add(halos, Color(100,100,255), 3, 3, 1, true, true)
if halos[1]==nil then return end
halo.Add(halos, color_halo, 3, 3, 1, true, true)
halos = {}
halos_inv = {}
end)
Expand Down Expand Up @@ -510,15 +515,18 @@ ENT.LINK_STATUS_DEACTIVATED = 2 -- alias
ENT.LINK_STATUS_ACTIVE = 3
ENT.LINK_STATUS_ACTIVATED = 3 -- alias
function ENT:ColorByLinkStatus(status)
local a = self:GetColor().a

if status == self.LINK_STATUS_UNLINKED then
self:SetColor(Color(255,0,0,a))
elseif status == self.LINK_STATUS_LINKED then
self:SetColor(Color(255,165,0,a))
elseif status == self.LINK_STATUS_ACTIVE then
self:SetColor(Color(0,255,0,a))
local tab = self:GetTable()
local color = self:GetColor()

if status == tab.LINK_STATUS_UNLINKED then
color.r, color.g, color.b = 255, 0, 0
elseif status == tab.LINK_STATUS_LINKED then
color.r, color.g, color.b = 255, 165, 0
elseif status == tab.LINK_STATUS_ACTIVE then
color.r, color.g, color.b = 0, 255, 0
else
self:SetColor(Color(255,255,255,a))
color.r, color.g, color.b = 255, 255, 255
end

self:SetColor(color)
end
Loading