Putting basic TOT handling into its own class

svn-id: r41821
This commit is contained in:
Sven Hesse 2009-06-23 23:55:19 +00:00
parent 7ba3205f58
commit 04d4ce4a8b
8 changed files with 214 additions and 76 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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();

View File

@ -48,6 +48,7 @@ MODULE_OBJS := \
scenery_v1.o \
scenery_v2.o \
script.o \
totfile.o \
util.o \
variables.o \
video.o \

View File

@ -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
TOTFile totFile(_vm);
_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
Common::MemoryReadStream *videoExtraData = _vm->_vidPlayer->getExtraData(fileName.c_str());
if (videoExtraData) {
warning("Loading TOT \"%s\" from video file", fileName.c_str());
_totSize = videoExtraData->size();
_totData = new byte[_totSize];
videoExtraData->read(_totData, _totSize);
delete videoExtraData;
}
}
if (_totData == 0)
if (!totFile.load(fileName))
return false;
return getTOTProperties();
Common::SeekableReadStream *stream = totFile.getStream();
if (!stream)
return false;
_totSize = stream->size();
if (_totSize <= 0)
return false;
_totData = new byte[_totSize];
if (stream->read(_totData, _totSize) != _totSize)
return false;
if (!totFile.getProperties(_totProperties))
return false;
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) {

View File

@ -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();
};

101
engines/gob/totfile.cpp Normal file
View File

@ -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

75
engines/gob/totfile.h Normal file
View File

@ -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