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

Fixed loop sound bug #580

Open
wants to merge 1 commit into
base: dev
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
2 changes: 1 addition & 1 deletion lua/entities/gmod_subway_81-714_lvz/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function ENT:Think()
else
self:SetPackedRatio("BLPressure", Pneumatic.BrakeLinePressure/16.0)
end
self:SetPackedRatio("TLPressure", Pneumatic.TrainLinePressure/16.0)
self:SetPackedRatio("TLPressure", Pneumatic.AuxiliaryLinePressure/16.0)
self:SetPackedRatio("BCPressure", Pneumatic.BrakeCylinderPressure/6.0)

self:SetPackedRatio("BatteryVoltage",Panel["V1"]*self.Battery.Voltage/150.0)
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/gmod_subway_81-714_mvm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ function ENT:Think()
else
self:SetPackedRatio("BLPressure", Pneumatic.BrakeLinePressure/16.0)
end
self:SetPackedRatio("TLPressure", Pneumatic.TrainLinePressure/16.0)
self:SetPackedRatio("TLPressure", Pneumatic.AuxiliaryLinePressure/16.0)
self:SetPackedRatio("BCPressure", Pneumatic.BrakeCylinderPressure/6.0)

----------------------------------*****************************--------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/gmod_subway_81-717_lvz/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ function ENT:Think()
else
self:SetPackedRatio("BLPressure", self.Pneumatic.BrakeLinePressure/16.0)
end
self:SetPackedRatio("TLPressure", self.Pneumatic.TrainLinePressure/16.0)
self:SetPackedRatio("TLPressure", self.Pneumatic.AuxiliaryLinePressure/16.0)
self:SetPackedRatio("BCPressure", self.Pneumatic.BrakeCylinderPressure/6.0)
self:SetPackedRatio("EnginesVoltage", self.Electric.Aux750V/1000.0)
self:SetPackedRatio("EnginesCurrent2", 0.5 + 0.5*(self.Electric.I13/500.0))
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/gmod_subway_81-717_mvm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ function ENT:Think()
else
self:SetPackedRatio("BLPressure", Pneumatic.BrakeLinePressure/16.0)
end
self:SetPackedRatio("TLPressure", Pneumatic.TrainLinePressure/16.0)
self:SetPackedRatio("TLPressure", Pneumatic.AuxiliaryLinePressure/16.0)
self:SetPackedRatio("BCPressure", Pneumatic.BrakeCylinderPressure/6.0)
self:SetPackedRatio("EnginesVoltage", self.Electric.Aux750V/1000.0)
self:SetPackedRatio("EnginesCurrent2", 0.5 + 0.5*(self.Electric.I13/500.0))
Expand Down
37 changes: 27 additions & 10 deletions lua/entities/gmod_subway_base/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1089,22 +1089,26 @@ function ENT:Think()
for i,stbl in ipairs(v) do
local snd = stbl.sound
if not IsValid(snd) then continue end
if k == "horn" and v[1].state and IsValid(v[3].sound) and v[3].sound:GetState() == GMOD_CHANNEL_PLAYING then
v[3].sound:Pause()
v[3].sound:SetTime(0)
end
if snd:GetState() == GMOD_CHANNEL_PLAYING then
self:SetPitchVolume(snd,v.pitch or 1,stbl.volume,tbl)
if stbl.volume == 0 and not stbl.time then
snd:Pause()
snd:SetTime(0)
end
end
if snd:GetState() ~= GMOD_CHANNEL_PLAYING and stbl.volume ~= 0 then
if snd:GetState() ~= GMOD_CHANNEL_PLAYING and stbl.volume ~= 0 and not stbl.state then
stbl.volume = 0
end
if stbl.time then
local targetvol = stbl.state and v.volume or 0
if stbl.time == true then
stbl.volume = targetvol
else
stbl.volume = math.Clamp((stbl.volume or 0) + FrameTime()/(stbl.time/v.pitch)*(stbl.state and 1 or -1)*v.volume,0,v.volume)
stbl.volume = math.Clamp((stbl.volume or 0) + FrameTime()/(stbl.time/(v.pitch))*(stbl.state and 1 or -1)*v.volume,0,v.volume)
end
if stbl.volume == targetvol then
stbl.time = nil
Expand All @@ -1113,11 +1117,15 @@ function ENT:Think()

if i==1 then
local no1 = ntbl.loop and ntbl.loop==0
local endt = (ntbl.loop and snd:GetTime() > ntbl.loop or snd:GetTime()/snd:GetLength() >= 0.8) or no1
if stbl.state and stbl.volume < v.volume and not no1 then
local endt
if k ~= "horn" then
endt = (ntbl.loop and snd:GetTime() > ntbl.loop or snd:GetTime()/snd:GetLength() >= 0.8) or no1
end
if stbl.state and stbl.volume ~= v.volume and not no1 then
if snd:GetState() ~= GMOD_CHANNEL_PLAYING then
snd:Play()
self:SetBASSPos(snd,tbl)
if k == "horn" then self._HornLoopTime = CurTime() end
end
stbl.volume = v.volume
self:SetPitchVolume(snd,v.pitch,stbl.volume,tbl)
Expand All @@ -1134,16 +1142,21 @@ function ENT:Think()
end
stbl.time = nil
end
if k == "horn" and self._HornLoopTime then
endt = ntbl.loop and (CurTime() - self._HornLoopTime > ntbl.loop) or (CurTime() - self._HornLoopTime > snd:GetLength()*0.8)--0.3
end
if stbl.state and endt then
stbl.state = false
if k == "horn" then self._HornLoopTime = false end
if no1 then
stbl.time = true
v[2].state = not v[3].state
end
end

