Skip to content

Commit 3252785

Browse files
committed
Tentative fix for nil _links table, new tool
A potential fix for floodfill in connectivity_sv erroring when running through an entity's _links table, due to said table being set to nil if the last link in that table happened to be removed Also new tool (to be fleshed out later) to aid in seeing an entity's connections in various manners for CFW. Right now it requires 'developer 1' due to usage of debugoverlay, later an overlay can be made alongside networking for CFW info. Due to that requirement, the tool will not be listed in the menu and must be accessed alternatively, such as 'gmod_tool cfw_tool'
1 parent 7331e60 commit 3252785

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

lua/cfw/classes/link_sv.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ do -- Class def
5757
entA._links[indexB] = nil
5858

5959
if not next(entA._links) then
60-
entA._links = nil
6160
entA:GetContraption():Sub(entA)
6261

6362
contraptionPopped = true
@@ -70,7 +69,6 @@ do -- Class def
7069
entB._links[indexA] = nil
7170

7271
if not next(entB._links) then
73-
entB._links = nil
7472
entB:GetContraption():Sub(entB)
7573

7674
contraptionPopped = true
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
TOOL.Category = "Contraption Framework"
2+
TOOL.Name = "CFW Tool"
3+
TOOL.AddToMenu = false
4+
5+
6+
--[[
7+
To access this, use 'gmod_tool cfw_tool'
8+
Hidden because this relies on developer 1, so not for use by normal means, for now
9+
Eventually this will get fleshed out with multiple debug modes
10+
11+
For example:
12+
Op 1 - Show entity's links via link table
13+
Op 2 - Show contraption that this entity is a part of
14+
Op 3 - ?
15+
16+
Tool screen should reflect mode of the tool as well
17+
When this happens, maybe allow normal use of the tool as well?
18+
]]
19+
20+
21+
TOOL.Entity = nil
22+
23+
function TOOL:LeftClick(tr)
24+
if not IsFirstTimePredicted() then return end
25+
if CLIENT then return true end
26+
27+
if (not IsValid(tr.Entity)) or tr.Entity:IsWorld() then
28+
self.Entity = nil
29+
else
30+
self.Entity = tr.Entity
31+
end
32+
33+
return true
34+
end
35+
36+
function TOOL:Reload()
37+
if not IsFirstTimePredicted() then return end
38+
if CLIENT then return end
39+
40+
self.Entity = nil
41+
end
42+
43+
function TOOL:Think()
44+
local ent = self.Entity
45+
if not IsValid(ent) then return end
46+
local selftbl = ent:GetTable()
47+
48+
if not selftbl._links then return end
49+
50+
local tick = engine.TickInterval() + 0.05
51+
52+
local Rendered = {}
53+
for _, link in pairs(selftbl._links) do
54+
local entA, entB = link.entA, link.entB
55+
debugoverlay.Line(entA:GetPos(),entB:GetPos(),tick,link.color,true)
56+
57+
if not Rendered[entA] then
58+
debugoverlay.Text(entA:GetPos(),"A",tick,false)
59+
60+
Rendered[entA] = true
61+
end
62+
63+
if not Rendered[entB] then
64+
debugoverlay.Text(entB:GetPos(),"B",tick,false)
65+
Rendered[entB] = true
66+
end
67+
68+
69+
70+
end
71+
end
72+

0 commit comments

Comments
 (0)