local p=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local N=game:GetService("\082\117\110\083\101\114\118\105\099\101")local q=p("\083\117\109\109\101\100\067\097\109\101\114\097")local k=p("\077\097\105\100")local a={}a.ClassName="\072\101\097\114\116\098\101\097\116\067\097\109\101\114\097"a.ProfileName="\072\101\097\114\116\098\101\097\116\067\097\109\101\114\097"function a.new(p)local q=setmetatable({},a)q.Camera=p or error("\078\111 \099\097\109\101\114\097")q.Maid=k.new()q.CurrentStateCache=q.Camera.CameraState or error("\067\097\109\101\114\097 \115\116\097\116\101 \114\101\116\117\114\110\101\100 \110\117\108\108")q.Maid.Heartbeat=N.Heartbeat:Connect(function()debug.profilebegin(q.ProfileName)q.CurrentStateCache=q.Camera.CameraState or error("\067\097\109\101\114\097 \115\116\097\116\101 \114\101\116\117\114\110\101\100 \110\117\108\108")debug.profileend()end)return q end function a.__add(N,p)return q.new(N,p)end function a.ForceUpdateCache(p)p.CurrentStateCache=p.Camera.CameraState end function a.__index(N,p)if p=="\083\116\097\116\101"or p=="\067\097\109\101\114\097\083\116\097\116\101"or p=="\067\097\109\101\114\097"then return N.CurrentStateCache elseif p=="\070\111\099\117\115"then return N.FocusCamera.CameraState elseif p=="\079\114\105\103\105\110"then return N.OriginCamera.CameraState else return a[p]end end function a.Destroy(p)p.Maid:DoCleaning()end return a
-- Update on heartbeat, must GC this camera state, unlike others. This
-- allows for camera effects to run on heartbeat and cache information once instead
-- of potentially going deeep into a tree and getting invoked multiple times
-- @classmod HeartbeatCamera

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local RunService = game:GetService("RunService")

local SummedCamera = require("SummedCamera")
local Maid = require("Maid")

local HeartbeatCamera = {}
HeartbeatCamera.ClassName = "HeartbeatCamera"
HeartbeatCamera.ProfileName = "HeartbeatCamera"

function HeartbeatCamera.new(Camera)
	local self = setmetatable({}, HeartbeatCamera)

	self.Camera = Camera or error("No camera")
	self.Maid = Maid.new()

	self.CurrentStateCache = self.Camera.CameraState or error("Camera state returned null")
	self.Maid.Heartbeat = RunService.Heartbeat:Connect(function()
		debug.profilebegin(self.ProfileName)
		self.CurrentStateCache = self.Camera.CameraState or error("Camera state returned null")
		debug.profileend()
	end)

	return self
end

function HeartbeatCamera:__add(other)
	return SummedCamera.new(self, other)
end

function HeartbeatCamera:ForceUpdateCache()
	self.CurrentStateCache = self.Camera.CameraState
end

function HeartbeatCamera:__index(index)
	if index == "State" or index == "CameraState" or index == "Camera" then
		return self.CurrentStateCache
	elseif index == "Focus" then
		return self.FocusCamera.CameraState
	elseif index == "Origin" then
		return self.OriginCamera.CameraState
	else
		return HeartbeatCamera[index]
	end
end

function HeartbeatCamera:Destroy()
	self.Maid:DoCleaning()
end

return HeartbeatCamera