Skip to content

Commit

Permalink
TOON: Add more dirtyRect checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvaintv committed Mar 13, 2011
1 parent 9e1245c commit 3964ce8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 45 deletions.
4 changes: 2 additions & 2 deletions engines/toon/font.cpp
Expand Up @@ -265,8 +265,8 @@ void FontRenderer::renderMultiLineText(int32 x, int32 y, Common::String origText
if (x - 30 - maxWidth / 2 < 0)
x = maxWidth / 2 + 30;

if (x + 30 + (maxWidth / 2) > 640)
x = 640 - (maxWidth / 2) - 30;
if (x + 30 + (maxWidth / 2) > TOON_SCREEN_WIDTH)
x = TOON_SCREEN_WIDTH - (maxWidth / 2) - 30;

// we have good coordinates now, we can render the multi line
int32 curX = x;
Expand Down
32 changes: 16 additions & 16 deletions engines/toon/picture.cpp
Expand Up @@ -48,12 +48,12 @@ bool Picture::loadPicture(Common::String file, bool totalPalette /*= false*/) {
decompressLZSS(fileData + 8, _data, dstsize);

// size can only be 640x400 or 1280x400
if (dstsize > 640 * 400 + 768)
_width = 1280;
if (dstsize > TOON_SCREEN_WIDTH * TOON_SCREEN_HEIGHT + 768)
_width = TOON_BACKBUFFER_WIDTH;
else
_width = 640;
_width = TOON_SCREEN_WIDTH;

_height = 400;
_height = TOON_SCREEN_HEIGHT;

// do we have a palette ?
_paletteEntries = (dstsize & 0x7ff) / 3;
Expand All @@ -78,12 +78,12 @@ bool Picture::loadPicture(Common::String file, bool totalPalette /*= false*/) {
}

// size can only be 640x400 or 1280x400
if (decSize > 640 * 400 + 768)
_width = 1280;
if (decSize > TOON_SCREEN_WIDTH * TOON_SCREEN_HEIGHT + 768)
_width = TOON_BACKBUFFER_WIDTH;
else
_width = 640;
_width = TOON_SCREEN_WIDTH;

_height = 400;
_height = TOON_SCREEN_HEIGHT;

// decompress the picture into our buffer
decompressSPCN(fileData + 16 + _paletteEntries * 3, _data, decSize);
Expand All @@ -100,12 +100,12 @@ bool Picture::loadPicture(Common::String file, bool totalPalette /*= false*/) {
rnc.unpackM1(fileData, _data);

// size can only be 640x400 or 1280x400
if (decSize > 640 * 400 + 768)
_width = 1280;
if (decSize > TOON_SCREEN_WIDTH * TOON_SCREEN_HEIGHT + 768)
_width = TOON_BACKBUFFER_WIDTH;
else
_width = 640;
_width = TOON_SCREEN_WIDTH;

_height = 400;
_height = TOON_SCREEN_HEIGHT;
return true;
}
case kCompRNC2: {
Expand All @@ -118,12 +118,12 @@ bool Picture::loadPicture(Common::String file, bool totalPalette /*= false*/) {

decSize = rnc.unpackM2(fileData, _data);

if (decSize > 640 * 400 + 768)
_width = 1280;
if (decSize > TOON_SCREEN_WIDTH * TOON_SCREEN_HEIGHT + 768)
_width = TOON_BACKBUFFER_WIDTH;
else
_width = 640;
_width = TOON_SCREEN_WIDTH;

_height = 400;
_height = TOON_SCREEN_HEIGHT;
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion engines/toon/script_func.cpp
Expand Up @@ -947,7 +947,7 @@ int32 ScriptFunc::sys_Cmd_Init_Scene_Anim(EMCState *state) {
int32 layerZ = stackPos(3);

if (dx == -2)
sceneAnim->_animInstance->moveRelative(640, 0, 0);
sceneAnim->_animInstance->moveRelative(TOON_SCREEN_WIDTH, 0, 0);
else if (dx < 0) {
dx = sceneAnim->_animation->_x1;
}
Expand Down
52 changes: 26 additions & 26 deletions engines/toon/toon.cpp
Expand Up @@ -57,7 +57,7 @@ void ToonEngine::init() {
_hotspots = new Hotspots(this);

_mainSurface = new Graphics::Surface();
_mainSurface->create(1280, 400, 1);
_mainSurface->create(TOON_BACKBUFFER_WIDTH, TOON_BACKBUFFER_HEIGHT, 1);

_finalPalette = new uint8[768];
_backupPalette = new uint8[768];
Expand Down Expand Up @@ -322,8 +322,8 @@ void ToonEngine::updateScrolling(bool force, int32 timeIncrement) {
if ((_gameState->_locations[_gameState->_currentScene]._flags & 0x80) == 0) {
if (desiredScrollValue < 0)
desiredScrollValue = 0;
if (desiredScrollValue >= _currentPicture->getWidth() - 640)
desiredScrollValue = _currentPicture->getWidth() - 640;
if (desiredScrollValue >= _currentPicture->getWidth() - TOON_SCREEN_WIDTH)
desiredScrollValue = _currentPicture->getWidth() - TOON_SCREEN_WIDTH;

if (force) {
_gameState->_currentScrollValue = desiredScrollValue;
Expand Down Expand Up @@ -381,7 +381,7 @@ void ToonEngine::render() {
_currentCutaway->draw(*_mainSurface, 0, 0, 0, 0);
else
_currentPicture->draw(*_mainSurface, 0, 0, 0, 0);
_dirtyRects.push_back(Common::Rect(0, 0, 1280, 400));
_dirtyRects.push_back(Common::Rect(0, 0, TOON_BACKBUFFER_WIDTH, TOON_BACKBUFFER_HEIGHT));
} else {
if (_gameState->_inCutaway)
_currentCutaway->drawWithRectList(*_mainSurface, 0, 0, 0, 0, _dirtyRects);
Expand Down Expand Up @@ -498,7 +498,7 @@ void ToonEngine::copyToVirtualScreen(bool updateScreen) {

if (_dirtyAll || _gameState->_currentScrollValue != lastScroll) {
// we have to refresh everything in case of scrolling.
_system->copyRectToScreen((byte *)_mainSurface->pixels + state()->_currentScrollValue, 1280, 0, 0, 640, 400);
_system->copyRectToScreen((byte *)_mainSurface->pixels + state()->_currentScrollValue, TOON_BACKBUFFER_WIDTH, 0, 0, TOON_SCREEN_WIDTH, TOON_SCREEN_HEIGHT);
} else {

int32 offX = 0;
Expand All @@ -512,9 +512,9 @@ void ToonEngine::copyToVirtualScreen(bool updateScreen) {
offX = -rect.left;
rect.left = 0;
}
rect.clip(640, 400);
rect.clip(TOON_SCREEN_WIDTH, TOON_SCREEN_HEIGHT);
if (rect.left >= 0 && rect.top >= 0 && rect.right - rect.left > 0 && rect.bottom - rect.top > 0) {
_system->copyRectToScreen((byte *)_mainSurface->pixels + _oldDirtyRects[i].left + offX + _oldDirtyRects[i].top * 1280, 1280, rect.left , rect.top, rect.right - rect.left, rect.bottom - rect.top);
_system->copyRectToScreen((byte *)_mainSurface->pixels + _oldDirtyRects[i].left + offX + _oldDirtyRects[i].top * TOON_BACKBUFFER_WIDTH, TOON_BACKBUFFER_WIDTH, rect.left , rect.top, rect.right - rect.left, rect.bottom - rect.top);
}
}

Expand All @@ -528,9 +528,9 @@ void ToonEngine::copyToVirtualScreen(bool updateScreen) {
offX = -rect.left;
rect.left = 0;
}
rect.clip(640, 400);
rect.clip(TOON_SCREEN_WIDTH, TOON_SCREEN_HEIGHT);
if (rect.left >= 0 && rect.top >= 0 && rect.right - rect.left > 0 && rect.bottom - rect.top > 0) {
_system->copyRectToScreen((byte *)_mainSurface->pixels + _dirtyRects[i].left + offX + _dirtyRects[i].top * 1280, 1280, rect.left , rect.top, rect.right - rect.left, rect.bottom - rect.top);
_system->copyRectToScreen((byte *)_mainSurface->pixels + _dirtyRects[i].left + offX + _dirtyRects[i].top * TOON_BACKBUFFER_WIDTH, TOON_BACKBUFFER_WIDTH, rect.left , rect.top, rect.right - rect.left, rect.bottom - rect.top);
}
}
}
Expand Down Expand Up @@ -662,7 +662,7 @@ bool ToonEngine::showMainmenu(bool &loadedGame) {

if(_dirtyAll) {
mainmenuPicture->draw(*_mainSurface, 0, 0, 0, 0);
addDirtyRect(0, 0, 640, 400);
addDirtyRect(0, 0, TOON_SCREEN_WIDTH, TOON_SCREEN_HEIGHT);
} else {
mainmenuPicture->drawWithRectList(*_mainSurface, 0, 0, 0, 0, _dirtyRects);
}
Expand Down Expand Up @@ -779,7 +779,7 @@ Common::Error ToonEngine::run() {

g_eventRec.registerRandomSource(_rnd, "toon");

initGraphics(640, 400, true);
initGraphics(TOON_SCREEN_WIDTH, TOON_SCREEN_HEIGHT, true);
init();

// do we need to load directly a game?
Expand Down Expand Up @@ -1478,7 +1478,7 @@ void ToonEngine::clickEvent() {

int32 mouseX = _mouseX;
if (_gameState->_inCutaway) {
mouseX += 1280;
mouseX += TOON_BACKBUFFER_WIDTH;
}

// find hotspot
Expand Down Expand Up @@ -1615,7 +1615,7 @@ void ToonEngine::selectHotspot() {
int32 mouseX = _mouseX;

if (_gameState->_inCutaway)
mouseX += 1280;
mouseX += TOON_BACKBUFFER_WIDTH;

if (_gameState->_sackVisible) {
if (_mouseX > 0 && _mouseX < 40 && _mouseY > 356 && _mouseY < 396) {
Expand Down Expand Up @@ -1784,7 +1784,7 @@ void ToonEngine::flipScreens() {
_gameState->_inCloseUp = !_gameState->_inCloseUp;

if (_gameState->_inCloseUp) {
_gameState->_currentScrollValue = 640;
_gameState->_currentScrollValue = TOON_SCREEN_WIDTH;
setPaletteEntries(_cutawayPalette, 1, 128);
setPaletteEntries(_additionalPalette2, 232, 23);
} else {
Expand Down Expand Up @@ -1874,8 +1874,8 @@ int32 ToonEngine::getScaleAtPoint(int32 x, int32 y) {
return 1024;

// clamp values
x = MIN<int32>(1279, MAX<int32>(0, x));
y = MIN<int32>(399, MAX<int32>(0, y));
x = MIN<int32>(TOON_BACKBUFFER_WIDTH - 1, MAX<int32>(0, x));
y = MIN<int32>(TOON_BACKBUFFER_HEIGHT - 1, MAX<int32>(0, y));

int32 maskData = _currentMask->getData(x, y) & 0x1f;
return _roomScaleData[maskData + 2] * 1024 / 100;
Expand All @@ -1886,8 +1886,8 @@ int32 ToonEngine::getLayerAtPoint(int32 x, int32 y) {
return 0;

// clamp values
x = MIN<int32>(1279, MAX<int32>(0, x));
y = MIN<int32>(399, MAX<int32>(0, y));
x = MIN<int32>(TOON_BACKBUFFER_WIDTH - 1, MAX<int32>(0, x));
y = MIN<int32>(TOON_BACKBUFFER_HEIGHT - 1, MAX<int32>(0, y));

int32 maskData = _currentMask->getData(x, y) & 0x1f;
return _roomScaleData[maskData + 130] << 5;
Expand Down Expand Up @@ -2560,7 +2560,7 @@ void ToonEngine::renderInventory() {
_inventoryPicture->drawWithRectList(*_mainSurface, 0, 0, 0, 0, _dirtyRects);
} else {
_inventoryPicture->draw(*_mainSurface, 0, 0, 0, 0);
_dirtyRects.push_back(Common::Rect(0, 0, 640, 400));
_dirtyRects.push_back(Common::Rect(0, 0, TOON_SCREEN_WIDTH, TOON_SCREEN_HEIGHT));
}
clearDirtyRects();

Expand Down Expand Up @@ -2866,7 +2866,7 @@ void ToonEngine::getTextPosition(int32 characterId, int32 *retX, int32 *retY) {
// drew
int32 x = _drew->getX();
int32 y = _drew->getY();
if (x >= _gameState->_currentScrollValue && x <= _gameState->_currentScrollValue + 640) {
if (x >= _gameState->_currentScrollValue && x <= _gameState->_currentScrollValue + TOON_SCREEN_WIDTH) {
if (!_gameState->_inCutaway && !_gameState->_inInventory) {
*retX = x;
*retY = y - ((_drew->getScale() * 256 / 1024) >> 1) - 45;
Expand All @@ -2876,7 +2876,7 @@ void ToonEngine::getTextPosition(int32 characterId, int32 *retX, int32 *retY) {
// flux
int32 x = _flux->getX();
int32 y = _flux->getY();
if (x >= _gameState->_currentScrollValue && x <= _gameState->_currentScrollValue + 640) {
if (x >= _gameState->_currentScrollValue && x <= _gameState->_currentScrollValue + TOON_SCREEN_WIDTH) {
if (!_gameState->_inCutaway) {
*retX = x;
*retY = y - ((_drew->getScale() * 100 / 1024) >> 1) - 30;
Expand Down Expand Up @@ -2906,7 +2906,7 @@ void ToonEngine::getTextPosition(int32 characterId, int32 *retX, int32 *retY) {
Character *character = getCharacterById(characterId);
if (character && !_gameState->_inCutaway) {
if (character->getAnimationInstance()) {
if (character->getX() >= _gameState->_currentScrollValue && character->getX() <= _gameState->_currentScrollValue + 640) {
if (character->getX() >= _gameState->_currentScrollValue && character->getX() <= _gameState->_currentScrollValue + TOON_SCREEN_WIDTH) {
int32 x1, y1, x2, y2;
character->getAnimationInstance()->getRect(&x1, &y1, &x2, &y2);
*retX = (x1 + x2) / 2;
Expand Down Expand Up @@ -4674,10 +4674,10 @@ void ToonEngine::dirtyAllScreen()
}

void ToonEngine::addDirtyRect( int32 left, int32 top, int32 right, int32 bottom ) {
left = MAX<int32>(left, 0);
right = MIN<int32>(right, 1280);
top = MAX<int32>(top, 0);
bottom = MIN<int32>(bottom, 400);
left = MIN<int32>(MAX<int32>(left, 0), TOON_BACKBUFFER_WIDTH - 1);
right = MIN<int32>(MAX<int32>(right, 0), TOON_BACKBUFFER_WIDTH - 1);
top = MIN<int32>(MAX<int32>(top, 0), TOON_BACKBUFFER_HEIGHT - 1);
bottom = MIN<int32>(MAX<int32>(bottom, 0), TOON_BACKBUFFER_HEIGHT - 1);

Common::Rect rect(left, top, right, bottom);

Expand Down
5 changes: 5 additions & 0 deletions engines/toon/toon.h
Expand Up @@ -52,6 +52,11 @@ class MemoryWriteStreamDynamic;
#define TOON_SAVEGAME_VERSION 4
#define DATAALIGNMENT 4

#define TOON_SCREEN_WIDTH 640
#define TOON_SCREEN_HEIGHT 400
#define TOON_BACKBUFFER_WIDTH 1280
#define TOON_BACKBUFFER_HEIGHT 400

/**
* This is the namespace of the Toon engine.
*
Expand Down

0 comments on commit 3964ce8

Please sign in to comment.