Skip to content

Commit

Permalink
Fixed: Correct return value of entity:trackasmlibApplyPhysical% and…
Browse files Browse the repository at this point in the history
… bodygroup/skin

Replaced: Rest of "Make" with "New"
Consolidated: `GetTerm` and `GetVacant`
  • Loading branch information
dvdvideo1234 committed Apr 18, 2024
1 parent efb7734 commit 5917f61
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 67 deletions.
6 changes: 3 additions & 3 deletions data/expression2/TA_ExtensionTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if(first() || dupefinished())
print("Skin OK<"+B+">")
}else{ error("Skin fail "+B) }

E1 = E:trackasmlibMakePiece(E:pos(), E:angles():rotateAroundAxis(E:up(), 90))
E2 = E:trackasmlibMakePiece(E:pos(), E:angles():rotateAroundAxis(E:forward(), 90), 666, "0/0", vec(50, 150, 250))
E2 = E:trackasmlibMakePiece(E:pos(), E:angles():rotateAroundAxis(E:forward(), -90), 666, "0/0", vec(250, 150, 50))
E1 = E:trackasmlibNewPiece(E:pos(), E:angles():rotateAroundAxis(E:up(), 90))
E2 = E:trackasmlibNewPiece(E:pos(), E:angles():rotateAroundAxis(E:forward(), 90), 666, "0/0", vec(50, 150, 250))
E2 = E:trackasmlibNewPiece(E:pos(), E:angles():rotateAroundAxis(E:forward(), -90), 666, "0/0", vec(250, 150, 50))
}
66 changes: 33 additions & 33 deletions lua/autorun/trackassembly_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ local asmlib = trackasmlib; if(not asmlib) then -- Module present
------------ CONFIGURE ASMLIB ------------

asmlib.InitBase("track","assembly")
asmlib.SetOpVar("TOOL_VERSION","8.764")
asmlib.SetOpVar("TOOL_VERSION","8.765")

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

Expand Down Expand Up @@ -152,40 +152,40 @@ asmlib.SetBorder(gsToolPrefL.."rtradmenu", -gnMaxRot, gnMaxRot)
------------ CONFIGURE LOGGING ------------

asmlib.SetOpVar("LOG_DEBUGEN",false)
asmlib.MakeAsmConvar("logsmax", 0, nil, gnIndependentUsed, "Maximum logging lines being written")
asmlib.MakeAsmConvar("logfile", 0, nil, gnIndependentUsed, "File logging output flag control")
asmlib.NewAsmConvar("logsmax", 0, nil, gnIndependentUsed, "Maximum logging lines being written")
asmlib.NewAsmConvar("logfile", 0, nil, gnIndependentUsed, "File logging output flag control")
asmlib.SetLogControl(asmlib.GetAsmConvar("logsmax","INT"), asmlib.GetAsmConvar("logfile","BUL"))
asmlib.SettingsLogs("SKIP"); asmlib.SettingsLogs("ONLY")

------------ CONFIGURE NON-REPLICATED CVARS ------------ Client's got a mind of its own

asmlib.MakeAsmConvar("modedb" , "LUA", nil, gnIndependentUsed, "Database storage operating mode LUA or SQL")
asmlib.MakeAsmConvar("devmode" , 0 , nil, gnIndependentUsed, "Toggle developer mode on/off server side")
asmlib.MakeAsmConvar("maxtrmarg", 0.02 , nil, gnIndependentUsed, "Maximum time to avoid performing new traces")
asmlib.MakeAsmConvar("maxmenupr", 5 , nil, gnIndependentUsed, "Maximum decimal places utilized in the control panel")
asmlib.MakeAsmConvar("timermode", "CQT@1800@1@1/CQT@900@1@1/CQT@600@1@1", nil, gnIndependentUsed, "Memory management setting when DB mode is SQL")
asmlib.NewAsmConvar("modedb" , "LUA", nil, gnIndependentUsed, "Database storage operating mode LUA or SQL")
asmlib.NewAsmConvar("devmode" , 0 , nil, gnIndependentUsed, "Toggle developer mode on/off server side")
asmlib.NewAsmConvar("maxtrmarg", 0.02 , nil, gnIndependentUsed, "Maximum time to avoid performing new traces")
asmlib.NewAsmConvar("maxmenupr", 5 , nil, gnIndependentUsed, "Maximum decimal places utilized in the control panel")
asmlib.NewAsmConvar("timermode", "CQT@1800@1@1/CQT@900@1@1/CQT@600@1@1", nil, gnIndependentUsed, "Memory management setting when DB mode is SQL")

