Skip to content

Commit

Permalink
Reduce index calls on EGP:ValidEGP (wiremod#2962)
Browse files Browse the repository at this point in the history
* Reduce index calls

* Add IsEGP and adjust the ValidEGP function

* Use GetTableinstead of GetVar

* Use Entity.IsValid instead of _G.IsValid
  • Loading branch information
brandonsturgeon authored Jan 4, 2024
1 parent 762ee51 commit 857bb81
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions lua/entities/gmod_wire_egp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

ENT.IsEGP = true
ENT.WireDebugName = "E2 Graphics Processor"

function ENT:Initialize()
Expand Down
13 changes: 10 additions & 3 deletions lua/entities/gmod_wire_egp/lib/egplib/usefulfunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,15 @@ end
--------------------------------------------------------
-- Other
--------------------------------------------------------
function EGP:ValidEGP( Ent )
return IsValid( Ent ) and (Ent:GetClass() == "gmod_wire_egp" or Ent:GetClass() == "gmod_wire_egp_hud" or Ent:GetClass() == "gmod_wire_egp_emitter")
do
local EntMeta = FindMetaTable( "Entity" )
local IsValid = EntMeta.IsValid
local GetTable = EntMeta.GetTable

function EGP:ValidEGP( Ent )
if not IsValid( Ent ) then return false end
return GetTable( Ent ).IsEGP == true
end
end


Expand Down Expand Up @@ -507,4 +514,4 @@ function EGP.Draw(ent)
end
EGP:FixMaterial(oldtex)
end
end
end
3 changes: 2 additions & 1 deletion lua/entities/gmod_wire_egp_emitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ENT.PrintName = "Wire E2 Graphics Processor Emitter"
ENT.WireDebugName = "E2 Graphics Processor Emitter"
ENT.RenderGroup = RENDERGROUP_BOTH

ENT.IsEGP = true
ENT.gmod_wire_egp_emitter = true

local DrawOffsetPos = Vector(0, 0, 71)
Expand Down Expand Up @@ -174,4 +175,4 @@ if CLIENT then
end
end

function ENT:UpdateTransmitState() return TRANSMIT_ALWAYS end
function ENT:UpdateTransmitState() return TRANSMIT_ALWAYS end
1 change: 1 addition & 0 deletions lua/entities/gmod_wire_egp_hud/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include("huddraw.lua")

DEFINE_BASECLASS("base_wire_entity")

ENT.IsEGP = true
ENT.WireDebugName = "E2 Graphics Processor HUD"

util.AddNetworkString("EGP_HUD_Use")
Expand Down

0 comments on commit 857bb81

Please sign in to comment.