Optimizations to AdvBoneSelectRender

- Bone positions are only rendered when it is visible on the screen. This results in about 23% increase in performance on average from looking away at a model with 139 bones
+ Added comments about mindist and maxdist
This commit is contained in:
vlazed 2024-12-23 13:32:27 -06:00
parent 6ca12972fc
commit b8a367d2b0

View File

@ -1140,6 +1140,8 @@ function AdvBoneSelectRender(ent, bonenodes, prevbones, calc)
end
bonedistances[i] = dist
end
-- maxdist or mindist may be nil if we weren't looking at all the bones.
-- We set them to some numbers to avoid issues with indicing with these
maxdist = maxdist or 1
mindist = mindist or 0
maxdist = maxdist - mindist
@ -1156,12 +1158,6 @@ function AdvBoneSelectRender(ent, bonenodes, prevbones, calc)
local dist = math.abs((mx - x)^2 + (my - y)^2)
local circ = table.Copy(RGM_CIRCLE)
for k, v in ipairs(circ) do
v.x = v.x + x
v.y = v.y + y
end
if calc then
local fraction = ( bonedistances[i] - mindist ) / maxdist
prevbones[i] = math.Clamp(math.ceil(fraction * NUM_GRADIENT_POINTS), 1, NUM_GRADIENT_POINTS )
@ -1178,17 +1174,25 @@ function AdvBoneSelectRender(ent, bonenodes, prevbones, calc)
end
end
draw.NoTexture()
surface.DrawPoly(circ)
if bonenodes[ent][i].bonelock then
surface.SetMaterial(LockGo)
surface.SetDrawColor(COLOR_WHITE:Unpack())
surface.DrawTexturedRect(x - 12, y - 12, 24, 24)
elseif bonenodes[ent][i].poslock or bonenodes[ent][i].anglock then
surface.SetMaterial(Lock)
surface.SetDrawColor(COLOR_WHITE:Unpack())
surface.DrawTexturedRect(x - 12, y - 12, 24, 24)
if pos.visible then
local circ = table.Copy(RGM_CIRCLE)
for k, v in ipairs(circ) do
v.x = v.x + x
v.y = v.y + y
end
draw.NoTexture()
surface.DrawPoly(circ)
if bonenodes[ent][i].bonelock then
surface.SetMaterial(LockGo)
surface.SetDrawColor(COLOR_WHITE:Unpack())
surface.DrawTexturedRect(x - 12, y - 12, 24, 24)
elseif bonenodes[ent][i].poslock or bonenodes[ent][i].anglock then
surface.SetMaterial(Lock)
surface.SetDrawColor(COLOR_WHITE:Unpack())
surface.DrawTexturedRect(x - 12, y - 12, 24, 24)
end
end
end