2010-01-31 12:35:15 +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"
|
2010-06-23 15:23:37 +00:00
|
|
|
#include "sci/engine/kernel.h"
|
2010-01-31 12:35:15 +00:00
|
|
|
#include "sci/engine/state.h"
|
|
|
|
#include "sci/engine/selector.h"
|
|
|
|
#include "sci/graphics/compare.h"
|
2010-02-05 20:44:03 +00:00
|
|
|
#include "sci/graphics/coordadjuster.h"
|
2010-01-31 12:35:15 +00:00
|
|
|
#include "sci/graphics/animate.h"
|
|
|
|
#include "sci/graphics/cache.h"
|
|
|
|
#include "sci/graphics/screen.h"
|
|
|
|
#include "sci/graphics/view.h"
|
|
|
|
|
|
|
|
namespace Sci {
|
|
|
|
|
2010-02-05 20:44:03 +00:00
|
|
|
GfxCompare::GfxCompare(SegManager *segMan, Kernel *kernel, GfxCache *cache, GfxScreen *screen, GfxCoordAdjuster *coordAdjuster)
|
|
|
|
: _segMan(segMan), _kernel(kernel), _cache(cache), _screen(screen), _coordAdjuster(coordAdjuster) {
|
2010-01-31 12:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GfxCompare::~GfxCompare() {
|
|
|
|
}
|
|
|
|
|
2010-02-05 22:56:05 +00:00
|
|
|
uint16 GfxCompare::isOnControl(uint16 screenMask, const Common::Rect &rect) {
|
2010-01-31 12:35:15 +00:00
|
|
|
int16 x, y;
|
|
|
|
uint16 result = 0;
|
|
|
|
|
|
|
|
if (rect.isEmpty())
|
|
|
|
return 0;
|
|
|
|
|
2010-05-15 08:57:13 +00:00
|
|
|
if (screenMask & GFX_SCREEN_MASK_PRIORITY) {
|
2010-01-31 12:35:15 +00:00
|
|
|
for (y = rect.top; y < rect.bottom; y++) {
|
|
|
|
for (x = rect.left; x < rect.right; x++) {
|
|
|
|
result |= 1 << _screen->getPriority(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (y = rect.top; y < rect.bottom; y++) {
|
|
|
|
for (x = rect.left; x < rect.right; x++) {
|
|
|
|
result |= 1 << _screen->getControl(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-02-05 22:56:05 +00:00
|
|
|
bool GfxCompare::canBeHereCheckRectList(reg_t checkObject, const Common::Rect &checkRect, List *list) {
|
2010-01-31 12:35:15 +00:00
|
|
|
reg_t curAddress = list->first;
|
|
|
|
Node *curNode = _segMan->lookupNode(curAddress);
|
|
|
|
reg_t curObject;
|
|
|
|
uint16 signal;
|
|
|
|
Common::Rect curRect;
|
|
|
|
|
|
|
|
while (curNode) {
|
|
|
|
curObject = curNode->value;
|
|
|
|
if (curObject != checkObject) {
|
2010-05-29 23:37:15 +00:00
|
|
|
signal = readSelectorValue(_segMan, curObject, SELECTOR(signal));
|
2010-01-31 12:35:15 +00:00
|
|
|
if ((signal & (kSignalIgnoreActor | kSignalRemoveView | kSignalNoUpdate)) == 0) {
|
2010-05-29 23:37:15 +00:00
|
|
|
curRect.left = readSelectorValue(_segMan, curObject, SELECTOR(brLeft));
|
|
|
|
curRect.top = readSelectorValue(_segMan, curObject, SELECTOR(brTop));
|
|
|
|
curRect.right = readSelectorValue(_segMan, curObject, SELECTOR(brRight));
|
|
|
|
curRect.bottom = readSelectorValue(_segMan, curObject, SELECTOR(brBottom));
|
2010-01-31 12:35:15 +00:00
|
|
|
// Check if curRect is within checkRect
|
2010-02-05 22:55:41 +00:00
|
|
|
// TODO: This check is slightly odd, because it means that a rect is not contained
|
|
|
|
// in itself. It may very well be that the original SCI engine did it just
|
|
|
|
// this way, so it should not be changed lightly. However, somebody should
|
|
|
|
// confirm whether the original engine really did it this way. Then, update
|
|
|
|
// this comment accordingly, and, if necessary, fix the code.
|
2010-02-05 22:55:18 +00:00
|
|
|
if (curRect.right > checkRect.left &&
|
|
|
|
curRect.left < checkRect.right &&
|
|
|
|
curRect.bottom > checkRect.top &&
|
|
|
|
curRect.top < checkRect.bottom) {
|
2010-01-31 12:35:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curAddress = curNode->succ;
|
|
|
|
curNode = _segMan->lookupNode(curAddress);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-05 22:56:05 +00:00
|
|
|
uint16 GfxCompare::kernelOnControl(byte screenMask, const Common::Rect &rect) {
|
2010-02-05 20:44:03 +00:00
|
|
|
Common::Rect adjustedRect = _coordAdjuster->onControl(rect);
|
|
|
|
|
|
|
|
uint16 result = isOnControl(screenMask, adjustedRect);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxCompare::kernelSetNowSeen(reg_t objectReference) {
|
2010-02-04 22:17:58 +00:00
|
|
|
GfxView *view = NULL;
|
2010-01-31 12:35:15 +00:00
|
|
|
Common::Rect celRect(0, 0);
|
2010-05-29 23:37:15 +00:00
|
|
|
GuiResourceId viewId = (GuiResourceId)readSelectorValue(_segMan, objectReference, SELECTOR(view));
|
2010-02-06 16:30:32 +00:00
|
|
|
|
|
|
|
// HACK: Ignore invalid views for now (perhaps unimplemented text views?)
|
2010-02-06 15:58:59 +00:00
|
|
|
if (viewId == 0xFFFF) // invalid view
|
|
|
|
return;
|
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
int16 loopNo = readSelectorValue(_segMan, objectReference, SELECTOR(loop));
|
|
|
|
int16 celNo = readSelectorValue(_segMan, objectReference, SELECTOR(cel));
|
|
|
|
int16 x = (int16)readSelectorValue(_segMan, objectReference, SELECTOR(x));
|
|
|
|
int16 y = (int16)readSelectorValue(_segMan, objectReference, SELECTOR(y));
|
2010-01-31 12:35:15 +00:00
|
|
|
int16 z = 0;
|
2010-06-10 09:18:57 +00:00
|
|
|
if (SELECTOR(z) > -1)
|
2010-05-29 23:37:15 +00:00
|
|
|
z = (int16)readSelectorValue(_segMan, objectReference, SELECTOR(z));
|
2010-01-31 12:35:15 +00:00
|
|
|
|
|
|
|
// now get cel rectangle
|
|
|
|
view = _cache->getView(viewId);
|
|
|
|
view->getCelRect(loopNo, celNo, x, y, z, &celRect);
|
|
|
|
|
2010-06-10 09:18:57 +00:00
|
|
|
if (lookupSelector(_segMan, objectReference, SELECTOR(nsTop), NULL, NULL) == kSelectorVariable) {
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, objectReference, SELECTOR(nsLeft), celRect.left);
|
|
|
|
writeSelectorValue(_segMan, objectReference, SELECTOR(nsRight), celRect.right);
|
|
|
|
writeSelectorValue(_segMan, objectReference, SELECTOR(nsTop), celRect.top);
|
|
|
|
writeSelectorValue(_segMan, objectReference, SELECTOR(nsBottom), celRect.bottom);
|
2010-01-31 12:35:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-05 20:44:03 +00:00
|
|
|
bool GfxCompare::kernelCanBeHere(reg_t curObject, reg_t listReference) {
|
|
|
|
Common::Rect checkRect;
|
|
|
|
Common::Rect adjustedRect;
|
|
|
|
uint16 signal, controlMask;
|
|
|
|
bool result;
|
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
checkRect.left = readSelectorValue(_segMan, curObject, SELECTOR(brLeft));
|
|
|
|
checkRect.top = readSelectorValue(_segMan, curObject, SELECTOR(brTop));
|
|
|
|
checkRect.right = readSelectorValue(_segMan, curObject, SELECTOR(brRight));
|
|
|
|
checkRect.bottom = readSelectorValue(_segMan, curObject, SELECTOR(brBottom));
|
2010-02-05 20:44:03 +00:00
|
|
|
|
2010-02-21 09:52:44 +00:00
|
|
|
if (!checkRect.isValidRect()) { // can occur in Iceman - HACK? TODO: is this really occuring in sierra sci? check this
|
|
|
|
warning("kCan(t)BeHere - invalid rect %d, %d -> %d, %d", checkRect.left, checkRect.top, checkRect.right, checkRect.bottom);
|
2010-02-21 00:50:27 +00:00
|
|
|
return false;
|
2010-02-21 09:52:44 +00:00
|
|
|
}
|
2010-02-21 00:50:27 +00:00
|
|
|
|
2010-02-05 20:44:03 +00:00
|
|
|
adjustedRect = _coordAdjuster->onControl(checkRect);
|
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
signal = readSelectorValue(_segMan, curObject, SELECTOR(signal));
|
|
|
|
controlMask = readSelectorValue(_segMan, curObject, SELECTOR(illegalBits));
|
2010-05-15 08:57:13 +00:00
|
|
|
result = (isOnControl(GFX_SCREEN_MASK_CONTROL, adjustedRect) & controlMask) ? false : true;
|
2010-02-05 20:44:03 +00:00
|
|
|
if ((result) && (signal & (kSignalIgnoreActor | kSignalRemoveView)) == 0) {
|
|
|
|
List *list = _segMan->lookupList(listReference);
|
|
|
|
if (!list)
|
|
|
|
error("kCanBeHere called with non-list as parameter");
|
|
|
|
|
|
|
|
result = canBeHereCheckRectList(curObject, checkRect, list);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GfxCompare::kernelIsItSkip(GuiResourceId viewId, int16 loopNo, int16 celNo, Common::Point position) {
|
|
|
|
GfxView *tmpView = _cache->getView(viewId);
|
|
|
|
CelInfo *celInfo = tmpView->getCelInfo(loopNo, celNo);
|
|
|
|
position.x = CLIP<int>(position.x, 0, celInfo->width - 1);
|
|
|
|
position.y = CLIP<int>(position.y, 0, celInfo->height - 1);
|
|
|
|
byte *celData = tmpView->getBitmap(loopNo, celNo);
|
|
|
|
bool result = (celData[position.y * celInfo->width + position.x] == celInfo->clearKey);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxCompare::kernelBaseSetter(reg_t object) {
|
2010-06-10 09:18:57 +00:00
|
|
|
if (lookupSelector(_segMan, object, SELECTOR(brLeft), NULL, NULL) == kSelectorVariable) {
|
2010-05-29 23:37:15 +00:00
|
|
|
int16 x = readSelectorValue(_segMan, object, SELECTOR(x));
|
|
|
|
int16 y = readSelectorValue(_segMan, object, SELECTOR(y));
|
2010-06-10 09:18:57 +00:00
|
|
|
int16 z = (SELECTOR(z) > -1) ? readSelectorValue(_segMan, object, SELECTOR(z)) : 0;
|
2010-05-29 23:37:15 +00:00
|
|
|
int16 yStep = readSelectorValue(_segMan, object, SELECTOR(yStep));
|
|
|
|
GuiResourceId viewId = readSelectorValue(_segMan, object, SELECTOR(view));
|
|
|
|
int16 loopNo = readSelectorValue(_segMan, object, SELECTOR(loop));
|
|
|
|
int16 celNo = readSelectorValue(_segMan, object, SELECTOR(cel));
|
2010-02-05 20:44:03 +00:00
|
|
|
|
2010-02-06 16:30:32 +00:00
|
|
|
// HACK: Ignore invalid views for now (perhaps unimplemented text views?)
|
2010-02-06 15:58:59 +00:00
|
|
|
if (viewId == 0xFFFF) // invalid view
|
|
|
|
return;
|
|
|
|
|
2010-02-05 20:44:03 +00:00
|
|
|
GfxView *tmpView = _cache->getView(viewId);
|
|
|
|
Common::Rect celRect;
|
|
|
|
|
|
|
|
tmpView->getCelRect(loopNo, celNo, x, y, z, &celRect);
|
|
|
|
celRect.bottom = y + 1;
|
|
|
|
celRect.top = celRect.bottom - yStep;
|
|
|
|
|
2010-05-29 23:37:15 +00:00
|
|
|
writeSelectorValue(_segMan, object, SELECTOR(brLeft), celRect.left);
|
|
|
|
writeSelectorValue(_segMan, object, SELECTOR(brRight), celRect.right);
|
|
|
|
writeSelectorValue(_segMan, object, SELECTOR(brTop), celRect.top);
|
|
|
|
writeSelectorValue(_segMan, object, SELECTOR(brBottom), celRect.bottom);
|
2010-02-05 20:44:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-31 12:35:15 +00:00
|
|
|
} // End of namespace Sci
|