diff options
Diffstat (limited to 'engines/kyra/animator_v2.cpp')
-rw-r--r-- | engines/kyra/animator_v2.cpp | 339 |
1 files changed, 26 insertions, 313 deletions
diff --git a/engines/kyra/animator_v2.cpp b/engines/kyra/animator_v2.cpp index 8efbdbe747..af22056eee 100644 --- a/engines/kyra/animator_v2.cpp +++ b/engines/kyra/animator_v2.cpp @@ -24,37 +24,23 @@ */ #include "kyra/kyra_v2.h" +#include "kyra/screen_v2.h" #include "kyra/wsamovie.h" #include "common/endian.h" namespace Kyra { -void KyraEngine_v2::clearAnimObjects() { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::clearAnimObjects()"); - memset(_animObjects, 0, sizeof(_animObjects)); - - _animObjects[0].index = 0; - _animObjects[0].type = 0; - _animObjects[0].enabled = 1; - _animObjects[0].flags = 0x800; - _animObjects[0].width = 32; - _animObjects[0].height = 49; - _animObjects[0].width2 = 4; - _animObjects[0].height2 = 10; - - for (int i = 1; i < 11; ++i) { - _animObjects[i].index = i; - _animObjects[i].type = 2; - } +void KyraEngine_v2::allocAnimObjects(int actors, int anims, int items) { + debugC(9, kDebugLevelAnimator, "KyraEngine_v2::allocAnimObjects(%d, %d, %d)", actors, anims, items); + _animObjects = new AnimObj[actors+anims+items]; + assert(_animObjects); - for (int i = 11; i <= 40; ++i) { - _animObjects[i].index = i; - _animObjects[i].type = 1; - _animObjects[i].flags = 0x800; - _animObjects[i].width = 16; - _animObjects[i].height = 16; - } + memset(_animObjects, 0, sizeof(AnimObj)*(actors+anims+items)); + + _animActor = _animObjects; + _animAnims = _animObjects + actors; + _animItems = _animObjects + actors + anims; } KyraEngine_v2::AnimObj *KyraEngine_v2::initAnimList(AnimObj *list, AnimObj *entry) { @@ -136,65 +122,6 @@ KyraEngine_v2::AnimObj *KyraEngine_v2::deleteAnimListEntry(AnimObj *list, AnimOb return list; } -void KyraEngine_v2::drawAnimObjects() { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::drawAnimObjects()"); - for (AnimObj *curObject = _animList; curObject; curObject = curObject->nextObject) { - if (!curObject->enabled) - continue; - - int x = curObject->xPos2 - (_screen->getScreenDim(2)->sx << 3); - int y = curObject->yPos2 - _screen->getScreenDim(2)->sy; - int layer = 7; - - if (curObject->flags & 0x800) { - if (curObject->animFlags) - layer = 0; - else - layer = getDrawLayer(curObject->xPos1, curObject->yPos1); - } - curObject->flags |= 0x800; - - if (curObject->index) - drawSceneAnimObject(curObject, x, y, layer); - else - drawCharacterAnimObject(curObject, x, y, layer); - } -} - -void KyraEngine_v2::refreshAnimObjects(int force) { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::refreshAnimObjects(%d)", force); - for (AnimObj *curObject = _animList; curObject; curObject = curObject->nextObject) { - if (!curObject->enabled) - continue; - if (!curObject->needRefresh && !force) - continue; - - int x = curObject->xPos2 - curObject->width2; - if (x < 0) - x = 0; - if (x >= 320) - x = 319; - int y = curObject->yPos2 - curObject->height2; - if (y < 0) - y = 0; - if (y >= 143) - y = 142; - - int width = curObject->width + curObject->width2 + 8; - int height = curObject->height + curObject->height2*2; - if (width + x > 320) - width -= width + x - 322; - if (height + y > 143) - height -= height + y - 144; - - _screen->hideMouse(); - _screen->copyRegion(x, y, x, y, width, height, 2, 0, Screen::CR_NO_P_CHECK); - _screen->showMouse(); - - curObject->needRefresh = false; - } -} - void KyraEngine_v2::refreshAnimObjectsIfNeed() { debugC(9, kDebugLevelAnimator, "KyraEngine_v2::refreshAnimObjectsIfNeed()"); for (AnimObj *curEntry = _animList; curEntry; curEntry = curEntry->nextObject) { @@ -202,256 +129,62 @@ void KyraEngine_v2::refreshAnimObjectsIfNeed() { restorePage3(); drawAnimObjects(); refreshAnimObjects(0); - _screen->updateScreen(); + screen()->updateScreen(); return; } } } -void KyraEngine_v2::updateItemAnimations() { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::updateItemAnimations()"); - bool nextFrame = false; - - if (_itemAnimData[0].itemIndex == -1 || _inventorySaved) - return; - - const ItemAnimData_v2 *s = &_itemAnimData[_nextAnimItem]; - ActiveItemAnim *a = &_activeItemAnim[_nextAnimItem]; - - if (++_nextAnimItem == 14) { - _nextAnimItem = 0; - return; - } - - uint32 ctime = _system->getMillis(); - if (ctime < a->nextFrame) - return; - - uint16 shpIdx = s->frames[a->currentFrame].index + 64; - if ((s->itemIndex == _handItemSet || s->itemIndex == _itemInHand) && (!_mouseState && _screen->isMouseVisible())) { - nextFrame = true; - _screen->setMouseCursor(8, 15, getShapePtr(shpIdx)); - } - - for (int i = 0; i < 10; i++) { - if (s->itemIndex == _mainCharacter.inventory[i]) { - nextFrame = true; - _screen->drawShape(2, _defaultShapeTable[240 + i], 304, 184, 0, 0); - _screen->drawShape(2, getShapePtr(shpIdx), 304, 184, 0, 0); - _screen->copyRegion(304, 184, _inventoryX[i], _inventoryY[i], 16, 16, 2, 0); - } - } - - _screen->updateScreen(); - - for (int i = 11; i < 40; i++) { - AnimObj *animObject = &_animObjects[i]; - if (animObject->shapeIndex2 == s->itemIndex + 64) { - if (s->itemIndex == 121) { - int f = findItem(_mainCharacter.sceneId, 121); - int nx = _itemList[f].x - 4; - if (nx > 12) { - if (lineIsPassable(nx, _itemList[f].y)) { - animObject->xPos2 -= 4; - _itemList[f].x -= 4; - } - } - } - animObject->shapePtr = _defaultShapeTable[shpIdx]; - animObject->shapeIndex1 = shpIdx; - animObject->needRefresh = 1; - nextFrame = true; - } - } - - if (nextFrame) { - a->nextFrame = _system->getMillis() + (s->frames[a->currentFrame].delay * _tickLength); - a->currentFrame = ++a->currentFrame % s->numFrames; - } -} - void KyraEngine_v2::flagAnimObjsForRefresh() { debugC(9, kDebugLevelAnimator, "KyraEngine_v2::flagAnimObjsForRefresh()"); for (AnimObj *curEntry = _animList; curEntry; curEntry = curEntry->nextObject) curEntry->needRefresh = 1; } -void KyraEngine_v2::flagAnimObjsUnk8() { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::flagAnimObjsUnk8()"); +void KyraEngine_v2::flagAnimObjsSpecialRefresh() { + debugC(9, kDebugLevelAnimator, "KyraEngine_v2::flagAnimObjsSpecialRefresh()"); for (AnimObj *curEntry = _animList; curEntry; curEntry = curEntry->nextObject) - curEntry->unk8 = 1; -} - -void KyraEngine_v2::updateCharFacing() { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::updateCharFacing()"); - if (_mainCharacter.x1 > _mouseX) - _mainCharacter.facing = 5; - else - _mainCharacter.facing = 3; - - _mainCharacter.animFrame = _characterFrameTable[_mainCharacter.facing]; - updateCharacterAnim(0); - refreshAnimObjectsIfNeed(); -} - -void KyraEngine_v2::updateCharacterAnim(int) { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::updateCharacterAnim(-)"); - Character *c = &_mainCharacter; - AnimObj *animState = _animObjects; - - animState->needRefresh = 1; - animState->unk8 = 1; - - if (c->facing >= 1 && c->facing <= 3) - animState->flags |= 1; - else if (c->facing >= 5 && c->facing <= 7) - animState->flags &= ~1; - - animState->xPos2 = animState->xPos1 = c->x1; - animState->yPos2 = animState->yPos1 = c->y1; - animState->shapePtr = _defaultShapeTable[c->animFrame]; - animState->shapeIndex1 = animState->shapeIndex2 = c->animFrame; - - int xAdd = _shapeDescTable[c->animFrame-9].xAdd; - int yAdd = _shapeDescTable[c->animFrame-9].yAdd; - - _charScaleX = _charScaleY = getScale(c->x1, c->y1); - - animState->xPos2 += (xAdd * _charScaleX) >> 8; - animState->yPos2 += (yAdd * _charScaleY) >> 8; - animState->width2 = 8; - animState->height2 = 10; - - _animList = deleteAnimListEntry(_animList, animState); - if (_animList) - _animList = addToAnimListSorted(_animList, animState); - else - _animList = initAnimList(_animList, animState); - - updateCharPal(1); -} - -void KyraEngine_v2::updateSceneAnim(int anim, int newFrame) { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::updateSceneAnim(%d, %d)", anim, newFrame); - AnimObj *animObject = &_animObjects[1+anim]; - if (!animObject->enabled) - return; - - animObject->needRefresh = 1; - animObject->unk8 = 1; - animObject->flags = 0; - - if (_sceneAnims[anim].flags & 2) - animObject->flags |= 0x800; - else - animObject->flags &= ~0x800; - - if (_sceneAnims[anim].flags & 4) - animObject->flags |= 1; - else - animObject->flags &= ~1; - - if (_sceneAnims[anim].flags & 0x20) { - animObject->shapePtr = _sceneShapeTable[newFrame]; - animObject->shapeIndex2 = 0xFFFF; - animObject->shapeIndex3 = 0xFFFF; - animObject->animNum = 0xFFFF; - } else { - animObject->shapePtr = 0; - animObject->shapeIndex3 = newFrame; - animObject->animNum = anim; - } - - animObject->xPos1 = _sceneAnims[anim].x; - animObject->yPos1 = _sceneAnims[anim].y; - animObject->xPos2 = _sceneAnims[anim].x2; - animObject->yPos2 = _sceneAnims[anim].y2; - - if (_sceneAnims[anim].flags & 2) { - _animList = deleteAnimListEntry(_animList, animObject); - if (!_animList) - _animList = initAnimList(_animList, animObject); - else - _animList = addToAnimListSorted(_animList, animObject); - } -} - -void KyraEngine_v2::drawSceneAnimObject(AnimObj *obj, int x, int y, int layer) { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::drawSceneAnimObject(%p, %d, %d, %d)", (const void*)obj, x, y, layer); - if (obj->type == 1) { - if (obj->shapeIndex1 == 0xFFFF) - return; - int scale = getScale(obj->xPos1, obj->yPos1); - _screen->drawShape(2, getShapePtr(obj->shapeIndex1), x, y, 2, obj->flags | 4, layer, scale, scale); - return; - } - - if (obj->shapePtr) { - _screen->drawShape(2, obj->shapePtr, x, y, 2, obj->flags, layer); - } else { - if (obj->shapeIndex3 == 0xFFFF || obj->animNum == 0xFFFF) - return; - - int flags = 0x4000; - if (obj->flags & 0x800) - flags |= 0x8000; - - if (_sceneAnims[obj->animNum].wsaFlag) { - x = y = 0; - } else { - x = obj->xPos2; - y = obj->yPos2; - } - - _sceneAnimMovie[obj->animNum]->setX(x); - _sceneAnimMovie[obj->animNum]->setY(y); - _sceneAnimMovie[obj->animNum]->setDrawPage(2); - _sceneAnimMovie[obj->animNum]->displayFrame(obj->shapeIndex3, int(flags | layer), 0, 0); - } -} - -void KyraEngine_v2::drawCharacterAnimObject(AnimObj *obj, int x, int y, int layer) { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::drawCharacterAnimObject(%p, %d, %d, %d)", (const void*)obj, x, y, layer); - if (_drawNoShapeFlag || obj->shapeIndex1 == 0xFFFF) - return; - _screen->drawShape(2, getShapePtr(obj->shapeIndex1), x, y, 2, obj->flags | 4, layer, _charScaleX, _charScaleY); + curEntry->specialRefresh = 1; } void KyraEngine_v2::addItemToAnimList(int item) { debugC(9, kDebugLevelAnimator, "KyraEngine_v2::addItemToAnimList(%d)", item); + assert(item < _itemListSize); + restorePage3(); - AnimObj *animObj = &_animObjects[11+item]; + AnimObj *animObj = _animItems + item; animObj->enabled = 1; animObj->needRefresh = 1; - animObj->unk8 = 1; int itemId = _itemList[item].id; animObj->xPos2 = animObj->xPos1 = _itemList[item].x; animObj->yPos2 = animObj->yPos1 = _itemList[item].y; - animObj->shapePtr = _defaultShapeTable[64+itemId]; - animObj->shapeIndex2 = animObj->shapeIndex1 = 64+itemId; + animObj->shapePtr = getShapePtr(itemId + _desc.itemShapeStart); + animSetupPaletteEntry(animObj); + animObj->shapeIndex2 = animObj->shapeIndex1 = itemId + _desc.itemShapeStart; int scaleY, scaleX; scaleY = scaleX = getScale(animObj->xPos1, animObj->yPos1); - uint8 *shapePtr = getShapePtr(64+itemId); - animObj->xPos3 = (animObj->xPos2 -= (_screen->getShapeScaledWidth(shapePtr, scaleX) >> 1)); - animObj->yPos3 = (animObj->yPos2 -= _screen->getShapeScaledHeight(shapePtr, scaleY)); + uint8 *shapePtr = getShapePtr(itemId + _desc.itemShapeStart); + animObj->xPos3 = (animObj->xPos2 -= (screen_v2()->getShapeScaledWidth(shapePtr, scaleX) >> 1)); + animObj->yPos3 = (animObj->yPos2 -= screen_v2()->getShapeScaledHeight(shapePtr, scaleY)); animObj->width2 = animObj->height2 = 0; _animList = addToAnimListSorted(_animList, animObj); animObj->needRefresh = 1; - animObj->unk8 = 1; } void KyraEngine_v2::deleteItemAnimEntry(int item) { debugC(9, kDebugLevelAnimator, "KyraEngine_v2::deleteItemAnimEntry(%d)", item); - AnimObj *animObj = &_animObjects[11+item]; + assert(item < _itemListSize); + + AnimObj *animObj = _animItems + item; restorePage3(); @@ -459,7 +192,6 @@ void KyraEngine_v2::deleteItemAnimEntry(int item) { animObj->shapeIndex1 = 0xFFFF; animObj->shapeIndex2 = 0xFFFF; animObj->needRefresh = 1; - animObj->unk8 = 1; refreshAnimObjectsIfNeed(); @@ -467,24 +199,5 @@ void KyraEngine_v2::deleteItemAnimEntry(int item) { _animList = deleteAnimListEntry(_animList, animObj); } -void KyraEngine_v2::setCharacterAnimDim(int w, int h) { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::setCharacterAnimDim(%d, %d)", w, h); - restorePage3(); - - _animObj0Width = _animObjects[0].width; - _animObj0Height = _animObjects[0].height; - - _animObjects[0].width = w; - _animObjects[0].height = h; -} - -void KyraEngine_v2::resetCharacterAnimDim() { - debugC(9, kDebugLevelAnimator, "KyraEngine_v2::resetCharacterAnimDim()"); - restorePage3(); - - _animObjects[0].width = _animObj0Width; - _animObjects[0].height = _animObj0Height; -} - } // end of namespace Kyra |