Skip to content
Permalink
Browse files

ADL: Refactor Display class

  • Loading branch information...
waltervn committed Jul 22, 2019
1 parent 92a3a3a commit d5c7e9d2073c54ed284e1aa4e532f36bf68c3818
@@ -286,7 +286,7 @@ byte AdlEngine::inputKey(bool showCursor) const {
if (_inputScript && !_scriptPaused)
return _display->asciiToNative('\r');

_display->copyTextSurface();
_display->renderText();
g_system->delayMillis(16);
}

@@ -730,7 +730,7 @@ void AdlEngine::gameLoop() {
}

Common::Error AdlEngine::run() {
_display = new Display_A2();
_display = Display_A2_create();
_console = new Console(this);
_display->init();

@@ -964,7 +964,7 @@ Common::Error AdlEngine::saveGameState(int slot, const Common::String &desc) {
uint32 playTime = getTotalPlayTime();
outFile->writeUint32BE(playTime);

_display->saveThumbnail(*outFile);
Graphics::saveThumbnail(*outFile);
saveState(*outFile);
outFile->finalize();

@@ -1280,7 +1280,7 @@ int AdlEngine::o_restart(ScriptEnv &e) {
if (input.size() == 0 || input[0] != _display->asciiToNative('N')) {
_isRestarting = true;
_graphics->clearScreen();
_display->copyGfxSurface();
_display->renderGraphics();
_display->printString(_strings.pressReturn);
initState();
_display->printAsciiString(_strings.lineFeeds);
@@ -112,7 +112,7 @@ void AdlEngine_v2::checkTextOverflow(char c) {

void AdlEngine_v2::handleTextOverflow() {
_linesPrinted = 0;
_display->copyTextSurface();
_display->renderText();

if (_inputScript) {
// Set pause flag to activate regular behaviour of delay and inputKey
@@ -185,7 +185,7 @@ void AdlEngine_v2::printString(const Common::String &str) {

checkTextOverflow(returnChar);
_display->printChar(returnChar);
_display->copyTextSurface();
_display->renderText();
}

void AdlEngine_v2::drawItem(Item &item, const Common::Point &pos) {
@@ -263,7 +263,7 @@ void AdlEngine_v2::showRoom() {
if (!_state.isDark)
drawItems();

_display->copyGfxSurface();
_display->renderGraphics();
printString(_roomData.description);
}

@@ -182,8 +182,8 @@ void Console::prepareGame() {
_engine->_graphics->clearScreen();
_engine->loadRoom(_engine->_state.room);
_engine->showRoom();
_engine->_display->copyTextSurface();
_engine->_display->copyGfxSurface();
_engine->_display->renderText();
_engine->_display->renderGraphics();
}

bool Console::Cmd_Region(int argc, const char **argv) {
@@ -25,27 +25,12 @@
#include "common/str.h"
#include "common/system.h"

#include "graphics/surface.h"

#include "adl/display.h"

namespace Adl {

Display::~Display() {
delete[] _textBuf;
_textSurface->free();
delete _textSurface;

_gfxSurface->free();
delete _gfxSurface;
}

void Display::createSurfaces(uint gfxWidth, uint gfxHeight, uint splitHeight) {
_gfxSurface = new Graphics::Surface;
_gfxSurface->create(gfxWidth, gfxHeight, Graphics::PixelFormat::createFormatCLUT8());
_textSurface = new Graphics::Surface;
_textSurface->create(gfxWidth, gfxHeight, Graphics::PixelFormat::createFormatCLUT8());
_splitHeight = splitHeight;
}

void Display::createTextBuffer(uint textWidth, uint textHeight) {
@@ -60,31 +45,9 @@ void Display::setMode(Display::Mode mode) {
_mode = mode;

if (_mode == Display::kModeText || _mode == Display::kModeMixed)
copyTextSurface();
renderText();
if (_mode == Display::kModeGraphics || _mode == Display::kModeMixed)
copyGfxSurface();
}

void Display::copyTextSurface() {
updateTextSurface();

if (_mode == Display::kModeText)
g_system->copyRectToScreen(_textSurface->getPixels(), _textSurface->pitch, 0, 0, _textSurface->w, _textSurface->h);
else if (_mode == Display::kModeMixed)
g_system->copyRectToScreen(_textSurface->getBasePtr(0, _textSurface->h - _splitHeight), _textSurface->pitch, 0, _textSurface->h - _splitHeight, _textSurface->w, _splitHeight);

g_system->updateScreen();
}

void Display::copyGfxSurface() {
updateGfxSurface();

if (_mode == kModeGraphics)
g_system->copyRectToScreen(_gfxSurface->getPixels(), _gfxSurface->pitch, 0, 0, _gfxSurface->w, _gfxSurface->h);
else if (_mode == kModeMixed)
g_system->copyRectToScreen(_gfxSurface->getPixels(), _gfxSurface->pitch, 0, 0, _gfxSurface->w, _gfxSurface->h - _splitHeight);

g_system->updateScreen();
renderGraphics();
}

void Display::home() {
@@ -116,15 +79,15 @@ void Display::printString(const Common::String &str) {
for (c = str.begin(); c != str.end(); ++c)
printChar(*c);

copyTextSurface();
renderText();
}

void Display::printAsciiString(const Common::String &str) {
Common::String::const_iterator c;
for (c = str.begin(); c != str.end(); ++c)
printChar(asciiToNative(*c));

copyTextSurface();
renderText();
}

void Display::setCharAtCursor(byte c) {
@@ -26,15 +26,10 @@
#include "common/types.h"

namespace Common {
class WriteStream;
class String;
struct Point;
}

namespace Graphics {
struct Surface;
}

namespace Adl {

class Display {
@@ -48,10 +43,9 @@ class Display {
virtual ~Display();

virtual void init() = 0;
virtual bool saveThumbnail(Common::WriteStream &out) = 0;
void setMode(Mode mode);
void copyTextSurface();
void copyGfxSurface();
virtual void renderText() = 0;
virtual void renderGraphics() = 0;

virtual char asciiToNative(char c) const = 0;
virtual void printChar(char c) = 0;
@@ -68,23 +62,13 @@ class Display {
void scrollUp();

protected:
Display() : _textBuf(nullptr), _textSurface(nullptr), _gfxSurface(nullptr), _cursorPos(0),
_mode(kModeText), _splitHeight(0), _textWidth(0), _textHeight(0) { }
Display() : _textBuf(nullptr), _cursorPos(0), _mode(kModeText), _textWidth(0), _textHeight(0) { }

void createSurfaces(uint gfxWidth, uint gfxHeight, uint splitHeight);
void createTextBuffer(uint textWidth, uint textHeight);

byte *_textBuf;
Graphics::Surface *_textSurface;
Graphics::Surface *_gfxSurface;
uint _cursorPos;

private:
virtual void updateTextSurface() = 0;
virtual void updateGfxSurface() = 0;

Mode _mode;
uint _splitHeight;
uint _textWidth;
uint _textHeight;
};

0 comments on commit d5c7e9d

Please sign in to comment.
You can’t perform that action at this time.