diff options
Diffstat (limited to 'engines/supernova')
-rw-r--r-- | engines/supernova/console.cpp | 58 | ||||
-rw-r--r-- | engines/supernova/console.h | 11 | ||||
-rw-r--r-- | engines/supernova/graphics.cpp | 31 | ||||
-rw-r--r-- | engines/supernova/graphics.h | 5 | ||||
-rw-r--r-- | engines/supernova/supernova.cpp | 80 | ||||
-rw-r--r-- | engines/supernova/supernova.h | 4 |
6 files changed, 122 insertions, 67 deletions
diff --git a/engines/supernova/console.cpp b/engines/supernova/console.cpp index 7ad9c0a2b6..98875ecba6 100644 --- a/engines/supernova/console.cpp +++ b/engines/supernova/console.cpp @@ -27,20 +27,60 @@ namespace Supernova { -Console::Console(SupernovaEngine *vm) +Console::Console(SupernovaEngine *vm, GameManager *gm) { - registerCmd("test", WRAP_METHOD(Console, cmdTest)); + registerCmd("render", WRAP_METHOD(Console, cmdRenderImage)); + registerCmd("play", WRAP_METHOD(Console, cmdPlaySound)); + registerCmd("list", WRAP_METHOD(Console, cmdList)); + registerCmd("inventory", WRAP_METHOD(Console, cmdInventory)); + + _vm = vm; + _gm = gm; } -bool Console::cmdTest(int argc, const char **argv) -{ - if (argc == 2) { - debugPrintf("Success!"); +bool Console::cmdRenderImage(int argc, const char **argv) { + if (argc != 3) { + debugPrintf("Usage: render [filenumber] [section]\n"); return true; - } else { - debugPrintf("Failure!"); - return false; } + + int filenumber = atoi(argv[1]); + int section = atoi(argv[2]); + + _vm->renderImage(atoi(argv[1]), atoi(argv[2])); + + return true; +} + +bool Console::cmdPlaySound(int argc, const char **argv) { + if (argc != 3) { + debugPrintf("Usage: play [filenumber] [offset]\n"); + return true; + } + + int filenumber = atoi(argv[1]); + int offset = atoi(argv[2]); + + _vm->playSound(filenumber, offset); + + return true; +} + +bool Console::cmdList(int argc, const char **argv) { + // Objects in room and sections + + return true; +} + +bool Console::cmdInventory(int argc, const char **argv) { + if (argc != 2 || argc != 3) { + debugPrintf("Usage: inventory [list][add/remove [object]]"); + return true; + } + + // TODO + + return true; } } diff --git a/engines/supernova/console.h b/engines/supernova/console.h index 89e8a1c2bc..19efe47705 100644 --- a/engines/supernova/console.h +++ b/engines/supernova/console.h @@ -28,6 +28,7 @@ namespace Supernova { class SupernovaEngine; +class GameManager; enum { kDebugGeneral = 1 << 0 @@ -35,12 +36,16 @@ enum { class Console : public GUI::Debugger { public: - Console(Supernova::SupernovaEngine *vm); + Console(Supernova::SupernovaEngine *vm, Supernova::GameManager *gm); virtual ~Console() {} - - bool cmdTest(int argc, const char **argv); + + bool cmdRenderImage(int argc, const char **argv); + bool cmdPlaySound(int argc, const char **argv); + bool cmdList(int argc, const char **argv); + bool cmdInventory(int argc, const char **argv); private: SupernovaEngine *_vm; + GameManager *_gm; }; } diff --git a/engines/supernova/graphics.cpp b/engines/supernova/graphics.cpp index ae71db6a7d..d59438983d 100644 --- a/engines/supernova/graphics.cpp +++ b/engines/supernova/graphics.cpp @@ -41,6 +41,18 @@ MSNImageDecoder::~MSNImageDecoder() { destroy(); } +bool MSNImageDecoder::init(int filenumber) { + Common::File file; + if (!file.open(Common::String::format("msn_data.%03d", filenumber))) { + error("File %s could not be read!", file.getName()); + } + + _filenumber = filenumber; + loadStream(file); + + return true; +} + bool MSNImageDecoder::loadStream(Common::SeekableReadStream &stream) { destroy(); @@ -68,13 +80,13 @@ bool MSNImageDecoder::loadStream(Common::SeekableReadStream &stream) { } } - byte numSections = stream.readByte(); + _numSections = stream.readByte(); for (size_t i = 0; i < kMaxSections; ++i) { _section[i].addressHigh = 0xff; _section[i].addressLow = 0xffff; _section[i].x2 = 0; } - for (int i = 0; i < numSections; ++i) { + for (int i = 0; i < _numSections; ++i) { _section[i].x1 = stream.readUint16LE(); _section[i].x2 = stream.readUint16LE(); _section[i].y1 = stream.readByte(); @@ -84,8 +96,8 @@ bool MSNImageDecoder::loadStream(Common::SeekableReadStream &stream) { _section[i].addressHigh = stream.readByte(); } - byte numClickFields = stream.readByte(); - for (int i = 0; i < numClickFields; ++i) { + _numClickFields = stream.readByte(); + for (int i = 0; i < _numClickFields; ++i) { _clickField[i].x1 = stream.readUint16LE(); _clickField[i].x2 = stream.readUint16LE(); _clickField[i].y1 = stream.readByte(); @@ -101,7 +113,7 @@ bool MSNImageDecoder::loadStream(Common::SeekableReadStream &stream) { byte input = 0; size_t i = 0; - // wat + while (stream.read(&input, 1)) { if (input < numRepeat) { ++input; @@ -123,13 +135,16 @@ bool MSNImageDecoder::loadStream(Common::SeekableReadStream &stream) { return true; } -bool MSNImageDecoder::loadSection(int filenumber, int section) { +bool MSNImageDecoder::loadSection(int section) { int imageWidth = 320; int imageHeight = 200; + + if (_surface) + _surface->free(); + _surface = new Graphics::Surface; - _filenumber = filenumber; - if (filenumber == 1 || filenumber == 2) { + if (_filenumber == 1 || _filenumber == 2) { imageWidth = 640; imageHeight = 480; _pitch = 640; diff --git a/engines/supernova/graphics.h b/engines/supernova/graphics.h index d41b70769e..3bd2bfdd29 100644 --- a/engines/supernova/graphics.h +++ b/engines/supernova/graphics.h @@ -46,13 +46,16 @@ public: virtual const Graphics::Surface *getSurface() const { return _surface; } virtual const byte *getPalette() const { return _palette; } - bool loadSection(int filenumber, int section); + bool loadSection(int section); + bool init(int filenumber); static const int kMaxSections = 50; static const int kMaxClickFields = 80; int _filenumber; int _pitch; + int _numSections; + int _numClickFields; Graphics::Surface *_surface; byte *_palette; byte *_encodedImage; diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp index e00875f1d4..ede216d735 100644 --- a/engines/supernova/supernova.cpp +++ b/engines/supernova/supernova.cpp @@ -70,6 +70,7 @@ ObjectType &operator^=(ObjectType &a, ObjectType b) { SupernovaEngine::SupernovaEngine(OSystem *syst) : Engine(syst) , _console(NULL) + , _currentImage(_images) , _brightness(255) , _menuBrightness(255) , _imageIndex(0) @@ -95,12 +96,12 @@ SupernovaEngine::~SupernovaEngine() { Common::Error SupernovaEngine::run() { initGraphics(kScreenWidth, kScreenHeight); - _console = new Console(this); + GameManager gm(this, &_event); + _console = new Console(this, &gm); initData(); initPalette(); paletteFadeIn(); - GameManager gm(this, &_event); CursorMan.showMouse(true); @@ -117,23 +118,6 @@ Common::Error SupernovaEngine::run() { if (_event.kbd.keycode == Common::KEYCODE_d && _event.kbd.hasFlags(Common::KBD_CTRL)) { _console->attach(); } - if (_event.kbd.keycode == Common::KEYCODE_q) { - playSound(48, 13530); - } - if (_event.kbd.keycode == Common::KEYCODE_RIGHT) { - ++_imageIndex; - _sectionIndex = 0; - } - if (_event.kbd.keycode == Common::KEYCODE_LEFT) { - --_imageIndex; - _sectionIndex = 0; - } - if (_event.kbd.keycode == Common::KEYCODE_UP) { - ++_sectionIndex; - } - if (_event.kbd.keycode == Common::KEYCODE_DOWN) { - --_sectionIndex; - } break; case Common::EVENT_LBUTTONUP: @@ -151,10 +135,9 @@ Common::Error SupernovaEngine::run() { // gm.processInput(); } - renderImage(_imageIndex, _sectionIndex, true); + _console->onFrame(); renderText(Common::String::format("%3d | %3d", _imageIndex, _sectionIndex).c_str(), 10, 190, kColorLightGreen); - _console->onFrame(); _system->updateScreen(); _system->delayMillis(_delay); } @@ -179,6 +162,11 @@ void SupernovaEngine::updateEvents() { } void SupernovaEngine::initData() { + // Images + for (int i = 0; i < 44; ++i) + _images[i].init(i); + + // Sound } void SupernovaEngine::initPalette() { @@ -202,44 +190,46 @@ void SupernovaEngine::stopSound() { _mixer->stopHandle(_soundHandle); } -void playSoundMod(int filenumber) +void SupernovaEngine::playSoundMod(int filenumber) { if (filenumber != 49 || filenumber != 52) { error("File not supposed to be played!"); } Common::File *file = new Common::File; - if (!file->open(Common::String::format("msn_data.0%2d", filenumber))) { + if (!file->open(Common::String::format("msn_data.%03d", filenumber))) { error("File %s could not be read!", file->getName()); } // play Supernova MOD file } -void SupernovaEngine::renderImage(int filenumber, int section, bool fullscreen) { - Common::File file; - if (!file.open(Common::String::format("msn_data.%03d", filenumber))) { - error("File %s could not be read!", file.getName()); - } +void SupernovaEngine::renderImage(MSNImageDecoder &image, int section, bool fullscreen) { + _currentImage = ℑ + _imageIndex = image._filenumber; + _sectionIndex = section; - if (_currentImage.loadStream(file) && _currentImage.loadSection(filenumber, section)) { - _system->getPaletteManager()->setPalette(_currentImage.getPalette(), 16, 239); - paletteBrightness(); - if (fullscreen) { - _system->copyRectToScreen(_currentImage.getSurface()->getPixels(), - _currentImage._pitch, 0, 0, kScreenWidth, kScreenHeight); - } else { - size_t offset = _currentImage._section[section].y1 * 320 + _currentImage._section[section].x1; - _system->copyRectToScreen(static_cast<const byte *>(_currentImage.getSurface()->getPixels()) + offset, - 320, - _currentImage._section[section].x1, - _currentImage._section[section].y1, - _currentImage._section[section].x2 - _currentImage._section[section].x1, - _currentImage._section[section].y2 - _currentImage._section[section].y1); - } + image.loadSection(section); + _system->getPaletteManager()->setPalette(image.getPalette(), 16, 239); + paletteBrightness(); + if (fullscreen) { + _system->copyRectToScreen(image.getSurface()->getPixels(), + image._pitch, 0, 0, kScreenWidth, kScreenHeight); + } else { + size_t offset = image._section[section].y1 * 320 + image._section[section].x1; + _system->copyRectToScreen(static_cast<const byte *>(image.getSurface()->getPixels()) + offset, + 320, + image._section[section].x1, + image._section[section].y1, + image._section[section].x2 - image._section[section].x1, + image._section[section].y2 - image._section[section].y1); } } +void SupernovaEngine::renderImage(int filenumber, int section, bool fullscreen) { + renderImage(_images[filenumber], section, fullscreen); +} + void SupernovaEngine::saveScreen(int x, int y, int width, int height) { _screenBuffer.push(x, y, width, height); } @@ -410,8 +400,8 @@ void SupernovaEngine::paletteBrightness() { } for (size_t i = 0; i < 717; ++i) { const byte *imagePalette; - if (_currentImage.getPalette()) { - imagePalette = _currentImage.getPalette(); + if (_currentImage->getPalette()) { + imagePalette = _currentImage->getPalette(); } else { imagePalette = palette; } diff --git a/engines/supernova/supernova.h b/engines/supernova/supernova.h index 801637aab6..01049a2539 100644 --- a/engines/supernova/supernova.h +++ b/engines/supernova/supernova.h @@ -80,7 +80,8 @@ public: Console *_console; Audio::SoundHandle _soundHandle; ScreenBufferStack _screenBuffer; - MSNImageDecoder _currentImage; + MSNImageDecoder _images[44]; + MSNImageDecoder *_currentImage; Common::Event _event; bool _gameRunning; @@ -104,6 +105,7 @@ public: void playSound(int filenumber, int offset = 0); void playSoundMod(int filenumber); void stopSound(); + void renderImage(MSNImageDecoder &image, int section, bool fullscreen = false); void renderImage(int filenumber, int section, bool fullscreen = false); void saveScreen(int x, int y, int width, int height); void restoreScreen(); |