aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorD G Turner2011-06-01 02:16:39 +0100
committerEugene Sandulenko2015-12-27 15:39:52 +0100
commit624c4018736f93b499597f78b6dabed7e08d1016 (patch)
treedcbe67a554f3ff464a46b726ea4143a9856f2366 /engines
parent57b464b2e9c8d5e8aff0d5c35e1f8fcb1ef2ae90 (diff)
downloadscummvm-rg350-624c4018736f93b499597f78b6dabed7e08d1016.tar.gz
scummvm-rg350-624c4018736f93b499597f78b6dabed7e08d1016.tar.bz2
scummvm-rg350-624c4018736f93b499597f78b6dabed7e08d1016.zip
WAGE: Change Script Object to use Common::SeekableReadStream.
This replaces the use of (byte* data, int dataSize) type buffer. Also, some replacements of code in world object to incorporate. Still not compilable. Signed-off-by: Eugene Sandulenko <sev@scummvm.org>
Diffstat (limited to 'engines')
-rw-r--r--engines/wage/script.cpp50
-rw-r--r--engines/wage/script.h6
-rw-r--r--engines/wage/world.cpp31
3 files changed, 40 insertions, 47 deletions
diff --git a/engines/wage/script.cpp b/engines/wage/script.cpp
index 685ba66b12..dd40497e16 100644
--- a/engines/wage/script.cpp
+++ b/engines/wage/script.cpp
@@ -53,6 +53,8 @@
#include "wage/script.h"
#include "wage/world.h"
+#include "common/stream.h"
+
namespace Wage {
bool Script::execute(World *world, int loopCount, String *inputText, Designed *inputClick, WageEngine *callbacks) {
@@ -63,20 +65,18 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
_callbacks = callbacks;
_handled = false;
- _index = 12;
- while (_index < _dataSize) {
- switch(_data[_index]) {
+ _data->skip(12);
+ while (_data->pos() < _data->size()) {
+ switch(_data->readByte()) {
case 0x80: // IF
- _index++;
processIf();
break;
case 0x87: // EXIT
- debug(0, "exit at offset %d", _index - 1);
+ debug(0, "exit at offset %d", _data->pos() - 1);
return true;
case 0x89: // MOVE
{
- _index++;
Scene *currentScene = _world->_player->_currentScene;
processMove();
if (_world->_player->_currentScene != currentScene)
@@ -85,43 +85,41 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
}
case 0x8B: // PRINT
{
- _index++;
Operand *op = readOperand();
// TODO check op type is string or number, or something good...
appendText(op->_str);
- // TODO check data[_index] == 0xFD
- _index++;
+ byte d = _data->readByte();
+ if (d != 0xFD)
+ warning("Operand 0x8B (PRINT) End Byte != 0xFD");
break;
}
case 0x8C: // SOUND
{
- _index++;
Operand *op = readOperand();
// TODO check op type is string.
_handled = true;
callbacks->playSound(op->_str);
- // TODO check data[_index] == 0xFD
- _index++;
+ byte d = _data->readByte();
+ if (d != 0xFD)
+ warning("Operand 0x8B (PRINT) End Byte != 0xFD");
break;
}
case 0x8E: // LET
- _index++;
processLet();
break;
case 0x95: // MENU
{
- _index++;
Operand *op = readStringOperand(); // allows empty menu
// TODO check op type is string.
_callbacks->setMenu(op->_str);
- // TODO check data[_index] == 0xFD
- _index++;
+ byte d = _data->readByte();
+ if (d != 0xFD)
+ warning("Operand 0x8B (PRINT) End Byte != 0xFD");
}
case 0x88: // END
- _index++;
break;
default:
- debug(0, "Unknown opcode: %d", _index);
+ debug(0, "Unknown opcode: %d", _data->pos());
}
}
@@ -194,7 +192,8 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
}
Script::Operand *Script::readOperand() {
- switch (_data[_index++]) {
+ byte operandType = _data->readByte();
+ switch (operandType) {
case 0xA0: // TEXT$
return new Operand(_inputText, Operand::TEXT_INPUT);
case 0xA1:
@@ -228,7 +227,7 @@ Script::Operand *Script::readOperand() {
case 0xFF:
{
// user variable
- int value = _data[_index++];
+ int value = _data->readByte();
if (value < 0)
value += 256;
@@ -272,13 +271,11 @@ Script::Operand *Script::readOperand() {
case 0xE8:
return new Operand(_world->_player->_context._statVariables[Context::PHYS_SPE_CUR], Operand::NUMBER);
default:
- _index--;
- if (_data[_index] >= 0x20 && _data[_index] < 0x80) {
+ if (operandType >= 0x20 && operandType < 0x80) {
return readStringOperand();
} else {
- debug("Dunno what %x is (index=%d)!\n", _data[_index], _index);
+ debug("Dunno what %x is (index=%d)!\n", operandType, _data->pos()-1);
}
- _index++;
return NULL;
}
}
@@ -289,8 +286,9 @@ Script::Operand *Script::readStringOperand() {
sb = new String();
- while (_data[_index] >= 0x20 && _data[_index] < 0x80) {
- char c = _data[_index++];
+ byte c = 0x20;
+ while (c >= 0x20 && c < 0x80) {
+ c = _data->readByte();
if (c < '0' || c > '9')
allDigits = false;
*sb += c;
diff --git a/engines/wage/script.h b/engines/wage/script.h
index a5288d66da..7f7ea0df07 100644
--- a/engines/wage/script.h
+++ b/engines/wage/script.h
@@ -55,19 +55,17 @@ namespace Wage {
class Script {
public:
- Script(byte *data, int dataSize) : _data(data), _dataSize(dataSize) {}
+ Script(Common::SeekableReadStream *data) : _data(data) {}
~Script();
private:
- byte *_data;
- int _dataSize;
+ Common::SeekableReadStream *_data;
WageEngine *_callbacks;
World *_world;
int _loopCount;
String *_inputText;
Designed *_inputClick;
- int _index;
bool _evalResult;
bool _handled;
diff --git a/engines/wage/world.cpp b/engines/wage/world.cpp
index d33ca69b38..a8bba1b448 100644
--- a/engines/wage/world.cpp
+++ b/engines/wage/world.cpp
@@ -75,7 +75,7 @@ bool World::loadWorld(Common::MacResManager *resMan) {
// Load global script
res = resMan->getResource(MKTAG('G','C','O','D'), resArray[0]);
- _globalScript = new Script(res, res->size());
+ _globalScript = new Script(res);
// Load main configuration
if ((resArray = resMan->getResIDArray(MKTAG('V','E','R','S'))).size() == 0)
@@ -86,23 +86,22 @@ bool World::loadWorld(Common::MacResManager *resMan) {
res = resMan->getResource(MKTAG('V','E','R','S'), resArray[0]);
- Common::MemoryReadStream readS(res, res->size());
- readS.skip(10);
- byte b = readS.readByte();
+ res->skip(10);
+ byte b = res->readByte();
_weaponMenuDisabled = (b != 0);
if (b != 0 && b != 1)
error("Unexpected value for weapons menu");
- readS.skip(3);
- _aboutMessage = readPascalString(readS);
+ res->skip(3);
+ _aboutMessage = readPascalString(res);
if (!scumm_stricmp(resMan->getFileName().c_str(), "Scepters"))
- readS.skip(1); // ????
+ res->skip(1); // ????
- _soundLibrary1 = readPascalString(readS);
- _soundLibrary2 = readPascalString(readS);
+ _soundLibrary1 = readPascalString(res);
+ _soundLibrary2 = readPascalString(res);
- free(res);
+ delete res;
// Load scenes
resArray = resMan->getResIDArray(MKTAG('A','S','C','N'));
@@ -116,10 +115,9 @@ bool World::loadWorld(Common::MacResManager *resMan) {
res = resMan->getResource(MKTAG('A','T','X','T'), *iter);
if (res != NULL) {
- Common::MemoryReadStream readT(res, res->size());
- scene->_textBounds = readRect(readT);
- scene->_fontType = readT.readUint16BE();
- scene->_fontSize = readT.readUint16BE();
+ scene->_textBounds = readRect(res);
+ scene->_fontType = res->readUint16BE();
+ scene->_fontSize = res->readUint16BE();
for (int i = 12; i < res->size(); i++)
if (res[i] == 0x0d)
@@ -168,12 +166,11 @@ bool World::loadWorld(Common::MacResManager *resMan) {
// Load Patterns
res = resMan->getResource(MKTAG('P','A','T','#'), 900);
if (res != NULL) {
- Common::MemoryReadStream readP(res, res->size());
- int count = readP.readUint16BE();
+ int count = res->readUint16BE();
for (int i = 0; i < count; i++) {
byte *pattern = (byte *)malloc(8);
for (int j = 0; j < 8; j++) {
- pattern[j] = readP.readByte();
+ pattern[j] = res->readByte();
_patterns.push_back(pattern);
}
}