Skip to content

Commit

Permalink
Fixed: Wired connections being skipped on paste
Browse files Browse the repository at this point in the history
Fixed: Client type not being the same as server datatype
Added: Parallel focus margin for easy lens behavior
Added: Custom Override for EntityCopy/EntityPaste/ApplyDupeInfo
Removed: Code repetition for EntityCopy/EntityPaste/ApplyDupeInfo
  • Loading branch information
dvdvideo1234 committed Sep 24, 2023
1 parent f18e3ee commit 54c779f
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 54 deletions.
29 changes: 23 additions & 6 deletions lua/autorun/laserlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1147,11 +1147,21 @@ function LaserLib.Configure(unit)
unit.meOrderInfo = nil; gtUNITS[uas] = true
-- Instance specific configuration
if(SERVER) then -- Do server configuration finalizer
if(unit.WireRemove) then function unit:OnRemove() self:WireRemove() end end
if(unit.WireRestored) then function unit:OnRestore() self:WireRestored() end end
if(unit.WirePreEntityCopy) then function unit:PreEntityCopy() self:WirePreEntityCopy() end end
if(unit.WirePostEntityPaste) then function unit:PostEntityPaste(ply, ent, created) self:WirePreEntityCopy(ply, ent, created) end end
if(unit.WireApplyDupeInfo) then function unit:ApplyDupeInfo(ply, ent, info, fentid) self:WirePreEntityCopy(ply, ent, info, fentid) end end
if(unit.OverrideOnRemove) then
function unit:OnRemove() self:OverrideOnRemove() end
else function unit:OnRemove() self:WireRemove() end end
if(unit.OverrideOnRestore) then
function unit:OnRemove() self:OverrideOnRestore() end
else function unit:OnRestore() self:WireRestored() end end
if(unit.OverridePreEntityCopy) then
function unit:PreEntityCopy() self:OverridePreEntityCopy() end
else function unit:PreEntityCopy() self:WirePreEntityCopy() end end
if(unit.OverridePostEntityPaste) then
function unit:PostEntityPaste(ply, ent, cre) self:OverridePostEntityPaste(ply, ent, cre) end
else function unit:PostEntityPaste(ply, ent, cre) self:WirePostEntityPaste(ply, ent, cre) end end
if(unit.OverrideApplyDupeInfo) then
function unit:ApplyDupeInfo(ply, ent, info, feid) self:OverrideApplyDupeInfo(ply, ent, info, feid) end
else function unit:ApplyDupeInfo(ply, ent, info, feid) self:WireApplyDupeInfo(ply, ent, info, feid) end end
else -- Do client configuration finalizer
language.Add(uas, unit.Information)
if(uas ~= cas) then -- Setup the same kill icon
Expand Down Expand Up @@ -3907,10 +3917,17 @@ local gtACTORS = {
local bdot, mdot = ent:GetHitPower(norm, beam, trace, bmln)
if(trace and trace.Hit and beam and bdot) then
beam.IsTrace = true -- Beam hits correct surface. Continue
local focu = ent:GetFocus() -- Apply custom focus
local vdot = (ent:GetBeamDimmer() and mdot or 1)
local node = beam:SetPowerRatio(vdot) -- May absorb
beam.VrOrigin:Set(trace.HitPos)
beam.VrDirect:Set(trace.HitNormal); beam.VrDirect:Negate()
if(focu == 0) then
beam.VrDirect:Set(trace.HitNormal); beam.VrDirect:Negate()
else
local obb = ent:LocalToWorld(ent:OBBCenter())
local odv = Vector(obb); odv:Sub(trace.HitPos)
odv:Mul(focu); beam.VrDirect:Add(odv)
end
beam:SetActor(ent) -- Makes beam pass the dimmer
end
end,
Expand Down
12 changes: 0 additions & 12 deletions lua/entities/gmod_laser/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ local cvMXBMLENG = LaserLib.GetData("MXBMLENG")
local cvMXBMDAMG = LaserLib.GetData("MXBMDAMG")
local cvMXBMFORC = LaserLib.GetData("MXBMFORC")

function ENT:PreEntityCopy()
self:WirePreEntityCopy()
end

function ENT:PostEntityPaste(ply, ent, cre)
self:WirePostEntityPaste(ply, ent, cre)
end

function ENT:ApplyDupeInfo(ply, ent, info, fentid)
self:WireApplyDupeInfo(ply, ent, info, fentid)
end

function ENT:Initialize()
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/gmod_laser/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function ENT:GetBeamSafety()
return safe
else
local safe = self:GetInBeamSafety()
return self:GetNWFloat("GetInBeamSafety", safe)
return self:GetNWBool("GetInBeamSafety", safe)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/entities/gmod_laser_dimmer/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function ENT:GetHitNormal()
return normal
else
local normal = self:GetNormalLocal()
return self:GetNWFloat("GetNormalLocal", normal)
return self:GetNWVector("GetNormalLocal", normal)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/entities/gmod_laser_divider/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function ENT:GetHitNormal()
return normal
else
local normal = self:GetNormalLocal()
return self:GetNWFloat("GetNormalLocal", normal)
return self:GetNWVector("GetNormalLocal", normal)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/entities/gmod_laser_filter/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function ENT:GetHitNormal()
return normal
else
local normal = self:GetNormalLocal()
return self:GetNWFloat("GetNormalLocal", normal)
return self:GetNWVector("GetNormalLocal", normal)
end
end

Expand Down
5 changes: 4 additions & 1 deletion lua/entities/gmod_laser_parallel/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ function ENT:Initialize()
self:SetMoveType(MOVETYPE_VPHYSICS)

self:WireCreateInputs(
{"Normal", "VECTOR", "Parallel surface normal"}
{"Normal", "VECTOR", "Parallel surface normal"},
{"Focus" , "NORMAL", "Parallel focus margin" }
):WireCreateOutputs(
{"Normal", "VECTOR", "Parallel surface normal"},
{"Focus" , "NORMAL", "Parallel focus margin" },
{"Entity", "ENTITY", "Parallel entity itself" }
)

self:SetFocusMargin(0)
self:SetBeamDimmer(false)

local phys = self:GetPhysicsObject()
Expand Down
22 changes: 18 additions & 4 deletions lua/entities/gmod_laser_parallel/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function ENT:SetupDataTables()
self:EditableSetVector("NormalLocal", "General") -- Used as forward
self:EditableSetBool ("BeamDimmer" , "General")
self:EditableSetBool ("LinearMapping", "General")
self:EditableSetBool ("InPowerOn" , "Internals")
self:EditableSetFloat ("FocusMargin" , "General", -1, 1)
LaserLib.Configure(self)
end

Expand All @@ -49,13 +49,27 @@ function ENT:GetHitNormal()
return normal
else
local normal = self:GetNormalLocal()
return self:GetNWFloat("GetNormalLocal", normal)
return self:GetNWVector("GetNormalLocal", normal)
end
end

function ENT:GetFocus()
if(SERVER) then
local focus = self:WireRead("Focus", true)
if(not focus) then
focus = self:GetFocusMargin()
end -- Make sure length is one unit
self:SetNWFloat("GetFocusMargin", focus)
self:WireWrite("Focus", focus)
return focus
else
local focus = self:GetFocusMargin()
return self:GetNWFloat("GetFocusMargin", normal)
end
end

function ENT:GetHitPower(normal, beam, trace, bmln)
local norm = Vector(normal)
norm:Rotate(self:GetAngles())
local norm = Vector(normal); norm:Rotate(self:GetAngles())
local dotv = math.abs(norm:Dot(beam.VrDirect))
if(bmln) then dotv = 2 * math.asin(dotv) / math.pi end
local dott = math.abs(norm:Dot(trace.HitNormal))
Expand Down
18 changes: 5 additions & 13 deletions lua/entities/gmod_laser_portal/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ include("shared.lua")

resource.AddFile("materials/vgui/entities/gmod_laser_portal.vmt")

function ENT:PreEntityCopy()
self:WirePreEntityCopy()
end

function ENT:PostEntityPaste(ply, ent, created)
self:WirePostEntityPaste(ply, ent, created)
function ENT:OverridePostEntityPaste(ply, ent, cre)
self:WirePostEntityPaste(ply, ent, cre)
local idx = (tonumber(self:GetEntityExitID()) or 0)
local ent = created[idx]; self:SetEntityExitID(0)
if(not self:IsTrueExit(ent)) then return end
self:SetEntityExitID(tostring(ent:EntIndex()))
end

function ENT:ApplyDupeInfo(ply, ent, info, fentid)
self:WireApplyDupeInfo(ply, ent, info, fentid)
local out = cre[idx]; self:SetEntityExitID(0)
if(not self:IsTrueExit(out)) then return end
self:SetEntityExitID(tostring(out:EntIndex()))
end

function ENT:Initialize()
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/gmod_laser_rdivider/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function ENT:GetHitNormal()
return normal
else
local normal = self:GetNormalLocal()
return self:GetNWFloat("GetNormalLocal", normal)
return self:GetNWVector("GetNormalLocal", normal)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lua/entities/gmod_laser_sensor/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function ENT:GetUnitDirection()
return norm
else
local norm = self:GetDirectLocal()
return self:GetNWFloat("GetDirectLocal", norm)
return self:GetNWVector("GetDirectLocal", norm)
end
end

Expand All @@ -55,7 +55,7 @@ function ENT:GetUnitOrigin()
return opos
else
local opos = self:GetOriginLocal()
return self:GetNWFloat("GetOriginLocal", opos)
return self:GetNWVector("GetOriginLocal", opos)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/entities/gmod_laser_splitterm/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function ENT:GetHitNormal()
return normal
else
local normal = self:GetNormalLocal()
return self:GetNWFloat("GetNormalLocal", normal)
return self:GetNWVector("GetNormalLocal", normal)
end
end

Expand Down
20 changes: 10 additions & 10 deletions lua/laseremitter/wire_wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ end
--[[
* Procedure. Applies duplicator needed wire information
* Does not return anything. It is prcedure
* ply > Player to store the info for
* ent > Entity to store the info for
* info > Information table to apply
* fentid > Pointer to function retrieving entity by ID
* Usage: function ENT:ApplyDupeInfo(ply, ent, info, fentid)
self:WireApplyDupeInfo(ply, ent, info, fentid) end
* ply > Player to store the info for
* ent > Entity to store the info for
* info > Information table to apply
* feid > Pointer to function retrieving entity by ID
* Usage: function ENT:ApplyDupeInfo(ply, ent, info, feid)
self:WireApplyDupeInfo(ply, ent, info, feid) end
]]
function ENT:WireApplyDupeInfo(ply, ent, info, fentid)
function ENT:WireApplyDupeInfo(ply, ent, info, feid)
if(not WireLib) then return self end
WireLib.ApplyDupeInfo(ply, ent, info, fentid)
WireLib.ApplyDupeInfo(ply, ent, info, feid)
return self
end

Expand All @@ -185,8 +185,8 @@ end
--[[
* Procedure. Must be run inside `ENT:PostEntityPaste`
* Makes wire do the post-paste preparation for dupe info
* Usage: function ENT:PostEntityPaste(player, entity, created)
self:WirePostEntityPaste(player, entity, created) end
* Usage: function ENT:PostEntityPaste(ply, ent, cre)
self:WirePostEntityPaste(ply, ent, cre) end
* ply > The player calling the routune
* ent > The entity being post-pasted
* cre > The created entities list after paste
Expand Down

0 comments on commit 54c779f

Please sign in to comment.