Skip to content

Commit

Permalink
Fixed: Laser draw beam method stops getting called when player looks …
Browse files Browse the repository at this point in the history
…away

Updated: Typos for some convar and more fail-safe when drawing beams
Removed: Beam draw queue and registration routine via beam method
Removed: Beam draw queue hook needed for processing registered draws
Removed: Laser testing methods `DrawBeamOn` and `DrawBeamOff`
Updated: readme.md and known behavior tube refraction
  • Loading branch information
dvdvideo1234 committed Jul 26, 2022
1 parent 9d11f48 commit 0bcfe86
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 56 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 6 additions & 34 deletions lua/autorun/laserlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ DATA.NSPLITER = CreateConVar(DATA.TOOL.."_nspliter", 2, DATA.FGSRVCN, "Controls
DATA.XSPLITER = CreateConVar(DATA.TOOL.."_xspliter", 1, DATA.FGSRVCN, "Controls the default splitter X direction", 0, 1)
DATA.YSPLITER = CreateConVar(DATA.TOOL.."_yspliter", 1, DATA.FGSRVCN, "Controls the default splitter Y direction", 0, 1)
DATA.EFFECTDT = CreateConVar(DATA.TOOL.."_effectdt", 0.15, DATA.FGINDCN, "Controls the time between effect drawing", 0, 5)
DATA.ENSOUNDS = CreateConVar(DATA.TOOL.."_ensounds", 1, DATA.FGSRVCN, "Trigger this to enable or disable redirector sounds")
DATA.ENSOUNDS = CreateConVar(DATA.TOOL.."_ensounds", 1, DATA.FGSRVCN, "Trigger this to enable or disable redirecton sounds")
DATA.LNDIRACT = CreateConVar(DATA.TOOL.."_lndiract", 20, DATA.FGINDCN, "How long will the direction of output beams be rendered", 0, 50)
DATA.DAMAGEDT = CreateConVar(DATA.TOOL.."_damagedt", 0.1, DATA.FGSRVCN, "The time frame to pass between the beam damage cycles", 0, 10)
DATA.DRWBMSPD = CreateConVar(DATA.TOOL.."_drwbmspd", 8, DATA.FGINDCN, "The speed used to render the beam in the main routine", 0, 16)
Expand Down Expand Up @@ -287,8 +287,6 @@ local gtTRACE = {
output = nil
}

local gtBEAMDRAW = {}

if(CLIENT) then
DATA.TAHD = TEXT_ALIGN_CENTER
DATA.KILL = "vgui/entities/gmod_laser_killicon"
Expand Down Expand Up @@ -2147,27 +2145,6 @@ local function Beam(origin, direct, width, damage, length, force)
return self
end

--[[
* Registers the benm to be drawn in the dedicated `drawbeam` routine
* Arguments are the same as beam:Draw(...). Submits beams for drawing
* This is equivalent to a push operation with beams as keys
]]
function mtBeam:SetDraw(sours, imatr, color)
local arg = {sours, imatr, color}
gtBEAMDRAW[self] = arg; return self
end

--[[
* Returns the arguments the beam was submitted for drawing with
* This is equvalent to a pop operation with a beams as keys
* rem > Force remove the beam entry from the queue
]]
function mtBeam:GetDraw(rem)
local arg = gtBEAMDRAW[self]
if(rem) then gtBEAMDRAW[self] = nil end
return arg
end

--[[
* Returns the desired nore information
* index > Node index to be used. Defaults to node size
Expand Down Expand Up @@ -2880,9 +2857,11 @@ function mtBeam:Draw(sours, imatr, color)
if(SERVER) then return self end
local tvpnt = self.TvPoints
-- Check node availability
if(not tvpnt) then return self end
if(not tvpnt[1]) then return self end
if(not tvpnt.Size) then return self end
if(tvpnt.Size <= 0) then return self end
local szv = tvpnt.Size -- Vertex size
if(not szv) then return self end
if(szv <= 0) then return self end
-- Update rendering boundaries
local sours = (sours or self.BmSource)
local ushit = LocalPlayer():GetEyeTrace().HitPos
Expand All @@ -2901,7 +2880,7 @@ function mtBeam:Draw(sours, imatr, color)
local cup = (color or self.BmColor)
local spd = DATA.DRWBMSPD:GetFloat()
-- Draw the beam sequentially being faster
for idx = 2, tvpnt.Size do
for idx = 2, szv do
local org = tvpnt[idx - 1]
local new = tvpnt[idx - 0]
local ntx, otx = new[1], org[1] -- Read origin
Expand Down Expand Up @@ -3758,13 +3737,6 @@ end

if(CLIENT) then
-- https://wiki.facepunch.com/gmod/3D_Rendering_Hooks
hook.Add("PreDrawEffects", DATA.TOOL.."_drawbeam", function()
for beam, args in pairs(gtBEAMDRAW) do
beam:Draw(args[1], args[2], args[3])
gtBEAMDRAW[beam] = nil
end
end)

hook.Add("PostDrawHUD", DATA.TOOL.."_grab_draw", -- Physgun draw beam assist
function() -- Handles drawing the assist when user holds laser unit
local ply = LocalPlayer(); if(not LaserLib.IsValid(ply)) then return end
Expand Down
43 changes: 22 additions & 21 deletions lua/entities/gmod_laser/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,33 @@ function ENT:DrawBeam()
self:DrawEndingEffect(beam, trace)
end

function ENT:DrawBeamOn()
local width = self:GetBeamWidth()
width = LaserLib.GetWidth(width)
local length = self:GetBeamLength()
if(width > 0 and length > 0) then
self:UpdateFlags()
self:DrawBeam()
end
end

function ENT:DrawBeamOff()
local color = LaserLib.GetColor("YELLOW")
local lndir = LaserLib.GetData("LNDIRACT"):GetFloat()
local origin = self:GetBeamOrigin()
local direct = self:GetBeamDirection()
direct:Mul(lndir); direct:Add(origin)
render.DrawLine(origin, direct, color)
end

function ENT:Draw()
self:DrawModel()
self:DrawShadow(false)

if(self:GetOn()) then
self:DrawBeamOn()
local width = self:GetBeamWidth()
width = LaserLib.GetWidth(width)
local length = self:GetBeamLength()
if(width > 0 and length > 0) then
self:UpdateFlags()
self:DrawBeam()
end
else
self:DrawBeamOff()
local color = LaserLib.GetColor("YELLOW")
local lndir = LaserLib.GetData("LNDIRACT"):GetFloat()
local origin = self:GetBeamOrigin()
local direct = self:GetBeamDirection()
direct:Mul(lndir); direct:Add(origin)
render.DrawLine(origin, direct, color)
end
end

--[[
* The think method is not needed in general
* but it is defined empty because otherwise
* the draw method will not get called when
* the player is not looking at the entity
]]
function ENT:Think()
end
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ version anymore. This was the only way I could support the things I needed the m
3. [Refract][ref-refract-pic] beam traces via hit surface material override
4. Calculate [full internal reflection][ref-total-reflect] according to [medium boundary][ref-boundary]
5. Code base and updates in tone with [Garry's mod 13][ref-gmod-link]
6. Supports [wire][ref-wire] and every element supports advanced duplicator 1 and 2
6. Supports [wire][ref-wire] and every element supports advanced duplicator [1][ref-adv-dupe1] and [2][ref-adv-dupe2]
7. [Wire inputs][ref-wire] override internals when connected
8. Internal [wire wrapper][ref-wire-wrap] taking care of the wire interface
9. Surface [reflection][ref-reflect] and medium [refraction][ref-refract] power [absorption][ref-reflect-rate]
Expand Down Expand Up @@ -81,3 +81,5 @@ I am a fan of this tool, so any help I get will be appreciated.
[ref-git-pr]: https://github.com/dvdvideo1234/LaserSTool/pulls
[ref-ws-publish]: https://github.com/dvdvideo1234/LaserSTool/blob/main/workshop_publish.bat
[ref-exp-irl]: https://www.grammarly.com/blog/irl-meaning/
[ref-adv-dupe1]: https://github.com/wiremod/advduplicator
[ref-adv-dupe2]: https://github.com/wiremod/advdupe2

0 comments on commit 0bcfe86

Please sign in to comment.