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
e81fd36d8f
commit
26977b69c9
@ -1105,20 +1105,24 @@ concommand.Add("ragdollmover_changelog", function()
|
|||||||
showChangelog()
|
showChangelog()
|
||||||
end)
|
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 mx, my = input.GetCursorPos() -- possible bug on mac https://wiki.facepunch.com/gmod/input.GetCursorPos
|
||||||
local nodesExist = bonenodes and bonenodes[ent] and true
|
local nodesExist = bonenodes and bonenodes[ent] and true
|
||||||
local bonedistances = {}
|
local bonedistances = {}
|
||||||
local plpos = LocalPlayer():EyePos()
|
local plpos = LocalPlayer():EyePos()
|
||||||
local mindist, maxdist = nil, nil
|
local mindist, maxdist = nil, nil
|
||||||
|
|
||||||
for i = 0, ent:GetBoneCount() - 1 do
|
if calc then
|
||||||
local dist = plpos:DistToSqr( ent:GetBonePosition(i) )
|
prevbones = {}
|
||||||
if not mindist or mindist > dist then mindist = dist end
|
|
||||||
if not maxdist or maxdist < dist then maxdist = dist end
|
for i = 0, ent:GetBoneCount() - 1 do
|
||||||
bonedistances[i] = dist
|
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
|
end
|
||||||
maxdist = maxdist - mindist
|
|
||||||
|
|
||||||
local selectedBones = {}
|
local selectedBones = {}
|
||||||
for i = 0, ent:GetBoneCount() - 1 do
|
for i = 0, ent:GetBoneCount() - 1 do
|
||||||
@ -1137,12 +1141,16 @@ function AdvBoneSelectRender(ent, bonenodes)
|
|||||||
v.y = v.y + y
|
v.y = v.y + y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if calc then
|
||||||
|
prevbones[i] = ( ( bonedistances[i] - mindist ) < maxdist * 0.5 ) and 1 or 2
|
||||||
|
end
|
||||||
|
|
||||||
if dist < 576 then -- 24 pixels
|
if dist < 576 then -- 24 pixels
|
||||||
surface.SetDrawColor(COLOR_BRIGHT_YELLOW:Unpack())
|
surface.SetDrawColor(COLOR_BRIGHT_YELLOW:Unpack())
|
||||||
table.insert(selectedBones, {name, i})
|
table.insert(selectedBones, {name, i})
|
||||||
else
|
else
|
||||||
if nodesExist and bonenodes[ent][i] and bonenodes[ent][i].Type then
|
if nodesExist and bonenodes[ent][i] and bonenodes[ent][i].Type then
|
||||||
surface.SetDrawColor(BONETYPE_COLORS[bonenodes[ent][i].Type][( ( bonedistances[i] - mindist ) < maxdist * 0.5 ) and 1 or 2]:Unpack())
|
surface.SetDrawColor(BONETYPE_COLORS[bonenodes[ent][i].Type][prevbones[i]]:Unpack())
|
||||||
else
|
else
|
||||||
surface.SetDrawColor(COLOR_RGMGREEN:Unpack())
|
surface.SetDrawColor(COLOR_RGMGREEN:Unpack())
|
||||||
end
|
end
|
||||||
@ -1197,6 +1205,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)
|
draw.SimpleTextOutlined(selectedBones[i + 1][1], "RagdollMoverFont", xPos, yPos, color, TEXT_ALIGN_LEFT, TEXT_ALIGN_BOTTOM, OUTLINE_WIDTH, COLOR_RGMBLACK)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return prevbones
|
||||||
end
|
end
|
||||||
|
|
||||||
function AdvBoneSelectPick(ent, bonenodes)
|
function AdvBoneSelectPick(ent, bonenodes)
|
||||||
|
@ -4892,6 +4892,9 @@ hook.Add("KeyPress", "rgmSwitchSelectionMode", function(pl, key)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local BoneColors = nil
|
||||||
|
local LastThink, LastEnt = 0, nil
|
||||||
|
|
||||||
function TOOL:DrawHUD()
|
function TOOL:DrawHUD()
|
||||||
|
|
||||||
if not RAGDOLLMOVER[pl] then RAGDOLLMOVER[pl] = {} end
|
if not RAGDOLLMOVER[pl] then RAGDOLLMOVER[pl] = {} end
|
||||||
@ -4902,6 +4905,7 @@ function TOOL:DrawHUD()
|
|||||||
local bone = plTable.Bone
|
local bone = plTable.Bone
|
||||||
local axis = plTable.Axis
|
local axis = plTable.Axis
|
||||||
local moving = plTable.Moving or false
|
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,
|
--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.
|
--or if we're not allowed to draw it.
|
||||||
|
|
||||||
@ -4947,11 +4951,19 @@ function TOOL:DrawHUD()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if self:GetOperation() == 2 and IsValid(ent) then
|
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
|
if self:GetStage() == 0 then
|
||||||
rgm.AdvBoneSelectRender(ent, nodes)
|
BoneColors = rgm.AdvBoneSelectRender(ent, nodes, BoneColors, calc)
|
||||||
else
|
else
|
||||||
rgm.AdvBoneSelectRadialRender(ent, plTable.SelectedBones, nodes, ResetMode)
|
rgm.AdvBoneSelectRadialRender(ent, plTable.SelectedBones, nodes, ResetMode)
|
||||||
end
|
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
|
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.DrawBoneConnections(tr.Entity, aimedbone)
|
||||||
rgm.DrawBoneName(tr.Entity, aimedbone)
|
rgm.DrawBoneName(tr.Entity, aimedbone)
|
||||||
|
Loading…
Reference in New Issue
Block a user