diff options
author | Nicola Mettifogo | 2007-09-17 18:22:52 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2007-09-17 18:22:52 +0000 |
commit | ef0df159f14ffae39860801db1c6c7f5c7872137 (patch) | |
tree | 3d013309447f10ec0958c9be2ac636575cbde0f6 /engines/parallaction/objects.cpp | |
parent | c4aa4fe644a13d381a9140db6c7b93db7eb1f30c (diff) | |
download | scummvm-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/parallaction/objects.cpp')
-rw-r--r-- | engines/parallaction/objects.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
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 |