1 | // SuperTux |
2 | // Copyright (C) 2006 Matthias Braun <matze@braunis.de> |
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 | |
17 | /** |
18 | * Ambient Sound Source, gamma version. Features: |
19 | * |
20 | * - "rounded rectangle" geometry with position, dimension and |
21 | * "rounding radius" (extending in all directions) of a 100% |
22 | * volume area, adjustable maximum volume, inverse square |
23 | * falloff outside area. |
24 | * |
25 | * - degenerates gracefully to a disc for dimension=0 |
26 | * |
27 | * - parameters: |
28 | * |
29 | * x, y position |
30 | * width, height dimension |
31 | * distance_factor high = steep falloff |
32 | * distance_bias high = big "100% disc" |
33 | * silence_distance defaults reasonably. |
34 | * sample sample to be played back in loop mode |
35 | * |
36 | * basti_ |
37 | */ |
38 | |
39 | #ifndef HEADER_SUPERTUX_OBJECT_AMBIENT_SOUND_HPP |
40 | #define |
41 | |
42 | #include "math/vector.hpp" |
43 | #include "supertux/moving_object.hpp" |
44 | #include "scripting/ambient_sound.hpp" |
45 | #include "squirrel/exposed_object.hpp" |
46 | |
47 | class GameObject; |
48 | class ReaderMapping; |
49 | class SoundSource; |
50 | |
51 | class AmbientSound final : public MovingObject, |
52 | public ExposedObject<AmbientSound, scripting::AmbientSound> |
53 | { |
54 | public: |
55 | AmbientSound(const ReaderMapping& mapping); |
56 | AmbientSound(const Vector& pos, float factor, float bias, float vol, const std::string& file); |
57 | ~AmbientSound(); |
58 | |
59 | virtual HitResponse collision(GameObject& other, const CollisionHit& hit_) override; |
60 | |
61 | virtual std::string get_class() const override { return "ambient-sound" ; } |
62 | virtual std::string get_display_name() const override { return _("Ambient Sound" ); } |
63 | virtual bool has_variable_size() const override { return true; } |
64 | |
65 | /** @name Scriptable Methods |
66 | @{ */ |
67 | #ifndef SCRIPTING_API |
68 | virtual void set_pos(const Vector& pos) override; |
69 | #endif |
70 | void set_pos(float x, float y); |
71 | float get_pos_x() const; |
72 | float get_pos_y() const; |
73 | /** @} */ |
74 | |
75 | virtual void draw(DrawingContext& context) override; |
76 | |
77 | virtual ObjectSettings get_settings() override; |
78 | virtual void after_editor_set() override; |
79 | |
80 | protected: |
81 | virtual void update(float dt_sec) override; |
82 | virtual void start_playing(); |
83 | virtual void stop_playing(); |
84 | |
85 | private: |
86 | std::string sample; |
87 | std::unique_ptr<SoundSource> sound_source; |
88 | int latency; |
89 | |
90 | float distance_factor; /// distance scaling |
91 | float distance_bias; /// 100% volume disc radius |
92 | float silence_distance; /// not implemented yet |
93 | |
94 | float maximumvolume; /// maximum volume |
95 | float targetvolume; /// how loud we want to be |
96 | float currentvolume; /// how loud we are |
97 | |
98 | private: |
99 | AmbientSound(const AmbientSound&) = delete; |
100 | AmbientSound& operator=(const AmbientSound&) = delete; |
101 | }; |
102 | |
103 | #endif |
104 | |
105 | /* EOF */ |
106 | |