Fix steam engine sound playing forever (H#121)
parent
7082038f75
commit
35a6f14561
|
@ -5,6 +5,9 @@ else
|
||||||
S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
|
S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- length of the steam engine loop sound
|
||||||
|
local SND_LOOP_LEN = 5
|
||||||
|
|
||||||
advtrains.register_wagon("newlocomotive", {
|
advtrains.register_wagon("newlocomotive", {
|
||||||
mesh="advtrains_engine_steam.b3d",
|
mesh="advtrains_engine_steam.b3d",
|
||||||
textures = {"advtrains_engine_steam.png"},
|
textures = {"advtrains_engine_steam.png"},
|
||||||
|
@ -111,13 +114,19 @@ advtrains.register_wagon("detailed_steam_engine", {
|
||||||
self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
|
self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
|
||||||
self.old_anim_velocity=advtrains.abs_ceil(velocity)
|
self.old_anim_velocity=advtrains.abs_ceil(velocity)
|
||||||
end
|
end
|
||||||
if velocity > 0 and not self.sound_loop_handle then
|
end,
|
||||||
self.sound_loop_handle = minetest.sound_play({name="advtrains_steam_loop", gain=2}, {object = self.object, loop=true})
|
custom_on_step=function(self, dtime)
|
||||||
elseif velocity==0 then
|
if self:train().velocity > 0 then -- First make sure that the train isn't standing
|
||||||
if self.sound_loop_handle then
|
if not self.sound_loop_tmr or self.sound_loop_tmr <= 0 then
|
||||||
minetest.sound_stop(self.sound_loop_handle)
|
-- start the sound if it was never started or has expired
|
||||||
self.sound_loop_handle = nil
|
self.sound_loop_handle = minetest.sound_play({name="advtrains_steam_loop", gain=2}, {object=self.object})
|
||||||
|
self.sound_loop_tmr = SND_LOOP_LEN
|
||||||
end
|
end
|
||||||
|
--decrease the sound timer
|
||||||
|
self.sound_loop_tmr = self.sound_loop_tmr - dtime
|
||||||
|
else
|
||||||
|
-- If the train is standing, the sound will be stopped in some time. We do not need to interfere with it.
|
||||||
|
self.sound_loop_tmr = nil
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
custom_on_activate = function(self, staticdata_table, dtime_s)
|
custom_on_activate = function(self, staticdata_table, dtime_s)
|
||||||
|
|
Loading…
Reference in New Issue