Skip to content

Commit

Permalink
Make single place to control E + SPAWN (#27)
Browse files Browse the repository at this point in the history
Fixed: Admins cannot remove players stuff
Fixed: Refraction in case water texture entry misses sequential source
Fixed: Surface world `SetSurfaceWorld` moved outside
Fixed: Tool HUD shows reflector info incorrectly
Fixed: Use beam general temporary trace output instead of `tr`
Fixed: Water surface finder not supporting filters
Fixed: `LaserLib.IsOther` returns the correct flag
Fixed: `LaserLib.RegisterUnit` is unneeded now
Added: Beam meta trace result
Added: Checker for non utilizable models `IsOther`
Added: Class registration and visual updates. Tested on crystal
Added: Class, model and material will be inserted on spawn
Added: Contents ID extractor to use refract table
Added: Contents to the sequential table keys
Added: Error message for invalid unit registration
Added: Laser unit proper initialization
Added: Library function `LaserLib.SetClass` and `LaserLib.IsOther`
Added: Reflector support `GetReflectInfo`
Added: Refraction reverse indexing for sequential
Added: Second argument to model and material to update cashe
Added: Sim for disabling values
Added: Some models for portal and portal 2
Added: Support for other mediums different than water
Added: Surface world added current contents argument
Added: Unique unit ID for every laser entity
Added: `SetWaterSurface`
Removed: 3-rd column (variable name extension) from units list
Removed: Dedicated library function `GeFolder`
Removed: Dedicated medium contents
Removed: Global material and model tables. Stored in gtUNITS
Removed: Passing laser unit ID to `SpawnFunction`
Removed: `LaserLib.GetUnit` as it is not needed anymore
Renamed: Library function `LaserLib.SetClass`
Renamed: Plane to surface ( water surface )
Renamed: Sone internal variables
Renamed: `LaserLib.SetClass` to `LaserLib.RegisterUnit`
Updated: Dedicated unit registration creating convars `RegisterUnit`
Updated: Material and models configure routine
Updated: Rearrange of data values and calls
Updated: Snap custom and normal to accept trace reference
Updated: Surface angle to do only one indexing
Updated: Trace entity model replace with `E`
Updated: Water direct to use temporary
Utilize: `SetWaterSurface` in some methods and cases
Factorize: Contents manager `SetRefractContent`
  • Loading branch information
dvdvideo1234 authored Aug 31, 2022
1 parent e554834 commit ca2a93f
Show file tree
Hide file tree
Showing 27 changed files with 447 additions and 400 deletions.
613 changes: 329 additions & 284 deletions lua/autorun/laserlib.lua

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lua/entities/gmod_laser/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ENT.Contact = "[email protected]"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_OPAQUE
ENT.UnitID = 1

local EFFECTDT = LaserLib.GetData("EFFECTDT")
local DAMAGEDT = LaserLib.GetData("DAMAGEDT")
Expand Down Expand Up @@ -235,7 +236,7 @@ function ENT:DoSound(state)
if(self.onState ~= state) then
self.onState = state -- Write the state
local pos, enb = self:GetPos(), LaserLib.GetData("ENSOUNDS")
local cls, mcs = self:GetClass(), LaserLib.GetClass(1, 1)
local cls, mcs = self:GetClass(), LaserLib.GetClass(1)
if(cls == mcs or enb:GetBool()) then
if(state) then -- Activating laser for given position
self:EmitSound(self:GetStartSound())
Expand Down
11 changes: 4 additions & 7 deletions lua/entities/gmod_laser_crystal/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,18 @@ end

function ENT:SpawnFunction(ply, tr)
if(not tr.Hit) then return end
local cas = LaserLib.GetClass(self.UnitID)
local gen = LaserLib.GetTool()
local ang = LaserLib.GetAngleSF(ply)
local ent = ents.Create(LaserLib.GetClass(2, 1))
local ent = ents.Create(cas)
if(LaserLib.IsValid(ent)) then
LaserLib.SetMaterial(ent, LaserLib.GetMaterial(2))
LaserLib.SnapNormal(ent, tr.HitPos, tr.HitNormal, 90)
LaserLib.SnapNormal(ent, tr, 90)
ent:SetAngles(ang) -- Appy angle after spawn
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
ent:SetSolid(SOLID_VPHYSICS)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent:SetNotSolid(false)
if(ply:KeyDown(IN_USE)) then
if(not LaserLib.Replace(tr.Entity, ent)) then
ent:SetModel(LaserLib.GetModel(2)) end
else ent:SetModel(LaserLib.GetModel(2)) end
LaserLib.SetVisuals(ply, ent, tr)
ent:SetBeamTransform()
ent:Spawn()
ent:SetCreator(ply)
Expand Down
5 changes: 4 additions & 1 deletion lua/entities/gmod_laser_crystal/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ENT.Type = "anim"
ENT.Category = LaserLib.GetData("CATG")
ENT.PrintName = "Crystal"
ENT.Information = ENT.Category.." "..ENT.PrintName
ENT.Base = LaserLib.GetClass(1, 1)
ENT.Base = LaserLib.GetClass(1)
if(WireLib) then
ENT.WireDebugName = ENT.Information
end
Expand All @@ -11,6 +11,9 @@ ENT.Contact = "[email protected]"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.UnitID = 2

LaserLib.RegisterUnit(ENT, "models/props_c17/pottery02a.mdl", "models/dog/eyeglass")

function ENT:SetupDataTables()
LaserLib.SetPrimary(self)
Expand Down
11 changes: 4 additions & 7 deletions lua/entities/gmod_laser_dimmer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,18 @@ end

function ENT:SpawnFunction(ply, tr)
if(not tr.Hit) then return end
local cas = LaserLib.GetClass(self.UnitID)
local gen = LaserLib.GetTool()
local ang = LaserLib.GetAngleSF(ply)
local ent = ents.Create(LaserLib.GetClass(7, 1))
local ent = ents.Create(cas)
if(LaserLib.IsValid(ent)) then
LaserLib.SetMaterial(ent, LaserLib.GetMaterial(7))
LaserLib.SnapNormal(ent, tr.HitPos, tr.HitNormal, 90)
LaserLib.SnapNormal(ent, tr, 90)
ent:SetAngles(ang) -- Appy angle after spawn
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
ent:SetSolid(SOLID_VPHYSICS)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent:SetNotSolid(false)
if(ply:KeyDown(IN_USE)) then
if(not LaserLib.Replace(tr.Entity, ent)) then
ent:SetModel(LaserLib.GetModel(7)) end
else ent:SetModel(LaserLib.GetModel(7)) end
LaserLib.SetVisuals(ply, ent, tr)
ent:Spawn()
ent:SetCreator(ply)
ent:Activate()
Expand Down
3 changes: 3 additions & 0 deletions lua/entities/gmod_laser_dimmer/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ ENT.Contact = "[email protected]"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.UnitID = 7

LaserLib.RegisterUnit(ENT, "models/props_c17/furnitureshelf001b.mdl", "models/dog/eyeglass")

include(LaserLib.GetTool().."/wire_wrapper.lua")
include(LaserLib.GetTool().."/editable_wrapper.lua")
Expand Down
11 changes: 4 additions & 7 deletions lua/entities/gmod_laser_divider/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,18 @@ end

function ENT:SpawnFunction(ply, tr)
if(not tr.Hit) then return end
local cas = LaserLib.GetClass(self.UnitID)
local gen = LaserLib.GetTool()
local ang = LaserLib.GetAngleSF(ply)
local ent = ents.Create(LaserLib.GetClass(5, 1))
local ent = ents.Create(cas)
if(LaserLib.IsValid(ent)) then
LaserLib.SetMaterial(ent, LaserLib.GetMaterial(5))
LaserLib.SnapNormal(ent, tr.HitPos, tr.HitNormal, 90)
LaserLib.SnapNormal(ent, tr, 90)
ent:SetAngles(ang) -- Appy angle after spawn
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
ent:SetSolid(SOLID_VPHYSICS)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent:SetNotSolid(false)
if(ply:KeyDown(IN_USE)) then
if(not LaserLib.Replace(tr.Entity, ent)) then
ent:SetModel(LaserLib.GetModel(5)) end
else ent:SetModel(LaserLib.GetModel(5)) end
LaserLib.SetVisuals(ply, ent, tr)
ent:Spawn()
ent:SetCreator(ply)
ent:Activate()
Expand Down
5 changes: 4 additions & 1 deletion lua/entities/gmod_laser_divider/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ENT.Type = "anim"
ENT.Category = LaserLib.GetData("CATG")
ENT.PrintName = "Divider"
ENT.Information = ENT.Category.." "..ENT.PrintName
ENT.Base = LaserLib.GetClass(1, 1)
ENT.Base = LaserLib.GetClass(1)
if(WireLib) then
ENT.WireDebugName = ENT.Information
end
Expand All @@ -12,6 +12,9 @@ ENT.Contact = "[email protected]"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.UnitID = 5

LaserLib.RegisterUnit(ENT, "models/props_c17/furnitureshelf001b.mdl", "models/dog/eyeglass")

function ENT:UpdateInternals()
self.hitSize = 0 -- Add sources in array
Expand Down
11 changes: 4 additions & 7 deletions lua/entities/gmod_laser_filter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,18 @@ end

function ENT:SpawnFunction(ply, tr)
if(not tr.Hit) then return end
local cas = LaserLib.GetClass(self.UnitID)
local gen = LaserLib.GetTool()
local ang = LaserLib.GetAngleSF(ply)
local ent = ents.Create(LaserLib.GetClass(11, 1))
local ent = ents.Create(cas)
if(LaserLib.IsValid(ent)) then
LaserLib.SetMaterial(ent, LaserLib.GetMaterial(11))
LaserLib.SnapNormal(ent, tr.HitPos, tr.HitNormal, 90)
LaserLib.SnapNormal(ent, tr, 90)
ent:SetAngles(ang) -- Appy angle after spawn
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
ent:SetSolid(SOLID_VPHYSICS)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent:SetNotSolid(false)
if(ply:KeyDown(IN_USE)) then
if(not LaserLib.Replace(tr.Entity, ent)) then
ent:SetModel(LaserLib.GetModel(11)) end
else ent:SetModel(LaserLib.GetModel(11)) end
LaserLib.SetVisuals(ply, ent, tr)
ent:Spawn()
ent:SetCreator(ply)
ent:Activate()
Expand Down
3 changes: 3 additions & 0 deletions lua/entities/gmod_laser_filter/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ ENT.Contact = "[email protected]"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.UnitID = 11

LaserLib.RegisterUnit(ENT, "models/props_c17/frame002a.mdl", "models/props_combine/citadel_cable")

include(LaserLib.GetTool().."/wire_wrapper.lua")
include(LaserLib.GetTool().."/editable_wrapper.lua")
Expand Down
11 changes: 4 additions & 7 deletions lua/entities/gmod_laser_parallel/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,18 @@ end

function ENT:SpawnFunction(ply, tr)
if(not tr.Hit) then return end
local cas = LaserLib.GetClass(self.UnitID)
local gen = LaserLib.GetTool()
local ang = LaserLib.GetAngleSF(ply)
local ent = ents.Create(LaserLib.GetClass(10, 1))
local ent = ents.Create(cas)
if(LaserLib.IsValid(ent)) then
LaserLib.SetMaterial(ent, LaserLib.GetMaterial(10))
LaserLib.SnapNormal(ent, tr.HitPos, tr.HitNormal, 90)
LaserLib.SnapNormal(ent, tr, 90)
ent:SetAngles(ang) -- Appy angle after spawn
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
ent:SetSolid(SOLID_VPHYSICS)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent:SetNotSolid(false)
if(ply:KeyDown(IN_USE)) then
if(not LaserLib.Replace(tr.Entity, ent)) then
ent:SetModel(LaserLib.GetModel(10)) end
else ent:SetModel(LaserLib.GetModel(10)) end
LaserLib.SetVisuals(ply, ent, tr)
ent:Spawn()
ent:SetCreator(ply)
ent:Activate()
Expand Down
3 changes: 3 additions & 0 deletions lua/entities/gmod_laser_parallel/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ ENT.Contact = "[email protected]"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.UnitID = 10

LaserLib.RegisterUnit(ENT, "models/props_c17/furnitureshelf001b.mdl", "models/dog/eyeglass")

include(LaserLib.GetTool().."/wire_wrapper.lua")
include(LaserLib.GetTool().."/editable_wrapper.lua")
Expand Down
13 changes: 5 additions & 8 deletions lua/entities/gmod_laser_portal/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ENT:Initialize()
self:SetMoveType(MOVETYPE_VPHYSICS)

self:WireCreateOutputs(
{"Entity", "ENTITY", "Portal entity itself" }
{"Entity", "ENTITY", "Portal entity itself"}
)

-- Mirror the exit position by default
Expand All @@ -44,21 +44,18 @@ end

function ENT:SpawnFunction(ply, tr)
if(not tr.Hit) then return end
local cas = LaserLib.GetClass(self.UnitID)
local gen = LaserLib.GetTool()
local ang = LaserLib.GetAngleSF(ply)
local ent = ents.Create(LaserLib.GetClass(9, 1))
local ent = ents.Create(cas)
if(LaserLib.IsValid(ent)) then
LaserLib.SetMaterial(ent, LaserLib.GetMaterial(9))
LaserLib.SnapNormal(ent, tr.HitPos, tr.HitNormal, 90)
LaserLib.SnapNormal(ent, tr, 90)
ent:SetAngles(ang) -- Appy angle after spawn
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
ent:SetSolid(SOLID_VPHYSICS)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent:SetNotSolid(false)
if(ply:KeyDown(IN_USE)) then
if(not LaserLib.Replace(tr.Entity, ent)) then
ent:SetModel(LaserLib.GetModel(9)) end
else ent:SetModel(LaserLib.GetModel(9)) end
LaserLib.SetVisuals(ply, ent, tr)
ent:Spawn()
ent:SetCreator(ply)
ent:Activate()
Expand Down
3 changes: 3 additions & 0 deletions lua/entities/gmod_laser_portal/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ ENT.Contact = "[email protected]"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.UnitID = 9

LaserLib.RegisterUnit(ENT, "models/props_c17/frame002a.mdl", "models/props_combine/com_shield001a")

include(LaserLib.GetTool().."/wire_wrapper.lua")
include(LaserLib.GetTool().."/editable_wrapper.lua")
Expand Down
11 changes: 4 additions & 7 deletions lua/entities/gmod_laser_rdivider/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,18 @@ end

function ENT:SpawnFunction(ply, tr)
if(not tr.Hit) then return end
local cas = LaserLib.GetClass(self.UnitID)
local gen = LaserLib.GetTool()
local ang = LaserLib.GetAngleSF(ply)
local ent = ents.Create("gmod_laser_rdivider")
local ent = ents.Create(cas)
if(LaserLib.IsValid(ent)) then
LaserLib.SetMaterial(ent, LaserLib.GetMaterial(7))
LaserLib.SnapNormal(ent, tr.HitPos, tr.HitNormal, 90)
LaserLib.SnapNormal(ent, tr, 90)
ent:SetAngles(ang) -- Appy angle after spawn
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
ent:SetSolid(SOLID_VPHYSICS)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent:SetNotSolid(false)
if(ply:KeyDown(IN_USE)) then
if(not LaserLib.Replace(tr.Entity, ent)) then
ent:SetModel(LaserLib.GetModel(7)) end
else ent:SetModel(LaserLib.GetModel(7)) end
LaserLib.SetVisuals(ply, ent, tr)
ent:Spawn()
ent:SetCreator(ply)
ent:Activate()
Expand Down
1 change: 1 addition & 0 deletions lua/entities/gmod_laser_rdivider/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ENT.Contact = "[email protected]"
ENT.Spawnable = false
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.UnitID = 0

include(LaserLib.GetTool().."/wire_wrapper.lua")
include(LaserLib.GetTool().."/editable_wrapper.lua")
Expand Down
11 changes: 4 additions & 7 deletions lua/entities/gmod_laser_reflector/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@ end

function ENT:SpawnFunction(ply, tr)
if(not tr.Hit) then return end
local cas = LaserLib.GetClass(self.UnitID)
local gen = LaserLib.GetTool()
local ang = LaserLib.GetAngleSF(ply)
local ent = ents.Create(LaserLib.GetClass(3, 1))
local ent = ents.Create(cas)
if(LaserLib.IsValid(ent)) then
LaserLib.SetMaterial(ent, LaserLib.GetMaterial(3))
LaserLib.SnapNormal(ent, tr.HitPos, tr.HitNormal, 90)
LaserLib.SnapNormal(ent, tr, 90)
ent:SetAngles(ang)
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
ent:SetSolid(SOLID_VPHYSICS)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent:SetNotSolid(false)
if(ply:KeyDown(IN_USE)) then
if(not LaserLib.Replace(tr.Entity, ent)) then
ent:SetModel(LaserLib.GetModel(3)) end
else ent:SetModel(LaserLib.GetModel(3)) end
LaserLib.SetVisuals(ply, ent, tr)
ent:Spawn()
ent:SetCreator(ply)
ent:Activate()
Expand Down
10 changes: 10 additions & 0 deletions lua/entities/gmod_laser_reflector/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ ENT.Contact = "[email protected]"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.UnitID = 3

LaserLib.RegisterUnit(ENT, "models/madjawa/laser_reflector.mdl", "debug/env_cubemap_model")

include(LaserLib.GetTool().."/wire_wrapper.lua")
include(LaserLib.GetTool().."/editable_wrapper.lua")
Expand Down Expand Up @@ -42,3 +45,10 @@ function ENT:SetReflectRatio(ratio)
self:WireWrite("Ratio", ratio)
return self
end

function ENT:GetReflectInfo(reflect)
local cpy = table.Copy(reflect)
local rat = self:GetReflectRatio()
cpy[1] = ((rat > 0) and rat or reflect[1])
return cpy -- Return modified row copy
end
11 changes: 4 additions & 7 deletions lua/entities/gmod_laser_refractor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,18 @@ end

function ENT:SpawnFunction(ply, tr)
if(not tr.Hit) then return end
local cas = LaserLib.GetClass(self.UnitID)
local gen = LaserLib.GetTool()
local ang = LaserLib.GetAngleSF(ply)
local ent = ents.Create(LaserLib.GetClass(12, 1))
local ent = ents.Create(cas)
if(LaserLib.IsValid(ent)) then
LaserLib.SetMaterial(ent, LaserLib.GetMaterial(12))
LaserLib.SnapNormal(ent, tr.HitPos, tr.HitNormal, 90)
LaserLib.SnapNormal(ent, tr, 90)
ent:SetAngles(ang)
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
ent:SetSolid(SOLID_VPHYSICS)
ent:SetMoveType(MOVETYPE_VPHYSICS)
ent:SetNotSolid(false)
if(ply:KeyDown(IN_USE)) then
if(not LaserLib.Replace(tr.Entity, ent)) then
ent:SetModel(LaserLib.GetModel(12)) end
else ent:SetModel(LaserLib.GetModel(12)) end
LaserLib.SetVisuals(ply, ent, tr)
ent:Spawn()
ent:SetCreator(ply)
ent:Activate()
Expand Down
5 changes: 4 additions & 1 deletion lua/entities/gmod_laser_refractor/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ ENT.Contact = "[email protected]"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_BOTH
ENT.UnitID = 12

LaserLib.RegisterUnit(ENT, "models/madjawa/laser_reflector.mdl", "models/props_combine/health_charger_glass")

include(LaserLib.GetTool().."/wire_wrapper.lua")
include(LaserLib.GetTool().."/editable_wrapper.lua")
Expand Down Expand Up @@ -73,5 +76,5 @@ function ENT:GetRefractInfo(refract)
if(self:GetZeroIndexMode()) then cpy[1] = idx
else cpy[1] = ((idx ~= 0) and idx or refract[1]) end
cpy[2], cpy[3] = ((rat > 0) and rat or refract[2]), nil
return cpy
return cpy -- Return modified row copy
end
Loading

0 comments on commit ca2a93f

Please sign in to comment.