From 3a543a1e6d35a5bcab61a8fb4257b7d567d9e278 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 25 Nov 2018 12:41:39 -0800 Subject: GLK: FROTZ: Add derived Screen class to add Infocom character graphics font --- engines/glk/frotz/frotz.cpp | 5 +++++ engines/glk/frotz/frotz.h | 5 +++++ engines/glk/frotz/pics_decoder.cpp | 6 +++--- engines/glk/frotz/screen.cpp | 16 ++++++++++++++++ engines/glk/frotz/screen.h | 12 ++++++++++++ engines/glk/glk.cpp | 9 +++++++-- engines/glk/glk.h | 5 +++++ engines/glk/screen.cpp | 24 ++++++++++++++---------- engines/glk/screen.h | 18 ++++++++++++++---- 9 files changed, 81 insertions(+), 19 deletions(-) diff --git a/engines/glk/frotz/frotz.cpp b/engines/glk/frotz/frotz.cpp index d3b0749649..421b7785a6 100644 --- a/engines/glk/frotz/frotz.cpp +++ b/engines/glk/frotz/frotz.cpp @@ -22,6 +22,7 @@ #include "glk/frotz/frotz.h" #include "glk/frotz/frotz_types.h" +#include "glk/frotz/screen.h" #include "common/config-manager.h" namespace Glk { @@ -38,6 +39,10 @@ Frotz::~Frotz() { reset_memory(); } +Screen *Frotz::createScreen() { + return new FrotzScreen(); +} + void Frotz::runGame(Common::SeekableReadStream *gameFile) { story_fp = gameFile; initialize(); diff --git a/engines/glk/frotz/frotz.h b/engines/glk/frotz/frotz.h index 0dd8b69e89..22604e59bd 100644 --- a/engines/glk/frotz/frotz.h +++ b/engines/glk/frotz/frotz.h @@ -32,6 +32,11 @@ namespace Frotz { * Frotz interpreter for Z-code games */ class Frotz : public Processor { +protected: + /** + * Create the screen class + */ + virtual Screen *createScreen() override; public: /** * Constructor diff --git a/engines/glk/frotz/pics_decoder.cpp b/engines/glk/frotz/pics_decoder.cpp index d601874ca5..6dde910508 100644 --- a/engines/glk/frotz/pics_decoder.cpp +++ b/engines/glk/frotz/pics_decoder.cpp @@ -42,15 +42,14 @@ Common::SeekableReadStream *PictureDecoder::decode(Common::ReadStream &src, uint Common::MemoryWriteStreamDynamic out(DisposeAfterUse::NO); byte buf[512]; byte transparent; - int colour_shift; - int first_colour; + int colour_shift = 0; + int first_colour = 0; int code, prev_code = 0; int next_entry; int bits_per_code; int bits_shift; int bits; int bufpos = 0; - int i; /* * Write out dimensions of image @@ -83,6 +82,7 @@ Common::SeekableReadStream *PictureDecoder::decode(Common::ReadStream &src, uint first_colour = 65; break; default: + error("Unsupported mode"); break; } diff --git a/engines/glk/frotz/screen.cpp b/engines/glk/frotz/screen.cpp index eef6d6118d..a71217cc26 100644 --- a/engines/glk/frotz/screen.cpp +++ b/engines/glk/frotz/screen.cpp @@ -21,10 +21,26 @@ */ #include "glk/frotz/screen.h" +#include "common/file.h" +#include "image/bmp.h" namespace Glk { namespace Frotz { +void FrotzScreen::loadFonts(Common::Archive *archive) { + Screen::loadFonts(archive); + + Image::BitmapDecoder decoder; + Common::File f; + if (!f.open("infocom_graphics.bmp", *archive)) + error("Could not load font"); + + decoder.loadStream(f); + _fonts.push_back(new Frotz::BitmapFont(*decoder.getSurface())); +} + +/*--------------------------------------------------------------------------*/ + BitmapFont::BitmapFont(const Graphics::Surface &src, uint charWidth, uint charHeight, unsigned char startingChar) : _startingChar(startingChar) { assert(src.format.bytesPerPixel == 1); diff --git a/engines/glk/frotz/screen.h b/engines/glk/frotz/screen.h index dac716c436..d8b2b89a3f 100644 --- a/engines/glk/frotz/screen.h +++ b/engines/glk/frotz/screen.h @@ -28,10 +28,22 @@ #include "common/archive.h" #include "common/array.h" #include "common/rect.h" +#include "glk/screen.h" namespace Glk { namespace Frotz { +/** + * Derived screen class that adds in the Infocom character graphics font + */ +class FrotzScreen : public Glk::Screen { +protected: + /** + * Load the fonts + */ + virtual void loadFonts(Common::Archive *archive) override; +}; + /** * Implements a fixed width font stored as a grid on a passed surface */ diff --git a/engines/glk/glk.cpp b/engines/glk/glk.cpp index 87b736cb25..98ce410d68 100644 --- a/engines/glk/glk.cpp +++ b/engines/glk/glk.cpp @@ -71,9 +71,10 @@ void GlkEngine::initialize() { DebugMan.addDebugChannel(kDebugSound, "sound", "Sound and Music handling"); initGraphicsMode(); - _conf = new Conf(getInterpreterType()); - _screen = new Screen(); + _conf = new Conf(getInterpreterType()); + _screen = createScreen(); + _screen->initialize(); _clipboard = new Clipboard(); _events = new Events(); _pictures = new Pictures(); @@ -82,6 +83,10 @@ void GlkEngine::initialize() { _windows = new Windows(_screen); } +Screen *GlkEngine::createScreen() { + return new Screen(); +} + void GlkEngine::initGraphicsMode() { uint width = ConfMan.hasKey("width") ? ConfMan.getInt("width") : 640; uint height = ConfMan.hasKey("height") ? ConfMan.getInt("height") : 480; diff --git a/engines/glk/glk.h b/engines/glk/glk.h index af9a42ba43..526755b1aa 100644 --- a/engines/glk/glk.h +++ b/engines/glk/glk.h @@ -89,6 +89,11 @@ protected: */ virtual bool hasFeature(EngineFeature f) const; + /** + * Create the screen + */ + virtual Screen *createScreen(); + /** * Main game loop for the individual interpreters */ diff --git a/engines/glk/screen.cpp b/engines/glk/screen.cpp index cfe8cde84f..6768360df1 100644 --- a/engines/glk/screen.cpp +++ b/engines/glk/screen.cpp @@ -33,7 +33,12 @@ namespace Glk { #define FONTS_VERSION 1.0 #define FONTS_FILENAME "fonts.dat" -Screen::Screen() { +Screen::~Screen() { + for (int idx = 0; idx < FONTS_TOTAL; ++idx) + delete _fonts[idx]; +} + +void Screen::initialize() { if (!loadFonts()) error("Could not load data file"); @@ -49,11 +54,6 @@ Screen::Screen() { g_conf->_cellH = g_conf->_leading; } -Screen::~Screen() { - for (int idx = 0; idx < FONTS_TOTAL; ++idx) - delete _fonts[idx]; -} - void Screen::fill(const byte *rgb) { uint color = format.RGBToColor(rgb[0], rgb[1], rgb[2]); clear(color); @@ -100,7 +100,6 @@ void Screen::drawCaret(const Point &pos) { bool Screen::loadFonts() { Common::Archive *archive = nullptr; - _fonts.resize(FONTS_TOTAL); if (!Common::File::exists(FONTS_FILENAME) || (archive = Common::makeZipArchive(FONTS_FILENAME)) == nullptr) return false; @@ -122,12 +121,20 @@ bool Screen::loadFonts() { return false; } + loadFonts(archive); + + delete archive; + return true; +} + +void Screen::loadFonts(Common::Archive *archive) { // R ead in the fonts double monoAspect = g_conf->_monoAspect; double propAspect = g_conf->_propAspect; double monoSize = g_conf->_monoSize; double propSize = g_conf->_propSize; + _fonts.resize(FONTS_TOTAL); _fonts[0] = loadFont(MONOR, archive, monoSize, monoAspect, FONTR); _fonts[1] = loadFont(MONOB, archive, monoSize, monoAspect, FONTB); _fonts[2] = loadFont(MONOI, archive, monoSize, monoAspect, FONTI); @@ -137,9 +144,6 @@ bool Screen::loadFonts() { _fonts[5] = loadFont(PROPB, archive, propSize, propAspect, FONTB); _fonts[6] = loadFont(PROPI, archive, propSize, propAspect, FONTI); _fonts[7] = loadFont(PROPZ, archive, propSize, propAspect, FONTZ); - - delete archive; - return true; } const Graphics::Font *Screen::loadFont(FACES face, Common::Archive *archive, double size, double aspect, int diff --git a/engines/glk/screen.h b/engines/glk/screen.h index 541e9e190e..bb5d7f6d25 100644 --- a/engines/glk/screen.h +++ b/engines/glk/screen.h @@ -45,11 +45,9 @@ enum STYLES { FONTR, FONTB, FONTI, FONTZ }; * Screen surface class */ class Screen : public Graphics::Screen { -private: - Common::Array _fonts; private: /** - * Load all the fonts + * Open the fonts archive and load all the fonts */ bool loadFonts(); @@ -58,6 +56,13 @@ private: */ const Graphics::Font *loadFont(FACES face, Common::Archive *archive, double size, double aspect, int style); +protected: + Common::Array _fonts; +protected: + /** + * Load the fonts + */ + virtual void loadFonts(Common::Archive *archive); public: /** * Return the font Id for a given name @@ -67,13 +72,18 @@ public: /** * Constructor */ - Screen(); + Screen() : Graphics::Screen() {} /** * Destructor */ virtual ~Screen(); + /** + * Initialize the screen + */ + void initialize(); + /** * Fills the screen with a given rgb color */ -- cgit v1.2.3