aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2016-09-26 22:58:32 +0300
committerFilippos Karapetis2016-10-03 00:34:14 +0300
commit93a83a6b86116dabc058c4d799615d7e6c496a0c (patch)
tree44bace74fcc1a94bab2986c16954466906809995
parent8767b44fe0e216145e6f4218966b604e158f912e (diff)
downloadscummvm-rg350-93a83a6b86116dabc058c4d799615d7e6c496a0c.tar.gz
scummvm-rg350-93a83a6b86116dabc058c4d799615d7e6c496a0c.tar.bz2
scummvm-rg350-93a83a6b86116dabc058c4d799615d7e6c496a0c.zip
CHEWY: Add an event manager, and get rid of g_engine
-rw-r--r--engines/chewy/chewy.cpp24
-rw-r--r--engines/chewy/chewy.h7
-rw-r--r--engines/chewy/console.cpp10
-rw-r--r--engines/chewy/events.cpp62
-rw-r--r--engines/chewy/events.h51
-rw-r--r--engines/chewy/graphics.cpp10
-rw-r--r--engines/chewy/graphics.h5
-rw-r--r--engines/chewy/sound.cpp9
-rw-r--r--engines/chewy/sound.h3
-rw-r--r--engines/chewy/video/cfo_decoder.cpp24
-rw-r--r--engines/chewy/video/cfo_decoder.h7
11 files changed, 169 insertions, 43 deletions
diff --git a/engines/chewy/chewy.cpp b/engines/chewy/chewy.cpp
index 35575e10b4..a91bd2fe91 100644
--- a/engines/chewy/chewy.cpp
+++ b/engines/chewy/chewy.cpp
@@ -31,6 +31,7 @@
#include "chewy/chewy.h"
#include "chewy/console.h"
+#include "chewy/events.h"
#include "chewy/graphics.h"
#include "chewy/resource.h"
#include "chewy/sound.h"
@@ -54,18 +55,21 @@ ChewyEngine::ChewyEngine(OSystem *syst, const ChewyGameDescription *gameDesc)
}
ChewyEngine::~ChewyEngine() {
- delete _console;
+ delete _events;
delete _sound;
delete _graphics;
+ delete _console;
}
void ChewyEngine::initialize() {
_console = new Console(this);
- _graphics = new Graphics();
- _sound = new Sound();
+ _graphics = new Graphics(this);
+ _sound = new Sound(_mixer);
+ _events = new Events(this, _graphics, _console);
_curCursor = 0;
_elapsedFrames = 0;
+ _videoNum = -1;
}
Common::Error ChewyEngine::run() {
@@ -90,14 +94,7 @@ Common::Error ChewyEngine::run() {
// Run a dummy loop
while (!shouldQuit()) {
- while (g_system->getEventManager()->pollEvent(_event)) {
- if (_event.type == Common::EVENT_KEYDOWN && _event.kbd.keycode == Common::KEYCODE_ESCAPE)
- g_engine->quitGame();
- if ((_event.type == Common::EVENT_KEYDOWN && _event.kbd.keycode == Common::KEYCODE_SPACE) || _event.type == Common::EVENT_RBUTTONUP)
- _graphics->nextCursor();
- if (_event.type == Common::EVENT_KEYDOWN && _event.kbd.flags & Common::KBD_CTRL && _event.kbd.keycode == Common::KEYCODE_d)
- _console->attach();
- }
+ _events->processEvents();
_console->onFrame();
@@ -105,6 +102,11 @@ Common::Error ChewyEngine::run() {
if (_elapsedFrames % 30 == 0)
_graphics->animateCursor();
+ if (_videoNum >= 0) {
+ _graphics->playVideo(_videoNum);
+ _videoNum = -1;
+ }
+
g_system->updateScreen();
g_system->delayMillis(10);
diff --git a/engines/chewy/chewy.h b/engines/chewy/chewy.h
index a3f5f9298d..6bb9df536f 100644
--- a/engines/chewy/chewy.h
+++ b/engines/chewy/chewy.h
@@ -25,7 +25,6 @@
#include "common/scummsys.h"
-#include "common/events.h"
#include "common/file.h"
#include "common/util.h"
#include "common/str.h"
@@ -39,6 +38,7 @@ namespace Chewy {
struct ChewyGameDescription;
class Console;
+class Events;
class Graphics;
class Sound;
@@ -55,6 +55,8 @@ public:
const ChewyGameDescription *_gameDescription;
Common::RandomSource _rnd;
+ void setPlayVideo(uint num) { _videoNum = num; }
+
Graphics *_graphics;
Sound *_sound;
@@ -67,10 +69,11 @@ protected:
void shutdown();
Console *_console;
+ Events *_events;
- Common::Event _event;
uint _curCursor;
uint _elapsedFrames;
+ int _videoNum;
};
} // End of namespace Chewy
diff --git a/engines/chewy/console.cpp b/engines/chewy/console.cpp
index deaa1e3a62..f982cade75 100644
--- a/engines/chewy/console.cpp
+++ b/engines/chewy/console.cpp
@@ -108,9 +108,7 @@ bool Console::Cmd_Draw(int argc, const char **argv) {
Common::String filename = argv[1];
int resNum = atoi(argv[2]);
- Graphics *g = new Graphics();
- g->drawImage(filename, resNum);
- delete g;
+ _vm->_graphics->drawImage(filename, resNum);
return false;
}
@@ -157,12 +155,8 @@ bool Console::Cmd_PlayVideo(int argc, const char **argv) {
return true;
}
- detach(); // close the console
-
int resNum = atoi(argv[1]);
- Graphics *g = new Graphics();
- g->playVideo(resNum);
- delete g;
+ _vm->setPlayVideo(resNum);
return false;
}
diff --git a/engines/chewy/events.cpp b/engines/chewy/events.cpp
new file mode 100644
index 0000000000..cfbcb8ba1f
--- /dev/null
+++ b/engines/chewy/events.cpp
@@ -0,0 +1,62 @@
+/* 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.
+ *
+ */
+
+#include "common/system.h"
+#include "common/events.h"
+
+#include "chewy/chewy.h"
+#include "chewy/console.h"
+#include "chewy/events.h"
+#include "chewy/graphics.h"
+
+namespace Chewy {
+
+Events::Events(ChewyEngine *vm, Graphics *graphics, Console *console) :
+ _vm(vm), _graphics(graphics), _console(console) {
+
+ _eventManager = g_system->getEventManager();
+}
+
+void Events::processEvents() {
+ while (_eventManager->pollEvent(_event)) {
+ if (_event.type == Common::EVENT_KEYDOWN) {
+ switch (_event.kbd.keycode) {
+ case Common::KEYCODE_ESCAPE:
+ _vm->quitGame();
+ break;
+ case Common::KEYCODE_SPACE:
+ _graphics->nextCursor();
+ break;
+ case Common::KEYCODE_d:
+ if (_event.kbd.flags & Common::KBD_CTRL)
+ _console->attach();
+ break;
+ default:
+ break;
+ }
+ } else if (_event.type == Common::EVENT_RBUTTONUP) {
+ _graphics->nextCursor();
+ }
+ }
+}
+
+} // End of namespace Chewy
diff --git a/engines/chewy/events.h b/engines/chewy/events.h
new file mode 100644
index 0000000000..c202b277de
--- /dev/null
+++ b/engines/chewy/events.h
@@ -0,0 +1,51 @@
+/* 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.
+ *
+ */
+
+#ifndef CHEWY_EVENTS_H
+#define CHEWY_EVENTS_H
+
+#include "common/events.h"
+
+namespace Chewy {
+
+class ChewyEngine;
+class Graphics;
+class Console;
+
+class Events {
+public:
+ Events(ChewyEngine *vm, Graphics *graphics, Console *console);
+ ~Events() {}
+
+ void processEvents();
+
+private:
+ Common::Event _event;
+ Common::EventManager *_eventManager;
+ ChewyEngine *_vm;
+ Graphics *_graphics;
+ Console *_console;
+};
+
+} // End of namespace Chewy
+
+#endif
diff --git a/engines/chewy/graphics.cpp b/engines/chewy/graphics.cpp
index 2b90ab7802..612551d5e0 100644
--- a/engines/chewy/graphics.cpp
+++ b/engines/chewy/graphics.cpp
@@ -49,7 +49,7 @@ const byte _cursorFrames[] = {
1 // gun
};
-Graphics::Graphics() {
+Graphics::Graphics(ChewyEngine *vm) : _vm(vm) {
_curCursor = 0;
_curCursorFrame = 0;
_cursorSprites = new SpriteResource("cursor.taf");
@@ -73,7 +73,7 @@ void Graphics::drawImage(Common::String filename, int imageNum) {
}
void Graphics::playVideo(uint num) {
- CfoDecoder *cfoDecoder = new CfoDecoder();
+ CfoDecoder *cfoDecoder = new CfoDecoder(_vm->_mixer);
VideoResource *videoResource = new VideoResource("cut.tap");
Common::SeekableReadStream *videoStream = videoResource->getVideoStream(num);
@@ -87,9 +87,11 @@ void Graphics::playVideo(uint num) {
uint16 y = (g_system->getHeight() - cfoDecoder->getHeight()) / 2;
bool skipVideo = false;
+ hideCursor();
+
cfoDecoder->start();
- while (!g_engine->shouldQuit() && !cfoDecoder->endOfVideo() && !skipVideo) {
+ while (!_vm->shouldQuit() && !cfoDecoder->endOfVideo() && !skipVideo) {
if (cfoDecoder->needsUpdate()) {
const ::Graphics::Surface *frame = cfoDecoder->decodeNextFrame();
if (frame) {
@@ -112,6 +114,8 @@ void Graphics::playVideo(uint num) {
}
cfoDecoder->close();
+
+ showCursor();
}
void Graphics::setCursor(uint num, bool newCursor) {
diff --git a/engines/chewy/graphics.h b/engines/chewy/graphics.h
index 381e8f513c..90315e34a1 100644
--- a/engines/chewy/graphics.h
+++ b/engines/chewy/graphics.h
@@ -31,7 +31,7 @@ class SpriteResource;
class Graphics {
public:
- Graphics();
+ Graphics(ChewyEngine *vm);
~Graphics();
void drawImage(Common::String filename, int imageNum);
@@ -41,7 +41,10 @@ public:
void hideCursor();
void animateCursor();
void nextCursor();
+
private:
+ ChewyEngine *_vm;
+
uint _curCursor;
uint _curCursorFrame;
SpriteResource *_cursorSprites;
diff --git a/engines/chewy/sound.cpp b/engines/chewy/sound.cpp
index 9ef4df97d9..fc27f637d4 100644
--- a/engines/chewy/sound.cpp
+++ b/engines/chewy/sound.cpp
@@ -30,7 +30,8 @@
namespace Chewy {
-Sound::Sound() {
+Sound::Sound(Audio::Mixer *mixer) {
+ _mixer = mixer;
_speechRes = new SoundResource("speech.tvp");
_soundRes = new SoundResource("details.tap");
}
@@ -51,7 +52,7 @@ void Sound::playSound(int num, bool loop) {
DisposeAfterUse::NO),
loop ? 0 : 1);
- g_engine->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, stream);
+ _mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, stream);
delete[] sound->data;
delete sound;
@@ -72,7 +73,7 @@ void Sound::playMusic(int num, bool loop) {
DisposeAfterUse::NO),
loop ? 0 : 1);
- g_engine->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, stream);
+ _mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, stream);
}
void Sound::playSpeech(int num) {
@@ -86,7 +87,7 @@ void Sound::playSpeech(int num) {
DisposeAfterUse::NO),
1);
- g_engine->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, stream);
+ _mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, stream);
delete[] sound->data;
delete sound;
diff --git a/engines/chewy/sound.h b/engines/chewy/sound.h
index 23610272e5..9dc953618c 100644
--- a/engines/chewy/sound.h
+++ b/engines/chewy/sound.h
@@ -32,7 +32,7 @@ class SoundResource;
class Sound {
public:
- Sound();
+ Sound(Audio::Mixer *mixer);
~Sound();
void playSound(int num, bool loop = false);
@@ -40,6 +40,7 @@ public:
void playSpeech(int num);
private:
+ Audio::Mixer *_mixer;
Audio::SoundHandle _soundHandle;
Audio::SoundHandle _musicHandle;
Audio::SoundHandle _speechHandle;
diff --git a/engines/chewy/video/cfo_decoder.cpp b/engines/chewy/video/cfo_decoder.cpp
index 9ec11cc4a1..09d264afb1 100644
--- a/engines/chewy/video/cfo_decoder.cpp
+++ b/engines/chewy/video/cfo_decoder.cpp
@@ -69,11 +69,11 @@ bool CfoDecoder::loadStream(Common::SeekableReadStream *stream) {
uint16 width = stream->readUint16LE();
uint16 height = stream->readUint16LE();
- addTrack(new CfoVideoTrack(stream, frameCount, width, height));
+ addTrack(new CfoVideoTrack(stream, frameCount, width, height, _mixer));
return true;
}
-CfoDecoder::CfoVideoTrack::CfoVideoTrack(Common::SeekableReadStream *stream, uint16 frameCount, uint16 width, uint16 height) :
+CfoDecoder::CfoVideoTrack::CfoVideoTrack(Common::SeekableReadStream *stream, uint16 frameCount, uint16 width, uint16 height, Audio::Mixer *mixer) :
Video::FlicDecoder::FlicVideoTrack(stream, frameCount, width, height, true) {
readHeader();
@@ -81,10 +81,12 @@ CfoDecoder::CfoVideoTrack::CfoVideoTrack(Common::SeekableReadStream *stream, uin
_soundEffects[i] = nullptr;
_soundEffectSize[i] = 0;
}
+
+ _mixer = mixer;
}
CfoDecoder::CfoVideoTrack::~CfoVideoTrack() {
- g_engine->_mixer->stopAll();
+ _mixer->stopAll();
for (int i = 0; i < MAX_SOUND_EFFECTS; i++) {
delete[] _soundEffects[i];
@@ -222,17 +224,17 @@ void CfoDecoder::CfoVideoTrack::handleCustomFrame() {
error("Unused chunk kChunkPlayPattern found");
break;
case kChunkStopMusic:
- g_engine->_mixer->stopHandle(_musicHandle);
+ _mixer->stopHandle(_musicHandle);
break;
case kChunkWaitMusicEnd:
do {
g_system->delayMillis(10);
- } while (g_engine->_mixer->isSoundHandleActive(_musicHandle));
+ } while (_mixer->isSoundHandleActive(_musicHandle));
break;
case kChunkSetMusicVolume:
volume = _fileStream->readUint16LE() * Audio::Mixer::kMaxChannelVolume / 63;
- g_engine->_mixer->setVolumeForSoundType(Audio::Mixer::SoundType::kMusicSoundType, volume);
+ _mixer->setVolumeForSoundType(Audio::Mixer::SoundType::kMusicSoundType, volume);
break;
case kChunkSetLoopMode:
error("Unused chunk kChunkSetLoopMode found");
@@ -254,20 +256,20 @@ void CfoDecoder::CfoVideoTrack::handleCustomFrame() {
DisposeAfterUse::NO),
(repeat == 0) ? 1 : repeat);
- g_engine->_mixer->setVolumeForSoundType(Audio::Mixer::SoundType::kSFXSoundType, volume);
- g_engine->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle[channel], stream);
+ _mixer->setVolumeForSoundType(Audio::Mixer::SoundType::kSFXSoundType, volume);
+ _mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle[channel], stream);
break;
case kChunkSetSoundVolume:
volume = _fileStream->readUint16LE() * Audio::Mixer::kMaxChannelVolume / 63;
- g_engine->_mixer->setVolumeForSoundType(Audio::Mixer::SoundType::kSFXSoundType, volume);
+ _mixer->setVolumeForSoundType(Audio::Mixer::SoundType::kSFXSoundType, volume);
break;
case kChunkSetChannelVolume:
channel = _fileStream->readUint16LE();
volume = _fileStream->readUint16LE() * Audio::Mixer::kMaxChannelVolume / 63;
assert(channel < MAX_SOUND_EFFECTS);
- g_engine->_mixer->setChannelVolume(_soundHandle[channel], volume);
+ _mixer->setChannelVolume(_soundHandle[channel], volume);
break;
case kChunkFreeSoundEffect:
number = _fileStream->readUint16LE();
@@ -290,7 +292,7 @@ void CfoDecoder::CfoVideoTrack::handleCustomFrame() {
balance = (_fileStream->readUint16LE() * 2) - 127;
assert(channel < MAX_SOUND_EFFECTS);
- g_engine->_mixer->setChannelBalance(_soundHandle[channel], balance);
+ _mixer->setChannelBalance(_soundHandle[channel], balance);
break;
case kChunkSetSpeed:
error("Unused chunk kChunkSetSpeed found");
diff --git a/engines/chewy/video/cfo_decoder.h b/engines/chewy/video/cfo_decoder.h
index 4396205607..b15b00e0b2 100644
--- a/engines/chewy/video/cfo_decoder.h
+++ b/engines/chewy/video/cfo_decoder.h
@@ -34,15 +34,17 @@ namespace Chewy {
// A FLIC decoder, with a modified header and additional custom frames
class CfoDecoder : public Video::FlicDecoder {
public:
- CfoDecoder() : Video::FlicDecoder() {}
+ CfoDecoder(Audio::Mixer *mixer) : Video::FlicDecoder() { _mixer = mixer; }
virtual ~CfoDecoder() {}
bool loadStream(Common::SeekableReadStream *stream);
private:
+ Audio::Mixer *_mixer;
+
class CfoVideoTrack : public Video::FlicDecoder::FlicVideoTrack {
public:
- CfoVideoTrack(Common::SeekableReadStream *stream, uint16 frameCount, uint16 width, uint16 height);
+ CfoVideoTrack(Common::SeekableReadStream *stream, uint16 frameCount, uint16 width, uint16 height, Audio::Mixer *mixer);
virtual ~CfoVideoTrack();
void readHeader();
@@ -56,6 +58,7 @@ private:
void handleFrame();
void handleCustomFrame();
+ Audio::Mixer *_mixer;
Audio::SoundHandle _musicHandle;
Audio::SoundHandle _soundHandle[MAX_SOUND_EFFECTS];
byte *_soundEffects[MAX_SOUND_EFFECTS];