From 5e3f4c12d87d3e7b0172b545229df70aa095b763 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Thu, 3 Feb 2022 17:59:43 -0300 Subject: [PATCH] sound fix --- automobiles_buggy/buggy_entities.lua | 7 ++++++- automobiles_buggy/buggy_utilities.lua | 4 ++-- automobiles_roadster/roadster_entities.lua | 7 ++++++- automobiles_roadster/roadster_utilities.lua | 4 ++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/automobiles_buggy/buggy_entities.lua b/automobiles_buggy/buggy_entities.lua index 4692dee..d36d5be 100755 --- a/automobiles_buggy/buggy_entities.lua +++ b/automobiles_buggy/buggy_entities.lua @@ -288,6 +288,7 @@ minetest.register_entity("automobiles_buggy:buggy", { _light_old_pos = nil, _last_ground_check = 0, _last_light_move = 0, + _last_engine_sound_update = 0, get_staticdata = function(self) -- unloaded/unloads ... is now saved return minetest.serialize({ @@ -596,7 +597,11 @@ minetest.register_entity("automobiles_buggy:buggy", { if self.sound_handle then minetest.sound_stop(self.sound_handle) end --minetest.chat_send_player(self.driver_name, "Out of fuel") else - buggy.engine_set_sound_and_animation(self, longit_speed) + self._last_engine_sound_update = self._last_engine_sound_update + dtime + if self._last_engine_sound_update > 0.300 then + self._last_engine_sound_update = 0 + buggy.engine_set_sound_and_animation(self, longit_speed) + end end local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy) diff --git a/automobiles_buggy/buggy_utilities.lua b/automobiles_buggy/buggy_utilities.lua index d70dd3a..524b8d3 100755 --- a/automobiles_buggy/buggy_utilities.lua +++ b/automobiles_buggy/buggy_utilities.lua @@ -57,10 +57,10 @@ end function buggy.engine_set_sound_and_animation(self, _longit_speed) --minetest.chat_send_all('test1 ' .. dump(self._engine_running) ) if self.sound_handle then - if (math.abs(self._longit_speed) > math.abs(_longit_speed) + 0.08) or (math.abs(self._longit_speed) + 0.08 < math.abs(_longit_speed)) then + --if (math.abs(self._longit_speed) > math.abs(_longit_speed) + 0.08) or (math.abs(self._longit_speed) + 0.08 < math.abs(_longit_speed)) then --minetest.chat_send_all('test2') buggy.engineSoundPlay(self) - end + --end end end diff --git a/automobiles_roadster/roadster_entities.lua b/automobiles_roadster/roadster_entities.lua index 49eeace..b49efd1 100755 --- a/automobiles_roadster/roadster_entities.lua +++ b/automobiles_roadster/roadster_entities.lua @@ -270,6 +270,7 @@ minetest.register_entity("automobiles_roadster:roadster", { _light_old_pos = nil, _last_ground_check = 0, _last_light_move = 0, + _last_engine_sound_update = 0, get_staticdata = function(self) -- unloaded/unloads ... is now saved return minetest.serialize({ @@ -569,7 +570,11 @@ minetest.register_entity("automobiles_roadster:roadster", { if self.sound_handle then minetest.sound_stop(self.sound_handle) end --minetest.chat_send_player(self.driver_name, "Out of fuel") else - roadster.engine_set_sound_and_animation(self, longit_speed) + self._last_engine_sound_update = self._last_engine_sound_update + dtime + if self._last_engine_sound_update > 0.300 then + self._last_engine_sound_update = 0 + roadster.engine_set_sound_and_animation(self, longit_speed) + end end local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy) diff --git a/automobiles_roadster/roadster_utilities.lua b/automobiles_roadster/roadster_utilities.lua index a5991a7..ff4ab29 100755 --- a/automobiles_roadster/roadster_utilities.lua +++ b/automobiles_roadster/roadster_utilities.lua @@ -55,10 +55,10 @@ end function roadster.engine_set_sound_and_animation(self, _longit_speed) --minetest.chat_send_all('test1 ' .. dump(self._engine_running) ) if self.sound_handle then - if (math.abs(self._longit_speed) > math.abs(_longit_speed) + 0.08) or (math.abs(self._longit_speed) + 0.08 < math.abs(_longit_speed)) then + --if (math.abs(self._longit_speed) > math.abs(_longit_speed) + 0.08) or (math.abs(self._longit_speed) + 0.08 < math.abs(_longit_speed)) then --minetest.chat_send_all('test2') roadster.engineSoundPlay(self) - end + --end end end