mirror of
https://github.com/Winded/RagdollMover.git
synced 2025-03-04 03:13:36 -05:00
Attempt to optimize the distance drawing by having it run distance check every 0.1 of a second rather than each tick
This commit is contained in:
parent
5f1fea75ad
commit
f12c354f43
@ -1006,7 +1006,7 @@ local function gradient(startPoint, endPoint, points)
|
||||
return colors
|
||||
end
|
||||
|
||||
local NUM_GRADIENT_POINTS = 2
|
||||
local NUM_GRADIENT_POINTS = 4
|
||||
|
||||
local BONETYPE_COLORS = {
|
||||
gradient(RGM_Constants.COLOR_GREEN, RGM_Constants.COLOR_DARKGREEN, NUM_GRADIENT_POINTS),
|
||||
@ -1120,20 +1120,24 @@ concommand.Add("ragdollmover_changelog", function()
|
||||
showChangelog()
|
||||
end)
|
||||
|
||||
function AdvBoneSelectRender(ent, bonenodes)
|
||||
function AdvBoneSelectRender(ent, bonenodes, prevbones, calc)
|
||||
local mx, my = input.GetCursorPos() -- possible bug on mac https://wiki.facepunch.com/gmod/input.GetCursorPos
|
||||
local nodesExist = bonenodes and bonenodes[ent] and true
|
||||
local bonedistances = {}
|
||||
local plpos = LocalPlayer():EyePos()
|
||||
local mindist, maxdist = nil, nil
|
||||
|
||||
for i = 0, ent:GetBoneCount() - 1 do
|
||||
local dist = plpos:DistToSqr( ent:GetBonePosition(i) )
|
||||
if not mindist or mindist > dist then mindist = dist end
|
||||
if not maxdist or maxdist < dist then maxdist = dist end
|
||||
bonedistances[i] = dist
|
||||
if calc then
|
||||
prevbones = {}
|
||||
|
||||
for i = 0, ent:GetBoneCount() - 1 do
|
||||
local dist = plpos:DistToSqr( ent:GetBonePosition(i) )
|
||||
if not mindist or mindist > dist then mindist = dist end
|
||||
if not maxdist or maxdist < dist then maxdist = dist end
|
||||
bonedistances[i] = dist
|
||||
end
|
||||
maxdist = maxdist - mindist
|
||||
end
|
||||
maxdist = maxdist - mindist
|
||||
|
||||
local selectedBones = {}
|
||||
for i = 0, ent:GetBoneCount() - 1 do
|
||||
@ -1152,14 +1156,17 @@ function AdvBoneSelectRender(ent, bonenodes)
|
||||
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 )
|
||||
end
|
||||
|
||||
if dist < 576 then -- 24 pixels
|
||||
surface.SetDrawColor(COLOR_BRIGHT_YELLOW:Unpack())
|
||||
table.insert(selectedBones, {name, i})
|
||||
else
|
||||
if nodesExist and bonenodes[ent][i] and bonenodes[ent][i].Type then
|
||||
local fraction = ( bonedistances[i] - mindist ) / maxdist
|
||||
fraction = math.max(1, math.ceil(fraction * NUM_GRADIENT_POINTS))
|
||||
surface.SetDrawColor(BONETYPE_COLORS[bonenodes[ent][i].Type][fraction]:Unpack())
|
||||
surface.SetDrawColor(BONETYPE_COLORS[bonenodes[ent][i].Type][prevbones[i]]:Unpack())
|
||||
else
|
||||
surface.SetDrawColor(COLOR_RGMGREEN:Unpack())
|
||||
end
|
||||
@ -1214,6 +1221,8 @@ function AdvBoneSelectRender(ent, bonenodes)
|
||||
|
||||
draw.SimpleTextOutlined(selectedBones[i + 1][1], "RagdollMoverFont", xPos, yPos, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM, OUTLINE_WIDTH, COLOR_RGMBLACK)
|
||||
end
|
||||
|
||||
return prevbones
|
||||
end
|
||||
|
||||
function AdvBoneSelectPick(ent, bonenodes)
|
||||
|
@ -4892,6 +4892,9 @@ hook.Add("KeyPress", "rgmSwitchSelectionMode", function(pl, key)
|
||||
end
|
||||
end)
|
||||
|
||||
local BoneColors = nil
|
||||
local LastThink, LastEnt = 0, nil
|
||||
|
||||
function TOOL:DrawHUD()
|
||||
|
||||
if not RAGDOLLMOVER[pl] then RAGDOLLMOVER[pl] = {} end
|
||||
@ -4902,6 +4905,7 @@ function TOOL:DrawHUD()
|
||||
local bone = plTable.Bone
|
||||
local axis = plTable.Axis
|
||||
local moving = plTable.Moving or false
|
||||
local thinktime = CurTime()
|
||||
--We don't draw the axis if we don't have the axis entity or the target entity,
|
||||
--or if we're not allowed to draw it.
|
||||
|
||||
@ -4947,11 +4951,19 @@ function TOOL:DrawHUD()
|
||||
end
|
||||
|
||||
if self:GetOperation() == 2 and IsValid(ent) then
|
||||
local timecheck = (thinktime - LastThink) > 0.1
|
||||
local calc = ( not LastEnt or LastEnt ~= ent ) or timecheck
|
||||
|
||||
if self:GetStage() == 0 then
|
||||
rgm.AdvBoneSelectRender(ent, nodes)
|
||||
BoneColors = rgm.AdvBoneSelectRender(ent, nodes, BoneColors, calc)
|
||||
else
|
||||
rgm.AdvBoneSelectRadialRender(ent, plTable.SelectedBones, nodes, ResetMode)
|
||||
end
|
||||
|
||||
LastEnt = ent
|
||||
if timecheck then
|
||||
LastThink = thinktime
|
||||
end
|
||||
elseif IsValid(tr.Entity) and EntityFilter(tr.Entity, self) and (not bone or aimedbone ~= bone or tr.Entity ~= ent) and not moving then
|
||||
rgm.DrawBoneConnections(tr.Entity, aimedbone)
|
||||
rgm.DrawBoneName(tr.Entity, aimedbone)
|
||||
|
Loading…
Reference in New Issue
Block a user