------------ CONFIGURE REPLICATED CVARS ------------ Server tells the client what value to use

asmlib.MakeAsmConvar("maxmass" , 50000 , nil, gnServerControled, "Maximum mass that can be applied on a piece")
asmlib.MakeAsmConvar("maxlinear", 5000 , nil, gnServerControled, "Maximum linear offset of the piece")
asmlib.MakeAsmConvar("maxforce" , 100000, nil, gnServerControled, "Maximum force limit when creating welds")
asmlib.MakeAsmConvar("maxactrad", 200 , nil, gnServerControled, "Maximum active radius to search for a point ID")
asmlib.MakeAsmConvar("maxstcnt" , 200 , nil, gnServerControled, "Maximum spawned pieces in stacking mode")
asmlib.MakeAsmConvar("maxghcnt" , 1500 , nil, gnServerControled, "Maximum ghost pieces being spawned by client")
asmlib.MakeAsmConvar("enwiremod", 1 , nil, gnServerControled, "Toggle the wire extension on/off server side")
asmlib.MakeAsmConvar("enmultask", 1 , nil, gnServerControled, "Toggle the spawn multitasking on/off server side")
asmlib.MakeAsmConvar("enctxmenu", 1 , nil, gnServerControled, "Toggle the context menu on/off in general")
asmlib.MakeAsmConvar("enctxmall", 0 , nil, gnServerControled, "Toggle the context menu on/off for all props")
asmlib.MakeAsmConvar("endsvlock", 0 , nil, gnServerControled, "Toggle the DSV external database file update on/off")
asmlib.MakeAsmConvar("curvefact", 0.5 , nil, gnServerControled, "Parametric constant track curving factor")
asmlib.MakeAsmConvar("curvsmple", 50 , nil, gnServerControled, "Amount of samples between two curve nodes")
asmlib.MakeAsmConvar("spawnrate", 1 , nil, gnServerControled, "Maximum pieces spawned in every think tick")
asmlib.MakeAsmConvar("bnderrmod","LOG" , nil, gnServerControled, "Unreasonable position error handling mode")
asmlib.MakeAsmConvar("maxfruse" , 50 , nil, gnServerControled, "Maximum frequent pieces to be listed")
asmlib.MakeAsmConvar("maxspmarg", 0 , nil, gnServerControled, "Maximum spawn distance new piece created margin")
asmlib.MakeAsmConvar("dtmessage", 1 , nil, gnServerControled, "Time interval for server addressed messages")
asmlib.MakeAsmConvar("*sbox_max"..gsLimitName, 1500, nil, gnServerControled, "Maximum number of tracks to be spawned")
asmlib.NewAsmConvar("maxmass" , 50000 , nil, gnServerControled, "Maximum mass that can be applied on a piece")
asmlib.NewAsmConvar("maxlinear", 5000 , nil, gnServerControled, "Maximum linear offset of the piece")
asmlib.NewAsmConvar("maxforce" , 100000, nil, gnServerControled, "Maximum force limit when creating welds")
asmlib.NewAsmConvar("maxactrad", 200 , nil, gnServerControled, "Maximum active radius to search for a point ID")
asmlib.NewAsmConvar("maxstcnt" , 200 , nil, gnServerControled, "Maximum spawned pieces in stacking mode")
asmlib.NewAsmConvar("maxghcnt" , 1500 , nil, gnServerControled, "Maximum ghost pieces being spawned by client")
asmlib.NewAsmConvar("enwiremod", 1 , nil, gnServerControled, "Toggle the wire extension on/off server side")
asmlib.NewAsmConvar("enmultask", 1 , nil, gnServerControled, "Toggle the spawn multitasking on/off server side")
asmlib.NewAsmConvar("enctxmenu", 1 , nil, gnServerControled, "Toggle the context menu on/off in general")
asmlib.NewAsmConvar("enctxmall", 0 , nil, gnServerControled, "Toggle the context menu on/off for all props")
asmlib.NewAsmConvar("endsvlock", 0 , nil, gnServerControled, "Toggle the DSV external database file update on/off")
asmlib.NewAsmConvar("curvefact", 0.5 , nil, gnServerControled, "Parametric constant track curving factor")
asmlib.NewAsmConvar("curvsmple", 50 , nil, gnServerControled, "Amount of samples between two curve nodes")
asmlib.NewAsmConvar("spawnrate", 1 , nil, gnServerControled, "Maximum pieces spawned in every think tick")
asmlib.NewAsmConvar("bnderrmod","LOG" , nil, gnServerControled, "Unreasonable position error handling mode")
asmlib.NewAsmConvar("maxfruse" , 50 , nil, gnServerControled, "Maximum frequent pieces to be listed")
asmlib.NewAsmConvar("maxspmarg", 0 , nil, gnServerControled, "Maximum spawn distance new piece created margin")
asmlib.NewAsmConvar("dtmessage", 1 , nil, gnServerControled, "Time interval for server addressed messages")
asmlib.NewAsmConvar("*sbox_max"..gsLimitName, 1500, nil, gnServerControled, "Maximum number of tracks to be spawned")

