aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-05-06 23:44:58 -0400
committerPaul Gilbert2016-07-10 16:38:40 -0400
commit09002173031558ccda8c05ef4cc1df329d1da6eb (patch)
treef96cb2ee5551513646c5a00f866a267e70a6a98b
parent695549585e4fb0578d6add32ac20d19be2c59a0b (diff)
downloadscummvm-rg350-09002173031558ccda8c05ef4cc1df329d1da6eb.tar.gz
scummvm-rg350-09002173031558ccda8c05ef4cc1df329d1da6eb.tar.bz2
scummvm-rg350-09002173031558ccda8c05ef4cc1df329d1da6eb.zip
TITANIC: Implement CDialogueFile read
-rw-r--r--engines/titanic/true_talk/dialogue_file.cpp19
-rw-r--r--engines/titanic/true_talk/dialogue_file.h32
2 files changed, 45 insertions, 6 deletions
diff --git a/engines/titanic/true_talk/dialogue_file.cpp b/engines/titanic/true_talk/dialogue_file.cpp
index b52bf2a885..1d1d789188 100644
--- a/engines/titanic/true_talk/dialogue_file.cpp
+++ b/engines/titanic/true_talk/dialogue_file.cpp
@@ -55,7 +55,7 @@ void CDialogueFile::clear() {
DialogueFileCacheEntry *CDialogueFile::addToCache(int index) {
if (_entries.size() == 0 || index < 0 || index >= (int)_entries.size()
- || !_entries[index]._v1)
+ || _cache.empty())
return nullptr;
// Scan cache for a free slot
@@ -70,7 +70,7 @@ DialogueFileCacheEntry *CDialogueFile::addToCache(int index) {
cacheEntry._active = true;
cacheEntry._offset = entry._offset;
- cacheEntry.v3 = 0;
+ cacheEntry._bytesRead = 0;
cacheEntry._entryPtr = &entry;
// Figure out the size of the entry
@@ -80,7 +80,22 @@ DialogueFileCacheEntry *CDialogueFile::addToCache(int index) {
cacheEntry._size = _entries[index + 1]._offset - entry._offset;
}
+ // Return a pointer to the loaded entry
return &cacheEntry;
}
+bool CDialogueFile::read(DialogueFileCacheEntry *cacheEntry, byte *buffer, size_t bytesToRead) {
+ // Sanity checks that a valid record is passed, and the size can be read
+ if (!cacheEntry || !cacheEntry->_active || !bytesToRead
+ || (cacheEntry->_bytesRead + bytesToRead) > cacheEntry->_size)
+ return false;
+
+ // Move to the correct position in the file
+ _file.seek(cacheEntry->_offset + cacheEntry->_bytesRead);
+ bool result = _file.read(buffer, bytesToRead) == bytesToRead;
+ cacheEntry->_bytesRead += bytesToRead;
+
+ return result;
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/true_talk/dialogue_file.h b/engines/titanic/true_talk/dialogue_file.h
index 8d40045686..5db91d9c4c 100644
--- a/engines/titanic/true_talk/dialogue_file.h
+++ b/engines/titanic/true_talk/dialogue_file.h
@@ -37,11 +37,16 @@ struct DialogueFileIndexEntry {
struct DialogueFileCacheEntry {
bool _active;
- uint _offset, v3, _size;
+ uint _offset, _bytesRead, _size;
DialogueFileIndexEntry *_entryPtr;
- DialogueFileCacheEntry() : _active(false), _offset(0), _size(0),
- v3(0), _entryPtr(nullptr) {}
+ DialogueFileCacheEntry() : _active(false), _offset(0),
+ _bytesRead(0), _size(0), _entryPtr(nullptr) {}
+
+ /**
+ * Return the size of a cache entry
+ */
+ int size() const { return _active ? _size : 0; }
};
class CDialogueFile {
@@ -49,6 +54,11 @@ private:
Common::File _file;
Common::Array<DialogueFileIndexEntry> _entries;
Common::Array<DialogueFileCacheEntry> _cache;
+private:
+ /**
+ * Add a dialogue file entry to the active cache
+ */
+ DialogueFileCacheEntry *addToCache(int index);
public:
CDialogueFile(const CString &filename, uint count);
~CDialogueFile();
@@ -61,7 +71,21 @@ public:
/**
* Add a dialogue file entry to the active cache
*/
- DialogueFileCacheEntry *addToCache(int index);
+ DialogueFileCacheEntry *addToCacheDouble(int index) {
+ return addToCache(index * 2);
+ }
+
+ /**
+ * Add a dialogue file entry to the active cache
+ */
+ DialogueFileCacheEntry *addToCacheDouble1(int index) {
+ return addToCache(index * 2 + 1);
+ }
+
+ /**
+ * Read data for a resource
+ */
+ bool read(DialogueFileCacheEntry *cacheEntry, byte *buffer, size_t bytesToRead);
};
} // End of namespace Titanic