diff options
Diffstat (limited to 'pacman-c++/common')
| -rw-r--r-- | pacman-c++/common/actor.cpp | 6 | ||||
| -rw-r--r-- | pacman-c++/common/audio.cpp | 109 | ||||
| -rw-r--r-- | pacman-c++/common/audio.h | 96 | ||||
| -rw-r--r-- | pacman-c++/common/audiointerface.h | 60 | ||||
| -rw-r--r-- | pacman-c++/common/common.pro | 3 | ||||
| -rw-r--r-- | pacman-c++/common/constants.h | 1 | ||||
| -rw-r--r-- | pacman-c++/common/sceneholder.cpp | 60 | ||||
| -rw-r--r-- | pacman-c++/common/sceneholder.h | 8 |
8 files changed, 202 insertions, 141 deletions
diff --git a/pacman-c++/common/actor.cpp b/pacman-c++/common/actor.cpp index 83a54e3..de8d77e 100644 --- a/pacman-c++/common/actor.cpp +++ b/pacman-c++/common/actor.cpp | |||
| @@ -296,21 +296,21 @@ void Actor::die() | |||
| 296 | setZValue(zValue() * 10); | 296 | setZValue(zValue() * 10); |
| 297 | m_dieing->start(); | 297 | m_dieing->start(); |
| 298 | if (m_local) | 298 | if (m_local) |
| 299 | AudioManager::self()->audioPlayer()->play(Sound::Die); | 299 | AudioManager::self()->play(Sound::Die); |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | void Actor::eatingFruit() | 302 | void Actor::eatingFruit() |
| 303 | { | 303 | { |
| 304 | if (!m_local) | 304 | if (!m_local) |
| 305 | return; | 305 | return; |
| 306 | AudioManager::self()->audioPlayer()->play(Sound::EatingFruit); | 306 | AudioManager::self()->play(Sound::EatingFruit); |
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | void Actor::eatingPacman() | 309 | void Actor::eatingPacman() |
| 310 | { | 310 | { |
| 311 | if (!m_local) | 311 | if (!m_local) |
| 312 | return; | 312 | return; |
| 313 | AudioManager::self()->audioPlayer()->play(Sound::EatingGhost); | 313 | AudioManager::self()->play(Sound::EatingGhost); |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | void Actor::startEating() | 316 | void Actor::startEating() |
diff --git a/pacman-c++/common/audio.cpp b/pacman-c++/common/audio.cpp index d29303d..eddbace 100644 --- a/pacman-c++/common/audio.cpp +++ b/pacman-c++/common/audio.cpp | |||
| @@ -23,7 +23,7 @@ AudioManager::AudioManager() | |||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | preload(); | 25 | preload(); |
| 26 | if (!tryLoadPhononPlugin()) | 26 | if (!tryLoadAudioPlugin("*phononplayer*")) |
| 27 | { | 27 | { |
| 28 | qWarning() << "Unable to load audio plugin. Audio disabled.."; | 28 | qWarning() << "Unable to load audio plugin. Audio disabled.."; |
| 29 | m_players.append(new NoopAudioPlayer(this)); | 29 | m_players.append(new NoopAudioPlayer(this)); |
| @@ -31,6 +31,7 @@ AudioManager::AudioManager() | |||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | AudioPlayer *firstplayer = m_factory->create(this); | 33 | AudioPlayer *firstplayer = m_factory->create(this); |
| 34 | firstplayer->setWorking(m_working); | ||
| 34 | firstplayer->test(m_sounds[Sound::EatingFruit], Sound::length[Sound::EatingFruit] * 2); | 35 | firstplayer->test(m_sounds[Sound::EatingFruit], Sound::length[Sound::EatingFruit] * 2); |
| 35 | m_working = firstplayer->isWorking(); | 36 | m_working = firstplayer->isWorking(); |
| 36 | m_players.append(firstplayer); | 37 | m_players.append(firstplayer); |
| @@ -118,6 +119,33 @@ void AudioManager::unregisterAudioPlayer(AudioPlayer *player) | |||
| 118 | m_players.removeAll(player); | 119 | m_players.removeAll(player); |
| 119 | } | 120 | } |
| 120 | 121 | ||
| 122 | |||
| 123 | void AudioManager::unregisterAudioPlayer_helper(QObject *player) | ||
| 124 | { | ||
| 125 | unregisterAudioPlayer(static_cast<AudioPlayer *>(player)); | ||
| 126 | } | ||
| 127 | |||
| 128 | void AudioManager::play(Sound::Type sound, AudioPlayer *player) | ||
| 129 | { | ||
| 130 | if (player == NULL) | ||
| 131 | player = audioPlayer(); | ||
| 132 | player->play(this->sound(sound), length(sound)); | ||
| 133 | } | ||
| 134 | |||
| 135 | void AudioManager::setSource(Sound::Type sound, AudioPlayer *player) | ||
| 136 | { | ||
| 137 | if (player == NULL) | ||
| 138 | player = audioPlayer(); | ||
| 139 | player->setSource(this->sound(sound), length(sound)); | ||
| 140 | } | ||
| 141 | |||
| 142 | void AudioManager::enqueue(Sound::Type sound, AudioPlayer *player) | ||
| 143 | { | ||
| 144 | if (player == NULL) | ||
| 145 | player = audioPlayer(); | ||
| 146 | player->enqueue(this->sound(sound), length(sound)); | ||
| 147 | } | ||
| 148 | |||
| 121 | QFile *AudioManager::sound(Sound::Type sound) | 149 | QFile *AudioManager::sound(Sound::Type sound) |
| 122 | { | 150 | { |
| 123 | if (!isWorking()) | 151 | if (!isWorking()) |
| @@ -125,9 +153,9 @@ QFile *AudioManager::sound(Sound::Type sound) | |||
| 125 | return m_sounds.at(sound); | 153 | return m_sounds.at(sound); |
| 126 | } | 154 | } |
| 127 | 155 | ||
| 128 | void AudioManager::unregisterAudioPlayer_helper(QObject *player) | 156 | unsigned int AudioManager::length(Sound::Type sound) |
| 129 | { | 157 | { |
| 130 | unregisterAudioPlayer(static_cast<AudioPlayer *>(player)); | 158 | return Sound::length[sound]; |
| 131 | } | 159 | } |
| 132 | 160 | ||
| 133 | void AudioManager::preload() | 161 | void AudioManager::preload() |
| @@ -137,13 +165,14 @@ void AudioManager::preload() | |||
| 137 | Q_ASSERT(sounds.count() > 0); | 165 | Q_ASSERT(sounds.count() > 0); |
| 138 | for(unsigned i = 1; i <= sounds.count(); ++i) | 166 | for(unsigned i = 1; i <= sounds.count(); ++i) |
| 139 | m_sounds.append(new QFile(QString(":/sound/sound%1").arg(i), this)); | 167 | m_sounds.append(new QFile(QString(":/sound/sound%1").arg(i), this)); |
| 168 | Q_ASSERT(m_sounds.count() != (sizeof(Sound::length) / sizeof(unsigned int))); | ||
| 140 | } | 169 | } |
| 141 | 170 | ||
| 142 | bool AudioManager::tryLoadPhononPlugin() | 171 | bool AudioManager::tryLoadAudioPlugin(const QString &libraryname) |
| 143 | { | 172 | { |
| 144 | QDir dir = qApp->applicationDirPath(); | 173 | QDir dir = qApp->applicationDirPath(); |
| 145 | QStringList filters; | 174 | QStringList filters; |
| 146 | filters << "*phononplayer*"; | 175 | filters << libraryname; |
| 147 | foreach (QString file, dir.entryList(filters, QDir::Files)) | 176 | foreach (QString file, dir.entryList(filters, QDir::Files)) |
| 148 | { | 177 | { |
| 149 | file = dir.absoluteFilePath(file); | 178 | file = dir.absoluteFilePath(file); |
| @@ -163,25 +192,19 @@ bool AudioManager::tryLoadPhononPlugin() | |||
| 163 | return false; | 192 | return false; |
| 164 | } | 193 | } |
| 165 | 194 | ||
| 166 | AudioPlayer *AudioManager::createAudioPlayer() | 195 | AudioPlayer *AudioManager::createAudioPlayer(QObject *parent) |
| 167 | { | 196 | { |
| 168 | if (m_factory == NULL) | 197 | if (m_factory == NULL) |
| 169 | return NULL; | 198 | return NULL; |
| 170 | 199 | ||
| 171 | AudioPlayer *player = m_factory->create(this); | 200 | AudioPlayer *player = m_factory->create(parent != NULL ? parent : this); |
| 201 | player->setWorking(m_working); | ||
| 172 | registerAudioPlayer(player); | 202 | registerAudioPlayer(player); |
| 173 | return player; | 203 | return player; |
| 174 | } | 204 | } |
| 175 | 205 | ||
| 176 | /* --------------------------------------------------------------- */ | 206 | /* --------------------------------------------------------------- */ |
| 177 | 207 | ||
| 178 | AudioPlayer *NoopAudioPlayerFactory::create(QObject *parent) | ||
| 179 | { | ||
| 180 | return new FakeAudioPlayer(parent); | ||
| 181 | } | ||
| 182 | |||
| 183 | /* --------------------------------------------------------------- */ | ||
| 184 | |||
| 185 | NoopAudioPlayer::NoopAudioPlayer(QObject *parent) | 208 | NoopAudioPlayer::NoopAudioPlayer(QObject *parent) |
| 186 | : AudioPlayer(parent), m_working(false), m_muted(false), m_playing(false), m_paused(false) | 209 | : AudioPlayer(parent), m_working(false), m_muted(false), m_playing(false), m_paused(false) |
| 187 | {} | 210 | {} |
| @@ -209,19 +232,6 @@ void NoopAudioPlayer::play() | |||
| 209 | m_playing = false; | 232 | m_playing = false; |
| 210 | } | 233 | } |
| 211 | 234 | ||
| 212 | void NoopAudioPlayer::play(Sound::Type /* sound */) | ||
| 213 | { | ||
| 214 | play(); | ||
| 215 | } | ||
| 216 | |||
| 217 | bool NoopAudioPlayer::isPlaying() | ||
| 218 | { | ||
| 219 | return m_playing; | ||
| 220 | } | ||
| 221 | |||
| 222 | void NoopAudioPlayer::enqueue(Sound::Type /* sound */) | ||
| 223 | {} | ||
| 224 | |||
| 225 | void NoopAudioPlayer::pause() | 235 | void NoopAudioPlayer::pause() |
| 226 | { | 236 | { |
| 227 | m_paused = true; | 237 | m_paused = true; |
| @@ -258,7 +268,32 @@ void NoopAudioPlayer::prefinishMarkReached_ex(qint32 mark) | |||
| 258 | emit prefinishMarkReached(mark); | 268 | emit prefinishMarkReached(mark); |
| 259 | } | 269 | } |
| 260 | 270 | ||
| 261 | void NoopAudioPlayer::test(QFile * /* testsound */, qint32 /* length */) | 271 | void NoopAudioPlayer::seek(qint64 /* time */) |
| 272 | {} | ||
| 273 | |||
| 274 | void NoopAudioPlayer::setWorking(bool working) | ||
| 275 | { | ||
| 276 | m_working = working; | ||
| 277 | } | ||
| 278 | |||
| 279 | void NoopAudioPlayer::test(QFile * /* sound */, unsigned int /* length */) | ||
| 280 | {} | ||
| 281 | |||
| 282 | void NoopAudioPlayer::play(QFile *sound, unsigned int length) | ||
| 283 | { | ||
| 284 | setSource(sound, length); | ||
| 285 | play(); | ||
| 286 | } | ||
| 287 | |||
| 288 | void NoopAudioPlayer::setSource(QFile * /* sound */, unsigned int /* length */) | ||
| 289 | {} | ||
| 290 | |||
| 291 | bool NoopAudioPlayer::isPlaying() | ||
| 292 | { | ||
| 293 | return m_playing; | ||
| 294 | } | ||
| 295 | |||
| 296 | void NoopAudioPlayer::enqueue(QFile * /* sound */, unsigned int /* length */) | ||
| 262 | {} | 297 | {} |
| 263 | 298 | ||
| 264 | /* --------------------------------------------------------------- */ | 299 | /* --------------------------------------------------------------- */ |
| @@ -270,13 +305,13 @@ FakeAudioPlayer::FakeAudioPlayer(QObject *parent) | |||
| 270 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(finished_ex())); | 305 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(finished_ex())); |
| 271 | } | 306 | } |
| 272 | 307 | ||
| 273 | void FakeAudioPlayer::play(Sound::Type sound) | 308 | void FakeAudioPlayer::play(QFile * /* sound */, unsigned int length) |
| 274 | { | 309 | { |
| 275 | m_playing = true; | 310 | m_playing = true; |
| 276 | m_paused = false; | 311 | m_paused = false; |
| 277 | 312 | ||
| 278 | m_timer.setSingleShot(true); | 313 | m_timer.setSingleShot(true); |
| 279 | unsigned int interval = Sound::length[sound]; | 314 | unsigned int interval = length; |
| 280 | /* add a small delay server side only */ | 315 | /* add a small delay server side only */ |
| 281 | if (Constants::server) | 316 | if (Constants::server) |
| 282 | interval += Constants::tick; | 317 | interval += Constants::tick; |
| @@ -299,17 +334,15 @@ GaplessAudioPlayer::GaplessAudioPlayer(Sound::Type sound, qint32 mark, QObject * | |||
| 299 | if (!m_working) | 334 | if (!m_working) |
| 300 | return; | 335 | return; |
| 301 | 336 | ||
| 302 | m_player1 = AudioManager::self()->createAudioPlayer(); | 337 | m_player1 = AudioManager::self()->createAudioPlayer(this); |
| 303 | m_player2 = AudioManager::self()->createAudioPlayer(); | 338 | m_player2 = AudioManager::self()->createAudioPlayer(this); |
| 304 | 339 | ||
| 340 | /* this doesn't work reliable on all platforms (e.g. windows) */ | ||
| 305 | m_player2->setPrefinishMark(mark); | 341 | m_player2->setPrefinishMark(mark); |
| 306 | m_player1->setPrefinishMark(mark); | 342 | m_player1->setPrefinishMark(mark); |
| 307 | 343 | ||
| 308 | connect(m_player1, SIGNAL(prefinishMarkReached(qint32)), this, SLOT(startPlayer2())); | 344 | connect(m_player1, SIGNAL(prefinishMarkReached(qint32)), this, SLOT(startPlayer2())); |
| 309 | connect(m_player2, SIGNAL(prefinishMarkReached(qint32)), this, SLOT(startPlayer1())); | 345 | connect(m_player2, SIGNAL(prefinishMarkReached(qint32)), this, SLOT(startPlayer1())); |
| 310 | |||
| 311 | AudioManager::self()->registerAudioPlayer(m_player1); | ||
| 312 | AudioManager::self()->registerAudioPlayer(m_player2); | ||
| 313 | } | 346 | } |
| 314 | 347 | ||
| 315 | bool GaplessAudioPlayer::isWorking() const | 348 | bool GaplessAudioPlayer::isWorking() const |
| @@ -350,10 +383,12 @@ void GaplessAudioPlayer::pause() | |||
| 350 | 383 | ||
| 351 | void GaplessAudioPlayer::startPlayer1() | 384 | void GaplessAudioPlayer::startPlayer1() |
| 352 | { | 385 | { |
| 353 | m_player1->play(m_sound); | 386 | AudioManager::self()->play(m_sound, m_player1); |
| 387 | m_player2->pause(); | ||
| 354 | } | 388 | } |
| 355 | 389 | ||
| 356 | void GaplessAudioPlayer::startPlayer2() | 390 | void GaplessAudioPlayer::startPlayer2() |
| 357 | { | 391 | { |
| 358 | m_player2->play(m_sound); | 392 | AudioManager::self()->play(m_sound, m_player2); |
| 393 | m_player1->pause(); | ||
| 359 | } | 394 | } |
diff --git a/pacman-c++/common/audio.h b/pacman-c++/common/audio.h index bc7d66e..45af34b 100644 --- a/pacman-c++/common/audio.h +++ b/pacman-c++/common/audio.h | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #ifndef AUDIO_H | 1 | #ifndef AUDIO_H |
| 2 | #define AUDIO_H | 2 | #define AUDIO_H |
| 3 | 3 | ||
| 4 | #include "audiointerface.h" | ||
| 4 | #include <QObject> | 5 | #include <QObject> |
| 5 | #include <QList> | 6 | #include <QList> |
| 6 | #include <QFile> | 7 | #include <QFile> |
| @@ -19,52 +20,12 @@ namespace Sound | |||
| 19 | }; | 20 | }; |
| 20 | 21 | ||
| 21 | const unsigned int length[] = { | 22 | const unsigned int length[] = { |
| 22 | 4310, 2090, 570, 570, 1720, | 23 | 4310, 2090, 570, 570, 1720, 1990 |
| 23 | }; | 24 | }; |
| 24 | }; | 25 | }; |
| 25 | 26 | ||
| 26 | /* --------------------------------------------------------------- */ | 27 | /* --------------------------------------------------------------- */ |
| 27 | 28 | ||
| 28 | class AudioPlayer | ||
| 29 | : public QObject | ||
| 30 | { | ||
| 31 | Q_OBJECT | ||
| 32 | friend class AudioManager; | ||
| 33 | |||
| 34 | public: | ||
| 35 | AudioPlayer(QObject *parent = 0) | ||
| 36 | : QObject(parent) | ||
| 37 | {} | ||
| 38 | virtual ~AudioPlayer() | ||
| 39 | {} | ||
| 40 | virtual bool isWorking() const = 0; | ||
| 41 | virtual void setMuted(bool mute = true) = 0; | ||
| 42 | virtual bool isMuted() const = 0; | ||
| 43 | virtual void play() = 0; | ||
| 44 | virtual void play(Sound::Type sound) = 0; | ||
| 45 | virtual bool isPlaying() = 0; | ||
| 46 | virtual void enqueue(Sound::Type sound) = 0; | ||
| 47 | virtual void pause() = 0; | ||
| 48 | virtual bool isPaused() = 0; | ||
| 49 | virtual void stop() = 0; | ||
| 50 | virtual bool isStopped() = 0; | ||
| 51 | virtual void clear() = 0; | ||
| 52 | virtual void clearQueue() = 0; | ||
| 53 | virtual void setPrefinishMark(qint32 msecToEnd) = 0; | ||
| 54 | |||
| 55 | protected slots: | ||
| 56 | virtual void prefinishMarkReached_ex(qint32 mark) = 0; | ||
| 57 | |||
| 58 | signals: | ||
| 59 | void finished(); | ||
| 60 | void prefinishMarkReached(qint32 mark); | ||
| 61 | |||
| 62 | protected: | ||
| 63 | virtual void test(QFile *testsound, qint32 length) = 0; | ||
| 64 | }; | ||
| 65 | |||
| 66 | /* --------------------------------------------------------------- */ | ||
| 67 | |||
| 68 | class NoopAudioPlayer | 29 | class NoopAudioPlayer |
| 69 | : public AudioPlayer | 30 | : public AudioPlayer |
| 70 | { | 31 | { |
| @@ -72,14 +33,11 @@ class NoopAudioPlayer | |||
| 72 | friend class AudioManager; | 33 | friend class AudioManager; |
| 73 | 34 | ||
| 74 | public: | 35 | public: |
| 75 | NoopAudioPlayer(QObject *parent = 0); | ||
| 76 | virtual bool isWorking() const; | 36 | virtual bool isWorking() const; |
| 77 | virtual void setMuted(bool mute = true); | 37 | virtual void setMuted(bool mute = true); |
| 78 | virtual bool isMuted() const; | 38 | virtual bool isMuted() const; |
| 79 | virtual void play(); | 39 | virtual void play(); |
| 80 | virtual void play(Sound::Type sound); | ||
| 81 | virtual bool isPlaying(); | 40 | virtual bool isPlaying(); |
| 82 | virtual void enqueue(Sound::Type sound); | ||
| 83 | virtual void pause(); | 41 | virtual void pause(); |
| 84 | virtual bool isPaused(); | 42 | virtual bool isPaused(); |
| 85 | virtual void stop(); | 43 | virtual void stop(); |
| @@ -87,14 +45,20 @@ public: | |||
| 87 | virtual void clear(); | 45 | virtual void clear(); |
| 88 | virtual void clearQueue(); | 46 | virtual void clearQueue(); |
| 89 | virtual void setPrefinishMark(qint32 msecToEnd); | 47 | virtual void setPrefinishMark(qint32 msecToEnd); |
| 48 | virtual void seek(qint64 time); | ||
| 49 | |||
| 50 | protected: | ||
| 51 | NoopAudioPlayer(QObject *parent = 0); | ||
| 52 | virtual void setWorking(bool working = true); | ||
| 53 | virtual void test(QFile *sound, unsigned int length); | ||
| 54 | virtual void play(QFile *sound, unsigned int length); | ||
| 55 | virtual void setSource(QFile *sound, unsigned int length); | ||
| 56 | virtual void enqueue(QFile *sound, unsigned int length); | ||
| 90 | 57 | ||
| 91 | protected slots: | 58 | protected slots: |
| 92 | virtual void prefinishMarkReached_ex(qint32 mark); | 59 | virtual void prefinishMarkReached_ex(qint32 mark); |
| 93 | 60 | ||
| 94 | protected: | 61 | protected: |
| 95 | virtual void test(QFile *testsound, qint32 length); | ||
| 96 | |||
| 97 | protected: | ||
| 98 | bool m_working; | 62 | bool m_working; |
| 99 | bool m_muted; | 63 | bool m_muted; |
| 100 | bool m_playing; | 64 | bool m_playing; |
| @@ -109,9 +73,9 @@ class FakeAudioPlayer | |||
| 109 | Q_OBJECT | 73 | Q_OBJECT |
| 110 | friend class AudioManager; | 74 | friend class AudioManager; |
| 111 | 75 | ||
| 112 | public: | 76 | protected: |
| 113 | FakeAudioPlayer(QObject *parent = 0); | 77 | FakeAudioPlayer(QObject *parent = 0); |
| 114 | virtual void play(Sound::Type sound); | 78 | virtual void play(QFile *sound, unsigned int length); |
| 115 | 79 | ||
| 116 | protected slots: | 80 | protected slots: |
| 117 | void finished_ex(); | 81 | void finished_ex(); |
| @@ -148,27 +112,6 @@ protected: | |||
| 148 | 112 | ||
| 149 | /* --------------------------------------------------------------- */ | 113 | /* --------------------------------------------------------------- */ |
| 150 | 114 | ||
| 151 | class AudioPlayerFactory | ||
| 152 | { | ||
| 153 | public: | ||
| 154 | virtual ~AudioPlayerFactory() | ||
| 155 | {} | ||
| 156 | virtual AudioPlayer *create(QObject *parent = 0) = 0; | ||
| 157 | }; | ||
| 158 | |||
| 159 | Q_DECLARE_INTERFACE(AudioPlayerFactory, "at.ac.tuwien.foop.pacman.AudioPlayerFactory/1.0"); | ||
| 160 | |||
| 161 | /* --------------------------------------------------------------- */ | ||
| 162 | |||
| 163 | class NoopAudioPlayerFactory | ||
| 164 | : public AudioPlayerFactory | ||
| 165 | { | ||
| 166 | public: | ||
| 167 | virtual AudioPlayer *create(QObject *parent = 0); | ||
| 168 | }; | ||
| 169 | |||
| 170 | /* --------------------------------------------------------------- */ | ||
| 171 | |||
| 172 | class AudioManager | 115 | class AudioManager |
| 173 | : public QObject | 116 | : public QObject |
| 174 | { | 117 | { |
| @@ -189,8 +132,9 @@ public: | |||
| 189 | AudioPlayer *audioPlayer(); | 132 | AudioPlayer *audioPlayer(); |
| 190 | void registerAudioPlayer(AudioPlayer *player); | 133 | void registerAudioPlayer(AudioPlayer *player); |
| 191 | void unregisterAudioPlayer(AudioPlayer *player); | 134 | void unregisterAudioPlayer(AudioPlayer *player); |
| 192 | 135 | void play(Sound::Type sound, AudioPlayer *player = NULL); | |
| 193 | QFile *sound(Sound::Type sound); | 136 | void setSource(Sound::Type sound, AudioPlayer *player = NULL); |
| 137 | void enqueue(Sound::Type sound, AudioPlayer *player = NULL); | ||
| 194 | 138 | ||
| 195 | signals: | 139 | signals: |
| 196 | void mutedChanged(bool muted); | 140 | void mutedChanged(bool muted); |
| @@ -200,8 +144,10 @@ private slots: | |||
| 200 | 144 | ||
| 201 | protected: | 145 | protected: |
| 202 | void preload(); | 146 | void preload(); |
| 203 | bool tryLoadPhononPlugin(); | 147 | bool tryLoadAudioPlugin(const QString &libraryname); |
| 204 | AudioPlayer *createAudioPlayer(); | 148 | AudioPlayer *createAudioPlayer(QObject *parent = 0); |
| 149 | QFile *sound(Sound::Type sound); | ||
| 150 | unsigned int length(Sound::Type sound); | ||
| 205 | 151 | ||
| 206 | private: | 152 | private: |
| 207 | bool m_muted; | 153 | bool m_muted; |
| @@ -212,4 +158,4 @@ private: | |||
| 212 | AudioPlayerFactory *m_factory; | 158 | AudioPlayerFactory *m_factory; |
| 213 | }; | 159 | }; |
| 214 | 160 | ||
| 215 | #endif // AUDIOPLAYER_H | 161 | #endif // AUDIO_H |
diff --git a/pacman-c++/common/audiointerface.h b/pacman-c++/common/audiointerface.h new file mode 100644 index 0000000..66679b6 --- /dev/null +++ b/pacman-c++/common/audiointerface.h | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | #ifndef AUDIOINTERFACE_H | ||
| 2 | #define AUDIOINTERFACE_H | ||
| 3 | |||
| 4 | #include <QObject> | ||
| 5 | #include <QFile> | ||
| 6 | |||
| 7 | class AudioPlayer | ||
| 8 | : public QObject | ||
| 9 | { | ||
| 10 | Q_OBJECT | ||
| 11 | friend class AudioManager; | ||
| 12 | |||
| 13 | public: | ||
| 14 | virtual ~AudioPlayer() | ||
| 15 | {} | ||
| 16 | virtual bool isWorking() const = 0; | ||
| 17 | virtual void setMuted(bool mute = true) = 0; | ||
| 18 | virtual bool isMuted() const = 0; | ||
| 19 | virtual void play() = 0; | ||
| 20 | virtual bool isPlaying() = 0; | ||
| 21 | virtual void pause() = 0; | ||
| 22 | virtual bool isPaused() = 0; | ||
| 23 | virtual void stop() = 0; | ||
| 24 | virtual bool isStopped() = 0; | ||
| 25 | virtual void clear() = 0; | ||
| 26 | virtual void clearQueue() = 0; | ||
| 27 | virtual void setPrefinishMark(qint32 msecToEnd) = 0; | ||
| 28 | virtual void seek(qint64 time) = 0; | ||
| 29 | |||
| 30 | signals: | ||
| 31 | void finished(); | ||
| 32 | void prefinishMarkReached(qint32 mark); | ||
| 33 | |||
| 34 | protected: | ||
| 35 | AudioPlayer(QObject *parent = 0) | ||
| 36 | : QObject(parent) | ||
| 37 | {} | ||
| 38 | virtual void setWorking(bool working = true) = 0; | ||
| 39 | virtual void test(QFile *sound, unsigned int length) = 0; | ||
| 40 | virtual void play(QFile *sound, unsigned int length) = 0; | ||
| 41 | virtual void setSource(QFile *sound, unsigned int length) = 0; | ||
| 42 | virtual void enqueue(QFile *sound, unsigned int length) = 0; | ||
| 43 | |||
| 44 | protected slots: | ||
| 45 | virtual void prefinishMarkReached_ex(qint32 mark) = 0; | ||
| 46 | }; | ||
| 47 | |||
| 48 | /* --------------------------------------------------------------- */ | ||
| 49 | |||
| 50 | class AudioPlayerFactory | ||
| 51 | { | ||
| 52 | public: | ||
| 53 | virtual ~AudioPlayerFactory() | ||
| 54 | {} | ||
| 55 | virtual AudioPlayer *create(QObject *parent = 0) = 0; | ||
| 56 | }; | ||
| 57 | |||
| 58 | Q_DECLARE_INTERFACE(AudioPlayerFactory, "at.ac.tuwien.foop.pacman.AudioPlayerFactory/1.0"); | ||
| 59 | |||
| 60 | #endif // AUDIOINTERFACE_H | ||
diff --git a/pacman-c++/common/common.pro b/pacman-c++/common/common.pro index 1114e17..39481c0 100644 --- a/pacman-c++/common/common.pro +++ b/pacman-c++/common/common.pro | |||
| @@ -24,7 +24,8 @@ HEADERS += pixmapitem.h \ | |||
| 24 | audio.h \ | 24 | audio.h \ |
| 25 | sceneholder.h \ | 25 | sceneholder.h \ |
| 26 | util.h \ | 26 | util.h \ |
| 27 | gameentity.h | 27 | gameentity.h \ |
| 28 | audiointerface.h | ||
| 28 | 29 | ||
| 29 | OTHER_FILES += style.qss \ | 30 | OTHER_FILES += style.qss \ |
| 30 | pacman.rc | 31 | pacman.rc |
diff --git a/pacman-c++/common/constants.h b/pacman-c++/common/constants.h index d40c39e..7f32422 100644 --- a/pacman-c++/common/constants.h +++ b/pacman-c++/common/constants.h | |||
| @@ -22,6 +22,7 @@ namespace Constants { | |||
| 22 | const unsigned int port = 7321; | 22 | const unsigned int port = 7321; |
| 23 | const unsigned int connection_timeout = 3000; | 23 | const unsigned int connection_timeout = 3000; |
| 24 | const unsigned int packet_timeout = 3000; | 24 | const unsigned int packet_timeout = 3000; |
| 25 | const unsigned int recv_interval = Constants::tick / 2; | ||
| 25 | } | 26 | } |
| 26 | 27 | ||
| 27 | namespace Game | 28 | namespace Game |
diff --git a/pacman-c++/common/sceneholder.cpp b/pacman-c++/common/sceneholder.cpp index bd9b01b..d429445 100644 --- a/pacman-c++/common/sceneholder.cpp +++ b/pacman-c++/common/sceneholder.cpp | |||
| @@ -23,7 +23,7 @@ SceneHolder::SceneHolder(QObject *parent) | |||
| 23 | void SceneHolder::reset() | 23 | void SceneHolder::reset() |
| 24 | { | 24 | { |
| 25 | processDelayedItems(); | 25 | processDelayedItems(); |
| 26 | showEatingText(false); | 26 | hideOverlayText(); |
| 27 | 27 | ||
| 28 | /* remove actors from scene so they don't get deleted during clear */ | 28 | /* remove actors from scene so they don't get deleted during clear */ |
| 29 | foreach(Actor *actor, m_actors) | 29 | foreach(Actor *actor, m_actors) |
| @@ -272,15 +272,22 @@ QList<Color::Color> &SceneHolder::eatingOrder() | |||
| 272 | return m_eatingorder; | 272 | return m_eatingorder; |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | void SceneHolder::showEatingText(bool show) | 275 | void SceneHolder::hideOverlayText() |
| 276 | { | 276 | { |
| 277 | if (!show) | 277 | if (m_overlayText->scene() == this) |
| 278 | { | 278 | removeItem(m_overlayText); |
| 279 | if (m_overlayText->scene() == this) | 279 | } |
| 280 | removeItem(m_overlayText); | 280 | |
| 281 | return; | 281 | void SceneHolder::centerOverlayText(unsigned int lines) |
| 282 | } | 282 | { |
| 283 | QFontMetrics metrics(m_overlayText->font()); | ||
| 284 | m_overlayText->setPos((width() - m_overlayText->textWidth()) / 2, (height() - metrics.height() * lines) / 2); | ||
| 285 | m_overlayText->setZValue(100); | ||
| 286 | } | ||
| 283 | 287 | ||
| 288 | void SceneHolder::showEatingText() | ||
| 289 | { | ||
| 290 | hideOverlayText(); | ||
| 284 | m_overlayText->setDefaultTextColor(Qt::black); | 291 | m_overlayText->setDefaultTextColor(Qt::black); |
| 285 | QString text = QString( | 292 | QString text = QString( |
| 286 | "<div style=\"background-color: gray;\" align=\"center\">" | 293 | "<div style=\"background-color: gray;\" align=\"center\">" |
| @@ -307,23 +314,14 @@ void SceneHolder::showEatingText(bool show) | |||
| 307 | m_overlayText->setHtml(text); | 314 | m_overlayText->setHtml(text); |
| 308 | m_overlayText->setTextWidth(150); | 315 | m_overlayText->setTextWidth(150); |
| 309 | m_overlayText->setOpacity(0.9); | 316 | m_overlayText->setOpacity(0.9); |
| 310 | 317 | centerOverlayText(lines); | |
| 311 | QFontMetrics metrics(m_overlayText->font()); | ||
| 312 | m_overlayText->setPos((width() - m_overlayText->textWidth()) / 2, (height() - metrics.height() * lines) / 2); | ||
| 313 | m_overlayText->setZValue(100); | ||
| 314 | 318 | ||
| 315 | addItem(m_overlayText); | 319 | addItem(m_overlayText); |
| 316 | } | 320 | } |
| 317 | 321 | ||
| 318 | void SceneHolder::showWaitingForPlayers(bool show) | 322 | void SceneHolder::showWaitingForPlayers() |
| 319 | { | 323 | { |
| 320 | if (!show) | 324 | hideOverlayText(); |
| 321 | { | ||
| 322 | if (m_overlayText->scene() == this) | ||
| 323 | removeItem(m_overlayText); | ||
| 324 | return; | ||
| 325 | } | ||
| 326 | |||
| 327 | m_overlayText->setDefaultTextColor(Qt::black); | 325 | m_overlayText->setDefaultTextColor(Qt::black); |
| 328 | QString text = QString( | 326 | QString text = QString( |
| 329 | "<div style=\"background-color: gray;\" align=\"center\">" | 327 | "<div style=\"background-color: gray;\" align=\"center\">" |
| @@ -335,10 +333,26 @@ void SceneHolder::showWaitingForPlayers(bool show) | |||
| 335 | m_overlayText->setHtml(text); | 333 | m_overlayText->setHtml(text); |
| 336 | m_overlayText->setTextWidth(150); | 334 | m_overlayText->setTextWidth(150); |
| 337 | m_overlayText->setOpacity(0.9); | 335 | m_overlayText->setOpacity(0.9); |
| 336 | centerOverlayText(lines); | ||
| 338 | 337 | ||
| 339 | QFontMetrics metrics(m_overlayText->font()); | 338 | addItem(m_overlayText); |
| 340 | m_overlayText->setPos((width() - m_overlayText->textWidth()) / 2, (height() - metrics.height() * lines) / 2); | 339 | } |
| 341 | m_overlayText->setZValue(100); | 340 | |
| 341 | void SceneHolder::showWonLost(bool won) | ||
| 342 | { | ||
| 343 | hideOverlayText(); | ||
| 344 | m_overlayText->setDefaultTextColor(Qt::black); | ||
| 345 | QString text = QString( | ||
| 346 | "<div style=\"background-color: gray;\" align=\"center\">" | ||
| 347 | "<br />" | ||
| 348 | "You %1!<br />" | ||
| 349 | "</div>" | ||
| 350 | ).arg((won) ? "won" : "lost"); | ||
| 351 | unsigned int lines = 3; | ||
| 352 | m_overlayText->setHtml(text); | ||
| 353 | m_overlayText->setTextWidth(150); | ||
| 354 | m_overlayText->setOpacity(0.9); | ||
| 355 | centerOverlayText(lines); | ||
| 342 | 356 | ||
| 343 | addItem(m_overlayText); | 357 | addItem(m_overlayText); |
| 344 | } | 358 | } |
diff --git a/pacman-c++/common/sceneholder.h b/pacman-c++/common/sceneholder.h index 0872837..801b98b 100644 --- a/pacman-c++/common/sceneholder.h +++ b/pacman-c++/common/sceneholder.h | |||
| @@ -24,8 +24,12 @@ public: | |||
| 24 | Color::Color color(); | 24 | Color::Color color(); |
| 25 | void setEatingOrder(QList<Color::Color> &order); | 25 | void setEatingOrder(QList<Color::Color> &order); |
| 26 | QList<Color::Color> &eatingOrder(); | 26 | QList<Color::Color> &eatingOrder(); |
| 27 | void showEatingText(bool show = true); | 27 | |
| 28 | void showWaitingForPlayers(bool show = true); | 28 | void hideOverlayText(); |
| 29 | void centerOverlayText(unsigned int lines); | ||
| 30 | void showEatingText(); | ||
| 31 | void showWaitingForPlayers(); | ||
| 32 | void showWonLost(bool won); | ||
| 29 | 33 | ||
| 30 | signals: | 34 | signals: |
| 31 | void allPointsRemoved(); | 35 | void allPointsRemoved(); |
