[Scummvm-cvs-logs] SF.net SVN: scummvm: [28933] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Mon Sep 17 20:22:52 CEST 2007


Revision: 28933
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28933&view=rev
Author:   peres001
Date:     2007-09-17 11:22:52 -0700 (Mon, 17 Sep 2007)

Log Message:
-----------
* moved Table handling to objects.cpp 
* added helper functions to load tables from files
* fixed occasional lock-ups on location change because of broken Table deallocation

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/disk_br.cpp
    scummvm/trunk/engines/parallaction/disk_ns.cpp
    scummvm/trunk/engines/parallaction/objects.cpp
    scummvm/trunk/engines/parallaction/objects.h
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h

Modified: scummvm/trunk/engines/parallaction/disk_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/disk_br.cpp	2007-09-16 15:15:15 UTC (rev 28932)
+++ scummvm/trunk/engines/parallaction/disk_br.cpp	2007-09-17 18:22:52 UTC (rev 28933)
@@ -357,14 +357,8 @@
 	if (!stream.open(path))
 		errorFileNotFound(path);
 
-	Table *t = new Table(100);
+	Table *t = createTableFromStream(100, stream);
 
-	fillBuffers(stream);
-	while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
-		t->addData(_tokens[0]);
-		fillBuffers(stream);
-	}
-
 	stream.close();
 
 	return t;

Modified: scummvm/trunk/engines/parallaction/disk_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/disk_ns.cpp	2007-09-16 15:15:15 UTC (rev 28932)
+++ scummvm/trunk/engines/parallaction/disk_ns.cpp	2007-09-17 18:22:52 UTC (rev 28933)
@@ -659,14 +659,8 @@
 	if (!stream.open(path))
 		errorFileNotFound(path);
 
-	Table *t = new Table(100);
+	Table *t = createTableFromStream(100, stream);
 
-	fillBuffers(stream);
-	while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
-		t->addData(_tokens[0]);
-		fillBuffers(stream);
-	}
-
 	stream.close();
 
 	return t;
@@ -1404,14 +1398,8 @@
 		stream = &_resArchive;
 	}
 
-	Table *t = new Table(100);
+	Table *t = createTableFromStream(100, *stream);
 
-	fillBuffers(*stream);
-	while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
-		t->addData(_tokens[0]);
-		fillBuffers(*stream);
-	}
-
 	if (dispose)
 		delete stream;
 

Modified: scummvm/trunk/engines/parallaction/objects.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/objects.cpp	2007-09-16 15:15:15 UTC (rev 28932)
+++ scummvm/trunk/engines/parallaction/objects.cpp	2007-09-17 18:22:52 UTC (rev 28933)
@@ -25,6 +25,7 @@
 
 #include "common/stdafx.h"
 #include "parallaction/objects.h"
+#include "parallaction/parser.h"
 
 namespace Parallaction {
 
@@ -337,5 +338,71 @@
 	_pvalue = 0;
 }
 
+Table::Table(uint32 size) : _size(size), _used(0), _disposeMemory(true) {
+	_data = (char**)calloc(size, sizeof(char*));
+}
 
+Table::Table(uint32 size, const char **data) : _size(size), _used(size), _disposeMemory(false) {
+	_data = const_cast<char**>(data);
+}
+
+Table::~Table() {
+
+	if (!_disposeMemory) return;
+
+	clear();
+
+	free(_data);
+
+}
+
+void Table::addData(const char* s) {
+
+	if (!(_used < _size))
+		error("Table overflow");
+
+	_data[_used++] = strdup(s);
+
+}
+
+uint16 Table::lookup(const char* s) {
+
+	for (uint16 i = 0; i < _used; i++) {
+		if (!scumm_stricmp(_data[i], s)) return i + 1;
+	}
+
+	return notFound;
+}
+
+void Table::clear() {
+	for (uint32 i = 0; i < _used; i++)
+		free(_data[i]);
+
+	_used = 0;
+}
+
+FixedTable::FixedTable(uint32 size, uint32 fixed) : Table(size), _numFixed(fixed) {
+}
+
+void FixedTable::clear() {
+	for (uint32 i = _numFixed; i < _used; i++) {
+		free(_data[i]);
+		_used--;
+	}
+}
+
+Table* createTableFromStream(uint32 size, Common::SeekableReadStream &stream) {
+
+	Table *t = new Table(size);
+
+	fillBuffers(stream);
+	while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
+		t->addData(_tokens[0]);
+		fillBuffers(stream);
+	}
+
+	return t;
+}
+
+
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/objects.h
===================================================================
--- scummvm/trunk/engines/parallaction/objects.h	2007-09-16 15:15:15 UTC (rev 28932)
+++ scummvm/trunk/engines/parallaction/objects.h	2007-09-17 18:22:52 UTC (rev 28933)
@@ -424,6 +424,40 @@
 typedef ManagedList<AnimationPointer> AnimationList;
 
 
