aboutsummaryrefslogtreecommitdiff
path: root/engines/lure
diff options
context:
space:
mode:
authorPaul Gilbert2015-11-16 20:48:01 -0500
committerPaul Gilbert2015-11-16 20:48:01 -0500
commitf8b36bf8551c374616b88773b3b03e8c73092c8d (patch)
treeeca210e9cb7c27395d91e4bd1a4fbcec068efbb7 /engines/lure
parentf68dae1849adc933838fca5c37f271ca737e7a17 (diff)
downloadscummvm-rg350-f8b36bf8551c374616b88773b3b03e8c73092c8d.tar.gz
scummvm-rg350-f8b36bf8551c374616b88773b3b03e8c73092c8d.tar.bz2
scummvm-rg350-f8b36bf8551c374616b88773b3b03e8c73092c8d.zip
LURE: Simplify StringList class
Diffstat (limited to 'engines/lure')
-rw-r--r--engines/lure/res_struct.cpp21
-rw-r--r--engines/lure/res_struct.h13
2 files changed, 12 insertions, 22 deletions
diff --git a/engines/lure/res_struct.cpp b/engines/lure/res_struct.cpp
index 5a4761c87b..73efc3a29a 100644
--- a/engines/lure/res_struct.cpp
+++ b/engines/lure/res_struct.cpp
@@ -1217,26 +1217,19 @@ void BarmanLists::loadFromStream(Common::ReadStream *stream) {
// String list resource class
void StringList::load(MemoryBlock *data) {
- _data = Memory::allocate(data->size());
- _data->copyFrom(data);
+ // Get the number of entries
+ uint count = READ_LE_UINT16(data->data());
- _numEntries = READ_LE_UINT16(_data->data());
- char *p = (char *) _data->data() + sizeof(uint16);
-
- _entries = (char **) Memory::alloc(_numEntries * sizeof(char *));
-
- for (int index = 0; index < _numEntries; ++index) {
- _entries[index] = p;
+ // Iterate through loading the strings one at a time
+ const char *p = (const char *)data->data() + sizeof(uint16);
+ for (uint index = 0; index < count; ++index) {
+ _entries.push_back(p);
p += strlen(p) + 1;
}
}
void StringList::clear() {
- if (_numEntries != 0) {
- Memory::dealloc(_entries);
- delete _data;
- _numEntries = 0;
- }
+ _entries.clear();
}
// Field list and miscellaneous variables
diff --git a/engines/lure/res_struct.h b/engines/lure/res_struct.h
index 9190912f5b..72cfa2ff99 100644
--- a/engines/lure/res_struct.h
+++ b/engines/lure/res_struct.h
@@ -28,6 +28,7 @@
#include "common/list.h"
#include "common/file.h"
#include "common/ptr.h"
+#include "common/str-array.h"
#include "common/textconsole.h"
namespace Lure {
@@ -850,19 +851,15 @@ enum StringEnum {S_CREDITS = 25, S_RESTART_GAME = 26, S_SAVE_GAME = 27, S_RESTOR
class StringList {
private:
- MemoryBlock *_data;
- int _numEntries;
- char **_entries;
+ Common::StringArray _entries;
public:
- StringList() { _numEntries = 0; }
- ~StringList() { clear(); }
+ StringList() {}
void load(MemoryBlock *data);
void clear();
- int count() { return _numEntries; }
+ int count() { return _entries.size(); }
const char *getString(int index) {
- if ((index < 0) || (index >= _numEntries)) error("Invalid index specified to String List");
- return _entries[index];
+ return _entries[index].c_str();
}
const char *getString(Action action) { return getString((int) action - 1); }
const char *getString(StringEnum sEnum) { return getString((int) sEnum); }