2009-10-13 15:28:27 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/util.h"
|
|
|
|
#include "common/stack.h"
|
|
|
|
#include "graphics/primitives.h"
|
|
|
|
|
|
|
|
#include "sci/sci.h"
|
|
|
|
#include "sci/engine/state.h"
|
2010-01-29 11:03:54 +00:00
|
|
|
#include "sci/engine/selector.h"
|
2009-10-19 13:26:13 +00:00
|
|
|
#include "sci/engine/vm.h"
|
2010-01-31 12:35:15 +00:00
|
|
|
#include "sci/graphics/cache.h"
|
2010-01-31 15:07:36 +00:00
|
|
|
#include "sci/graphics/cursor.h"
|
2010-01-31 12:35:15 +00:00
|
|
|
#include "sci/graphics/ports.h"
|
|
|
|
#include "sci/graphics/paint16.h"
|
2010-01-05 01:37:57 +00:00
|
|
|
#include "sci/graphics/view.h"
|
|
|
|
#include "sci/graphics/screen.h"
|
|
|
|
#include "sci/graphics/transitions.h"
|
|
|
|
#include "sci/graphics/animate.h"
|
2009-10-13 15:28:27 +00:00
|
|
|
|
|
|
|
namespace Sci {
|
|
|
|
|
2010-04-24 21:45:17 +00:00
|
|
|
GfxAnimate::GfxAnimate(EngineState *state, GfxCache *cache, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen, GfxPalette *palette, GfxCursor *cursor, GfxTransitions *transitions)
|
|
|
|
: _s(state), _cache(cache), _ports(ports), _paint16(paint16), _screen(screen), _palette(palette), _cursor(cursor), _transitions(transitions) {
|
2009-10-13 15:28:27 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
GfxAnimate::~GfxAnimate() {
|
2010-01-03 19:37:43 +00:00
|
|
|
free(_listData);
|
|
|
|
free(_lastCastData);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::init() {
|
2009-10-13 15:28:27 +00:00
|
|
|
_listData = NULL;
|
2009-10-30 09:26:14 +00:00
|
|
|
_listCount = 0;
|
|
|
|
_lastCastData = NULL;
|
|
|
|
_lastCastCount = 0;
|
2009-10-21 20:57:42 +00:00
|
|
|
|
|
|
|
_ignoreFastCast = false;
|
2009-10-21 21:07:21 +00:00
|
|
|
// fastCast object is not found in any SCI games prior SCI1
|
2009-10-21 20:57:42 +00:00
|
|
|
if (getSciVersion() <= SCI_VERSION_01)
|
|
|
|
_ignoreFastCast = true;
|
2009-10-21 21:07:21 +00:00
|
|
|
// Also if fastCast object exists at gamestartup, we can assume that the interpreter doesnt do kAnimate aborts
|
2010-06-13 22:01:10 +00:00
|
|
|
// (found in Larry 1)
|
|
|
|
if (getSciVersion() > SCI_VERSION_0_EARLY) {
|
|
|
|
if (!_s->_segMan->findObjectByName("fastCast").isNull())
|
|
|
|
_ignoreFastCast = true;
|
|
|
|
}
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::disposeLastCast() {
|
2009-10-30 09:26:14 +00:00
|
|
|
_lastCastCount = 0;
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
bool GfxAnimate::invoke(List *list, int argc, reg_t *argv) {
|
2009-10-13 15:28:27 +00:00
|
|
|
reg_t curAddress = list->first;
|
|
|
|
Node *curNode = _s->_segMan->lookupNode(curAddress);
|
|
|
|
reg_t curObject;
|
|
|
|
uint16 signal;
|
|
|
|
|
|
|
|
while (curNode) {
|
|
|
|
curObject = curNode->value;
|
2009-10-19 14:33:48 +00:00
|
|
|
|
2009-10-21 20:57:42 +00:00
|
|
|
if (!_ignoreFastCast) {
|
|
|
|
// Check if the game has a fastCast object set
|
|
|
|
// if we don't abort kAnimate processing, at least in kq5 there will be animation cels drawn into speech boxes.
|
2010-06-09 09:17:48 +00:00
|
|
|
if (!_s->variables[VAR_GLOBAL][84].isNull()) {
|
|
|
|
if (!strcmp(_s->_segMan->getObjectName(_s->variables[VAR_GLOBAL][84]), "fastCast"))
|
2009-10-21 20:57:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-10-19 14:33:48 +00:00
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
signal = readSelectorValue(_s->_segMan, curObject, SELECTOR(signal));
|
2009-10-21 19:19:03 +00:00
|
|
|
if (!(signal & kSignalFrozen)) {
|
2009-10-13 15:28:27 +00:00
|
|
|
// Call .doit method of that object
|
2010-06-10 09:18:57 +00:00
|
|
|
invokeSelector(_s, curObject, SELECTOR(doit), argc, argv, 0);
|
2009-10-13 15:28:27 +00:00
|
|
|
// Lookup node again, since the nodetable it was in may have been reallocated
|
|
|
|
curNode = _s->_segMan->lookupNode(curAddress);
|
|
|
|
}
|
2010-04-16 12:58:14 +00:00
|
|
|
|
|
|
|
if (curNode) {
|
|
|
|
curAddress = curNode->succ;
|
|
|
|
curNode = _s->_segMan->lookupNode(curAddress);
|
|
|
|
}
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
2009-10-19 13:26:13 +00:00
|
|
|
return true;
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:37:57 +00:00
|
|
|
bool sortHelper(const AnimateEntry* entry1, const AnimateEntry* entry2) {
|
2010-05-24 15:39:30 +00:00
|
|
|
if (entry1->y == entry2->y) {
|
|
|
|
// if both y and z are the same, use the order we were given originally
|
|
|
|
// this is needed for special cases like iceman room 35
|
|
|
|
if (entry1->z == entry2->z)
|
|
|
|
return entry1->givenOrderNo < entry2->givenOrderNo;
|
|
|
|
else
|
|
|
|
return entry1->z < entry2->z;
|
|
|
|
}
|
|
|
|
return entry1->y < entry2->y;
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::makeSortedList(List *list) {
|
2009-10-13 15:28:27 +00:00
|
|
|
reg_t curAddress = list->first;
|
|
|
|
Node *curNode = _s->_segMan->lookupNode(curAddress);
|
|
|
|
reg_t curObject;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateEntry *listEntry;
|
2009-10-13 15:28:27 +00:00
|
|
|
int16 listNr, listCount = 0;
|
|
|
|
|
|
|
|
// Count the list entries
|
|
|
|
while (curNode) {
|
|
|
|
listCount++;
|
|
|
|
curAddress = curNode->succ;
|
|
|
|
curNode = _s->_segMan->lookupNode(curAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
_list.clear();
|
|
|
|
|
|
|
|
// No entries -> exit immediately
|
|
|
|
if (listCount == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Adjust list size, if needed
|
2009-10-30 09:26:14 +00:00
|
|
|
if ((_listData == NULL) || (_listCount < listCount)) {
|
2010-01-03 19:37:43 +00:00
|
|
|
free(_listData);
|
2010-01-05 01:37:57 +00:00
|
|
|
_listData = (AnimateEntry *)malloc(listCount * sizeof(AnimateEntry));
|
2009-10-13 15:28:27 +00:00
|
|
|
if (!_listData)
|
2009-10-30 09:26:14 +00:00
|
|
|
error("Could not allocate memory for _listData");
|
|
|
|
_listCount = listCount;
|
|
|
|
|
2010-01-03 19:37:43 +00:00
|
|
|
free(_lastCastData);
|
2010-01-05 01:37:57 +00:00
|
|
|
_lastCastData = (AnimateEntry *)malloc(listCount * sizeof(AnimateEntry));
|
2009-10-30 09:26:14 +00:00
|
|
|
if (!_lastCastData)
|
|
|
|
error("Could not allocate memory for _lastCastData");
|
|
|
|
_lastCastCount = 0;
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fill the list
|
|
|
|
curAddress = list->first;
|
|
|
|
curNode = _s->_segMan->lookupNode(curAddress);
|
|
|
|
listEntry = _listData;
|
|
|
|
for (listNr = 0; listNr < listCount; listNr++) {
|
|
|
|
curObject = curNode->value;
|
|
|
|
listEntry->object = curObject;
|
|
|
|
|
|
|
|
// Get data from current object
|
2010-05-24 15:39:30 +00:00
|
|
|
listEntry->givenOrderNo = listNr;
|
2010-05-29 23:37:15 +00:00
|
|
|
listEntry->viewId = readSelectorValue(_s->_segMan, curObject, SELECTOR(view));
|
|
|
|
listEntry->loopNo = readSelectorValue(_s->_segMan, curObject, SELECTOR(loop));
|
|
|
|
listEntry->celNo = readSelectorValue(_s->_segMan, curObject, SELECTOR(cel));
|
|
|
|
listEntry->paletteNo = readSelectorValue(_s->_segMan, curObject, SELECTOR(palette));
|
|
|
|
listEntry->x = readSelectorValue(_s->_segMan, curObject, SELECTOR(x));
|
|
|
|
listEntry->y = readSelectorValue(_s->_segMan, curObject, SELECTOR(y));
|
|
|
|
listEntry->z = readSelectorValue(_s->_segMan, curObject, SELECTOR(z));
|
|
|
|
listEntry->priority = readSelectorValue(_s->_segMan, curObject, SELECTOR(priority));
|
|
|
|
listEntry->signal = readSelectorValue(_s->_segMan, curObject, SELECTOR(signal));
|
2010-01-15 21:13:33 +00:00
|
|
|
if (getSciVersion() >= SCI_VERSION_1_1) {
|
|
|
|
// Cel scaling
|
2010-05-29 23:37:15 +00:00
|
|
|
listEntry->scaleSignal = readSelectorValue(_s->_segMan, curObject, SELECTOR(scaleSignal));
|
2010-01-15 21:32:18 +00:00
|
|
|
if (listEntry->scaleSignal & kScaleSignalDoScaling) {
|
2010-05-29 23:37:15 +00:00
|
|
|
listEntry->scaleX = readSelectorValue(_s->_segMan, curObject, SELECTOR(scaleX));
|
|
|
|
listEntry->scaleY = readSelectorValue(_s->_segMan, curObject, SELECTOR(scaleY));
|
2010-01-15 21:32:18 +00:00
|
|
|
} else {
|
|
|
|
listEntry->scaleX = 128;
|
|
|
|
listEntry->scaleY = 128;
|
|
|
|
}
|
2010-01-16 19:44:33 +00:00
|
|
|
// TODO
|
|
|
|
// On scaleSignal bit 1 sierra sci does some stuff with global var 2, current Port
|
|
|
|
// and some other stuff and sets scaleX/Y accordingly. It seems this functionality is needed in at
|
|
|
|
// least sq5 right when starting the game before wilco exists the room. Currently we dont get scaling
|
|
|
|
// but sierra sci does scaling there. I dont fully understand the code yet, that's why i didnt implement
|
|
|
|
// anything.
|
2010-01-15 21:13:33 +00:00
|
|
|
} else {
|
|
|
|
listEntry->scaleSignal = 0;
|
|
|
|
listEntry->scaleX = 128;
|
|
|
|
listEntry->scaleY = 128;
|
|
|
|
}
|
2009-10-13 15:28:27 +00:00
|
|
|
// listEntry->celRect is filled in AnimateFill()
|
|
|
|
listEntry->showBitsFlag = false;
|
|
|
|
|
|
|
|
_list.push_back(listEntry);
|
|
|
|
|
|
|
|
listEntry++;
|
|
|
|
curAddress = curNode->succ;
|
|
|
|
curNode = _s->_segMan->lookupNode(curAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now sort the list according y and z (descending)
|
|
|
|
Common::sort(_list.begin(), _list.end(), sortHelper);
|
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::fill(byte &old_picNotValid) {
|
2009-10-13 15:28:27 +00:00
|
|
|
reg_t curObject;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateEntry *listEntry;
|
2009-10-13 15:28:27 +00:00
|
|
|
uint16 signal;
|
2010-02-04 22:17:58 +00:00
|
|
|
GfxView *view = NULL;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateList::iterator listIterator;
|
|
|
|
AnimateList::iterator listEnd = _list.end();
|
2009-10-13 15:28:27 +00:00
|
|
|
|
|
|
|
listIterator = _list.begin();
|
|
|
|
while (listIterator != listEnd) {
|
|
|
|
listEntry = *listIterator;
|
|
|
|
curObject = listEntry->object;
|
|
|
|
|
|
|
|
// Get the corresponding view
|
2010-01-31 12:35:15 +00:00
|
|
|
view = _cache->getView(listEntry->viewId);
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-13 15:28:27 +00:00
|
|
|
// adjust loop and cel, if any of those is invalid
|
|
|
|
if (listEntry->loopNo >= view->getLoopCount()) {
|
|
|
|
listEntry->loopNo = 0;
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(loop), listEntry->loopNo);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
if (listEntry->celNo >= view->getCelCount(listEntry->loopNo)) {
|
|
|
|
listEntry->celNo = 0;
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(cel), listEntry->celNo);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create rect according to coordinates and given cel
|
2010-01-16 16:17:45 +00:00
|
|
|
if (listEntry->scaleSignal & kScaleSignalDoScaling) {
|
|
|
|
view->getCelScaledRect(listEntry->loopNo, listEntry->celNo, listEntry->x, listEntry->y, listEntry->z, listEntry->scaleX, listEntry->scaleY, &listEntry->celRect);
|
|
|
|
} else {
|
|
|
|
view->getCelRect(listEntry->loopNo, listEntry->celNo, listEntry->x, listEntry->y, listEntry->z, &listEntry->celRect);
|
|
|
|
}
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsLeft), listEntry->celRect.left);
|
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsTop), listEntry->celRect.top);
|
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsRight), listEntry->celRect.right);
|
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(nsBottom), listEntry->celRect.bottom);
|
2009-10-13 15:28:27 +00:00
|
|
|
|
|
|
|
signal = listEntry->signal;
|
|
|
|
|
|
|
|
// Calculate current priority according to y-coordinate
|
2009-10-21 19:19:03 +00:00
|
|
|
if (!(signal & kSignalFixedPriority)) {
|
2010-02-05 22:20:46 +00:00
|
|
|
listEntry->priority = _ports->kernelCoordinateToPriority(listEntry->y);
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(priority), listEntry->priority);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if (signal & kSignalNoUpdate) {
|
|
|
|
if (signal & (kSignalForceUpdate | kSignalViewUpdated)
|
|
|
|
|| (signal & kSignalHidden && !(signal & kSignalRemoveView))
|
|
|
|
|| (!(signal & kSignalHidden) && signal & kSignalRemoveView)
|
|
|
|
|| (signal & kSignalAlwaysUpdate))
|
2009-10-13 15:28:27 +00:00
|
|
|
old_picNotValid++;
|
2009-10-21 19:19:03 +00:00
|
|
|
signal &= 0xFFFF ^ kSignalStopUpdate;
|
2009-10-13 15:28:27 +00:00
|
|
|
} else {
|
2009-10-21 19:19:03 +00:00
|
|
|
if (signal & kSignalStopUpdate || signal & kSignalAlwaysUpdate)
|
2009-10-13 15:28:27 +00:00
|
|
|
old_picNotValid++;
|
2009-10-21 19:19:03 +00:00
|
|
|
signal &= 0xFFFF ^ kSignalForceUpdate;
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
listEntry->signal = signal;
|
|
|
|
|
|
|
|
listIterator++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::update() {
|
2009-10-13 15:28:27 +00:00
|
|
|
reg_t curObject;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateEntry *listEntry;
|
2009-10-13 15:28:27 +00:00
|
|
|
uint16 signal;
|
|
|
|
reg_t bitsHandle;
|
|
|
|
Common::Rect rect;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateList::iterator listIterator;
|
|
|
|
AnimateList::iterator listBegin = _list.begin();
|
|
|
|
AnimateList::iterator listEnd = _list.end();
|
2009-10-13 15:28:27 +00:00
|
|
|
|
|
|
|
// Remove all no-update cels, if requested
|
|
|
|
listIterator = _list.reverse_begin();
|
|
|
|
while (listIterator != listEnd) {
|
|
|
|
listEntry = *listIterator;
|
|
|
|
curObject = listEntry->object;
|
|
|
|
signal = listEntry->signal;
|
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if (signal & kSignalNoUpdate) {
|
|
|
|
if (!(signal & kSignalRemoveView)) {
|
2010-05-29 23:37:15 +00:00
|
|
|
bitsHandle = readSelector(_s->_segMan, curObject, SELECTOR(underBits));
|
2009-10-13 15:28:27 +00:00
|
|
|
if (_screen->_picNotValid != 1) {
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->bitsRestore(bitsHandle);
|
2009-10-13 15:28:27 +00:00
|
|
|
listEntry->showBitsFlag = true;
|
|
|
|
} else {
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->bitsFree(bitsHandle);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(underBits), 0);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
2009-10-21 19:19:03 +00:00
|
|
|
signal &= 0xFFFF ^ kSignalForceUpdate;
|
|
|
|
signal &= signal & kSignalViewUpdated ? 0xFFFF ^ (kSignalViewUpdated | kSignalNoUpdate) : 0xFFFF;
|
|
|
|
} else if (signal & kSignalStopUpdate) {
|
|
|
|
signal = (signal & (0xFFFF ^ kSignalStopUpdate)) | kSignalNoUpdate;
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
listEntry->signal = signal;
|
|
|
|
listIterator--;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw always-update cels
|
|
|
|
listIterator = listBegin;
|
|
|
|
while (listIterator != listEnd) {
|
|
|
|
listEntry = *listIterator;
|
|
|
|
curObject = listEntry->object;
|
|
|
|
signal = listEntry->signal;
|
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if (signal & kSignalAlwaysUpdate) {
|
2009-10-13 15:28:27 +00:00
|
|
|
// draw corresponding cel
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo, listEntry->scaleX, listEntry->scaleY);
|
2009-10-13 15:28:27 +00:00
|
|
|
listEntry->showBitsFlag = true;
|
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
signal &= 0xFFFF ^ (kSignalStopUpdate | kSignalViewUpdated | kSignalNoUpdate | kSignalForceUpdate);
|
|
|
|
if ((signal & kSignalIgnoreActor) == 0) {
|
2009-10-13 15:28:27 +00:00
|
|
|
rect = listEntry->celRect;
|
2010-02-05 22:20:46 +00:00
|
|
|
rect.top = CLIP<int16>(_ports->kernelPriorityToCoordinate(listEntry->priority) - 1, rect.top, rect.bottom - 1);
|
2010-05-15 08:57:13 +00:00
|
|
|
_paint16->fillRect(rect, GFX_SCREEN_MASK_CONTROL, 0, 0, 15);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
listEntry->signal = signal;
|
|
|
|
}
|
|
|
|
listIterator++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Saving background for all NoUpdate-cels
|
|
|
|
listIterator = listBegin;
|
|
|
|
while (listIterator != listEnd) {
|
|
|
|
listEntry = *listIterator;
|
|
|
|
curObject = listEntry->object;
|
|
|
|
signal = listEntry->signal;
|
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if (signal & kSignalNoUpdate) {
|
|
|
|
if (signal & kSignalHidden) {
|
|
|
|
signal |= kSignalRemoveView;
|
2009-10-13 15:28:27 +00:00
|
|
|
} else {
|
2009-10-21 19:19:03 +00:00
|
|
|
signal &= 0xFFFF ^ kSignalRemoveView;
|
|
|
|
if (signal & kSignalIgnoreActor)
|
2010-05-15 08:57:13 +00:00
|
|
|
bitsHandle = _paint16->bitsSave(listEntry->celRect, GFX_SCREEN_MASK_VISUAL|GFX_SCREEN_MASK_PRIORITY);
|
2009-10-13 15:28:27 +00:00
|
|
|
else
|
2010-05-15 08:57:13 +00:00
|
|
|
bitsHandle = _paint16->bitsSave(listEntry->celRect, GFX_SCREEN_MASK_ALL);
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelector(_s->_segMan, curObject, SELECTOR(underBits), bitsHandle);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
listEntry->signal = signal;
|
|
|
|
}
|
|
|
|
listIterator++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw NoUpdate cels
|
|
|
|
listIterator = listBegin;
|
|
|
|
while (listIterator != listEnd) {
|
|
|
|
listEntry = *listIterator;
|
|
|
|
curObject = listEntry->object;
|
|
|
|
signal = listEntry->signal;
|
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if (signal & kSignalNoUpdate && !(signal & kSignalHidden)) {
|
2009-10-13 15:28:27 +00:00
|
|
|
// draw corresponding cel
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo, listEntry->scaleX, listEntry->scaleY);
|
2009-10-13 15:28:27 +00:00
|
|
|
listEntry->showBitsFlag = true;
|
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if ((signal & kSignalIgnoreActor) == 0) {
|
2009-10-13 15:28:27 +00:00
|
|
|
rect = listEntry->celRect;
|
2010-02-05 22:20:46 +00:00
|
|
|
rect.top = CLIP<int16>(_ports->kernelPriorityToCoordinate(listEntry->priority) - 1, rect.top, rect.bottom - 1);
|
2010-05-15 08:57:13 +00:00
|
|
|
_paint16->fillRect(rect, GFX_SCREEN_MASK_CONTROL, 0, 0, 15);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
listIterator++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::drawCels() {
|
2009-10-13 15:28:27 +00:00
|
|
|
reg_t curObject;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateEntry *listEntry;
|
|
|
|
AnimateEntry *lastCastEntry = _lastCastData;
|
2009-10-13 15:28:27 +00:00
|
|
|
uint16 signal;
|
|
|
|
reg_t bitsHandle;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateList::iterator listIterator;
|
|
|
|
AnimateList::iterator listEnd = _list.end();
|
2009-10-30 09:26:14 +00:00
|
|
|
_lastCastCount = 0;
|
|
|
|
|
2009-10-13 15:28:27 +00:00
|
|
|
listIterator = _list.begin();
|
|
|
|
while (listIterator != listEnd) {
|
|
|
|
listEntry = *listIterator;
|
|
|
|
curObject = listEntry->object;
|
|
|
|
signal = listEntry->signal;
|
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if (!(signal & (kSignalNoUpdate | kSignalHidden | kSignalAlwaysUpdate))) {
|
2009-10-13 15:28:27 +00:00
|
|
|
// Save background
|
2010-05-15 08:57:13 +00:00
|
|
|
bitsHandle = _paint16->bitsSave(listEntry->celRect, GFX_SCREEN_MASK_ALL);
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelector(_s->_segMan, curObject, SELECTOR(underBits), bitsHandle);
|
2009-10-13 15:28:27 +00:00
|
|
|
|
|
|
|
// draw corresponding cel
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo, listEntry->scaleX, listEntry->scaleY);
|
2009-10-13 15:28:27 +00:00
|
|
|
listEntry->showBitsFlag = true;
|
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if (signal & kSignalRemoveView) {
|
|
|
|
signal &= 0xFFFF ^ kSignalRemoveView;
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
listEntry->signal = signal;
|
2009-10-30 09:26:14 +00:00
|
|
|
|
|
|
|
// Remember that entry in lastCast
|
2010-01-05 01:37:57 +00:00
|
|
|
memcpy(lastCastEntry, listEntry, sizeof(AnimateEntry));
|
2009-10-30 09:26:14 +00:00
|
|
|
lastCastEntry++; _lastCastCount++;
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
listIterator++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::updateScreen(byte oldPicNotValid) {
|
2009-10-17 20:42:19 +00:00
|
|
|
reg_t curObject;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateEntry *listEntry;
|
2009-10-13 15:28:27 +00:00
|
|
|
uint16 signal;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateList::iterator listIterator;
|
|
|
|
AnimateList::iterator listEnd = _list.end();
|
2009-10-17 20:42:19 +00:00
|
|
|
Common::Rect lsRect;
|
|
|
|
Common::Rect workerRect;
|
2009-10-13 15:28:27 +00:00
|
|
|
|
|
|
|
listIterator = _list.begin();
|
|
|
|
while (listIterator != listEnd) {
|
|
|
|
listEntry = *listIterator;
|
2009-10-17 20:42:19 +00:00
|
|
|
curObject = listEntry->object;
|
2009-10-13 15:28:27 +00:00
|
|
|
signal = listEntry->signal;
|
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if (listEntry->showBitsFlag || !(signal & (kSignalRemoveView | kSignalNoUpdate) ||
|
|
|
|
(!(signal & kSignalRemoveView) && (signal & kSignalNoUpdate) && oldPicNotValid))) {
|
2010-05-29 23:37:15 +00:00
|
|
|
lsRect.left = readSelectorValue(_s->_segMan, curObject, SELECTOR(lsLeft));
|
|
|
|
lsRect.top = readSelectorValue(_s->_segMan, curObject, SELECTOR(lsTop));
|
|
|
|
lsRect.right = readSelectorValue(_s->_segMan, curObject, SELECTOR(lsRight));
|
|
|
|
lsRect.bottom = readSelectorValue(_s->_segMan, curObject, SELECTOR(lsBottom));
|
2009-10-17 20:42:19 +00:00
|
|
|
|
|
|
|
workerRect = lsRect;
|
|
|
|
workerRect.clip(listEntry->celRect);
|
|
|
|
|
|
|
|
if (!workerRect.isEmpty()) {
|
|
|
|
workerRect = lsRect;
|
|
|
|
workerRect.extend(listEntry->celRect);
|
|
|
|
} else {
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->bitsShow(lsRect);
|
2009-10-17 20:42:19 +00:00
|
|
|
workerRect = listEntry->celRect;
|
|
|
|
}
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(lsLeft), workerRect.left);
|
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(lsTop), workerRect.top);
|
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(lsRight), workerRect.right);
|
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(lsBottom), workerRect.bottom);
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->bitsShow(workerRect);
|
2009-10-17 20:42:19 +00:00
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if (signal & kSignalHidden) {
|
|
|
|
listEntry->signal |= kSignalRemoveView;
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
listIterator++;
|
|
|
|
}
|
2009-10-17 20:42:19 +00:00
|
|
|
// use this for debug purposes
|
|
|
|
// _screen->copyToScreen();
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::restoreAndDelete(int argc, reg_t *argv) {
|
2009-10-13 15:28:27 +00:00
|
|
|
reg_t curObject;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateEntry *listEntry;
|
2009-10-13 15:28:27 +00:00
|
|
|
uint16 signal;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateList::iterator listIterator;
|
|
|
|
AnimateList::iterator listEnd = _list.end();
|
2009-10-13 15:28:27 +00:00
|
|
|
|
2009-10-21 15:12:10 +00:00
|
|
|
|
|
|
|
// This has to be done in a separate loop. At least in sq1 some .dispose modifies FIXEDLOOP flag in signal for
|
|
|
|
// another object. In that case we would overwrite the new signal with our version of the old signal
|
|
|
|
listIterator = _list.begin();
|
|
|
|
while (listIterator != listEnd) {
|
|
|
|
listEntry = *listIterator;
|
|
|
|
curObject = listEntry->object;
|
|
|
|
signal = listEntry->signal;
|
|
|
|
|
|
|
|
// Finally update signal
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(signal), signal);
|
2009-10-21 15:12:10 +00:00
|
|
|
listIterator++;
|
|
|
|
}
|
|
|
|
|
2009-10-13 15:28:27 +00:00
|
|
|
listIterator = _list.reverse_begin();
|
|
|
|
while (listIterator != listEnd) {
|
|
|
|
listEntry = *listIterator;
|
|
|
|
curObject = listEntry->object;
|
2009-10-21 15:23:05 +00:00
|
|
|
// We read out signal here again, this is not by accident but to ensure that we got an up-to-date signal
|
2010-05-29 23:37:15 +00:00
|
|
|
signal = readSelectorValue(_s->_segMan, curObject, SELECTOR(signal));
|
2009-10-13 15:28:27 +00:00
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if ((signal & (kSignalNoUpdate | kSignalRemoveView)) == 0) {
|
2010-05-29 23:37:15 +00:00
|
|
|
_paint16->bitsRestore(readSelector(_s->_segMan, curObject, SELECTOR(underBits)));
|
|
|
|
writeSelectorValue(_s->_segMan, curObject, SELECTOR(underBits), 0);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 19:19:03 +00:00
|
|
|
if (signal & kSignalDisposeMe) {
|
2009-10-13 15:28:27 +00:00
|
|
|
// Call .delete_ method of that object
|
2010-06-10 09:18:57 +00:00
|
|
|
invokeSelector(_s, curObject, SELECTOR(delete_), argc, argv, 0);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
listIterator--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::reAnimate(Common::Rect rect) {
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateEntry *lastCastEntry;
|
2009-10-30 09:26:14 +00:00
|
|
|
uint16 lastCastCount;
|
|
|
|
|
|
|
|
if (_lastCastCount > 0) {
|
|
|
|
lastCastEntry = _lastCastData;
|
|
|
|
lastCastCount = _lastCastCount;
|
|
|
|
while (lastCastCount > 0) {
|
2010-05-15 08:57:13 +00:00
|
|
|
lastCastEntry->castHandle = _paint16->bitsSave(lastCastEntry->celRect, GFX_SCREEN_MASK_VISUAL|GFX_SCREEN_MASK_PRIORITY);
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->drawCel(lastCastEntry->viewId, lastCastEntry->loopNo, lastCastEntry->celNo, lastCastEntry->celRect, lastCastEntry->priority, lastCastEntry->paletteNo, lastCastEntry->scaleX, lastCastEntry->scaleY);
|
2009-10-30 09:26:14 +00:00
|
|
|
lastCastEntry++; lastCastCount--;
|
|
|
|
}
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->bitsShow(rect);
|
2009-10-30 09:26:14 +00:00
|
|
|
// restoring
|
|
|
|
lastCastCount = _lastCastCount;
|
|
|
|
while (lastCastCount > 0) {
|
|
|
|
lastCastEntry--;
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->bitsRestore(lastCastEntry->castHandle);
|
2009-10-30 09:26:14 +00:00
|
|
|
lastCastCount--;
|
|
|
|
}
|
|
|
|
} else {
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->bitsShow(rect);
|
2009-10-30 09:26:14 +00:00
|
|
|
}
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::addToPicDrawCels() {
|
2009-10-13 15:28:27 +00:00
|
|
|
reg_t curObject;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateEntry *listEntry;
|
2010-02-04 22:17:58 +00:00
|
|
|
GfxView *view = NULL;
|
2010-01-05 01:37:57 +00:00
|
|
|
AnimateList::iterator listIterator;
|
|
|
|
AnimateList::iterator listEnd = _list.end();
|
2009-10-13 15:28:27 +00:00
|
|
|
|
|
|
|
listIterator = _list.begin();
|
|
|
|
while (listIterator != listEnd) {
|
|
|
|
listEntry = *listIterator;
|
|
|
|
curObject = listEntry->object;
|
|
|
|
|
|
|
|
if (listEntry->priority == -1)
|
2010-02-05 22:20:46 +00:00
|
|
|
listEntry->priority = _ports->kernelCoordinateToPriority(listEntry->y);
|
2009-10-13 15:28:27 +00:00
|
|
|
|
|
|
|
// Get the corresponding view
|
2010-01-31 12:35:15 +00:00
|
|
|
view = _cache->getView(listEntry->viewId);
|
2009-10-13 15:28:27 +00:00
|
|
|
|
|
|
|
// Create rect according to coordinates and given cel
|
|
|
|
view->getCelRect(listEntry->loopNo, listEntry->celNo, listEntry->x, listEntry->y, listEntry->z, &listEntry->celRect);
|
|
|
|
|
|
|
|
// draw corresponding cel
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->drawCel(listEntry->viewId, listEntry->loopNo, listEntry->celNo, listEntry->celRect, listEntry->priority, listEntry->paletteNo);
|
2009-10-21 19:19:03 +00:00
|
|
|
if ((listEntry->signal & kSignalIgnoreActor) == 0) {
|
2010-02-05 22:20:46 +00:00
|
|
|
listEntry->celRect.top = CLIP<int16>(_ports->kernelPriorityToCoordinate(listEntry->priority) - 1, listEntry->celRect.top, listEntry->celRect.bottom - 1);
|
2010-05-15 08:57:13 +00:00
|
|
|
_paint16->fillRect(listEntry->celRect, GFX_SCREEN_MASK_CONTROL, 0, 0, 15);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
listIterator++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
void GfxAnimate::addToPicDrawView(GuiResourceId viewId, int16 loopNo, int16 celNo, int16 leftPos, int16 topPos, int16 priority, int16 control) {
|
2010-02-04 22:17:58 +00:00
|
|
|
GfxView *view = _cache->getView(viewId);
|
2009-10-13 15:28:27 +00:00
|
|
|
Common::Rect celRect;
|
|
|
|
|
|
|
|
// Create rect according to coordinates and given cel
|
|
|
|
view->getCelRect(loopNo, celNo, leftPos, topPos, priority, &celRect);
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->drawCel(view, loopNo, celNo, celRect, priority, 0);
|
2009-10-13 15:28:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 15:07:36 +00:00
|
|
|
|
|
|
|
void GfxAnimate::animateShowPic() {
|
|
|
|
Port *picPort = _ports->_picWind;
|
|
|
|
Common::Rect picRect = picPort->rect;
|
|
|
|
bool previousCursorState = _cursor->isVisible();
|
|
|
|
|
|
|
|
if (previousCursorState)
|
2010-02-05 14:48:51 +00:00
|
|
|
_cursor->kernelHide();
|
2010-01-31 15:07:36 +00:00
|
|
|
// Adjust picRect to become relative to screen
|
|
|
|
picRect.translate(picPort->left, picPort->top);
|
|
|
|
_transitions->doit(picRect);
|
|
|
|
if (previousCursorState)
|
2010-02-05 14:48:51 +00:00
|
|
|
_cursor->kernelShow();
|
2010-01-31 15:07:36 +00:00
|
|
|
|
|
|
|
// We set SCI1.1 priority band information here
|
|
|
|
_ports->priorityBandsRecall();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxAnimate::kernelAnimate(reg_t listReference, bool cycle, int argc, reg_t *argv) {
|
|
|
|
byte old_picNotValid = _screen->_picNotValid;
|
|
|
|
|
|
|
|
if (listReference.isNull()) {
|
|
|
|
disposeLastCast();
|
|
|
|
if (_screen->_picNotValid)
|
|
|
|
animateShowPic();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
List *list = _s->_segMan->lookupList(listReference);
|
|
|
|
if (!list)
|
|
|
|
error("kAnimate called with non-list as parameter");
|
|
|
|
|
|
|
|
if (cycle) {
|
|
|
|
if (!invoke(list, argc, argv))
|
|
|
|
return;
|
2010-06-18 15:40:18 +00:00
|
|
|
|
|
|
|
// Look up the list again, as it may have been modified
|
|
|
|
list = _s->_segMan->lookupList(listReference);
|
2010-01-31 15:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Port *oldPort = _ports->setPort((Port *)_ports->_picWind);
|
|
|
|
disposeLastCast();
|
|
|
|
|
|
|
|
makeSortedList(list);
|
|
|
|
fill(old_picNotValid);
|
|
|
|
|
|
|
|
if (old_picNotValid) {
|
2010-04-24 21:45:17 +00:00
|
|
|
// beginUpdate()/endUpdate() were introduced SCI1
|
2010-04-24 20:08:03 +00:00
|
|
|
// calling those for SCI0 will work most of the time but breaks minor stuff like percentage bar of qfg1ega
|
|
|
|
// at the character skill screen
|
2010-04-24 21:45:17 +00:00
|
|
|
if (getSciVersion() >= SCI_VERSION_1_EGA)
|
2010-04-24 20:08:03 +00:00
|
|
|
_ports->beginUpdate(_ports->_picWind);
|
2010-01-31 15:07:36 +00:00
|
|
|
update();
|
2010-04-24 21:45:17 +00:00
|
|
|
if (getSciVersion() >= SCI_VERSION_1_EGA)
|
2010-04-24 20:08:03 +00:00
|
|
|
_ports->endUpdate(_ports->_picWind);
|
2010-01-31 15:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
drawCels();
|
|
|
|
|
|
|
|
if (_screen->_picNotValid)
|
|
|
|
animateShowPic();
|
|
|
|
|
|
|
|
updateScreen(old_picNotValid);
|
|
|
|
restoreAndDelete(argc, argv);
|
|
|
|
|
|
|
|
if (getLastCastCount() > 1)
|
|
|
|
_s->_throttleTrigger = true;
|
|
|
|
|
|
|
|
_ports->setPort(oldPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxAnimate::addToPicSetPicNotValid() {
|
|
|
|
if (getSciVersion() <= SCI_VERSION_1_EARLY)
|
|
|
|
_screen->_picNotValid = 1;
|
|
|
|
else
|
|
|
|
_screen->_picNotValid = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxAnimate::kernelAddToPicList(reg_t listReference, int argc, reg_t *argv) {
|
|
|
|
List *list;
|
|
|
|
|
|
|
|
_ports->setPort((Port *)_ports->_picWind);
|
|
|
|
|
|
|
|
list = _s->_segMan->lookupList(listReference);
|
|
|
|
if (!list)
|
|
|
|
error("kAddToPic called with non-list as parameter");
|
|
|
|
|
|
|
|
makeSortedList(list);
|
|
|
|
addToPicDrawCels();
|
|
|
|
|
|
|
|
addToPicSetPicNotValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxAnimate::kernelAddToPicView(GuiResourceId viewId, int16 loopNo, int16 celNo, int16 leftPos, int16 topPos, int16 priority, int16 control) {
|
|
|
|
_ports->setPort((Port *)_ports->_picWind);
|
|
|
|
addToPicDrawView(viewId, loopNo, celNo, leftPos, topPos, priority, control);
|
|
|
|
addToPicSetPicNotValid();
|
|
|
|
}
|
|
|
|
|
2009-10-13 15:28:27 +00:00
|
|
|
} // End of namespace Sci
|