if not stbl.state and stbl.volume == v.volume and not stbl.time then
stbl.time = not ntbl.loop or 0.1/v.pitch--endt and (snd:GetLength()-snd:GetTime())*0.8 or 0.05
--stbl.time = not ntbl.loop or 0.1/v.pitch--endt and (snd:GetLength()-snd:GetTime())*0.8 or 0.05
stbl.time = not ntbl.loop or 0.07/v.pitch
v[2].state = not v[3].state
end
end
Expand All @@ -1157,7 +1170,7 @@ function ENT:Think()
if v[1].time == true then
stbl.volume = v.volume
elseif v[1].time then
stbl.time = v[1].time
stbl.time = v[1].time*0.1
stbl.volume = 0
end
self:SetPitchVolume(snd,v.pitch,stbl.volume,tbl)
Expand All @@ -1168,15 +1181,19 @@ function ENT:Think()
end
if i==3 then
local time = v[2].time or v[1].time
local hlt = self._HornLoopTime3 or CurTime()
local timelim = (k == "horn") and ((CurTime()-hlt) > snd:GetLength()*0.9) or (snd:GetTime()/snd:GetLength()>=0.9)
--вот тут сомнительное место: time вполне может стать false раньше, чем это нужно
if stbl.state and time and not stbl.time then
if snd:GetState() ~= GMOD_CHANNEL_PLAYING then
snd:Play()
self:SetBASSPos(snd,tbl)
if k == "horn" then self._HornLoopTime3 = CurTime() end
end
stbl.volume = 0
self:SetPitchVolume(snd,v.pitch,stbl.volume,tbl)

stbl.time = 0.1/v.pitch
--stbl.time = 0.1/v.pitch
stbl.time = 0.07/v.pitch
for i=1,2 do
if v[i].volume > 0 then
v[i].time=0.07/v.pitch
Expand All @@ -1187,10 +1204,10 @@ function ENT:Think()
self:SetPitchVolume(v[i].sound,v.pitch,v[i].volume,tbl)
end
end
elseif (not stbl.state or (snd:GetTime()/snd:GetLength() >= 0.9)) and stbl.time then
elseif (not stbl.state or timelim) and stbl.time then
stbl.time = nil
stbl.volume = 0
stbl.state = false
if k == "horn" then self._HornLoopTime3 = false end
end
end
end
Expand Down
10 changes: 9 additions & 1 deletion lua/metrostroi/systems/sys_81_717_pneumatic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function TRAIN_SYSTEM:Initialize(parameters)
-- Pressure in trains brake line
self.BrakeLinePressure = 0.0 -- atm
self.EPKPressure = 0.0 -- atm
-- Pressure in train's auxiliary line
self.AuxiliaryLinePressure = 8.0 -- atm
-- Pressure in brake cylinder
self.BrakeCylinderPressure = 0.0 -- atm
-- Pressure in the door line
Expand Down Expand Up @@ -155,7 +157,7 @@ end

function TRAIN_SYSTEM:Outputs()
return { "BrakeLinePressure", "BrakeCylinderPressure", "DriverValvePosition",
"ReservoirPressure", "TrainLinePressure", "DoorLinePressure", "WeightLoadRatio", "WorkingChamberPressure" }
"ReservoirPressure", "TrainLinePressure", "DoorLinePressure", "WeightLoadRatio", "WorkingChamberPressure", "AuxiliaryLinePressure" }
end

function TRAIN_SYSTEM:TriggerInput(name,value)
Expand Down Expand Up @@ -324,6 +326,7 @@ function TRAIN_SYSTEM:Think(dT)
self.BrakeCylinderPressure_dPdT = 0.0
self.ParkingBrakePressure_dPdT = 0.0
self.WorkingChamberPressure_dPdT = 0.0
self.AuxiliaryLinePressure_dPdT = 0.0

local rnd = math.random(1,10)
local offs = 0.1
Expand Down Expand Up @@ -622,6 +625,11 @@ function TRAIN_SYSTEM:Think(dT)
Train.SQ3:TriggerInput("Set", Train.PassengerDoor and 0 or 1)

----------------------------------------------------------------------------
-- Simulate air pressure drop while the horn is engaged
local horny = self.Train:GetNW2Bool("HornState",false)
self:equalizePressure(dT,"AuxiliaryLinePressure", horny and math.max(0,self.TrainLinePressure - 0.3) or self.TrainLinePressure, 22) --was 12
self.TrainLinePressure = self.TrainLinePressure - (horny and 0.012 or 0)

-- Simulate doors opening, closing
if self.DoorLinePressure > 3.5 then
if (Train.VDOL.Value == 1.0) and (Train.VDOP.Value == 0.0) and not self.DoorLeft then
Expand Down