+class Table {
+
+protected:
+	char	**_data;
+	uint16	_size;
+	uint16	_used;
+	bool	_disposeMemory;
+
+public:
+	Table(uint32 size);
+	Table(uint32 size, const char** data);
+
+	virtual ~Table();
+
+	enum {
+		notFound = 0
+	};
+
+	virtual void addData(const char* s);
+	virtual void clear();
+	virtual uint16 lookup(const char* s);
+};
+
+class FixedTable : public Table {
+
+	uint16	_numFixed;
+
+public:
+	FixedTable(uint32 size, uint32 fixed);
+	void clear();
+};
+
+Table* createTableFromStream(uint32 size, Common::SeekableReadStream &stream);
+
 } // namespace Parallaction
 
 #endif

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2007-09-16 15:15:15 UTC (rev 28932)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2007-09-17 18:22:52 UTC (rev 28933)
@@ -752,64 +752,8 @@
 }
 
 
-Table::Table(uint32 size) : _size(size), _used(0), _disposeMemory(true) {
-	_data = (char**)malloc(sizeof(char*)*size);
-}
 
-Table::Table(uint32 size, const char **data) : _size(size), _used(size), _disposeMemory(false) {
-	_data = const_cast<char**>(data);
-}
 
-Table::~Table() {
-
-	if (!_disposeMemory) return;
-
-	clear();
-
-	free(_data);
-
-}
-
-void Table::addData(const char* s) {
-
-	if (!(_used < _size))
-		error("Table overflow");
-
-	_data[_used++] = strdup(s);
-
-}
-
-uint16 Table::lookup(const char* s) {
-
-	for (uint16 i = 0; i < _used; i++) {
-		if (!scumm_stricmp(_data[i], s)) return i + 1;
-	}
-
-	return notFound;
-}
-
-void Table::clear() {
-	for (uint32 i = 0; i < _used; i++)
-		free(_data[i]);
-
-	_used = 0;
-}
-
-FixedTable::FixedTable(uint32 size, uint32 fixed) : Table(size), _numFixed(fixed) {
-}
-
-FixedTable::~FixedTable() {
-	_numFixed = 0;
-}
-
-void FixedTable::clear() {
-	for (uint32 i = _numFixed; i < _used; i++) {
-		free(_data[i]);
-		_used--;
-	}
-}
-
-
 void Parallaction::pushParserTables(OpcodeSet *opcodes, Table *statements) {
 	_opcodes.push(_currentOpcodes);
 	_statements.push(_currentStatements);

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2007-09-16 15:15:15 UTC (rev 28932)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2007-09-17 18:22:52 UTC (rev 28933)
@@ -253,39 +253,8 @@
 };
 
 
-class Table {
 
-protected:
-	char	**_data;
-	uint16	_size;
-	uint16	_used;
-	bool	_disposeMemory;
 
-public:
-	Table(uint32 size);
-	Table(uint32 size, const char** data);
-
-	virtual ~Table();
-
-	enum {
-		notFound = 0
-	};
-
-	virtual void addData(const char* s);
-	virtual void clear();
-	virtual uint16 lookup(const char* s);
-};
-
-class FixedTable : public Table {
-
-	uint16	_numFixed;
-
-public:
-	FixedTable(uint32 size, uint32 fixed);
-	~FixedTable();
-	void clear();
-};
-
 struct BackgroundInfo {
 	uint width;
 	uint height;


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