Hemiptera Bugtracker at bugs.linux-forks.de

advtrains

Re-enable looped sounds, cleanup before destroying object

Send replies to 168@bugs.linux-forks.de or using the Form below.
avatar From: OP
Sat, 12 Dec 2020 10:10:01 -0000

Hi! I think not looping the sounds really takes away from the experience

they could provide, and while I have no idea how the minetest engine

progresses on this, I don't want to wait for it if we can easily work

around it right now. I made a cleanup mod that keeps track of all sounds

attached to an object and can stop all of them before destroying the object

itself. I wish I could have just redefined `:remove()` for the objects...

well, now I learned what `userdata` means in lua.

You can find the mod at: https://gitlab.com/PeterNerlich/sound_cleanup

Here is a quick patch to re-enable loops and use the cleanup function:

diff --git a/advtrains/depends.txt b/advtrains/depends.txt

index 1815e54..b2575b0 100644

--- a/advtrains/depends.txt

+++ b/advtrains/depends.txt

@@ -1,3 +1,4 @@

default

+sound_cleanup

mesecons?

digtron?

\ No newline at end of file

diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua

index 5564fa5..e7049eb 100644

--- a/advtrains/wagons.lua

+++ b/advtrains/wagons.lua

@@ -76,7 +76,8 @@ end

function wagon:on_activate(sd_uid, dtime_s)

if sd_uid~="" then

--destroy when loaded from static block.

- self.object:remove()

+ --self.object:remove()

+ minetest.cleanup_object(self.object)

return

end

self.object:set_armor_groups({immortal=1})

@@ -265,7 +266,8 @@ function wagon:destroy()

end

--atdebug("[wagon ", self.id, "]: destroying")

- self.object:remove()

+ --self.object:remove()

+ minetest.cleanup_object(self.object)

return true

end

@@ -527,7 +529,8 @@ function wagon:on_step(dtime)

if not players_in then

if advtrains.outside_range(pos) then

--atdebug("wagon",self.id,"unloading (too far away)")

- self.object:remove()

+ --self.object:remove()

+ minetest.cleanup_object(self.object)

end

end

end

diff --git a/advtrains_train_steam/init.lua b/advtrains_train_steam/init.lua

index 057ad8f..d04077e 100755

--- a/advtrains_train_steam/init.lua

+++ b/advtrains_train_steam/init.lua

@@ -111,9 +111,9 @@ advtrains.register_wagon("detailed_steam_engine", {

end,

custom_on_step=function(self, dtime)

if self:train().velocity > 0 then -- First make sure that the train isn't

standing

- if not self.sound_loop_tmr or self.sound_loop_tmr <= 0 then

+ if not self.sound_loop_tmr or self.sound_loop_tmr <= 0 and

self.sound_loop_handle == nil then

-- start the sound if it was never started or has expired

- self.sound_loop_handle =

minetest.sound_play({name="advtrains_steam_loop", gain=2},

{object=self.object})

+ self.sound_loop_handle =

minetest.sound_play({name="advtrains_steam_loop", gain=2},

{object=self.object, loop=true})

self.sound_loop_tmr = SND_LOOP_LEN

end

--decrease the sound timer

diff --git a/advtrains_train_subway/init.lua

b/advtrains_train_subway/init.lua

index add961b..9b896b7 100644

--- a/advtrains_train_subway/init.lua

+++ b/advtrains_train_subway/init.lua

@@ -82,8 +82,8 @@ advtrains.register_wagon("subway_wagon", {

minetest.sound_stop(self.sound_arrive_handle)

self.sound_arrive_handle = nil

end

- if velocity > 0 and (self.sound_loop_tmr or 0)<=0 then

- self.sound_loop_handle =

minetest.sound_play({name="advtrains_subway_loop", gain=0.3}, {object =

self.object})

+ if velocity > 0 and (self.sound_loop_tmr or 0)<=0 and

self.sound_loop_handle == nil then

+ self.sound_loop_handle =

minetest.sound_play({name="advtrains_subway_loop", gain=0.3}, {object =

self.object, loop = true})

self.sound_loop_tmr=3

elseif velocity>0 then

self.sound_loop_tmr = self.sound_loop_tmr - dtime

Reply