FREESCAPE: improved rendering of fonts in castle for dos

This commit is contained in:
neuromancer 2024-07-11 07:46:17 +02:00
parent b5d035c9cb
commit c8e8e5edff
5 changed files with 54 additions and 11 deletions

View File

@ -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);
}
}

View File

@ -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<Common::String> &lines);
// Game state

View File

@ -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);

View File

@ -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);

View File

@ -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() {