ADL: Clean up Display class

This commit is contained in:
Walter van Niftrik 2016-03-04 20:06:16 +01:00
parent ec14c397ee
commit e6d478ad15
4 changed files with 79 additions and 60 deletions

View File

@ -312,7 +312,7 @@ void AdlEngine::doActions(const Command &command, byte noun, byte offset) {
if (input.size() == 0 || input[0] != APPLECHAR('N')) {
_isRestarting = true;
_display->clear(0x00);
_display->decodeFrameBuffer();
_display->updateHiResScreen();
restartGame();
return;
}
@ -515,9 +515,9 @@ void AdlEngine::showRoom() {
if (!_state.isDark) {
drawPic(curRoom().curPicture);
drawItems();
_display->updateHiResScreen();
}
_display->decodeFrameBuffer();
printMessage(curRoom().description, false);
}
@ -913,9 +913,7 @@ byte AdlEngine::inputKey() {
};
}
_display->updateTextSurface();
_display->updateScreen();
g_system->updateScreen();
_display->updateTextScreen();
g_system->delayMillis(16);
}
@ -942,8 +940,6 @@ void AdlEngine::delay(uint32 ms) {
}
}
}
_display->updateScreen();
g_system->updateScreen();
g_system->delayMillis(16);
}
}

View File

