diff options
Diffstat (limited to 'engines/titanic/true_talk')
-rw-r--r-- | engines/titanic/true_talk/dialogue_file.cpp | 45 | ||||
-rw-r--r-- | engines/titanic/true_talk/dialogue_file.h | 32 |
2 files changed, 63 insertions, 14 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 diff --git a/engines/titanic/true_talk/dialogue_file.h b/engines/titanic/true_talk/dialogue_file.h index 00bacacbd2..8d40045686 100644 --- a/engines/titanic/true_talk/dialogue_file.h +++ b/engines/titanic/true_talk/dialogue_file.h @@ -28,18 +28,27 @@ namespace Titanic { +struct DialogueFileIndexEntry { + uint _v1, _offset; + + DialogueFileIndexEntry() : _v1(0), _offset(0) {} + void load(Common::SeekableReadStream &s); +}; + +struct DialogueFileCacheEntry { + bool _active; + uint _offset, v3, _size; + DialogueFileIndexEntry *_entryPtr; + + DialogueFileCacheEntry() : _active(false), _offset(0), _size(0), + v3(0), _entryPtr(nullptr) {} +}; + class CDialogueFile { - struct CDialogueFileEntry { - uint v1; - uint v2; - }; - struct EntryRec { - uint v1, v2, v3, v4, v5; - }; private: Common::File _file; - Common::Array<CDialogueFileEntry> _entries; - Common::Array<EntryRec> _data1; + Common::Array<DialogueFileIndexEntry> _entries; + Common::Array<DialogueFileCacheEntry> _cache; public: CDialogueFile(const CString &filename, uint count); ~CDialogueFile(); @@ -48,6 +57,11 @@ public: * Clear the loaded data */ void clear(); + + /** + * Add a dialogue file entry to the active cache + */ + DialogueFileCacheEntry *addToCache(int index); }; } // End of namespace Titanic |