From 9ce6391a94db959f3dde54ed3d0153e000aa3d5a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 8 May 2016 20:57:03 -0400 Subject: TITANIC: Beginnings of TTWord hierarchy --- engines/titanic/true_talk/script_handler.cpp | 6 +- engines/titanic/true_talk/script_handler.h | 5 ++ engines/titanic/true_talk/st_vocab.cpp | 20 ++++++- engines/titanic/true_talk/st_vocab.h | 4 +- engines/titanic/true_talk/title_engine.cpp | 15 +++-- engines/titanic/true_talk/title_engine.h | 21 +++---- engines/titanic/true_talk/tt_string.cpp | 38 ++++++++++++ engines/titanic/true_talk/tt_string.h | 39 +++++++++--- engines/titanic/true_talk/tt_word.cpp | 75 ++++++++++++++++++++++++ engines/titanic/true_talk/tt_word.h | 88 ++++++++++++++++++++++++++++ 10 files changed, 278 insertions(+), 33 deletions(-) create mode 100644 engines/titanic/true_talk/tt_word.cpp create mode 100644 engines/titanic/true_talk/tt_word.h (limited to 'engines/titanic/true_talk') diff --git a/engines/titanic/true_talk/script_handler.cpp b/engines/titanic/true_talk/script_handler.cpp index bd98aad15f..09110a3f19 100644 --- a/engines/titanic/true_talk/script_handler.cpp +++ b/engines/titanic/true_talk/script_handler.cpp @@ -53,10 +53,14 @@ ScriptChangedResult CScriptHandler::scriptChanged(TTRoomScript *roomScript, TTNp void CScriptHandler::processInput(TTRoomScript *roomScript, TTNpcScript *npcScript, const TTString &line) { - if (!roomScript || line.empty()) + if (!roomScript || !line.isValid()) return; // TODO } +SimpleFile *CScriptHandler::openResource(const CString &name) { + return _owner->open(name); +} + } // End of namespace Titanic diff --git a/engines/titanic/true_talk/script_handler.h b/engines/titanic/true_talk/script_handler.h index 16dff1bf36..38da259021 100644 --- a/engines/titanic/true_talk/script_handler.h +++ b/engines/titanic/true_talk/script_handler.h @@ -85,6 +85,11 @@ public: void processInput(TTRoomScript *roomScript, TTNpcScript *npcScript, const TTString &line); + + /** + * Open a resource for access + */ + SimpleFile *openResource(const CString &name); }; } // End of namespace Titanic diff --git a/engines/titanic/true_talk/st_vocab.cpp b/engines/titanic/true_talk/st_vocab.cpp index ed41a4a61b..b725101214 100644 --- a/engines/titanic/true_talk/st_vocab.cpp +++ b/engines/titanic/true_talk/st_vocab.cpp @@ -20,18 +20,32 @@ * */ +#include "common/file.h" #include "titanic/true_talk/st_vocab.h" +#include "titanic/titanic.h" namespace Titanic { -STVocab::STVocab(int val): _field0(0), _field4(0), _field8(0), +STVocab::STVocab(int val): _field0(0), _field4(0), _vocab(nullptr), _fieldC(0), _field10(0), _field18(val) { _field14 = load("STvocab.txt"); } int STVocab::load(const CString &name) { - // TODO - return 0; + SimpleFile *file = g_vm->_fileReader._owner->openResource(name); + int result = 0; + + while (!file->eos()) { + int mode = file->readNumber(); + + switch (mode) { + case 0: + break; + } + } + + delete file; + return result; } } // End of namespace Titanic diff --git a/engines/titanic/true_talk/st_vocab.h b/engines/titanic/true_talk/st_vocab.h index 2b4ebb8d72..090dc74237 100644 --- a/engines/titanic/true_talk/st_vocab.h +++ b/engines/titanic/true_talk/st_vocab.h @@ -24,6 +24,8 @@ #define TITANIC_ST_VOCAB_H #include "titanic/support/string.h" +#include "titanic/true_talk/tt_string.h" +#include "titanic/true_talk/tt_word.h" namespace Titanic { @@ -31,7 +33,7 @@ class STVocab { private: int _field0; int _field4; - int _field8; + TTString *_vocab; int _fieldC; int _field10; int _field14; diff --git a/engines/titanic/true_talk/title_engine.cpp b/engines/titanic/true_talk/title_engine.cpp index 3908ea0986..24cc4216ee 100644 --- a/engines/titanic/true_talk/title_engine.cpp +++ b/engines/titanic/true_talk/title_engine.cpp @@ -64,14 +64,13 @@ void STtitleEngine::dump(int val1, int val2) { // TODO } -void STtitleEngine::open(const CString &name) { - _stream = _resources.getResource(Common::WinResourceID("Text"), - name); -} - -void STtitleEngine::close() { - delete _stream; - _stream = nullptr; +SimpleFile *STtitleEngine::open(const CString &name) { + Common::SeekableReadStream *stream = _resources.getResource( + Common::WinResourceID("Text"), name); + + SimpleFile *file = new SimpleFile(); + file->open(stream); + return file; } } // End of namespace Titanic diff --git a/engines/titanic/true_talk/title_engine.h b/engines/titanic/true_talk/title_engine.h index 12a02e2b81..fda35ac7bf 100644 --- a/engines/titanic/true_talk/title_engine.h +++ b/engines/titanic/true_talk/title_engine.h @@ -32,6 +32,13 @@ namespace Titanic { +class CTitleEngine; + +class CTitleStream : public SimpleFile { +public: + CTitleStream() : SimpleFile() {} +}; + class CTitleEngine { public: CScriptHandler *_scriptHandler; @@ -56,12 +63,7 @@ public: /** * Open a designated file */ - virtual void open(const CString &name) = 0; - - /** - * Close the file - */ - virtual void close() = 0; + virtual SimpleFile *open(const CString &name) = 0; }; class STtitleEngine : public CTitleEngine { @@ -96,12 +98,7 @@ public: /** * Open a designated file */ - virtual void open(const CString &name); - - /** - * Close the file - */ - virtual void close(); + virtual SimpleFile *open(const CString &name); }; } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_string.cpp b/engines/titanic/true_talk/tt_string.cpp index f9ae5d6e11..ffe6509e07 100644 --- a/engines/titanic/true_talk/tt_string.cpp +++ b/engines/titanic/true_talk/tt_string.cpp @@ -24,4 +24,42 @@ namespace Titanic { +TTString::TTString() : _status(SS_VALID) { + _data = new TTStringData(); +} + +TTString::TTString(const char *str) : _status(SS_VALID) { + _data = new TTStringData(str); +} + +TTString::TTString(const CString &str) { + if (_status != SS_VALID) { + _status = SS_5; + _data = nullptr; + } else { + _status = SS_VALID; + _data = new TTStringData(str); + } +} + +TTString::TTString(TTString &str) { + if (_status != SS_VALID) { + _status = SS_5; + _data = nullptr; + } else { + _status = SS_VALID; + _data = str._data; + _data->_referenceCount++; + } +} + +TTString::~TTString() { + if (--_data->_referenceCount == 0) + delete _data; +} + +bool TTString::isValid() const { + return _status == SS_VALID; +} + } // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_string.h b/engines/titanic/true_talk/tt_string.h index d593553f5c..947007f1ff 100644 --- a/engines/titanic/true_talk/tt_string.h +++ b/engines/titanic/true_talk/tt_string.h @@ -27,18 +27,41 @@ namespace Titanic { -class TTString: public CString { +class TTStringData { +private: + CString _string; public: - int _status; + int _referenceCount; public: - TTString() : CString(), _status(0) {} - TTString(const char *str) : CString(str), _status(0) {} - TTString(const CString &str) : CString(str), _status(0) {} - virtual ~TTString() {} + TTStringData() : _referenceCount(1) {} + TTStringData(const char *str) : _string(str), _referenceCount(1) {} + TTStringData(const CString &str) : _string(str), _referenceCount(1) {} +}; + +enum TTStringStatus { SS_VALID = 0, SS_5 = 5, SS_7 = 7 }; + +class TTString { +private: + TTStringData *_data; + TTStringStatus _status; +public: + TTString(); + TTString(const char *str); + TTString(const CString &str); + TTString(TTString &str); + virtual ~TTString(); + + /** + * Returns true if the string is valid + */ + bool isValid() const; - bool isValid() const { return !_status; } + /** + * Get the status of the string + */ + TTStringStatus getStatus() const { return _status; } }; } // End of namespace Titanic -#endif /* TITANIC_TT_OBJ8_H */ +#endif /* TITANIC_TT_STRING_H */ diff --git a/engines/titanic/true_talk/tt_word.cpp b/engines/titanic/true_talk/tt_word.cpp new file mode 100644 index 0000000000..4405f72555 --- /dev/null +++ b/engines/titanic/true_talk/tt_word.cpp @@ -0,0 +1,75 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "titanic/true_talk/tt_word.h" + +namespace Titanic { + +TTWord::TTWord(TTString &str, int val1, int val2) : _string(str), + _field18(val1), _field1C(val2), _fieldC(0), _field10(0), + _field20(0), _field24(0), _field28(0) { + _status = str.getStatus() == SS_VALID ? SS_VALID : SS_5; +} + +/*------------------------------------------------------------------------*/ + +void TTWord::readSyn(SimpleFile *file) { +} + +/*------------------------------------------------------------------------*/ + +TTWord1::TTWord1(TTString &str, int val1, int val2, int val3) : + TTWord(str, val1, val2), _field2C(val3) { +} + +/*------------------------------------------------------------------------*/ + +TTWord2::TTWord2(TTString &str, int val1, int val2, int val3, int val4) : + TTWord1(str, val1, val2, val3), _field30(val4) { +} + +/*------------------------------------------------------------------------*/ + +TTWord3::TTWord3(TTString &str, int val1, int val2, int val3, int val4, int val5, int val6) : + TTWord1(str, val1, val2, val4), _field34(val3), _field30(val5), _field3C(val6), + _field38(0) { +} + +/*------------------------------------------------------------------------*/ + +TTWord4::TTWord4(TTString &str, int val1, int val2, int val3, int val4) : + TTWord1(str, val1, val2, val3) { + if (val4 >= 0 && val4 <= 9) { + _field30 = val4; + } else { + _field30 = 0; + _status = SS_5; + } +} + +/*------------------------------------------------------------------------*/ + +TTWord5::TTWord5(TTString &str, int val1, int val2, int val3, int val4) : + TTWord1(str, val1, val2, val3), _field30(val4) { +} + +} // End of namespace Titanic diff --git a/engines/titanic/true_talk/tt_word.h b/engines/titanic/true_talk/tt_word.h new file mode 100644 index 0000000000..d8b34ed04e --- /dev/null +++ b/engines/titanic/true_talk/tt_word.h @@ -0,0 +1,88 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef TITANIC_TT_WORD_H +#define TITANIC_TT_WORD_H + +#include "titanic/support/simple_file.h" +#include "titanic/true_talk/tt_string.h" + +namespace Titanic { + +class TTWord { +protected: + TTString _string; + int _fieldC; + int _field10; + TTStringStatus _status; + int _field18; + int _field1C; + int _field20; + int _field24; + int _field28; +public: + TTWord(TTString &str, int val1, int val2); + + void readSyn(SimpleFile *file); +}; + +class TTWord1 : public TTWord { +protected: + int _field2C; +public: + TTWord1(TTString &str, int val1, int val2, int val3); +}; + +class TTWord2 : public TTWord1 { +protected: + int _field30; +public: + TTWord2(TTString &str, int val1, int val2, int val3, int val4); +}; + +class TTWord3 : public TTWord1 { +protected: + int _field30; + int _field34; + int _field38; + int _field3C; +public: + TTWord3(TTString &str, int val1, int val2, int val3, int val4, int val5, int val6); +}; + +class TTWord4 : public TTWord1 { +protected: + int _field30; +public: + TTWord4(TTString &str, int val1, int val2, int val3, int val4); +}; + +class TTWord5 : public TTWord1 { +protected: + int _field30; +public: + TTWord5(TTString &str, int val1, int val2, int val3, int val4); +}; + +} // End of namespace Titanic + +#endif /* TITANIC_TT_WORD_H */ -- cgit v1.2.3