sound_object.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SuperTux
  2. // Copyright (C) 2023 mrkubax10 <mrkubax10@onet.pl>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #ifndef HEADER_SUPERTUX_SOUND_OBJECT_HPP
  17. #define HEADER_SUPERTUX_SOUND_OBJECT_HPP
  18. #include "supertux/game_object.hpp"
  19. #include "squirrel/exposed_object.hpp"
  20. #include "scripting/sound_object.hpp"
  21. class ReaderMapping;
  22. class SoundSource;
  23. /** Plays sound at given interval with specified volume hearable in entire Sector */
  24. class SoundObject final : public GameObject,
  25. public ExposedObject<SoundObject, scripting::SoundObject>
  26. {
  27. public:
  28. SoundObject(const ReaderMapping& mapping);
  29. SoundObject(float vol, const std::string& file);
  30. ~SoundObject() override;
  31. virtual void draw(DrawingContext& context) override {}
  32. virtual void update(float dt_sec) override;
  33. static std::string class_name() { return "sound-object"; }
  34. virtual std::string get_class_name() const override { return class_name(); }
  35. static std::string display_name() { return _("Sound"); }
  36. virtual std::string get_display_name() const override { return display_name(); }
  37. virtual const std::string get_icon_path() const override { return "images/engine/editor/sound.png"; }
  38. virtual ObjectSettings get_settings() override;
  39. virtual void stop_looping_sounds() override;
  40. virtual void play_looping_sounds() override;
  41. /** @name Scriptable methods
  42. @{ */
  43. void set_volume(float volume);
  44. float get_volume() const { return m_volume; }
  45. /** @} */
  46. private:
  47. std::string m_sample;
  48. std::unique_ptr<SoundSource> m_sound_source;
  49. float m_volume;
  50. bool m_started;
  51. private:
  52. void prepare_sound_source();
  53. private:
  54. SoundObject(const SoundObject&) = delete;
  55. SoundObject& operator=(const SoundObject&) = delete;
  56. };
  57. #endif
  58. /* EOF */