diff options
author | Strangerke | 2012-04-27 22:08:56 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2018-03-28 17:36:57 +0200 |
commit | b2ac6e06316405881473c78d4a84a6baa8dbcee7 (patch) | |
tree | c1ffb8a67f66ca5a8d0e1ee2b1d7605187f2d95c | |
parent | 32ed5e62af5e8689babb0cb4dced12996e757655 (diff) | |
download | scummvm-rg350-b2ac6e06316405881473c78d4a84a6baa8dbcee7.tar.gz scummvm-rg350-b2ac6e06316405881473c78d4a84a6baa8dbcee7.tar.bz2 scummvm-rg350-b2ac6e06316405881473c78d4a84a6baa8dbcee7.zip |
LILLIPUT: Replace MemoryReadStream by a custom read/write stream
-rw-r--r-- | engines/lilliput/lilliput.cpp | 6 | ||||
-rw-r--r-- | engines/lilliput/lilliput.h | 1 | ||||
-rw-r--r-- | engines/lilliput/module.mk | 3 | ||||
-rw-r--r-- | engines/lilliput/script.cpp | 11 | ||||
-rw-r--r-- | engines/lilliput/script.h | 13 | ||||
-rw-r--r-- | engines/lilliput/stream.cpp | 43 | ||||
-rw-r--r-- | engines/lilliput/stream.h | 42 |
7 files changed, 104 insertions, 15 deletions
diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp index 8d33df3f0a..87864407c8 100644 --- a/engines/lilliput/lilliput.cpp +++ b/engines/lilliput/lilliput.cpp @@ -1993,7 +1993,7 @@ void LilliputEngine::handleMenu() { return; sub170EE(_word10804); - _scriptHandler->runMenuScript(Common::MemoryReadStream(_menuScript, _menuScript_size)); + _scriptHandler->runMenuScript(ScriptStream(_menuScript, _menuScript_size)); _savedMousePosDivided = 0xFFFF; _byte129A0 = 0xFF; @@ -2036,7 +2036,7 @@ void LilliputEngine::handleGameScripts() { assert(tmpVal < _gameScriptIndexSize); debugC(1, kDebugEngine, "========================== Game Script %d ==========================", tmpVal); - _scriptHandler->runScript(Common::MemoryReadStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal])); + _scriptHandler->runScript(ScriptStream(&_arrayGameScripts[_arrayGameScriptIndex[tmpVal]], _arrayGameScriptIndex[tmpVal + 1] - _arrayGameScriptIndex[tmpVal])); } Common::Error LilliputEngine::run() { @@ -2067,7 +2067,7 @@ Common::Error LilliputEngine::run() { //TODO: Init sound/music player - _scriptHandler->runScript(Common::MemoryReadStream(_initScript, _initScript_size)); + _scriptHandler->runScript(ScriptStream(_initScript, _initScript_size)); _int8installed = true; diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h index 14bd9ada7b..ddcbfbe526 100644 --- a/engines/lilliput/lilliput.h +++ b/engines/lilliput/lilliput.h @@ -26,6 +26,7 @@ #include "lilliput/console.h" #include "lilliput/script.h" #include "lilliput/sound.h" +#include "lilliput/stream.h" #include "common/file.h" #include "engines/engine.h" diff --git a/engines/lilliput/module.mk b/engines/lilliput/module.mk index 807f53639c..8a095e8045 100644 --- a/engines/lilliput/module.mk +++ b/engines/lilliput/module.mk @@ -5,7 +5,8 @@ MODULE_OBJS = \ detection.o \ lilliput.o \ script.o \ - sound.o + sound.o \ + stream.o MODULE_DIRS += \ engines/lilliput diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp index 1ca521c52a..fe343b4d44 100644 --- a/engines/lilliput/script.cpp +++ b/engines/lilliput/script.cpp @@ -551,7 +551,7 @@ void LilliputScript::handleOpcodeType2(int curWord) { } } -int LilliputScript::handleOpcode(Common::MemoryReadStream *script) { +int LilliputScript::handleOpcode(ScriptStream *script) { debugC(2, kDebugScript, "handleOpcode"); _currScript = script; uint16 curWord = _currScript->readUint16LE(); @@ -584,7 +584,7 @@ int LilliputScript::handleOpcode(Common::MemoryReadStream *script) { } } -void LilliputScript::runScript(Common::MemoryReadStream script) { +void LilliputScript::runScript(ScriptStream script) { debugC(1, kDebugScript, "runScript"); _byte16F05_ScriptHandler = 1; @@ -592,7 +592,7 @@ void LilliputScript::runScript(Common::MemoryReadStream script) { _vm->update(); } -void LilliputScript::runMenuScript(Common::MemoryReadStream script) { +void LilliputScript::runMenuScript(ScriptStream script) { debugC(1, kDebugScript, "runMenuScript"); warning("========================== Menu Script =============================="); _byte16F05_ScriptHandler = 0; @@ -1217,7 +1217,6 @@ byte LilliputScript::OC_sub1779E() { _currScript->seek(_currScript->pos() + 6); return 0; } - int var2 = _currScript->readUint16LE(); byte *buf = getMapPtr(tmpVal); byte var1 = buf[var2]; @@ -1635,9 +1634,9 @@ void LilliputScript::OC_sub17BB7() { if (_byte16F05_ScriptHandler == 0) { _vm->_byte1714E = 0; - runMenuScript(Common::MemoryReadStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index])); + runMenuScript(ScriptStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index])); } else { - runScript(Common::MemoryReadStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index])); + runScript(ScriptStream(&_vm->_arrayGameScripts[scriptIndex], _vm->_arrayGameScriptIndex[index + 1] - _vm->_arrayGameScriptIndex[index])); } _currScript = _scriptStack.pop(); diff --git a/engines/lilliput/script.h b/engines/lilliput/script.h index ce92e81bdf..0b218d628d 100644 --- a/engines/lilliput/script.h +++ b/engines/lilliput/script.h @@ -27,9 +27,12 @@ #include "common/stack.h" #include "common/random.h" +#include "lilliput/stream.h" + namespace Lilliput { class LilliputEngine; + class LilliputScript { public: byte displayMap; @@ -66,13 +69,13 @@ public: LilliputScript(LilliputEngine *vm); ~LilliputScript(); - void runScript(Common::MemoryReadStream script); - void runMenuScript(Common::MemoryReadStream script); + void runScript(ScriptStream script); + void runMenuScript(ScriptStream script); private: LilliputEngine *_vm; - Common::MemoryReadStream *_currScript; - Common::Stack<Common::MemoryReadStream *> _scriptStack; + ScriptStream *_currScript; + Common::Stack<ScriptStream *> _scriptStack; byte _byte16F05_ScriptHandler; byte _byte12A09; @@ -88,7 +91,7 @@ private: int _word1855E; int _word18776; - int handleOpcode(Common::MemoryReadStream *script); + int handleOpcode(ScriptStream *script); byte handleOpcodeType1(int curWord); void handleOpcodeType2(int curWord); diff --git a/engines/lilliput/stream.cpp b/engines/lilliput/stream.cpp new file mode 100644 index 0000000000..30c7f145c6 --- /dev/null +++ b/engines/lilliput/stream.cpp @@ -0,0 +1,43 @@ +/* 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 "lilliput/stream.h" + +namespace Lilliput { + +ScriptStream::ScriptStream(byte *buf, int size) : Common::MemoryReadStream(buf, size) { + _orgPtr = buf; +} + +ScriptStream::~ScriptStream() { +} + +void ScriptStream::writeUint16LE(int value, int relativePos) { + Common::MemoryWriteStream tmpStream = Common::MemoryWriteStream(_orgPtr, size()); + int writePos = pos() + relativePos < size(); + + assert((writePos >= 0) && (writePos < size())); + + tmpStream.writeSint16LE(value); +} + +} // End of namespace Lilliput diff --git a/engines/lilliput/stream.h b/engines/lilliput/stream.h new file mode 100644 index 0000000000..d6b8c36510 --- /dev/null +++ b/engines/lilliput/stream.h @@ -0,0 +1,42 @@ +/* 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 LILLIPUT_STREAM_H +#define LILLIPUT_STREAM_H + +#include "common/memstream.h" + +namespace Lilliput { + +class ScriptStream : public Common::MemoryReadStream { +private: + byte *_orgPtr; +public: + ScriptStream(byte *buf, int size); + virtual ~ScriptStream(); + + void writeUint16LE(int value, int relativePos = 0); +}; + +} // End of namespace Lilliput + +#endif |