aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2019-09-02 17:57:36 +0200
committerEugene Sandulenko2019-11-13 22:07:08 +0100
commit297fd21e76dd74717a63ecb536bc3fe68d761e0d (patch)
tree155b4be161544610fb3cbe7fbae5e999ecb99a07
parent204c7893c0d4ce84bac6ceadc060a3abbb091bd8 (diff)
downloadscummvm-rg350-297fd21e76dd74717a63ecb536bc3fe68d761e0d.tar.gz
scummvm-rg350-297fd21e76dd74717a63ecb536bc3fe68d761e0d.tar.bz2
scummvm-rg350-297fd21e76dd74717a63ecb536bc3fe68d761e0d.zip
GRIFFON: Move sound-related method to separate file
-rw-r--r--engines/griffon/engine.cpp160
-rw-r--r--engines/griffon/griffon.h2
-rw-r--r--engines/griffon/module.mk3
-rw-r--r--engines/griffon/sound.cpp202
4 files changed, 207 insertions, 160 deletions
diff --git a/engines/griffon/engine.cpp b/engines/griffon/engine.cpp
index 4478c757a4..0cfffac761 100644
--- a/engines/griffon/engine.cpp
+++ b/engines/griffon/engine.cpp
@@ -34,10 +34,6 @@
*
*/
-#include "audio/audiostream.h"
-#include "audio/decoders/vorbis.h"
-#include "common/memstream.h"
-
#include "griffon/griffon.h"
#include "griffon/config.h"
#include "griffon/console.h"
@@ -100,72 +96,6 @@ enum {
*/
-void GriffonEngine::setChannelVolume(int channel, int volume) {}
-
-int GriffonEngine::getSoundHandle() {
- for (uint i = 0; i < kSoundHandles; i++) {
- if (!_mixer->isSoundHandleActive(_handles[i])) {
- return i;
- }
- }
-
- error("getSoundHandle(): Too many sound handles");
-
- return -1;
-}
-
-int GriffonEngine::playSound(DataChunk *chunk, bool looped) {
- int ch = getSoundHandle();
-
-#ifdef USE_VORBIS
- Audio::SeekableAudioStream *audioStream = Audio::makeVorbisStream(new Common::MemoryReadStream(chunk->data, chunk->size), DisposeAfterUse::YES);
-
-
- if (looped) {
- Audio::AudioStream *loopingStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
- _mixer->playStream(Audio::Mixer::kSFXSoundType, &_handles[ch], loopingStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES, false, false);
-
- } else {
- _mixer->playStream(Audio::Mixer::kSFXSoundType, &_handles[ch], audioStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES, false, false);
- }
-#endif // USE_VORBIS
-
- return ch;
-}
-
-void GriffonEngine::pauseSoundChannel(int channel) {
- _mixer->pauseHandle(_handles[channel], true);
-}
-
-void GriffonEngine::haltSoundChannel(int channel) {
- _mixer->stopHandle(_handles[channel]);
-}
-
-void GriffonEngine::resumeSoundChannel(int channel) {
- _mixer->pauseHandle(_handles[channel], false);
-}
-
-bool GriffonEngine::isSoundChannelPlaying(int channel) {
- return _mixer->isSoundHandleActive(_handles[channel]);
-}
-
-DataChunk *cacheSound(const char *name) {
- Common::File file;
- DataChunk *res = new DataChunk;
-
- file.open(name);
- if (!file.isOpen())
- error("Cannot open file %s", name);
-
- res->size = file.size();
- res->data = (byte *)malloc(res->size);
-
- file.read(res->data, res->size);
-
- return res;
-}
-
-
void GriffonEngine::griffon_main() {
sys_initialize();
game_showlogos();
@@ -335,7 +265,7 @@ void game_fillrect(Graphics::TransparentSurface *surface, int x, int y, int w, i
surface->fillRect(Common::Rect(x, y, x + w, y + h), color);
}
-Graphics::TransparentSurface *IMG_Load(const char *name, bool colorkey = false) {
+Graphics::TransparentSurface *GriffonEngine::IMG_Load(const char *name, bool colorkey) {
Common::File file;
file.open(name);
@@ -8061,94 +7991,6 @@ void GriffonEngine::sys_print(Graphics::TransparentSurface *buffer, const char *
}
}
-void GriffonEngine::sys_progress(int w, int wm) {
- long ccc = _videobuffer->format.RGBToColor(0, 255, 0);
-
- rcDest.setWidth(w * 74 / wm);
- _videobuffer->fillRect(rcDest, ccc);
-
- g_system->copyRectToScreen(_videobuffer->getPixels(), _videobuffer->pitch, 0, 0, _videobuffer->w, _videobuffer->h);
- g_system->updateScreen();
-
- g_system->getEventManager()->pollEvent(_event);
-}
-
-void GriffonEngine::sys_setupAudio() {
- // FIXME
- //Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024);
-
- //atexit(Mix_Quit);
- //atexit(Mix_CloseAudio);
-
- const char *stri = "Loading...";
- sys_print(_videobuffer, stri, 160 - 4 * strlen(stri), 116, 0);
-
- Graphics::TransparentSurface *loadimg = IMG_Load("art/load.bmp", true);
-
- rcSrc.left = 0;
- rcSrc.top = 0;
- rcSrc.setWidth(88);
- rcSrc.setHeight(32);
-
- rcDest.left = 160 - 44;
- rcDest.top = 116 + 12;
-
- loadimg->setAlpha(160, true); // 128
- loadimg->blit(*_videobuffer, rcDest.left, rcDest.top, Graphics::FLIP_NONE, &rcSrc);
-
- g_system->copyRectToScreen(_videobuffer->getPixels(), _videobuffer->pitch, 0, 0, _videobuffer->w, _videobuffer->h);
- g_system->updateScreen();
-
- rcDest.left = 160 - 44 + 7;
- rcDest.top = 116 + 12 + 12;
- rcDest.setHeight(8);
-
- _mboss = cacheSound("music/boss.ogg");
- sys_progress(1, 21);
- _mgardens = cacheSound("music/gardens.ogg");
- sys_progress(2, 21);
- _mgardens2 = cacheSound("music/gardens2.ogg");
- sys_progress(3, 21);
- _mgardens3 = cacheSound("music/gardens3.ogg");
- sys_progress(4, 21);
- _mgardens4 = cacheSound("music/gardens4.ogg");
- sys_progress(5, 21);
- _mendofgame = cacheSound("music/endofgame.ogg");
- sys_progress(6, 21);
- _mmenu = cacheSound("music/menu.ogg");
- sys_progress(7, 21);
-
- _sfx[0] = cacheSound("sfx/bite.ogg");
- sys_progress(8, 21);
- _sfx[1] = cacheSound("sfx/crystal.ogg");
- sys_progress(9, 21);
- _sfx[2] = cacheSound("sfx/door.ogg");
- sys_progress(10, 21);
- _sfx[3] = cacheSound("sfx/enemyhit.ogg");
- sys_progress(11, 21);
- _sfx[4] = cacheSound("sfx/ice.ogg");
- sys_progress(12, 21);
- _sfx[5] = cacheSound("sfx/lever.ogg");
- sys_progress(13, 21);
- _sfx[6] = cacheSound("sfx/lightning.ogg");
- sys_progress(14, 21);
- _sfx[7] = cacheSound("sfx/metalhit.ogg");
- sys_progress(15, 21);
- _sfx[8] = cacheSound("sfx/powerup.ogg");
- sys_progress(16, 21);
- _sfx[9] = cacheSound("sfx/rocks.ogg");
- sys_progress(17, 21);
- _sfx[10] = cacheSound("sfx/swordhit.ogg");
- sys_progress(18, 21);
- _sfx[11] = cacheSound("sfx/throw.ogg");
- sys_progress(19, 21);
- _sfx[12] = cacheSound("sfx/chest.ogg");
- sys_progress(20, 21);
- _sfx[13] = cacheSound("sfx/fire.ogg");
- sys_progress(21, 21);
- _sfx[14] = cacheSound("sfx/beep.ogg");
-}
-
void GriffonEngine::sys_update() {
g_system->updateScreen();
g_system->getEventManager()->pollEvent(_event);
diff --git a/engines/griffon/griffon.h b/engines/griffon/griffon.h
index 9c502d6844..ca4d98cbb8 100644
--- a/engines/griffon/griffon.h
+++ b/engines/griffon/griffon.h
@@ -321,6 +321,8 @@ private:
void resumeSoundChannel(int channel);
bool isSoundChannelPlaying(int channel);
+ Graphics::TransparentSurface *IMG_Load(const char *name, bool colorkey = false);
+
private:
Graphics::TransparentSurface *_video, *_videobuffer, *_videobuffer2, *_videobuffer3;
diff --git a/engines/griffon/module.mk b/engines/griffon/module.mk
index de09712b88..5fa2a801ad 100644
--- a/engines/griffon/module.mk
+++ b/engines/griffon/module.mk
@@ -6,7 +6,8 @@ MODULE_OBJS := \
engine.o \
griffon.o \
detection.o \
- saveload.o
+ saveload.o \
+ sound.o
MODULE_DIRS += \
engines/griffon
diff --git a/engines/griffon/sound.cpp b/engines/griffon/sound.cpp
new file mode 100644
index 0000000000..27ba2b3dc4
--- /dev/null
+++ b/engines/griffon/sound.cpp
@@ -0,0 +1,202 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Originally written by Syn9 in FreeBASIC with SDL
+ * http://syn9.thehideoutgames.com/index_backup.php
+ *
+ * Ported to plain C for GCW-Zero handheld by Dmitry Smagin
+ * http://github.com/dmitrysmagin/griffon_legend
+ *
+ *
+ * Programming/Graphics: Daniel "Syn9" Kennedy
+ * Music/Sound effects: David Turner
+ *
+ * Beta testing and gameplay design help:
+ * Deleter, Cha0s, Aether Fox, and Kiz
+ *
+ */
+
+#include "audio/audiostream.h"
+#include "audio/decoders/vorbis.h"
+#include "common/memstream.h"
+
+#include "common/file.h"
+#include "common/system.h"
+
+#include "griffon/griffon.h"
+
+namespace Griffon {
+
+void GriffonEngine::setChannelVolume(int channel, int volume) {}
+
+int GriffonEngine::getSoundHandle() {
+ for (uint i = 0; i < kSoundHandles; i++) {
+ if (!_mixer->isSoundHandleActive(_handles[i])) {
+ return i;
+ }
+ }
+
+ error("getSoundHandle(): Too many sound handles");
+
+ return -1;
+}
+
+int GriffonEngine::playSound(DataChunk *chunk, bool looped) {
+ int ch = getSoundHandle();
+
+#ifdef USE_VORBIS
+ Audio::SeekableAudioStream *audioStream = Audio::makeVorbisStream(new Common::MemoryReadStream(chunk->data, chunk->size), DisposeAfterUse::YES);
+
+
+ if (looped) {
+ Audio::AudioStream *loopingStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
+ _mixer->playStream(Audio::Mixer::kSFXSoundType, &_handles[ch], loopingStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES, false, false);
+
+ } else {
+ _mixer->playStream(Audio::Mixer::kSFXSoundType, &_handles[ch], audioStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES, false, false);
+ }
+#endif // USE_VORBIS
+
+ return ch;
+}
+
+void GriffonEngine::pauseSoundChannel(int channel) {
+ _mixer->pauseHandle(_handles[channel], true);
+}
+
+void GriffonEngine::haltSoundChannel(int channel) {
+ _mixer->stopHandle(_handles[channel]);
+}
+
+void GriffonEngine::resumeSoundChannel(int channel) {
+ _mixer->pauseHandle(_handles[channel], false);
+}
+
+bool GriffonEngine::isSoundChannelPlaying(int channel) {
+ return _mixer->isSoundHandleActive(_handles[channel]);
+}
+
+DataChunk *cacheSound(const char *name) {
+ Common::File file;
+ DataChunk *res = new DataChunk;
+
+ file.open(name);
+ if (!file.isOpen())
+ error("Cannot open file %s", name);
+
+ res->size = file.size();
+ res->data = (byte *)malloc(res->size);
+
+ file.read(res->data, res->size);
+
+ return res;
+}
+
+void GriffonEngine::sys_progress(int w, int wm) {
+ long ccc = _videobuffer->format.RGBToColor(0, 255, 0);
+
+ rcDest.setWidth(w * 74 / wm);
+ _videobuffer->fillRect(rcDest, ccc);
+
+ g_system->copyRectToScreen(_videobuffer->getPixels(), _videobuffer->pitch, 0, 0, _videobuffer->w, _videobuffer->h);
+ g_system->updateScreen();
+
+ g_system->getEventManager()->pollEvent(_event);
+}
+
+void GriffonEngine::sys_setupAudio() {
+ // FIXME
+ //Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024);
+
+ //atexit(Mix_Quit);
+ //atexit(Mix_CloseAudio);
+
+ const char *stri = "Loading...";
+ sys_print(_videobuffer, stri, 160 - 4 * strlen(stri), 116, 0);
+
+ Graphics::TransparentSurface *loadimg = IMG_Load("art/load.bmp", true);
+
+ rcSrc.left = 0;
+ rcSrc.top = 0;
+ rcSrc.setWidth(88);
+ rcSrc.setHeight(32);
+
+ rcDest.left = 160 - 44;
+ rcDest.top = 116 + 12;
+
+ loadimg->setAlpha(160, true); // 128
+ loadimg->blit(*_videobuffer, rcDest.left, rcDest.top, Graphics::FLIP_NONE, &rcSrc);
+
+ g_system->copyRectToScreen(_videobuffer->getPixels(), _videobuffer->pitch, 0, 0, _videobuffer->w, _videobuffer->h);
+ g_system->updateScreen();
+
+ rcDest.left = 160 - 44 + 7;
+ rcDest.top = 116 + 12 + 12;
+ rcDest.setHeight(8);
+
+ _mboss = cacheSound("music/boss.ogg");
+ sys_progress(1, 21);
+ _mgardens = cacheSound("music/gardens.ogg");
+ sys_progress(2, 21);
+ _mgardens2 = cacheSound("music/gardens2.ogg");
+ sys_progress(3, 21);
+ _mgardens3 = cacheSound("music/gardens3.ogg");
+ sys_progress(4, 21);
+ _mgardens4 = cacheSound("music/gardens4.ogg");
+ sys_progress(5, 21);
+ _mendofgame = cacheSound("music/endofgame.ogg");
+ sys_progress(6, 21);
+ _mmenu = cacheSound("music/menu.ogg");
+ sys_progress(7, 21);
+
+ _sfx[0] = cacheSound("sfx/bite.ogg");
+ sys_progress(8, 21);
+ _sfx[1] = cacheSound("sfx/crystal.ogg");
+ sys_progress(9, 21);
+ _sfx[2] = cacheSound("sfx/door.ogg");
+ sys_progress(10, 21);
+ _sfx[3] = cacheSound("sfx/enemyhit.ogg");
+ sys_progress(11, 21);
+ _sfx[4] = cacheSound("sfx/ice.ogg");
+ sys_progress(12, 21);
+ _sfx[5] = cacheSound("sfx/lever.ogg");
+ sys_progress(13, 21);
+ _sfx[6] = cacheSound("sfx/lightning.ogg");
+ sys_progress(14, 21);
+ _sfx[7] = cacheSound("sfx/metalhit.ogg");
+ sys_progress(15, 21);
+ _sfx[8] = cacheSound("sfx/powerup.ogg");
+ sys_progress(16, 21);
+ _sfx[9] = cacheSound("sfx/rocks.ogg");
+ sys_progress(17, 21);
+ _sfx[10] = cacheSound("sfx/swordhit.ogg");
+ sys_progress(18, 21);
+ _sfx[11] = cacheSound("sfx/throw.ogg");
+ sys_progress(19, 21);
+ _sfx[12] = cacheSound("sfx/chest.ogg");
+ sys_progress(20, 21);
+ _sfx[13] = cacheSound("sfx/fire.ogg");
+ sys_progress(21, 21);
+ _sfx[14] = cacheSound("sfx/beep.ogg");
+}
+
+
+} // end of namespace Griffon