| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2013 Jussi Lind <[email protected]> |
| 3 | // |
| 4 | // Dust Racing 2D 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 | // Dust Racing 2D is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | #ifndef CARSOUNDEFFECTMANAGER_HPP |
| 17 | #define CARSOUNDEFFECTMANAGER_HPP |
| 18 | |
| 19 | #include <QString> |
| 20 | #include <QTimer> |
| 21 | |
| 22 | #include "audiosource.hpp" |
| 23 | #include <Location> |
| 24 | #include <MCVector3d> |
| 25 | #include <memory> |
| 26 | |
| 27 | class Car; |
| 28 | class MCObject; |
| 29 | |
| 30 | /*! Manages sound effects, like the engine sound. These are connected |
| 31 | * to the AudioThread via Qt signals. */ |
| 32 | class CarSoundEffectManager : public AudioSource |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | |
| 36 | public: |
| 37 | /*! Handles to special sounds that can be played simultaneously by each car */ |
| 38 | struct MultiSoundHandles |
| 39 | { |
| 40 | QString engineSoundHandle; |
| 41 | QString hitSoundHandle; |
| 42 | QString skidSoundHandle; |
| 43 | }; |
| 44 | |
| 45 | //! Constructor. |
| 46 | CarSoundEffectManager(Car & car, const MultiSoundHandles & handles); |
| 47 | |
| 48 | //! Destructor. |
| 49 | virtual ~CarSoundEffectManager(); |
| 50 | |
| 51 | void update(); |
| 52 | |
| 53 | void collision(MCObject & collidingObject); |
| 54 | |
| 55 | public slots: |
| 56 | |
| 57 | void startEngineSound(); |
| 58 | |
| 59 | void stopEngineSound(); |
| 60 | |
| 61 | private: |
| 62 | void processEngineSound(); |
| 63 | |
| 64 | void processSkidSound(); |
| 65 | |
| 66 | Car & m_car; |
| 67 | |
| 68 | int m_gear; |
| 69 | |
| 70 | int m_prevSpeed; |
| 71 | |
| 72 | MCVector3dF m_prevLocation; |
| 73 | |
| 74 | QTimer m_hitTimer; |
| 75 | |
| 76 | QTimer m_skidTimer; |
| 77 | |
| 78 | MultiSoundHandles m_handles; |
| 79 | |
| 80 | bool m_skidPlaying; |
| 81 | }; |
| 82 | |
| 83 | typedef std::shared_ptr<CarSoundEffectManager> CarSoundEffectManagerPtr; |
| 84 | |
| 85 | #endif // CARSOUNDEFFECTMANAGER_HPP |