Skip to content

Commit

Permalink
Removed: Category hash table and current category reference
Browse files Browse the repository at this point in the history
Removed: Reverse-hash indexing for tree nodes
Removed: `GetDirectory` using revers indexing. Utilize reference hash-jumps instead
Updated: `SetDirectory` to match the new tree creation routine
  • Loading branch information
dvdvideo1234 committed Oct 21, 2024
1 parent 5d97ab0 commit a52fe71
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ local asmlib = trackasmlib; if(not asmlib) then -- Module present
------------ CONFIGURE ASMLIB ------------

asmlib.InitBase("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","8.772")
asmlib.SetOpVar("TOOL_VERSION","8.773")

------------ CONFIGURE GLOBAL INIT OPVARS ------------

Expand Down
20 changes: 2 additions & 18 deletions lua/trackassembly/trackasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,6 @@ function InitBase(sName, sPurp)
SetOpVar("ARRAY_GHOST",{Size=0, Slot=GetOpVar("MISS_NOMD")})
SetOpVar("TABLE_CATEGORIES",{})
SetOpVar("CLIPBOARD_TEXT","")
SetOpVar("TREE_KEYPANEL","#$@KEY&*PAN*&OBJ@$#")
end; LogInstance("Success"); return true
end

Expand Down Expand Up @@ -1709,17 +1708,6 @@ function UpdateListView(pnListView,frUsed,nCount,sCol,sPat)
LogInstance("Updated "..GetReport(frUsed.Size)); return true
end

function GetDirectory(pCurr, vName)
if(not pCurr) then
LogInstance("Location invalid"); return nil end
local keyOb = GetOpVar("TREE_KEYPANEL")
local sName = tostring(vName or "")
sName = IsBlank(sName) and "Other" or sName
local pItem = pCurr[sName]; if(not IsHere(pItem)) then
LogInstance("Name missing "..GetReport(sName)); return nil end
return pItem, pItem[keyOb]
end

function SetExpandNode(pnBase)
local bEx = pnBase:GetExpanded()
if(inputIsKeyDown(KEY_LSHIFT)) then
Expand All @@ -1729,18 +1717,14 @@ function SetExpandNode(pnBase)
end
end

function SetDirectory(pnBase, pCurr, vName)
function SetDirectory(pnBase, vName)
if(not IsValid(pnBase)) then
LogInstance("Base panel invalid"); return nil end
if(not pCurr) then
LogInstance("Location invalid"); return nil end
local tSkin = pnBase:GetSkin()
local sTool = GetOpVar("TOOLNAME_NL")
local keyOb = GetOpVar("TREE_KEYPANEL")
local sName = tostring(vName or "")
sName = (IsBlank(sName) and "Other" or sName)
local pNode = pnBase:AddNode(sName)
pCurr[sName] = {}; pCurr[sName][keyOb] = pNode
pNode:SetTooltip(languageGetPhrase("tool."..sTool..".subfolder"))
pNode.Icon:SetImage(ToIcon("subfolder_item"))
pNode.DoClick = function() SetExpandNode(pNode) end
Expand All @@ -1749,7 +1733,7 @@ function SetDirectory(pnBase, pCurr, vName)
SetClipboardText(pNode:GetText())
end
pNode:UpdateColours(tSkin)
return pCurr[sName], pNode
return pNode
end

function SetDirectoryNode(pnBase, sName, sModel)
Expand Down
24 changes: 14 additions & 10 deletions lua/weapons/gmod_tool/stools/trackassembly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,7 @@ function TOOL.BuildCPanel(CPanel)
pTree:UpdateColours(drmSkin) -- Apply current skin
CPanel:AddItem(pTree) -- Register it to the panel
local defTable = makTab:GetDefinition()
local tType, tCats, tRoot = {}, {}, {Size = 0}
local tType, tRoot = {}, {Size = 0}
for iC = 1, qPanel.Size do
local vRec, bNow = qPanel[iC], true
local sMod, sTyp, sNam = vRec.M, vRec.T, vRec.N
Expand All @@ -2335,19 +2335,23 @@ function TOOL.BuildCPanel(CPanel)
else SetClipboardText(pRoot:GetText()) end
end
pRoot:UpdateColours(drmSkin)
tType[sTyp] = pRoot
tType[sTyp] = {Base = pRoot, Node = {}}
end -- Reset the primary tree node pointer
if(tType[sTyp]) then pItem = tType[sTyp] else pItem = pTree end
if(tType[sTyp]) then pItem = tType[sTyp].Base else pItem = pTree end
-- Register the node associated with the track piece when is intended for later
local pCur = tCats[sTyp]; if(not asmlib.IsHere(pCur)) then
tCats[sTyp] = {}; pCur = tCats[sTyp] end -- Create category tree path
if(vRec.C) then -- When category for the track type is available
if(vRec.C and vRec.C.Size > 0) then -- When category for the track type is available
local tNode = tType[sTyp].Node -- Index the contend for the track type
for iD = 1, vRec.C.Size do -- Generate the path to the track piece
local sCat = vRec.C[iD] -- Read the category name
if(pCur[sCat]) then -- Jump next if already created
pCur, pItem = asmlib.GetDirectory(pCur, sCat)
local tCat = tNode[sCat] -- Index the internal sub-category
if(tCat) then -- Jump next if already created
pItem = tCat.Base -- Assume that the category is allocated
tNode = tCat.Node -- Jump to the next set of base nodes
else -- Create a new sub-category for the incoming content
pCur, pItem = asmlib.SetDirectory(pItem, pCur, sCat)
tNode[sCat] = {}; tCat = tNode[sCat] -- Create node info
pItem = asmlib.SetDirectory(pItem, sCat) -- Create category
tCat.Base = pItem; tCat.Node = {} -- Allocate node info
tNode = tCat.Node -- Jump to the allocated set of base nodes
end -- Create the last needed node regarding pItem
end -- When the category has at least one element
else -- Panel cannot categorize the entry add it to the list
Expand All @@ -2363,7 +2367,7 @@ function TOOL.BuildCPanel(CPanel)
local iRox = tRoot[iR]
local vRec = qPanel[iRox]
local sMod, sTyp, sNam = vRec.M, vRec.T, vRec.N
asmlib.SetDirectoryNode(tType[sTyp], sNam, sMod)
asmlib.SetDirectoryNode(tType[sTyp].Base, sNam, sMod)
asmlib.LogInstance("Rooting item "..asmlib.GetReport(sTyp, sNam, sMod), sLog)
end -- Process all the items without category defined
asmlib.LogInstance("Found items #"..qPanel.Size, sLog)
Expand Down

0 comments on commit a52fe71

Please sign in to comment.