[Scummvm-cvs-logs] SF.net SVN: scummvm:[41821] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Wed Jun 24 01:55:19 CEST 2009


Revision: 41821
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41821&view=rev
Author:   drmccoy
Date:     2009-06-23 23:55:19 +0000 (Tue, 23 Jun 2009)

Log Message:
-----------
Putting basic TOT handling into its own class

Modified Paths:
--------------
    scummvm/trunk/engines/gob/draw.cpp
    scummvm/trunk/engines/gob/game_v1.cpp
    scummvm/trunk/engines/gob/game_v2.cpp
    scummvm/trunk/engines/gob/module.mk
    scummvm/trunk/engines/gob/script.cpp
    scummvm/trunk/engines/gob/script.h

Added Paths:
-----------
    scummvm/trunk/engines/gob/totfile.cpp
    scummvm/trunk/engines/gob/totfile.h

Modified: scummvm/trunk/engines/gob/draw.cpp
===================================================================
--- scummvm/trunk/engines/gob/draw.cpp	2009-06-23 23:08:29 UTC (rev 41820)
+++ scummvm/trunk/engines/gob/draw.cpp	2009-06-23 23:55:19 UTC (rev 41821)
@@ -390,7 +390,7 @@
 	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);
 

Modified: scummvm/trunk/engines/gob/game_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/game_v1.cpp	2009-06-23 23:08:29 UTC (rev 41820)
+++ scummvm/trunk/engines/gob/game_v1.cpp	2009-06-23 23:55:19 UTC (rev 41821)
@@ -164,7 +164,7 @@
 			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();
 

Modified: scummvm/trunk/engines/gob/game_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/game_v2.cpp	2009-06-23 23:08:29 UTC (rev 41820)
+++ scummvm/trunk/engines/gob/game_v2.cpp	2009-06-23 23:55:19 UTC (rev 41821)
@@ -199,7 +199,7 @@
 			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();
 

Modified: scummvm/trunk/engines/gob/module.mk
===================================================================
--- scummvm/trunk/engines/gob/module.mk	2009-06-23 23:08:29 UTC (rev 41820)
+++ scummvm/trunk/engines/gob/module.mk	2009-06-23 23:55:19 UTC (rev 41821)
@@ -48,6 +48,7 @@
 	scenery_v1.o \
 	scenery_v2.o \
 	script.o \
+	totfile.o \
 	util.o \
 	variables.o \
 	video.o \

Modified: scummvm/trunk/engines/gob/script.cpp
===================================================================
--- scummvm/trunk/engines/gob/script.cpp	2009-06-23 23:08:29 UTC (rev 41820)
+++ scummvm/trunk/engines/gob/script.cpp	2009-06-23 23:55:19 UTC (rev 41821)
@@ -44,6 +44,8 @@
 	_totSize = 0;
 
 	_lomHandle = -1;
+
+	memset(&_totProperties, 0, sizeof(TOTFile::Properties));
 }
 
 Script::~Script() {
@@ -359,33 +361,27 @@
 }
 
 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());
+	if (!totFile.load(fileName))
+		return false;
 
-	} else  {
-		// Trying to read the TOT file out of the currently loaded video file
+	Common::SeekableReadStream *stream = totFile.getStream();
+	if (!stream)
+		return false;
 
-		Common::MemoryReadStream *videoExtraData = _vm->_vidPlayer->getExtraData(fileName.c_str());
+	_totSize = stream->size();
+	if (_totSize <= 0)
+		return false;
 
-		if (videoExtraData) {
-			warning("Loading TOT \"%s\" from video file", fileName.c_str());
+	_totData = new byte[_totSize];
+	if (stream->read(_totData, _totSize) != _totSize)
+		return false;
 
-			_totSize = videoExtraData->size();
-			_totData = new byte[_totSize];
-
-			videoExtraData->read(_totData, _totSize);
-
-			delete videoExtraData;
-		}
-	}
-
-	if (_totData == 0)
+	if (!totFile.getProperties(_totProperties))
 		return false;
 
-	return getTOTProperties();
+	return true;
 }
 
 bool Script::loadLOM(const Common::String &fileName) {
@@ -406,31 +402,9 @@
 
 	delete stream;
 
-	return getTOTProperties();
+	return false;
 }
 
-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;
-}
-
 void Script::unload() {
 	unloadTOT();
 }
@@ -505,39 +479,39 @@
 }
 
 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 @@
 	// 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) {

Modified: scummvm/trunk/engines/gob/script.h
===================================================================
--- scummvm/trunk/engines/gob/script.h	2009-06-23 23:08:29 UTC (rev 41820)
+++ scummvm/trunk/engines/gob/script.h	2009-06-23 23:55:19 UTC (rev 41821)
@@ -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 Script {
 public:
-	enum Function {
-		kFunctionStart  =  0,
-		kFunctionCenter = 13
-	};
-
 	Script(GobEngine *vm);
 	~Script();
 
@@ -154,15 +151,7 @@
 
 	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 @@
 	/** Loading a LOM file. */
 	bool loadLOM(const Common::String &fileName);
 
-	bool getTOTProperties();
-
 	/** Unloading a TOT file. */
 	void unloadTOT();
 };

Added: scummvm/trunk/engines/gob/totfile.cpp
===================================================================
--- scummvm/trunk/engines/gob/totfile.cpp	                        (rev 0)
+++ scummvm/trunk/engines/gob/totfile.cpp	2009-06-23 23:55:19 UTC (rev 41821)
@@ -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


Property changes on: scummvm/trunk/engines/gob/totfile.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Added: scummvm/trunk/engines/gob/totfile.h
===================================================================
--- scummvm/trunk/engines/gob/totfile.h	                        (rev 0)
+++ scummvm/trunk/engines/gob/totfile.h	2009-06-23 23:55:19 UTC (rev 41821)
@@ -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


Property changes on: scummvm/trunk/engines/gob/totfile.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list