Skip to content

Commit

Permalink
Minor CalcRPM optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
thecraftianman committed Nov 1, 2024
1 parent 234fc13 commit db04dc3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 7 additions & 8 deletions lua/entities/acf_engine/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AddCSLuaFile("shared.lua")
include("shared.lua")

local ACF = ACF
local Mobility = ACF.Mobility
local Mobility = ACF.Mobility
local MobilityObj = Mobility.Objects
local MaxDistance = ACF.LinkDistance * ACF.LinkDistance

Expand Down Expand Up @@ -67,7 +67,7 @@ do

local Rope

if tobool(Engine.Owner:GetInfoNum("ACF_MobilityRopeLinks", 1)) then
if tobool(Engine:CPPIGetOwner():GetInfoNum("ACF_MobilityRopeLinks", 1)) then
Rope = constraint.CreateKeyframeRope(OutPos, 1, "cable/cable2", nil, Engine, Engine.Out, 0, Target, Target.In, 0)
end

Expand All @@ -77,11 +77,11 @@ do
Link:SetTargetPos(Target.In)
Link:SetAxis(Direction)

Link.Rope = Rope
Link.RopeLen = (OutPos - InPos):Length()
Link.Rope = Rope
Link.RopeLen = (OutPos - InPos):Length()

Engine.Gearboxes[Target] = Link
Target.Engines[Engine] = true
Target.Engines[Engine] = true

Engine:UpdateOverlay()
Target:UpdateOverlay()
Expand Down Expand Up @@ -111,6 +111,7 @@ do
return true, "Engine unlinked successfully!"
end)
end

--===============================================================================================--
-- Local Funcs and Vars
--===============================================================================================--
Expand Down Expand Up @@ -531,8 +532,6 @@ function ENT:Disable()
end

function ENT:UpdateOutputs(SelfTbl)
if not IsValid(self) then return end

SelfTbl = SelfTbl or self:GetTable()
local FuelUsage = Round(SelfTbl.FuelUsage)
local Torque = SelfTbl.Torque
Expand Down Expand Up @@ -686,7 +685,7 @@ end
function ENT:GetConsumption(Throttle, RPM, FuelTank, SelfTbl)
SelfTbl = SelfTbl or self:GetTable()
FuelTank = FuelTank or SelfTbl.FuelTank
if not IsValid(FuelTank) then return 0 end
if not FuelTank and not IsValid(FuelTank) then return 0 end

if SelfTbl.FuelType == "Electric" then
return Throttle * SelfTbl.FuelUse * SelfTbl.Torque * RPM * 1.05e-4
Expand Down
9 changes: 6 additions & 3 deletions lua/entities/acf_fueltank/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -484,19 +484,21 @@ function ENT:Consume(Amount, SelfTbl)
local Fuel = Clamp(SelfTbl.Fuel - Amount, 0, SelfTbl.Capacity)
SelfTbl.Fuel = Fuel

self:UpdateOverlay()
self:UpdateMass(_, SelfTbl)

Fuel = Round(Fuel, 2)
local Activated = self:CanConsume(SelfTbl) and 1 or 0

if SelfTbl.LastFuel ~= Fuel then
SelfTbl.LastFuel = Fuel
WireLib.TriggerOutput(self, "Fuel", Fuel)

self:UpdateOverlay()
self:UpdateMass(_, SelfTbl)
end
if SelfTbl.LastActivated ~= Activated then
SelfTbl.LastActivated = Activated
WireLib.TriggerOutput(self, "Activated", Activated)

self:UpdateOverlay()
end
end

Expand Down Expand Up @@ -568,6 +570,7 @@ do
return true
end
end

function ENT:OnRemove()
local Class = self.ClassData

Expand Down

0 comments on commit db04dc3

Please sign in to comment.