Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WireLib.clampPos/Force optimization #3221

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions lua/wire/wireshared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -942,11 +942,7 @@ local minx, miny, minz = -16384, -16384, -16384
local maxx, maxy, maxz = 16384, 16384, 16384
local clamp = math.Clamp
function WireLib.clampPos(pos)
pos = Vector(pos)
pos.x = clamp(pos.x, minx, maxx)
pos.y = clamp(pos.y, miny, maxy)
pos.z = clamp(pos.z, minz, maxz)
return pos
return Vector(clamp(pos.x, minx, maxx), clamp(pos.y, miny, maxy), clamp(pos.z, minz, maxz))
end

function WireLib.setPos(ent, pos)
Expand Down Expand Up @@ -1014,10 +1010,12 @@ end)

-- Nan never equals itself, so if the value doesn't equal itself replace it with 0.
function WireLib.clampForce( v )
local x, y, z = v:Unpack()

return Vector(
v[1] == v[1] and math.Clamp( v[1], min_force, max_force ) or 0,
v[2] == v[2] and math.Clamp( v[2], min_force, max_force ) or 0,
v[3] == v[3] and math.Clamp( v[3], min_force, max_force ) or 0
clamp( x, min_force, max_force ),
clamp( y, min_force, max_force ),
clamp( z, min_force, max_force )
)
end

Expand Down Expand Up @@ -1330,4 +1328,4 @@ local typeIDToStringTable = {
-- Silly function to make printouts more userfriendly.
function WireLib.typeIDToString(typeID)
return typeIDToStringTable[typeID] or "unregistered type"
end
end
Loading