aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2014-03-17 00:00:22 -0400
committerPaul Gilbert2014-03-17 00:00:22 -0400
commitb831323c85bb1ca26368cee6690d4664c37e9c0b (patch)
tree6f1a29204c6a78f93b15e1f66ee02424c7c4e0b4 /engines
parentacba8f9254a724ce9c57f5ddd81e6b9264c07274 (diff)
downloadscummvm-rg350-b831323c85bb1ca26368cee6690d4664c37e9c0b.tar.gz
scummvm-rg350-b831323c85bb1ca26368cee6690d4664c37e9c0b.tar.bz2
scummvm-rg350-b831323c85bb1ca26368cee6690d4664c37e9c0b.zip
MADS: Added caching for font instances
Diffstat (limited to 'engines')
-rw-r--r--engines/mads/dialogs.cpp1
-rw-r--r--engines/mads/font.cpp46
-rw-r--r--engines/mads/font.h17
-rw-r--r--engines/mads/mads.cpp1
-rw-r--r--engines/mads/messages.cpp1
5 files changed, 41 insertions, 25 deletions
diff --git a/engines/mads/dialogs.cpp b/engines/mads/dialogs.cpp
index 4c1a789a57..333bbe98b4 100644
--- a/engines/mads/dialogs.cpp
+++ b/engines/mads/dialogs.cpp
@@ -106,7 +106,6 @@ TextDialog::TextDialog(MADSEngine *vm, const Common::String &fontName,
_fontName = fontName;
_position = pos;
- _vm->_font->setFont(FONT_INTERFACE);
_vm->_font->setColors(TEXTDIALOG_BLACK, TEXTDIALOG_BLACK, TEXTDIALOG_BLACK, TEXTDIALOG_BLACK);
_innerWidth = (_vm->_font->maxWidth() + 1) * maxChars;
diff --git a/engines/mads/font.cpp b/engines/mads/font.cpp
index 205e653639..ed7542d2e5 100644
--- a/engines/mads/font.cpp
+++ b/engines/mads/font.cpp
@@ -28,7 +28,9 @@
namespace MADS {
-MADSEngine *Font::_vm = nullptr;
+MADSEngine *Font::_vm;
+
+Common::HashMap<Common::String, Font *> *Font::_fonts;
uint8 Font::_fontColors[4];
@@ -38,24 +40,40 @@ void Font::init(MADSEngine *vm) {
_fontColors[1] = 0xF;
_fontColors[2] = 7;
_fontColors[3] = 8;
+
+ _fonts = new Common::HashMap<Common::String, Font *>();
+}
+
+void Font::deinit() {
+ Common::HashMap<Common::String, Font *>::iterator i;
+ for (i = _fonts->begin(); i != _fonts->end(); ++i)
+ delete (*i)._value;
+
+ delete _fonts;
}
Font *Font::getFont(const Common::String &fontName) {
- Font *font = new Font();
- font->setFont(fontName);
- return font;
+ if (_fonts->contains(fontName)) {
+ return _fonts->getVal(fontName);
+ } else {
+ Font *font = new Font(fontName);
+ _fonts->setVal(fontName, font);
+ return font;
+ }
}
Font::Font() {
- _sysFont = true;
+ setFont(FONT_INTERFACE);
+}
+
+Font::Font(const Common::String &filename) {
+ setFont(filename);
}
Font::~Font() {
- if (!_sysFont) {
- delete[] _charWidths;
- delete[] _charOffs;
- delete[] _charData;
- }
+ delete[] _charWidths;
+ delete[] _charOffs;
+ delete[] _charData;
}
void Font::setFont(const Common::String &filename) {
@@ -63,7 +81,6 @@ void Font::setFont(const Common::String &filename) {
// Already using specified font, so don't bother reloading
return;
- _sysFont = false;
_filename = filename;
MadsPack fontData(filename, _vm);
@@ -95,13 +112,6 @@ void Font::setFont(const Common::String &filename) {
delete fontFile;
}
-void Font::setColor(uint8 color) {
- if (_sysFont)
- _fontColors[1] = color;
- else
- _fontColors[3] = color;
-}
-
void Font::setColors(uint8 v1, uint8 v2, uint8 v3, uint8 v4) {
_fontColors[0] = v1;
_fontColors[1] = v2;
diff --git a/engines/mads/font.h b/engines/mads/font.h
index 9b3e5bc828..5079f1261f 100644
--- a/engines/mads/font.h
+++ b/engines/mads/font.h
@@ -24,8 +24,9 @@
#define MADS_FONT_H
#include "common/scummsys.h"
-#include "common/util.h"
+#include "common/hashmap.h"
#include "common/endian.h"
+#include "common/util.h"
#include "mads/msurface.h"
namespace MADS {
@@ -44,6 +45,7 @@ class Font {
private:
static uint8 _fontColors[4];
static MADSEngine *_vm;
+ static Common::HashMap<Common::String, Font *> *_fonts;
public:
/**
* Initialise the font system
@@ -51,24 +53,29 @@ public:
static void init(MADSEngine *vm);
/**
+ * Free up the resources used by the font
+ */
+ static void deinit();
+
+ /**
* Returns a new Font instance using the specified font name
*/
static Font *getFont(const Common::String &fontName);
-protected:
+private:
uint8 _maxWidth, _maxHeight;
uint8 *_charWidths;
uint16 *_charOffs;
uint8 *_charData;
- bool _sysFont;
Common::String _filename;
int getBpp(int charWidth);
+
+ void setFont(const Common::String &filename);
public:
Font();
+ Font(const Common::String &filename);
virtual ~Font();
- void setFont(const Common::String &filename);
- void setColor(uint8 color);
void setColors(uint8 v1, uint8 v2, uint8 v3, uint8 v4);
void setColorMode(int mode);
diff --git a/engines/mads/mads.cpp b/engines/mads/mads.cpp
index 80a797b8d4..1785ce3f00 100644
--- a/engines/mads/mads.cpp
+++ b/engines/mads/mads.cpp
@@ -59,6 +59,7 @@ MADSEngine::~MADSEngine() {
delete _dialogs;
delete _events;
delete _font;
+ Font::deinit();
delete _game;
delete _palette;
delete _resources;
diff --git a/engines/mads/messages.cpp b/engines/mads/messages.cpp
index c355dacb7c..592dd4bd28 100644
--- a/engines/mads/messages.cpp
+++ b/engines/mads/messages.cpp
@@ -40,7 +40,6 @@ KernelMessages::KernelMessages(MADSEngine *vm): _vm(vm) {
}
KernelMessages::~KernelMessages() {
- delete _talkFont;
}
void KernelMessages::clear() {