)
This commit is contained in:
@@ -1,40 +1,13 @@
|
||||
--@include libs/utils.txt
|
||||
--@client
|
||||
|
||||
require("libs/utils.txt")
|
||||
require("/koptilnya/libs/utils.txt")
|
||||
|
||||
EngineSound = class("EngineSound")
|
||||
|
||||
accessorFunc(EngineSound, "_masterVolume", "MasterVolume", 1)
|
||||
accessorFunc(EngineSound, "_parent", "Parent", chip())
|
||||
|
||||
function EngineSound:initialize(soundsMap)
|
||||
self._rpm = 0
|
||||
self._soundsMap = soundsMap
|
||||
self._sources = {}
|
||||
|
||||
for k, v in pairs(soundsMap) do
|
||||
bass.loadURL(v.link, "3d noblock", function(snd, err, errtxt)
|
||||
if snd then
|
||||
snd:setPos(self:getParent():getPos())
|
||||
snd:setLooping(true)
|
||||
snd:setVolume(0)
|
||||
|
||||
v.source = snd
|
||||
table.insert(self._sources, snd)
|
||||
elseif errtext then
|
||||
error(errtxt)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
hook.add("think", "EngineSound_think", function()
|
||||
for _, v in pairs(self._sources) do
|
||||
v:setPos(self:getParent():getPos())
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function fadeIn(rpm, range)
|
||||
local fadeIn = 1
|
||||
|
||||
@@ -55,19 +28,47 @@ local function fadeOut(rpm, range)
|
||||
return fadeOut
|
||||
end
|
||||
|
||||
function EngineSound:setRPM(rpm)
|
||||
self._rpm = rpm
|
||||
function EngineSound:initialize(soundsMap)
|
||||
self._rpm = 0
|
||||
self._targetRPM = 0
|
||||
self._soundsMap = soundsMap
|
||||
self._sources = {}
|
||||
|
||||
for _, v in pairs(self._soundsMap) do
|
||||
if v.source then
|
||||
local pitch = rpm / v.rootPitch
|
||||
local fadeIn = fadeIn(rpm, v.fadeIn)
|
||||
local fadeOut = fadeOut(rpm, v.fadeOut)
|
||||
|
||||
v.source:setVolume(math.max(self:getMasterVolume() * (fadeIn + fadeOut - 1), 0.01))
|
||||
v.source:setPitch(math.max(pitch, 0.01))
|
||||
end
|
||||
for k, v in pairs(soundsMap) do
|
||||
bass.loadURL(v.link, "3d noblock", function(snd, err, errtxt)
|
||||
if snd then
|
||||
snd:setPos(self:getParent():getPos())
|
||||
snd:setLooping(true)
|
||||
snd:setVolume(0)
|
||||
|
||||
v.source = snd
|
||||
table.insert(self._sources, snd)
|
||||
elseif errtext then
|
||||
error(errtxt)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
hook.add("think", "EngineSound_think", function()
|
||||
self._rpm = math.lerp(0.2, self._rpm, self._targetRPM)
|
||||
|
||||
for _, v in pairs(self._soundsMap) do
|
||||
if v.source then
|
||||
v.source:setPos(self:getParent():getPos())
|
||||
|
||||
local pitch = self._rpm / v.rootPitch
|
||||
local fadeIn = fadeIn(self._rpm, v.fadeIn)
|
||||
local fadeOut = fadeOut(self._rpm, v.fadeOut)
|
||||
|
||||
v.source:setVolume(math.max(self:getMasterVolume() * (fadeIn + fadeOut - 1), 0.01))
|
||||
v.source:setPitch(math.max(pitch, 0.01))
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function EngineSound:setRPM(rpm)
|
||||
self._targetRPM = rpm
|
||||
end
|
||||
|
||||
function EngineSound:getRPM()
|
||||
|
||||
Reference in New Issue
Block a user