From ced59ea5e90fafff585f72395ca75aa1b7b829e8 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Wed, 29 Apr 2009 23:54:29 +0000 Subject: Moving the demo-related stuff into a demos-subdirectory svn-id: r40212 --- engines/gob/demos/batplayer.cpp | 84 ++++++++++++++++++++ engines/gob/demos/batplayer.h | 48 +++++++++++ engines/gob/demos/demoplayer.cpp | 166 +++++++++++++++++++++++++++++++++++++++ engines/gob/demos/demoplayer.h | 62 +++++++++++++++ engines/gob/demos/scnplayer.cpp | 131 ++++++++++++++++++++++++++++++ engines/gob/demos/scnplayer.h | 55 +++++++++++++ 6 files changed, 546 insertions(+) create mode 100644 engines/gob/demos/batplayer.cpp create mode 100644 engines/gob/demos/batplayer.h create mode 100644 engines/gob/demos/demoplayer.cpp create mode 100644 engines/gob/demos/demoplayer.h create mode 100644 engines/gob/demos/scnplayer.cpp create mode 100644 engines/gob/demos/scnplayer.h (limited to 'engines/gob/demos') diff --git a/engines/gob/demos/batplayer.cpp b/engines/gob/demos/batplayer.cpp new file mode 100644 index 0000000000..d3aae2691d --- /dev/null +++ b/engines/gob/demos/batplayer.cpp @@ -0,0 +1,84 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#include "common/endian.h" + +#include "gob/gob.h" +#include "gob/demos/batplayer.h" +#include "gob/global.h" +#include "gob/util.h" +#include "gob/draw.h" +#include "gob/inter.h" +#include "gob/videoplayer.h" + +namespace Gob { + +BATPlayer::BATPlayer(GobEngine *vm) : DemoPlayer(vm) { + _doubleMode = false; +} + +BATPlayer::~BATPlayer() { +} + +bool BATPlayer::play(const char *fileName) { + if (!fileName) + return false; + + debugC(1, kDebugDemo, "Playing BAT \"%s\"", fileName); + + init(); + + Common::File bat; + + if (!bat.open(fileName)) + return false; + + return play(bat); +} + +bool BATPlayer::play(Common::File &bat) { + // Iterate over all lines + while (!bat.err() && !bat.eos()) { + Common::String line = bat.readLine(); + + // Interpret + if (lineStartsWith(line, "slide ")) { + playVideo(line.c_str() + 6); + clearScreen(); + } + + // Mind user input + _vm->_util->processInput(); + if (_vm->shouldQuit()) + return true; + } + + if (bat.err()) + return false; + + return true; +} + +} // End of namespace Gob diff --git a/engines/gob/demos/batplayer.h b/engines/gob/demos/batplayer.h new file mode 100644 index 0000000000..861b0b8749 --- /dev/null +++ b/engines/gob/demos/batplayer.h @@ -0,0 +1,48 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#ifndef GOB_BATPLAYER_H +#define GOB_BATPLAYER_H + +#include "common/file.h" + +#include "gob/demos/demoplayer.h" + +namespace Gob { + +class BATPlayer : public DemoPlayer { +public: + BATPlayer(GobEngine *vm); + virtual ~BATPlayer(); + + virtual bool play(const char *fileName); + +private: + bool play(Common::File &bat); +}; + +} // End of namespace Gob + +#endif // GOB_BATPLAYER_H diff --git a/engines/gob/demos/demoplayer.cpp b/engines/gob/demos/demoplayer.cpp new file mode 100644 index 0000000000..c19a955981 --- /dev/null +++ b/engines/gob/demos/demoplayer.cpp @@ -0,0 +1,166 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#include "common/endian.h" + +#include "gob/gob.h" +#include "gob/demos/demoplayer.h" +#include "gob/global.h" +#include "gob/util.h" +#include "gob/draw.h" +#include "gob/inter.h" +#include "gob/videoplayer.h" + +namespace Gob { + +DemoPlayer::DemoPlayer(GobEngine *vm) : _vm(vm) { + _doubleMode = false; +} + +DemoPlayer::~DemoPlayer() { +} + +bool DemoPlayer::lineStartsWith(const Common::String &line, const char *start) { + return (strstr(line.c_str(), start) == line.c_str()); +} + +void DemoPlayer::init() { + // The video player needs some fake variables + _vm->_inter->allocateVars(32); + + // Init the screen + _vm->_draw->initScreen(); + _vm->_draw->_cursorIndex = -1; + + _vm->_util->longDelay(200); // Letting everything settle + +} + +void DemoPlayer::clearScreen() { + debugC(1, kDebugDemo, "Clearing the screen"); + _vm->_video->clearScreen(); +} + +void DemoPlayer::playVideo(const char *fileName) { + uint32 waitTime = 0; + char *file, *filePtr; + + file = filePtr = new char[strlen(fileName) + 1]; + strcpy(file, fileName); + + // Trimming spaces front + while (*file == ' ') + file++; + + char *spaceBack = strchr(file, ' '); + if (spaceBack) { + char *nextSpace = strchr(spaceBack, ' '); + + if (nextSpace) + *nextSpace = '\0'; + + *spaceBack++ = '\0'; + + waitTime = atoi(spaceBack) * 100; + } + + // WORKAROUND: The Inca2 demo wants to play cons2.imd, but that file doesn't exist. + // cons.imd does, however. + if ((_vm->getGameType() == kGameTypeInca2) && (!scumm_stricmp(file, "cons2.imd"))) + strcpy(file, "cons.imd"); + + debugC(1, kDebugDemo, "Playing video \"%s\"", file); + + if (_vm->_vidPlayer->primaryOpen(file)) { + bool videoSupportsDouble = + ((_vm->_vidPlayer->getFeatures() & CoktelVideo::kFeaturesSupportsDouble) != 0); + + if (_doubleMode) { + if (videoSupportsDouble) { + _vm->_vidPlayer->slotSetDoubleMode(-1, true); + playVideoNormal(); + } else + playVideoDoubled(); + } else + playVideoNormal(); + + _vm->_vidPlayer->primaryClose(); + + if (waitTime > 0) + _vm->_util->longDelay(waitTime); + } + + + delete[] filePtr; +} + +void DemoPlayer::playVideoNormal() { + _vm->_vidPlayer->primaryPlay(); +} + +void DemoPlayer::playVideoDoubled() { + const char *fileNameOpened; + char *fileName; + + fileNameOpened = _vm->_vidPlayer->getFileName(); + + fileName = new char[strlen(fileNameOpened) + 1]; + strcpy(fileName, fileNameOpened); + + _vm->_vidPlayer->primaryClose(); + + if (_vm->_vidPlayer->primaryOpen(fileName, 0, -1, VideoPlayer::kFlagOtherSurface)) { + for (int i = 0; i < _vm->_vidPlayer->getFramesCount(); i++) { + if (_vm->_vidPlayer->primaryPlay(i, i)) + break; + + CoktelVideo::State state = _vm->_vidPlayer->getState(); + + int16 w = state.right - state.left + 1; + int16 h = state.bottom - state.top + 1; + int16 wD = (state.left * 2) + (w * 2); + int16 hD = (state.top * 2) + (h * 2); + + _vm->_video->drawSpriteDouble(_vm->_draw->_spritesArray[0], _vm->_draw->_frontSurface, + state.left, state.top, state.right, state.bottom, state.left, state.top, 0); + _vm->_draw->dirtiedRect(_vm->_draw->_frontSurface, + state.left * 2, state.top * 2, wD, hD); + _vm->_video->retrace(); + } + } + + delete[] fileName; +} + +void DemoPlayer::evaluateVideoMode(const char *mode) { + debugC(2, kDebugDemo, "Video mode \"%s\"", mode); + + if (!scumm_strnicmp(mode, "VESA", 4)) + _doubleMode = false; + else if (!scumm_strnicmp(mode, "VGA", 3) && _vm->is640()) + _doubleMode = true; +} + +} // End of namespace Gob diff --git a/engines/gob/demos/demoplayer.h b/engines/gob/demos/demoplayer.h new file mode 100644 index 0000000000..c26ecacaa9 --- /dev/null +++ b/engines/gob/demos/demoplayer.h @@ -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. + * + * $URL$ + * $Id$ + * + */ + +#ifndef GOB_DEMOPLAYER_H +#define GOB_DEMOPLAYER_H + +#include "common/file.h" +#include "common/str.h" +#include "common/hashmap.h" + +namespace Gob { + +class GobEngine; + +class DemoPlayer { +public: + DemoPlayer(GobEngine *vm); + virtual ~DemoPlayer(); + + virtual bool play(const char *fileName) = 0; + +protected: + GobEngine *_vm; + bool _doubleMode; + + bool lineStartsWith(const Common::String &line, const char *start); + + void init(); + + void evaluateVideoMode(const char *mode); + void clearScreen(); + void playVideo(const char *fileName); + + void playVideoNormal(); + void playVideoDoubled(); +}; + +} // End of namespace Gob + +#endif // GOB_DEMOPLAYER_H diff --git a/engines/gob/demos/scnplayer.cpp b/engines/gob/demos/scnplayer.cpp new file mode 100644 index 0000000000..3b4fd498de --- /dev/null +++ b/engines/gob/demos/scnplayer.cpp @@ -0,0 +1,131 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#include "common/endian.h" + +#include "gob/gob.h" +#include "gob/demos/scnplayer.h" +#include "gob/global.h" +#include "gob/util.h" +#include "gob/draw.h" +#include "gob/inter.h" +#include "gob/videoplayer.h" + +namespace Gob { + +SCNPlayer::SCNPlayer(GobEngine *vm) : DemoPlayer(vm) { + _doubleMode = false; +} + +SCNPlayer::~SCNPlayer() { +} + +bool SCNPlayer::play(const char *fileName) { + if (!fileName) + return false; + + debugC(1, kDebugDemo, "Playing SCN \"%s\"", fileName); + + init(); + + Common::File scn; + + if (!scn.open(fileName)) + return false; + + return play(scn); +} + +bool SCNPlayer::play(Common::File &scn) { + // Read labels + LabelMap labels; + if (!readLabels(scn, labels)) + return false; + + // Iterate over all lines + while (!scn.err() && !scn.eos()) { + Common::String line = scn.readLine(); + + // Interpret + if (line == "CLEAR") { + clearScreen(); + } else if (lineStartsWith(line, "VIDEO:")) { + evaluateVideoMode(line.c_str() + 6); + } else if (lineStartsWith(line, "IMD_PRELOAD ")) { + playVideo(line.c_str() + 12); + } else if (lineStartsWith(line, "IMD ")) { + playVideo(line.c_str() + 4); + } else if (lineStartsWith(line, "GOTO ")) { + gotoLabel(scn, labels, line.c_str() + 5); + } + + // Mind user input + _vm->_util->processInput(); + if (_vm->shouldQuit()) + return true; + } + + if (scn.err()) + return false; + + return true; +} + +bool SCNPlayer::readLabels(Common::File &scn, LabelMap &labels) { + debugC(1, kDebugDemo, "Reading SCN labels"); + + int32 startPos = scn.pos(); + + // Iterate over all lines + while (!scn.err() && !scn.eos()) { + Common::String line = scn.readLine(); + + if (lineStartsWith(line, "LABEL ")) { + // Label => Add to the hashmap + labels.setVal(line.c_str() + 6, scn.pos()); + debugC(2, kDebugDemo, "Found label \"%s\" (%d)", line.c_str() + 6, scn.pos()); + } + } + + if (scn.err()) + return false; + + // Seek back + if (!scn.seek(startPos)) + return false; + + return true; +} + +void SCNPlayer::gotoLabel(Common::File &scn, const LabelMap &labels, const char *label) { + debugC(2, kDebugDemo, "Jumping to label \"%s\"", label); + + if (!labels.contains(label)) + return; + + scn.seek(labels.getVal(label)); +} + +} // End of namespace Gob diff --git a/engines/gob/demos/scnplayer.h b/engines/gob/demos/scnplayer.h new file mode 100644 index 0000000000..752e3714c7 --- /dev/null +++ b/engines/gob/demos/scnplayer.h @@ -0,0 +1,55 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#ifndef GOB_SCNPLAYER_H +#define GOB_SCNPLAYER_H + +#include "common/file.h" +#include "common/str.h" +#include "common/hashmap.h" + +#include "gob/demos/demoplayer.h" + +namespace Gob { + +class SCNPlayer : public DemoPlayer { +public: + SCNPlayer(GobEngine *vm); + virtual ~SCNPlayer(); + + virtual bool play(const char *fileName); + +private: + typedef Common::HashMap LabelMap; + + bool play(Common::File &scn); + bool readLabels(Common::File &scn, LabelMap &labels); + + void gotoLabel(Common::File &scn, const LabelMap &labels, const char *label); +}; + +} // End of namespace Gob + +#endif // GOB_SCNPLAYER_H -- cgit v1.2.3