aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/true_talk/dialogue_file.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2016-05-06 23:15:56 -0400
committerPaul Gilbert2016-07-10 16:38:39 -0400
commit695549585e4fb0578d6add32ac20d19be2c59a0b (patch)
treef2087c563d1adec22e26e3d424db9392fbe481e3 /engines/titanic/true_talk/dialogue_file.cpp
parentb138134192bda77a4c1c941e194dc9d353aae256 (diff)
downloadscummvm-rg350-695549585e4fb0578d6add32ac20d19be2c59a0b.tar.gz
scummvm-rg350-695549585e4fb0578d6add32ac20d19be2c59a0b.tar.bz2
scummvm-rg350-695549585e4fb0578d6add32ac20d19be2c59a0b.zip
TITANIC: Implemented CDialogueFile addToCache
Diffstat (limited to 'engines/titanic/true_talk/dialogue_file.cpp')
-rw-r--r--engines/titanic/true_talk/dialogue_file.cpp45
1 files changed, 40 insertions, 5 deletions
diff --git a/engines/titanic/true_talk/dialogue_file.cpp b/engines/titanic/true_talk/dialogue_file.cpp
index 341d973f36..b52bf2a885 100644
--- a/engines/titanic/true_talk/dialogue_file.cpp
+++ b/engines/titanic/true_talk/dialogue_file.cpp
@@ -24,20 +24,25 @@
namespace Titanic {
+void DialogueFileIndexEntry::load(Common::SeekableReadStream &s) {
+ _v1 = s.readUint32LE();
+ _offset = s.readUint32LE();
+}
+
+/*------------------------------------------------------------------------*/
+
CDialogueFile::CDialogueFile(const CString &filename, uint count) {
if (!_file.open(filename))
error("Could not locate dialogue file - %s", filename.c_str());
- _data1.resize(count);
+ _cache.resize(count);
_file.readUint32LE(); // Skip over file Id
_entries.resize(_file.readUint32LE());
// Read in the entries
- for (uint idx = 0; idx < _entries.size(); ++idx) {
- _entries[idx].v1 = _file.readUint32LE();
- _entries[idx].v2 = _file.readUint32LE();
- }
+ for (uint idx = 0; idx < _entries.size(); ++idx)
+ _entries[idx].load(_file);
}
CDialogueFile::~CDialogueFile() {
@@ -48,4 +53,34 @@ void CDialogueFile::clear() {
_file.close();
}
+DialogueFileCacheEntry *CDialogueFile::addToCache(int index) {
+ if (_entries.size() == 0 || index < 0 || index >= (int)_entries.size()
+ || !_entries[index]._v1)
+ return nullptr;
+
+ // Scan cache for a free slot
+ uint cacheIndex = 0;
+ while (cacheIndex < _cache.size() && !_cache[cacheIndex]._active)
+ ++cacheIndex;
+ if (cacheIndex == _cache.size())
+ return nullptr;
+
+ DialogueFileIndexEntry &entry = _entries[index];
+ DialogueFileCacheEntry &cacheEntry = _cache[cacheIndex];
+
+ cacheEntry._active = true;
+ cacheEntry._offset = entry._offset;
+ cacheEntry.v3 = 0;
+ cacheEntry._entryPtr = &entry;
+
+ // Figure out the size of the entry
+ if (index == ((int)_entries.size() - 1)) {
+ cacheEntry._size = _file.size() - entry._offset;
+ } else {
+ cacheEntry._size = _entries[index + 1]._offset - entry._offset;
+ }
+
+ return &cacheEntry;
+}
+
} // End of namespace Titanic