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

use common static values for Vector2/Vector3/CFrame #233

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@

!ModuleList.txt

Exported.rbxm
Exported.rbxm
node_modules
.env
roblox.toml
6 changes: 3 additions & 3 deletions Modules/Client/Backings/PillBackingBuilder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function PillBackingBuilder:Create(gui, options)
-- Prevent negative sizes (for circles)
local sizeConstraint = Instance.new("UISizeConstraint")
sizeConstraint.MaxSize = Vector2.new(math.huge, math.huge)
sizeConstraint.MinSize = Vector2.new(0, 0)
sizeConstraint.MinSize = Vector2.zero
sizeConstraint.Parent = pillBacking

local left = self:_createLeft(options)
Expand Down Expand Up @@ -100,7 +100,7 @@ function PillBackingBuilder:CreateVertical(gui, options)
-- Prevent negative sizes (for circles)
local sizeConstraint = Instance.new("UISizeConstraint")
sizeConstraint.MaxSize = Vector2.new(math.huge, math.huge)
sizeConstraint.MinSize = Vector2.new(0, 0)
sizeConstraint.MinSize = Vector2.zero
sizeConstraint.Parent = pillBacking

local top = self:_createTop(options)
Expand Down Expand Up @@ -163,7 +163,7 @@ function PillBackingBuilder:CreateShadow(gui, options)
-- Prevent negative sizes (for circles)
local sizeConstraint = Instance.new("UISizeConstraint")
sizeConstraint.MaxSize = Vector2.new(math.huge, math.huge)
sizeConstraint.MinSize = Vector2.new(0, 0)
sizeConstraint.MinSize = Vector2.zero
sizeConstraint.Parent = shadow

local left = self:_createLeftShadow(options)
Expand Down
4 changes: 2 additions & 2 deletions Modules/Client/Camera/Controls/CameraControls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function CameraControls:BeginDrag(beginInputObject)
end))

if self._rotatedCamera.ClassName == "SmoothRotatedCamera" then
self._rotVelocityTracker = self:_getVelocityTracker(0.05, Vector2.new())
self._rotVelocityTracker = self:_getVelocityTracker(0.05, Vector2.zero)
end

self._maid._dragMaid = maid
Expand Down Expand Up @@ -308,7 +308,7 @@ function CameraControls:_handleGamepadRotateStart()
local maid = Maid.new()

if self._rotatedCamera.ClassName == "SmoothRotatedCamera" then
self._rotVelocityTracker = self:_getVelocityTracker(0.05, Vector2.new())
self._rotVelocityTracker = self:_getVelocityTracker(0.05, Vector2.zero)
end