@ -36,10 +36,12 @@
namespace Adl {
// TODO: Implement partial screen updates
#define DISPLAY_PITCH (DISPLAY_WIDTH / 7)
#define COLOR_PALETTE_SIZE 6
const byte colorPalette[COLOR_PALETTE_SIZE * 3] = {
#define COLOR_PALETTE_ENTRIES 6
const byte colorPalette[COLOR_PALETTE_ENTRIES * 3] = {
0x00, 0x00, 0x00,
0xff, 0xff, 0xff,
0xc7, 0x34, 0xff,
@ -48,8 +50,8 @@ const byte colorPalette[COLOR_PALETTE_SIZE * 3] = {
0xf2, 0x5e, 0x00
};
#define MONO_PALETTE_SIZE 2
const byte monoPalette[MONO_PALETTE_SIZE * 3] = {
#define MONO_PALETTE_ENTRIES 2
const byte monoPalette[MONO_PALETTE_ENTRIES * 3] = {
0x00, 0x00, 0x00,
0x00, 0xc0, 0x01
};
@ -100,9 +102,9 @@ Display::Display() :
_scanlines = ConfMan.getBool("scanlines");
if (_monochrome)
g_system->getPaletteManager()->setPalette(monoPalette, 0, MONO_PALETTE_SIZE);
g_system->getPaletteManager()->setPalette(monoPalette, 0, MONO_PALETTE_ENTRIES);
else
g_system->getPaletteManager()->setPalette(colorPalette, 0, COLOR_PALETTE_SIZE);
g_system->getPaletteManager()->setPalette(colorPalette, 0, COLOR_PALETTE_ENTRIES);
enableScanlines(_scanlines);
@ -134,15 +136,35 @@ Display::~Display() {
delete _font;
}
void Display::updateScreen() {
if (_mode == DISPLAY_MODE_TEXT) {
void Display::setMode(DisplayMode mode) {
_mode = mode;
if (_mode == DISPLAY_MODE_TEXT || _mode == DISPLAY_MODE_MIXED)
updateTextScreen();
if (_mode == DISPLAY_MODE_HIRES || _mode == DISPLAY_MODE_MIXED)
updateHiResScreen();
}
void Display::updateTextScreen() {
updateTextSurface();
if (_mode == DISPLAY_MODE_TEXT)
g_system->copyRectToScreen(_textBufSurface->getPixels(), _textBufSurface->pitch, 0, 0, _textBufSurface->w, _textBufSurface->h);
} else if (_mode == DISPLAY_MODE_HIRES) {
g_system->copyRectToScreen(_frameBufSurface->getPixels(), _frameBufSurface->pitch, 0, 0, _frameBufSurface->w, _frameBufSurface->h);
} else {
g_system->copyRectToScreen(_frameBufSurface->getPixels(), _frameBufSurface->pitch, 0, 0, _frameBufSurface->w, _frameBufSurface->h - 4 * 8 * 2);
else if (_mode == DISPLAY_MODE_MIXED)
g_system->copyRectToScreen(_textBufSurface->getBasePtr(0, _textBufSurface->h - 4 * 8 * 2), _textBufSurface->pitch, 0, _textBufSurface->h - 4 * 8 * 2, _textBufSurface->w, 4 * 8 * 2);
}
g_system->updateScreen();
}
void Display::updateHiResScreen() {
updateHiResSurface();
if (_mode == DISPLAY_MODE_HIRES)
g_system->copyRectToScreen(_frameBufSurface->getPixels(), _frameBufSurface->pitch, 0, 0, _frameBufSurface->w, _frameBufSurface->h);
else if (_mode == DISPLAY_MODE_MIXED)
g_system->copyRectToScreen(_frameBufSurface->getPixels(), _frameBufSurface->pitch, 0, 0, _frameBufSurface->w, _frameBufSurface->h - 4 * 8 * 2);
g_system->updateScreen();
}
bool Display::saveThumbnail(Common::WriteStream &out) {
@ -177,17 +199,6 @@ void Display::loadFrameBuffer(Common::ReadStream &stream) {
}
}
void Display::decodeFrameBuffer() {
byte *src = _frameBuf;
byte *dst = (byte *)_frameBufSurface->getPixels();
for (uint i = 0; i < DISPLAY_HEIGHT; ++i) {
decodeScanline(dst, _frameBufSurface->pitch, src);
src += DISPLAY_PITCH;
dst += _frameBufSurface->pitch * 2;
}
}
void Display::putPixel(Common::Point p, byte color) {
byte offset = p.x / 7;
@ -216,27 +227,6 @@ void Display::clear(byte color) {
}
}
void Display::updateTextSurface() {
for (uint row = 0; row < 24; ++row)
for (uint col = 0; col < 40; ++col) {
int charPos = row * 40 + col;
char c = _textBuf[row * 40 + col];
if (charPos == _cursorPos && _showCursor)
c = (c & 0x3f) | 0x40;
Common::Rect r(7 * 2, 8 * 2);
r.translate(((c & 0x3f) % 16) * 7 * 2, (c & 0x3f) / 16 * 8 * 2);
if (!(c & 0x80)) {
if (!(c & 0x40) || ((g_system->getMillis() / 270) & 1))
r.translate(0, 4 * 8 * 2);
}
_textBufSurface->copyRectToSurface(*_font, col * 7 * 2, row * 8 * 2, r);
}
}
void Display::home() {
memset(_textBuf, APPLECHAR(' '), kTextBufSize);
_cursorPos = 0;
@ -279,7 +269,7 @@ void Display::printString(const Common::String &str) {
scrollUp();
}
updateTextSurface();
updateTextScreen();
}
void Display::setCharAtCursor(byte c) {
@ -291,7 +281,7 @@ void Display::showCursor(bool enable) {
}
void Display::enableScanlines(bool enable) {
byte pal[6 * 3] = { };
byte pal[COLOR_PALETTE_ENTRIES * 3] = { };
if (enable)
g_system->getPaletteManager()->setPalette(pal, 6, 6);
@ -301,6 +291,17 @@ void Display::enableScanlines(bool enable) {
}
}
void Display::updateHiResSurface() {
byte *src = _frameBuf;
byte *dst = (byte *)_frameBufSurface->getPixels();
for (uint i = 0; i < DISPLAY_HEIGHT; ++i) {
decodeScanline(dst, _frameBufSurface->pitch, src);
src += DISPLAY_PITCH;
dst += _frameBufSurface->pitch * 2;
}
}
void Display::decodeScanlineColor(byte *dst, int pitch, byte *src) const {
// TODO: shift secondPal by half a pixel
@ -370,6 +371,27 @@ void Display::decodeScanline(byte *dst, int pitch, byte *src) const {
decodeScanlineColor(dst, pitch, src);
}
void Display::updateTextSurface() {
for (uint row = 0; row < 24; ++row)
for (uint col = 0; col < 40; ++col) {
int charPos = row * 40 + col;
char c = _textBuf[row * 40 + col];
if (charPos == _cursorPos && _showCursor)
c = (c & 0x3f) | 0x40;
Common::Rect r(7 * 2, 8 * 2);
r.translate(((c & 0x3f) % 16) * 7 * 2, (c & 0x3f) / 16 * 8 * 2);
if (!(c & 0x80)) {
if (!(c & 0x40) || ((g_system->getMillis() / 270) & 1))
r.translate(0, 4 * 8 * 2);
}
_textBufSurface->copyRectToSurface(*_font, col * 7 * 2, row * 8 * 2, r);
}
}
void Display::drawChar(byte c, int x, int y) {
byte *buf = (byte *)_font->getPixels() + y * _font->pitch + x;

View File

@ -54,18 +54,17 @@ public:
Display();
~Display();
void setMode(DisplayMode mode) { _mode = mode; }
void updateScreen();
void setMode(DisplayMode mode);
void updateTextScreen();
void updateHiResScreen();
bool saveThumbnail(Common::WriteStream &out);
// Graphics
void loadFrameBuffer(Common::ReadStream &stream);
void decodeFrameBuffer();
void putPixel(Common::Point p1, byte color);
void clear(byte color);
// Text
void updateTextSurface();
void home();
void moveCursorTo(const Common::Point &pos);
void moveCursorForward();
@ -79,11 +78,13 @@ private:
kTextBufSize = 40 * 24
};
void updateHiResSurface();
void enableScanlines(bool enable);
void decodeScanlineColor(byte *dst, int pitch, byte *src) const;
void decodeScanlineMono(byte *dst, int pitch, byte *src) const;
void decodeScanline(byte *dst, int pitch, byte *src) const;
void updateTextSurface();
void drawChar(byte c, int x, int y);
void createFont();
void scrollUp();

View File

@ -96,7 +96,7 @@ void HiRes1Engine::runIntro() {
file.seek(IDI_HR1_OFS_LOGO_0);
_display->setMode(DISPLAY_MODE_HIRES);
_display->loadFrameBuffer(file);
_display->decodeFrameBuffer();
_display->updateHiResScreen();
delay(4000);
if (shouldQuit())
@ -186,7 +186,7 @@ void HiRes1Engine::runIntro() {
// Title screen shown during loading
file.seek(0x1800);
_display->loadFrameBuffer(file);
_display->decodeFrameBuffer();
_display->updateHiResScreen();
delay(2000);
}