From a52fe714b7e55486053714afa2db01028f3ed6d4 Mon Sep 17 00:00:00 2001 From: Deyan Dobromirov Date: Mon, 21 Oct 2024 15:46:22 +0300 Subject: [PATCH] Removed: Category hash table and current category reference 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 --- lua/autorun/trackassembly_init.lua | 2 +- lua/trackassembly/trackasmlib.lua | 20 ++-------------- .../gmod_tool/stools/trackassembly.lua | 24 +++++++++++-------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/lua/autorun/trackassembly_init.lua b/lua/autorun/trackassembly_init.lua index 6c9e0a07..114062e2 100644 --- a/lua/autorun/trackassembly_init.lua +++ b/lua/autorun/trackassembly_init.lua @@ -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 ------------ diff --git a/lua/trackassembly/trackasmlib.lua b/lua/trackassembly/trackasmlib.lua index 6f31a055..a3cd3ca4 100644 --- a/lua/trackassembly/trackasmlib.lua +++ b/lua/trackassembly/trackasmlib.lua @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/lua/weapons/gmod_tool/stools/trackassembly.lua b/lua/weapons/gmod_tool/stools/trackassembly.lua index 43b1b47a..031009a6 100644 --- a/lua/weapons/gmod_tool/stools/trackassembly.lua +++ b/lua/weapons/gmod_tool/stools/trackassembly.lua @@ -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 @@ -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 @@ -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)