maid:GiveTask(RunService.Stepped:Connect(function()
Expand Down
2 changes: 1 addition & 1 deletion Modules/Client/Camera/Controls/GamepadRotateModel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end

function GamepadRotateModel:GetThumbstickDeltaAngle()
if not self._lastInputObject then
return Vector2.new()
return Vector2.zero
end

return Vector2.new(self._rampVelocityX.p, self._rampVelocityY.p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function FadeBetweenCamera:__index(index)
if animating then
return self._spring.Velocity
else
return Vector3.new(0, 0, 0)
return Vector3.zero
end
elseif index == "HasReachedTarget" then
local animating = SpringUtils.animating(self._spring)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function FadeBetweenCamera3:__index(index)
if animating then
return self._spring.Velocity
else
return Vector3.new(0, 0, 0)
return Vector3.zero
end
elseif index == "HasReachedTarget" then
local animating = SpringUtils.animating(self._spring)
Expand Down
2 changes: 1 addition & 1 deletion Modules/Client/Camera/Effects/ImpulseCamera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ImpulseCamera.ClassName = "ImpulseCamera"

function ImpulseCamera.new()
local self = setmetatable({
_spring = Spring.new(Vector3.new(0, 0, 0))
_spring = Spring.new(Vector3.zero)
}, ImpulseCamera)

self._spring.Damper = 0.5
Expand Down
4 changes: 2 additions & 2 deletions Modules/Client/Camera/Effects/LagPointCamera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LagPointCamera._OriginCamera = nil
function LagPointCamera.new(originCamera, focusCamera)
local self = setmetatable({}, LagPointCamera)

self.FocusSpring = Spring.new(Vector3.new())
self.FocusSpring = Spring.new(Vector3.zero)
self.OriginCamera = originCamera or error("Must have originCamera")
self.FocusCamera = focusCamera or error("Must have focusCamera")
self.Speed = 10
Expand All @@ -36,7 +36,7 @@ function LagPointCamera:__newindex(index, value)
rawset(self, "_" .. index, value)
self.FocusSpring.Target = self.FocusCamera.CameraState.Position
self.FocusSpring.Position = self.FocusSpring.Target
self.FocusSpring.Velocity = Vector3.new(0, 0, 0)
self.FocusSpring.Velocity = Vector3.zero
elseif index == "OriginCamera" then
rawset(self, "_" .. index, value)
elseif index == "LastFocusUpdate" or index == "FocusSpring" then
Expand Down
4 changes: 2 additions & 2 deletions Modules/Client/Camera/Effects/SmoothPositionCamera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SmoothPositionCamera.ClassName = "SmoothPositionCamera"
function SmoothPositionCamera.new(baseCamera)
local self = setmetatable({}, SmoothPositionCamera)

self.Spring = Spring.new(Vector3.new())
self.Spring = Spring.new(Vector3.zero)
self.BaseCamera = baseCamera or error("Must have BaseCamera")
self.Speed = 10

Expand All @@ -31,7 +31,7 @@ function SmoothPositionCamera:__newindex(index, value)
rawset(self, "_" .. index, value)
self.Spring.Target = self.BaseCamera.CameraState.Position
self.Spring.Position = self.Spring.Target
self.Spring.Velocity = Vector3.new(0, 0, 0)
self.Spring.Velocity = Vector3.zero
elseif index == "_lastUpdateTime" or index == "Spring" then
rawset(self, index, value)
elseif index == "Speed" or index == "Damper" or index == "Velocity" or index == "Position" then
Expand Down
4 changes: 2 additions & 2 deletions Modules/Client/Character/HumanoidMoveDirectionUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ local UserInputService = game:GetService("UserInputService")

local getRotationInXZPlane = require("getRotationInXZPlane")

local ZERO_VECTOR = Vector3.new(0, 0, 0)
local RIGHT = Vector3.new(1, 0, 0)
local ZERO_VECTOR = Vector3.zero
local RIGHT = Vector3.xAxis
local DIRECTION_INPUT_MAPS = {
[Enum.KeyCode.Left] = -RIGHT;
[Enum.KeyCode.Right] = RIGHT;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Client/Gui/UltrawideContainerUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function UltrawideContainerUtils.createContainer(parent)

local uiSizeConstraint = Instance.new("UISizeConstraint")
uiSizeConstraint.MaxSize = Vector2.new(1920, 1080)
uiSizeConstraint.MinSize = Vector2.new(0, 0)
uiSizeConstraint.MinSize = Vector2.zero
uiSizeConstraint.Parent = frame

frame.Parent = parent
Expand Down
4 changes: 4 additions & 0 deletions Modules/Client/IK/IKServiceClient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ end
--- which will override for a limited time.
-- @param position May be nil to set no position
function IKServiceClient:SetAimPosition(position, optionalPriority)
if position ~= position then
return
end

local aimer = self:GetLocalAimer()
if not aimer then
return
Expand Down
10 changes: 5 additions & 5 deletions Modules/Client/Particles/ParticleEngineClient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ function ParticleEngineClient:Add(p)
return
end

p.Position = p.Position or Vector3.new()
p.Velocity = p.Velocity or Vector3.new()
p.Position = p.Position or Vector3.zero
p.Velocity = p.Velocity or Vector3.zero
p.Size = p.Size or Vector2.new(0.2,0.2)
p.Bloom = p.Bloom or Vector2.new()
p.Gravity = p.Gravity or Vector3.new()
p.Bloom = p.Bloom or Vector2.zero
p.Gravity = p.Gravity or Vector3.zero
p.Color = p.Color or Color3.new(1,1,1)
p.Transparency = p.Transparency or 0.5

Expand Down Expand Up @@ -145,7 +145,7 @@ function ParticleEngineClient:_updatePosVel(p, dt, t)
if p.WindResistance then
wind = (particleWind(t, p.Position)*self._windSpeed - p.Velocity)*p.WindResistance
else
wind = Vector3.new()
wind = Vector3.zero
end

p.Velocity = p.Velocity + (p.Gravity + wind)*dt
Expand Down
2 changes: 1 addition & 1 deletion Modules/Client/Skybox/FakeSkyboxSide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function FakeSkyboxSide:UpdateSizing()
local Offset = Direction * self.PartWidth/2

self.Relative = CFrame.new(Direction*(self.PartSize/2) + Offset)
* CFrame.new(Vector3.new(0, 0, 0), -Direction)
* CFrame.new(Vector3.zero, -Direction)

if self.Normal == Enum.NormalId.Bottom then
-- Hack
Expand Down
10 changes: 0 additions & 10 deletions Modules/Server/IK/IKService.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Never
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local CharacterUtils = require("CharacterUtils")
local IKConstants = require("IKConstants")
local Binder = require("Binder")
local Maid = require("Maid")
Expand Down Expand Up @@ -78,15 +77,6 @@ function IKService:UpdateServerRigTarget(humanoid, target)
serverRig:SetRigTarget(target)
end

function IKService:_onServerEvent(player, target)
assert(typeof(target) == "Vector3")

local humanoid = CharacterUtils.getAlivePlayerHumanoid(player)
if not humanoid then
return
end
end

function IKService:_handlePlayerRemoving(player)
self._maid[player] = nil
end
Expand Down
5 changes: 5 additions & 0 deletions Modules/Server/IK/Rig/IKRig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ function IKRig:_onServerEvent(player, target)
assert(player == CharacterUtils.getPlayerFromCharacter(self._obj))
assert(typeof(target) == "Vector3" or target == nil)

-- Guard against NaN
if target ~= target then
return
end

self._target = target

local torso = self:GetTorso()
Expand Down
4 changes: 2 additions & 2 deletions Modules/Server/Particles/ParticleEngineServer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ function ParticleEngineServer:ParticleNew(p)
assert(self._remoteEvent)

p.Position = p.Position or error("No Position")
p.Velocity = p.Velocity or Vector3.new()
p.Velocity = p.Velocity or Vector3.zero
p.Size = p.Size or Vector2.new(0.2,0.2)
p.Bloom = p.Bloom or Vector2.new(0,0)
p.Gravity = p.Gravity or Vector3.new()
p.Gravity = p.Gravity or Vector3.zero
p.LifeTime = p.LifeTime;
p.Color = p.Color or Color3.new(1,1,1)
p.Transparency = p.Transparency or 0.5
Expand Down
4 changes: 2 additions & 2 deletions Modules/Shared/CFrame/AxisAngleUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function AxisAngleUtils.toCFrame(axisAngle, position)
if position then
return CFrame.new(position)
else
return CFrame.new()
return CFrame.identity
end
end

Expand All @@ -29,7 +29,7 @@ function AxisAngleUtils.fromCFrame(cframe)

if axisAngle ~= axisAngle then
-- warn("[AxisAngleUtils.fromCFrame] - axisAngle is NAN")
return Vector3.new(0, 0, 0), cframe.Position
return Vector3.zero, cframe.Position
end

return axisAngle, cframe.Position
Expand Down
6 changes: 3 additions & 3 deletions Modules/Shared/CFrame/SurfaceUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

local SurfaceUtils = {}

local UP = Vector3.new(0, 1, 0)
local BACK = Vector3.new(0, 0, 1)
local UP = Vector3.yAxis
local BACK = Vector3.zAxis
local EXTRASPIN = CFrame.fromEulerAnglesXYZ(math.pi/2, 0, 0)

local function getTranstionBetween(v1, v2, pitchAxis)
local dot = v1:Dot(v2)
if (dot > 0.99999) then
return CFrame.new()
return CFrame.identity
elseif (dot < -0.99999) then
return CFrame.fromAxisAngle(pitchAxis, math.pi)
end
Expand Down
2 changes: 1 addition & 1 deletion Modules/Shared/CFrame/getRotationInXZPlane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ return function(cframe)
return cframe -- we're looking straight down
end

local top = Vector3.new(0, 1, 0)
local top = Vector3.yAxis
local right = top:Cross(back)

return CFrame.new(
Expand Down
2 changes: 1 addition & 1 deletion Modules/Shared/Character/HumanoidTeleportUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function HumanoidTeleportUtils.identifySafePosition(position, raycaster)
local hitData = raycaster:FindPartOnRay(Ray.new(origin, direction))

if not hitData then
local secondHit = raycaster:FindPartOnRay(Ray.new(origin+direction - Vector3.new(0, 1, 0), -direction))
local secondHit = raycaster:FindPartOnRay(Ray.new(origin+direction - Vector3.yAxis, -direction))

-- try to identify flat surface
if secondHit then
Expand Down
2 changes: 1 addition & 1 deletion Modules/Shared/Collision/PartTouchingCalculator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function PartTouchingCalculator:CheckIfTouchingHumanoid(humanoid, parts)
end

function PartTouchingCalculator:GetCollidingPartFromParts(parts, relativeTo, padding)
relativeTo = relativeTo or CFrame.new()
relativeTo = relativeTo or CFrame.identity

local size, position = BoundingBoxUtils.getPartsBoundingBox(parts, relativeTo)

Expand Down
6 changes: 3 additions & 3 deletions Modules/Shared/Debug/Draw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function Draw.ray(ray, color, parent, meshDiameter, diameter)
rotatedPart.CastShadow = false
rotatedPart.CFrame = CFrame.new(ray.Origin, ray.Origin + ray.Direction)
rotatedPart.Transparency = 1
rotatedPart.Size = Vector3.new(1, 1, 1)
rotatedPart.Size = Vector3.one
rotatedPart.Parent = part

local lineHandleAdornment = Instance.new("LineHandleAdornment")
Expand All @@ -78,7 +78,7 @@ function Draw.ray(ray, color, parent, meshDiameter, diameter)
lineHandleAdornment.Parent = rotatedPart

local mesh = Instance.new("SpecialMesh")
mesh.Scale = Vector3.new(0, 1, 0) + Vector3.new(meshDiameter, 0, meshDiameter) / diameter
mesh.Scale = Vector3.yAxis + Vector3.new(meshDiameter, 0, meshDiameter) / diameter
mesh.Parent = part

part.Parent = parent
Expand Down Expand Up @@ -110,7 +110,7 @@ function Draw._textOnAdornee(adornee, text, color)
local billboardGui = Instance.new("BillboardGui")
billboardGui.Name = "DebugBillboardGui"
billboardGui.SizeOffset = Vector2.new(0, 0.5)
billboardGui.ExtentsOffset = Vector3.new(0, 1, 0)
billboardGui.ExtentsOffset = Vector3.yAxis
billboardGui.AlwaysOnTop = true
billboardGui.Adornee = adornee
billboardGui.StudsOffset = Vector3.new(0, 0, 0.01)
Expand Down
4 changes: 2 additions & 2 deletions Modules/Shared/Geometry/BoundingBoxUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ end

--- Gets a boundingBox for the given data
-- @param data List of things with both Size and CFrame
-- @tparam[opt=CFrame.new()] relativeTo
-- @tparam[opt=CFrame.identity] relativeTo
-- @treturn Vector3 Size
-- @treturn Position position
-- https://gist.github.com/zeux/1a67e8930df782d5474276e218831e22
function BoundingBoxUtils.getBoundingBox(data, relativeTo)
relativeTo = relativeTo or CFrame.new()
relativeTo = relativeTo or CFrame.identity
local abs = math.abs
local inf = math.huge

Expand Down
4 changes: 2 additions & 2 deletions Modules/Shared/Geometry/PartGeometry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local function IsSmoothPart(part)
return part:IsA("Part") and (part.Shape == Enum.PartType.Ball)
end

local UNIFORM_SCALE = Vector3.new(1, 1, 1)
local UNIFORM_SCALE = Vector3.one
local function GetShape(part)
for _, ch in pairs(part:GetChildren()) do
if ch:IsA("SpecialMesh") then
Expand Down Expand Up @@ -234,7 +234,7 @@ function PartGeometry.getGeometry(part, hit, cframeOverride)
-- }
--
-- local xvec = CFrame.Angles(0, math.pi/2*(orientToNumberMap[orient]-1), 0).lookVector
-- local yvec = Vector3.new(0, 1, 0)
-- local yvec = Vector3.yAxis
-- local zvec = xvec:Cross(yvec)
--
if block == Enum.CellBlock.Solid then
Expand Down
2 changes: 1 addition & 1 deletion Modules/Shared/Geometry/ScaleModel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local ScaleModel = {}

local CLASS_NAME_TO_MIN_SIZE = {
["TrussPart"] = Vector3.new(2, 2, 2);
["UnionOperation"] = Vector3.new(0, 0, 0);
["UnionOperation"] = Vector3.zero;
}

local MIN_PART_SIZE = Vector3.new(0.05, 0.05, 0.05)
Expand Down
2 changes: 1 addition & 1 deletion Modules/Shared/IK/Arm/ArmFABRIKBase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ function ArmFABRIKBase:_rebuildChain()
};
})

local chain = FABRIKChain.fromPointsConstraints(CFrame.new(), points, {
local chain = FABRIKChain.fromPointsConstraints(CFrame.identity, points, {
FABRIKShoulderConstraint.new();
FABRIKElbowConstraint.new();
FABRIKHandConstraint.new();
Expand Down
2 changes: 1 addition & 1 deletion Modules/Shared/IK/Arm/ArmIKBase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function ArmIKBase:Update()
local shoulderXAngle = self._shoulderXAngle
local elbowXAngle = self._elbowXAngle

local yrot = CFrame.new(Vector3.new(), self._offset)
local yrot = CFrame.new(Vector3.zero, self._offset)

self._shoulderTransform = (yrot * CFA_90X * CFrame.Angles(shoulderXAngle, 0, 0)) --:inverse()
self._elbowTransform = CFrame.Angles(elbowXAngle, 0, 0)
Expand Down
Loading