------------ CONFIGURE INTERNALS ------------

Expand Down Expand Up @@ -680,7 +680,7 @@ if(CLIENT) then
local atGho = asmlib.GetOpVar("ARRAY_GHOST")
if(asmlib.IsModel(model)) then
if(not (asmlib.HasGhosts() and ghcnt == atGho.Size and atGho.Slot == model)) then
if(not asmlib.MakeGhosts(ghcnt, model)) then
if(not asmlib.NewGhosts(ghcnt, model)) then
asmlib.LogInstance("Ghosting fail",sLog); return nil end
actTool:ElevateGhost(atGho[1], oPly) -- Elevate the properly created ghost
end; actTool:UpdateGhost(oPly) -- Update ghosts stack for the local player
Expand Down Expand Up @@ -1257,7 +1257,7 @@ if(CLIENT) then
if(asmlib.IsModel(trRec.Slot)) then -- The model has valid pre-cache
if(ghostcnt > 0) then -- The ghosting is enabled
if(not (hasghost and atGhosts.Size == 1 and trRec.Slot == atGhosts.Slot)) then
if(not asmlib.MakeGhosts(1, trRec.Slot)) then
if(not asmlib.NewGhosts(1, trRec.Slot)) then
asmlib.LogInstance("Ghosting fail",sLog); return nil end
end local eGho = atGhosts[1]; eGho:SetNoDraw(false)
eGho:SetPos(actSpawn.SPos); eGho:SetAngles(actSpawn.SAng)
Expand Down Expand Up @@ -1659,9 +1659,9 @@ asmlib.CreateTable("PIECES",{
local noTY = asmlib.GetOpVar("MISS_NOTP")
local noSQL = asmlib.GetOpVar("MISS_NOSQL")
local trCls = asmlib.GetOpVar("TRACE_CLASS")
arLine[2] = asmlib.GetTerm(arLine[2], noTY, asmlib.Categorize())
arLine[3] = asmlib.GetTerm(arLine[3], noMD, asmlib.ModelToName(arLine[1]))
arLine[8] = asmlib.GetTerm(arLine[8], noSQL, noSQL)
arLine[2] = asmlib.GetVacant(arLine[2], true, noTY, asmlib.Categorize())
arLine[3] = asmlib.GetVacant(arLine[3], true, noMD, asmlib.ModelToName(arLine[1]))
arLine[8] = asmlib.GetVacant(arLine[8], true, noSQL, noSQL)
if(not (asmlib.IsNull(arLine[8]) or trCls[arLine[8]] or asmlib.IsBlank(arLine[8]))) then
asmlib.LogInstance("Register trace "..asmlib.GetReport2(arLine[8],arLine[1]),vSrc)
trCls[arLine[8]] = true; -- Register the class provided to the trace hit list
Expand Down Expand Up @@ -1786,7 +1786,7 @@ asmlib.CreateTable("PHYSPROPERTIES",{
Trigs = {
Record = function(arLine, vSrc)
local noTY = asmlib.GetOpVar("MISS_NOTP")
arLine[1] = asmlib.GetTerm(arLine[1],noTY,asmlib.Categorize()); return true
arLine[1] = asmlib.GetVacant(arLine[1],true,noTY,asmlib.Categorize()); return true
end
},
Cache = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ e2function entity entity:trackasmlibNewPiece(vector vPos, angle aAng)
end

__e2setcost(15)
e2function entity entity:trackasmlibApplyPhysicalAnchor(entity eBase, number nWe, number nNc, number nNw, number nFm)
e2function number entity:trackasmlibApplyPhysicalAnchor(entity eBase, number nWe, number nNc, number nNw, number nFm)
if(not (this and this:IsValid() and enFlag)) then return anyFalse end
if(not (eBase and eBase:IsValid())) then return anyFalse end
local stRec = asmlib.CacheQueryPiece(this:GetModel()); if(not stRec) then return anyFalse end
return asmlib.ApplyPhysicalAnchor(this,eBase,(nWe~=0),(nNc~=0),(nNw~=0),nFm) and anyTrue or anyFalse
end

__e2setcost(15)
e2function entity entity:trackasmlibApplyPhysicalSettings(number nPi, number nFr, number nGr, string sPh)
e2function number entity:trackasmlibApplyPhysicalSettings(number nPi, number nFr, number nGr, string sPh)
if(not (this and this:IsValid() and enFlag)) then return anyFalse end
local stRec = asmlib.CacheQueryPiece(this:GetModel()); if(not stRec) then return anyFalse end
return asmlib.ApplyPhysicalSettings(this,(nPi~=0),(nFr~=0),(nGr~=0),sPh) and anyTrue or anyFalse
Expand All @@ -379,12 +379,12 @@ end

__e2setcost(20)
e2function string entity:trackasmlibGetBodyGroups()
if(not (this and this:IsValid() and enFlag)) then return 0 end
if(not (this and this:IsValid() and enFlag)) then return "" end
return asmlib.GetPropBodyGroup(this)
end

__e2setcost(20)
e2function string entity:trackasmlibGetSkin()
if(not (this and this:IsValid() and enFlag)) then return 0 end
if(not (this and this:IsValid() and enFlag)) then return "" end
return asmlib.GetPropSkin(this)
end
48 changes: 23 additions & 25 deletions lua/trackassembly/trackasmlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,6 @@ function GetOwner(oEnt)
end; return ows -- No owner is found. Nothing is returned
end

function GetVacant(sStr)
local sD = GetOpVar("OPSYM_DISABLE")
local sS = tostring(sStr or "") -- Default to string
local bE = (IsBlank(sS) or IsNull(sS) or sS:sub(1,1) == sD)
return bE, sS -- Scan whenever data to be decoded is present
end

------------------ LOGS ------------------------

function GetLogID()
Expand Down Expand Up @@ -1824,10 +1817,11 @@ function GetFrequentModels(snCount)
end

function SetComboBoxClipboard(pnCombo)
local sV = pnCombo:GetValue()
local iD = pnCombo:GetSelectedID()
local vT = pnCombo:GetOptionText(iD)
local sV = GetTerm(tostring(vT or ""), pnCombo:GetValue())
SetClipboardText(GetTerm(sV, gsNoAV))
local sT = pnCombo:GetOptionText(iD)
local sS = GetVacant(tostring(sT or ""), true, sS)
SetClipboardText(GetVacant(sS, true, gsNoAV))
end

function SetComboBoxList(cPanel, sVar)
Expand Down Expand Up @@ -2136,7 +2130,7 @@ end
* vPos > Custom position for the placeholder ( zero if none )
* aAng > Custom angles for the placeholder ( zero if none )
]]
function MakeEntityNone(sModel, vPos, aAng) local eNone
function NewEntityNone(sModel, vPos, aAng) local eNone
if(not IsModel(sModel)) then return nil end
if(SERVER) then eNone = entsCreate(GetOpVar("ENTITY_DEFCLASS"))
elseif(CLIENT) then eNone = entsCreateClientProp(sModel) end
Expand Down Expand Up @@ -2169,7 +2163,7 @@ function GetAttachmentByID(sModel, sID)
if(ePiece:GetModel() ~= sModel) then ePiece:SetModel(sModel)
LogInstance("Update "..GetReport3(ePiece:EntIndex(), sID, sModel)) end
else -- If there is no basis need to create one for attachment extraction
ePiece = MakeEntityNone(sModel); if(not (ePiece and ePiece:IsValid())) then
ePiece = NewEntityNone(sModel); if(not (ePiece and ePiece:IsValid())) then
LogInstance("Basis creation error "..GetReport2(sID, sModel)); return nil end
SetOpVar("ENTITY_TRANSFORMPOA", ePiece) -- Register the entity transform basis
end -- Transfer the data from the transform attachment location
Expand Down Expand Up @@ -2329,20 +2323,24 @@ function Sort(tTable, tCols)
end

------------- VARIABLE INTERFACES --------------

--[[
* Returns a string term whenever it is is missing or disabled
* Returns a string term whenever it is missing or disabled
* If these conditions are not met the function returns missing token
* sBas > The string to check whenever it is disabled or missing
* vDef > The default value to return when base is not string
* vDsb > The disable value to return when the base is disabled string
]]
function GetTerm(sBas, vDef, vDsb)
local sM = GetOpVar("MISS_NOAV")
function GetVacant(sBas, bTer, vDef, vDsb)
local sD = GetOpVar("OPSYM_DISABLE")
if(IsString(sBas)) then
if(sBas:sub(1,1) == sD) then return tostring(vDsb or sM)
elseif(not (IsNull(sBas) or IsBlank(sBas))) then return sBas end
end; if(IsString(vDef)) then return vDef end; return sM
local sS = tostring(sBas or "") -- Default to string
local bD = (sS:sub(1,1) == sD) -- Disabled string
local bE = (IsBlank(sS) or IsNull(sS) or bD)
if(not bTer) then return bE, sS end -- Data to be decoded
local sM = GetOpVar("MISS_NOAV") -- Not available
if(bD) then return tostring(vDsb or sM) end
if(bE) then return tostring(vDef or sM) end
return sS -- Return the base string
end

function ModelToNameRule(sRule, gCut, gSub, gApp)
Expand Down Expand Up @@ -2603,8 +2601,8 @@ function CreateTable(sTable,defTab,bDelete,bReload)
local self, tabDef, tabCmd = {}, defTab, {}
local symDis, sMoDB = GetOpVar("OPSYM_DISABLE"), GetOpVar("MODE_DATABASE")
for iCnt = 1, defTab.Size do local defCol = defTab[iCnt]
defCol[3] = GetTerm(tostring(defCol[3] or symDis), symDis)
defCol[4] = GetTerm(tostring(defCol[4] or symDis), symDis)
defCol[3] = GetVacant(tostring(defCol[3] or symDis), true, symDis)
defCol[4] = GetVacant(tostring(defCol[4] or symDis), true, symDis)
end; tableInsert(libQTable, defTab.Nick)
libCache[defTab.Name] = {}; libQTable[defTab.Nick] = self
-- Read table definition
Expand Down Expand Up @@ -4649,7 +4647,7 @@ function NewPiece(pPly,sModel,vPos,aAng,nMass,sBgSkIDs,clColor,sMode)
if(InSpawnMargin(pPly, stData, vPos, aAng)) then
LogInstance("Spawn margin stop <"..sModel..">"); return nil end
local sClass = GetOpVar("ENTITY_DEFCLASS")
local ePiece = entsCreate(GetTerm(stData.Unit, sClass, sClass))
local ePiece = entsCreate(GetVacant(stData.Unit, true, sClass, sClass))
if(not (ePiece and ePiece:IsValid())) then -- Create the piece unit
LogInstance("Piece invalid <"..tostring(ePiece)..">"); return nil end
ePiece:SetCollisionGroup(COLLISION_GROUP_NONE)
Expand Down Expand Up @@ -5043,7 +5041,7 @@ end
* aAng > Angles for the entity, otherwise zero is used
* It must have been our imagination.
]]
function MakeEntityGhost(sModel, vPos, aAng)
function NewEntityGhost(sModel, vPos, aAng)
if(not IsModel(sModel)) then return nil end
local cPal = GetContainer("COLORS_LIST")
local eGho = entsCreateClientProp(sModel)
Expand Down Expand Up @@ -5075,7 +5073,7 @@ end
* sModel > The model which the creation is requested for
* Not until we walk around the ghost town and see what we can find.
]]
function MakeGhosts(nCnt, sModel) -- Only he's not a shadow, he's a green ghost!
function NewGhosts(nCnt, sModel) -- Only he's not a shadow, he's a green ghost!
if(SERVER) then return true end -- Ghosting is client side only
local tGho = GetOpVar("ARRAY_GHOST") -- Read ghosts
if(nCnt == 0 and tGho.Size == 0) then return true end -- Skip processing
Expand All @@ -5085,7 +5083,7 @@ function MakeGhosts(nCnt, sModel) -- Only he's not a shadow, he's a green ghost!
if(eGho and eGho:IsValid()) then eGho:SetNoDraw(true)
if(eGho:GetModel() ~= sModel) then eGho:SetModel(sModel) end
else -- Reconfigure the first `nCnt` ghosts
tGho[iD] = MakeEntityGhost(sModel); eGho = tGho[iD]
tGho[iD] = NewEntityGhost(sModel); eGho = tGho[iD]
if(not (eGho and eGho:IsValid())) then ClearGhosts(iD)
LogInstance("Invalid ["..iD.."]"..sModel); return false end
end; iD = iD + 1 -- Fade all the ghosts and refresh these that must be drawn
Expand Down
4 changes: 2 additions & 2 deletions lua/weapons/gmod_tool/stools/trackassembly.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ function TOOL.BuildCPanel(CPanel)

