aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorNicola Mettifogo2007-09-17 18:22:52 +0000
committerNicola Mettifogo2007-09-17 18:22:52 +0000
commitef0df159f14ffae39860801db1c6c7f5c7872137 (patch)
tree3d013309447f10ec0958c9be2ac636575cbde0f6 /engines
parentc4aa4fe644a13d381a9140db6c7b93db7eb1f30c (diff)
downloadscummvm-rg350-ef0df159f14ffae39860801db1c6c7f5c7872137.tar.gz
scummvm-rg350-ef0df159f14ffae39860801db1c6c7f5c7872137.tar.bz2
scummvm-rg350-ef0df159f14ffae39860801db1c6c7f5c7872137.zip
* 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 svn-id: r28933
Diffstat (limited to 'engines')
-rw-r--r--engines/parallaction/disk_br.cpp8
-rw-r--r--engines/parallaction/disk_ns.cpp16
-rw-r--r--engines/parallaction/objects.cpp67
-rw-r--r--engines/parallaction/objects.h34
-rw-r--r--engines/parallaction/parallaction.cpp56
-rw-r--r--engines/parallaction/parallaction.h31
6 files changed, 104 insertions, 108 deletions
diff --git a/engines/parallaction/disk_br.cpp b/engines/parallaction/disk_br.cpp
index 64eb6b533d..5b79ad7df6 100644
--- a/engines/parallaction/disk_br.cpp
+++ b/engines/parallaction/disk_br.cpp
@@ -357,13 +357,7 @@ Table* DosDisk_br::loadTable(const char* name) {
if (!stream.open(path))
errorFileNotFound(path);
- Table *t = new Table(100);
-
- fillBuffers(stream);
- while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
- t->addData(_tokens[0]);
- fillBuffers(stream);
- }
+ Table *t = createTableFromStream(100, stream);
stream.close();
diff --git a/engines/parallaction/disk_ns.cpp b/engines/parallaction/disk_ns.cpp
index cb224b713b..8b5ce850ff 100644
--- a/engines/parallaction/disk_ns.cpp
+++ b/engines/parallaction/disk_ns.cpp
@@ -659,13 +659,7 @@ Table* DosDisk_ns::loadTable(const char* name) {
if (!stream.open(path))
errorFileNotFound(path);
- Table *t = new Table(100);
-
- fillBuffers(stream);
- while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
- t->addData(_tokens[0]);
- fillBuffers(stream);
- }
+ Table *t = createTableFromStream(100, stream);
stream.close();
@@ -1404,13 +1398,7 @@ Table* AmigaDisk_ns::loadTable(const char* name) {
stream = &_resArchive;
}
- Table *t = new Table(100);
-
- fillBuffers(*stream);
- while (scumm_stricmp(_tokens[0], "ENDTABLE")) {
- t->addData(_tokens[0]);
- fillBuffers(*stream);
- }
+ Table *t = createTableFromStream(100, *stream);
if (dispose)
delete stream;
diff --git a/engines/parallaction/objects.cpp b/engines/parallaction/objects.cpp
index c856d419e3..0e0d7c4c38 100644
--- a/engines/parallaction/objects.cpp
+++ b/engines/parallaction/objects.cpp
@@ -25,6 +25,7 @@
#include "common/stdafx.h"
#include "parallaction/objects.h"
+#include "parallaction/parser.h"
namespace Parallaction {
@@ -337,5 +338,71 @@ ScriptVar::ScriptVar() {
_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
diff --git a/engines/parallaction/objects.h b/engines/parallaction/objects.h
index b456a1960a..41e8bbcf5d 100644
--- a/engines/parallaction/objects.h
+++ b/engines/parallaction/objects.h
@@ -424,6 +424,40 @@ typedef Animation* AnimationPointer;
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
diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp
index 9b2ac2a6a1..7b641bf838 100644
--- a/engines/parallaction/parallaction.cpp
+++ b/engines/parallaction/parallaction.cpp
@@ -752,62 +752,6 @@ void Parallaction::runJobs() {
}
-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) {
diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h
index 7c9c93a0bf..c0975d4c85 100644
--- a/engines/parallaction/parallaction.h
+++ b/engines/parallaction/parallaction.h
@@ -253,38 +253,7 @@ struct Character {
};
-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;