diff options
author | Sven Hesse | 2007-03-20 14:51:57 +0000 |
---|---|---|
committer | Sven Hesse | 2007-03-20 14:51:57 +0000 |
commit | 2dc7cb2cd49c20a5f6bcfe5446fb8340f6a555c8 (patch) | |
tree | 4b442eb88ed1bcc6b4a664890c0b8d8d10b5a912 /engines/gob/draw_v2.cpp | |
parent | d94979c936c4edca5eaa23532b4814b2bf4cb933 (diff) | |
download | scummvm-rg350-2dc7cb2cd49c20a5f6bcfe5446fb8340f6a555c8.tar.gz scummvm-rg350-2dc7cb2cd49c20a5f6bcfe5446fb8340f6a555c8.tar.bz2 scummvm-rg350-2dc7cb2cd49c20a5f6bcfe5446fb8340f6a555c8.zip |
Major clean-up, including:
- Cutting down the code-dup
- Plucking leaks
- Removing dead/unused code
- Properly naming "word_2342F"-style variables and functions (removing the warnings alongside)
- Fleshing out the "stubby" functions
- Moving functions and variables to more appropriate/logical places
- Re-ordering functions and variables
- Re-structuring functions
- Moving the IMD stuff into a new "Imd" class in the new imd.cpp/.h (still to be completely implemented and cleaned up)
- Formatting
- Getting rid off the classes "Anim", "Pack" and "Timer", along with their files
svn-id: r26252
Diffstat (limited to 'engines/gob/draw_v2.cpp')
-rw-r--r-- | engines/gob/draw_v2.cpp | 756 |
1 files changed, 318 insertions, 438 deletions
diff --git a/engines/gob/draw_v2.cpp b/engines/gob/draw_v2.cpp index 500dcb586c..93cfe04be9 100644 --- a/engines/gob/draw_v2.cpp +++ b/engines/gob/draw_v2.cpp @@ -28,69 +28,184 @@ #include "gob/gob.h" #include "gob/draw.h" #include "gob/global.h" -#include "gob/game.h" #include "gob/util.h" +#include "gob/game.h" #include "gob/scenery.h" -#include "gob/inter.h" -#include "gob/cdrom.h" +#include "gob/video.h" namespace Gob { Draw_v2::Draw_v2(GobEngine *vm) : Draw_v1(vm) { } -void Draw_v2::printText(void) { - int i; +void Draw_v2::initScreen() { + _scrollOffsetX = 0; + _scrollOffsetY = 0; + + initSpriteSurf(21, _vm->_video->_surfWidth, _vm->_video->_surfHeight, 0); + _backSurface = _spritesArray[21]; + _vm->_video->clearSurf(_backSurface); + + initSpriteSurf(23, 32, 16, 2); + _cursorSpritesBack = _spritesArray[23]; + _cursorSprites = _cursorSpritesBack; + _scummvmCursor = + _vm->_video->initSurfDesc(_vm->_global->_videoMode, 16, 16, SCUMMVM_CURSOR); + + _spritesArray[20] = _frontSurface; + _spritesArray[21] = _backSurface; +} + +void Draw_v2::closeScreen() { + freeSprite(23); + _cursorSprites = 0; + _cursorSpritesBack = 0; + _scummvmCursor = 0; + freeSprite(21); +} + +void Draw_v2::blitCursor() { + if (_cursorIndex == -1) + return; + + _showCursor = (_showCursor & ~2) | ((_showCursor & 1) << 1); +} + +void Draw_v2::animateCursor(int16 cursor) { + Game::Collision *ptr; + int16 cursorIndex = cursor; + int16 newX = 0, newY = 0; + uint16 hotspotX = 0, hotspotY = 0; + + _showCursor |= 1; + + // .-- _draw_animateCursorSUB1 --- + if (cursorIndex == -1) { + cursorIndex = 0; + for (ptr = _vm->_game->_collisionAreas; ptr->left != -1; ptr++) { + if ((ptr->flags & 0xF00) || (ptr->id & 0x4000)) + continue; + + if (ptr->left > _vm->_global->_inter_mouseX) + continue; + + if (ptr->right < _vm->_global->_inter_mouseX) + continue; + + if (ptr->top > _vm->_global->_inter_mouseY) + continue; + + if (ptr->bottom < _vm->_global->_inter_mouseY) + continue; + + if ((ptr->flags & 0xF000) == 0) { + if ((ptr->flags & 0xF) >= 3) { + cursorIndex = 3; + break; + } else if (((ptr->flags & 0xF0) != 0x10) && (cursorIndex == 0)) + cursorIndex = 1; + } else if (cursorIndex == 0) + cursorIndex = (ptr->flags >> 12) & 0xF; + } + if (_cursorAnimLow[cursorIndex] == -1) + cursorIndex = 1; + } + // '------ + + if (_cursorAnimLow[cursorIndex] != -1) { + // .-- _draw_animateCursorSUB2 --- + if (cursorIndex == _cursorIndex) { + if ((_cursorAnimDelays[_cursorIndex] != 0) && + ((_cursorTimeKey + (_cursorAnimDelays[_cursorIndex] * 10)) <= + _vm->_util->getTimeKey())) { + _cursorAnim++; + if ((_cursorAnimHigh[_cursorIndex] < _cursorAnim) || + (_cursorAnimLow[_cursorIndex] > _cursorAnim)) + _cursorAnim = _cursorAnimLow[_cursorIndex]; + _cursorTimeKey = _vm->_util->getTimeKey(); + } else { + if (_noInvalidated && (_vm->_global->_inter_mouseX == _cursorX) && + (_vm->_global->_inter_mouseY == _cursorY)) { + _vm->_video->waitRetrace(_vm->_global->_videoMode); + return; + } + } + } else { + _cursorIndex = cursorIndex; + if (_cursorAnimDelays[cursorIndex] != 0) { + _cursorAnim = _cursorAnimLow[cursorIndex]; + _cursorTimeKey = _vm->_util->getTimeKey(); + } + } + + if (_cursorAnimDelays[_cursorIndex] != 0) { + if ((_cursorAnimHigh[_cursorIndex] < _cursorAnim) || + (_cursorAnimLow[_cursorIndex] > _cursorAnim)) + _cursorAnim = _cursorAnimLow[_cursorIndex]; + + cursorIndex = _cursorAnim; + } + // '------ + + newX = _vm->_global->_inter_mouseX; + newY = _vm->_global->_inter_mouseY; + if (_cursorHotspotXVar != -1) { + newX -= hotspotX = (uint16) VAR(_cursorIndex + _cursorHotspotXVar); + newY -= hotspotY = (uint16) VAR(_cursorIndex + _cursorHotspotYVar); + } + + _vm->_video->clearSurf(_scummvmCursor); + _vm->_video->drawSprite(_cursorSprites, _scummvmCursor, + cursorIndex * _cursorWidth, 0, + (cursorIndex + 1) * _cursorWidth - 1, + _cursorHeight - 1, 0, 0, 0); + CursorMan.replaceCursor(_scummvmCursor->getVidMem(), + _cursorWidth, _cursorHeight, hotspotX, hotspotY, 0); + + if (_frontSurface != _backSurface) { + if (!_noInvalidated) { + int16 tmp = _cursorIndex; + _cursorIndex = -1; + blitInvalidated(); + _cursorIndex = tmp; + } else { + _showCursor = 3; + _vm->_video->waitRetrace(_vm->_global->_videoMode); + if (MIN(newY, _cursorY) < 50) + _vm->_util->delay(5); + } + } + } else + blitCursor(); + + _showCursor &= ~1; + + _cursorX = newX; + _cursorY = newY; +} + +void Draw_v2::printTotText(int16 id) { byte *dataPtr; - byte *ptr; - byte *ptr2; - char mask[80]; - char str[80]; - char buf[50]; - char cmd; + byte *ptr, *ptrEnd; + byte cmd; int16 savedFlags; - int16 destX; - int16 destY; - int16 spriteRight; - int16 spriteBottom; + int16 destX, destY; + int16 spriteRight, spriteBottom; int16 val; - int16 index; - int16 rectLeft; - int16 rectTop; - int16 rectRight; - int16 rectBottom; - int16 fontIndex; - int16 strPos; // si - int16 frontColor; - int16 colId; - int16 strPos2; - int16 offX; - int16 offY; - int16 extraCmd; - int16 strPosBak; - int16 maskChar; - int16 width; + int16 rectLeft, rectTop, rectRight, rectBottom; int16 size; - index = _vm->_inter->load16(); - - _vm->_cdrom->playMultMusic(); - - if ((_vm->_game->_totTextData == 0) || (_vm->_game->_totTextData->dataPtr == 0)) + if (!_vm->_game->_totTextData || !_vm->_game->_totTextData->dataPtr) return; - if (_vm->_global->_languageWanted != _vm->_global->_language) { - warning("Your game version doesn't support the requested language, " - "using the first one available (%d)", _vm->_global->_language); - _vm->_global->_languageWanted = _vm->_global->_language; - } + _vm->validateLanguage(); - size = _vm->_game->_totTextData->items[index].size; + size = _vm->_game->_totTextData->items[id].size; dataPtr = ((byte *) _vm->_game->_totTextData->dataPtr) + - _vm->_game->_totTextData->items[index].offset; + _vm->_game->_totTextData->items[id].offset; ptr = dataPtr; - if ((_renderFlags & 0x400) && (ptr[1] & 0x80)) + if ((_renderFlags & RENDERFLAG_SKIPOPTIONALTEXT) && (ptr[1] & 0x80)) return; destX = READ_LE_UINT16(ptr) & 0x7FFF; @@ -117,92 +232,94 @@ void Draw_v2::printText(void) { spriteOperation(DRAW_CLEARRECT); _backColor = 0; - savedFlags = _renderFlags; _renderFlags &= ~RENDERFLAG_NOINVALIDATE; - for (; (_destSpriteX = READ_LE_UINT16(ptr)) != -1; ptr++) { + while ((_destSpriteX = READ_LE_UINT16(ptr)) != -1) { _destSpriteX += destX; _destSpriteY = READ_LE_UINT16(ptr + 2) + destY; _spriteRight = READ_LE_UINT16(ptr + 4) + destX; _spriteBottom = READ_LE_UINT16(ptr + 6) + destY; ptr += 8; - cmd = (*ptr & 0xf0) >> 4; - if (cmd == 0) { - _frontColor = *ptr & 0xf; + cmd = *ptr++; + switch ((cmd & 0xF0) >> 4) { + case 0: + _frontColor = cmd & 0xF; spriteOperation(DRAW_DRAWLINE); - } else if (cmd == 1) { - _frontColor = *ptr & 0xf; + break; + case 1: + _frontColor = cmd & 0xF; spriteOperation(DRAW_DRAWBAR); - } else if (cmd == 2) { - _backColor = *ptr & 0xf; + break; + case 2: + _backColor = cmd & 0xF; spriteOperation(DRAW_FILLRECTABS); + break; } } ptr += 2; - // Adding the boundary check *shouldn't* pose any problems, since access behind - // that point should be forbidden anyway. - for (i = 0, ptr2 = ptr; ((ptr2 - dataPtr) < size) && (*ptr2 != 1); i++) { - if ((_vm->_game->_totFileData[0x29] < 0x32) && (*ptr2 > 3) && (*ptr2 < 32)) - *ptr2 = 32; + ptrEnd = ptr; + while (((ptrEnd - dataPtr) < size) && (*ptrEnd != 1)) { + // Converting to unknown commands/characters to spaces + if ((_vm->_game->_totFileData[0x29] < 0x32) && (*ptrEnd > 3) && (*ptrEnd < 32)) + *ptrEnd = 32; - switch (*ptr2) { + switch (*ptrEnd) { case 1: break; case 2: case 5: - ptr2 += 5; + ptrEnd += 5; break; case 3: case 4: - ptr2 += 2; + ptrEnd += 2; break; case 6: - ptr2++; - switch (*ptr2 & 0xC0) { + ptrEnd++; + switch (*ptrEnd & 0xC0) { case 0x40: - ptr2 += 9; + ptrEnd += 9; break; case 0x80: - ptr2 += 3; + ptrEnd += 3; break; case 0xC0: - ptr2 += 11; + ptrEnd += 11; break; default: - ptr2++; + ptrEnd++; break; } break; case 10: - ptr2 += (ptr2[1] * 2) + 2; + ptrEnd += (ptrEnd[1] * 2) + 2; break; default: - ptr2++; + ptrEnd++; break; } } + ptrEnd++; - ptr2++; + int16 fontIndex = 0, frontColor = 0; + int16 strPos = 0, strPos2 = -1, strPosBak; + int16 offX = 0, offY = 0; + int16 colId = 0; + int16 colCmd = 0; + int16 width; + int16 maskChar = 0; + char mask[80], str[80], buf[50]; - fontIndex = 0; - strPos = 0; - extraCmd = 0; - frontColor = 0; - colId = 0; - offX = 0; - offY = 0; - strPos2 = -1; memset(mask, 0, 80); memset(str, ' ', 80); - maskChar = 0; _backColor = 0; _transparency = 1; @@ -212,7 +329,8 @@ void Draw_v2::printText(void) { strPosBak = strPos; width = strlen(str) * _fonts[fontIndex]->itemWidth; adjustCoords(1, &width, 0); - if (extraCmd & 0x0F) { + + if (colCmd & 0x0F) { rectLeft = offX - 2; rectTop = offY - 2; rectRight = offX + width + 1; @@ -221,36 +339,42 @@ void Draw_v2::printText(void) { rectBottom += offY + 1; adjustCoords(0, &rectLeft, &rectTop); adjustCoords(2, &rectRight, &rectBottom); + if (colId != -1) _vm->_game->addNewCollision(colId + 0xD000, rectLeft, rectTop, rectRight, rectBottom, 2, 0, 0, 0); - if (_word_2E8E2 != 2) - printTextCentered(extraCmd & 0x0F, rectLeft + 4, rectTop + 4, + + if (_needAdjust != 2) + printTextCentered(colCmd & 0x0F, rectLeft + 4, rectTop + 4, rectRight - 4, rectBottom - 4, str, fontIndex, frontColor); else - printTextCentered(extraCmd & 0x0F, rectLeft + 2, rectTop + 2, + printTextCentered(colCmd & 0x0F, rectLeft + 2, rectTop + 2, rectRight - 2, rectBottom - 2, str, fontIndex, frontColor); + } else { _destSpriteX = offX; _destSpriteY = offY; _fontIndex = fontIndex; _frontColor = frontColor; _textToPrint = str; - if (_word_2E8E2 != 2) { - if ((_destSpriteX >= destX) && (_destSpriteY >= destY)) { - if (((_fonts[_fontIndex]->itemHeight / 2) + _destSpriteY - 1) <= spriteBottom) { - while (((_destSpriteX + width - 1) > spriteRight) && (width > 0)) { - width -= _fonts[_fontIndex]->itemWidth / 2; - str[strlen(str) - 1] = '\0'; - } - spriteOperation(DRAW_PRINTTEXT); + + if (_needAdjust != 2) { + if ((_destSpriteX >= destX) && (_destSpriteY >= destY) && + (((_fonts[_fontIndex]->itemHeight / 2) + _destSpriteY - 1) <= spriteBottom)) { + while (((_destSpriteX + width - 1) > spriteRight) && (width > 0)) { + width -= _fonts[_fontIndex]->itemWidth / 2; + str[strlen(str) - 1] = '\0'; } + spriteOperation(DRAW_PRINTTEXT); } } else spriteOperation(DRAW_PRINTTEXT); + width = strlen(str); for (strPos = 0; strPos < width; strPos++) { - if (mask[strPos] == '\0') continue; + if (mask[strPos] == '\0') + continue; + rectLeft = _fonts[fontIndex]->itemWidth; rectTop = _fonts[fontIndex]->itemHeight; adjustCoords(1, &rectLeft, &rectTop); @@ -261,6 +385,7 @@ void Draw_v2::printText(void) { spriteOperation(DRAW_DRAWLINE); } } + rectLeft = _fonts[_fontIndex]->itemWidth; adjustCoords(1, &rectLeft, 0); offX += strPosBak * rectLeft; @@ -297,13 +422,13 @@ void Draw_v2::printText(void) { case 6: ptr++; - extraCmd = *ptr++; + colCmd = *ptr++; colId = -1; - if (extraCmd & 0x80) { + if (colCmd & 0x80) { colId = (int16)READ_LE_UINT16(ptr); ptr += 2; } - if (extraCmd & 0x40) { + if (colCmd & 0x40) { rectLeft = destX + (int16)READ_LE_UINT16(ptr); rectRight = destX + (int16)READ_LE_UINT16(ptr + 2); rectTop = destY + (int16)READ_LE_UINT16(ptr + 4); @@ -318,7 +443,7 @@ void Draw_v2::printText(void) { case 7: ptr++; - extraCmd = 0; + colCmd = 0; break; case 8: @@ -332,61 +457,61 @@ void Draw_v2::printText(void) { break; case 10: - // loc_12C93 - str[0] = (char)255; - WRITE_LE_UINT16((uint16*)(str+1), ((char *) ptr) - _vm->_game->_totTextData->dataPtr); + str[0] = (char) 255; + WRITE_LE_UINT16((uint16 *) (str + 1), + ((char *) ptr) - _vm->_game->_totTextData->dataPtr); str[3] = 0; ptr++; - i = *ptr++; - for (i = *ptr++; i > 0; i--) { + for (int i = *ptr++; i > 0; i--) { mask[strPos++] = maskChar; ptr += 2; } break; default: - str[strPos] = cmd; + str[strPos] = (char) cmd; case 32: mask[strPos++] = maskChar; ptr++; break; case 186: - cmd = ptr2[17] & 0x7f; + cmd = ptrEnd[17] & 0x7F; if (cmd == 0) { - val = READ_LE_UINT16(ptr2 + 18) * 4; + val = READ_LE_UINT16(ptrEnd + 18) * 4; sprintf(buf, "%d", VAR_OFFSET(val)); } else if (cmd == 1) { - val = READ_LE_UINT16(ptr2 + 18) * 4; + val = READ_LE_UINT16(ptrEnd + 18) * 4; strcpy(buf, GET_VARO_STR(val)); } else { - val = READ_LE_UINT16(ptr2 + 18) * 4; + val = READ_LE_UINT16(ptrEnd + 18) * 4; sprintf(buf, "%d", VAR_OFFSET(val)); if (buf[0] == '-') { - while (strlen(buf) - 1 < (uint32)ptr2[17]) { + while (strlen(buf) - 1 < (uint32)ptrEnd[17]) { _vm->_util->insertStr("0", buf, 1); } } else { - while (strlen(buf) - 1 < (uint32)ptr2[17]) { + while (strlen(buf) - 1 < (uint32)ptrEnd[17]) { _vm->_util->insertStr("0", buf, 0); } } if (_vm->_global->_language == 2) - _vm->_util->insertStr(".", buf, strlen(buf) + 1 - ptr2[17]); + _vm->_util->insertStr(".", buf, strlen(buf) + 1 - ptrEnd[17]); else - _vm->_util->insertStr(",", buf, strlen(buf) + 1 - ptr2[17]); + _vm->_util->insertStr(",", buf, strlen(buf) + 1 - ptrEnd[17]); } memcpy(str + strPos, buf, strlen(buf)); memset(mask, maskChar, strlen(buf)); - if (ptr2[17] & 0x80) { + if (ptrEnd[17] & 0x80) { strPos2 = strPos + strlen(buf); strPos++; - ptr2 += 23; + ptrEnd += 23; ptr++; } else { strPos += strlen(buf); if (ptr[1] != ' ') { - if ((ptr[1] == 2) && (((int16)READ_LE_UINT16(ptr + 4)) == _destSpriteY)) { + if ((ptr[1] == 2) && + (((int16)READ_LE_UINT16(ptr + 4)) == _destSpriteY)) { ptr += 5; str[strPos] = ' '; mask[strPos++] = maskChar; @@ -396,10 +521,11 @@ void Draw_v2::printText(void) { mask[strPos++] = maskChar; while (ptr[1] == ' ') ptr++; - if ((ptr[1] == 2) && (((int16)READ_LE_UINT16(ptr + 4)) == _destSpriteY)) + if ((ptr[1] == 2) && + (((int16)READ_LE_UINT16(ptr + 4)) == _destSpriteY)) ptr += 5; } - ptr2 += 23; + ptrEnd += 23; ptr++; } break; @@ -407,7 +533,7 @@ void Draw_v2::printText(void) { } _renderFlags = savedFlags; - if (!(_renderFlags & 4)) + if (!(_renderFlags & RENDERFLAG_COLLISIONS)) return; _vm->_game->checkCollisions(0, 0, 0, 0); @@ -416,8 +542,6 @@ void Draw_v2::printText(void) { (*_vm->_scenery->_pCaptureCounter)--; _vm->_game->capturePop(1); } - - return; } void Draw_v2::spriteOperation(int16 operation) { @@ -426,35 +550,19 @@ void Draw_v2::spriteOperation(int16 operation) { Game::TotResItem *itemPtr; int32 offset; int16 len; - int16 i; - int16 x; - int16 y; - Video::SurfaceDesc *sourceSurf; - Video::SurfaceDesc *destSurf; + int16 x, y; + SurfaceDesc *sourceSurf, *destSurf; bool deltaVeto; int16 left; int16 ratio; - int16 spriteLeft; - int16 spriteTop; - int16 spriteRight; - int16 spriteBottom; - int16 destSpriteX; - int16 destSpriteY; - int16 destSurface; - int16 sourceSurface; -// .--- - int8 word_2F2D2 = -1; -// '--- - - if (operation & 0x10) { - deltaVeto = true; - operation &= 0x0F; - } else - deltaVeto = false; + // Some handle, but always assigned to -1 in Game::loadTotFile() + int16 word_2F2D2 = -1; + + deltaVeto = (bool) (operation & 0x10); + operation &= 0x0F; if (_sourceSurface >= 100) _sourceSurface -= 80; - if (_destSurface >= 100) _destSurface -= 80; @@ -467,63 +575,44 @@ void Draw_v2::spriteOperation(int16 operation) { if (_destSurface == 21) { _destSpriteX += _backDeltaX; _destSpriteY += _backDeltaY; - if (operation == DRAW_DRAWLINE || - (operation >= DRAW_DRAWBAR - && operation <= DRAW_FILLRECTABS)) { + if ((operation == DRAW_DRAWLINE) || + ((operation >= DRAW_DRAWBAR) && + (operation <= DRAW_FILLRECTABS))) { _spriteRight += _backDeltaX; _spriteBottom += _backDeltaY; } } } - spriteLeft = _spriteLeft; - spriteTop = _spriteTop; - spriteRight = _spriteRight; - spriteBottom = _spriteLeft; - destSpriteX = _destSpriteX; - destSpriteY = _destSpriteY; - destSurface = _destSurface; - sourceSurface = _sourceSurface; - -// warning("GOB2 Stub! _off_2E51B"); - if (_off_2E51B != 0) { - if ((_frontSurface->height <= _destSpriteY) && - ((_destSurface == 20) || (_destSurface == 21))) { - _destSpriteY -= _frontSurface->height; - if (operation == DRAW_DRAWLINE || - (operation >= DRAW_DRAWBAR - && operation <= DRAW_FILLRECTABS)) { - _spriteBottom -= _frontSurface->height; - } - if (_destSurface == 21) - invalidateRect(0, _frontSurface->height, _vm->_video->_surfWidth - 1, - _frontSurface->height + _off_2E51B->height - 1); - destSurface += 4; - } - if ((_frontSurface->height <= _spriteTop) && (operation == DRAW_BLITSURF) - && ((_destSurface == 20) || (_destSurface == 21))) { - _spriteTop -= _frontSurface->height; - _sourceSurface += 4; - } - } + int16 spriteLeft = _spriteLeft; + int16 spriteTop = _spriteTop; + int16 spriteRight = _spriteRight; + int16 spriteBottom = _spriteLeft; + int16 destSpriteX = _destSpriteX; + int16 destSpriteY = _destSpriteY; + int16 destSurface = _destSurface; + int16 sourceSurface = _sourceSurface; adjustCoords(0, &_destSpriteX, &_destSpriteY); - if ((operation != DRAW_LOADSPRITE) && (_word_2E8E2 != 2)) { + if ((operation != DRAW_LOADSPRITE) && (_needAdjust != 2)) { adjustCoords(0, &_spriteRight, &_spriteBottom); adjustCoords(0, &_spriteLeft, &_spriteTop); - if (operation == DRAW_DRAWLETTER) + + if (operation == DRAW_DRAWLINE) { + if ((_spriteRight == _destSpriteX) || (_spriteBottom == _destSpriteY)) { + operation = DRAW_FILLRECTABS; + _backColor = _frontColor; + } + } else if (operation == DRAW_DRAWLETTER) operation = DRAW_BLITSURF; - if ((operation == DRAW_DRAWLINE) && - ((_spriteRight == _destSpriteX) || (_spriteBottom == _destSpriteY))) { - operation = DRAW_FILLRECTABS; - _backColor = _frontColor; - } + if (operation == DRAW_DRAWLINE) { if (_spriteBottom < _destSpriteY) { SWAP(_spriteBottom, _destSpriteY); SWAP(_spriteRight, _destSpriteX); } - } else if ((operation == DRAW_LOADSPRITE) || (operation > DRAW_PRINTTEXT)) { + } else if ((operation == DRAW_LOADSPRITE) || + (operation > DRAW_PRINTTEXT)) { if (_spriteBottom < _destSpriteY) SWAP(_spriteBottom, _destSpriteY); if (_spriteRight < _destSpriteX) @@ -539,7 +628,7 @@ void Draw_v2::spriteOperation(int16 operation) { switch (operation) { case DRAW_BLITSURF: case DRAW_DRAWLETTER: - if ((sourceSurf == 0) || (destSurf == 0)) + if (!sourceSurf || !destSurf) break; _vm->_video->drawSprite(_spritesArray[_sourceSurface], @@ -551,17 +640,17 @@ void Draw_v2::spriteOperation(int16 operation) { if (_destSurface == 21) { invalidateRect(_destSpriteX, _destSpriteY, - _destSpriteX + _spriteRight - 1, - _destSpriteY + _spriteBottom - 1); + _destSpriteX + _spriteRight - 1, + _destSpriteY + _spriteBottom - 1); } break; case DRAW_PUTPIXEL: - _vm->_video->putPixel(_destSpriteX, _destSpriteY, - _frontColor, _spritesArray[_destSurface]); + _vm->_video->putPixel(_destSpriteX, _destSpriteY, _frontColor, + _spritesArray[_destSurface]); if (_destSurface == 21) { invalidateRect(_destSpriteX, _destSpriteY, - _destSpriteX, _destSpriteY); + _destSpriteX, _destSpriteY); } break; @@ -572,8 +661,8 @@ void Draw_v2::spriteOperation(int16 operation) { if (_destSurface == 21) { invalidateRect(_destSpriteX, _destSpriteY, - _destSpriteX + _spriteRight - 1, - _destSpriteY + _spriteBottom - 1); + _destSpriteX + _spriteRight - 1, + _destSpriteY + _spriteBottom - 1); } break; @@ -584,7 +673,7 @@ void Draw_v2::spriteOperation(int16 operation) { if (_destSurface == 21) { invalidateRect(_destSpriteX, _destSpriteY, - _spriteRight, _spriteBottom); + _spriteRight, _spriteBottom); } break; @@ -592,9 +681,10 @@ void Draw_v2::spriteOperation(int16 operation) { _vm->_video->drawCircle(_spritesArray[_destSurface], _destSpriteX, _destSpriteY, _spriteRight, _frontColor); if (_destSurface == 21) { - invalidateRect(_destSpriteX - _spriteRight, _destSpriteY - _spriteBottom, // !! - _destSpriteX + _spriteRight, - _destSpriteY + _spriteBottom); + invalidateRect(_destSpriteX - _spriteRight, + _destSpriteY - _spriteBottom, + _destSpriteX + _spriteRight, + _destSpriteY + _spriteBottom); } break; @@ -602,17 +692,14 @@ void Draw_v2::spriteOperation(int16 operation) { id = _spriteLeft; if (id >= 30000) { dataBuf = - _vm->_game->loadExtData(id, &_spriteRight, - &_spriteBottom); - _vm->_video->drawPackedSprite((byte *)dataBuf, _spriteRight, - _spriteBottom, _destSpriteX, - _destSpriteY, _transparency, - _spritesArray[_destSurface]); + _vm->_game->loadExtData(id, &_spriteRight, &_spriteBottom); + _vm->_video->drawPackedSprite((byte *) dataBuf, + _spriteRight, _spriteBottom, _destSpriteX, _destSpriteY, + _transparency, _spritesArray[_destSurface]); if (_destSurface == 21) { - invalidateRect(_destSpriteX, - _destSpriteY, - _destSpriteX + _spriteRight - 1, - _destSpriteY + _spriteBottom - 1); + invalidateRect(_destSpriteX, _destSpriteY, + _destSpriteX + _spriteRight - 1, + _destSpriteY + _spriteBottom - 1); } delete[] dataBuf; break; @@ -621,49 +708,44 @@ void Draw_v2::spriteOperation(int16 operation) { itemPtr = &_vm->_game->_totResourceTable->items[id]; offset = itemPtr->offset; if (offset >= 0) { - dataBuf = - _vm->_game->_totResourceTable->dataPtr + - szGame_TotResTable + szGame_TotResItem * - _vm->_game->_totResourceTable->itemsCount + offset; + dataBuf = _vm->_game->_totResourceTable->dataPtr + + szGame_TotResTable + szGame_TotResItem * + _vm->_game->_totResourceTable->itemsCount + offset; } else { - dataBuf = - _vm->_game->_imFileData + - (int32)READ_LE_UINT32(&((int32 *)_vm->_game->_imFileData)[-offset - 1]); + dataBuf = _vm->_game->_imFileData + + (int32) READ_LE_UINT32(&((int32 *) _vm->_game->_imFileData)[-offset - 1]); } _spriteRight = itemPtr->width; _spriteBottom = itemPtr->height; - _vm->_video->drawPackedSprite((byte *)dataBuf, + _vm->_video->drawPackedSprite((byte *) dataBuf, _spriteRight, _spriteBottom, _destSpriteX, _destSpriteY, _transparency, _spritesArray[_destSurface]); if (_destSurface == 21) { invalidateRect(_destSpriteX, _destSpriteY, - _destSpriteX + _spriteRight - 1, - _destSpriteY + _spriteBottom - 1); + _destSpriteX + _spriteRight - 1, + _destSpriteY + _spriteBottom - 1); } break; case DRAW_PRINTTEXT: len = strlen(_textToPrint); left = _destSpriteX; + if ((_fontIndex >= 4) || (_fontToSprite[_fontIndex].sprite == -1)) { - if (_fonts[_fontIndex]->extraData == 0) { + + if (!_fonts[_fontIndex]->extraData) { if (((int8) _textToPrint[0]) == -1) { - if (_vm->_global->_languageWanted != _vm->_global->_language) { - warning("Your game version doesn't support the requested language, " - "using the first one available (%d)", - _vm->_global->_language); - _vm->_global->_languageWanted = _vm->_global->_language; - } + _vm->validateLanguage(); + dataBuf = _vm->_game->_totTextData->dataPtr + _textToPrint[1] + 1; len = *dataBuf++; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++, dataBuf += 2) { _vm->_video->drawLetter(READ_LE_UINT16(dataBuf), _destSpriteX, _destSpriteY, _fonts[_fontIndex], _transparency, _frontColor, _backColor, _spritesArray[_destSurface]); - dataBuf += 2; } } else { drawString(_textToPrint, _destSpriteX, _destSpriteY, _frontColor, @@ -672,40 +754,25 @@ void Draw_v2::spriteOperation(int16 operation) { _destSpriteX += len * _fonts[_fontIndex]->itemWidth; } } else { - if (word_2F2D2 >= 0) { - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { + if ((word_2F2D2 < 0) || (_textToPrint[i] != ' ')) { _vm->_video->drawLetter(_textToPrint[i], _destSpriteX, _destSpriteY, _fonts[_fontIndex], _transparency, _frontColor, _backColor, _spritesArray[_destSurface]); _destSpriteX += *(((char*)_fonts[_fontIndex]->extraData) + (_textToPrint[i] - _fonts[_fontIndex]->startItem)); } - } else { // loc_DBE9 - warning("Untested, does that work?"); - // Does something different for each character depending on whether it's a space - // That *should* be it... - for (i = 0; i < len; i++) { - if (_textToPrint[i] == ' ') - _destSpriteX += _fonts[_fontIndex]->itemWidth; - else { - _vm->_video->drawLetter(_textToPrint[i], - _destSpriteX, _destSpriteY, - _fonts[_fontIndex], - _transparency, - _frontColor, _backColor, - _spritesArray[_destSurface]); - _destSpriteX += - *(((char*)_fonts[_fontIndex]->extraData) + (_textToPrint[i] - _fonts[_fontIndex]->startItem)); - } - } + else + _destSpriteX += _fonts[_fontIndex]->itemWidth; } } + } else { sourceSurf = _spritesArray[_fontToSprite[_fontIndex].sprite]; ratio = ((sourceSurf == _frontSurface) || (sourceSurf == _backSurface)) ? - 320 : sourceSurf->width; + 320 : sourceSurf->getWidth(); ratio /= _fontToSprite[_fontIndex].width; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { y = ((_textToPrint[i] - _fontToSprite[_fontIndex].base) / ratio) * _fontToSprite[_fontIndex].height; x = ((_textToPrint[i] - _fontToSprite[_fontIndex].base) % ratio) @@ -721,13 +788,13 @@ void Draw_v2::spriteOperation(int16 operation) { if (_destSurface == 21) { invalidateRect(left, _destSpriteY, - _destSpriteX - 1, - _destSpriteY + _fonts[_fontIndex]->itemHeight - 1); + _destSpriteX - 1, + _destSpriteY + _fonts[_fontIndex]->itemHeight - 1); } break; case DRAW_DRAWBAR: - if (_word_2E8E2 != 2) { + if (_needAdjust != 2) { _vm->_video->fillRect(_spritesArray[_destSurface], _destSpriteX, _spriteBottom - 1, _spriteRight, _spriteBottom, _frontColor); @@ -762,7 +829,7 @@ void Draw_v2::spriteOperation(int16 operation) { } if (_destSurface == 21) { invalidateRect(_destSpriteX, _destSpriteY, - _spriteRight, _spriteBottom); + _spriteRight, _spriteBottom); } break; @@ -775,7 +842,7 @@ void Draw_v2::spriteOperation(int16 operation) { } if (_destSurface == 21) { invalidateRect(_destSpriteX, _destSpriteY, - _spriteRight, _spriteBottom); + _spriteRight, _spriteBottom); } break; @@ -786,7 +853,7 @@ void Draw_v2::spriteOperation(int16 operation) { if (_destSurface == 21) { invalidateRect(_destSpriteX, _destSpriteY, - _spriteRight, _spriteBottom); + _spriteRight, _spriteBottom); } break; } @@ -819,191 +886,4 @@ void Draw_v2::spriteOperation(int16 operation) { } } -void Draw_v2::blitCursor(void) { - if (_cursorIndex == -1) - return; - - _showCursor = (_showCursor & ~2) | ((_showCursor & 1) << 1); -} - -void Draw_v2::animateCursor(int16 cursor) { - int16 newX = 0; - int16 newY = 0; - Game::Collision *ptr; - int16 minX; - int16 minY; - int16 maxX; - int16 maxY; - int16 cursorIndex; - uint16 hotspotX = 0; - uint16 hotspotY = 0; - - _showCursor |= 1; - - // .-- _draw_animateCursorSUB1 --- - cursorIndex = cursor; - if (cursorIndex == -1) { - cursorIndex = 0; - for (ptr = _vm->_game->_collisionAreas; ptr->left != -1; ptr++) { - if ((ptr->flags & 0xF00) || (ptr->id & 0x4000)) - continue; - - if (ptr->left > _vm->_global->_inter_mouseX) - continue; - - if (ptr->right < _vm->_global->_inter_mouseX) - continue; - - if (ptr->top > _vm->_global->_inter_mouseY) - continue; - - if (ptr->bottom < _vm->_global->_inter_mouseY) - continue; - - if ((ptr->flags & 0xF000) == 0) { - if ((ptr->flags & 0xF) >= 3) { - cursorIndex = 3; - break; - } else if (((ptr->flags & 0xF0) != 0x10) && (cursorIndex == 0)) - cursorIndex = 1; - } else if (cursorIndex == 0) - cursorIndex = (ptr->flags >> 12) & 0xF; - } - if (_cursorAnimLow[cursorIndex] == -1) - cursorIndex = 1; - } - // '------ - - if (_cursorAnimLow[cursorIndex] != -1) { - // .-- _draw_animateCursorSUB2 --- - if (cursorIndex == _cursorIndex) { - if ((_cursorAnimDelays[_cursorIndex] != 0) && - ((_cursorTimeKey + (_cursorAnimDelays[_cursorIndex] * 10)) <= - _vm->_util->getTimeKey())) { - _cursorAnim++; - if ((_cursorAnimHigh[_cursorIndex] < _cursorAnim) || - (_cursorAnimLow[_cursorIndex] > _cursorAnim)) - _cursorAnim = _cursorAnimLow[_cursorIndex]; - _cursorTimeKey = _vm->_util->getTimeKey(); - } else { - if ((_noInvalidated != 0) && (_vm->_global->_inter_mouseX == _cursorX) && - (_vm->_global->_inter_mouseY == _cursorY)) { - _vm->_video->waitRetrace(_vm->_global->_videoMode); - return; - } - } - } else { - _cursorIndex = cursorIndex; - if (_cursorAnimDelays[cursorIndex] != 0) { - _cursorAnim = _cursorAnimLow[cursorIndex]; - _cursorTimeKey = _vm->_util->getTimeKey(); - } - } - - if (_cursorAnimDelays[_cursorIndex] != 0) { - if ((_cursorAnimHigh[_cursorIndex] < _cursorAnim) || - (_cursorAnimLow[_cursorIndex] > _cursorAnim)) - _cursorAnim = _cursorAnimLow[_cursorIndex]; - - cursorIndex = _cursorAnim; - } - // '------ - - newX = _vm->_global->_inter_mouseX; - newY = _vm->_global->_inter_mouseY; - if (_cursorXDeltaVar != -1) { - newX -= hotspotX = (uint16) VAR(_cursorIndex + _cursorXDeltaVar); - newY -= hotspotY = (uint16) VAR(_cursorIndex + _cursorYDeltaVar); - } - - minX = MIN(newX, _cursorX); - minY = MIN(newY, _cursorY); - maxX = MAX(_cursorX, newX) + _cursorWidth - 1; - maxY = MAX(_cursorY, newY) + _cursorHeight - 1; - - _vm->_video->clearSurf(_scummvmCursor); - _vm->_video->drawSprite(_cursorSprites, _scummvmCursor, cursorIndex * _cursorWidth, - 0, (cursorIndex * _cursorWidth) + _cursorWidth - 1, _cursorHeight - 1, 0, 0, 0); - CursorMan.replaceCursor(_scummvmCursor->vidPtr, _cursorWidth, _cursorHeight, - hotspotX, hotspotY, 0); - - if (_frontSurface != _backSurface) { - if (_noInvalidated == 0) { - int16 tmp = _cursorIndex; - _cursorIndex = -1; - blitInvalidated(); - _cursorIndex = tmp; - } else { - _showCursor = 3; - _vm->_video->waitRetrace(_vm->_global->_videoMode); - if (minY < 50) - _vm->_util->delay(5); - } - } - } else - blitCursor(); - - _showCursor &= ~1; - - _cursorX = newX; - _cursorY = newY; -} - -void Draw_v2::initScreen(void) { - _scrollOffsetX = 0; - _scrollOffsetY = 0; - - if (_word_2E51F != 0) { - _off_2E51B = new Video::SurfaceDesc; - memcpy(_off_2E51B, _frontSurface, sizeof(Video::SurfaceDesc)); - _off_2E51B->height = _vm->_global->_primaryHeight - _word_2E51F; - _frontSurface->height -= _off_2E51B->height; - _frontSurface->vidPtr = - _off_2E51B->vidPtr + ((_off_2E51B->width * _off_2E51B->height) / 4); - - _off_2E517 = new Video::SurfaceDesc; - memcpy(_off_2E517, _off_2E51B, sizeof(Video::SurfaceDesc)); - _off_2E517->width = _vm->_global->_primaryWidth; - _off_2E517->vidPtr = _frontSurface->vidPtr + - ((_frontSurface->width * _frontSurface->height ) / 4); - } - initBigSprite(21, _vm->_video->_surfWidth, _vm->_video->_surfHeight, 0); - _backSurface = _spritesArray[21]; - _vm->_video->clearSurf(_backSurface); - - initBigSprite(23, 32, 16, 2); - _cursorSpritesBack = _spritesArray[23]; - _cursorSprites = _cursorSpritesBack; - _scummvmCursor = - _vm->_video->initSurfDesc(_vm->_global->_videoMode, 16, 16, SCUMMVM_CURSOR); - - _spritesArray[20] = _frontSurface; - _spritesArray[21] = _backSurface; - -/* if (_word_2E51F != 0) { - dword_2F92D = _off_2E51B; - dword_2F931 = _off_2E517; - }*/ -} - -void Draw_v2::closeScreen(void) { - freeSprite(23); - _cursorSprites = 0; - _cursorSpritesBack = 0; - _vm->_video->freeSurfDesc(_scummvmCursor); - _scummvmCursor = 0; - if (_off_2E51B != 0) { - memcpy(_frontSurface, _off_2E51B, sizeof(Video::SurfaceDesc)); - _frontSurface->width = _vm->_video->_surfWidth; - _frontSurface->height = _vm->_video->_surfHeight; - delete _off_2E51B; - delete _off_2E517; - _off_2E51B = 0; - _off_2E517 = 0; - } - if (_frontSurface != _backSurface) - freeSprite(21); - _spritesArray[21] = 0; -} - } // End of namespace Gob |