aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Hesse2009-06-23 23:55:19 +0000
committerSven Hesse2009-06-23 23:55:19 +0000
commit04d4ce4a8be24bde70933c7e4a1dc41f374a75ad (patch)
treefcec792965534843ba33ae991484cc91f0309a22
parent7ba3205f584e826c2d811f699618256e3e388c35 (diff)
downloadscummvm-rg350-04d4ce4a8be24bde70933c7e4a1dc41f374a75ad.tar.gz
scummvm-rg350-04d4ce4a8be24bde70933c7e4a1dc41f374a75ad.tar.bz2
scummvm-rg350-04d4ce4a8be24bde70933c7e4a1dc41f374a75ad.zip
Putting basic TOT handling into its own class
svn-id: r41821
-rw-r--r--engines/gob/draw.cpp2
-rw-r--r--engines/gob/game_v1.cpp2
-rw-r--r--engines/gob/game_v2.cpp2
-rw-r--r--engines/gob/module.mk1
-rw-r--r--engines/gob/script.cpp80
-rw-r--r--engines/gob/script.h19
-rw-r--r--engines/gob/totfile.cpp101
-rw-r--r--engines/gob/totfile.h75
8 files changed, 210 insertions, 72 deletions
diff --git a/engines/gob/draw.cpp b/engines/gob/draw.cpp
index f0a84bbdcc..b3e5e7418c 100644
--- a/engines/gob/draw.cpp
+++ b/engines/gob/draw.cpp
@@ -390,7 +390,7 @@ void Draw::printTextCentered(int16 id, int16 left, int16 top, int16 right,
adjustCoords(1, &left, &top);
adjustCoords(1, &right, &bottom);
- uint16 centerOffset = _vm->_game->_script->getFunctionOffset(Script::kFunctionCenter);
+ uint16 centerOffset = _vm->_game->_script->getFunctionOffset(TOTFile::kFunctionCenter);
if (centerOffset != 0) {
_vm->_game->_script->call(centerOffset);
diff --git a/engines/gob/game_v1.cpp b/engines/gob/game_v1.cpp
index 31847075bc..f1bff7b1ab 100644
--- a/engines/gob/game_v1.cpp
+++ b/engines/gob/game_v1.cpp
@@ -164,7 +164,7 @@ void Game_v1::playTot(int16 skipPlay) {
if (!_vm->_inter->_variables)
_vm->_inter->allocateVars(_script->getVariablesCount() & 0xFFFF);
- _script->seek(_script->getFunctionOffset(Script::kFunctionStart));
+ _script->seek(_script->getFunctionOffset(TOTFile::kFunctionStart));
_vm->_inter->renewTimeInVars();
diff --git a/engines/gob/game_v2.cpp b/engines/gob/game_v2.cpp
index 54a70949bf..eed96a63d1 100644
--- a/engines/gob/game_v2.cpp
+++ b/engines/gob/game_v2.cpp
@@ -199,7 +199,7 @@ void Game_v2::playTot(int16 skipPlay) {
if (!_vm->_inter->_variables)
_vm->_inter->allocateVars(_script->getVariablesCount() & 0xFFFF);
- _script->seek(_script->getFunctionOffset(Script::kFunctionStart));
+ _script->seek(_script->getFunctionOffset(TOTFile::kFunctionStart));
_vm->_inter->renewTimeInVars();
diff --git a/engines/gob/module.mk b/engines/gob/module.mk
index 550bc0f6f5..22675e8d54 100644
--- a/engines/gob/module.mk
+++ b/engines/gob/module.mk
@@ -48,6 +48,7 @@ MODULE_OBJS := \
scenery_v1.o \
scenery_v2.o \
script.o \
+ totfile.o \
util.o \
variables.o \
video.o \
diff --git a/engines/gob/script.cpp b/engines/gob/script.cpp
index 20e6093d4f..c41da6cc2c 100644
--- a/engines/gob/script.cpp
+++ b/engines/gob/script.cpp
@@ -44,6 +44,8 @@ Script::Script(GobEngine *vm) : _vm(vm) {
_totSize = 0;
_lomHandle = -1;
+
+ memset(&_totProperties, 0, sizeof(TOTFile::Properties));
}
Script::~Script() {
@@ -359,33 +361,27 @@ bool Script::load(const char *fileName) {
}
bool Script::loadTOT(const Common::String &fileName) {
- if (_vm->_dataIO->existData(fileName.c_str())) {
- // Direct data file
-
- _totSize = _vm->_dataIO->getDataSize(_totFile.c_str());
- _totData = _vm->_dataIO->getData(_totFile.c_str());
-
- } else {
- // Trying to read the TOT file out of the currently loaded video file
+ TOTFile totFile(_vm);
- Common::MemoryReadStream *videoExtraData = _vm->_vidPlayer->getExtraData(fileName.c_str());
-
- if (videoExtraData) {
- warning("Loading TOT \"%s\" from video file", fileName.c_str());
+ if (!totFile.load(fileName))
+ return false;
- _totSize = videoExtraData->size();
- _totData = new byte[_totSize];
+ Common::SeekableReadStream *stream = totFile.getStream();
+ if (!stream)
+ return false;
- videoExtraData->read(_totData, _totSize);
+ _totSize = stream->size();
+ if (_totSize <= 0)
+ return false;
- delete videoExtraData;
- }
- }
+ _totData = new byte[_totSize];
+ if (stream->read(_totData, _totSize) != _totSize)
+ return false;
- if (_totData == 0)
+ if (!totFile.getProperties(_totProperties))
return false;
- return getTOTProperties();
+ return true;
}
bool Script::loadLOM(const Common::String &fileName) {
@@ -406,29 +402,7 @@ bool Script::loadLOM(const Common::String &fileName) {
delete stream;
- return getTOTProperties();
-}
-
-bool Script::getTOTProperties() {
- // Offset 39-41: Version in "Major.Minor" string form
- if (_totData[40] != '.')
- return false;
-
- _versionMajor = _totData[39] - '0';
- _versionMinor = _totData[41] - '0';
-
- _variablesCount = READ_LE_UINT32(_totData + 44);
-
- _textsOffset = READ_LE_UINT32(_totData + 48);
- _resourcesOffset = READ_LE_UINT32(_totData + 52);
-
- _animDataSize = READ_LE_UINT16(_totData + 56);
-
- _imFileNumber = _totData[59];
- _exFileNumber = _totData[60];
- _communHandling = _totData[61];
-
- return true;
+ return false;
}
void Script::unload() {
@@ -505,39 +479,39 @@ void Script::call(uint32 offset) {
}
uint8 Script::getVersionMajor() const {
- return _versionMajor;
+ return _totProperties.versionMajor;
}
uint8 Script::getVersionMinor() const {
- return _versionMinor;
+ return _totProperties.versionMinor;
}
uint32 Script::getVariablesCount() const {
- return _variablesCount;
+ return _totProperties.variablesCount;
}
uint32 Script::getTextsOffset() const {
- return _textsOffset;
+ return _totProperties.textsOffset;
}
uint32 Script::getResourcesOffset() const {
- return _resourcesOffset;
+ return _totProperties.resourcesOffset;
}
uint16 Script::getAnimDataSize() const {
- return _animDataSize;
+ return _totProperties.animDataSize;
}
uint8 Script::getImFileNumber() const {
- return _imFileNumber;
+ return _totProperties.imFileNumber;
}
uint8 Script::getExFileNumber() const {
- return _exFileNumber;
+ return _totProperties.exFileNumber;
}
uint8 Script::getCommunHandling() const {
- return _communHandling;
+ return _totProperties.communHandling;
}
uint16 Script::getFunctionOffset(uint8 function) const {
@@ -547,7 +521,7 @@ uint16 Script::getFunctionOffset(uint8 function) const {
// Offsets 100-128, 2 bytes per function
assert(function <= 13);
- return READ_LE_UINT16(_totData + 100 + function * 2);
+ return _totProperties.functions[function];
}
uint32 Script::getVariablesCount(const char *fileName, GobEngine *vm) {
diff --git a/engines/gob/script.h b/engines/gob/script.h
index f2f0571a3a..19fe2696ee 100644
--- a/engines/gob/script.h
+++ b/engines/gob/script.h
@@ -29,6 +29,8 @@
#include "common/str.h"
#include "common/stack.h"
+#include "gob/totfile.h"
+
namespace Gob {
class GobEngine;
@@ -36,11 +38,6 @@ class Expression;
class Script {
public:
- enum Function {
- kFunctionStart = 0,
- kFunctionCenter = 13
- };
-
Script(GobEngine *vm);
~Script();
@@ -154,15 +151,7 @@ private:
int16 _lomHandle;
- uint8 _versionMajor;
- uint8 _versionMinor;
- uint32 _variablesCount;
- uint32 _textsOffset;
- uint32 _resourcesOffset;
- uint16 _animDataSize;
- uint8 _imFileNumber;
- uint8 _exFileNumber;
- uint8 _communHandling;
+ TOTFile::Properties _totProperties;
Common::Stack<CallEntry> _callStack;
@@ -171,8 +160,6 @@ private:
/** Loading a LOM file. */
bool loadLOM(const Common::String &fileName);
- bool getTOTProperties();
-
/** Unloading a TOT file. */
void unloadTOT();
};
diff --git a/engines/gob/totfile.cpp b/engines/gob/totfile.cpp
new file mode 100644
index 0000000000..b8882ba588
--- /dev/null
+++ b/engines/gob/totfile.cpp
@@ -0,0 +1,101 @@
+/* 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/str.h"
+#include "common/stream.h"
+
+#include "gob/gob.h"
+#include "gob/totfile.h"
+#include "gob/dataio.h"
+#include "gob/videoplayer.h"
+
+namespace Gob {
+
+TOTFile::TOTFile(GobEngine *vm) : _vm(vm) {
+ _stream = 0;
+
+ memset(_header, 0, 128);
+}
+
+TOTFile::~TOTFile() {
+ unload();
+}
+
+bool TOTFile::load(const Common::String &fileName) {
+ if (_vm->_dataIO->existData(fileName.c_str()))
+ _stream = _vm->_dataIO->getDataStream(fileName.c_str());
+ else
+ _stream = _vm->_vidPlayer->getExtraData(fileName.c_str());
+
+ if (!_stream)
+ return false;
+
+ if (_stream->read(_header, 128) != 128)
+ return false;
+
+ _stream->seek(0);
+
+ return true;
+}
+
+void TOTFile::unload() {
+ delete _stream;
+
+ _stream = 0;
+}
+
+Common::SeekableReadStream *TOTFile::getStream() const {
+ return _stream;
+}
+
+bool TOTFile::getProperties(Properties &props) const {
+ if (!_stream)
+ return false;
+
+ // Offset 39-41: Version in "Major.Minor" string form
+ if (_header[40] != '.')
+ return false;
+
+ props.versionMajor = _header[39] - '0';
+ props.versionMinor = _header[41] - '0';
+
+ props.variablesCount = READ_LE_UINT32(_header + 44);
+
+ props.textsOffset = READ_LE_UINT32(_header + 48);
+ props.resourcesOffset = READ_LE_UINT32(_header + 52);
+
+ props.animDataSize = READ_LE_UINT16(_header + 56);
+
+ props.imFileNumber = _header[59];
+ props.exFileNumber = _header[60];
+ props.communHandling = _header[61];
+
+ for (int i = 0; i < 14; i++)
+ props.functions[i] = READ_LE_UINT16(_header + 100 + i * 2);
+
+ return true;
+}
+
+} // End of namespace Gob
diff --git a/engines/gob/totfile.h b/engines/gob/totfile.h
new file mode 100644
index 0000000000..a79cb715cc
--- /dev/null
+++ b/engines/gob/totfile.h
@@ -0,0 +1,75 @@
+/* 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_TOTFILE_H
+#define GOB_TOTFILE_H
+
+namespace Common {
+ class String;
+ class SeekableReadStream;
+}
+
+namespace Gob {
+
+class TOTFile {
+public:
+ enum Function {
+ kFunctionStart = 0,
+ kFunctionCenter = 13
+ };
+
+ struct Properties {
+ uint8 versionMajor;
+ uint8 versionMinor;
+ uint32 variablesCount;
+ uint32 textsOffset;
+ uint32 resourcesOffset;
+ uint16 animDataSize;
+ uint8 imFileNumber;
+ uint8 exFileNumber;
+ uint8 communHandling;
+ uint16 functions[14];
+ };
+
+ TOTFile(GobEngine *vm);
+ ~TOTFile();
+
+ bool load(const Common::String &fileName);
+ void unload();
+
+ Common::SeekableReadStream *getStream() const;
+ bool getProperties(Properties &props) const;
+
+private:
+ GobEngine *_vm;
+
+ Common::SeekableReadStream *_stream;
+
+ byte _header[128];
+};
+
+} // End of namespace Gob
+
+#endif // GOB_TOTFILE_H