mirror of
https://github.com/wiremod/wire.git
synced 2025-03-04 03:03:04 -05:00
Micro-optimizations for base_wire_entity (#3192)
* base_wire_entity optimizations * Do not create new vectors * table.IsEmpty -> halos[1] == nil Co-authored-by: thegrb93 <grbrown93@sbcglobal.net> * Revert some changes --------- Co-authored-by: thegrb93 <grbrown93@sbcglobal.net>
This commit is contained in:
parent
831bc00035
commit
a722233f1a
@ -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)
|
||||
@ -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 )
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
@ -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)
|
||||
@ -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
|
||||
local tab = self:GetTable()
|
||||
local color = self:GetColor()
|
||||
|
||||
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))
|
||||
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…
Reference in New Issue
Block a user