From c8e8e5edff346b3dd01b41efe7c844338d905e93 Mon Sep 17 00:00:00 2001 From: neuromancer Date: Thu, 11 Jul 2024 07:46:17 +0200 Subject: [PATCH] FREESCAPE: improved rendering of fonts in castle for dos --- engines/freescape/freescape.cpp | 5 ++-- engines/freescape/freescape.h | 4 ++-- engines/freescape/games/castle/castle.cpp | 20 ++++++++++++++++ engines/freescape/games/castle/castle.h | 7 ++++++ engines/freescape/games/castle/dos.cpp | 29 +++++++++++++++++------ 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/engines/freescape/freescape.cpp b/engines/freescape/freescape.cpp index deca21116fd..f863bf8fa21 100644 --- a/engines/freescape/freescape.cpp +++ b/engines/freescape/freescape.cpp @@ -936,6 +936,7 @@ void FreescapeEngine::drawStringInSurface(const Common::String &str, int x, int if (!_fontLoaded) return; Common::String ustr = str; + uint32 transparent = _gfx->_texturePixelFormat.ARGBToColor(0, 0, 0, 0); ustr.toUppercase(); int sizeX = 8; @@ -948,9 +949,9 @@ void FreescapeEngine::drawStringInSurface(const Common::String &str, int x, int int position = sizeX * sizeY * (offset + ustr[c] - 32); for (int j = 0; j < sizeY; j++) { for (int i = 0; i < sizeX; i++) { - if (_font.get(position + additional + j * 8 + i)) + if (_font.get(position + additional + j * 8 + i) && fontColor != transparent) surface->setPixel(x + 8 - i + sep * c, y + j, fontColor); - else + else if (backColor != transparent) surface->setPixel(x + 8 - i + sep * c, y + j, backColor); } } diff --git a/engines/freescape/freescape.h b/engines/freescape/freescape.h index 458e76a57b8..757e4d32502 100644 --- a/engines/freescape/freescape.h +++ b/engines/freescape/freescape.h @@ -443,8 +443,8 @@ public: Common::StringArray _currentEphymeralMessages; Common::BitArray _font; bool _fontLoaded; - void drawStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0); - void drawStringInSurface(const Common::String &str, int x, int y, uint32 primaryFontColor, uint32 secondaryFontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0); + virtual void drawStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0); + virtual void drawStringInSurface(const Common::String &str, int x, int y, uint32 primaryFontColor, uint32 secondaryFontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0); Graphics::Surface *drawStringsInSurface(const Common::Array &lines); // Game state diff --git a/engines/freescape/games/castle/castle.cpp b/engines/freescape/games/castle/castle.cpp index 6391b90d2ca..bb1004df5c4 100644 --- a/engines/freescape/games/castle/castle.cpp +++ b/engines/freescape/games/castle/castle.cpp @@ -331,6 +331,26 @@ void CastleEngine::drawRiddle(uint16 riddle, uint32 front, uint32 back, Graphics drawFullscreenSurface(surface); } +void CastleEngine::drawStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface, int offset) { + if (isSpectrum() || isCPC()) { + FreescapeEngine::drawStringInSurface(str, x, y, fontColor, backColor, surface, offset); + return; + } + + uint32 transparent = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0x00, 0x00, 0x00); + uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0x00); + //uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x80, 0x00); + + _font = _fontPlane1; + FreescapeEngine::drawStringInSurface(str, x, y, fontColor, backColor, surface, offset); + + _font = _fontPlane2; + FreescapeEngine::drawStringInSurface(str, x, y, yellow, transparent, surface, offset); + + //_font = _fontPlane3; + //FreescapeEngine::drawStringInSurface(str, x, y, transparent, green, surface, offset); +} + void CastleEngine::drawEnergyMeter(Graphics::Surface *surface) { uint32 back = 0; uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00); diff --git a/engines/freescape/games/castle/castle.h b/engines/freescape/games/castle/castle.h index bbfdbfe526c..3788855a088 100644 --- a/engines/freescape/games/castle/castle.h +++ b/engines/freescape/games/castle/castle.h @@ -52,6 +52,13 @@ public: Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override; Common::StringArray _riddleList; + Common::BitArray _fontPlane1; + Common::BitArray _fontPlane2; + Common::BitArray _fontPlane3; + + void drawStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0) override; + //void drawStringInSurface(const Common::String &str, int x, int y, uint32 primaryFontColor, uint32 secondaryFontColor, uint32 backColor, Graphics::Surface *surface, int offset = 0) override; + private: Common::SeekableReadStream *decryptFile(const Common::Path &filename); void loadRiddles(Common::SeekableReadStream *file, int offset, int number); diff --git a/engines/freescape/games/castle/dos.cpp b/engines/freescape/games/castle/dos.cpp index bee5b260320..4317b7147e3 100644 --- a/engines/freescape/games/castle/dos.cpp +++ b/engines/freescape/games/castle/dos.cpp @@ -53,23 +53,38 @@ extern Common::MemoryReadStream *unpackEXE(Common::File &ms); void CastleEngine::loadDOSFonts(Common::SeekableReadStream *file, int pos) { file->seek(pos); - byte *buffer = (byte *)malloc(sizeof(byte) * 59 * 8); + byte *bufferPlane1 = (byte *)malloc(sizeof(byte) * 59 * 8); + byte *bufferPlane2 = (byte *)malloc(sizeof(byte) * 59 * 8); + byte *bufferPlane3 = (byte *)malloc(sizeof(byte) * 59 * 8); for (int i = 0; i < 59 * 8; i++) { //debug("%lx", file->pos()); for (int j = 0; j < 4; j++) { uint16 c = readField(file, 16); - if (j == 3) { - //debugN("0x%x, ", c); - assert(c < 256); - buffer[i] = c; + assert(c < 256); + if (j == 1) { + bufferPlane1[i] = c; + } else if (j == 2) { + bufferPlane2[i] = c; + } else if (j == 3) { + bufferPlane3[i] = c; } } //debugN("\n"); } debug("%lx", file->pos()); - loadFonts(buffer, 59); - free(buffer); + _fontPlane1.set_size(64 * 59); + _fontPlane1.set_bits(bufferPlane1); + + _fontPlane2.set_size(64 * 59); + _fontPlane2.set_bits(bufferPlane2); + + _fontPlane3.set_size(64 * 59); + _fontPlane3.set_bits(bufferPlane3); + _fontLoaded = true; + free(bufferPlane1); + free(bufferPlane2); + free(bufferPlane3); } void CastleEngine::loadAssetsDOSFullGame() {