local pComboPhysName = CPanel:ComboBox(languageGetPhrase("tool."..gsToolNameL..".phyname_con"), sName)
pComboPhysName:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".phyname"))
pComboPhysName:SetValue(asmlib.GetTerm(asmlib.GetAsmConvar("physmater","STR"),
pComboPhysName:SetValue(asmlib.GetVacant(asmlib.GetAsmConvar("physmater","STR"), true,
languageGetPhrase("tool."..gsToolNameL..".phyname_def")))
pComboPhysName.DoRightClick = function(pnSelf) asmlib.SetComboBoxClipboard(pnSelf) end
pComboPhysName:Dock(TOP) -- Setting tallness gets ignored otherwise
Expand Down Expand Up @@ -2437,7 +2437,7 @@ function TOOL.BuildCPanel(CPanel)
local sName = asmlib.GetAsmConvar("bgskids", "NAM")
local pText = CPanel:TextEntry(languageGetPhrase("tool."..gsToolNameL..".bgskids_con"), sName)
pText:SetTooltip(languageGetPhrase("tool."..gsToolNameL..".bgskids"))
pText:SetText(asmlib.GetTerm(asmlib.GetAsmConvar("bgskids", "STR"),
pText:SetText(asmlib.GetVacant(asmlib.GetAsmConvar("bgskids", "STR"), true,
languageGetPhrase("tool."..gsToolNameL..".bgskids_def")))
pText:SetEnabled(false); pText:SetTall(22)

Expand Down

0 comments on commit 5917f61

Please sign in to comment.