Skip to content

Commit

Permalink
Improved sorting so nocollides are last. Also fixed lua error and bug…
Browse files Browse the repository at this point in the history
… with unsorted constraints.
  • Loading branch information
thegrb93 committed Jan 12, 2019
1 parent 1c7b67e commit c4aebd3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lua/weapons/gmod_tool/stools/advdupe2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if(SERVER)then
Slider = true,
Axis = true,
AdvBallsocket = true,
NoCollide = true,
-- NoCollide = true, Doesn't matter if nocollides make new systems, let the rigid stuff go first
Motor = true,
Pulley = true,
Ballsocket = true,
Expand All @@ -33,11 +33,21 @@ if(SERVER)then
}
//Orders constraints so that the dupe uses as little constraint systems as possible
local function GroupConstraintOrder( constraints )
local k = next(constraints)
if k == nil then return constraints end
local sortedConstraints = {constraints[k]}
local sortedConstraints = {}
local unsortedConstraints = {}
constraints[k] = nil

-- Get the initial constraint
for k, v in pairs(constraints) do
if phys_constraint_system_types[v.Type] then
sortedConstraints[#sortedConstraints + 1] = v
constraints[k] = nil
break
else
unsortedConstraints[#unsortedConstraints + 1] = v
constraints[k] = nil
end
end

while next(constraints) ~= nil do
for k, v in pairs(constraints) do
if phys_constraint_system_types[v.Type] then
Expand All @@ -57,6 +67,7 @@ if(SERVER)then
else
unsortedConstraints[#unsortedConstraints + 1] = v
constraints[k] = nil
goto super_loopbreak
end
end

Expand Down

0 comments on commit c4aebd3

Please sign in to comment.