diff options
author | Paul Gilbert | 2016-04-03 15:51:42 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-04-03 15:51:42 -0400 |
commit | 432153274385295a9a4eb01e56bfcc72cc5f202e (patch) | |
tree | 9111795dac811facf2b71691a5ef19326f0bc251 | |
parent | 32f7fcc7a0a74bcb3ffeb6899bf209099f9b55d5 (diff) | |
download | scummvm-rg350-432153274385295a9a4eb01e56bfcc72cc5f202e.tar.gz scummvm-rg350-432153274385295a9a4eb01e56bfcc72cc5f202e.tar.bz2 scummvm-rg350-432153274385295a9a4eb01e56bfcc72cc5f202e.zip |
TITANIC: Working on font loading
-rw-r--r-- | engines/titanic/files_manager.cpp | 18 | ||||
-rw-r--r-- | engines/titanic/files_manager.h | 9 | ||||
-rw-r--r-- | engines/titanic/font.cpp | 33 | ||||
-rw-r--r-- | engines/titanic/font.h | 14 | ||||
-rw-r--r-- | engines/titanic/string.cpp | 11 | ||||
-rw-r--r-- | engines/titanic/string.h | 5 |
6 files changed, 87 insertions, 3 deletions
diff --git a/engines/titanic/files_manager.cpp b/engines/titanic/files_manager.cpp index 617b71b06a..10898909e2 100644 --- a/engines/titanic/files_manager.cpp +++ b/engines/titanic/files_manager.cpp @@ -27,8 +27,12 @@ namespace Titanic { CFilesManager::CFilesManager() : _gameManager(nullptr), - _assetsPath("Assets"), _field0(0), _drive(-1), - _field18(0), _field1C(0), _field3C(0) { + _assetsPath("Assets"), _exeResources(nullptr), _field0(0), + _drive(-1), _field18(0), _field1C(0), _field3C(0) { +} + +CFilesManager::~CFilesManager() { + delete _exeResources; } bool CFilesManager::fileExists(const CString &name) { @@ -89,4 +93,14 @@ void CFilesManager::fn5(const CString &name) { warning("TODO: CFilesManager::fn5"); } +Common::SeekableReadStream *CFilesManager::getResource(const CString &name, + const CString &area) { + if (!_exeResources) { + _exeResources = new Common::NEResources(); + _exeResources->loadFromEXE("st.exe"); + } + + return nullptr; +} + } // End of namespace Titanic diff --git a/engines/titanic/files_manager.h b/engines/titanic/files_manager.h index 74895d7877..6c6b54445d 100644 --- a/engines/titanic/files_manager.h +++ b/engines/titanic/files_manager.h @@ -23,6 +23,7 @@ #ifndef TITANIC_FILES_MANAGER_H #define TITANIC_FILES_MANAGER_H +#include "common/winexe_ne.h" #include "titanic/core/list.h" #include "titanic/screen_manager.h" @@ -36,6 +37,7 @@ class CFilesManagerList : public List<ListItem> { class CFilesManager { private: CGameManager *_gameManager; + Common::NEResources *_exeResources; CFilesManagerList _list; CString _string1; CString _string2; @@ -47,6 +49,7 @@ private: const CString _assetsPath; public: CFilesManager(); + ~CFilesManager(); /** * Sets the game manager @@ -80,6 +83,12 @@ public: void fn4(const CString &name); void fn5(const CString &name); + + /** + * Get a resource from the executable + */ + Common::SeekableReadStream *getResource(const CString &name, + const CString &area); }; } // End of namespace Titanic diff --git a/engines/titanic/font.cpp b/engines/titanic/font.cpp index 962d6659e0..fd6bd54401 100644 --- a/engines/titanic/font.cpp +++ b/engines/titanic/font.cpp @@ -22,14 +22,45 @@ #include "common/textconsole.h" #include "titanic/font.h" +#include "titanic/files_manager.h" +#include "titanic/titanic.h" namespace Titanic { STFont::STFont() { + _dataPtr = nullptr; + _dataSize = 0; + _field8 = 0; + _maxCharWidth = 0; + _field810 = 0; + _field814 = 0; + _field818 = 0; +} + +STFont::~STFont() { + delete[] _dataPtr; } void STFont::load(int fontNumber) { - // TODO + assert(!_dataPtr); + CString fontNumStr = CString::format("%d", fontNumber); + Common::SeekableReadStream *stream = g_vm->_filesManager.getResource( + fontNumStr, "STFont"); + if (!stream) + return; + + _field8 = stream->readUint32LE(); + _maxCharWidth = stream->readUint32LE(); + for (uint idx = 0; idx < 256; ++idx) + _chars[idx]._charWidth = stream->readUint32LE(); + for (uint idx = 0; idx < 256; ++idx) + _chars[idx]._offset = stream->readUint32LE(); + + _dataSize = stream->readUint32LE(); + _dataPtr = new byte[_dataSize]; + stream->read(_dataPtr, _dataSize); + + delete stream; } void STFont::writeString(int maxWidth, const CString &text, int *v1, int *v2) { diff --git a/engines/titanic/font.h b/engines/titanic/font.h index db0698766c..20b960277d 100644 --- a/engines/titanic/font.h +++ b/engines/titanic/font.h @@ -24,14 +24,28 @@ #define TITANIC_FONT_H #include "common/scummsys.h" +#include "common/array.h" #include "titanic/string.h" namespace Titanic { class STFont { + struct CharEntry { + uint _charWidth; + uint _offset; + }; public: + byte *_dataPtr; + size_t _dataSize; + int _field8; + int _maxCharWidth; + Common::Array<CharEntry> _chars; + int _field810; + int _field814; + int _field818; public: STFont(); + ~STFont(); /** * Load a specified font diff --git a/engines/titanic/string.cpp b/engines/titanic/string.cpp index 6b43e7992b..b4af9206f6 100644 --- a/engines/titanic/string.cpp +++ b/engines/titanic/string.cpp @@ -108,4 +108,15 @@ ImageType CString::imageTypeSuffix() const { return IMAGETYPE_UNKNOWN; } +CString CString::format(const char *fmt, ...) { + String output; + + va_list va; + va_start(va, fmt); + output = String::vformat(fmt, va); + va_end(va); + + return output; +} + } // End of namespace Titanic diff --git a/engines/titanic/string.h b/engines/titanic/string.h index c41130369b..02775de067 100644 --- a/engines/titanic/string.h +++ b/engines/titanic/string.h @@ -94,6 +94,11 @@ public: int readInt() const { return atoi(c_str()); } + + /** + * Format a string + */ + static CString format(const char *fmt, ...); }; } // End of namespace Titanic |